From: dan Date: Mon, 29 Sep 2025 16:49:55 +0000 (+0000) Subject: Add further tests for the new ALTER TABLE commands on this branch. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d7330b571ddc224994f34c0878a3dbde790637ae;p=thirdparty%2Fsqlite.git Add further tests for the new ALTER TABLE commands on this branch. FossilOrigin-Name: 17a6f4e69e54a5dc233e33501f16f0f69f77fff071142cefc309b5407f57f721 --- diff --git a/manifest b/manifest index 50d983ce75..62a05ff1f5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stest\scases\sfor\sALTER\sTABLE\sand\sattached\sdatabases. -D 2025-09-27T19:17:08.692 +C Add\sfurther\stests\sfor\sthe\snew\sALTER\sTABLE\scommands\son\sthis\sbranch. +D 2025-09-29T16:49:55.217 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -670,7 +670,7 @@ F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 1b9c24374a85dfc7eb8fa7c4266ee0db4f9609cceecfc5481cd8307e5af04366 F sqlite3.pc.in e6dee284fba59ef500092fdc1843df3be8433323a3733c91da96690a50a5b398 -F src/alter.c d32bca69055d6b8cacc0cd20452aa15f9b815b4b20d4a81bc6f4c9a2d98cf14f +F src/alter.c 875b85a0306968cfb811650d1c994bf65cf3112a521717d058e363705853a4a6 F src/analyze.c 03bcfc083fc0cccaa9ded93604e1d4244ea245c17285d463ef6a60425fcb247d F src/attach.c 9af61b63b10ee702b1594ecd24fb8cea0839cfdb6addee52fba26fa879f5db9d F src/auth.c 54ab9c6c5803b47c0d45b76ce27eff22a03b4b1f767c5945a3a4eb13aa4c78dc @@ -839,11 +839,12 @@ F test/alter4.test 37cafe164067a6590a0ee4cec780bddbbaa33dc50b11542dcfbe0e6562649 F test/alterauth.test 63442ba61ceb0c1eeb63aac1f4f5cebfa509d352276059d27106ae256bafc959 F test/alterauth2.test 4b74fa8f184f4736497317feb587b65759eb87d87acfe3a8ef433d4d18bb002b F test/altercol.test b43fb5725332f4cf8cff0280605202c1672e808281accea60a066d2ccc5129e5 -F test/altercons.test 0d6fe564b65a1ed36564c2d3ffd99de92dc5d1abc4391806637b0772caaed77c +F test/altercons.test ac50608f34171021e67c5f2cbd9615a9fbf181804b84817d7a35e2cd89fbeb7d +F test/altercons2.test 9adc4e742655d2e55e38f507bd97dc1cd48bc91aa26b59bd3518fd2184a58114 F test/altercorrupt.test 2e1d705342cf9d7de884518ddbb053fd52d7e60d2b8869b7b63b2fda68435c12 F test/alterdropcol.test a653a3945f964d26845ec0cd0a8e74189f46de3119a984c5bc45457da392612e F test/alterdropcol2.test 527fce683b200d620f560f666c44ae33e22728e990a10a48a543280dfd4b4d41 -F test/alterfault.test 8ba6044ce2ad8b3317e7d8228398aae253f16e5387a3f8b0b67cf7d8acfd6425 +F test/alterfault.test 9baff95be91ad77e955701454fa9e4bdd8c94f7fe6e814939962d3d5efb83220 F test/alterlegacy.test f38c6d06cda39e1f7b955bbce57f2e3ef5b7cb566d3d1234502093e228c15811 F test/altermalloc.test 167a47de41b5c638f5f5c6efb59784002b196fff70f98d9b4ed3cd74a3fb80c9 F test/altermalloc2.test 17fb3724c4b004c469c27dc4ef181608aa644555fbd3f3236767584f73747c81 @@ -2170,8 +2171,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 34b47c9b1be8a6ead917c6e9a85f8a295b14640cde177d8f1384b15f8bc692bb -R d2caa87b8c36831673e0953b3d0f88d4 +P 8f2e066e9a0a34fe7a41b153c0fb54b621128b2195141cc454a44180c969b4a9 +R 7160ac4e86f1b04a352a7675b4a73b19 U dan -Z 9b0b3eab4eaaea4032a0321b3993a0ad +Z 729e8deb8af33990459f24e581d10a3d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index af54f15384..58c18efa7a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8f2e066e9a0a34fe7a41b153c0fb54b621128b2195141cc454a44180c969b4a9 +17a6f4e69e54a5dc233e33501f16f0f69f77fff071142cefc309b5407f57f721 diff --git a/src/alter.c b/src/alter.c index 541324939b..ac44db60bf 100644 --- a/src/alter.c +++ b/src/alter.c @@ -2798,7 +2798,6 @@ void sqlite3AlterSetNotNull( /* Find the length in bytes of the constraint definition */ pCons = pFirst->z; nCons = pParse->sLastToken.z - pCons; - if( pCons[nCons-1]==';' ) nCons--; while( sqlite3Isspace(pCons[nCons-1]) ) nCons--; /* Search for a constraint violation. Throw an exception if one is found. */ @@ -2907,7 +2906,6 @@ void sqlite3AlterAddConstraint( /* Edit the SQL for the named table. */ nCons = pParse->sLastToken.z - pFirst->z; - if( pFirst->z[nCons-1]==';' ) nCons--; while( sqlite3Isspace(pFirst->z[nCons-1]) ) nCons--; sqlite3NestedParse(pParse, "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " diff --git a/test/altercons.test b/test/altercons.test index 342ab913f8..be08c939df 100644 --- a/test/altercons.test +++ b/test/altercons.test @@ -42,6 +42,21 @@ foreach {tn before after} { 6 { CREATE TABLE t1(a, b,CONSTRAINT abc CHECK(t1.a != t1.b),PRIMARY KEY(a))} { CREATE TABLE t1(a, b,PRIMARY KEY(a)) } + 7 { CREATE TABLE t1(a, b CONSTRAINT abc CHECK(t1.a != t1.b) CONSTRAINT def UNIQUE) } + { CREATE TABLE t1(a, b CONSTRAINT def UNIQUE) } + + 8 { CREATE TABLE t1(a, b CONSTRAINT abc CHECK(t1.a != t1.b) CHECK (123)) } + { CREATE TABLE t1(a, b CHECK (123)) } + + 9 { CREATE TABLE t1(a, b CONSTRAINT abc CHECK(t1.a != t1.b) DEFAULT NULL) } + { CREATE TABLE t1(a, b DEFAULT NULL) } + + 10 { CREATE TABLE t1(a, b CONSTRAINT abc CHECK(t1.a != t1.b) COLLATE nocase) } + { CREATE TABLE t1(a, b COLLATE nocase) } + + 11 { CREATE TABLE t1(a, b CONSTRAINT abc CHECK(t1.a != t1.b) REFERENCES t2) } + { CREATE TABLE t1(a, b REFERENCES t2) } + } { reset_db @@ -91,6 +106,12 @@ foreach {tn col before after} { 7 b { CREATE TABLE t1(a, b NOT NULL PRIMARY KEY) } { CREATE TABLE t1(a, b PRIMARY KEY) } + + 8 b { CREATE TABLE t1(a, b CHECK ((b+a) IS NOT NULL) NOT NULL PRIMARY KEY) } + { CREATE TABLE t1(a, b CHECK ((b+a) IS NOT NULL) PRIMARY KEY) } + + 9 b { CREATE TABLE t1(a, b CONSTRAINT nn CHECK (b IS NOT NULL) NOT NULL) } + { CREATE TABLE t1(a, b CONSTRAINT nn CHECK (b IS NOT NULL)) } } { reset_db diff --git a/test/altercons2.test b/test/altercons2.test new file mode 100644 index 0000000000..e08619efa9 --- /dev/null +++ b/test/altercons2.test @@ -0,0 +1,112 @@ +# 2025 September 18 +# +# 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 altercons2 + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +foreach {tn newsql alter res final} { + 1 "CREATE TABLE t1(a, b" + "ALTER TABLE t1 ALTER c SET NOT NULL" + {1 {database disk image is malformed}} + "CREATE TABLE t1(a, b" + + 2 "CREATE TABLE t1(a, b, " + "ALTER TABLE t1 ALTER c DROP NOT NULL" + {0 {}} + "CREATE TABLE t1(a, b, " + + 3 "CREATE TABLE t1(a, b, CHECK( ..." + "ALTER TABLE t1 ALTER c DROP NOT NULL" + {0 {}} + "CREATE TABLE t1(a, b, CHECK( ..." + + 4 "CREATE TABLE t1(a, b, c NOT NULL" + "ALTER TABLE t1 ALTER c DROP NOT NULL" + {0 {}} + "CREATE TABLE t1(a, b, c " + + 5 "CREATE TABLE" + "ALTER TABLE t1 ALTER c DROP NOT NULL" + {1 {database disk image is malformed}} + "CREATE TABLE" + + 6 "CREATE TABLE" + "ALTER TABLE t1 ADD CONSTRAINT nn CHECK (a!=0)" + {1 {database disk image is malformed}} + "CREATE TABLE" + +} { + reset_db + do_execsql_test 1.$tn.0 { + CREATE TABLE t1(a, b, c NOT NULL, CONSTRAINT xyz CHECK( a!=0 )); + } + do_execsql_test 1.$tn.1 { + PRAGMA writable_schema = 1; + UPDATE sqlite_schema SET sql = $::newsql + } + do_catchsql_test 1.$tn.2 $alter $res + + do_execsql_test 1.$tn.3 { + SELECT sql FROM sqlite_schema WHERE name='t1' + } [list $final] +} + +#------------------------------------------------------------------------- + +reset_db +proc xAuth {t args} { + if {$t=="SQLITE_ALTER_TABLE"} { + return "SQLITE_DENY" + } + return "SQLITE_OK" +} +sqlite3 db test.db +db auth xAuth + +do_execsql_test 2.0 { + CREATE TABLE x1(a PRIMARY KEY, b CHECK(a!=b) NOT NULL, c); +} + +do_catchsql_test 2.1.1 { + ALTER TABLE x1 ADD CONSTRAINT ccc CHECK (a!='a') +} {1 {not authorized}} +do_execsql_test 2.1.2 { + SELECT sql FROM sqlite_schema WHERE name='x1' +} {{CREATE TABLE x1(a PRIMARY KEY, b CHECK(a!=b) NOT NULL, c)}} + +do_catchsql_test 2.2.1 { + ALTER TABLE x1 ALTER c SET NOT NULL +} {1 {not authorized}} +do_execsql_test 2.2.2 { + SELECT sql FROM sqlite_schema WHERE name='x1' +} {{CREATE TABLE x1(a PRIMARY KEY, b CHECK(a!=b) NOT NULL, c)}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(x); +} + +breakpoint +do_execsql_test 3.1 { + ALTER TABLE t1 ALTER x SET NOT NULL; +} + +finish_test + diff --git a/test/alterfault.test b/test/alterfault.test index d20d198616..cb10a33669 100644 --- a/test/alterfault.test +++ b/test/alterfault.test @@ -58,4 +58,18 @@ foreach {tn sql} { } } +# Test an OOM when returning an error. +# +do_faultsim_test 2.e -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + ALTER TABLE x1 DROP CONSTRAINT nosuchconstraint + } +} -test { + faultsim_test_result \ + {1 {no such constraint: nosuchconstraint}} \ + {1 {SQL logic error}} +} + finish_test