Merge pull request #4658 from dolthub/tim/bats/remove-server_query

Remove `server_query` in favor of `dolt sql-client` in bats
This commit is contained in:
Tim Sehn
2022-10-28 14:13:25 -07:00
committed by GitHub
7 changed files with 153 additions and 240 deletions
+46 -18
View File
@@ -28,8 +28,9 @@ import (
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/ishell"
"github.com/fatih/color"
_ "github.com/go-sql-driver/mysql"
mysqlDriver "github.com/go-sql-driver/mysql"
"github.com/gocraft/dbr/v2"
"github.com/gocraft/dbr/v2/dialect"
"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/cmd/dolt/commands"
@@ -202,42 +203,69 @@ func (cmd SqlClientCmd) Exec(ctx context.Context, commandStr string, args []stri
}
}
conn, err := dbr.Open("mysql", ConnectionString(serverConfig, dbToUse), nil)
// The standard DSN parser cannot handle a forward slash in the database name, so we have to workaround it.
// See the original issue: https://github.com/dolthub/dolt/issues/4623
parsedMySQLConfig, err := mysqlDriver.ParseDSN(ConnectionString(serverConfig, "no_database"))
if err != nil {
cli.PrintErrln(err.Error())
serverController.StopServer()
err = serverController.WaitForClose()
if err != nil {
cli.PrintErrln(err.Error())
}
return 1
}
parsedMySQLConfig.DBName = dbToUse
mysqlConnector, err := mysqlDriver.NewConnector(parsedMySQLConfig)
if err != nil {
cli.PrintErrln(err.Error())
return 1
}
conn := &dbr.Connection{DB: mysql.OpenDB(mysqlConnector), EventReceiver: nil, Dialect: dialect.MySQL}
_ = conn.Ping()
if hasQuery {
defer conn.Close()
rows, err := conn.Query(query)
if err != nil {
cli.PrintErrln(err.Error())
return 1
}
if rows != nil {
sqlCtx := sql.NewContext(ctx)
wrapper, err := NewMysqlRowWrapper(rows)
if apr.Contains(noAutoCommitFlag) {
_, err = conn.Exec("set @@autocommit = off;")
if err != nil {
cli.PrintErrln(err.Error())
return 1
}
defer wrapper.Close(sqlCtx)
if wrapper.HasMoreRows() {
err = engine.PrettyPrintResults(sqlCtx, format, wrapper.Schema(), wrapper)
}
scanner := commands.NewSqlStatementScanner(strings.NewReader(query))
query = ""
for scanner.Scan() {
query += scanner.Text()
if len(query) == 0 || query == "\n" {
continue
}
rows, err := conn.Query(query)
if err != nil {
cli.PrintErrln(err.Error())
return 1
}
if rows != nil {
sqlCtx := sql.NewContext(ctx)
wrapper, err := NewMysqlRowWrapper(rows)
if err != nil {
cli.PrintErrln(err.Error())
return 1
}
defer wrapper.Close(sqlCtx)
if wrapper.HasMoreRows() {
err = engine.PrettyPrintResults(sqlCtx, format, wrapper.Schema(), wrapper)
if err != nil {
cli.PrintErrln(err.Error())
return 1
}
}
}
query = ""
}
if err = scanner.Err(); err != nil {
cli.PrintErrln(err.Error())
return 1
}
return 0
}
+11 -11
View File
@@ -80,15 +80,14 @@ make_it() {
start_sql_server "dolt_repo_$$"
# Can't string together multiple queries in dolt sql-client
server_query "dolt_repo_$$" 1 dolt "" 'call dolt_checkout("to_keep"); call dolt_branch("-D", "main");' ""
dolt sql-client --use-db "dolt_repo_$$" -u dolt -P $PORT -q 'call dolt_checkout("to_keep"); call dolt_branch("-D", "main");'
# Against the default branch it fails
run dolt sql-client --use-db "dolt_repo_$$" -u dolt -P $PORT -q "SELECT * FROM test"
[ $status -ne 0 ]
# Against to_keep it succeeds
server_query "dolt_repo_$$/to_keep" 1 dolt "" "SELECT * FROM test" "id\n" ""
dolt sql-client --use-db "dolt_repo_$$/to_keep" -u dolt -P $PORT -q "SELECT * FROM test"
}
@test "deleted-branches: can SQL connect with existing branch revision specifier when dolt_default_branch is invalid" {
@@ -103,7 +102,7 @@ make_it() {
[ $status -ne 0 ]
# Against main, which exists it succeeds
server_query "dolt_repo_$$/main" 1 dolt "" "SELECT * FROM test" "id\n" ""
dolt sql-client --use-db "dolt_repo_$$/main" -u dolt -P $PORT -q "SELECT * FROM test"
}
@test "deleted-branches: calling DOLT_CHECKOUT on SQL connection with existing branch revision specifier when dolt_default_branch is invalid does not panic" {
@@ -114,10 +113,11 @@ make_it() {
dolt sql-client --use-db "dolt_repo_$$" -u dolt -P $PORT -q "SET @@GLOBAL.dolt_repo_$$_default_branch = 'this_branch_does_not_exist'" ""
# We are able to use a database branch revision in the connection string
server_query "dolt_repo_$$/main" 1 dolt "" "SELECT * FROM test;"
dolt sql-client --use-db "dolt_repo_$$/main" -u dolt -P $PORT -q "SELECT * FROM test;"
# Trying to checkout a new branch throws an error, but doesn't panic
run server_query "dolt_repo_$$/main" 1 dolt "" "CALL DOLT_CHECKOUT('to_keep');" "" 1
run dolt sql-client --use-db "dolt_repo_$$/main" -u dolt -P $PORT -q"CALL DOLT_CHECKOUT('to_keep');"
[ $status -ne 0 ]
[[ "$output" =~ "branch not found" ]] || false
}
@@ -128,14 +128,14 @@ make_it() {
start_sql_server "dolt_repo_$$"
server_query "dolt_repo_$$" 1 dolt "" 'call dolt_checkout("to_keep"); call dolt_branch("-D", "main");' ""
dolt sql-client --use-db "dolt_repo_$$" -u dolt -P $PORT -q "call dolt_checkout('to_keep'); call dolt_branch('-D', 'main');"
# We are able to use a database branch revision in the connection string
server_query "dolt_repo_$$/to_keep" 1 dolt "" "SELECT * FROM test;"
dolt sql-client --use-db "dolt_repo_$$/to_keep" -u dolt -P $PORT -q "SELECT * FROM test;"
# Trying to checkout a new branch throws an error, but doesn't panic
run server_query "dolt_repo_$$/to_keep" 1 dolt "" "CALL DOLT_CHECKOUT('to_checkout');" "" 1
run dolt sql-client --use-db "dolt_repo_$$/to_keep" -u dolt -P $PORT -q "CALL DOLT_CHECKOUT('to_checkout');"
[ $status -ne 0 ]
[[ "$output" =~ "branch not found" ]] || false
}
@@ -148,7 +148,7 @@ make_it() {
dolt sql-client --use-db "dolt_repo_$$" -u dolt -P $PORT -q "SET @@GLOBAL.dolt_repo_$$_default_branch = 'to_keep'" ""
server_query "dolt_repo_$$" 1 dolt "" 'call dolt_checkout("to_keep"); call dolt_branch("-D", "main");' ""
dolt sql-client --use-db "dolt_repo_$$" -u dolt -P $PORT -q "call dolt_checkout('to_keep'); call dolt_branch('-D', 'main');"
dolt sql-client --use-db "dolt_repo_$$" -u dolt -P $PORT -q "SELECT * FROM test"
-33
View File
@@ -13,15 +13,6 @@ def _print_err_and_exit(e):
print(e, file=sys.stderr)
sys.exit(1)
def csv_to_row_maps(csv_str):
csv_str = csv_str.replace('\\n', '\n')
rd = csv.DictReader(StringIO(csv_str))
rows = []
for row in rd:
rows.append(row)
return rows
class DoltConnection(object):
def __init__(self, user='root', password=None, host='127.0.0.1', port=3306, database='dolt', auto_commit=False):
self.user = user
@@ -42,30 +33,6 @@ class DoltConnection(object):
def close(self):
self.cnx.close()
def query(self, query_str, exit_on_err=True):
try:
cursor = self.cnx.cursor()
cursor.execute(query_str)
if cursor.description is None:
return [], cursor.rowcount
raw = cursor.fetchall()
row_maps = []
for curr in raw:
r = {}
for i, k in enumerate(cursor.column_names):
r[k] = str(curr[i])
row_maps.append(r)
return row_maps, cursor.rowcount
except BaseException as e:
if exit_on_err:
_print_err_and_exit(e)
raise e
class InfiniteRetryConnection(DoltConnection):
def connect(self):
while True:
@@ -2,88 +2,6 @@ SERVER_REQS_INSTALLED="FALSE"
SERVER_PID=""
DEFAULT_DB=""
PYTHON_QUERY_SCRIPT="
import os
import sys
args = sys.argv[sys.argv.index('--') + 1:]
query_results = None
expected_exception = None
working_dir, database, port_str, auto_commit, username, password, query_strs = args[0:7]
if len(args) > 7:
query_results = args[7]
if len(args) > 8:
expected_exception = args[8]
print('User: ' + username)
print('Password: ' + password)
print('Query Strings: ' + query_strs)
print('Working Dir: ' + working_dir)
print('Database: ' + database)
print('Port: ' + port_str)
print('Autocommit: ' + auto_commit)
print('Expected Results: ' + str(query_results))
print('Expected Exception: ' + str(expected_exception))
os.chdir(working_dir)
if auto_commit == '1':
auto_commit = True
else:
auto_commit = False
from pytest import DoltConnection, csv_to_row_maps
if not database:
dc = DoltConnection(port=int(port_str), database=None, user=username, password=password, auto_commit=auto_commit)
else:
dc = DoltConnection(port=int(port_str), database=database, user=username, password=password, auto_commit=auto_commit)
try:
dc.connect()
except BaseException as e:
print('caught exception', str(e))
if expected_exception is not None and len(expected_exception) > 0:
if expected_exception not in str(e):
print('expected exception: ', expected_exception, '\n got: ', str(e))
sys.exit(1)
else:
sys.exit(0)
queries = query_strs.split(';')
expected = [None]*len(queries)
if query_results is not None:
expected = query_results.split(';')
if len(expected) < len(queries):
expected.extend(['']*(len(queries)-len(expected)))
for i in range(len(queries)):
query_str = queries[i].strip()
print('executing:', query_str)
actual_rows, num_rows = None, None
try:
actual_rows, num_rows = dc.query(query_str, False)
except BaseException as e:
print('caught exception', str(e))
if expected_exception is not None and len(expected_exception) > 0:
if expected_exception not in str(e):
print('expected exception: ', expected_exception, '\n got: ', str(e))
sys.exit(1)
else:
sys.exit(1)
if expected[i] is not None and expected[i] != '':
print('Raw Expected: ', expected[i])
expected_rows = csv_to_row_maps(expected[i])
if expected_rows != actual_rows:
print('expected:', expected_rows, '\n actual:', actual_rows)
sys.exit(1)
"
set_server_reqs_installed() {
SERVER_REQS_INSTALLED=$(python3 -c "
requirements_installed = True
@@ -206,53 +124,6 @@ stop_sql_server() {
SERVER_PID=
}
# server_query connects to a running mysql server,
# executes a query (or list of queries separated by a `;`),
# and compares the results against what is expected.
#
# EXAMPLE: server_query db1 1 dolt "" "select * from test" "c1\n0"
#
# If executing multiple queries, separate the expected CSV values with a `;`.
#
# EXAMPLE: server_query "" 1 dolt "" "use db1; select * from test" ";c1\n0"
#
# If you expect an exception, leave query results blank and add an additional
# value of 1 to the end of the call. This could be improved to actually send
# up the exception string to be checked but I could not figure out how to do
# that. When calling with bats use `run` and then check the $output if you
# want to inspect the exception string.
#
# EXAMPLE: run server_query "" 1 dolt "" "garbage" "" 1
# [[ "$output" =~ "error" ]] || false
#
# In the event that the results do not match expectations,
# the python process will exit with an exit code of 1
#
# * param1: The database name for the connection string.
# Leave empy for no database.
# * param2: 1 for autocommit = true, 0 for autocommit = false
# * param3: User
# * param4: Password
# * param5: Query string or query strings separated by `;`
# * param6: A csv representing the expected result set.
# If a query is not expected to have a result set "" should
# be passed. Seprate multiple result sets with `;`
# * param7: Expected exception value of 1. Mutually exclusive with param6.
#
server_query() {
server_query_with_port "$PORT" "$@"
}
# See server_query, but first parameter is the port sql-server is running on,
# every other parameter is positionally one later.
server_query_with_port() {
let PORT="$1"
shift
PYTEST_DIR="$BATS_TEST_DIRNAME/helper"
echo Executing server_query
python3 -u -c "$PYTHON_QUERY_SCRIPT" -- "$PYTEST_DIR" "$1" "$PORT" "$2" "$3" "$4" "$5" "$6" "$7"
}
definePORT() {
getPORT=""
for i in {0..9}
+7 -1
View File
@@ -30,7 +30,13 @@ teardown() {
@test "multidb: database default branches" {
cd dbs1
start_multi_db_server repo1
server_query repo1 1 dolt "" "create database new; use new; call dcheckout('-b', 'feat'); create table t (x int); call dolt_add('.'); call dcommit('-am', 'cm'); set @@global.new_default_branch='feat'"
dolt sql-client -u dolt -P $PORT --use-db repo1 -q "create database new;
use new;
call dcheckout('-b', 'feat');
create table t (x int);
call dolt_add('.');
call dcommit('-am', 'cm');
set @@global.new_default_branch='feat'"
dolt sql-client -u dolt --use-db '' -P $PORT -q "use repo1"
}
+20 -9
View File
@@ -218,22 +218,30 @@ teardown() {
# Can't use dolt sql-client to connect to branches
# Connecting to heads that exist only on the remote should work fine (they get fetched)
server_query "repo2/new_feature" 1 dolt "" "show tables" "Tables_in_repo2/new_feature\ntest"
server_query repo2 1 dolt "" 'use `repo2/new_feature2`' ""
server_query repo2 1 dolt "" 'select * from `repo2/new_feature2`.test' "pk\n0\n1\n2"
dolt sql-client --use-db "repo2/new_feature" -u dolt -P $PORT -q "show tables" "Tables_in_repo2/new_feature\ntest"
dolt sql-client --use-db repo2 -P $PORT -u dolt -q 'use `repo2/new_feature2`'
run dolt sql-client --use-db repo2 -P $PORT -u dolt -q 'select * from `repo2/new_feature2`.test'
[ $status -eq 0 ]
[[ "$output" =~ "pk" ]] || false
[[ "$output" =~ " 0 " ]] || false
[[ "$output" =~ " 1 " ]] || false
[[ "$output" =~ " 2 " ]] || false
# Connecting to heads that don't exist should error out
run server_query "repo2/notexist" 1 dolt "" 'use `repo2/new_feature2`' "" 1
run dolt sql-client --use-db "repo2/notexist" -u dolt -P $PORT -q 'use `repo2/new_feature2`'
[ $status -ne 0 ]
[[ $output =~ "database not found" ]] || false
run server_query repo2 1 dolt "" 'use `repo2/notexist`' "" 1
run dolt sql-client --use-db repo2 -P $PORT -u dolt -q 'use `repo2/notexist`'
[ $status -ne 0 ]
[[ $output =~ "database not found" ]] || false
# Creating a branch locally that doesn't exist on the remote
# works, but connecting to it is an error (nothing to pull)
server_query "repo2/new_feature" 1 dolt "" "select dolt_checkout('-b', 'new_branch') as b" "b\n0"
dolt sql-client --use-db "repo2/new_feature" -u dolt -P $PORT -q "select dolt_checkout('-b', 'new_branch')"
run server_query "repo2/new_branch" 1 dolt "" "show tables" "Table\ntest" "" 1
run dolt sql-client --use-db "repo2/new_branch" -u dolt -P $PORT -q "show tables"
[ $status -ne 0 ]
[[ $output =~ "database not found" ]] || false
}
@@ -319,7 +327,10 @@ teardown() {
[ "$output" = "" ]
# Can't connect to a specific branch with dolt sql-client
server_query "repo2/feature-branch" 1 dolt "" "SHOW Tables" "Tables_in_repo2/feature-branch\ntest"
run dolt sql-client --use-db "repo2/feature-branch" -u dolt -P $PORT -q "SHOW Tables"
[ $status -eq 0 ]
[[ $output =~ "feature-branch" ]] || false
[[ $output =~ "test" ]] || false
}
@test "remotes-sql-server: connect to hash works" {
@@ -340,7 +351,7 @@ teardown() {
[[ $output =~ "Tables_in_repo2" ]] || false
[[ $output =~ "test" ]] || false
run dolt sql-client --use-db repo2 -P $PORT -u dolt -q"use \`repo2/$head_hash\`"
run dolt sql-client --use-db repo2 -P $PORT -u dolt -q "use \`repo2/$head_hash\`"
[ $status -eq 0 ]
[ "$output" = "" ]
}
+69 -39
View File
@@ -206,7 +206,7 @@ SQL
[[ "$output" =~ "No tables in working set" ]] || false
# create table with autocommit off and verify there are still no tables
server_query repo1 0 dolt "" "CREATE TABLE one_pk (
dolt sql-client -P $PORT -u dolt --no-auto-commit -q "" "CREATE TABLE one_pk (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
@@ -217,7 +217,8 @@ SQL
[[ "$output" =~ "No tables in working set" ]] || false
# check that dolt_commit throws an error when there are no changes to commit
run server_query repo1 0 dolt "" "CALL DOLT_COMMIT('-a', '-m', 'Commit1')" "" 1
run dolt sql-client -P $PORT -u dolt --no-auto-commit -q "CALL DOLT_COMMIT('-a', '-m', 'Commit1')"
[ $status -ne 0 ]
[[ "$output" =~ "nothing to commit" ]] || false
run dolt ls
@@ -286,7 +287,7 @@ SQL
[ "$status" -eq 0 ]
[[ "$output" =~ "6,6" ]] || false
server_query repo1 1 dolt "" "
dolt sql-client -P $PORT -u dolt -q "
INSERT INTO test VALUES (8,8);
CALL DOLT_RESET('--hard');"
@@ -311,7 +312,8 @@ SQL
PRIMARY KEY (pk))"
# create a table in repo2
server_query repo1 1 dolt "" "USE repo2; CREATE TABLE r2_one_pk (
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "USE repo2;
CREATE TABLE r2_one_pk (
pk BIGINT NOT NULL COMMENT 'tag:0',
c3 BIGINT COMMENT 'tag:1',
c4 BIGINT COMMENT 'tag:2',
@@ -322,10 +324,12 @@ SQL
run dolt sql-client -P $PORT -u dolt --use-db repo1 -q "SHOW tables"
[ $status -eq 0 ]
[[ $output =~ "r1_one_pk" ]] || false
server_query repo1 1 dolt "" "USE repo2; SHOW tables" ";Tables_in_repo2\nr2_one_pk"
run dolt sql-client -P $PORT -u dolt --use-db repo1 -q "USE repo2; SHOW tables"
[ $status -eq 0 ]
[[ $output =~ "r2_one_pk" ]] || false
# put data in both
server_query repo1 1 dolt "" "
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "
INSERT INTO r1_one_pk (pk) VALUES (0);
INSERT INTO r1_one_pk (pk,c1) VALUES (1,1);
INSERT INTO r1_one_pk (pk,c1,c2) VALUES (2,2,2),(3,3,3);
@@ -348,7 +352,7 @@ SQL
[[ $output =~ "2,2,2" ]] || false
[[ $output =~ "3,3,3" ]] || false
server_query repo1 1 dolt "" "
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "
DELETE FROM r1_one_pk where pk=0;
USE repo2;
DELETE FROM r2_one_pk where pk=0"
@@ -367,7 +371,7 @@ SQL
[[ $output =~ "2,2,2" ]] || false
[[ $output =~ "3,3,3" ]] || false
server_query repo1 1 dolt "" "
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "
UPDATE r1_one_pk SET c2=1 WHERE pk=1;
USE repo2;
UPDATE r2_one_pk SET c4=1 where pk=1"
@@ -497,7 +501,7 @@ SQL
[[ $output =~ " 1 " ]] || false
[[ $output =~ " 2 " ]] || false
server_query repo1 1 dolt "" "
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "
CALL DOLT_CHECKOUT('feature-branch');
INSERT INTO test VALUES (3);
INSERT INTO test VALUES (4);
@@ -514,12 +518,12 @@ SQL
! [[ $output =~ " 3 " ]] || false
! [[ $output =~ " 21 " ]] || false
server_query repo1 1 dolt "" "
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "
CALL DOLT_CHECKOUT('feature-branch');
CALL DOLT_COMMIT('-a', '-m', 'Insert 3');
"
server_query repo1 1 dolt "" "
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "
INSERT INTO test VALUES (500000);
INSERT INTO test VALUES (500001);
DELETE FROM test WHERE pk=500001;
@@ -549,7 +553,7 @@ SQL
cd repo1
start_sql_server repo1
server_query repo1 1 dolt "" "
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "
CREATE TABLE test (
pk int primary key
);
@@ -689,7 +693,7 @@ SQL
[ "${#lines[@]}" -eq 0 ]
# make some changes to main and commit to branch test_branch
server_query repo1 1 dolt "" "
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "
CALL DOLT_CHECKOUT('main');
CREATE TABLE one_pk (
pk BIGINT NOT NULL,
@@ -749,7 +753,7 @@ SQL
dolt checkout main
start_sql_server repo1
server_query "repo1/feature-branch" 1 dolt "" "CREATE TABLE test (
dolt sql-client --use-db "repo1/feature-branch" -u dolt -P $PORT -q "CREATE TABLE test (
pk int,
c1 int,
PRIMARY KEY (pk)
@@ -759,7 +763,10 @@ SQL
[ $status -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
server_query "repo1/feature-branch" 1 dolt "" "SHOW Tables" "Tables_in_repo1/feature-branch\ntest"
run dolt sql-client --use-db "repo1/feature-branch" -u dolt -P $PORT -q "SHOW Tables"
[ $status -eq 0 ]
[[ $output =~ "feature-branch" ]] || false
[[ $output =~ "test" ]] || false
}
@test "sql-server: connect to a commit with connection string" {
@@ -779,13 +786,19 @@ SQL
# get the second-to-last commit hash
hash=`dolt log | grep commit | cut -d" " -f2 | tail -n+2 | head -n1`
server_query "repo1/$hash" 1 dolt "" "select count(*) from test" "count(*)\n3"
run dolt sql-client --use-db "repo1/$hash" -u dolt -P $PORT -q "select count(*) from test"
[ $status -eq 0 ]
[[ $output =~ " 3 " ]] || false
# fails
server_query "repo1/$hash" 1 dolt "" "insert into test values (7)" "" "read-only"
run dolt sql-client --use-db "repo1/$hash" -u dolt -P $PORT -q "insert into test values (7)"
[ $status -ne 0 ]
[[ $output =~ "read-only" ]] || false
# server should still be alive after an error
server_query "repo1/$hash" 1 dolt "" "select count(*) from test" "count(*)\n3"
run dolt sql-client --use-db "repo1/$hash" -u dolt -P $PORT -q "select count(*) from test"
[ $status -eq 0 ]
[[ $output =~ " 3 " ]] || false
}
@test "sql-server: SET GLOBAL default branch as ref" {
@@ -796,10 +809,10 @@ SQL
dolt checkout main
start_sql_server repo1
server_query repo1 1 dolt "" '
run dolt sql-client -P $PORT -u dolt --use-db repo1 -q '
CALL dolt_checkout("new");
CREATE TABLE t (a int primary key, b int);
INSERT INTO t VALUES (2,2),(3,3);' ""
INSERT INTO t VALUES (2,2),(3,3);'
run dolt sql-client -P $PORT -u dolt --use-db repo1 -q "SHOW Tables"
[ $status -eq 0 ]
@@ -825,10 +838,10 @@ SQL
dolt checkout main
start_sql_server repo1
server_query repo1 1 dolt "" '
run dolt sql-client -P $PORT -u dolt --use-db repo1 -q '
select dolt_checkout("new");
CREATE TABLE t (a int primary key, b int);
INSERT INTO t VALUES (2,2),(3,3);' ""
INSERT INTO t VALUES (2,2),(3,3);'
run dolt sql-client -P $PORT -u dolt --use-db repo1 -q "SHOW Tables"
[ $status -eq 0 ]
@@ -964,8 +977,12 @@ END""")
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "call dolt_commit('-am', 'table with two values')"
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "call dolt_branch('new_branch')"
server_query repo1/new_branch 1 dolt "" "INSERT INTO t1 (val) VALUES (3)"
server_query repo1/new_branch 1 dolt "" "SELECT * FROM t1" "pk,val\n1,1\n2,2\n3,3"
dolt sql-client --use-db repo1/new_branch -u dolt -P $PORT -q "INSERT INTO t1 (val) VALUES (3)"
run dolt sql-client --use-db repo1/new_branch -u dolt -P $PORT --result-format csv -q "SELECT * FROM t1"
[ $status -eq 0 ]
[[ $output =~ "1,1" ]] || false
[[ $output =~ "2,2" ]] || false
[[ $output =~ "3,3" ]] || false
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "INSERT INTO t1 (val) VALUES (4)"
run dolt sql-client -P $PORT -u dolt --use-db repo1 --result-format csv -q "SELECT * FROM t1"
@@ -1130,25 +1147,34 @@ END""")
dolt sql-client -P $PORT -u dolt --use-db test3 -q "call dolt_commit('-a', '-m', 'new table a')"
dolt sql-client -P $PORT -u dolt --use-db test1 -q "call dolt_branch('newbranch')"
# Something weird is going on here. This should not need an order by
server_query "test1/newbranch" 1 dolt "" "select * from a order by x" "x\n1\n2"
run dolt sql-client --use-db "test1/newbranch" -u dolt -P $PORT -q "select * from a"
[ $status -eq 0 ]
[[ $output =~ " 1 " ]] || false
[[ $output =~ " 2 " ]] || false
dolt sql-client -P $PORT -u dolt --use-db test2 -q "call dolt_branch('newbranch')"
server_query "test2/newbranch" 1 dolt "" "select * from a" "x\n3\n4"
run dolt sql-client --use-db "test2/newbranch" -u dolt -P $PORT -q "select * from a"
[ $status -eq 0 ]
[[ $output =~ " 3 " ]] || false
[[ $output =~ " 4 " ]] || false
# uppercase to ensure db names are treated case insensitive
dolt sql-client -P $PORT -u dolt --use-db '' -q "drop database TEST1"
run server_query "test1/newbranch" 1 dolt "" "select * from a" "" 1
run dolt sql-client --use-db "test1/newbranch" -u dolt -P $PORT -q "select * from a"
[ $status -ne 0 ]
[[ "$output" =~ "database not found" ]] || false
# can't drop a branch-qualified database name
run server_query "" 1 dolt "" "drop database \`test2/newbranch\`" "" 1
run dolt sql-client -P $PORT -u dolt --use-db '' -q "drop database \`test2/newbranch\`"
[ $status -ne 0 ]
[[ "$output" =~ "unable to drop revision database: test2/newbranch" ]] || false
dolt sql-client -P $PORT -u dolt --use-db '' -q "drop database TEST2"
run server_query "test2/newbranch" 1 dolt "" "select * from a" "" 1
run dolt sql-client --use-db "test2/newbranch" -u dolt -P $PORT -q "select * from a"
[ $status -ne 0 ]
echo $output
[[ "$output" =~ "database not found" ]] || false
run dolt sql-client -P $PORT -u dolt --use-db test3 -q "select * from a"
@@ -1170,18 +1196,22 @@ END""")
[[ $output =~ "mysql" ]] || false
[[ $output =~ "information_schema" ]] || false
[[ $output =~ "Test1" ]] || false
server_query "" 1 dolt "" "use test1; create table a(x int);"
server_query "" 1 dolt "" "use TEST1; insert into a values (1), (2);"
server_query "" 1 dolt "" "use test1; call dolt_add('.'); call dolt_commit('-a', '-m', 'new table a');"
server_query "" 1 dolt "" "use test1; call dolt_checkout('-b', 'newbranch');"
server_query "" 1 dolt "" "use \`TEST1/newbranch\`; select * from a order by x" ";x\n1\n2"
server_query "" 1 dolt "" "use \`test1/newbranch\`; select * from a order by x" ";x\n1\n2"
dolt sql-client -P $PORT -u dolt --use-db '' -q "use test1; create table a(x int);"
dolt sql-client -P $PORT -u dolt --use-db '' -q "use TEST1; insert into a values (1), (2);"
dolt sql-client -P $PORT -u dolt --use-db '' -q "use test1; call dolt_add('.'); call dolt_commit('-a', '-m', 'new table a');"
dolt sql-client -P $PORT -u dolt --use-db '' -q "use test1; call dolt_checkout('-b', 'newbranch');"
dolt sql-client -P $PORT -u dolt --use-db '' -q "use \`TEST1/newbranch\`; select * from a order by x" ";x\n1\n2"
dolt sql-client -P $PORT -u dolt --use-db '' -q "use \`test1/newbranch\`; select * from a order by x" ";x\n1\n2"
run dolt sql-client -P $PORT -u dolt --use-db '' -q "use \`TEST1/NEWBRANCH\`"
[ $status -ne 0 ]
[[ $output =~ "database not found: TEST1/NEWBRANCH" ]] || false
server_query "" 1 dolt "" "create database test2; use test2; select database();" ";;database()\ntest2"
server_query "" 1 dolt "" "use test2; drop database TEST2; select database();" ";;database()\nNone"
run dolt sql-client -P $PORT -u dolt --use-db '' -q "create database test2; use test2; select database();"
[ $status -eq 0 ]
[[ $output =~ "test2" ]] || false
run dolt sql-client -P $PORT -u dolt --use-db '' -q "use test2; drop database TEST2; select database();"
[ $status -eq 0 ]
[[ $output =~ "NULL" ]] || false
}
@test "sql-server: create and drop database with --data-dir" {