SQLite

Check-in [96a717661a]
Login

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

Overview
Comment:Do not record the inserted rowid on when doing an INSERT within a trigger. Ticket #290. (CVS 906)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 96a717661a3b7108fe0cacb588d81fd8e91eb640
User & Date: drh 2003-04-15 14:01:43.000
Context
2003-04-15
17:22
Added btree_rb.c (CVS 907) (check-in: 93eb6c52ac user: paul tags: trunk)
14:01
Do not record the inserted rowid on when doing an INSERT within a trigger. Ticket #290. (CVS 906) (check-in: 96a717661a user: drh tags: trunk)
01:49
Change lemon to use <stdarg.h> instead of <varargs.h> because GCC no longer supports varargs.h. Tickets #288 and #280. Ironically, lemon originally used varargs.h because stdarg.h was not supported by the compiler I was using in 1989 (which was gcc if I recall correctly.) (CVS 905) (check-in: 7902e4778e user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbe.c.
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** in this file for details.  If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.213 2003/04/15 01:19:49 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** The makefile scans this source file and creates the following
** array of string constants which are the names of all VDBE opcodes.







|







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** in this file for details.  If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.214 2003/04/15 14:01:43 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** The makefile scans this source file and creates the following
** array of string constants which are the names of all VDBE opcodes.
3912
3913
3914
3915
3916
3917
3918
3919

3920
3921
3922
3923
3924
3925
3926
** Write an entry into the database file P1.  A new entry is
** created if it doesn't already exist or the data for an existing
** entry is overwritten.  The data is the value on the top of the
** stack.  The key is the next value down on the stack.  The key must
** be an integer.  The stack is popped twice by this instruction.
**
** If P2==1 then the row change count is incremented.  If P2==0 the
** row change count is unmodified.

*/
/* Opcode: PutStrKey P1 * *
**
** Write an entry into the database file P1.  A new entry is
** created if it doesn't already exist or the data for an existing
** entry is overwritten.  The data is the value on the top of the
** stack.  The key is the next value down on the stack.  The key must







|
>







3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
** Write an entry into the database file P1.  A new entry is
** created if it doesn't already exist or the data for an existing
** entry is overwritten.  The data is the value on the top of the
** stack.  The key is the next value down on the stack.  The key must
** be an integer.  The stack is popped twice by this instruction.
**
** If P2==1 then the row change count is incremented.  If P2==0 the
** row change count is unmodified.  The rowid is stored for subsequent
** return by the sqlite_last_insert_rowid() function if P2 is 1.
*/
/* Opcode: PutStrKey P1 * *
**
** Write an entry into the database file P1.  A new entry is
** created if it doesn't already exist or the data for an existing
** entry is overwritten.  The data is the value on the top of the
** stack.  The key is the next value down on the stack.  The key must
3941
3942
3943
3944
3945
3946
3947


3948
3949

3950
3951
3952
3953
3954
3955
3956
      nKey = aStack[nos].n;
      zKey = zStack[nos];
    }else{
      assert( aStack[nos].flags & STK_Int );
      nKey = sizeof(int);
      iKey = intToKey(aStack[nos].i);
      zKey = (char*)&iKey;


      db->lastRowid = aStack[nos].i;
      if( pOp->p2 ) db->nChange++;

      if( pC->nextRowidValid && aStack[nos].i>=pC->nextRowid ){
        pC->nextRowidValid = 0;
      }
    }
    rc = sqliteBtreeInsert(pC->pCursor, zKey, nKey,
                        zStack[tos], aStack[tos].n);
    pC->recnoIsValid = 0;







>
>
|
<
>







3942
3943
3944
3945
3946
3947
3948
3949
3950
3951

3952
3953
3954
3955
3956
3957
3958
3959
      nKey = aStack[nos].n;
      zKey = zStack[nos];
    }else{
      assert( aStack[nos].flags & STK_Int );
      nKey = sizeof(int);
      iKey = intToKey(aStack[nos].i);
      zKey = (char*)&iKey;
      if( pOp->p2 ){
        db->nChange++;
        db->lastRowid = aStack[nos].i;

      }
      if( pC->nextRowidValid && aStack[nos].i>=pC->nextRowid ){
        pC->nextRowidValid = 0;
      }
    }
    rc = sqliteBtreeInsert(pC->pCursor, zKey, nKey,
                        zStack[tos], aStack[tos].n);
    pC->recnoIsValid = 0;
Changes to test/rowid.test.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing the magic ROWID column that is
# found on all tables.
#
# $Id: rowid.test,v 1.8 2002/02/19 22:42:06 drh Exp $

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

# Basic ROWID functionality tests.
#
do_test rowid-1.1 {







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing the magic ROWID column that is
# found on all tables.
#
# $Id: rowid.test,v 1.9 2003/04/15 14:01:44 drh Exp $

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

# Basic ROWID functionality tests.
#
do_test rowid-1.1 {
348
349
350
351
352
353
354
355





















































356
do_test rowid-7.8 {
  execsql {
    DELETE FROM t2 WHERE a!=2;
    INSERT INTO t2(b) VALUES(111);
    SELECT * FROM t2;
  }
} {2 66 3 111}






















































finish_test








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

348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
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
404
405
406
407
408
409
do_test rowid-7.8 {
  execsql {
    DELETE FROM t2 WHERE a!=2;
    INSERT INTO t2(b) VALUES(111);
    SELECT * FROM t2;
  }
} {2 66 3 111}

# Make sure AFTER triggers that do INSERTs do not change the last_insert_rowid.
# Ticket #290
#
do_test rowid-8.1 {
  execsql {
    CREATE TABLE t3(a integer primary key);
    CREATE TABLE t4(x);
    INSERT INTO t4 VALUES(1);
    CREATE TRIGGER r3 AFTER INSERT on t3 FOR EACH ROW BEGIN
      INSERT INTO t4 VALUES(NEW.a+10);
    END;
    SELECT * FROM t3;
  }
} {}
do_test rowid-8.2 {
  execsql {
    SELECT rowid, * FROM t4;
  }
} {1 1}
do_test rowid-8.3 {
  execsql {
    INSERT INTO t3 VALUES(123);
    SELECT last_insert_rowid();
  }
} {123}
do_test rowid-8.4 {
  execsql {
    SELECT * FROM t3;
  }
} {123}
do_test rowid-8.5 {
  execsql {
    SELECT rowid, * FROM t4;
  }
} {1 1 2 133}
do_test rowid-8.6 {
  execsql {
    INSERT INTO t3 VALUES(NULL);
    SELECT last_insert_rowid();
  }
} {124}
do_test rowid-8.7 {
  execsql {
    SELECT * FROM t3;
  }
} {123 124}
do_test rowid-8.8 {
  execsql {
    SELECT rowid, * FROM t4;
  }
} {1 1 2 133 3 {}}


finish_test