]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a serious bug in INSERT when the source is a SELECT. (CVS 366)
authordrh <drh@noemail.net>
Sun, 3 Feb 2002 19:06:02 +0000 (19:06 +0000)
committerdrh <drh@noemail.net>
Sun, 3 Feb 2002 19:06:02 +0000 (19:06 +0000)
FossilOrigin-Name: 20ea737536700b016385c70105a2af8b2bffce2b

13 files changed:
manifest
manifest.uuid
src/btree.c
src/insert.c
src/select.c
src/vdbe.c
test/conflict.test
test/copy.test
test/insert.test
test/insert2.test
www/changes.tcl
www/index.tcl
www/lang.tcl

index 4ae4cffcf719a3456346802b4f8decbcedbeeedb..378e652632a065d63e188ef0a9bc852f1278775d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Put\sin\sPRAGMA\sSANITY_CHECK\sin\splace\sof\sVACUUM.\s(CVS\s365)
-D 2002-02-03T17:37:36
+C Fix\sa\sserious\sbug\sin\sINSERT\swhen\sthe\ssource\sis\sa\sSELECT.\s(CVS\s366)
+D 2002-02-03T19:06:03
 F Makefile.in 9fa4277413bf1d9cf91365f07d4108d7d87ed2af
 F Makefile.template 3372d45f8853afdb70bd30cc6fb50a3cd9069834
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -19,14 +19,14 @@ F ltmain.sh e9ed72eb1d690f447c13945eaf69e28af531eda1
 F publish.sh 5b59f4aff037aafa0e4a3b6fa599495dbd73f360
 F sqlite.1 2e2bb0529ef468ade9e4322bd609d0695fb9ded9
 F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6
-F src/btree.c cbe62fae68290ae5b5e1015f6a0696479244bc5b
+F src/btree.c 9d7a185510113c7d3a6e7ee9d4912f89838533a6
 F src/btree.h 53476ad4f76537591dceded79fa484a2dc168888
 F src/build.c 29504057ac5e2f40c08f19cb1574bd0512353169
 F src/delete.c f8ad71be53cf18656b6573de65395852fe817f0c
 F src/expr.c a2a87dbd411a508ff89dffa90505ad42dac2f920
 F src/hash.c 8f7c740ef2eaaa8decfa8751f2be30680b123e46
 F src/hash.h d1ce47900c7325af5e41c4feb4855c4bf2b841e7
-F src/insert.c 173da7b06fe9282e0f529ff1e599460304ceeb23
+F src/insert.c 98edfd1ae7da7558cbaad3ae5023e1ea271513a6
 F src/main.c 300320ba68d3e5b22c2c5b2c07fa884878202181
 F src/md5.c 52f677bfc590e09f71d07d7e327bd59da738d07c
 F src/os.c 1953080d14098cd45e5bde88941567688efb72b1
@@ -36,7 +36,7 @@ F src/pager.h b28f004e2f5541dc60cc32db01bf80cf4d056283
 F src/parse.y 734ba1e0dce9882345e65de5a14d9fe02fb757c2
 F src/printf.c 300a90554345751f26e1fc0c0333b90a66110a1d
 F src/random.c f6b36bec5ebd3edb3440224bf5bf811fe4ac9a1b
-F src/select.c fc11d5a8c2bae1b62d8028ffb111c773ad6bf161
+F src/select.c b32d3f38616f93f092b98c1c3e53c4dfe57dc359
 F src/shell.c c102dfe388c7618a668c944ff157c49cb48f28e3
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in f57074c84a2c112a5093ba7a9d9636aa9cacc87c
@@ -49,7 +49,7 @@ F src/test3.c d6775f95fd91f5b3cf0e2382a28e5aaeb68f745b
 F src/tokenize.c 01a09db6adf933e941db1b781789a0c175be6504
 F src/update.c 95459f94a061860bf8e5716b3426a5ba85c79103
 F src/util.c 8f8973dd55a6ec63be9632fc5de86965c99d6327
-F src/vdbe.c 6e9851f14edaa98fd244103ff899082063a0e519
+F src/vdbe.c 94704a5733db95b78cc902208c5e8e26a784e7f8
 F src/vdbe.h 3d49d22ba9ad14ea0e380bc582ff57347eaddb59
 F src/where.c 2dda39367f193194e4c7d2e0dcab31527d9d8aba
 F test/all.test 2a51e5395ac7c2c539689b123b9782a05e3837fe
