Port the "DEFAULT CURRENT_TIME" etc. functionality from an earlier fork of sqlite. (CVS 2082)
FossilOrigin-Name: 0d27c8ff48f327ad82dd5b5b3b47b8d221f119b7
This commit is contained in:
parent
0ba87cb85d
commit
7977a17f06
28
manifest
28
manifest
@ -1,5 +1,5 @@
|
||||
C Refactor\sthe\sspace-analysis\sscript\sfor\sreadability.\s(CVS\s2081)
|
||||
D 2004-11-09T07:42:11
|
||||
C Port\sthe\s"DEFAULT\sCURRENT_TIME"\setc.\sfunctionality\sfrom\san\searlier\sfork\sof\ssqlite.\s(CVS\s2082)
|
||||
D 2004-11-09T12:44:38
|
||||
F Makefile.in c4d2416860f472a1e3393714d0372074197565df
|
||||
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
||||
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
|
||||
@ -31,14 +31,14 @@ F src/attach.c e49d09dad9f5f9fb10b4b0c1be5a70ae4c45e689
|
||||
F src/auth.c 3b81f2a42f48a62c2c9c9b0eda31a157c681edea
|
||||
F src/btree.c 63a84350a18f6ca68f16e2a12018b5041444a2df
|
||||
F src/btree.h 861e40b759a195ba63819740e484390012cf81ab
|
||||
F src/build.c f01c2f9b3ad334a301e97ee4f299c36228ead110
|
||||
F src/date.c 34bdb0082db7ec2a83ef00063f7b44e61ee19dad
|
||||
F src/build.c d623d84fd7f4e9cc0c5e8d1b96aab7886cf0f84d
|
||||
F src/date.c dbf15c130ba2c0231c642b65a361d41dbc02db95
|
||||
F src/delete.c f0af21a1ede15524a5edd59fe10ef486283a1ee9
|
||||
F src/expr.c be18081d2959a2cc53846d0fbedfec40fbfa1d6e
|
||||
F src/expr.c 5f9afecf27e048b8f3627b5a9be3136bc1d9bdf1
|
||||
F src/func.c 600e506bccf7648df8ad03efb417560d0f7ad4c1
|
||||
F src/hash.c a97721a55440b7bea31ffe471bb2f6b4123cddd5
|
||||
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
|
||||
F src/insert.c 3fd6e00c9f62ad14daa94c75ae9971c32119f97e
|
||||
F src/insert.c 8bd40dc5a8e470cba5b9b14211fa88ea0350d2fa
|
||||
F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
|
||||
F src/main.c ba1b26f03af4b7f8be3394748123dd671b9ea147
|
||||
F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
|
||||
@ -54,14 +54,14 @@ F src/os_win.c 9482dfc92f289b68205bb2c9315757c7e3946bfb
|
||||
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
|
||||
F src/pager.c 2653787b86267c079283b8128541095f0febac4f
|
||||
F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862
|
||||
F src/parse.y 8456726833755ecd6dac9bcd8af205c8dc419d01
|
||||
F src/pragma.c 6a0ae7721e614c5a921e918ab5206d5e654f1a6f
|
||||
F src/parse.y 0af8d009cab3a30b967ab75dc260967d87b20496
|
||||
F src/pragma.c 44074b93216516b01cafacd85cb10621088693dd
|
||||
F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357
|
||||
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
|
||||
F src/select.c 156990c636102bb6b8de85e7ff3396a62568476b
|
||||
F src/shell.c 55adda3cf3c1cc2f6c1919aac17b2318f9c2a96f
|
||||
F src/sqlite.h.in 4f97b5907acfd2a5068cb0cec9d5178816734db7
|
||||
F src/sqliteInt.h 9f846c4b752b9a1237e8250f8f8b3ecd1347a086
|
||||
F src/sqliteInt.h 61133357ecd4bebbb2389d14e70d8ca99c7530ef
|
||||
F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
|
||||
F src/tclsqlite.c 0302e3f42f015d132d1291f3388c06e86c24a008
|
||||
F src/test1.c 91345097d94b4ad71f88776c2764e18c7955502a
|
||||
@ -119,7 +119,7 @@ F test/diskfull.test e2f6cfd868713ead06dc82b84a4938e868128fc0
|
||||
F test/enc.test 2f5463af488d50aef60c6110bec6b21b5efba961
|
||||
F test/enc2.test 7a60971a62748be6b607b4b4380eb4c5e151a6ec
|
||||
F test/enc3.test a96f4a7c44bac4d63bdc4ff422b8049912083998
|
||||
F test/expr.test 91358521f8ec41cd0fd1c5370c93104265f1fefc
|
||||
F test/expr.test a1855a3b47c0deab92e7b6a6d419a52782e7a67e
|
||||
F test/fkey1.test 81bb13caaa78f58d7d191d7f535529f7c91d821a
|
||||
F test/func.test 830d352574c7f5cd15149a9be58a6dcc2b995c05
|
||||
F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda
|
||||
@ -173,7 +173,7 @@ F test/select6.test 4ce9fa563662d5b2f5a8ff57e4d8b2f5cd186d38
|
||||
F test/select7.test c71c822a82c80bbd55558b4b69d35442dfe22ffd
|
||||
F test/sort.test c97c1a3289337b1dc349ac8a59e0780d2dcfd90b
|
||||
F test/subselect.test 50f98723f00e97b1839d36410ee63597ca82d775
|
||||
F test/table.test 109155b5a9aa6c11411c0351181bb6f0f2269d87
|
||||
F test/table.test 54081854744733598af2122451b97b59d64ae894
|
||||
F test/tableapi.test b21ab097e87a5484bb61029e69e1a4e5c5e65ede
|
||||
F test/tclsqlite.test 5e262df81a638a058536fb6d6666f316843ac7b2
|
||||
F test/temptable.test 63a16e3ad19adf073cfbcdf7624c92ac5236522c
|
||||
@ -254,7 +254,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25
|
||||
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
|
||||
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
||||
F www/whentouse.tcl fdacb0ba2d39831e8a6240d05a490026ad4c4e4c
|
||||
P 1cb8086612c7dec170da0910cf0cbe4e48c417f8
|
||||
R eadc5f0d5be30b3316f4f1cee213f451
|
||||
P 63f2ee22e20ed7e520fd9230acc5c6db43b69d13
|
||||
R c7c1616611e1356d29290318a6cf79f2
|
||||
U danielk1977
|
||||
Z ec6f06cb278db00adede15242b5bb8a0
|
||||
Z ee44e58703e5c1b5ed5b43c2151ec560
|
||||
|
@ -1 +1 @@
|
||||
63f2ee22e20ed7e520fd9230acc5c6db43b69d13
|
||||
0d27c8ff48f327ad82dd5b5b3b47b8d221f119b7
|
32
src/build.c
32
src/build.c
@ -22,7 +22,7 @@
|
||||
** COMMIT
|
||||
** ROLLBACK
|
||||
**
|
||||
** $Id: build.c,v 1.273 2004/11/07 13:01:50 drh Exp $
|
||||
** $Id: build.c,v 1.274 2004/11/09 12:44:38 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@ -388,7 +388,7 @@ static void sqliteResetColumnNames(Table *pTable){
|
||||
assert( pTable!=0 );
|
||||
for(i=0, pCol=pTable->aCol; i<pTable->nCol; i++, pCol++){
|
||||
sqliteFree(pCol->zName);
|
||||
sqliteFree(pCol->zDflt);
|
||||
sqlite3ExprDelete(pCol->pDflt);
|
||||
sqliteFree(pCol->zType);
|
||||
}
|
||||
sqliteFree(pTable->aCol);
|
||||
@ -851,23 +851,29 @@ void sqlite3AddColumnType(Parse *pParse, Token *pFirst, Token *pLast){
|
||||
}
|
||||
|
||||
/*
|
||||
** The given token is the default value for the last column added to
|
||||
** the table currently under construction. If "minusFlag" is true, it
|
||||
** means the value token was preceded by a minus sign.
|
||||
** The expression is the default value for the most recently added column
|
||||
** of the table currently under construction.
|
||||
**
|
||||
** Default value expressions must be constant. Raise an exception if this
|
||||
** is not the case.
|
||||
**
|
||||
** This routine is called by the parser while in the middle of
|
||||
** parsing a CREATE TABLE statement.
|
||||
*/
|
||||
void sqlite3AddDefaultValue(Parse *pParse, Token *pVal, int minusFlag){
|
||||
void sqlite3AddDefaultValue(Parse *pParse, Expr *pExpr){
|
||||
Table *p;
|
||||
int i;
|
||||
char *z;
|
||||
Column *pCol;
|
||||
if( (p = pParse->pNewTable)==0 ) return;
|
||||
i = p->nCol-1;
|
||||
if( i<0 ) return;
|
||||
assert( p->aCol[i].zDflt==0 );
|
||||
z = p->aCol[i].zDflt = sqlite3MPrintf("%s%T", minusFlag ? "-" : "", pVal);
|
||||
sqlite3Dequote(z);
|
||||
pCol = &(p->aCol[p->nCol-1]);
|
||||
if( !sqlite3ExprIsConstant(pExpr) ){
|
||||
sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
|
||||
pCol->zName);
|
||||
}else{
|
||||
sqlite3ExprDelete(pCol->pDflt);
|
||||
pCol->pDflt = sqlite3ExprDup(pExpr);
|
||||
sqlite3ExprCheck(pParse, pExpr, 0, 0);
|
||||
}
|
||||
sqlite3ExprDelete(pExpr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
58
src/date.c
58
src/date.c
@ -16,7 +16,7 @@
|
||||
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: date.c,v 1.37 2004/10/06 15:41:16 drh Exp $
|
||||
** $Id: date.c,v 1.38 2004/11/09 12:44:38 danielk1977 Exp $
|
||||
**
|
||||
** NOTES:
|
||||
**
|
||||
@ -862,7 +862,59 @@ static void strftimeFunc(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** current_time()
|
||||
**
|
||||
** This function returns the same value as time('now').
|
||||
*/
|
||||
static void ctimeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_value *pVal = sqlite3ValueNew();
|
||||
if( pVal ){
|
||||
sqlite3ValueSetStr(pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC);
|
||||
timeFunc(context, 1, &pVal);
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** current_date()
|
||||
**
|
||||
** This function returns the same value as date('now').
|
||||
*/
|
||||
static void cdateFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_value *pVal = sqlite3ValueNew();
|
||||
if( pVal ){
|
||||
sqlite3ValueSetStr(pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC);
|
||||
dateFunc(context, 1, &pVal);
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** current_timestamp()
|
||||
**
|
||||
** This function returns the same value as datetime('now').
|
||||
*/
|
||||
static void ctimestampFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_value *pVal = sqlite3ValueNew();
|
||||
if( pVal ){
|
||||
sqlite3ValueSetStr(pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC);
|
||||
datetimeFunc(context, 1, &pVal);
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
|
||||
|
||||
/*
|
||||
@ -882,6 +934,9 @@ void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
|
||||
{ "time", -1, timeFunc },
|
||||
{ "datetime", -1, datetimeFunc },
|
||||
{ "strftime", -1, strftimeFunc },
|
||||
{ "current_time", 0, ctimeFunc },
|
||||
{ "current_timestamp", 0, ctimestampFunc },
|
||||
{ "current_date", 0, cdateFunc },
|
||||
};
|
||||
int i;
|
||||
|
||||
@ -891,3 +946,4 @@ void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
33
src/expr.c
33
src/expr.c
@ -12,7 +12,7 @@
|
||||
** This file contains routines used for analyzing expressions and
|
||||
** for generating VDBE code that evaluates expressions in SQLite.
|
||||
**
|
||||
** $Id: expr.c,v 1.168 2004/11/05 05:10:29 drh Exp $
|
||||
** $Id: expr.c,v 1.169 2004/11/09 12:44:38 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@ -573,6 +573,9 @@ int sqlite3ExprIsConstant(Expr *p){
|
||||
case TK_INTEGER:
|
||||
case TK_FLOAT:
|
||||
case TK_VARIABLE:
|
||||
case TK_CTIME:
|
||||
case TK_CTIMESTAMP:
|
||||
case TK_CDATE:
|
||||
return 1;
|
||||
default: {
|
||||
if( p->pLeft && !sqlite3ExprIsConstant(p->pLeft) ) return 0;
|
||||
@ -1080,6 +1083,21 @@ static void getFunctionName(Expr *pExpr, const char **pzName, int *pnName){
|
||||
*pnName = 4;
|
||||
break;
|
||||
}
|
||||
case TK_CTIME: {
|
||||
*pzName = "current_time";
|
||||
*pnName = 12;
|
||||
break;
|
||||
}
|
||||
case TK_CDATE: {
|
||||
*pzName = "current_date";
|
||||
*pnName = 12;
|
||||
break;
|
||||
}
|
||||
case TK_CTIMESTAMP: {
|
||||
*pzName = "current_timestamp";
|
||||
*pnName = 17;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
*pzName = "can't happen";
|
||||
*pnName = 12;
|
||||
@ -1101,6 +1119,10 @@ int sqlite3ExprCheck(Parse *pParse, Expr *pExpr, int allowAgg, int *pIsAgg){
|
||||
int nErr = 0;
|
||||
if( pExpr==0 ) return 0;
|
||||
switch( pExpr->op ){
|
||||
case TK_CTIME:
|
||||
case TK_CTIMESTAMP:
|
||||
case TK_CDATE:
|
||||
/* Note: The above three were a seperate case in sqlmoto. Reason? */
|
||||
case TK_GLOB:
|
||||
case TK_LIKE:
|
||||
case TK_FUNCTION: {
|
||||
@ -1220,7 +1242,11 @@ static void codeInteger(Vdbe *v, const char *z, int n){
|
||||
void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
int op;
|
||||
if( v==0 || pExpr==0 ) return;
|
||||
if( v==0 ) return;
|
||||
if( pExpr==0 ){
|
||||
sqlite3VdbeAddOp(v, OP_String8, 0, 0); /* Empty expression evals to NULL */
|
||||
return;
|
||||
}
|
||||
op = pExpr->op;
|
||||
switch( op ){
|
||||
case TK_COLUMN: {
|
||||
@ -1357,6 +1383,9 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
|
||||
sqlite3VdbeAddOp(v, OP_AggGet, 0, pExpr->iAgg);
|
||||
break;
|
||||
}
|
||||
case TK_CDATE:
|
||||
case TK_CTIME:
|
||||
case TK_CTIMESTAMP:
|
||||
case TK_GLOB:
|
||||
case TK_LIKE:
|
||||
case TK_FUNCTION: {
|
||||
|
10
src/insert.c
10
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.123 2004/11/05 17:17:50 drh Exp $
|
||||
** $Id: insert.c,v 1.124 2004/11/09 12:44:38 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@ -490,7 +490,7 @@ void sqlite3Insert(
|
||||
}
|
||||
}
|
||||
if( pColumn && j>=pColumn->nId ){
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
|
||||
}else if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, srcTab, j);
|
||||
}else if( pSelect ){
|
||||
@ -571,7 +571,7 @@ void sqlite3Insert(
|
||||
}
|
||||
}
|
||||
if( pColumn && j>=pColumn->nId ){
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
|
||||
}else if( useTempTable ){
|
||||
sqlite3VdbeAddOp(v, OP_Column, srcTab, j);
|
||||
}else if( pSelect ){
|
||||
@ -772,7 +772,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
}else if( onError==OE_Default ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
if( onError==OE_Replace && pTab->aCol[i].zDflt==0 ){
|
||||
if( onError==OE_Replace && pTab->aCol[i].pDflt==0 ){
|
||||
onError = OE_Abort;
|
||||
}
|
||||
sqlite3VdbeAddOp(v, OP_Dup, nCol-1-i, 1);
|
||||
@ -794,7 +794,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
break;
|
||||
}
|
||||
case OE_Replace: {
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
|
||||
sqlite3VdbeAddOp(v, OP_Push, nCol-i, 0);
|
||||
break;
|
||||
}
|
||||
|
34
src/parse.y
34
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.150 2004/11/05 23:46:15 drh Exp $
|
||||
** @(#) $Id: parse.y,v 1.151 2004/11/09 12:44:38 danielk1977 Exp $
|
||||
*/
|
||||
%token_prefix TK_
|
||||
%token_type {Token}
|
||||
@ -203,10 +203,16 @@ carglist ::= carglist carg.
|
||||
carglist ::= .
|
||||
carg ::= CONSTRAINT nm ccons.
|
||||
carg ::= ccons.
|
||||
carg ::= DEFAULT ids(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT plus_num(X). {sqlite3AddDefaultValue(pParse,&X,0);}
|
||||
carg ::= DEFAULT minus_num(X). {sqlite3AddDefaultValue(pParse,&X,1);}
|
||||
carg ::= DEFAULT NULL.
|
||||
carg ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,X);}
|
||||
carg ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,X);}
|
||||
carg ::= DEFAULT MINUS term(X). {
|
||||
Expr *p = sqlite3Expr(TK_UMINUS, X, 0, 0);
|
||||
sqlite3AddDefaultValue(pParse,p);
|
||||
}
|
||||
carg ::= DEFAULT id(X). {
|
||||
Expr *p = sqlite3Expr(TK_STRING, 0, 0, &X);
|
||||
sqlite3AddDefaultValue(pParse,p);
|
||||
}
|
||||
|
||||
// In addition to the type name, we also care about the primary key and
|
||||
// UNIQUE constraints.
|
||||
@ -567,9 +573,12 @@ inscollist(A) ::= nm(Y). {A = sqlite3IdListAppend(0,&Y);}
|
||||
|
||||
%type expr {Expr*}
|
||||
%destructor expr {sqlite3ExprDelete($$);}
|
||||
%type term {Expr*}
|
||||
%destructor term {sqlite3ExprDelete($$);}
|
||||
|
||||
expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); }
|
||||
expr(A) ::= NULL(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= term(X). {A = X;}
|
||||
term(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); }
|
||||
term(A) ::= NULL(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= ID(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= JOIN_KW(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);}
|
||||
expr(A) ::= nm(X) DOT nm(Y). {
|
||||
@ -584,9 +593,9 @@ expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
|
||||
Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
|
||||
A = sqlite3Expr(TK_DOT, temp1, temp4, 0);
|
||||
}
|
||||
expr(A) ::= INTEGER(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= FLOAT(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= INTEGER(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= FLOAT(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
term(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);}
|
||||
expr(A) ::= REGISTER(X). {A = sqlite3RegisterExpr(pParse, &X);}
|
||||
expr(A) ::= VARIABLE(X). {
|
||||
@ -594,7 +603,7 @@ expr(A) ::= VARIABLE(X). {
|
||||
Expr *pExpr = A = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
|
||||
sqlite3ExprAssignVarNumber(pParse, pExpr);
|
||||
}
|
||||
expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
|
||||
term(A) ::= ID(X) LP exprlist(Y) RP(E). {
|
||||
A = sqlite3ExprFunction(Y, &X);
|
||||
sqlite3ExprSpan(A,&X,&E);
|
||||
}
|
||||
@ -602,6 +611,9 @@ expr(A) ::= ID(X) LP STAR RP(E). {
|
||||
A = sqlite3ExprFunction(0, &X);
|
||||
sqlite3ExprSpan(A,&X,&E);
|
||||
}
|
||||
term(A) ::= CTIME(OP). {A = sqlite3Expr(@OP,0,0,0);}
|
||||
term(A) ::= CDATE(OP). {A = sqlite3Expr(@OP,0,0,0);}
|
||||
term(A) ::= CTIMESTAMP(OP). {A = sqlite3Expr(@OP,0,0,0);}
|
||||
expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
expr(A) ::= expr(X) LT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
|
||||
|
@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the PRAGMA command.
|
||||
**
|
||||
** $Id: pragma.c,v 1.74 2004/11/05 15:45:11 danielk1977 Exp $
|
||||
** $Id: pragma.c,v 1.75 2004/11/09 12:44:38 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@ -406,8 +406,7 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
|
||||
sqlite3VdbeOp3(v, OP_String8, 0, 0,
|
||||
pTab->aCol[i].zDflt, P3_STATIC);
|
||||
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
|
||||
sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
|
||||
sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.335 2004/11/05 23:46:15 drh Exp $
|
||||
** @(#) $Id: sqliteInt.h,v 1.336 2004/11/09 12:44:39 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef _SQLITEINT_H_
|
||||
#define _SQLITEINT_H_
|
||||
@ -488,7 +488,7 @@ struct FuncDef {
|
||||
*/
|
||||
struct Column {
|
||||
char *zName; /* Name of this column */
|
||||
char *zDflt; /* Default value of this column */
|
||||
Expr *pDflt; /* Default value of this column */
|
||||
char *zType; /* Data type for this column */
|
||||
CollSeq *pColl; /* Collating sequence. If NULL, use the default */
|
||||
u8 notNull; /* True if there is a NOT NULL constraint */
|
||||
@ -1277,7 +1277,7 @@ void sqlite3AddColumn(Parse*,Token*);
|
||||
void sqlite3AddNotNull(Parse*, int);
|
||||
void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int);
|
||||
void sqlite3AddColumnType(Parse*,Token*,Token*);
|
||||
void sqlite3AddDefaultValue(Parse*,Token*,int);
|
||||
void sqlite3AddDefaultValue(Parse*,Expr*);
|
||||
void sqlite3AddCollateType(Parse*, const char*, int);
|
||||
void sqlite3EndTable(Parse*,Token*,Select*);
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing expressions.
|
||||
#
|
||||
# $Id: expr.test,v 1.36 2004/08/20 18:34:20 drh Exp $
|
||||
# $Id: expr.test,v 1.37 2004/11/09 12:44:39 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -474,5 +474,30 @@ test_expr2 expr-7.61 {GLOB('1?',a)} {10 11 12 13 14 15 16 17 18 19}
|
||||
test_expr2 expr-7.62 {GLOB('1*4',b)} {10 14}
|
||||
test_expr2 expr-7.63 {GLOB('*1[456]',b)} {4}
|
||||
|
||||
# Test the CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP expressions.
|
||||
#
|
||||
set sqlite_current_time [clock seconds]
|
||||
set date [clock format $sqlite_current_time -format %Y-%m-%d -gmt 1]
|
||||
set time [clock format $sqlite_current_time -format %H:%M:%S -gmt 1]
|
||||
do_test expr-8.1 {
|
||||
execsql {SELECT CURRENT_TIME==time('now');}
|
||||
} 1
|
||||
do_test expr-8.2 {
|
||||
execsql {SELECT CURRENT_TIME}
|
||||
} $time
|
||||
do_test expr-8.3 {
|
||||
execsql {SELECT CURRENT_DATE==date('now');}
|
||||
} 1
|
||||
do_test expr-8.4 {
|
||||
execsql {SELECT CURRENT_DATE}
|
||||
} $date
|
||||
do_test expr-8.5 {
|
||||
execsql {SELECT CURRENT_TIMESTAMP==datetime('now');}
|
||||
} 1
|
||||
do_test expr-8.6 {
|
||||
execsql {SELECT CURRENT_TIMESTAMP}
|
||||
} [list "$date $time"]
|
||||
set sqlite_current_time 0
|
||||
|
||||
finish_test
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the CREATE TABLE statement.
|
||||
#
|
||||
# $Id: table.test,v 1.30 2004/11/03 16:27:02 drh Exp $
|
||||
# $Id: table.test,v 1.31 2004/11/09 12:44:39 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -524,4 +524,36 @@ do_test table-12.2 {
|
||||
}
|
||||
} {{CREATE TABLE t8(b number(5,10),h,i integer,j BLOB)}}
|
||||
|
||||
# Test the ability to have default values of CURRENT_TIME, CURRENT_DATE
|
||||
# and CURRENT_TIMESTAMP.
|
||||
#
|
||||
do_test table-13.1 {
|
||||
execsql {
|
||||
CREATE TABLE tablet8(
|
||||
a integer primary key,
|
||||
tm text DEFAULT CURRENT_TIME,
|
||||
dt text DEFAULT CURRENT_DATE,
|
||||
dttm text DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
SELECT * FROM tablet8;
|
||||
}
|
||||
} {}
|
||||
set i 0
|
||||
foreach {date time} {
|
||||
1976-07-04 12:00:00
|
||||
1994-04-16 14:00:00
|
||||
2000-01-01 00:00:00
|
||||
2003-12-31 12:34:56
|
||||
} {
|
||||
incr i
|
||||
set sqlite_current_time [execsql "SELECT strftime('%s','$date $time')"]
|
||||
do_test table-13.2.$i {
|
||||
execsql "
|
||||
INSERT INTO tablet8(a) VALUES($i);
|
||||
SELECT tm, dt, dttm FROM tablet8 WHERE a=$i;
|
||||
"
|
||||
} [list $time $date [list $date $time]]
|
||||
}
|
||||
set sqlite_current_time 0
|
||||
|
||||
finish_test
|
||||
|
Loading…
Reference in New Issue
Block a user