From aab37bdd66d078946015c74a02a08a1e92443418 Mon Sep 17 00:00:00 2001 From: Claudson Oliveira Date: Thu, 29 Dec 2016 03:55:52 -0200 Subject: [PATCH] Allow to use 'in' statement with 'order by' When we used query like `select * from commits where 'cloudson' in hash order by date asc` gitql has failed. This closes #20 . --- runtime/commits.go | 6 ++---- runtime/reference.go | 6 ++---- runtime/remotes.go | 6 ++---- runtime/runtime_test.go | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/runtime/commits.go b/runtime/commits.go index b7c6e75..49eb163 100644 --- a/runtime/commits.go +++ b/runtime/commits.go @@ -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) diff --git a/runtime/reference.go b/runtime/reference.go index e82d977..e09fdbd 100644 --- a/runtime/reference.go +++ b/runtime/reference.go @@ -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) diff --git a/runtime/remotes.go b/runtime/remotes.go index cdb6cf8..91c348c 100644 --- a/runtime/remotes.go +++ b/runtime/remotes.go @@ -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) diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index fa54dd9..1e25cfa 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -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()) + } +}