/ Check-in [9e3cf4aa]
Login

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

Overview
Comment:When an attempt is made to insert an explicit NULL into an INTEGER PRIMARY KEY column, automatically convert the NULL value into a unique integer key. This was already happening when an implied NULL was inserted - when the INTEGER PRIMARY KEY column was omitted from the list of columns being inserted. Patches from Christian Werner. (CVS 510)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9e3cf4aa2cb44932015b8bd3fd800d7678cb09b6
User & Date: drh 2002-03-31 18:29:03
Context
2002-04-01
12:15
Remove from the index page of the website hyperlinks that are not directly related to SQLite. (CVS 511) check-in: 0cb5cfa8 user: drh tags: trunk
2002-03-31
18:29
When an attempt is made to insert an explicit NULL into an INTEGER PRIMARY KEY column, automatically convert the NULL value into a unique integer key. This was already happening when an implied NULL was inserted - when the INTEGER PRIMARY KEY column was omitted from the list of columns being inserted. Patches from Christian Werner. (CVS 510) check-in: 9e3cf4aa user: drh tags: trunk
2002-03-30
15:32
Version 2.4.4 (CVS 509) check-in: c4b6c0be user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to VERSION.

     1         -2.4.4
            1  +2.4.5

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.47 2002/03/03 18:59:41 drh Exp $
           15  +** $Id: insert.c,v 1.48 2002/03/31 18:29:03 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)
................................................................................
   202    202     ** except when the table has an INTEGER PRIMARY KEY column, in which
   203    203     ** case the record number is the same as that column. 
   204    204     */
   205    205     if( keyColumn>=0 ){
   206    206       if( srcTab>=0 ){
   207    207         sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
   208    208       }else{
          209  +      int addr;
   209    210         sqliteExprCode(pParse, pList->a[keyColumn].pExpr);
          211  +
          212  +      /* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
          213  +      ** to generate a unique primary key value.
          214  +      */
          215  +      addr = sqliteVdbeAddOp(v, OP_Dup, 0, 1);
          216  +      sqliteVdbeAddOp(v, OP_NotNull, 0, addr+4);
          217  +      sqliteVdbeAddOp(v, OP_Pop, 1, 0);
          218  +      sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
   210    219       }
   211    220       sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
   212    221     }else{
   213    222       sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
   214    223     }
   215    224   
   216    225     /* Push onto the stack, data for all columns of the new entry, beginning

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.8 2002/02/19 22:42:06 drh Exp $
           16  +# $Id: intpkey.test,v 1.9 2002/03/31 18:29:03 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   #
................................................................................
   434    434   do_test intpkey-9.1 {
   435    435     execsql {
   436    436       UPDATE t1 SET c='www' WHERE c='world';
   437    437       SELECT rowid, a, c FROM t1 WHERE c=='www';
   438    438     }
   439    439   } {5 5 www 11 11 www}
   440    440   
          441  +
          442  +# Check insert of NULL for primary key
          443  +#
          444  +do_test intpkey-10.1 {
          445  +  execsql {
          446  +    DROP TABLE t2;
          447  +    CREATE TABLE t2(x INTEGER PRIMARY KEY, y, z);
          448  +    INSERT INTO t2 VALUES(NULL, 1, 2);
          449  +    SELECT * from t2;
          450  +  }
          451  +} {1 1 2}
          452  +do_test intpkey-10.2 {
          453  +  execsql {
          454  +    INSERT INTO t2 VALUES(NULL, 2, 3);
          455  +    SELECT * from t2 WHERE x=2;
          456  +  }
          457  +} {2 2 3}
          458  +
   441    459   finish_test

Changes to www/changes.tcl.

    20     20   }
    21     21   
    22     22   
    23     23   proc chng {date desc} {
    24     24     puts "<DT><B>$date</B></DT>"
    25     25     puts "<DD><P><UL>$desc</UL></P></DD>"
    26     26   }
           27  +
           28  +chng {2002 Mar 31 (2.4.5)} {
           29  +<li>When inserting an explicit NULL into an INTEGER PRIMARY KEY, convert
           30  +    the NULL value into a unique key automatically.</li>
           31  +}
    27     32   
    28     33   chng {2002 Mar 24 (2.4.4)} {
    29     34   <li>Allow "VIEW" to be a column name</li>
    30     35   <li>Added support for CASE expressions (patch from Dan Kennedy)</li>
    31     36   <li>Added RPMS to the delivery (patches from Doug Henry)</li>
    32     37   <li>Fix typos in the documentation</li>
    33     38   <li>Cut over configuration management to a new CVS repository with