mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-30 19:09:34 -06:00
82 lines
2.1 KiB
Bash
82 lines
2.1 KiB
Bash
#!/usr/bin/env bats
|
|
load $BATS_TEST_DIRNAME/helper/common.bash
|
|
|
|
setup() {
|
|
setup_common
|
|
dolt sql <<SQL
|
|
CREATE TABLE test (
|
|
pk BIGINT NOT NULL COMMENT 'tag:0',
|
|
c1 BIGINT COMMENT 'tag:1',
|
|
c2 BIGINT COMMENT 'tag:2',
|
|
c3 BIGINT COMMENT 'tag:3',
|
|
c4 BIGINT COMMENT 'tag:4',
|
|
c5 BIGINT COMMENT 'tag:5',
|
|
PRIMARY KEY (pk)
|
|
);
|
|
SQL
|
|
}
|
|
|
|
teardown() {
|
|
teardown_common
|
|
}
|
|
|
|
@test "dolt sql -b and -batch are a valid commands" {
|
|
run dolt sql -b -q "insert into test values (0,0,0,0,0,0)"
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ "Rows inserted: 1" ]] || false
|
|
dolt sql -batch -q "insert into test values (1,0,0,0,0,0)"
|
|
run dolt sql -b -q "select * from test"
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ " 0 " ]] || false
|
|
[[ "$output" =~ " 1 " ]] || false
|
|
|
|
# check for trailing newline
|
|
# https://backreference.org/2010/05/23/sanitizing-files-with-no-trailing-newline/
|
|
dolt sql -batch -q "insert into test values (2,0,0,0,0,0)" > out.txt
|
|
lastline=$(tail -n 1 out.txt; echo x)
|
|
lastline=${lastline%x}
|
|
[[ $lastline =~ $'\n'$ ]] || false
|
|
}
|
|
|
|
@test "Piped SQL files interpreted in batch mode" {
|
|
run dolt sql <<SQL
|
|
insert into test values (0,0,0,0,0,0);
|
|
insert into test values (1,0,0,0,0,0);
|
|
SQL
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ "Rows inserted: 2" ]] || false
|
|
}
|
|
|
|
@test "Line number and bad query displayed on error in batch sql" {
|
|
run dolt sql <<SQL
|
|
insert into test values (0,0,0,0,0,0);
|
|
insert into test values (1,0,0,0,0,0);
|
|
insert into test values poop;
|
|
SQL
|
|
[ "$status" -ne 0 ]
|
|
[[ "$output" =~ "Error processing batch" ]] || false
|
|
[[ "$output" =~ "error on line 3 for query" ]] || false
|
|
[[ "$output" =~ "insert into test values poop" ]] || false
|
|
|
|
run dolt sql <<SQL
|
|
insert into test values (0,0,0,0,0,0);
|
|
|
|
insert into test values (1,0,
|
|
0,0,0,0);
|
|
|
|
insert into
|
|
test values (2,0,0,0,0,0)
|
|
;
|
|
|
|
insert into
|
|
test values
|
|
poop;
|
|
|
|
insert into test values (3,0,0,0,0,0);
|
|
SQL
|
|
[ "$status" -ne 0 ]
|
|
[[ "$output" =~ "Error processing batch" ]] || false
|
|
[[ "$output" =~ "error on line 10 for query" ]] || false
|
|
[[ "$output" =~ "poop" ]] || false
|
|
}
|