SQLite

Check-in [a2449bcc2c]
Login

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

Overview
Comment:Ensure the RETURNING clause is honoured when a row of a temp table is updated by an ON CONFLICT clause.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a2449bcc2c71d0f4c3289621fbf1cb97f0f407c9f7b5bf18245b7854a07c6cfa
User & Date: dan 2022-11-28 13:47:27.194
References
2023-10-26
12:59
Deal with the case of a reentrant INSERT on a virtual table where the outer INSERT has a RETURNING clause but the inner does not. dbsqlfuzz 3ac9a1e33f676254e02c0f297263b0a7aeb0c1a5. Fault injected by [a2449bcc2c71d0f4], first appearing in release 3.40.1. (check-in: 8aba78e4db user: drh tags: trunk)
Context
2022-12-26
16:24
Ensure the RETURNING clause is honoured when a row of a temp table is updated by an ON CONFLICT clause. (check-in: ac9568cf87 user: drh tags: branch-3.40)
2022-11-28
14:51
Add (optional) base64 and base85 UDF extensions. (check-in: b44ab10c49 user: larrybr tags: trunk)
14:11
Sync w/trunk, zap surplus space. (Closed-Leaf check-in: b8345630a2 user: larrybr tags: base_convert)
13:47
Ensure the RETURNING clause is honoured when a row of a temp table is updated by an ON CONFLICT clause. (check-in: a2449bcc2c user: dan tags: trunk)
02:28
Conform CLI .trace arg handling to its help. (check-in: 31546ea320 user: larrybr tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/trigger.c.
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  p = sqliteHashFirst(&pTmpSchema->trigHash);
  pList = pTab->pTrigger;
  while( p ){
    Trigger *pTrig = (Trigger *)sqliteHashData(p);
    if( pTrig->pTabSchema==pTab->pSchema
     && pTrig->table
     && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
     && pTrig->pTabSchema!=pTmpSchema
    ){
      pTrig->pNext = pList;
      pList = pTrig;
    }else if( pTrig->op==TK_RETURNING ){
#ifndef SQLITE_OMIT_VIRTUALTABLE
      assert( pParse->db->pVtabCtx==0 );
#endif







|







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  p = sqliteHashFirst(&pTmpSchema->trigHash);
  pList = pTab->pTrigger;
  while( p ){
    Trigger *pTrig = (Trigger *)sqliteHashData(p);
    if( pTrig->pTabSchema==pTab->pSchema
     && pTrig->table
     && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
     && (pTrig->pTabSchema!=pTmpSchema || pTrig->bReturning)
    ){
      pTrig->pNext = pList;
      pList = pTrig;
    }else if( pTrig->op==TK_RETURNING ){
#ifndef SQLITE_OMIT_VIRTUALTABLE
      assert( pParse->db->pVtabCtx==0 );
#endif
Changes to test/returning1.test.
371
372
373
374
375
376
377
























378
379
  INSERT INTO t1 VALUES(1,2,3),('a','b','c');
  CREATE TEMP TABLE t2(x,y,z);
  INSERT INTO t2 SELECT * FROM t1 RETURNING *;
} {1 2 3 a b c}
do_execsql_test 16.1 {
  SELECT * FROM t2;
} {1 2 3 a b c}

























finish_test







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


371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
  INSERT INTO t1 VALUES(1,2,3),('a','b','c');
  CREATE TEMP TABLE t2(x,y,z);
  INSERT INTO t2 SELECT * FROM t1 RETURNING *;
} {1 2 3 a b c}
do_execsql_test 16.1 {
  SELECT * FROM t2;
} {1 2 3 a b c}


foreach {tn temp} {
  1 ""
  2 TEMP
} {
  reset_db
  do_execsql_test 17.$tn.0 "
    CREATE $temp TABLE foo (
      fooid INTEGER PRIMARY KEY,
      fooval INTEGER NOT NULL UNIQUE,
      refcnt INTEGER NOT NULL DEFAULT 1
    );
  "
  do_execsql_test 17.$tn.1 {
    INSERT INTO foo (fooval) VALUES (17), (4711), (17)
      ON CONFLICT DO
      UPDATE SET refcnt = refcnt+1
    RETURNING fooid;
  } {
    1 2 1
  }
}


finish_test