mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add experimental implementation of ALTER TABLE DROP COLUMN. Only some cases work so far.
FossilOrigin-Name: f0217937d7306fb595727e61e871e8b03d8c881d339a0865bfd0117d90d42e4e
This commit is contained in:
113
test/alterdropcol.test
Normal file
113
test/alterdropcol.test
Normal file
@ -0,0 +1,113 @@
|
||||
# 2021 February 16
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix alterdropcol
|
||||
|
||||
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
|
||||
ifcapable !altertable {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a, b, c);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
|
||||
CREATE TABLE t2(x INTEGER PRIMARY KEY, y, z UNIQUE);
|
||||
CREATE INDEX t2y ON t2(y);
|
||||
}
|
||||
|
||||
do_catchsql_test 1.1 {
|
||||
ALTER TABLE nosuch DROP COLUMN z;
|
||||
} {1 {no such table: nosuch}}
|
||||
|
||||
do_catchsql_test 1.2 {
|
||||
ALTER TABLE v1 DROP COLUMN c;
|
||||
} {1 {cannot drop a column from a view}}
|
||||
|
||||
ifcapable fts5 {
|
||||
do_execsql_test 1.3.1 {
|
||||
CREATE VIRTUAL TABLE ft1 USING fts5(one, two);
|
||||
}
|
||||
do_catchsql_test 1.3.2 {
|
||||
ALTER TABLE ft1 DROP COLUMN two;
|
||||
} {1 {virtual tables may not be altered}}
|
||||
}
|
||||
|
||||
do_catchsql_test 1.4 {
|
||||
ALTER TABLE sqlite_schema DROP COLUMN sql;
|
||||
} {1 {table sqlite_master may not be altered}}
|
||||
|
||||
do_catchsql_test 1.5 {
|
||||
ALTER TABLE t1 DROP COLUMN d;
|
||||
} {1 {no such column: "d"}}
|
||||
|
||||
do_execsql_test 1.6.1 {
|
||||
ALTER TABLE t1 DROP COLUMN b;
|
||||
}
|
||||
do_execsql_test 1.6.2 {
|
||||
SELECT sql FROM sqlite_schema WHERE name = 't1'
|
||||
} {{CREATE TABLE t1(a, c)}}
|
||||
|
||||
do_execsql_test 1.7.1 {
|
||||
ALTER TABLE t1 DROP COLUMN c;
|
||||
}
|
||||
do_execsql_test 1.7.2 {
|
||||
SELECT sql FROM sqlite_schema WHERE name = 't1'
|
||||
} {{CREATE TABLE t1(a)}}
|
||||
|
||||
|
||||
do_catchsql_test 1.8 {
|
||||
ALTER TABLE t2 DROP COLUMN z
|
||||
} {1 {cannot drop UNIQUE column: "z"}}
|
||||
|
||||
do_catchsql_test 1.9 {
|
||||
ALTER TABLE t2 DROP COLUMN x
|
||||
} {1 {cannot drop PRIMARY KEY column: "x"}}
|
||||
|
||||
do_catchsql_test 1.10 {
|
||||
ALTER TABLE t2 DROP COLUMN y
|
||||
} {1 {cannot drop indexed column: "y"}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
foreach {tn wo} {
|
||||
1 {}
|
||||
2 {WITHOUT ROWID}
|
||||
} { eval [string map [list %TN% $tn %WO% $wo] {
|
||||
|
||||
reset_db
|
||||
do_execsql_test 2.%TN%.0 {
|
||||
CREATE TABLE t1(x, y INTEGER PRIMARY KEY, z) %WO% ;
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t1 VALUES(4, 5, 6);
|
||||
INSERT INTO t1 VALUES(7, 8, 9);
|
||||
}
|
||||
|
||||
do_execsql_test 2.%TN%.1 {
|
||||
ALTER TABLE t1 DROP COLUMN x;
|
||||
SELECT * FROM t1;
|
||||
} {
|
||||
2 3 5 6 8 9
|
||||
}
|
||||
do_execsql_test 2.%TN%.2 {
|
||||
ALTER TABLE t1 DROP COLUMN z;
|
||||
SELECT * FROM t1;
|
||||
} {
|
||||
2 5 8
|
||||
}
|
||||
}]}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user