/ Check-in [7072404a]
Login

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

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7072404ad0267b8ee774b2804ea59ea28e29316521d76d76a701595e51d1be97
User & Date: drh 2021-07-07 16:48:24
Context
2021-07-07
19:40
Fix a harmless compiler warning - duplicate local variable named "pRHS". (check-in: 5bc05faf user: drh tags: trunk)
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)
15:52
Fix a recently introduced segfault that might occur if a sub-select were used as a term on the RHS of an IN(...) operator for which the LHS is a row-value. (check-in: f586c06a user: dan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

1457
1458
1459
1460
1461
1462
1463

1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
        }
        addrOk = sqlite3VdbeMakeLabel(pParse);

        /* Generate code to read the child key values into registers
        ** regRow..regRow+n. If any of the child key values are NULL, this 
        ** 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);







>





<







1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469

1470
1471
1472
1473
1474
1475
1476
        }
        addrOk = sqlite3VdbeMakeLabel(pParse);

        /* Generate code to read the child key values into registers
        ** regRow..regRow+n. If any of the child key values are NULL, this 
        ** row cannot cause an FK violation. Jump directly to addrOk in 
        ** this case. */
        if( regRow+pFK->nCol>pParse->nMem ) pParse->nMem = regRow+pFK->nCol;
        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);

Changes to test/fkey1.test.

219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235
236





237
238
239

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







>











>
>
>
>
>



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245

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
# 2021-07-07 https://sqlite.org/forum/forumpost/79c9e4797d
# 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}
do_execsql_test 7.2 {
  DROP TABLE t1;
  CREATE TABLE t1(a,b,c AS(1),d, FOREIGN KEY(c,d,b,a,b,d,b,c) REFERENCES t0);
  PRAGMA foreign_key_check;
} {}


finish_test