@@ -57,15 +57,15 @@ F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
 F test/btree.test 6ab4dc5f595905a276ef588fad3c9236dc07a47b
 F test/btree2.test 08e9485619265cbaf5d11bd71f357cdc26bb87e0
 F test/btree3.test 9caa9e22491dd8cd8aa36d7ac3b48b089817c895
-F test/conflict.test 5515d5dcbb6be9c715d1b83b2796b8a9cb7a32d4
-F test/copy.test 9ff0063c0b95b3d51b8d0c7fe0ff51dabaa66549
+F test/conflict.test 7c7dbfdfaee24453237eff3570a93dab56cb755a
+F test/copy.test 6691f7f671a0521361b27c4ef6e5d340604d3b5c
 F test/delete.test c904a62129fe102b314a96111a8417f10249e4d8
 F test/expr.test c8a495050dcec3f9e68538c3ef466726933302c1
 F test/func.test 51dbe3f8a4c28972751697423e6acc5d6b551df1
 F test/in.test c09312672e3f0709fa02c8e2e9cd8fb4bd6269aa
 F test/index.test c8a471243bbf878974b99baf5badd59407237cf3
-F test/insert.test a5c122aa726f1cef6f07d6767e8fd6f220994c11
-F test/insert2.test d6901ca931e308fea7fca8c95ebe7dc957cc9fc2
+F test/insert.test 5e75827fc255cff240c30f11ccb635067dfc70ce
+F test/insert2.test 3fd6547056114bbb2da1d8cd7778affda4a30a12
 F test/intpkey.test ce3de8326082929667cf356855426519cfe2f5c7
 F test/ioerr.test 57d9bffaca18b34f9e976f786eadc2591d6efc6a
 F test/limit.test a930f3eba2a7691c8397ccab33710b931589566a
@@ -107,22 +107,22 @@ F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
 F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
 F www/arch.tcl 72a0c80e9054cc7025a50928d28d9c75c02c2b8b
 F www/c_interface.tcl 82a026b1681757f13b3f62e035f3a31407c1d353
-F www/changes.tcl 5c3b5b80d7144d46f100f333d4cab6184828a6c2
+F www/changes.tcl 445dd536ade7085f4ffe820805847451d01c87bb
 F www/conflict.tcl 81dd21f9a679e60aae049e9dd8ab53d59570cda2
 F www/crosscompile.tcl 3622ebbe518927a3854a12de51344673eb2dd060
 F www/download.tcl a6d75b8b117cd33dcb090bef7e80d7556d28ebe0
 F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
 F www/faq.tcl 32cbc134879871604070d4cc3a32e73fb22a35f9
 F www/formatchng.tcl 2d9a35c787823b48d72a5c64bb5414a43e26d5ad
-F www/index.tcl 748614d8208c761ed3840e7958b8eed04de81822
-F www/lang.tcl 260f3f9015344634ed9c2518f9a856462d37d6a6
+F www/index.tcl fba075f31a9cbbf13e6adec080e4943db54dbc05
+F www/lang.tcl 58077cb0c383fb312c04bf2ab6a80d7b1c525987
 F www/mingw.tcl f1c7c0a7f53387dd9bb4f8c7e8571b7561510ebc
 F www/opcode.tcl bdec8ef9f100dbd87bbef8976c54b88e43fd8ccc
 F www/speed.tcl 83457b2bf6bb430900bd48ca3dd98264d9a916a5
 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
 F www/tclsqlite.tcl 829b393d1ab187fd7a5e978631b3429318885c49
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 95d1f8389dd5e168bdf0290169662296b6a0f6d9
-R 1674dac486d8e0c1072b57bc5cd4e3c0
+P 7c65029e5bf26eb640aef529a7421cd0d6ffd1a9
+R 4e3b7ab35202d05c1b0326ce879539fa
 U drh
