]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Allow the default value for columns added using ALTER TABLE ADD COLUMN to be a functi...
authordan <dan@noemail.net>
Wed, 11 Mar 2015 20:59:42 +0000 (20:59 +0000)
committerdan <dan@noemail.net>
Wed, 11 Mar 2015 20:59:42 +0000 (20:59 +0000)
FossilOrigin-Name: ff868e22ca0393eaac417872a4c10738f0d7d970

manifest
manifest.uuid
src/alter.c
src/vdbemem.c

index 60c76c5cba670675a5fb397680407b8b7f5a371e..421022d674cbb6ce615f4657dffd884a1e573f40 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Allow\sthe\squery\splanner\sto\sevaluate\sdeterministic\sscalar\sSQL\sfunctions\sused\sin\sWHERE\sconstraints\sif\sall\sarguments\sare\sSQL\sliterals\sin\sorder\sto\scompare\sthe\sresults\swith\ssqlite_stat4\ssample\sdata.
-D 2015-03-11T20:06:40.904
+C Allow\sthe\sdefault\svalue\sfor\scolumns\sadded\susing\sALTER\sTABLE\sADD\sCOLUMN\sto\sbe\sa\sfunction\sin\sexisting\sschemas\sloaded\sfrom\sdisk.\sBut\sprevent\sthis\sversion\sof\sSQLite\sfrom\sbeing\sused\sto\screate\ssuch\sa\scolumn.
+D 2015-03-11T20:59:42.115
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -166,7 +166,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
 F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
 F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
-F src/alter.c ba266a779bc7ce10e52e59e7d3dc79fa342e8fdb
+F src/alter.c 809313ddb2dea2a8cdd2d0da944d6a859e3657dc
 F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d
 F src/attach.c 880f9b8641a829c563e52dd13c452ce457ae4dd8
 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
@@ -299,7 +299,7 @@ F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a
 F src/vdbeapi.c 5c207659c8a57c12c3f77a8fb97544e032fc2f14
 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5
 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90
-F src/vdbemem.c 8572106eb3b64ad6e02698c0fb312ccb47bb5c9e
+F src/vdbemem.c 85dd9cb7a98717ad821d388c10053da2fe66f0f7
 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2
 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010
 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01
@@ -1242,10 +1242,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P a2715b049a86555990abccc7aa363c524ddb9982
-R 8289f5b5a84378b5cf3294cc8646b1fb
-T *branch * stat4-function
-T *sym-stat4-function *
-T -sym-trunk *
+P b7f1fc26d24012e1e7c7f6b3cc0b84ad2b02b8ad
+R 3e606265a1ac491b0b1ab16052f58807
 U dan
-Z a4cf4e61f3250d5413e8887a5d5cd094
+Z 8153e0e591b223bdb869dacd2f48bbd5
index 28f0ab069bf17d1009ae8c84baf79f44060e33c0..906c7ad764a3c79349717910b7fa46fb597643e2 100644 (file)
@@ -1 +1 @@
-b7f1fc26d24012e1e7c7f6b3cc0b84ad2b02b8ad
\ No newline at end of file
+ff868e22ca0393eaac417872a4c10738f0d7d970
\ No newline at end of file
index dd060248b8f7a97500426c5ce8acc368943f9123..908b251f06d9c585e936807b49fc738f26bce35d 100644 (file)
@@ -690,7 +690,9 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
   */
   if( pDflt ){
     sqlite3_value *pVal = 0;
-    if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
+    if( pDflt->op!=TK_FUNCTION
+     && sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) 
+    ){
       db->mallocFailed = 1;
       return;
     }
index ce7b73deace976781ae79711985b286eb34b57ba..269afe148c2dca0dcc89762ac8e551c93f77045b 100644 (file)
@@ -1139,11 +1139,8 @@ static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
 ** to be a scalar SQL function. If
 **
 **   * all function arguments are SQL literals,
-**   * the SQLITE_FUNC_CONSTANT function flag is set,
-**   * the SQLITE_FUNC_NEEDCOLL function flag is not set, and
-**   * this routine is being invoked as part of examining stat4 data,
-**     not as part of handling a default value on a column created using
-**     ALTER TABLE ADD COLUMN, 
+**   * the SQLITE_FUNC_CONSTANT function flag is set, and
+**   * the SQLITE_FUNC_NEEDCOLL function flag is not set,
 **
 ** then this routine attempts to invoke the SQL function. Assuming no
 ** error occurs, output parameter (*ppVal) is set to point to a value 
@@ -1173,27 +1170,13 @@ static int valueFromFunction(
   sqlite3_value *pVal = 0;        /* New value */
   int rc = SQLITE_OK;             /* Return code */
   int nName;                      /* Size of function name in bytes */
-  ExprList *pList;                /* Function arguments */
+  ExprList *pList = 0;            /* Function arguments */
   int i;                          /* Iterator variable */
 
-  /* If pCtx==0, then this is probably being called to to obtain an 
-  ** sqlite3_value object for the default value of a column. In that case
-  ** function expressions are not supported. Function expressions are
-  ** only supported when extracting values to compare with sqlite_stat4 
-  ** records.
-  **
-  ** It may also be that this function expression is an argument passed
-  ** to another function expression. As in "f2(...)" within the query:
-  **
-  **   SELECT * FROM tbl WHERE tbl.c = f1(0, f2(...), 1);
-  **
-  ** For now, extracting the value of "f1(...)" is not supported either.
-  */
-  if( pCtx==0 ) return SQLITE_OK;
-  
-  assert( (p->flags & (EP_TokenOnly|EP_Reduced))==0 );
-  pList = p->x.pList;
-  if( pList ) nVal = pList->nExpr;
+  if( (p->flags & EP_TokenOnly)==0 ){
+    pList = p->x.pList;
+    if( pList ) nVal = pList->nExpr;
+  }
   nName = sqlite3Strlen30(p->u.zToken);
   pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
   assert( pFunc );
@@ -1228,7 +1211,7 @@ static int valueFromFunction(
   pFunc->xFunc(&ctx, nVal, apVal);
   if( ctx.isError ){
     rc = ctx.isError;
-    sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
+    if( pCtx ) sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
   }else{
     sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8);
     if( rc==SQLITE_OK ){