/ Check-in [d0719ad7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update this branch with latest changes from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | server-process-edition
Files: files | file ages | folders
SHA3-256: d0719ad757bdf7cf2d7d7a4f7b0e713c262ffb434b91ddbb12e190e479abd19e
User & Date: dan 2017-07-24 19:43:58
Context
2017-07-28
21:02
Reduce the number of mallocs required of writers in server mode. check-in: 60953997 user: dan tags: server-process-edition
2017-07-24
19:43
Update this branch with latest changes from trunk. check-in: d0719ad7 user: dan tags: server-process-edition
19:25
Do not attempt to run test file unionvtab.test with SQLITE_OMIT_VIRTUAL_TABLE builds. check-in: 9a5a3d60 user: dan tags: trunk
19:23
Only open a db in server-mode if there is a directory named "db-journal" in the file-system and the VFS is an exclusive locking VFS. check-in: e77d29f6 user: dan tags: server-process-edition
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/date.c.

   382    382     DateTime *p
   383    383   ){
   384    384     double r;
   385    385     if( parseYyyyMmDd(zDate,p)==0 ){
   386    386       return 0;
   387    387     }else if( parseHhMmSs(zDate, p)==0 ){
   388    388       return 0;
   389         -  }else if( sqlite3StrICmp(zDate,"now")==0){
          389  +  }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){
   390    390       return setDateTimeToCurrent(context, p);
   391    391     }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
   392    392       setRawDateNumber(p, r);
   393    393       return 0;
   394    394     }
   395    395     return 1;
   396    396   }
................................................................................
   665    665   #ifndef SQLITE_OMIT_LOCALTIME
   666    666       case 'l': {
   667    667         /*    localtime
   668    668         **
   669    669         ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
   670    670         ** show local time.
   671    671         */
   672         -      if( sqlite3_stricmp(z, "localtime")==0 ){
          672  +      if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
   673    673           computeJD(p);
   674    674           p->iJD += localtimeOffset(p, pCtx, &rc);
   675    675           clearYMD_HMS_TZ(p);
   676    676         }
   677    677         break;
   678    678       }
   679    679   #endif
................................................................................
   691    691             p->iJD = (sqlite3_int64)r;
   692    692             p->validJD = 1;
   693    693             p->rawS = 0;
   694    694             rc = 0;
   695    695           }
   696    696         }
   697    697   #ifndef SQLITE_OMIT_LOCALTIME
   698         -      else if( sqlite3_stricmp(z, "utc")==0 ){
          698  +      else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
   699    699           if( p->tzSet==0 ){
   700    700             sqlite3_int64 c1;
   701    701             computeJD(p);
   702    702             c1 = localtimeOffset(p, pCtx, &rc);
   703    703             if( rc==SQLITE_OK ){
   704    704               p->iJD -= c1;
   705    705               clearYMD_HMS_TZ(p);
................................................................................
  1227   1227   ** This function registered all of the above C functions as SQL
  1228   1228   ** functions.  This should be the only routine in this file with
  1229   1229   ** external linkage.
  1230   1230   */
  1231   1231   void sqlite3RegisterDateTimeFunctions(void){
  1232   1232     static FuncDef aDateTimeFuncs[] = {
  1233   1233   #ifndef SQLITE_OMIT_DATETIME_FUNCS
  1234         -    DFUNCTION(julianday,        -1, 0, 0, juliandayFunc ),
  1235         -    DFUNCTION(date,             -1, 0, 0, dateFunc      ),
  1236         -    DFUNCTION(time,             -1, 0, 0, timeFunc      ),
  1237         -    DFUNCTION(datetime,         -1, 0, 0, datetimeFunc  ),
  1238         -    DFUNCTION(strftime,         -1, 0, 0, strftimeFunc  ),
         1234  +    PURE_DATE(julianday,        -1, 0, 0, juliandayFunc ),
         1235  +    PURE_DATE(date,             -1, 0, 0, dateFunc      ),
         1236  +    PURE_DATE(time,             -1, 0, 0, timeFunc      ),
         1237  +    PURE_DATE(datetime,         -1, 0, 0, datetimeFunc  ),
         1238  +    PURE_DATE(strftime,         -1, 0, 0, strftimeFunc  ),
  1239   1239       DFUNCTION(current_time,      0, 0, 0, ctimeFunc     ),
  1240   1240       DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
  1241   1241       DFUNCTION(current_date,      0, 0, 0, cdateFunc     ),
  1242   1242   #else
  1243   1243       STR_FUNCTION(current_time,      0, "%H:%M:%S",          0, currentTimeFunc),
  1244   1244       STR_FUNCTION(current_date,      0, "%Y-%m-%d",          0, currentTimeFunc),
  1245   1245       STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
  1246   1246   #endif
  1247   1247     };
  1248   1248     sqlite3InsertBuiltinFuncs(aDateTimeFuncs, ArraySize(aDateTimeFuncs));
  1249   1249   }

Changes to src/delete.c.

   848    848     int j;
   849    849     int regBase;
   850    850     int nCol;
   851    851   
   852    852     if( piPartIdxLabel ){
   853    853       if( pIdx->pPartIdxWhere ){
   854    854         *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
   855         -      pParse->iSelfTab = iDataCur;
          855  +      pParse->iSelfTab = iDataCur + 1;
   856    856         sqlite3ExprCachePush(pParse);
   857    857         sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel, 
   858    858                               SQLITE_JUMPIFNULL);
          859  +      pParse->iSelfTab = 0;
   859    860       }else{
   860    861         *piPartIdxLabel = 0;
   861    862       }
   862    863     }
   863    864     nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
   864    865     regBase = sqlite3GetTempRange(pParse, nCol);
   865    866     if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;

Changes to src/expr.c.

  3234   3234     int iIdxCol,    /* The column of the index to be loaded */
  3235   3235     int regOut      /* Store the index column value in this register */
  3236   3236   ){
  3237   3237     i16 iTabCol = pIdx->aiColumn[iIdxCol];
  3238   3238     if( iTabCol==XN_EXPR ){
  3239   3239       assert( pIdx->aColExpr );
  3240   3240       assert( pIdx->aColExpr->nExpr>iIdxCol );
  3241         -    pParse->iSelfTab = iTabCur;
         3241  +    pParse->iSelfTab = iTabCur + 1;
  3242   3242       sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
         3243  +    pParse->iSelfTab = 0;
  3243   3244     }else{
  3244   3245       sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
  3245   3246                                       iTabCol, regOut);
  3246   3247     }
  3247   3248   }
  3248   3249   
  3249   3250   /*
................................................................................
  3479   3480           return target;
  3480   3481         }
  3481   3482         /* Otherwise, fall thru into the TK_COLUMN case */
  3482   3483       }
  3483   3484       case TK_COLUMN: {
  3484   3485         int iTab = pExpr->iTable;
  3485   3486         if( iTab<0 ){
  3486         -        if( pParse->ckBase>0 ){
         3487  +        if( pParse->iSelfTab<0 ){
  3487   3488             /* Generating CHECK constraints or inserting into partial index */
  3488         -          return pExpr->iColumn + pParse->ckBase;
         3489  +          return pExpr->iColumn - pParse->iSelfTab;
  3489   3490           }else{
  3490   3491             /* Coding an expression that is part of an index where column names
  3491   3492             ** in the index refer to the table to which the index belongs */
  3492         -          iTab = pParse->iSelfTab;
         3493  +          iTab = pParse->iSelfTab - 1;
  3493   3494           }
  3494   3495         }
  3495   3496         return sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
  3496   3497                                  pExpr->iColumn, iTab, target,
  3497   3498                                  pExpr->op2);
  3498   3499       }
  3499   3500       case TK_INTEGER: {
................................................................................
  3822   3823           pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
  3823   3824         }
  3824   3825   #endif
  3825   3826         if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
  3826   3827           if( !pColl ) pColl = db->pDfltColl; 
  3827   3828           sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
  3828   3829         }
  3829         -      sqlite3VdbeAddOp4(v, OP_Function0, constMask, r1, target,
  3830         -                        (char*)pDef, P4_FUNCDEF);
         3830  +      sqlite3VdbeAddOp4(v, pParse->iSelfTab ? OP_PureFunc0 : OP_Function0,
         3831  +                        constMask, r1, target, (char*)pDef, P4_FUNCDEF);
  3831   3832         sqlite3VdbeChangeP5(v, (u8)nFarg);
  3832   3833         if( nFarg && constMask==0 ){
  3833   3834           sqlite3ReleaseTempRange(pParse, r1, nFarg);
  3834   3835         }
  3835   3836         return target;
  3836   3837       }
  3837   3838   #ifndef SQLITE_OMIT_SUBQUERY

