0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-05-03 08:02:15 +00:00

adjust ALTER COLUMN parsing ()

* add basic TCL tests for ALTER COLUMN libsql feature

* propagate length of the new column definition directly from the parser

- this will allow libsql to automatically handle comment and space characters appended to the column definition

* small formatting fixes

* cargo xtask build-bundled

* add test against sqlite3 source in rust_suite

* fix test in rust_suite
This commit is contained in:
Sivukhin Nikita
2024-07-03 02:02:14 +04:00
committed by GitHub
parent b988125ec0
commit b17b6ee0d4
6 changed files with 92 additions and 22 deletions
libsql-ffi/bundled/src
libsql-sqlite3

@ -0,0 +1,54 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Test Organisation:
# ------------------
#
# libsql_alter-ok.*: Test that ALTER COLUMN correctly modifies the CREATE TABLE sql.
# libsql_alter-err.*: Test error messages.
#
do_test libsql_alter-ok.1 {
execsql {CREATE TABLE t1(x);}
execsql {ALTER TABLE t1 ALTER COLUMN x TO x;}
execsql {SELECT sql FROM sqlite_master WHERE tbl_name = 't1';}
} {{CREATE TABLE t1(x)}}
do_test libsql_alter-ok.2 {
execsql {CREATE TABLE t2(x);}
execsql {ALTER TABLE t2 ALTER COLUMN x TO x INTEGER DEFAULT(-1);}
execsql {SELECT sql FROM sqlite_master WHERE tbl_name = 't2';}
} {{CREATE TABLE t2(x INTEGER DEFAULT(-1))}}
do_test libsql_alter-ok.3 {
execsql {CREATE TABLE t3(x);}
# NOTE: extra spaces in the end of ALTER COLUMN command
execsql { ALTER TABLE t3 ALTER COLUMN x TO x INTEGER DEFAULT(-1); }
execsql {SELECT sql FROM sqlite_master WHERE tbl_name = 't3';}
} {{CREATE TABLE t3(x INTEGER DEFAULT(-1))}}
do_test libsql_alter-ok.4 {
execsql {CREATE TABLE t4(x);}
execsql { ALTER TABLE t4 ALTER COLUMN x TO x INTEGER DEFAULT(-1); -- explain alter command }
execsql {SELECT sql FROM sqlite_master WHERE tbl_name = 't4';}
} {{CREATE TABLE t4(x INTEGER DEFAULT(-1))}}
reset_db
do_test libsql_alter-err.1 {
execsql { CREATE TABLE t1(x); }
catchsql { ALTER TABLE t1 ALTER COLUMN x TO x PRIMARY KEY; }
} {1 {error in adding x PRIMARY KEY to t1: PRIMARY KEY constraint cannot be altered}}
do_test libsql_alter-err.2 {
execsql { CREATE TABLE t2(x); }
catchsql { ALTER TABLE t2 ALTER COLUMN x TO x INTEGER UNIQUE; }
} {1 {error in adding x INTEGER UNIQUE to t2: UNIQUE constraint cannot be altered}}
do_test libsql_alter-err.3 {
execsql { CREATE TABLE t3(x, y); }
catchsql { ALTER TABLE t3 ALTER COLUMN y TO y GENERATED ALWAYS AS (2 * x) VIRTUAL; }
} {1 {error in adding y GENERATED ALWAYS AS (2 * x) VIRTUAL to t3: GENERATED constraint cannot be altered}}
finish_test

@ -184,3 +184,15 @@ fn test_update_view_forbidden() {
.execute("ALTER TABLE v ALTER COLUMN id TO id", ())
.is_err());
}
#[test]
fn test_comment_in_the_end() {
let conn = Connection::open_in_memory().unwrap();
conn.execute("CREATE TABLE t(id)", ()).unwrap();
conn.execute(
"ALTER TABLE t ALTER COLUMN id TO id CHECK(id < 5); -- explanation for alter command ",
(),
)
.unwrap();
}