/ Check-in [d599f75b]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix for ticket #75: Autoincrement INTEGER PRIMARY KEY fields on an INSERT even if the data is coming from a SELECT statement. (CVS 630)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d599f75b659809a6e5eee09b0e9e6e90bde5af1e
User & Date: drh 2002-06-19 20:32:44
Context
2002-06-20
03:38
Fix for ticket #73: The ORDER BY clause is significant for subqueries. This passes all regression tests, but more testing is needed to exercise all paths through the new code. (CVS 631) check-in: 43c5aff5 user: drh tags: trunk
2002-06-19
20:32
Fix for ticket #75: Autoincrement INTEGER PRIMARY KEY fields on an INSERT even if the data is coming from a SELECT statement. (CVS 630) check-in: d599f75b user: drh tags: trunk
14:27
Version 2.5.1 (CVS 629) check-in: 5e8a3131 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/insert.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.61 2002/06/11 02:25:42 danielk1977 Exp $
*/
#include "sqliteInt.h"

/*
** This routine is call to handle SQL of the following forms:
**
**    insert into TABLE (IDLIST) values(EXPRLIST)
................................................................................
  */
  if( !pTab->pSelect ){
    if( keyColumn>=0 ){
      if( srcTab>=0 ){
        sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
      }else{
        sqliteExprCode(pParse, pList->a[keyColumn].pExpr);

        /* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
        ** to generate a unique primary key value.
        */
        sqliteVdbeAddOp(v, OP_NotNull, -1, sqliteVdbeCurrentAddr(v)+3);
        sqliteVdbeAddOp(v, OP_Pop, 1, 0);
        sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
      }
      sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
    }else{
      sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
    }

    /* Push onto the stack, data for all columns of the new entry, beginning
    ** with the first column.







|







 







|
|
|
|
|
|
|
<







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.62 2002/06/19 20:32:44 drh Exp $
*/
#include "sqliteInt.h"

/*
** This routine is call to handle SQL of the following forms:
**
**    insert into TABLE (IDLIST) values(EXPRLIST)
................................................................................
  */
  if( !pTab->pSelect ){
    if( keyColumn>=0 ){
      if( srcTab>=0 ){
        sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
      }else{
        sqliteExprCode(pParse, pList->a[keyColumn].pExpr);
      }
      /* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
      ** to generate a unique primary key value.
      */
      sqliteVdbeAddOp(v, OP_NotNull, -1, sqliteVdbeCurrentAddr(v)+3);
      sqliteVdbeAddOp(v, OP_Pop, 1, 0);
      sqliteVdbeAddOp(v, OP_NewRecno, base, 0);

      sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
    }else{
      sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
    }

    /* Push onto the stack, data for all columns of the new entry, beginning
    ** with the first column.

Changes to test/intpkey.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
451
452
453
454
455
456
457




458


459
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the special processing associated
# with INTEGER PRIMARY KEY columns.
#
# $Id: intpkey.test,v 1.9 2002/03/31 18:29:03 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a table with a primary key and a datatype other than
# integer
#
................................................................................
} {1 1 2}
do_test intpkey-10.2 {
  execsql {
    INSERT INTO t2 VALUES(NULL, 2, 3);
    SELECT * from t2 WHERE x=2;
  }
} {2 2 3}







finish_test







|







 







>
>
>
>
|
>
>

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the special processing associated
# with INTEGER PRIMARY KEY columns.
#
# $Id: intpkey.test,v 1.10 2002/06/19 20:32:45 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a table with a primary key and a datatype other than
# integer
#
................................................................................
} {1 1 2}
do_test intpkey-10.2 {
  execsql {
    INSERT INTO t2 VALUES(NULL, 2, 3);
    SELECT * from t2 WHERE x=2;
  }
} {2 2 3}
do_test intpkey-10.3 {
  execsql {
    INSERT INTO t2 SELECT NULL, z, y FROM t2;
    SELECT * FROM t2;
  }
} {1 1 2 2 2 3 3 2 1 4 3 2}

finish_test