]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
When initializing the sqlite_sequence entry for an AUTOINCREMENT table,
authordrh <drh@noemail.net>
Thu, 29 May 2008 03:20:59 +0000 (03:20 +0000)
committerdrh <drh@noemail.net>
Thu, 29 May 2008 03:20:59 +0000 (03:20 +0000)
make sure the value is an reasonable integer even if the initial insert
failed.  Ticket #3148. (CVS 5175)

FossilOrigin-Name: 7e6847852d4517b1d14bebb8f0ae4d938b0b6f6d

manifest
manifest.uuid
src/insert.c
test/autoinc.test

index f0989954a5858ddd1c3718ecf4484f7c4eceb3fe..39add3e2a7aa4854f4270636ce900fc4fd2da9b5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\sobsolete\scomment\son\sthe\sOP_Rowid\sopcode\sin\sthe\sVDBE.\s(CVS\s5174)
-D 2008-05-29T03:12:55
+C When\sinitializing\sthe\ssqlite_sequence\sentry\sfor\san\sAUTOINCREMENT\stable,\nmake\ssure\sthe\svalue\sis\san\sreasonable\sinteger\seven\sif\sthe\sinitial\sinsert\nfailed.\s\sTicket\s#3148.\s(CVS\s5175)
+D 2008-05-29T03:20:59
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 62b2a40ff5944dd33c9c3184b21f720ea8e48a44
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -109,7 +109,7 @@ F src/fault.c 1f6177188edb00641673e462f3fab8cba9f7422b
 F src/func.c 77a910a1ca7613d291fd0b5cba3be14c02f0dce0
 F src/hash.c fd8cb06fb54c2fe7d48c9195792059a2e5be8b70
 F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
-F src/insert.c 77f0829b3e2edd19e9238195c56b0d56ab000f17
+F src/insert.c e3277f313352ac27282b5be39972fda4f315d0c6
 F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
 F src/legacy.c 8f5a2b25d9673b4004287cf2bf51dbf7d0738406
 F src/loadext.c eac6c61810a3b531808774bec7f3d238cfe261f3
@@ -205,7 +205,7 @@ F test/attach3.test 7b92dc8e40c1ebca9732ca6f2d3fefbd46f196df
 F test/attachmalloc.test 56c5e55563dba6d64641ef2f70ce06900df16912
 F test/auth.test 100cde29a9913530994289038ec80ef5f63d38d3
 F test/auth2.test 65ac294b8d52cbdd463f61e77ad0165268373126
-F test/autoinc.test 0555aa5c789520f16d86a39c6c49b87998e01bea
+F test/autoinc.test 42af2c407c4e37d0626f9cda57ed381e94522c9d
 F test/autovacuum.test 4339e66003b9cf813dd667a83aed2dee27c4c36d
 F test/autovacuum_crash.test 05a63b8805b20cfba7ace82856ce4ccdda075a31
 F test/autovacuum_ioerr.test c46a76869cb6eddbbb40b419b2b6c4c001766b1f
@@ -590,7 +590,7 @@ F tool/speedtest16.c 6f5bc019dcf8b6537f379bbac0408a9e1a86f0b6
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c e74126bc12178fa29904f711bb100212a5448041
 F tool/speedtest8inst1.c 025879132979a5fdec11218472cba6cf8f6ec854
-P 5afc445a0e49def38f198455ffce9266fc8724ad
-R b2c1745f6c0390bde274854fea56c24c
+P 0d55328e680e23aae36d8f32a05aa3815393ac1d
+R ab453b09cecfedf1a77ed78183e41224
 U drh
-Z d8c9f6ac32584a71df5ee1017d267564
+Z 59397d3549d58da0def94fe92fd606ec
index db51c0b3922e4e35259f5b34d679d7b7479afdba..059c0dd5b3eb56b9b870e206c4e4b5abb980ecbf 100644 (file)
@@ -1 +1 @@
-0d55328e680e23aae36d8f32a05aa3815393ac1d
\ No newline at end of file
+7e6847852d4517b1d14bebb8f0ae4d938b0b6f6d
\ No newline at end of file
index 2640763a6649a6e915b71da11b43926ec70ba3af..e7b9a6945dbc3b6fe7d57d4685c6ea34b5be0fe1 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle INSERT statements in SQLite.
 **
-** $Id: insert.c,v 1.238 2008/04/28 18:46:43 drh Exp $
+** $Id: insert.c,v 1.239 2008/05/29 03:20:59 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -175,14 +175,15 @@ static int autoIncBegin(
     sqlite3OpenTable(pParse, iCur, iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
     addr = sqlite3VdbeCurrentAddr(v);
     sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, pTab->zName, 0);
-    sqlite3VdbeAddOp2(v, OP_Rewind, iCur, addr+8);
+    sqlite3VdbeAddOp2(v, OP_Rewind, iCur, addr+9);
     sqlite3VdbeAddOp3(v, OP_Column, iCur, 0, memId);
     sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId);
     sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
     sqlite3VdbeAddOp2(v, OP_Rowid, iCur, memId+1);
     sqlite3VdbeAddOp3(v, OP_Column, iCur, 1, memId);
-    sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+8);
+    sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
     sqlite3VdbeAddOp2(v, OP_Next, iCur, addr+2);
+    sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
     sqlite3VdbeAddOp2(v, OP_Close, iCur, 0);
   }
   return memId;
index ea9b46ea801673abf764a759e2e287c3f099d983..1c19fc7cf7e0dc73ec0703a05943d24d851d4a83 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script is testing the AUTOINCREMENT features.
 #
-# $Id: autoinc.test,v 1.11 2008/01/04 19:10:29 danielk1977 Exp $
+# $Id: autoinc.test,v 1.12 2008/05/29 03:20:59 drh Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -535,4 +535,21 @@ do_test autoinc-8.1 {
   }
 } {1}
 
+# Ticket #3148
+# Make sure the sqlite_sequence table is not damaged when doing
+# an empty insert - an INSERT INTO ... SELECT ... where the SELECT
+# clause returns an empty set.
+#
+do_test autoinc-9.1 {
+  db eval {
+    CREATE TABLE t2(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
+    INSERT INTO t2 VALUES(NULL, 1);
+    CREATE TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
+    INSERT INTO t3 SELECT * FROM t2 WHERE y>1;
+
+    SELECT * FROM sqlite_sequence WHERE name='t3';
+  }
+} {t3 0}
+
+
 finish_test