Skip to content

Commit

Permalink
Merge pull request #395 from liquidata-inc/aaron/sql-close-rowiters
Browse files Browse the repository at this point in the history
go/cmd/dolt/commands/sql.go: Always close row iters. Improves robustness when SQL returns an error.
  • Loading branch information
Tim Sehn authored Feb 17, 2020
2 parents 49963a6 + c7e5ce6 commit 22b4e97
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bats/sql-works-after-failing-query.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/expect

set timeout 1
spawn dolt sql
expect {
"doltsql> " { send "select json_unquote('\\\\');\r"; }
}
expect {
"error processing results: Missing a closing quotation mark in string"
}
expect {
"doltsql> " { send "select 1;\r"; }
}
expect {
"pid 0 is already in use" { exit 1 }
" 1 " { exit 0 }
}
5 changes: 5 additions & 0 deletions bats/sql.bats
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,8 @@ teardown() {
[ "${#lines[@]}" -eq 5 ]
[[ "${lines[3]}" =~ " <NULL> " ]] || false
}

@test "sql shell works after failing query" {
skiponwindows "Need to install expect and make this script work on windows."
$BATS_TEST_DIRNAME/sql-works-after-failing-query.expect
}
3 changes: 3 additions & 0 deletions go/cmd/dolt/commands/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ func processQuery(ctx context.Context, query string, se *sqlEngine) error {
case *sqlparser.Select, *sqlparser.Insert, *sqlparser.Update, *sqlparser.OtherRead, *sqlparser.Show, *sqlparser.Explain:
sqlSch, rowIter, err := se.query(ctx, query)
if err == nil {
defer rowIter.Close()
err = se.prettyPrintResults(ctx, se.ddb.ValueReadWriter().Format(), sqlSch, rowIter)
}
return err
Expand All @@ -543,6 +544,7 @@ func processQuery(ctx context.Context, query string, se *sqlEngine) error {
}
sqlSch, rowIter, err := se.query(ctx, query)
if err == nil {
defer rowIter.Close()
err = se.prettyPrintResults(ctx, se.ddb.Format(), sqlSch, rowIter)
}
return err
Expand Down Expand Up @@ -585,6 +587,7 @@ func processBatchQuery(ctx context.Context, query string, se *sqlEngine) error {
if err != nil {
return fmt.Errorf("Error inserting rows: %v", err.Error())
}
defer rowIter.Close()

err = mergeInsertResultIntoStats(rowIter, &batchEditStats)
if err != nil {
Expand Down

0 comments on commit 22b4e97

Please sign in to comment.