-Z 536d009bb8b29d6b3df6118f3f597eb5
+Z 666cc540a7569a442b5d9d36de8269cd
index c74144755463b8c7175a0c3baa6a5a08186435a4..d72f712a95b8f527a3ab7d85b9e80f2dd109ee5d 100644 (file)
@@ -1 +1 @@
-7c65029e5bf26eb640aef529a7421cd0d6ffd1a9
\ No newline at end of file
+20ea737536700b016385c70105a2af8b2bffce2b
\ No newline at end of file
index 5e8439cb36647c1dddf1a64958008d5c67cceb56..49616ec7d1779ceba45fb8c8a5531bb9f42da535 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.50 2002/02/03 17:37:36 drh Exp $
+** $Id: btree.c,v 1.51 2002/02/03 19:06:03 drh Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -2461,7 +2461,7 @@ int sqliteBtreeUpdateMeta(Btree *pBt, int *aMeta){
 ** All of the following code is omitted if the library is compiled with
 ** the -DNDEBUG=1 compiler option.
 ******************************************************************************/
-#ifndef NDEEBUG
+#ifndef NDEBUG
 
 /*
 ** Print a disassembly of the given page on standard output.  This routine
index e387150da3f01c626364f5268ae9dab8fffb5e1e..f993b89ea99884b81fb17447d1d5df23f24d3f5f 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.41 2002/02/03 00:56:10 drh Exp $
+** $Id: insert.c,v 1.42 2002/02/03 19:06:03 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -238,7 +238,7 @@ void sqliteInsert(
       sqliteVdbeAddOp(v, OP_String, 0, 0);
       sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zDflt, P3_STATIC);
     }else if( srcTab>=0 ){
-      sqliteVdbeAddOp(v, OP_Column, srcTab, i); 
+      sqliteVdbeAddOp(v, OP_Column, srcTab, j); 
     }else{
       sqliteExprCode(pParse, pList->a[j].pExpr);
     }
index b0ef7081fedffcd45e1a4ef47bd2882722aa0d66..b2cf364f6fdda26f38e499953e511681be4c2306 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.56 2002/01/28 15:53:05 drh Exp $
+** $Id: select.c,v 1.57 2002/02/03 19:06:03 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -335,7 +335,7 @@ static int fillInColumnList(Parse *pParse, Select *p){
     if( pTabList->a[i].zName==0 ){
       /* No table name is given.  Instead, there is a (SELECT ...) statement
       ** the results of which should be used in place of the table.  The
-      ** was this is implemented is that the (SELECT ...) writes its results
+      ** way this is implemented is that the (SELECT ...) writes its results
       ** into a temporary table which is then scanned like any other table.
       */
       sqliteSetString(&pParse->zErrMsg, 
index b663b315d3bb405c900bf336f3d41ebb95f60623..aa2273d8b194bad942ecf319082b7a293845c204 100644 (file)
@@ -30,7 +30,7 @@
 ** But other routines are also provided to help in building up
 ** a program instruction by instruction.
 **
-** $Id: vdbe.c,v 1.116 2002/02/03 03:34:09 drh Exp $
+** $Id: vdbe.c,v 1.117 2002/02/03 19:06:03 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -3493,7 +3493,7 @@ case OP_CreateTable: {
 ** This opcode is used for testing purposes only.
 */
 case OP_SanityCheck: {
-#if 1  /* This opcode used for testing only */
+#ifndef NDEBUG  /* This opcode used for testing only */
   int nRoot;
   int *aRoot;
   int tos = ++p->tos;
@@ -3503,10 +3503,8 @@ case OP_SanityCheck: {
   HashElem *i;
   char *z;
 
-  if( iSet<0 || iSet>=p->nSet ){
-    goto bad_instruction;
-  }
-  VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
+  if( iSet<0 || iSet>=p->nSet ) goto bad_instruction;
+  if( NeedStack(p, p->tos) ) goto no_mem;
   pSet = &p->aSet[iSet];
   nRoot = sqliteHashCount(&pSet->hash);
   aRoot = sqliteMalloc( sizeof(int)*(nRoot+1) );
@@ -3525,7 +3523,8 @@ case OP_SanityCheck: {
     aStack[tos].n = strlen(z) + 1;
     aStack[tos].flags = STK_Str | STK_Dyn;
   }
-#endif /* SQLITE_TEST */
+  sqliteFree(aRoot);
+#endif /* !define(NDEBUG) */
   break;
 }
 
index 7bf5efd6eec2693bd5a8a24d7b266b91a09e07c7..be0033c771bd300c493a156f3914b663733e7fbf 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests for the conflict resolution extension
 # to SQLite.
 #
-# $Id: conflict.test,v 1.6 2002/02/03 03:34:09 drh Exp $
+# $Id: conflict.test,v 1.7 2002/02/03 19:06:03 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -377,5 +377,10 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
   } [list $t0 $t1 $t2]
 }
 
+do_test insert-99.1 {
+  set x [execsql {PRAGMA sanity_check}]
+  if {$x==""} {set x ok}
+  set x
+} {ok}
 
 finish_test
index db0aa2b31d7e422452a93d137834d534523663f7..95afb35d3101f1f196297454a058d63ecf7f15ec 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the COPY statement.
 #
-# $Id: copy.test,v 1.8 2002/01/31 15:54:23 drh Exp $
+# $Id: copy.test,v 1.9 2002/02/03 19:06:03 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -207,6 +207,30 @@ do_test copy-5.4 {
     SELECT * FROM t1;
   }
 } {0 {22 33 11 33 22 44}}
