SQLite

Check-in [68db1ff9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:In the PRAGMA foreign_key_check, ensure that sufficient registers are allocated for the virtual machine, even if one or more foreign keys reuses the same column multiple times and has more columns than the table it is part of. Forum post a6b0c05277.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 68db1ff9c44fa9c37690ce55ad304d4263ba6fac490063d9e08470de6c17cfe6
User & Date: drh 2021-07-03 02:55:47
References
2021-07-07
16:48
Follow-up to [68db1ff9c44fa9c3]: The number of registers needed by PRAGMA foreign_key_check was increased too late for an assert() deep down inside of sqlite3ExprCode(). So move the size increase a little earlier. Forum post 79c9e4797d. (check-in: 7072404a user: drh tags: trunk)
Context
2021-07-03
19:20
Create infrastructure for dynamic shell extension. (check-in: 5e7e0d4e user: larrybr tags: cli_extension)
18:57
Fix a (harmless) typo in a comment. No code changes. (check-in: d2b9b8da user: drh tags: trunk)
02:55
In the PRAGMA foreign_key_check, ensure that sufficient registers are allocated for the virtual machine, even if one or more foreign keys reuses the same column multiple times and has more columns than the table it is part of. Forum post a6b0c05277. (check-in: 68db1ff9 user: drh tags: trunk)
2021-07-02
12:25
Put ALWAYS() on a branch that is always true due to [d4097364c511709b]. Fix a testcase precondition associated with the same check-in. (check-in: 55e2fbeb user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pragma.c.
1462
1463
1464
1465
1466
1467
1468

1469
1470
1471
1472
1473
1474
1475
        ** row cannot cause an FK violation. Jump directly to addrOk in 
        ** this case. */
        for(j=0; j<pFK->nCol; j++){
          int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
          sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
          sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
        }


        /* Generate code to query the parent index for a matching parent
        ** key. If a match is found, jump to addrOk. */
        if( pIdx ){
          sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
              sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
          sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);







>







1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
        ** row cannot cause an FK violation. Jump directly to addrOk in 
        ** this case. */
        for(j=0; j<pFK->nCol; j++){
          int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
          sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
          sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
        }
        if( regRow+j>pParse->nMem ) pParse->nMem = regRow+j;

        /* Generate code to query the parent index for a matching parent
        ** key. If a match is found, jump to addrOk. */
        if( pIdx ){
          sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
              sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
          sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
Changes to test/fkey1.test.
217
218
219
220
221
222
223













224
225
226
  INSERT INTO c1 VALUES(1);
} {1 {foreign key mismatch - "c1" referencing "p1"}}

do_execsql_test 6.2 {
  CREATE UNIQUE INDEX p1x2 ON p1(x);
  INSERT INTO c1 VALUES(1);
} {}















finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
  INSERT INTO c1 VALUES(1);
} {1 {foreign key mismatch - "c1" referencing "p1"}}

do_execsql_test 6.2 {
  CREATE UNIQUE INDEX p1x2 ON p1(x);
  INSERT INTO c1 VALUES(1);
} {}

# 2021-07-03 https://sqlite.org/forum/forumpost/a6b0c05277
# Failure to allocate enough registers in the VDBE for a
# PRAGMA foreign_key_check when the foreign key has more
# columns than the table.
#
reset_db
do_execsql_test 7.1 {
  PRAGMA foreign_keys=OFF;
  CREATE TABLE t1(a,b,c,FOREIGN KEY(a,a,a,a,a,a,a,a,a,a,a,a,a,a) REFERENCES t0);
  INSERT INTO t1 VALUES(1,2,3);
  PRAGMA foreign_key_check;
} {t1 1 t0 0}


finish_test