From: drh Date: Mon, 14 Aug 2006 14:23:41 +0000 (+0000) Subject: Change the table_info pragma to show the text of the default value expression, X-Git-Tag: version-3.6.10~2814 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=417ec6381f3946ae0b692a35329b622ae71b5092;p=thirdparty%2Fsqlite.git Change the table_info pragma to show the text of the default value expression, not the result of evaluating the default value expression. Ticket #1919. (CVS 3353) FossilOrigin-Name: b4d53974c30d195c061cc7605a707d7d30c52740 --- diff --git a/manifest b/manifest index 27f8b41e0a..f53f774797 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Adjust\sthe\sMakefile.in\sso\sthat\sthere\sare\sno\stest\serrors\swhen\susing\nthe\sconfigure\sscript.\s\sTicket\s#1918.\s(CVS\s3352) -D 2006-08-13T21:49:08 +C Change\sthe\stable_info\spragma\sto\sshow\sthe\stext\sof\sthe\sdefault\svalue\sexpression,\r\nnot\sthe\sresult\sof\sevaluating\sthe\sdefault\svalue\sexpression.\r\nTicket\s#1919.\s(CVS\s3353) +D 2006-08-14T14:23:42 F Makefile.in 986db66b0239b460fc118e7d2fa88b45b26c444e F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -36,7 +36,7 @@ F src/attach.c b11eb4d5d3fb99a10a626956bccc7215f6b68b16 F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f F src/btree.c b39b7147d400b4906a48850b83d22b0c2a641007 F src/btree.h 061c50e37de7f50b58528e352d400cf33ead7418 -F src/build.c 2ea8ad0e2e49b3957692588182524e6c390ab5a9 +F src/build.c 4359b34a36938716ed10ac037eec9dc5173b8f4b F src/callback.c fd9bb39f7ff6b52bad8365617abc61c720640429 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675 F src/date.c cd2bd5d1ebc6fa12d6312f69789ae5b0a2766f2e @@ -64,8 +64,8 @@ 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 ecac666005bec0c813681a81de88d1de5d27577f -F src/pragma.c cc12939bb74a6e28eb2e867e75175eecffe089a1 +F src/parse.y ec897a969f2b0488878f63c286bf466d38c55710 +F src/pragma.c dcb79b8170231f3aed99d4004b4d0a0fc14c4b4d F src/prepare.c 84e2c855600c7bfbe2ca691b263301de525f9123 F src/printf.c b179b6ed12f793e028dd169e2e2e2b2a37eedc63 F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261 @@ -224,7 +224,7 @@ F test/pager.test 6ee95e90ee8295e376e39a6c6566ef6df993601a F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4 F test/pagesize.test 05c74ea49f790734ec1e9ab765d9bf1cce79b8f2 -F test/pragma.test e2d72d9e9a24744356cd5a4d25ea842c5020d345 +F test/pragma.test b81f483cac7b8fe519988a102303799cc72d25a2 F test/printf.test cdd8e20dd901382a385afcbaa777b9377815c2ad F test/progress.test 8b22b4974b0a95272566385f8cb8c341c7130df8 x F test/quick.test 4eabf0fd67dc6e116cbebe3f8d899608239eae50 @@ -377,7 +377,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P dfc833ac79cb255902b20700d6d8949a66af093f -R e1cc72cb7c6e1344e7ec904d59f232df +P 6a25be921b7255e540952fc213e145ae3b56daf0 +R f4e4c034fd68390ec0fdfad99db713ed U drh -Z 943f77acaa1a7c5b768deaacaf18e194 +Z b7bd1406595f5fdc7d4072dd1c34cd85 diff --git a/manifest.uuid b/manifest.uuid index 8e9018312e..01d0fed955 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6a25be921b7255e540952fc213e145ae3b56daf0 \ No newline at end of file +b4d53974c30d195c061cc7605a707d7d30c52740 \ No newline at end of file diff --git a/src/build.c b/src/build.c index b379225aa1..1f7a9267d5 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.409 2006/07/26 16:22:15 danielk1977 Exp $ +** $Id: build.c,v 1.410 2006/08/14 14:23:42 drh Exp $ */ #include "sqliteInt.h" #include @@ -1077,8 +1077,12 @@ void sqlite3AddDefaultValue(Parse *pParse, Expr *pExpr){ sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant", pCol->zName); }else{ + Expr *pCopy; sqlite3ExprDelete(pCol->pDflt); - pCol->pDflt = sqlite3ExprDup(pExpr); + pCol->pDflt = pCopy = sqlite3ExprDup(pExpr); + if( pCopy ){ + sqlite3TokenCopy(&pCopy->span, &pExpr->span); + } } } sqlite3ExprDelete(pExpr); diff --git a/src/parse.y b/src/parse.y index c5b6c09990..0c0575362c 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.206 2006/07/11 10:42:36 drh Exp $ +** @(#) $Id: parse.y,v 1.207 2006/08/14 14:23:42 drh Exp $ */ // All token codes are small integers with #defines that begin with "TK_" @@ -676,7 +676,10 @@ term(A) ::= CTIME_KW(OP). { /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are ** treated as functions that return constants */ A = sqlite3ExprFunction(0,&OP); - if( A ) A->op = TK_CONST_FUNC; + if( A ){ + A->op = TK_CONST_FUNC; + A->span = OP; + } } 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);} diff --git a/src/pragma.c b/src/pragma.c index 299278746f..85374e79e5 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.121 2006/08/08 13:51:43 drh Exp $ +** $Id: pragma.c,v 1.122 2006/08/14 14:23:42 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -482,12 +482,15 @@ void sqlite3Pragma( sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC); sqlite3ViewGetColumnNames(pParse, pTab); for(i=0, pCol=pTab->aCol; inCol; i++, pCol++){ + const Token *pDflt; + static const Token noDflt = { (unsigned char*)"", 0, 0 }; sqlite3VdbeAddOp(v, OP_Integer, i, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zType ? pCol->zType : "", 0); sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0); - sqlite3ExprCode(pParse, pCol->pDflt); + pDflt = pCol->pDflt ? &pCol->pDflt->span : &noDflt; + sqlite3VdbeOp3(v, OP_String8, 0, 0, (char*)pDflt->z, pDflt->n); sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0); sqlite3VdbeAddOp(v, OP_Callback, 6, 0); } diff --git a/test/pragma.test b/test/pragma.test index 705abd70b0..9965401fa5 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -12,7 +12,7 @@ # # This file implements tests for the PRAGMA command. # -# $Id: pragma.test,v 1.43 2006/06/20 11:01:09 danielk1977 Exp $ +# $Id: pragma.test,v 1.44 2006/08/14 14:23:43 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -351,6 +351,12 @@ do_test pragma-6.2 { pragma table_info(t2) } } {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} +do_test pragma-6.2.2 { + execsql { + CREATE TABLE t5(a TEXT DEFAULT CURRENT_TIMESTAMP, b DEFAULT (5+3)); + PRAGMA table_info(t5); + } +} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0} ifcapable {foreignkey} { do_test pragma-6.3 { execsql {