+
+do_test copy-5.5 {
+  execsql {
+    DELETE FROM t1;
+    PRAGMA count_changes=on;
+    COPY t1 FROM 'data5.txt' USING DELIMITERS '|';
+  }
+} {2}
+do_test copy-5.6 {
+  execsql {
+    COPY OR REPLACE t1 FROM 'data5.txt' USING DELIMITERS '|';
+  }
+} {2}
+do_test copy-5.7 {
+  execsql {
+    COPY OR IGNORE t1 FROM 'data5.txt' USING DELIMITERS '|';
+  }
+} {0}
+
+do_test copy-6.0 {
+  set x [execsql {PRAGMA sanity_check}]
+  if {$x==""} {set x ok}
+  set x
+} {ok}
  
 
 # Cleanup 
index 8754769076db9f6b6464d2e1727a1d3c0da5947d..3db1a4422549de424236a67d793710d8d028d962 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the INSERT statement.
 #
-# $Id: insert.test,v 1.6 2001/09/16 00:13:28 drh Exp $
+# $Id: insert.test,v 1.7 2002/02/03 19:06:03 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -156,5 +156,11 @@ do_test insert-3.3 {
 do_test insert-3.4 {
   execsql {SELECT * FROM test2 WHERE f1=22 AND f2=-4.44}
 } {22 -4.44 hi abc-123 wham}
+do_test insert-3.5 {
+  set x [execsql {PRAGMA sanity_check}]
+  if {$x==""} {set x ok}
+  set x
+} {ok}
+
 
 finish_test
index 610e587511d23ae21c392723922ae4f2883cb766..51f95d5141b7712592dbff8efbf643991d269a25 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is testing the INSERT statement that takes is
 # result from a SELECT.
 #
-# $Id: insert2.test,v 1.5 2001/10/15 00:44:36 drh Exp $
+# $Id: insert2.test,v 1.6 2002/02/03 19:06:03 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -83,4 +83,39 @@ do_test insert2-1.4 {
   lappend r [execsql {SELECT log FROM t1 WHERE cnt=4 ORDER BY log}]
 } {0 1 1 1 2 2 3 4 4 8 5 4 4 {3 5}}
 
+do_test insert2-2.0 {
+  execsql {
+    CREATE TABLE t3(a,b,c);
+    CREATE TABLE t4(x,y);
+    INSERT INTO t4 VALUES(1,2);
+    SELECT * FROM t4;
+  }
+} {1 2}
+do_test insert2-2.1 {
+  execsql {
+    INSERT INTO t3(a,c) SELECT * FROM t4;
+    SELECT * FROM t3;
+  }
+} {1 {} 2}
+do_test insert2-2.2 {
+  execsql {
+    DELETE FROM t3;
+    INSERT INTO t3(c,b) SELECT * FROM t4;
+    SELECT * FROM t3;
+  }
+} {{} 2 1}
+do_test insert2-2.3 {
+  execsql {
+    DELETE FROM t3;
+    INSERT INTO t3(c,a,b) SELECT x, 'hi', y FROM t4;
+    SELECT * FROM t3;
+  }
+} {hi 2 1}
+
+do_test insert2-4.0 {
+  set x [execsql {PRAGMA sanity_check}]
+  if {$x==""} {set x ok}
+  set x
+} {ok}
+
 finish_test
