]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add support for INSERT INTO ... DEFAULT VALUES. Tickets #299, #1940. (CVS 3368)
authordrh <drh@noemail.net>
Fri, 25 Aug 2006 23:42:53 +0000 (23:42 +0000)
committerdrh <drh@noemail.net>
Fri, 25 Aug 2006 23:42:53 +0000 (23:42 +0000)
FossilOrigin-Name: bc84cb54b0df09738fd90e48820dc3cdfa7828c2

manifest
manifest.uuid
src/insert.c
src/parse.y
src/tclsqlite.c
test/insert3.test

index 2dff553ade99978b9d50bd4186c7b24ec1f49024..0d35188c76bdcd3288e054b7f8048542aa37f86e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sgcc\sgripe\sabout\sparens\sin\sa\s||/&&\sin\smergePosList().\nDrop\sunused\spBlob/nBlob\sin\sindex_insert_term().\nFix\sNULL\sderef\sin\san\sassertion\sin\sdocListUpdate()\sdelete\scase.\nMinor\scode\stightening\sin\sdocListUpdate().\s(CVS\s3367)
-D 2006-08-25T19:20:26
+C Add\ssupport\sfor\sINSERT\sINTO\s...\sDEFAULT\sVALUES.\s\sTickets\s#299,\s#1940.\s(CVS\s3368)
+D 2006-08-25T23:42:53
 F Makefile.in 8e7f9ecebab2c6e0f3db20ff129a8f9405ab64f8
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -54,7 +54,7 @@ F src/expr.c 0546cc60f08c426d96092dea0789d085aed3580e
 F src/func.c dd9cea8ed3246d7a4c49fd01034d470d5702b8b0
 F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185
 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
-F src/insert.c 63f01d3f4e0ba7ed171934a24aece2191824faec
+F src/insert.c 924d3cdd59a47d4a506fd13420b9c0b32d5ed377
 F src/legacy.c 10e01a902d7f2c872c7922fedf19a2df70935857
 F src/loadext.c 7a41142266dd2570fedf00108e1772047f98a673
 F src/main.c 96ab5f29fe903aa8a28f6e1463a3b8245bf1c416
@@ -72,7 +72,7 @@ F src/os_win.c c6976ae50b61fb5b7dce399e578aa1865f02b84f
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
 F src/pager.c e51c079b3cad8394898a6c22330150339103700a
 F src/pager.h 0cff9de5e9019cb695a04d18df8caaaff933a272
-F src/parse.y ec897a969f2b0488878f63c286bf466d38c55710
+F src/parse.y b26898e5270c3dc58798047e72cd57113663f761
 F src/pragma.c dcb79b8170231f3aed99d4004b4d0a0fc14c4b4d
 F src/prepare.c 84e2c855600c7bfbe2ca691b263301de525f9123
 F src/printf.c b179b6ed12f793e028dd169e2e2e2b2a37eedc63
@@ -84,7 +84,7 @@ F src/sqlite.h.in 84ac26ca94a84dd603fb57a27d862f51bfd9f687
 F src/sqlite3ext.h 11a046b3519c4b9b7709e6d6a95c3a36366f684a
 F src/sqliteInt.h 325a2d45be2b22c1e21ad649e0a898c74eaec7de
 F src/table.c d8817f43a6c6bf139487db161760b9e1e02da3f1
-F src/tclsqlite.c b706556687f0113e01d0574b0caa59c1cd4f3034
+F src/tclsqlite.c 4e97383988f6349b01f11b55946536a46e247aa3
 F src/test1.c 535294d7f21a4127082c4f7a57f225482df9cc36
 F src/test2.c ca74a1d8aeb7d9606e8f6b762c5daf85c1a3f92b
 F src/test3.c 85135c09560c48bdb0a23c9b890ab405486b8ec9
@@ -192,7 +192,7 @@ F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
 F test/index3.test f66718cd92ce1216819d47e6a156755e4b2c4ca1
 F test/insert.test 42e26d9192f36859938765e6817fb957cf19532b
 F test/insert2.test 5a20e1ace5fa0800b58d28284212290189b49aed
-F test/insert3.test 0096bd9766f94f4fa06ef712658e590b782cb44f
+F test/insert3.test 09a532d5b6f3a788d91be0d4d368462f522685d1
 F test/interrupt.test c38b7f7c17914f0cd6a119beed5d03bc3f47f9eb
 F test/intpkey.test af4fd826c4784ec5c93b444de07adea0254d0d30
 F test/ioerr.test 804d56cfa698e7c90590921f984eb49ceb30c2a9
