From: dan Date: Mon, 17 Apr 2017 18:02:41 +0000 (+0000) Subject: Fix a problem in "PRAGMA foreign_key_check" in handling a WITHOUT ROWID child X-Git-Tag: version-3.19.0~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=940464b1dc501ab5fd0e8161e9cff6229af53733;p=thirdparty%2Fsqlite.git Fix a problem in "PRAGMA foreign_key_check" in handling a WITHOUT ROWID child table with an INTEGER PRIMARY KEY parent key. Also, if an FK violation is detected in a WITHOUT ROWID child table, do not try to read and return the rowid. The third column returned by "PRAGMA foreign_key_check" in this case (WITHOUT ROWID child table) is now always set to NULL. FossilOrigin-Name: 690870bd7b2e607b7992c4496c9f08c29eb72a36af002c606fd7aa3dcf94a2a4 --- diff --git a/manifest b/manifest index bffc8069fb..b80db914a6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\simprovements\sto\stest\scoverage\sin\sfts3. -D 2017-04-17T16:07:25.320 +C Fix\sa\sproblem\sin\s"PRAGMA\sforeign_key_check"\sin\shandling\sa\sWITHOUT\sROWID\schild\ntable\swith\san\sINTEGER\sPRIMARY\sKEY\sparent\skey.\sAlso,\sif\san\sFK\sviolation\sis\ndetected\sin\sa\sWITHOUT\sROWID\schild\stable,\sdo\snot\stry\sto\sread\sand\sreturn\sthe\nrowid.\sThe\sthird\scolumn\sreturned\sby\s"PRAGMA\sforeign_key_check"\sin\sthis\scase\n(WITHOUT\sROWID\schild\stable)\sis\snow\salways\sset\sto\sNULL. +D 2017-04-17T18:02:41.447 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6a8c838220f7c00820e1fc0ac1bccaaa8e5676067e1dbfa1bafa7a4ffecf8ae6 @@ -395,7 +395,7 @@ F src/parse.y 48b03113704ee8bd78ee6996d81de7fbee22e105 F src/pcache.c 62835bed959e2914edd26afadfecce29ece0e870 F src/pcache.h 2cedcd8407eb23017d92790b112186886e179490 F src/pcache1.c 1195a21fe28e223e024f900b2011e80df53793f0356a24caace4188b098540dc -F src/pragma.c 220474f113cade6a6b5bacd3e3a65eca339acbee804128bc5db13a9cad55fba5 +F src/pragma.c 943f71f762d8c7ab5a7b00641308cb9cd5effeddc3c709f0303e394ca8c21228 F src/pragma.h 37a1311d0388db480388d7ec09054f7103045eff20d4971f8a433b77f40b9921 F src/prepare.c b1140c3d0cf59bc85ace00ce363153041b424b7a F src/printf.c 8757834f1b54dae512fb25eb1acc8e94a0d15dd2290b58f2563f65973265adb2 @@ -708,7 +708,7 @@ F test/fkey1.test ba64806ff9a04eecab2679caad377ae99a5e94e4 F test/fkey2.test 155809016fad6b2a1491facf2ac53a551bc57c2c F test/fkey3.test 76d475c80b84ee7a5d062e56ccb6ea68882e2b49 F test/fkey4.test 86446017011273aad8f9a99c1a65019e7bd9ca9d -F test/fkey5.test 5a373303f201ac03c22ba1ef17a733d3f56e611a +F test/fkey5.test 67eac5be27ab6c80b1131ed7a060d0df5df748a0cb51600db495221a0e70b732 F test/fkey6.test d078a1e323a740062bed38df32b8a736fd320dc0 F test/fkey7.test 72e915890ee4a005daaf3002cb208e8fe973ac13 F test/fkey8.test e5372e32cdb4481f121ec3550703eeb7b4e0762c @@ -1575,8 +1575,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1a08a836fa919524216a16faf5212eebc9ad788c9e15463b68b0576dfccd4387 -Q +e00aa665903d2328bab3f192ad364e43d5d8483509671626d8ef5384b305557f -R e503b12d92602617090d73924f6d0603 +P 352413eed469802665e7d2c17b7fe6e3a0b0b2209ce45bdc85fd4243cec50ea6 +R 46f0a9ecba377acfe7b4e03c3b9e97dc U dan -Z 3da6b7e6b10076610ce2d669ba020b22 +Z a6a806ccfe0a8fddda7afe6e73d07801 diff --git a/manifest.uuid b/manifest.uuid index 0945f8bf91..fa5e7a216c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -352413eed469802665e7d2c17b7fe6e3a0b0b2209ce45bdc85fd4243cec50ea6 \ No newline at end of file +690870bd7b2e607b7992c4496c9f08c29eb72a36af002c606fd7aa3dcf94a2a4 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 7f0b683f13..45b190fbd8 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1333,8 +1333,8 @@ void sqlite3Pragma( int iKey = pFK->aCol[0].iFrom; assert( iKey>=0 && iKeynCol ); if( iKey!=pTab->iPKey ){ - sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow); - sqlite3ColumnDefault(v, pTab, iKey, regRow); + sqlite3ExprCodeGetColumnOfTable( + v, pTab, 0, pFK->aCol[0].iFrom, regRow); sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v); }else{ sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow); @@ -1355,7 +1355,11 @@ void sqlite3Pragma( VdbeCoverage(v); } } - sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1); + if( HasRowid(pTab) ){ + sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1); + }else{ + sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1); + } sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1); sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4); sqlite3VdbeResolveLabel(v, addrOk); diff --git a/test/fkey5.test b/test/fkey5.test index b9e1fc2eec..690983460d 100644 --- a/test/fkey5.test +++ b/test/fkey5.test @@ -388,5 +388,28 @@ do_execsql_test 9.4 { PRAGMA foreign_key_check(k2); } {k2 3 s1 0} +#------------------------------------------------------------------------- +# Test using a WITHOUT ROWID table as the child table with an INTEGER +# PRIMARY KEY as the parent key. +# +reset_db +do_execsql_test 10.1 { + CREATE TABLE p30 (id INTEGER PRIMARY KEY); + CREATE TABLE IF NOT EXISTS c30 ( + line INTEGER, + master REFERENCES p30(id), + PRIMARY KEY(master) + ) WITHOUT ROWID; + + INSERT INTO p30 (id) VALUES (1); + INSERT INTO c30 (master, line) VALUES (1, 999); +} +do_execsql_test 10.2 { + PRAGMA foreign_key_check; +} +do_execsql_test 10.3 { + INSERT INTO c30 VALUES(45, 45); + PRAGMA foreign_key_check; +} {c30 {} p30 0} finish_test