index 148aa577a6c5612e7826351af393506d1882063c..732fe6cc78bf77230e2ca4eb9b30e9e95fe8af85 100644 (file)
@@ -17,7 +17,10 @@ proc chng {date desc} {
   puts "<DD><P><UL>$desc</UL></P></DD>"
 }
 
-chng {2002 Jan 30 (2.3.0 beta)} {
+chng {2002 Jan 30 (2.3.0)} {
+<li>Fix a serious bug in the INSERT command which was causing data to go
+    into the wrong columns if the data source was a SELECT and the INSERT
+    clauses specified its columns in some order other than the default.</li>
 <li>Added the ability to resolve constraint conflicts is ways other than
     an abort and rollback.  See the documentation on the "ON CONFLICT"
     clause for details.</li>
@@ -28,6 +31,7 @@ chng {2002 Jan 30 (2.3.0 beta)} {
 <li>NOT NULL constraints are honored.</li>
 <li>The COPY command puts NULLs in columns whose data is '\N'.</li>
 <li>In the COPY command, backslash can now be used to escape a newline.</li>
+<li>Added the SANITY_CHECK pragma.</li>
 }
 
 chng {2002 Jan 28 (2.2.5)} {
index 3ae7a97b2b681c9bc31a3decc833e815a90c10dc..10e78ba103cdbf3ce06e5cd496e82c78b485e3a6 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Run this TCL script to generate HTML for the index.html file.
 #
-set rcsid {$Id: index.tcl,v 1.52 2002/01/29 18:41:26 drh Exp $}
+set rcsid {$Id: index.tcl,v 1.53 2002/02/03 19:06:04 drh Exp $}
 
 puts {<html>
 <head><title>SQLite: An SQL Database Engine In A C Library</title></head>
@@ -64,8 +64,7 @@ puts {<h2>Current Status</h2>
 <p>A <a href="changes.html">change history</a> is available online.
 The latest source code is
 <a href="download.html">available for download</a>.
-There are currently no known memory leaks or bugs
-in version 2.2.5 of the library.
+For a list of recently discovered bugs, refer to the change history.
 </p>
 
 <p>
index 39ed433008b4513f2cf3ed6af824346d1c9f02be..bfed8280c230eebfc26befae25269c6e4cf95825 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Run this Tcl script to generate the sqlite.html file.
 #
-set rcsid {$Id: lang.tcl,v 1.21 2002/02/03 00:56:11 drh Exp $}
+set rcsid {$Id: lang.tcl,v 1.22 2002/02/03 19:06:04 drh Exp $}
 
 puts {<html>
 <head>
@@ -624,7 +624,7 @@ the command made prior to encountering the constraint violation
 are preserved and are not backed out.  For example, if an UPDATE
 statement encountered a constraint violation on the 100th row that
 it attempts to update, then the first 99 row changes are preserved
-by change to rows 100 and beyond never occur.</p></dd>
+but changes to rows 100 and beyond never occur.</p></dd>
 
 <dt><b>IGNORE</b></dt>
 <dd><p>When a constraint violation occurs, the one row that contains
@@ -637,7 +637,11 @@ normally.  No error is returned.</p></dd>
 <dd><p>When a UNIQUE constraint violation occurs, the pre-existing row
 that is causing the constraint violation is removed prior to inserting
 or updating the current row.  Thus the insert or update always occurs.
-The command continues executing normally.  No error is returned.</p></dd>
+The command continues executing normally.  No error is returned.</p>
+<p>If a NOT NULL constraint violation occurs, the NULL value is replaced
+by the default value for that column.  If the column has no default
+value, then the ABORT algorithm is used.</p>
+</dd>
 </dl>
 
 <p>
@@ -736,6 +740,15 @@ with caution.</p>
     This only works if the library is compiled without the NDEBUG macro.
     </p></li>
 
+<li><p><b>PRAGMA sanity_check;</b></p>
+    <p>The command does an integrity check of the entire database.  It
+    looks for out-of-order records, missing pages, and malformed records.
+    If any problems are found, then a single string is returned which is
+    a description of all problems.  If everything is in order, "ok" is
+    returned.  This command is used for testing and debugging only and
+    is not available if the library is compiled 
+    with the -DNDEBUG=1 compiler option.</p>
+
 <li><p><b>PRAGMA table_info(</b><i>table-name</i><b>);</b></p>
     <p>For each column in the named table, invoke the callback function
     once with information about that column, including the column name,