Changes to src/insert.c.

  1329   1329     }
  1330   1330   
  1331   1331     /* Test all CHECK constraints
  1332   1332     */
  1333   1333   #ifndef SQLITE_OMIT_CHECK
  1334   1334     if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
  1335   1335       ExprList *pCheck = pTab->pCheck;
  1336         -    pParse->ckBase = regNewData+1;
         1336  +    pParse->iSelfTab = -(regNewData+1);
  1337   1337       onError = overrideError!=OE_Default ? overrideError : OE_Abort;
  1338   1338       for(i=0; i<pCheck->nExpr; i++){
  1339   1339         int allOk;
  1340   1340         Expr *pExpr = pCheck->a[i].pExpr;
  1341   1341         if( aiChng && checkConstraintUnchanged(pExpr, aiChng, pkChng) ) continue;
  1342   1342         allOk = sqlite3VdbeMakeLabel(v);
  1343   1343         sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL);
................................................................................
  1349   1349           if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
  1350   1350           sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
  1351   1351                                 onError, zName, P4_TRANSIENT,
  1352   1352                                 P5_ConstraintCheck);
  1353   1353         }
  1354   1354         sqlite3VdbeResolveLabel(v, allOk);
  1355   1355       }
         1356  +    pParse->iSelfTab = 0;
  1356   1357     }
  1357   1358   #endif /* !defined(SQLITE_OMIT_CHECK) */
  1358   1359   
  1359   1360     /* If rowid is changing, make sure the new rowid does not previously
  1360   1361     ** exist in the table.
  1361   1362     */
  1362   1363     if( pkChng && pPk==0 ){
................................................................................
  1493   1494       }
  1494   1495       iThisCur = iIdxCur+ix;
  1495   1496       addrUniqueOk = sqlite3VdbeMakeLabel(v);
  1496   1497   
  1497   1498       /* Skip partial indices for which the WHERE clause is not true */
  1498   1499       if( pIdx->pPartIdxWhere ){
  1499   1500         sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
  1500         -      pParse->ckBase = regNewData+1;
         1501  +      pParse->iSelfTab = -(regNewData+1);
  1501   1502         sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, addrUniqueOk,
  1502   1503                               SQLITE_JUMPIFNULL);
  1503         -      pParse->ckBase = 0;
         1504  +      pParse->iSelfTab = 0;
  1504   1505       }
  1505   1506   
  1506   1507       /* Create a record for this index entry as it should appear after
  1507   1508       ** the insert or update.  Store that record in the aRegIdx[ix] register
  1508   1509       */
  1509   1510       regIdx = aRegIdx[ix]+1;
  1510   1511       for(i=0; i<pIdx->nColumn; i++){
  1511   1512         int iField = pIdx->aiColumn[i];
  1512   1513         int x;
  1513   1514         if( iField==XN_EXPR ){
  1514         -        pParse->ckBase = regNewData+1;
         1515  +        pParse->iSelfTab = -(regNewData+1);
  1515   1516           sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
  1516         -        pParse->ckBase = 0;
         1517  +        pParse->iSelfTab = 0;
  1517   1518           VdbeComment((v, "%s column %d", pIdx->zName, i));
  1518   1519         }else{
  1519   1520           if( iField==XN_ROWID || iField==pTab->iPKey ){
  1520   1521             x = regNewData;
  1521   1522           }else{
  1522   1523             x = iField + regNewData + 1;
  1523   1524           }

Changes to src/pragma.c.

  1617   1617           if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
  1618   1618             ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
  1619   1619             if( db->mallocFailed==0 ){
  1620   1620               int addrCkFault = sqlite3VdbeMakeLabel(v);
  1621   1621               int addrCkOk = sqlite3VdbeMakeLabel(v);
  1622   1622               char *zErr;
  1623   1623               int k;
  1624         -            pParse->iSelfTab = iDataCur;
         1624  +            pParse->iSelfTab = iDataCur + 1;
  1625   1625               sqlite3ExprCachePush(pParse);
  1626   1626               for(k=pCheck->nExpr-1; k>0; k--){
  1627   1627                 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
  1628   1628               }
  1629   1629               sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, 
  1630   1630                   SQLITE_JUMPIFNULL);
  1631   1631               sqlite3VdbeResolveLabel(v, addrCkFault);
         1632  +            pParse->iSelfTab = 0;
  1632   1633               zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
  1633   1634                   pTab->zName);
  1634   1635               sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
  1635   1636               integrityCheckResultRow(v, 3);
  1636   1637               sqlite3VdbeResolveLabel(v, addrCkOk);
  1637   1638               sqlite3ExprCachePop(pParse);
  1638   1639             }

