]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix for bug #11: Output the correct row count when and INSERT does an
authordrh <drh@noemail.net>
Tue, 9 Apr 2002 03:28:01 +0000 (03:28 +0000)
committerdrh <drh@noemail.net>
Tue, 9 Apr 2002 03:28:01 +0000 (03:28 +0000)
IGNORE action. (CVS 524)

FossilOrigin-Name: bb83642e9a6c1c9ade861618496933c9f922a8f8

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

index 344883006e79fba5e8821187fc335b6f09ed2470..75d51833a36571cad077a2a4aefbd5ea76a0ee17 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sfor\sbug\s#10:\sPop\sthe\sstack\sby\sthe\sright\samount\son\san\sIGNORE\sso\sthat\sthe\nstack\sdoes\snot\sgrow\swithout\sbound.\s(CVS\s523)
-D 2002-04-09T03:15:07
+C Fix\sfor\sbug\s#11:\sOutput\sthe\scorrect\srow\scount\swhen\sand\sINSERT\sdoes\san\nIGNORE\saction.\s(CVS\s524)
+D 2002-04-09T03:28:01
 F Makefile.in 50f1b3351df109b5774771350d8c1b8d3640130d
 F Makefile.template 89e373b2dad0321df00400fa968dc14b61a03296
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -28,7 +28,7 @@ F src/expr.c e7a1e22bc2ebcd789f0f8c0db544cf16ad664054
 F src/func.c dca9df811298cd0beb3724d40cee348e884352b2
 F src/hash.c cc259475e358baaf299b00a2c7370f2b03dda892
 F src/hash.h dca065dda89d4575f3176e75e9a3dc0f4b4fb8b9
-F src/insert.c bae1964a0923e4716d73639becda6f8040b8889e
+F src/insert.c 9ddb3b05a77644cd0e325a97a4d896c328c13601
 F src/main.c b21019084b93fe685a8a25217d01f6958584ae9b
 F src/md5.c b2b1a34fce66ceca97f4e0dabc20be8be7933c92
 F src/os.c 5ab8b6b4590d0c1ab8e96c67996c170e4462e0fc
@@ -60,7 +60,7 @@ F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
 F test/btree.test bf326f546a666617367a7033fa2c07451bd4f8e1
 F test/btree2.test e3b81ec33dc2f89b3e6087436dfe605b870c9080
 F test/btree3.test 9caa9e22491dd8cd8aa36d7ac3b48b089817c895
-F test/conflict.test cbefdd1acf526d516ee355bcbae3f6ac20dba433
+F test/conflict.test 3383ac08da14cdba11bb4c9495583cf87f67afb1
 F test/copy.test b3cefcb520c64d7e7dfedbab06b4d4c31fa5b99a
 F test/delete.test c904a62129fe102b314a96111a8417f10249e4d8
 F test/expr.test 846795016b5993a7411f772eebe82ab67bd7230a
@@ -131,7 +131,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f
 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
 F www/tclsqlite.tcl 829b393d1ab187fd7a5e978631b3429318885c49
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 760bf568c882d7b28746b1e004309ef08d2ff4c0
-R 6b0c28f4fe8903649bf342fb8427f838
+P f46acfc3b828620e4e97b09f9aff119b9313e5d7
+R 692fc2d1862a53490444758eb16748ac
 U drh
-Z 331e7f72889413d22a80eccdf9b3c49a
+Z 6902a29913af9f8655adc77cc99b4640
index 896dd33a278d7e3cee1b70b2baa90734c3795cd4..4e1bd4d269dad2e08b2e97a60350d956ec7aa9ac 100644 (file)
@@ -1 +1 @@
-f46acfc3b828620e4e97b09f9aff119b9313e5d7
\ No newline at end of file
+bb83642e9a6c1c9ade861618496933c9f922a8f8
\ No newline at end of file
index 0a05c0819946091d9107fac9eb1949c3d4089670..55e2a212a5f01204c8a27bd399053abd7d0b8c10 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.49 2002/04/09 03:15:07 drh Exp $
+** $Id: insert.c,v 1.50 2002/04/09 03:28:01 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -183,15 +183,18 @@ void sqliteInsert(
   }
   pParse->nTab += idx;
 
+  /* Initialize the count of rows to be inserted
+  */
+  if( db->flags & SQLITE_CountRows ){
+    sqliteVdbeAddOp(v, OP_Integer, 0, 0);  /* Initialize the row count */
+  }
+
   /* If the data source is a SELECT statement, then we have to create
   ** a loop because there might be multiple rows of data.  If the data
   ** source is an expression list, then exactly one row will be inserted
   ** and the loop is not used.
   */
   if( srcTab>=0 ){
-    if( db->flags & SQLITE_CountRows ){
-      sqliteVdbeAddOp(v, OP_Integer, 0, 0);  /* Initialize the row count */
-    }
     iBreak = sqliteVdbeMakeLabel(v);
     sqliteVdbeAddOp(v, OP_Rewind, srcTab, iBreak);
     iCont = sqliteVdbeCurrentAddr(v);
@@ -258,10 +261,9 @@ void sqliteInsert(
   sqliteGenerateConstraintChecks(pParse, pTab, base, 0,0,0, onError, endOfLoop);
   sqliteCompleteInsertion(pParse, pTab, base, 0,0,0);
 
-  /* If inserting from a SELECT, keep a count of the number of
-  ** rows inserted.
+  /* Update the count of rows that are inserted
   */
-  if( srcTab>=0 && (db->flags & SQLITE_CountRows)!=0 ){
+  if( (db->flags & SQLITE_CountRows)!=0 ){
     sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
   }
 
@@ -286,9 +288,6 @@ void sqliteInsert(
     sqliteVdbeAddOp(v, OP_ColumnCount, 1, 0);
     sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
     sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
-    if( srcTab<0 ){
-      sqliteVdbeAddOp(v, OP_Integer, 1, 0);
-    }
     sqliteVdbeAddOp(v, OP_Callback, 1, 0);
   }
 
index b51d21512d89f4563a6c37194b117abe0107e607..a3f6bee74581ee604f8281a026f35f63f8091cd5 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests for the conflict resolution extension
 # to SQLite.
 #
-# $Id: conflict.test,v 1.9 2002/04/09 03:15:08 drh Exp $
+# $Id: conflict.test,v 1.10 2002/04/09 03:28:01 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -426,6 +426,43 @@ do_test conflict-7.7 {
   }
 } {1}
 
+# Make sure the row count is right for rows that are ignored on
+# an insert.
+#
+do_test conflict-8.1 {
+  execsql {
+    DELETE FROM t1;
+    INSERT INTO t1 VALUES(1,2);
+  }
+  execsql {
+    INSERT OR IGNORE INTO t1 VALUES(2,3);
+  }
+} {1}
+do_test conflict-8.2 {
+  execsql {
+    INSERT OR IGNORE INTO t1 VALUES(2,4);
+  }
+} {0}
+do_test conflict-8.3 {
+  execsql {
+    INSERT OR REPLACE INTO t1 VALUES(2,4);
+  }
+} {1}
+do_test conflict-8.4 {
+  execsql {
+    INSERT OR IGNORE INTO t1 SELECT * FROM t1;
+  }
+} {0}
+do_test conflict-8.5 {
+  execsql {
+    INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1;
+  }
+} {2}
+do_test conflict-8.6 {
+  execsql {
+    INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1;
+  }
+} {3}
 
 do_test insert-99.1 {
   set x [execsql {PRAGMA integrity_check}]