@@ -388,7 +388,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P e029637e54e190c89206725a99e1ee7db6c23804
-R 9ce35272ab9df42e9d49ed3b7fe1ef36
-U shess
-Z 3eca536fbc68da4d34c55754ff00f971
+P a6fcf9101a831bf5f129c6045eabf30376d365dc
+R 80b06007a2365db4d7bc49bb74bd766d
+U drh
+Z 3665a6d74cbe1ba1fd5fe6a0a1a1da6c
index d5c22d2603e2172819cba4c6e08f85521c7d1e40..0379321b01e91afbf4a69ab33977e1a0b2903360 100644 (file)
@@ -1 +1 @@
-a6fcf9101a831bf5f129c6045eabf30376d365dc
\ No newline at end of file
+bc84cb54b0df09738fd90e48820dc3cdfa7828c2
\ No newline at end of file
index 0c79d6e61e7825b7c42c1a57685afd8147b759fd..2ee5c79e261376ba55122667682b6c773500ad08 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.170 2006/06/19 03:05:10 danielk1977 Exp $
+** $Id: insert.c,v 1.171 2006/08/25 23:42:53 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -387,11 +387,9 @@ void sqlite3Insert(
     NameContext sNC;
     memset(&sNC, 0, sizeof(sNC));
     sNC.pParse = pParse;
-    assert( pList!=0 );
     srcTab = -1;
     useTempTable = 0;
-    assert( pList );
-    nColumn = pList->nExpr;
+    nColumn = pList ? pList->nExpr : 0;
     for(i=0; i<nColumn; i++){
       if( sqlite3ExprResolveNames(&sNC, pList->a[i].pExpr) ){
         goto insert_cleanup;
@@ -402,7 +400,7 @@ void sqlite3Insert(
   /* Make sure the number of columns in the source data matches the number
   ** of columns to be inserted into the table.
   */
-  if( pColumn==0 && nColumn!=pTab->nCol ){
+  if( pColumn==0 && nColumn && nColumn!=pTab->nCol ){
     sqlite3ErrorMsg(pParse, 
        "table %S has %d columns but %d values were supplied",
        pTabList, 0, pTab->nCol, nColumn);
@@ -455,7 +453,7 @@ void sqlite3Insert(
   ** key, the set the keyColumn variable to the primary key column index
   ** in the original table definition.
   */
-  if( pColumn==0 ){
+  if( pColumn==0 && nColumn>0 ){
     keyColumn = pTab->iPKey;
   }
 
@@ -618,7 +616,7 @@ void sqlite3Insert(
           if( pColumn->a[j].idx==i ) break;
         }
       }
-      if( pColumn && j>=pColumn->nId ){
+      if( nColumn==0 || (pColumn && j>=pColumn->nId) ){
         sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
       }else if( useTempTable ){
         sqlite3VdbeAddOp(v, OP_Column, srcTab, j); 
index 0c0575362c3fa7ded2543c6a9ff48d4059653e6e..f9445113c4730a831e2fcd662b6e80548d71bde0 100644 (file)
@@ -14,7 +14,7 @@
 ** the parser.  Lemon will also generate a header file containing
 ** numeric codes for all of the tokens.
 **
-** @(#) $Id: parse.y,v 1.207 2006/08/14 14:23:42 drh Exp $
+** @(#) $Id: parse.y,v 1.208 2006/08/25 23:42:53 drh Exp $
 */
 
 // All token codes are small integers with #defines that begin with "TK_"
@@ -600,6 +600,8 @@ cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F)
             {sqlite3Insert(pParse, X, Y, 0, F, R);}
 cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) select(S).
             {sqlite3Insert(pParse, X, 0, S, F, R);}
+cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) DEFAULT VALUES.
+            {sqlite3Insert(pParse, X, 0, 0, F, R);}
 
 %type insert_cmd {int}
 insert_cmd(A) ::= INSERT orconf(R).   {A = R;}
index e7b317041c9aaea6250620777276a3da629b364e..6222083786023c688154f212476e36bf3d30da50 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** A TCL Interface to SQLite
 **
-** $Id: tclsqlite.c,v 1.169 2006/08/24 14:59:46 drh Exp $
+** $Id: tclsqlite.c,v 1.170 2006/08/25 23:42:53 drh Exp $
 */
 #ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
 
@@ -2073,8 +2073,6 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
   zArg = Tcl_GetStringFromObj(objv[1], 0);
   Tcl_CreateObjCommand(interp, zArg, DbObjCmd, (char*)p, DbDeleteCmd);
 
-  /* If a TCL procedure named "::sqlite3_init
-
   /* If compiled with SQLITE_TEST turned on, then register the "md5sum"
   ** SQL function.
   */
index a6a3a6bf72080636cdc3088b42a2c932d6ca19f9..62af4ddae189262a5e030a1cd0004b385e5ba148 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing corner cases of the INSERT statement.
 #
-# $Id: insert3.test,v 1.4 2006/01/23 18:42:21 drh Exp $
+# $Id: insert3.test,v 1.5 2006/08/25 23:42:53 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -138,4 +138,31 @@ do_test insert3-3.4 {
 
 } ;# ifcapable {trigger}
 
+# Tests for the INSERT INTO ... DEFAULT VALUES construct
+#
+do_test insert4-3.5 {
+  execsql {
+    CREATE TABLE t5(
+      a INTEGER PRIMARY KEY,
+      b DEFAULT 'xyz'
+    );
+    INSERT INTO t5 DEFAULT VALUES;
+    SELECT * FROM t5;
+  }
+} {1 xyz}
+do_test insert4-3.6 {
+  execsql {
+    INSERT INTO t5 DEFAULT VALUES;
+    SELECT * FROM t5;
+  }
+} {1 xyz 2 xyz}
+do_test insert4-3.7 {
+  execsql {
+    CREATE TABLE t6(x,y DEFAULT 4.3, z DEFAULT x'6869');
+    INSERT INTO t6 DEFAULT VALUES;
+    SELECT * FROM t6;
+  }
+} {{} 4.3 hi}
+
+
 finish_test