Skip to content

Commit

Permalink
fix warnings in dolt sql shell (#8150)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor authored Jul 26, 2024
1 parent 7ba4439 commit 3e2a7a6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go/cmd/dolt/commands/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions integration-tests/bats/sql-shell-warnings.expect
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions integration-tests/bats/sql-shell.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3e2a7a6

Please sign in to comment.