/ Check-in [d599f75b]
Login

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 Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/insert.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle INSERT statements in SQLite.
    14     14   **
    15         -** $Id: insert.c,v 1.61 2002/06/11 02:25:42 danielk1977 Exp $
           15  +** $Id: insert.c,v 1.62 2002/06/19 20:32:44 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** This routine is call to handle SQL of the following forms:
    21     21   **
    22     22   **    insert into TABLE (IDLIST) values(EXPRLIST)
................................................................................
   288    288     */
   289    289     if( !pTab->pSelect ){
   290    290       if( keyColumn>=0 ){
   291    291         if( srcTab>=0 ){
   292    292           sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
   293    293         }else{
   294    294           sqliteExprCode(pParse, pList->a[keyColumn].pExpr);
   295         -
   296         -        /* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
   297         -        ** to generate a unique primary key value.
   298         -        */
   299         -        sqliteVdbeAddOp(v, OP_NotNull, -1, sqliteVdbeCurrentAddr(v)+3);
   300         -        sqliteVdbeAddOp(v, OP_Pop, 1, 0);
   301         -        sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
   302    295         }
          296  +      /* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
          297  +      ** to generate a unique primary key value.
          298  +      */
          299  +      sqliteVdbeAddOp(v, OP_NotNull, -1, sqliteVdbeCurrentAddr(v)+3);
          300  +      sqliteVdbeAddOp(v, OP_Pop, 1, 0);
          301  +      sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
   303    302         sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
   304    303       }else{
   305    304         sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
   306    305       }
   307    306   
   308    307       /* Push onto the stack, data for all columns of the new entry, beginning
   309    308       ** with the first column.

Changes to test/intpkey.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for the special processing associated
    14     14   # with INTEGER PRIMARY KEY columns.
    15     15   #
    16         -# $Id: intpkey.test,v 1.9 2002/03/31 18:29:03 drh Exp $
           16  +# $Id: intpkey.test,v 1.10 2002/06/19 20:32:45 drh Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # Create a table with a primary key and a datatype other than
    22     22   # integer
    23     23   #
................................................................................
   451    451   } {1 1 2}
   452    452   do_test intpkey-10.2 {
   453    453     execsql {
   454    454       INSERT INTO t2 VALUES(NULL, 2, 3);
   455    455       SELECT * from t2 WHERE x=2;
   456    456     }
   457    457   } {2 2 3}
          458  +do_test intpkey-10.3 {
          459  +  execsql {
          460  +    INSERT INTO t2 SELECT NULL, z, y FROM t2;
          461  +    SELECT * FROM t2;
          462  +  }
          463  +} {1 1 2 2 2 3 3 2 1 4 3 2}
   458    464   
   459    465   finish_test