Skip to content

Commit

Permalink
Allow to use 'in' statement with 'order by'
Browse files Browse the repository at this point in the history
When we used query like
`select * from commits where 'cloudson' in hash order by date asc`
gitql has failed.
This closes #20 .
  • Loading branch information
Claudson Oliveira committed Dec 29, 2016
1 parent 9242a1a commit aab37bd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
6 changes: 2 additions & 4 deletions runtime/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ func walkCommits(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, er
if err != nil {
return nil, err
}
if usingOrder {
if counter > s.Limit {
counter = s.Limit
}
if usingOrder && counter > s.Limit {
counter = s.Limit
rowsSliced = rowsSliced[0:counter]
}
tableData := new(TableData)
Expand Down
6 changes: 2 additions & 4 deletions runtime/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ func walkReferences(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData,
if err != nil {
return nil, err
}
if usingOrder {
if counter > s.Limit {
counter = s.Limit
}
if usingOrder && counter > s.Limit {
counter = s.Limit
rowsSliced = rowsSliced[0:counter]
}
tableData := new(TableData)
Expand Down
6 changes: 2 additions & 4 deletions runtime/remotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ func walkRemotes(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, er
if err != nil {
return nil, err
}
if usingOrder {
if counter > s.Limit {
counter = s.Limit
}
if usingOrder && counter > s.Limit {
counter = s.Limit
rowsSliced = rowsSliced[0:counter]
}
tableData := new(TableData)
Expand Down
26 changes: 26 additions & 0 deletions runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,29 @@ func TestCanConvertToTypeFormats(t *testing.T) {
typeFormat := "json"
Run(ast, &typeFormat)
}

func TestNotFoundCommitWithInStatementAndSorting(t *testing.T) {
folder, errFile := filepath.Abs("../")

if errFile != nil {
t.Errorf(errFile.Error())
}

query := "select author from commits where 'thisisnotfound' in hash order by date desc"

parser.New(query)
ast, errGit := parser.AST()
if errGit != nil {
t.Errorf(errGit.Error())
}
ast.Path = &folder
errGit = semantical.Analysis(ast)
if errGit != nil {
t.Errorf(errGit.Error())
}

typeFormat := "table"
if errGit = Run(ast, &typeFormat); errGit != nil {
t.Errorf(errGit.Error())
}
}

0 comments on commit aab37bd

Please sign in to comment.