fix warnings in dolt sql shell (#8150)

This commit is contained in:
James Cor
2024-07-26 11:43:59 -07:00
committed by GitHub
parent 7ba443975a
commit 3e2a7a61e6
3 changed files with 48 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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