Add support for INSERT INTO ... DEFAULT VALUES.  Tickets #299, #1940. (CVS 3368)

FossilOrigin-Name: bc84cb54b0df09738fd90e48820dc3cdfa7828c2
diff --git a/src/insert.c b/src/insert.c
index 0c79d6e..2ee5c79 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -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 @@
     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 @@
   /* 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 @@
   ** 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 @@
           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); 
diff --git a/src/parse.y b/src/parse.y
index 0c05753..f944511 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -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 @@
             {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;}
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index e7b3170..6222083 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -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 @@
   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.
   */