Changes to src/shell.c.

  8392   8392     find_home_dir(1);
  8393   8393   #if !SQLITE_SHELL_IS_UTF8
  8394   8394     for(i=0; i<argc; i++) sqlite3_free(argv[i]);
  8395   8395     sqlite3_free(argv);
  8396   8396   #endif
  8397   8397     return rc;
  8398   8398   }
  8399         -

Changes to src/sqlite.h.in.

  3644   3644     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  3645   3645     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  3646   3646   );
  3647   3647   int sqlite3_prepare16_v3(
  3648   3648     sqlite3 *db,            /* Database handle */
  3649   3649     const void *zSql,       /* SQL statement, UTF-16 encoded */
  3650   3650     int nByte,              /* Maximum length of zSql in bytes. */
  3651         -  unsigned int prepFalgs, /* Zero or more SQLITE_PREPARE_ flags */
         3651  +  unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
  3652   3652     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  3653   3653     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  3654   3654   );
  3655   3655   
  3656   3656   /*
  3657   3657   ** CAPI3REF: Retrieving Statement SQL
  3658   3658   ** METHOD: sqlite3_stmt
................................................................................
  3889   3889   ** ^The sqlite3_bind_pointer(S,I,P,T) routine causes the I-th parameter in
  3890   3890   ** [prepared statement] S to have an SQL value of NULL, but to also be
  3891   3891   ** associated with the pointer P of type T.
  3892   3892   ** ^The sqlite3_bind_pointer() routine can be used to pass
  3893   3893   ** host-language pointers into [application-defined SQL functions].
  3894   3894   ** ^A parameter that is initialized using [sqlite3_bind_pointer()] appears
  3895   3895   ** to be an ordinary SQL NULL value to everything other than
  3896         -** [sqlite3_value_pointer()].  The T parameter should be a static string.
         3896  +** [sqlite3_value_pointer()].  The T parameter should be a static string,
         3897  +** preferably a string literal.  The procedure that invokes 
         3898  +** sqlite3_bind_pointer(S,I,P,T) continues to own the P and T pointers and
         3899  +** must guarantee that those pointers remain valid until after the last
         3900  +** access via [sqlite3_value_pointer()].  The sqlite3_bind_pointer() routine
         3901  +** is part of the [pointer passing interface] added for SQLite 3.20.0.
  3897   3902   **
  3898   3903   ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
  3899   3904   ** for the [prepared statement] or with a prepared statement for which
  3900   3905   ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
  3901   3906   ** then the call will return [SQLITE_MISUSE].  If any sqlite3_bind_()
  3902   3907   ** routine is passed a [prepared statement] that has been finalized, the
  3903   3908   ** result is undefined and probably harmful.
................................................................................
  5100   5105   ** kind of [sqlite3_value] object can be used with this interface.
  5101   5106   **
  5102   5107   ** ^The sqlite3_result_pointer(C,P,T) interface sets the result to an
  5103   5108   ** SQL NULL value, just like [sqlite3_result_null(C)], except that it
  5104   5109   ** also associates the host-language pointer P or type T with that 
  5105   5110   ** NULL value such that the pointer can be retrieved within an
  5106   5111   ** [application-defined SQL function] using [sqlite3_value_pointer()].
  5107         -** The T parameter should be a static string.
  5108         -** This mechanism can be used to pass non-SQL values between
  5109         -** application-defined functions.
         5112  +** The T parameter should be a static string and preferably a string
         5113  +** literal. The procedure that invokes sqlite3_result_pointer(C,P,T)
         5114  +** continues to own the P and T pointers and must guarantee that 
         5115  +** those pointers remain valid until after the last access via
         5116  +** [sqlite3_value_pointer()].  The sqlite3_result_pointer() routine
         5117  +** is part of the [pointer passing interface] added for SQLite 3.20.0.
  5110   5118   **
  5111   5119   ** If these routines are called from within the different thread
  5112   5120   ** than the one containing the application-defined function that received
  5113   5121   ** the [sqlite3_context] pointer, the results are undefined.
  5114   5122   */
  5115   5123   void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  5116   5124   void sqlite3_result_blob64(sqlite3_context*,const void*,

Changes to src/sqliteInt.h.

  1626   1626   **   VFUNCTION(zName, nArg, iArg, bNC, xFunc)
  1627   1627   **     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
  1628   1628   **
  1629   1629   **   DFUNCTION(zName, nArg, iArg, bNC, xFunc)
  1630   1630   **     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
  1631   1631   **     adds the SQLITE_FUNC_SLOCHNG flag.  Used for date & time functions
  1632   1632   **     and functions like sqlite_version() that can change, but not during
  1633         -**     a single query.
         1633  +**     a single query.  The iArg is ignored.  The user-data is always set
         1634  +**     to a NULL pointer.  The bNC parameter is not used.
         1635  +**
         1636  +**   PURE_DATE(zName, nArg, iArg, bNC, xFunc)
         1637  +**     Used for "pure" date/time functions, this macro is like DFUNCTION
         1638  +**     except that it does set the SQLITE_FUNC_CONSTANT flags.  iArg is
         1639  +**     ignored and the user-data for these functions is set to an 
         1640  +**     arbitrary non-NULL pointer.  The bNC parameter is not used.
  1634   1641   **
  1635   1642   **   AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
  1636   1643   **     Used to create an aggregate function definition implemented by
  1637   1644   **     the C functions xStep and xFinal. The first four parameters
  1638   1645   **     are interpreted in the same way as the first 4 parameters to
  1639   1646   **     FUNCTION().
  1640   1647   **
................................................................................
  1649   1656   #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
  1650   1657     {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
  1651   1658      SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
  1652   1659   #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
  1653   1660     {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
  1654   1661      SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
  1655   1662   #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
  1656         -  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
  1657         -   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
         1663  +  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
         1664  +   0, 0, xFunc, 0, #zName, {0} }
         1665  +#define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
         1666  +  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
         1667  +   (void*)&sqlite3Config, 0, xFunc, 0, #zName, {0} }
  1658   1668   #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
  1659   1669     {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
  1660   1670      SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
  1661   1671   #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
  1662   1672     {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
  1663   1673      pArg, 0, xFunc, 0, #zName, }
  1664   1674   #define LIKEFUNC(zName, nArg, arg, flags) \
................................................................................
  2951   2961     int nRangeReg;       /* Size of the temporary register block */
  2952   2962     int iRangeReg;       /* First register in temporary register block */
  2953   2963     int nErr;            /* Number of errors seen */
  2954   2964     int nTab;            /* Number of previously allocated VDBE cursors */
  2955   2965     int nMem;            /* Number of memory cells used so far */
  2956   2966     int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
  2957   2967     int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  2958         -  int ckBase;          /* Base register of data during check constraints */
  2959         -  int iSelfTab;        /* Table of an index whose exprs are being coded */
         2968  +  int iSelfTab;        /* Table for associated with an index on expr, or negative
         2969  +                       ** of the base register during check-constraint eval */
  2960   2970     int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
  2961   2971     int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
  2962   2972     int nLabel;          /* Number of labels used */
  2963   2973     int *aLabel;         /* Space to hold the labels */
  2964   2974     ExprList *pConstExpr;/* Constant expressions */
  2965   2975     Token constraintName;/* Name of the constraint currently being parsed */
  2966   2976     yDbMask writeMask;   /* Start a write transaction on these databases */

Changes to src/test_blob.c.

   237    237     ){ 
   238    238       return TCL_ERROR;
   239    239     }
   240    240   
   241    241     if( nByte>0 ){
   242    242       zBuf = (unsigned char *)Tcl_AttemptAlloc(nByte);
   243    243       if( zBuf==0 ){
   244         -      Tcl_AppendResult(interp, "out of memory", 0);
          244  +      Tcl_AppendResult(interp, "out of memory in " __FILE__, 0);
   245    245         return TCL_ERROR;
   246    246       }
   247    247     }
   248    248     rc = sqlite3_blob_read(pBlob, zBuf, nByte, iOffset);
   249    249     if( rc==SQLITE_OK ){
   250    250       Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zBuf, nByte));
   251    251     }else{

Changes to src/vdbe.c.

  1586   1586     assert( pOp->p4type==P4_COLLSEQ );
  1587   1587     if( pOp->p1 ){
  1588   1588       sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
  1589   1589     }
  1590   1590     break;
  1591   1591   }
  1592   1592   
  1593         -/* Opcode: Function0 P1 P2 P3 P4 P5
  1594         -** Synopsis: r[P3]=func(r[P2@P5])
  1595         -**
  1596         -** Invoke a user function (P4 is a pointer to a FuncDef object that
  1597         -** defines the function) with P5 arguments taken from register P2 and
  1598         -** successors.  The result of the function is stored in register P3.
  1599         -** Register P3 must not be one of the function inputs.
  1600         -**
  1601         -** P1 is a 32-bit bitmask indicating whether or not each argument to the 
  1602         -** function was determined to be constant at compile time. If the first
  1603         -** argument was constant then bit 0 of P1 is set. This is used to determine
  1604         -** whether meta data associated with a user function argument using the
  1605         -** sqlite3_set_auxdata() API may be safely retained until the next
  1606         -** invocation of this opcode.
  1607         -**
  1608         -** See also: Function, AggStep, AggFinal
  1609         -*/
  1610         -/* Opcode: Function P1 P2 P3 P4 P5
  1611         -** Synopsis: r[P3]=func(r[P2@P5])
  1612         -**
  1613         -** Invoke a user function (P4 is a pointer to an sqlite3_context object that
  1614         -** contains a pointer to the function to be run) with P5 arguments taken
  1615         -** from register P2 and successors.  The result of the function is stored
  1616         -** in register P3.  Register P3 must not be one of the function inputs.
  1617         -**
  1618         -** P1 is a 32-bit bitmask indicating whether or not each argument to the 
  1619         -** function was determined to be constant at compile time. If the first
  1620         -** argument was constant then bit 0 of P1 is set. This is used to determine
  1621         -** whether meta data associated with a user function argument using the
  1622         -** sqlite3_set_auxdata() API may be safely retained until the next
  1623         -** invocation of this opcode.
  1624         -**
  1625         -** SQL functions are initially coded as OP_Function0 with P4 pointing
  1626         -** to a FuncDef object.  But on first evaluation, the P4 operand is
  1627         -** automatically converted into an sqlite3_context object and the operation
  1628         -** changed to this OP_Function opcode.  In this way, the initialization of
  1629         -** the sqlite3_context object occurs only once, rather than once for each
  1630         -** evaluation of the function.
  1631         -**
  1632         -** See also: Function0, AggStep, AggFinal
  1633         -*/
  1634         -case OP_Function0: {
  1635         -  int n;
  1636         -  sqlite3_context *pCtx;
  1637         -
  1638         -  assert( pOp->p4type==P4_FUNCDEF );
  1639         -  n = pOp->p5;
  1640         -  assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
  1641         -  assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
  1642         -  assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
  1643         -  pCtx = sqlite3DbMallocRawNN(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
  1644         -  if( pCtx==0 ) goto no_mem;
  1645         -  pCtx->pOut = 0;
  1646         -  pCtx->pFunc = pOp->p4.pFunc;
  1647         -  pCtx->iOp = (int)(pOp - aOp);
  1648         -  pCtx->pVdbe = p;
  1649         -  pCtx->argc = n;
  1650         -  pOp->p4type = P4_FUNCCTX;
  1651         -  pOp->p4.pCtx = pCtx;
  1652         -  pOp->opcode = OP_Function;
  1653         -  /* Fall through into OP_Function */
  1654         -}
  1655         -case OP_Function: {
  1656         -  int i;
  1657         -  sqlite3_context *pCtx;
  1658         -
  1659         -  assert( pOp->p4type==P4_FUNCCTX );
  1660         -  pCtx = pOp->p4.pCtx;
  1661         -
  1662         -  /* If this function is inside of a trigger, the register array in aMem[]
  1663         -  ** might change from one evaluation to the next.  The next block of code
  1664         -  ** checks to see if the register array has changed, and if so it
  1665         -  ** reinitializes the relavant parts of the sqlite3_context object */
  1666         -  pOut = &aMem[pOp->p3];
  1667         -  if( pCtx->pOut != pOut ){
  1668         -    pCtx->pOut = pOut;
  1669         -    for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
  1670         -  }
  1671         -
  1672         -  memAboutToChange(p, pOut);
  1673         -#ifdef SQLITE_DEBUG
  1674         -  for(i=0; i<pCtx->argc; i++){
  1675         -    assert( memIsValid(pCtx->argv[i]) );
  1676         -    REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
  1677         -  }
  1678         -#endif
  1679         -  MemSetTypeFlag(pOut, MEM_Null);
  1680         -  pCtx->fErrorOrAux = 0;
  1681         -  (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
  1682         -
  1683         -  /* If the function returned an error, throw an exception */
  1684         -  if( pCtx->fErrorOrAux ){
  1685         -    if( pCtx->isError ){
  1686         -      sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut));
  1687         -      rc = pCtx->isError;
  1688         -    }
  1689         -    sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
  1690         -    if( rc ) goto abort_due_to_error;
  1691         -  }
  1692         -
  1693         -  /* Copy the result of the function into register P3 */
  1694         -  if( pOut->flags & (MEM_Str|MEM_Blob) ){
  1695         -    sqlite3VdbeChangeEncoding(pOut, encoding);
  1696         -    if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
  1697         -  }
  1698         -
  1699         -  REGISTER_TRACE(pOp->p3, pOut);
  1700         -  UPDATE_MAX_BLOBSIZE(pOut);
  1701         -  break;
  1702         -}
  1703         -
  1704   1593   /* Opcode: BitAnd P1 P2 P3 * *
  1705   1594   ** Synopsis: r[P3]=r[P1]&r[P2]
  1706   1595   **
  1707   1596   ** Take the bit-wise AND of the values in register P1 and P2 and
  1708   1597   ** store the result in register P3.
  1709   1598   ** If either input is NULL, the result is NULL.
  1710   1599   */
................................................................................
  7024   6913       newMax = sqlite3BtreeLastPage(pBt);
  7025   6914       if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3;
  7026   6915     }
  7027   6916     pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax);
  7028   6917     break;
  7029   6918   }
  7030   6919   #endif
         6920  +
         6921  +/* Opcode: Function0 P1 P2 P3 P4 P5
         6922  +** Synopsis: r[P3]=func(r[P2@P5])
         6923  +**
         6924  +** Invoke a user function (P4 is a pointer to a FuncDef object that
         6925  +** defines the function) with P5 arguments taken from register P2 and
         6926  +** successors.  The result of the function is stored in register P3.
         6927  +** Register P3 must not be one of the function inputs.
         6928  +**
         6929  +** P1 is a 32-bit bitmask indicating whether or not each argument to the 
         6930  +** function was determined to be constant at compile time. If the first
         6931  +** argument was constant then bit 0 of P1 is set. This is used to determine
         6932  +** whether meta data associated with a user function argument using the
         6933  +** sqlite3_set_auxdata() API may be safely retained until the next
         6934  +** invocation of this opcode.
         6935  +**
         6936  +** See also: Function, AggStep, AggFinal
         6937  +*/
         6938  +/* Opcode: Function P1 P2 P3 P4 P5
         6939  +** Synopsis: r[P3]=func(r[P2@P5])
         6940  +**
         6941  +** Invoke a user function (P4 is a pointer to an sqlite3_context object that
         6942  +** contains a pointer to the function to be run) with P5 arguments taken
         6943  +** from register P2 and successors.  The result of the function is stored
         6944  +** in register P3.  Register P3 must not be one of the function inputs.
         6945  +**
         6946  +** P1 is a 32-bit bitmask indicating whether or not each argument to the 
         6947  +** function was determined to be constant at compile time. If the first
         6948  +** argument was constant then bit 0 of P1 is set. This is used to determine
         6949  +** whether meta data associated with a user function argument using the
         6950  +** sqlite3_set_auxdata() API may be safely retained until the next
         6951  +** invocation of this opcode.
         6952  +**
         6953  +** SQL functions are initially coded as OP_Function0 with P4 pointing
         6954  +** to a FuncDef object.  But on first evaluation, the P4 operand is
         6955  +** automatically converted into an sqlite3_context object and the operation
         6956  +** changed to this OP_Function opcode.  In this way, the initialization of
         6957  +** the sqlite3_context object occurs only once, rather than once for each
         6958  +** evaluation of the function.
         6959  +**
         6960  +** See also: Function0, AggStep, AggFinal
         6961  +*/
         6962  +case OP_PureFunc0:
         6963  +case OP_Function0: {
         6964  +  int n;
         6965  +  sqlite3_context *pCtx;
         6966  +
         6967  +  assert( pOp->p4type==P4_FUNCDEF );
         6968  +  n = pOp->p5;
         6969  +  assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
         6970  +  assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
         6971  +  assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
         6972  +  pCtx = sqlite3DbMallocRawNN(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
         6973  +  if( pCtx==0 ) goto no_mem;
         6974  +  pCtx->pOut = 0;
         6975  +  pCtx->pFunc = pOp->p4.pFunc;
         6976  +  pCtx->iOp = (int)(pOp - aOp);
         6977  +  pCtx->pVdbe = p;
         6978  +  pCtx->argc = n;
         6979  +  pOp->p4type = P4_FUNCCTX;
         6980  +  pOp->p4.pCtx = pCtx;
         6981  +  assert( OP_PureFunc == OP_PureFunc0+2 );
         6982  +  assert( OP_Function == OP_Function0+2 );
         6983  +  pOp->opcode += 2;
         6984  +  /* Fall through into OP_Function */
         6985  +}
         6986  +case OP_PureFunc:
         6987  +case OP_Function: {
         6988  +  int i;
         6989  +  sqlite3_context *pCtx;
         6990  +
         6991  +  assert( pOp->p4type==P4_FUNCCTX );
         6992  +  pCtx = pOp->p4.pCtx;
         6993  +
         6994  +  /* If this function is inside of a trigger, the register array in aMem[]
         6995  +  ** might change from one evaluation to the next.  The next block of code
         6996  +  ** checks to see if the register array has changed, and if so it
         6997  +  ** reinitializes the relavant parts of the sqlite3_context object */
         6998  +  pOut = &aMem[pOp->p3];
         6999  +  if( pCtx->pOut != pOut ){
         7000  +    pCtx->pOut = pOut;
         7001  +    for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
         7002  +  }
         7003  +
         7004  +  memAboutToChange(p, pOut);
         7005  +#ifdef SQLITE_DEBUG
         7006  +  for(i=0; i<pCtx->argc; i++){
         7007  +    assert( memIsValid(pCtx->argv[i]) );
         7008  +    REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
         7009  +  }
         7010  +#endif
         7011  +  MemSetTypeFlag(pOut, MEM_Null);
         7012  +  pCtx->fErrorOrAux = 0;
         7013  +  (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
         7014  +
         7015  +  /* If the function returned an error, throw an exception */
         7016  +  if( pCtx->fErrorOrAux ){
         7017  +    if( pCtx->isError ){
         7018  +      sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut));
         7019  +      rc = pCtx->isError;
         7020  +    }
         7021  +    sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
         7022  +    if( rc ) goto abort_due_to_error;
         7023  +  }
         7024  +
         7025  +  /* Copy the result of the function into register P3 */
         7026  +  if( pOut->flags & (MEM_Str|MEM_Blob) ){
         7027  +    sqlite3VdbeChangeEncoding(pOut, encoding);
         7028  +    if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
         7029  +  }
         7030  +
         7031  +  REGISTER_TRACE(pOp->p3, pOut);
         7032  +  UPDATE_MAX_BLOBSIZE(pOut);
         7033  +  break;
         7034  +}
  7031   7035   
  7032   7036   
  7033   7037   /* Opcode: Init P1 P2 * P4 *
  7034   7038   ** Synopsis: Start at P2
  7035   7039   **
  7036   7040   ** Programs contain a single instance of this opcode as the very first
  7037   7041   ** opcode.

Changes to src/vdbe.h.

   248    248   
   249    249   typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
   250    250   RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
   251    251   
   252    252   #ifndef SQLITE_OMIT_TRIGGER
   253    253   void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
   254    254   #endif
          255  +
          256  +int sqlite3NotPureFunc(sqlite3_context*);
   255    257   
   256    258   /* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
   257    259   ** each VDBE opcode.
   258    260   **
   259    261   ** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
   260    262   ** comments in VDBE programs that show key decision points in the code
   261    263   ** generator.

Changes to src/vdbeaux.c.

  4579   4579     assert( (v->db->flags & SQLITE_EnableQPSG)==0 );
  4580   4580     if( iVar>=32 ){
  4581   4581       v->expmask |= 0x80000000;
  4582   4582     }else{
  4583   4583       v->expmask |= ((u32)1 << (iVar-1));
  4584   4584     }
  4585   4585   }
         4586  +
         4587  +/*
         4588  +** Cause a function to throw an error if it was call from OP_PureFunc
         4589  +** rather than OP_Function.
         4590  +**
         4591  +** OP_PureFunc means that the function must be deterministic, and should
         4592  +** throw an error if it is given inputs that would make it non-deterministic.
         4593  +** This routine is invoked by date/time functions that use non-deterministic
         4594  +** features such as 'now'.
         4595  +*/
         4596  +int sqlite3NotPureFunc(sqlite3_context *pCtx){
         4597  +  if( pCtx->pVdbe->aOp[pCtx->iOp].opcode==OP_PureFunc ){
         4598  +    sqlite3_result_error(pCtx, 
         4599  +       "non-deterministic function in index expression or CHECK constraint",
         4600  +       -1);
         4601  +    return 0;
         4602  +  }
         4603  +  return 1;
         4604  +}
  4586   4605   
  4587   4606   #ifndef SQLITE_OMIT_VIRTUALTABLE
  4588   4607   /*
  4589   4608   ** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
  4590   4609   ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
  4591   4610   ** in memory obtained from sqlite3DbMalloc).
  4592   4611   */

