diff --git a/go/cmd/dolt/commands/sql.go b/go/cmd/dolt/commands/sql.go index 379db9cb4d0..ddb23ce2d7e 100644 --- a/go/cmd/dolt/commands/sql.go +++ b/go/cmd/dolt/commands/sql.go @@ -878,6 +878,9 @@ func formattedPrompts(db, branch string, dirty bool) (string, string) { // along the way by printing red error messages to the CLI. If there was an issue getting the db name, the ok return // value will be false and the strings will be empty. func getDBBranchFromSession(sqlCtx *sql.Context, qryist cli.Queryist) (db string, branch string, ok bool) { + sqlCtx.Session.LockWarnings() + defer sqlCtx.Session.UnlockWarnings() + _, resp, err := qryist.Query(sqlCtx, "select database() as db, active_branch() as branch") if err != nil { cli.Println(color.RedString("Failure to get DB Name for session: " + err.Error())) @@ -917,6 +920,9 @@ func getDBBranchFromSession(sqlCtx *sql.Context, qryist cli.Queryist) (db string // isDirty returns true if the workspace is dirty, false otherwise. This function _assumes_ you are on a database // with a branch. If you are not, you will get an error. func isDirty(sqlCtx *sql.Context, qryist cli.Queryist) (bool, error) { + sqlCtx.Session.LockWarnings() + defer sqlCtx.Session.UnlockWarnings() + _, resp, err := qryist.Query(sqlCtx, "select count(table_name) > 0 as dirty from dolt_status") if err != nil { @@ -948,6 +954,8 @@ func newCompleter( sqlCtx := sql.NewContext(subCtx, sql.WithSession(ctx.Session)) + sqlCtx.Session.LockWarnings() + defer sqlCtx.Session.UnlockWarnings() _, iter, err := qryist.Query(sqlCtx, "select table_schema, table_name, column_name from information_schema.columns;") if err != nil { return nil, err diff --git a/integration-tests/bats/sql-shell-warnings.expect b/integration-tests/bats/sql-shell-warnings.expect new file mode 100755 index 00000000000..4f5457ef129 --- /dev/null +++ b/integration-tests/bats/sql-shell-warnings.expect @@ -0,0 +1,25 @@ +#!/usr/bin/expect + +set timeout 5 +set env(NO_COLOR) 1 +spawn dolt sql + +expect { + -re "dolt-repo-.*> " { send "select 1/0;\r"; } + timeout { exit 1; } + failed { exit 1; } +} + +expect { + -re "dolt-repo-.*> " { send "show warnings;\r"; } + timeout { exit 1; } + failed { exit 1; } +} + +expect { + -re "dolt-repo-.*> " { send "exit;\r"; } + timeout { exit 1; } + failed { exit 1; } +} + +expect eof \ No newline at end of file diff --git a/integration-tests/bats/sql-shell.bats b/integration-tests/bats/sql-shell.bats index 7777cea8db0..abe8103c3e2 100644 --- a/integration-tests/bats/sql-shell.bats +++ b/integration-tests/bats/sql-shell.bats @@ -21,6 +21,21 @@ teardown() { teardown_common } + +# bats test_tags=no_lambda +@test "sql-shell: warnings are not suppressed" { + skiponwindows "Need to install expect and make this script work on windows." + if [ "$SQL_ENGINE" = "remote-engine" ]; then + skip "session ctx in shell is no the same as session in server" + fi + run $BATS_TEST_DIRNAME/sql-shell-warnings.expect + echo "$output" + + [[ "$output" =~ "Warning" ]] || false + [[ "$output" =~ "1365" ]] || false + [[ "$output" =~ "Division by 0" ]] || false +} + @test "sql-shell: use user without privileges, and no superuser created" { rm -rf .doltcfg