Mario Frasca wrote:
I'm throwing this here, I assume that it would not be too much work to
complete this patch. the aim is to support the sql92 syntax insert
into <table> default values;
all right, a possible complete patch, maybe could be added to the
rest... don't tell me that it looks ugly, I totally agree, but it
behaves as described... :)
regards,
MF
cvs diff: Diffing src
Index: src/insert.c
===================================================================
RCS file: /sqlite/sqlite/src/insert.c,v
retrieving revision 1.170
diff -u -r1.170 insert.c
--- src/insert.c 19 Jun 2006 03:05:10 -0000 1.170
+++ src/insert.c 1 Aug 2006 11:56:15 -0000
@@ -123,6 +123,7 @@
**
** insert into TABLE (IDLIST) values(EXPRLIST)
** insert into TABLE (IDLIST) select
+** insert into TABLE default values
**
** The IDLIST following the table name is always optional. If omitted,
** then a list of all columns for the table is substituted. The IDLIST
@@ -380,14 +381,36 @@
}else{
sqlite3VdbeJumpHere(v, iInitCode);
}
- }else{
+ }else if (pList == 0){
+ assert( pColumn == 0 );
+ /* This is the case if no data has been supplied and DEFAULT VALUES are
+ ** to be inserted. this is a minimalistic impact approach... a fake
+ ** list of columns containing just the primary key and a fake list of
+ ** values containing just a NULL are created, as if the user had issued
+ ** the SQL command: "insert into <table> (<pkey>) values (NULL)". the
+ ** rest of the function remains untouched. error messages are issued if
+ ** the equivalent command causes them.
+ */
+ Expr *A;
+ Token the_null = { (u8*)"NULL", 0, 4 };
+
+ A = sqlite3Expr(TK_NULL, 0, 0, &the_null);
+ pList = sqlite3ExprListAppend(0,A,0);
+ nColumn = 1; /* same as pList->nExpr */
+
+ Token the_pkey = { 0, 0, 0 };
+ the_pkey.z = pTab->aCol[pTab->iPKey].zName;
+ the_pkey.n = strlen(pTab->aCol[pTab->iPKey].zName);
+
+ pColumn = sqlite3IdListAppend(0, &the_pkey);
+
+ } else{
/* This is the case if the data for the INSERT is coming from a VALUES
** clause
*/
NameContext sNC;
memset(&sNC, 0, sizeof(sNC));
sNC.pParse = pParse;
- assert( pList!=0 );
srcTab = -1;
useTempTable = 0;
assert( pList );
Index: src/parse.y
===================================================================
RCS file: /sqlite/sqlite/src/parse.y,v
retrieving revision 1.206
diff -u -r1.206 parse.y
--- src/parse.y 11 Jul 2006 10:42:36 -0000 1.206
+++ src/parse.y 1 Aug 2006 11:56:16 -0000
@@ -598,6 +598,10 @@
cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F)
VALUES LP itemlist(Y) RP.
{sqlite3Insert(pParse, X, Y, 0, F, R);}
+cmd ::= insert_cmd(R) INTO fullname(X) DEFAULT VALUES.
+ { sqlite3Insert(pParse, X, 0, 0, 0, R);}
+cmd ::= insert_cmd(R) INTO fullname(X) LP RP VALUES LP RP.
+ { sqlite3Insert(pParse, X, 0, 0, 0, R);}
cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) select(S).
{sqlite3Insert(pParse, X, 0, S, F, R);}
cvs diff: Diffing src/ex