Added test/date2.test.

            1  +# 2017-07-20
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is testing date and time functions used in
           13  +# check constraints and index expressions.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +
           19  +# Skip this whole file if date and time functions are omitted
           20  +# at compile-time
           21  +#
           22  +ifcapable {!datetime} {
           23  +  finish_test
           24  +  return
           25  +}
           26  +
           27  +do_execsql_test date2-100 {
           28  +  CREATE TABLE t1(x, y, CHECK( date(x) BETWEEN '2017-07-01' AND '2017-07-31' ));
           29  +  INSERT INTO t1(x,y) VALUES('2017-07-20','one');
           30  +} {}
           31  +do_catchsql_test date2-110 {
           32  +  INSERT INTO t1(x,y) VALUES('now','two');
           33  +} {1 {non-deterministic function in index expression or CHECK constraint}}
           34  +do_execsql_test date2-120 {
           35  +  SELECT * FROM t1;
           36  +} {2017-07-20 one}
           37  +do_catchsql_test date2-130 {
           38  +  INSERT INTO t1(x,y) VALUES('2017-08-01','two');
           39  +} {1 {CHECK constraint failed: t1}}
           40  +
           41  +do_execsql_test date2-200 {
           42  +  CREATE TABLE t2(x,y);
           43  +  INSERT INTO t2(x,y) VALUES(1, '2017-07-20'), (2, 'xyzzy');
           44  +  CREATE INDEX t2y ON t2(date(y));
           45  +}
           46  +do_catchsql_test date2-210 {
           47  +  INSERT INTO t2(x,y) VALUES(3, 'now');
           48  +} {1 {non-deterministic function in index expression or CHECK constraint}}
           49  +do_execsql_test date2-220 {
           50  +  SELECT x, y FROM t2 ORDER BY x;
           51  +} {1 2017-07-20 2 xyzzy}
           52  +
           53  +do_execsql_test date2-300 {
           54  +  CREATE TABLE t3(a INTEGER PRIMARY KEY,b);
           55  +  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000)
           56  +    INSERT INTO t3(a,b) SELECT x, julianday('2017-07-01')+x FROM c;
           57  +  UPDATE t3 SET b='now' WHERE a=500;
           58  +}
           59  +do_catchsql_test date2-310 {
           60  +  CREATE INDEX t3b1 ON t3(datetime(b));
           61  +} {1 {non-deterministic function in index expression or CHECK constraint}}
           62  +do_catchsql_test date2-320 {
           63  +  CREATE INDEX t3b1 ON t3(datetime(b)) WHERE typeof(b)='real';
           64  +} {0 {}}
           65  +do_execsql_test date2-330 {
           66  +  EXPLAIN QUERY PLAN
           67  +  SELECT a FROM t3
           68  +   WHERE typeof(b)='real'
           69  +     AND datetime(b) BETWEEN '2017-07-04' AND '2017-07-08';
           70  +} {/USING INDEX t3b/}
           71  +do_execsql_test date2-331 {
           72  +  SELECT a FROM t3
           73  +   WHERE typeof(b)='real'
           74  +     AND datetime(b) BETWEEN '2017-07-04' AND '2017-07-08'
           75  +  ORDER BY a;
           76  +} {3 4 5 6}
           77  +
           78  +do_execsql_test date2-400 {
           79  +  CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
           80  +  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000)
           81  +    INSERT INTO t4(a,b) SELECT x, julianday('2017-07-01')+x FROM c;
           82  +  UPDATE t4 SET b='now' WHERE a=500;
           83  +}
           84  +do_catchsql_test date2-410 {
           85  +  CREATE INDEX t4b1 ON t4(b)
           86  +    WHERE date(b) BETWEEN '2017-06-01' AND '2017-08-31';
           87  +} {1 {non-deterministic function in index expression or CHECK constraint}}
           88  +do_execsql_test date2-420 {
           89  +  DELETE FROM t4 WHERE a=500;
           90  +  CREATE INDEX t4b1 ON t4(b)
           91  +    WHERE date(b) BETWEEN '2017-06-01' AND '2017-08-31';
           92  +}
           93  +do_catchsql_test date2-430 {
           94  +  INSERT INTO t4(a,b) VALUES(9999,'now');
           95  +} {1 {non-deterministic function in index expression or CHECK constraint}}
           96  +
           97  +do_execsql_test date2-500 {
           98  +  CREATE TABLE mods(x);
           99  +  INSERT INTO mods(x) VALUES
          100  +    ('+10 days'),
          101  +    ('-10 days'),
          102  +    ('+10 hours'),
          103  +    ('-10 hours'),
          104  +    ('+10 minutes'),
          105  +    ('-10 minutes'),
          106  +    ('+10 seconds'),
          107  +    ('-10 seconds'),
          108  +    ('+10 months'),
          109  +    ('-10 months'),
          110  +    ('+10 years'),
          111  +    ('-10 years'),
          112  +    ('start of month'),
          113  +    ('start of year'),
          114  +    ('start of day'),
          115  +    ('weekday 1'),
          116  +    ('unixepoch');
          117  +  CREATE TABLE t5(y,m);
          118  +  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<5)
          119  +    INSERT INTO t5(y,m) SELECT julianday('2017-07-01')+c.x, mods.x FROM c, mods;
          120  +  CREATE INDEX t5x1 on t5(y) WHERE datetime(y,m) IS NOT NULL;
          121  +}
          122  +do_catchsql_test date2-510 {
          123  +  INSERT INTO t5(y,m) VALUES('2017-07-20','localtime');
          124  +} {1 {non-deterministic function in index expression or CHECK constraint}}
          125  +do_catchsql_test date2-520 {
          126  +  INSERT INTO t5(y,m) VALUES('2017-07-20','utc');
          127  +} {1 {non-deterministic function in index expression or CHECK constraint}}
          128  +
          129  +
          130  +
          131  +  
          132  +
          133  +
          134  +finish_test

