SQLite

Check-in [77b1c90a]
Login

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

Overview
Comment:Fix the handling of NOT NULL constraint violations for generated columns in a REPLACE statement. Ticket [2399f5986134f79c]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 77b1c90add514050fe62f22751362fecacd99f9775346cffc60e09c326e64e10
User & Date: drh 2019-11-06 14:49:43
Context
2019-11-06
17:31
Fix the OP_DeferredSeek index-to-table column map in P4 so that it works with generated columns. Ticket [ce22a07731530118] (check-in: 36c11ad5 user: drh tags: trunk)
14:49
Fix the handling of NOT NULL constraint violations for generated columns in a REPLACE statement. Ticket [2399f5986134f79c] (check-in: 77b1c90a user: drh tags: trunk)
2019-11-04
12:49
Changes an unreachable testcase() into an assert(). (check-in: 5710845b user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/insert.c.

1514
1515
1516
1517
1518
1519
1520

1521
1522
1523

1524
1525
1526
1527
1528
1529
1530
      iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1;
      switch( onError ){
        case OE_Replace: {
          assert( onError==OE_Replace );
          addr1 = sqlite3VdbeMakeLabel(pParse);
          sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1);
            VdbeCoverage(v);

          sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
          sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1);
            VdbeCoverage(v);

          onError = OE_Abort;
          /* Fall through into the OE_Abort case to generate code that runs
          ** if both the input and the default value are NULL */
        }
        case OE_Abort:
          sqlite3MayAbort(pParse);
          /* Fall through */







>
|
|
|
>







1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
      iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1;
      switch( onError ){
        case OE_Replace: {
          assert( onError==OE_Replace );
          addr1 = sqlite3VdbeMakeLabel(pParse);
          sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1);
            VdbeCoverage(v);
          if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ){
            sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
            sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1);
              VdbeCoverage(v);
          }
          onError = OE_Abort;
          /* Fall through into the OE_Abort case to generate code that runs
          ** if both the input and the default value are NULL */
        }
        case OE_Abort:
          sqlite3MayAbort(pParse);
          /* Fall through */

Changes to test/gencol1.test.

201
202
203
204
205
206
207






208
  INSERT INTO t1a VALUES(1, 1);
  INSERT INTO t1a VALUES(2, 4);
  INSERT INTO t1a VALUES(3, 7);
  DELETE FROM t1 WHERE b=5;
  SELECT id,x,'|' FROM t1a ORDER BY id;
} {1 1 | 3 7 |}  







finish_test







>
>
>
>
>
>

201
202
203
204
205
206
207
208
209
210
211
212
213
214
  INSERT INTO t1a VALUES(1, 1);
  INSERT INTO t1a VALUES(2, 4);
  INSERT INTO t1a VALUES(3, 7);
  DELETE FROM t1 WHERE b=5;
  SELECT id,x,'|' FROM t1a ORDER BY id;
} {1 1 | 3 7 |}  

do_catchsql_test gencol1-6.10 {
  DROP TABLE IF EXISTS t0;
  CREATE TABLE t0(c0 NOT NULL AS(c1), c1);
  REPLACE INTO t0(c1) VALUES(NULL);
} {1 {NOT NULL constraint failed: t0.c0}}

finish_test