mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Fix the preupdate hook so that it works when the "old.*" row has a column with a non-NULL default value that was added by ALTER TABLE ADD COLUMN after the current record was created.
FossilOrigin-Name: 00a398cf900179aa5a8aab09fe4a671d99e7a31583282848ef39390f2ef246eb
This commit is contained in:
@ -706,11 +706,13 @@ ifcapable altertable {
|
||||
}
|
||||
}
|
||||
|
||||
if 0 {
|
||||
if 1 {
|
||||
# At time of writing, these two are broken. They demonstrate that the
|
||||
# sqlite3_preupdate_old() method does not handle the case where ALTER TABLE
|
||||
# has been used to add a column with a default value other than NULL.
|
||||
#
|
||||
# 2024-09-18: These are now fixed.
|
||||
#
|
||||
do_preupdate_test 7.5.2.1 {
|
||||
DELETE FROM t8 WHERE a = 'one'
|
||||
} {
|
||||
@ -1022,4 +1024,37 @@ do_catchsql_test 12.6 {
|
||||
INSERT INTO t4 VALUES('def', 3);
|
||||
} {1 {UNIQUE constraint failed: t4.a}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test adding non-NULL default values using ALTER TABLE.
|
||||
#
|
||||
reset_db
|
||||
db preupdate hook preupdate_hook
|
||||
do_execsql_test 13.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY);
|
||||
INSERT INTO t1 VALUES(100), (200), (300), (400);
|
||||
}
|
||||
|
||||
do_execsql_test 13.1 {
|
||||
ALTER TABLE t1 ADD COLUMN b DEFAULT 1234;
|
||||
ALTER TABLE t1 ADD COLUMN c DEFAULT 'abcdef';
|
||||
ALTER TABLE t1 ADD COLUMN d DEFAULT NULL;
|
||||
}
|
||||
|
||||
do_preupdate_test 13.2 {
|
||||
DELETE FROM t1 WHERE a=300
|
||||
} {DELETE main t1 300 300 0 300 1234 abcdef {}}
|
||||
|
||||
do_preupdate_test 13.3 {
|
||||
UPDATE t1 SET d='hello world' WHERE a=200
|
||||
} {
|
||||
UPDATE main t1 200 200 0 200 1234 abcdef {}
|
||||
200 1234 abcdef {hello world}
|
||||
}
|
||||
|
||||
do_preupdate_test 13.4 {
|
||||
INSERT INTO t1 DEFAULT VALUES;
|
||||
} {
|
||||
INSERT main t1 401 401 0 401 1234 abcdef {}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user