From 4e147dcd8d0632b10ec0a5fd84fc1fe4291965f3 Mon Sep 17 00:00:00 2001 From: Neil Macneale IV Date: Mon, 17 Jul 2023 09:04:21 -0700 Subject: [PATCH 1/3] Verify that a prompt can be an empty string using expect --- .../bats/sql-shell-empty-prompt.expect | 32 +++++++++++++++++++ integration-tests/bats/sql-shell.bats | 13 ++++++++ .../bats/sql-works-after-failing-query.expect | 3 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 integration-tests/bats/sql-shell-empty-prompt.expect diff --git a/integration-tests/bats/sql-shell-empty-prompt.expect b/integration-tests/bats/sql-shell-empty-prompt.expect new file mode 100755 index 0000000000..3ed2e01076 --- /dev/null +++ b/integration-tests/bats/sql-shell-empty-prompt.expect @@ -0,0 +1,32 @@ +#!/usr/bin/expect -f + +set timeout 5 +spawn dolt sql + +expect { + "> " { send "select 23;\r"; } + timeout { exit 1; } +} + +expect { + "| 23 |" { } + timeout { exit 1; } +} +expect { + "| 23 |" { } + timeout { exit 1; } +} + +expect { + "> " { send "exit;\r"; } + timeout { exit 1; } +} + +expect { + eof { } + timeout { exit 1; } +} + +set waitval [wait -i $spawn_id] +set exval [lindex $waitval 3] +exit $exval diff --git a/integration-tests/bats/sql-shell.bats b/integration-tests/bats/sql-shell.bats index 2503aa2a65..7f5da8d55a 100644 --- a/integration-tests/bats/sql-shell.bats +++ b/integration-tests/bats/sql-shell.bats @@ -71,7 +71,20 @@ teardown() { $BATS_TEST_DIRNAME/sql-works-after-failing-query.expect } +@test "sql-shell: empty DB in prompt is OK" { + skiponwindows "Need to install expect and make this script work on windows." + if [ "$SQL_ENGINE" = "remote-engine" ]; then + skip "Presently sql command will not connect to remote server due to lack of lock file where there are not DBs." + fi + # ignore common setup. Use an empty db with no server. + rm -rf .dolt + mkdir emptyDb + cd emptyDb + $BATS_TEST_DIRNAME/sql-shell-empty-prompt.expect +} + @test "sql-shell: delimiter" { + skiponwindows "Need to install expect and make this script work on windows." mkdir doltsql cd doltsql diff --git a/integration-tests/bats/sql-works-after-failing-query.expect b/integration-tests/bats/sql-works-after-failing-query.expect index cc206124ac..a5dc1c183f 100755 --- a/integration-tests/bats/sql-works-after-failing-query.expect +++ b/integration-tests/bats/sql-works-after-failing-query.expect @@ -1,4 +1,4 @@ -#!/usr/bin/expect +#!/usr/bin/expect -f set timeout 1 spawn dolt sql @@ -15,3 +15,4 @@ expect { "pid 0 is already in use" { exit 1 } " 1 " { exit 0 } } + From cc65904ec6ddb092e1a5dd4b9c1bf338db336ab9 Mon Sep 17 00:00:00 2001 From: Neil Macneale IV Date: Fri, 14 Jul 2023 18:08:18 -0700 Subject: [PATCH 2/3] Allow empty databases in the shell prompt --- go/cmd/dolt/commands/sql.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/go/cmd/dolt/commands/sql.go b/go/cmd/dolt/commands/sql.go index 043a4a71f2..88d25abd31 100644 --- a/go/cmd/dolt/commands/sql.go +++ b/go/cmd/dolt/commands/sql.go @@ -811,7 +811,6 @@ func execShell(sqlCtx *sql.Context, qryist cli.Queryist, format engine.PrintResu // getDBFromSession returns the current database name for the session, handling all the errors along the way by printing // red error messages to the CLI. If there was an issue getting the db name, the second return value is false. func getDBFromSession(sqlCtx *sql.Context, qryist cli.Queryist) (db string, ok bool) { - db = "unknown" _, resp, err := qryist.Query(sqlCtx, "select database()") if err != nil { cli.Println(color.RedString("Failure to get DB Name for session" + err.Error())) @@ -827,11 +826,11 @@ func getDBFromSession(sqlCtx *sql.Context, qryist cli.Queryist) (db string, ok b cli.Println(color.RedString("Failure to get DB Name for session" + err.Error())) return db, false } - if row[0] == nil || row[0].(string) == "" { - cli.Println(color.RedString("Empty Database name obtained" + err.Error())) - return db, false + if row[0] == nil { + db = "" + } else { + db = row[0].(string) } - db = row[0].(string) return db, true } From e94d0b26fb4ca8948fefaec4b4467f048dfb5565 Mon Sep 17 00:00:00 2001 From: Neil Macneale IV <46170177+macneale4@users.noreply.github.com> Date: Tue, 18 Jul 2023 17:14:08 -0700 Subject: [PATCH 3/3] Remove mistaken insert Co-authored-by: Jason Fulghum --- integration-tests/bats/sql-shell.bats | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-tests/bats/sql-shell.bats b/integration-tests/bats/sql-shell.bats index 7f5da8d55a..a4e7e08a80 100644 --- a/integration-tests/bats/sql-shell.bats +++ b/integration-tests/bats/sql-shell.bats @@ -84,7 +84,6 @@ teardown() { } @test "sql-shell: delimiter" { - skiponwindows "Need to install expect and make this script work on windows." mkdir doltsql cd doltsql