1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-01-06 08:01:16 +03:00

Disallow using the implicit rowid column as the parent key of an FK constraint.

FossilOrigin-Name: a5f7e71f424900071a3925e53e9128c9148ea2e8
This commit is contained in:
dan
2009-09-23 13:59:17 +00:00
parent 6f94702f20
commit d981d44781
4 changed files with 32 additions and 33 deletions

View File

@@ -1,8 +1,5 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Add\stest\scases\sfor\sthe\sIS\sand\sIS\sNOT\soperator.
D 2009-09-23T13:39:57
C Disallow\susing\sthe\simplicit\srowid\scolumn\sas\sthe\sparent\skey\sof\san\sFK\sconstraint.
D 2009-09-23T13:59:17
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 4ca3f1dd6efa2075bcb27f4dc43eef749877740d
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -119,7 +116,7 @@ F src/date.c 657ff12ca0f1195b531561afacbb38b772d16638
F src/delete.c 15499f5d10047d38e68ce991b3f88cbddb6e0931
F src/expr.c 8a663240f374a5326ee157df3d27751f58b7676a
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
F src/fkey.c 320b318d3131139424ad36514cb376d326920610
F src/fkey.c 9a0afe076ce51552ce00ab0f730213798bf75720
F src/func.c e536218d193b8d326aab91120bc4c6f28aa2b606
F src/global.c 271952d199a8cc59d4ce840b3bbbfd2f30c8ba32
F src/hash.c ebcaa921ffd9d86f7ea5ae16a0a29d1c871130a7
@@ -333,7 +330,7 @@ F test/expr.test 9f521ae22f00e074959f72ce2e55d46b9ed23f68
F test/filectrl.test 8923a6dc7630f31c8a9dd3d3d740aa0922df7bf8
F test/filefmt.test 84e3d0fe9f12d0d2ac852465c6f8450aea0d6f43
F test/fkey1.test 01c7de578e11747e720c2d9aeef27f239853c4da
F test/fkey2.test 24668ccff4a2dc3177cc3271ffcbed158d90adca
F test/fkey2.test 9f451a47695ee9c19772bd2107d9a3c788672b0f
F test/fkey_malloc.test a18bdb482c6a7b9a61865616a516584d17f04a04
F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7
@@ -756,14 +753,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 7d086afe69da4d03bd1de5408626858273f91e8f
R 35b5b657e12fcb3cbc987e191dc83216
U drh
Z e9ed2d16226d496aaa308a9dcf1b2040
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFKuiUwoxKgR168RlERAu8gAKCKUlvtbsebzIAVA2IzXEFkaTgAIACdF6N7
kr8Bdbz7nMMRJn6r4uB+tVc=
=gtYM
-----END PGP SIGNATURE-----
P 101ed58cf4a1dfe53031b98cfc7ed01e86b4c7b6
R b46a4f5afd3ba101cf0c76c3fa2edc83
U dan
Z 033b8b51f2009360e4a4d40c8021977a

View File

@@ -1 +1 @@
101ed58cf4a1dfe53031b98cfc7ed01e86b4c7b6
a5f7e71f424900071a3925e53e9128c9148ea2e8

View File

@@ -197,13 +197,11 @@ static int locateFkeyIndex(
if( nCol==1 ){
/* The FK maps to the IPK if any of the following are true:
**
** 1) The FK is explicitly mapped to "rowid", "oid" or "_rowid_", or
** 2) There is an explicit INTEGER PRIMARY KEY column and the FK is
** implicitly mapped to the primary key of table pParent, or
** 3) The FK is explicitly mapped to a column declared as INTEGER
** 1) There is an INTEGER PRIMARY KEY column and the FK is implicitly
** mapped to the primary key of table pParent, or
** 2) The FK is explicitly mapped to a column declared as INTEGER
** PRIMARY KEY.
*/
if( zKey && sqlite3IsRowid(zKey) ) return 0;
if( pParent->iPKey>=0 ){
if( !zKey ) return 0;
if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zName, zKey) ) return 0;

View File

@@ -81,9 +81,6 @@ set FkeySimpleSchema {
CREATE TABLE t3(a PRIMARY KEY, b);
CREATE TABLE t4(c REFERENCES t3 /D/, d);
CREATE TABLE t5(a INTEGER PRIMARY KEY, b);
CREATE TABLE t6(c REFERENCES t5(oid) /D/, d);
CREATE TABLE t7(a, b INTEGER PRIMARY KEY);
CREATE TABLE t8(c REFERENCES t7 /D/, d);
@@ -108,10 +105,6 @@ set FkeySimpleTests {
2.2 "INSERT INTO t3 VALUES(1, 2)" {0 {}}
2.3 "INSERT INTO t4 VALUES(1, 3)" {0 {}}
3.1 "INSERT INTO t6 VALUES(1, 3)" {1 {foreign key constraint failed}}
3.2 "INSERT INTO t5 VALUES(1, 2)" {0 {}}
3.3 "INSERT INTO t6 VALUES(1, 3)" {0 {}}
4.1 "INSERT INTO t8 VALUES(1, 3)" {1 {foreign key constraint failed}}
4.2 "INSERT INTO t7 VALUES(2, 1)" {0 {}}
4.3 "INSERT INTO t8 VALUES(1, 3)" {0 {}}
@@ -542,8 +535,8 @@ foreach zSql [list {
} {1 {foreign key mismatch}}
}
# "rowid" cannot be used as part of a child key definition unless it
# happens to be the name of an explicitly declared column.
# "rowid" cannot be used as part of a child or parent key definition
# unless it happens to be the name of an explicitly declared column.
#
do_test fkey2-10.2.1 {
drop_all_tables
@@ -559,6 +552,24 @@ do_test fkey2-10.2.2 {
CREATE TABLE t2(rowid, d, FOREIGN KEY(rowid) REFERENCES t1(a));
}
} {0 {}}
do_test fkey2-10.2.1 {
drop_all_tables
catchsql {
CREATE TABLE t1(a, b);
CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid));
INSERT INTO t1(rowid, a, b) VALUES(1, 1, 1);
INSERT INTO t2 VALUES(1, 1);
}
} {1 {foreign key mismatch}}
do_test fkey2-10.2.2 {
drop_all_tables
catchsql {
CREATE TABLE t1(rowid PRIMARY KEY, b);
CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid));
INSERT INTO t1(rowid, b) VALUES(1, 1);
INSERT INTO t2 VALUES(1, 1);
}
} {0 {}}
#-------------------------------------------------------------------------