Changes to test/incrblob2.test.

   327    327   if {$::tcl_platform(pointerSize)>=8} {
   328    328     do_test incrblob2-6.2b {
   329    329       set rc [catch {
   330    330         # Prior to 2015-02-07, the following caused a segfault due to
   331    331         # integer overflow.
   332    332         sqlite3_blob_read $rdHandle 2147483647 2147483647
   333    333       } errmsg]
          334  +    if {[string match {out of memory in *test_blob.c} $errmsg]} {
          335  +      set errmsg SQLITE_ERROR
          336  +    }
   334    337       lappend rc $errmsg
   335    338     } {1 SQLITE_ERROR}
   336    339   }
   337    340   do_test incrblob2-6.2c {
   338    341     set rc [catch {
   339    342       # Prior to 2015-02-07, the following caused a segfault due to
   340    343       # integer overflow.

Changes to test/indexexpr1.test.

   177    177     EXPLAIN QUERY PLAN
   178    178     SELECT id, b, c FROM t1
   179    179      WHERE substr(a,27,3)=='ord' AND d>=29;
   180    180   } {/USING INDEX t1a2/}
   181    181   
   182    182   
   183    183   do_catchsql_test indexexpr1-300 {
   184         -  CREATE TABLE t2(a,b,c);
          184  +  CREATE TABLE t2(a,b,c); INSERT INTO t2 VALUES(1,2,3);
   185    185     CREATE INDEX t2x1 ON t2(a,b+random());
   186    186   } {1 {non-deterministic functions prohibited in index expressions}}
   187    187   do_catchsql_test indexexpr1-301 {
   188         -  CREATE INDEX t2x1 ON t2(a+julianday('now'));
   189         -} {1 {non-deterministic functions prohibited in index expressions}}
          188  +  CREATE INDEX t2x1 ON t2(julianday('now',a));
          189  +} {1 {non-deterministic function in index expression or CHECK constraint}}
   190    190   do_catchsql_test indexexpr1-310 {
   191    191     CREATE INDEX t2x2 ON t2(a,b+(SELECT 15));
   192    192   } {1 {subqueries prohibited in index expressions}}
   193    193   do_catchsql_test indexexpr1-320 {
   194    194     CREATE TABLE e1(x,y,UNIQUE(y,substr(x,1,5)));
   195    195   } {1 {expressions prohibited in PRIMARY KEY and UNIQUE constraints}}
   196    196   do_catchsql_test indexexpr1-330 {

Changes to test/unionvtab.test.

    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is percentile.c extension
    13     13   #
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   set testprefix unionvtab
           18  +
           19  +ifcapable !vtab {
           20  +  finish_test
           21  +  return
           22  +}
    18     23   
    19     24   load_static_extension db unionvtab
    20     25   
    21     26   #-------------------------------------------------------------------------
    22     27   # Warm body tests.
    23     28   #
    24     29   forcedelete test.db2