System.Data.SQLite
Check-in [b5ae536a3d]
Not logged in

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

Overview
Comment:Update SQLite core library to the latest trunk code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b5ae536a3dfaf3944f5ca83f3eff36f236b737e1
User & Date: mistachkin 2013-09-12 21:30:50
Context
2013-09-13
01:38
Add SQLiteCommand.Execute, SQLiteCommand.ExecuteNonQuery, and SQLiteCommand.ExecuteScalar method overloads that take a CommandBehavior parameter. check-in: 00b02c1aa6 user: mistachkin tags: trunk
00:58
Make sure the database cannot be changed by a query when the CommandBehavior.SchemaOnly flag is used. Fix for [f8dbab8baf]. check-in: 30e2ba0f43 user: mistachkin tags: tkt-f8dbab8baf
2013-09-12
21:30
Update SQLite core library to the latest trunk code. check-in: b5ae536a3d user: mistachkin tags: trunk
2013-09-10
06:33
Update Eagle in externals to the beta 28 release. check-in: e7fa8c655e user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to SQLite.Interop/props/sqlite3.props.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    11     11     <PropertyGroup Label="UserMacros">
    12     12       <SQLITE_MANIFEST_VERSION>3.8.1</SQLITE_MANIFEST_VERSION>
    13     13       <SQLITE_RC_VERSION>3,8,1</SQLITE_RC_VERSION>
    14         -    <SQLITE_COMMON_DEFINES>_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT3=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1</SQLITE_COMMON_DEFINES>
           14  +    <SQLITE_COMMON_DEFINES>_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT4=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1</SQLITE_COMMON_DEFINES>
    15     15       <SQLITE_EXTRA_DEFINES>SQLITE_HAS_CODEC=1</SQLITE_EXTRA_DEFINES>
    16     16       <SQLITE_WINCE_DEFINES>SQLITE_OMIT_WAL=1</SQLITE_WINCE_DEFINES>
    17     17       <SQLITE_DEBUG_DEFINES>SQLITE_DEBUG=1;SQLITE_MEMDEBUG=1;SQLITE_ENABLE_EXPENSIVE_ASSERT=1</SQLITE_DEBUG_DEFINES>
    18     18       <SQLITE_RELEASE_DEFINES>SQLITE_WIN32_MALLOC=1</SQLITE_RELEASE_DEFINES>
    19     19       <SQLITE_DISABLE_WARNINGS>4055;4100;4127;4146;4210;4232;4244;4245;4267;4306;4389;4701;4703;4706</SQLITE_DISABLE_WARNINGS>
    20     20       <SQLITE_DISABLE_X64_WARNINGS></SQLITE_DISABLE_X64_WARNINGS>
    21     21     </PropertyGroup>

Changes to SQLite.Interop/props/sqlite3.vsprops.

    20     20   	<UserMacro
    21     21   		Name="SQLITE_RC_VERSION"
    22     22   		Value="3,8,1"
    23     23   		PerformEnvironmentSet="true"
    24     24   	/>
    25     25   	<UserMacro
    26     26   		Name="SQLITE_COMMON_DEFINES"
    27         -		Value="_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT3=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1"
           27  +		Value="_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT4=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1"
    28     28   		PerformEnvironmentSet="true"
    29     29   	/>
    30     30   	<UserMacro
    31     31   		Name="SQLITE_EXTRA_DEFINES"
    32     32   		Value="SQLITE_HAS_CODEC=1"
    33     33   		PerformEnvironmentSet="true"
    34     34   	/>

Changes to SQLite.Interop/src/contrib/extension-functions.c.

  1694   1694   
  1695   1695   /*
  1696   1696   ** This function registered all of the above C functions as SQL
  1697   1697   ** functions.  This should be the only routine in this file with
  1698   1698   ** external linkage.
  1699   1699   */
  1700   1700   int RegisterExtensionFunctions(sqlite3 *db){
  1701         -  static const struct FuncDefs {
         1701  +  static const struct {
  1702   1702        char *zName;
  1703   1703        signed char nArg;
  1704   1704        u8 argType;           /* 0: none.  1: db  2: (-1) */
  1705   1705        u8 eTextRep;          /* 1: UTF-16.  0: UTF-8 */
  1706   1706        u8 needCollSeq;
  1707   1707        void (*xFunc)(sqlite3_context*,int,sqlite3_value **);
  1708   1708     } aFuncs[] = {
................................................................................
  1762   1762       { "padl",               2, 0, SQLITE_UTF8,    0, padlFunc },
  1763   1763       { "padr",               2, 0, SQLITE_UTF8,    0, padrFunc },
  1764   1764       { "padc",               2, 0, SQLITE_UTF8,    0, padcFunc },
  1765   1765       { "strfilter",          2, 0, SQLITE_UTF8,    0, strfilterFunc },
  1766   1766   
  1767   1767     };
  1768   1768     /* Aggregate functions */
  1769         -  static const struct FuncDefAgg {
         1769  +  static const struct {
  1770   1770       char *zName;
  1771   1771       signed char nArg;
  1772   1772       u8 argType;
  1773   1773       u8 needCollSeq;
  1774   1774       void (*xStep)(sqlite3_context*,int,sqlite3_value**);
  1775   1775       void (*xFinalize)(sqlite3_context*);
  1776   1776     } aAggs[] = {
................................................................................
  1794   1794       sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
  1795   1795           aFuncs[i].eTextRep, pArg, aFuncs[i].xFunc, 0, 0);
  1796   1796   #if 1
  1797   1797       if( aFuncs[i].needCollSeq ){
  1798   1798         struct FuncDef *pFunc = sqlite3FindFunction(db, aFuncs[i].zName,
  1799   1799             strlen(aFuncs[i].zName), aFuncs[i].nArg, aFuncs[i].eTextRep, 0);
  1800   1800         if( pFunc && aFuncs[i].needCollSeq ){
         1801  +#if SQLITE_VERSION_NUMBER >= 3008001
         1802  +        pFunc->funcFlags |= SQLITE_FUNC_NEEDCOLL;
         1803  +#else
  1801   1804           pFunc->flags |= SQLITE_FUNC_NEEDCOLL;
         1805  +#endif
  1802   1806         }
  1803   1807       }
  1804   1808   #endif
  1805   1809     }
  1806   1810   
  1807   1811     for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){
  1808   1812       void *pArg = 0;
................................................................................
  1812   1816       }
  1813   1817       /* sqlite3CreateFunc */
  1814   1818       /* LMH no error checking */
  1815   1819       sqlite3_create_function(db, aAggs[i].zName, aAggs[i].nArg, SQLITE_UTF8,
  1816   1820           pArg, 0, aAggs[i].xStep, aAggs[i].xFinalize);
  1817   1821   #if 0
  1818   1822       if( aAggs[i].needCollSeq ){
  1819         -      struct FuncDefAgg *pFunc = sqlite3FindFunction( db, aAggs[i].zName,
         1823  +      struct FuncDef *pFunc = sqlite3FindFunction( db, aAggs[i].zName,
  1820   1824             strlen(aAggs[i].zName), aAggs[i].nArg, SQLITE_UTF8, 0);
  1821   1825         if( pFunc && aAggs[i].needCollSeq ){
  1822         -        pFunc->needCollSeq = 1;
         1826  +#if SQLITE_VERSION_NUMBER >= 3008001
         1827  +        pFunc->funcFlags |= SQLITE_FUNC_NEEDCOLL;
         1828  +#else
         1829  +        pFunc->flags |= SQLITE_FUNC_NEEDCOLL;
         1830  +#endif
  1823   1831         }
  1824   1832       }
  1825   1833   #endif
  1826   1834     }
  1827   1835     return 0;
  1828   1836   }
  1829   1837   

Changes to SQLite.Interop/src/core/sqlite3.c.

   654    654   **
   655    655   ** See also: [sqlite3_libversion()],
   656    656   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   657    657   ** [sqlite_version()] and [sqlite_source_id()].
   658    658   */
   659    659   #define SQLITE_VERSION        "3.8.1"
   660    660   #define SQLITE_VERSION_NUMBER 3008001
   661         -#define SQLITE_SOURCE_ID      "2013-09-04 04:04:08 8df95bb0b3f72222cf262174247a467c234f9939"
          661  +#define SQLITE_SOURCE_ID      "2013-09-12 02:09:05 75a8a8c1b39725d36db627536d0c69401f8e0815"
   662    662   
   663    663   /*
   664    664   ** CAPI3REF: Run-Time Library Version Numbers
   665    665   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   666    666   **
   667    667   ** These interfaces provide the same information as the [SQLITE_VERSION],
   668    668   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
 10141  10141     int (*xWalCallback)(void *, sqlite3 *, const char *, int);
 10142  10142     void *pWalArg;
 10143  10143   #endif
 10144  10144     void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
 10145  10145     void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
 10146  10146     void *pCollNeededArg;
 10147  10147     sqlite3_value *pErr;          /* Most recent error message */
 10148         -  char *zErrMsg;                /* Most recent error message (UTF-8 encoded) */
 10149         -  char *zErrMsg16;              /* Most recent error message (UTF-16 encoded) */
 10150  10148     union {
 10151  10149       volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
 10152  10150       double notUsed1;            /* Spacer */
 10153  10151     } u1;
 10154  10152     Lookaside lookaside;          /* Lookaside malloc configuration */
 10155  10153   #ifndef SQLITE_OMIT_AUTHORIZATION
 10156  10154     int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
................................................................................
 10285  10283   ** Each SQL function is defined by an instance of the following
 10286  10284   ** structure.  A pointer to this structure is stored in the sqlite.aFunc
 10287  10285   ** hash table.  When multiple functions have the same name, the hash table
 10288  10286   ** points to a linked list of these structures.
 10289  10287   */
 10290  10288   struct FuncDef {
 10291  10289     i16 nArg;            /* Number of arguments.  -1 means unlimited */
 10292         -  u8 iPrefEnc;         /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
 10293         -  u8 flags;            /* Some combination of SQLITE_FUNC_* */
        10290  +  u16 funcFlags;       /* Some combination of SQLITE_FUNC_* */
 10294  10291     void *pUserData;     /* User data parameter */
 10295  10292     FuncDef *pNext;      /* Next function with same name */
 10296  10293     void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
 10297  10294     void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
 10298  10295     void (*xFinalize)(sqlite3_context*);                /* Aggregate finalizer */
 10299  10296     char *zName;         /* SQL name of the function. */
 10300  10297     FuncDef *pHash;      /* Next with a different name but the same hash */
................................................................................
 10322  10319   };
 10323  10320   
 10324  10321   /*
 10325  10322   ** Possible values for FuncDef.flags.  Note that the _LENGTH and _TYPEOF
 10326  10323   ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG.  There
 10327  10324   ** are assert() statements in the code to verify this.
 10328  10325   */
 10329         -#define SQLITE_FUNC_LIKE     0x01 /* Candidate for the LIKE optimization */
 10330         -#define SQLITE_FUNC_CASE     0x02 /* Case-sensitive LIKE-type function */
 10331         -#define SQLITE_FUNC_EPHEM    0x04 /* Ephemeral.  Delete with VDBE */
 10332         -#define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
 10333         -#define SQLITE_FUNC_COUNT    0x10 /* Built-in count(*) aggregate */
 10334         -#define SQLITE_FUNC_COALESCE 0x20 /* Built-in coalesce() or ifnull() function */
 10335         -#define SQLITE_FUNC_LENGTH   0x40 /* Built-in length() function */
 10336         -#define SQLITE_FUNC_TYPEOF   0x80 /* Built-in typeof() function */
        10326  +#define SQLITE_FUNC_ENCMASK  0x003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
        10327  +#define SQLITE_FUNC_LIKE     0x004 /* Candidate for the LIKE optimization */
        10328  +#define SQLITE_FUNC_CASE     0x008 /* Case-sensitive LIKE-type function */
        10329  +#define SQLITE_FUNC_EPHEM    0x010 /* Ephemeral.  Delete with VDBE */
        10330  +#define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
        10331  +#define SQLITE_FUNC_LENGTH   0x040 /* Built-in length() function */
        10332  +#define SQLITE_FUNC_TYPEOF   0x080 /* Built-in typeof() function */
        10333  +#define SQLITE_FUNC_COUNT    0x100 /* Built-in count(*) aggregate */
        10334  +#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
        10335  +#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
 10337  10336   
 10338  10337   /*
 10339  10338   ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
 10340  10339   ** used to create the initializers for the FuncDef structures.
 10341  10340   **
 10342  10341   **   FUNCTION(zName, nArg, iArg, bNC, xFunc)
 10343  10342   **     Used to create a scalar function definition of a function zName 
................................................................................
 10357  10356   **     that accepts nArg arguments and is implemented by a call to C 
 10358  10357   **     function likeFunc. Argument pArg is cast to a (void *) and made
 10359  10358   **     available as the function user-data (sqlite3_user_data()). The
 10360  10359   **     FuncDef.flags variable is set to the value passed as the flags
 10361  10360   **     parameter.
 10362  10361   */
 10363  10362   #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
 10364         -  {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL), \
        10363  +  {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
 10365  10364      SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
 10366  10365   #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
 10367         -  {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
        10366  +  {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
 10368  10367      SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
 10369  10368   #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
 10370         -  {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
        10369  +  {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
 10371  10370      pArg, 0, xFunc, 0, 0, #zName, 0, 0}
 10372  10371   #define LIKEFUNC(zName, nArg, arg, flags) \
 10373         -  {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
        10372  +  {nArg, SQLITE_UTF8|flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
 10374  10373   #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
 10375         -  {nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
        10374  +  {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
 10376  10375      SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
 10377  10376   
 10378  10377   /*
 10379  10378   ** All current savepoints are stored in a linked list starting at
 10380  10379   ** sqlite3.pSavepoint. The first element in the list is the most recently
 10381  10380   ** opened savepoint. Savepoints are added to the list by the vdbe
 10382  10381   ** OP_Savepoint instruction.
................................................................................
 12429  12428   ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign
 12430  12429   ** key functionality is available. If OMIT_TRIGGER is defined but
 12431  12430   ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
 12432  12431   ** this case foreign keys are parsed, but no other functionality is 
 12433  12432   ** provided (enforcement of FK constraints requires the triggers sub-system).
 12434  12433   */
 12435  12434   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
 12436         -SQLITE_PRIVATE   void sqlite3FkCheck(Parse*, Table*, int, int);
        12435  +SQLITE_PRIVATE   void sqlite3FkCheck(Parse*, Table*, int, int, int*, int);
 12437  12436   SQLITE_PRIVATE   void sqlite3FkDropTable(Parse*, SrcList *, Table*);
 12438         -SQLITE_PRIVATE   void sqlite3FkActions(Parse*, Table*, ExprList*, int);
        12437  +SQLITE_PRIVATE   void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
 12439  12438   SQLITE_PRIVATE   int sqlite3FkRequired(Parse*, Table*, int*, int);
 12440  12439   SQLITE_PRIVATE   u32 sqlite3FkOldmask(Parse*, Table*);
 12441  12440   SQLITE_PRIVATE   FKey *sqlite3FkReferences(Table *);
 12442  12441   #else
 12443         -  #define sqlite3FkActions(a,b,c,d)
        12442  +  #define sqlite3FkActions(a,b,c,d,e,f)
 12444  12443     #define sqlite3FkCheck(a,b,c,d)
 12445  12444     #define sqlite3FkDropTable(a,b,c)
 12446         -  #define sqlite3FkOldmask(a,b)      0
 12447         -  #define sqlite3FkRequired(a,b,c,d) 0
        12445  +  #define sqlite3FkOldmask(a,b)          0
        12446  +  #define sqlite3FkRequired(a,b,c,d,e,f) 0
 12448  12447   #endif
 12449  12448   #ifndef SQLITE_OMIT_FOREIGN_KEY
 12450  12449   SQLITE_PRIVATE   void sqlite3FkDelete(sqlite3 *, Table*);
 12451  12450   SQLITE_PRIVATE   int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
 12452  12451   #else
 12453  12452     #define sqlite3FkDelete(a,b)
 12454  12453     #define sqlite3FkLocateIndex(a,b,c,d,e)
................................................................................
 30807  30806   ** Returns non-zero if the character should be treated as a directory
 30808  30807   ** separator.
 30809  30808   */
 30810  30809   #ifndef winIsDirSep
 30811  30810   #  define winIsDirSep(a)                (((a) == '/') || ((a) == '\\'))
 30812  30811   #endif
 30813  30812   
        30813  +/*
        30814  +** This macro is used when a local variable is set to a value that is
        30815  +** [sometimes] not used by the code (e.g. via conditional compilation).
        30816  +*/
        30817  +#ifndef UNUSED_VARIABLE_VALUE
        30818  +#  define UNUSED_VARIABLE_VALUE(x) (void)(x)
        30819  +#endif
        30820  +
 30814  30821   /*
 30815  30822   ** Returns the string that should be used as the directory separator.
 30816  30823   */
 30817  30824   #ifndef winGetDirDep
 30818  30825   #  ifdef __CYGWIN__
 30819  30826   #    define winGetDirDep()              "/"
 30820  30827   #  else
................................................................................
 31057  31064   ** 2:   Operating system is WinNT.
 31058  31065   **
 31059  31066   ** In order to facilitate testing on a WinNT system, the test fixture
 31060  31067   ** can manually set this value to 1 to emulate Win98 behavior.
 31061  31068   */
 31062  31069   #ifdef SQLITE_TEST
 31063  31070   SQLITE_API int sqlite3_os_type = 0;
 31064         -#else
        31071  +#elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
        31072  +      defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_HAS_WIDE)
 31065  31073   static int sqlite3_os_type = 0;
 31066  31074   #endif
 31067  31075   
 31068  31076   #ifndef SYSCALL
 31069  31077   #  define SYSCALL sqlite3_syscall_ptr
 31070  31078   #endif
 31071  31079   
................................................................................
 31858  31866     assert( hHeap!=INVALID_HANDLE_VALUE );
 31859  31867   #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
 31860  31868     assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
 31861  31869   #endif
 31862  31870     assert( nBytes>=0 );
 31863  31871     p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
 31864  31872     if( !p ){
 31865         -    sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p",
        31873  +    sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%lu), heap=%p",
 31866  31874                   nBytes, osGetLastError(), (void*)hHeap);
 31867  31875     }
 31868  31876     return p;
 31869  31877   }
 31870  31878   
 31871  31879   /*
 31872  31880   ** Free memory.
................................................................................
 31879  31887     assert( hHeap!=0 );
 31880  31888     assert( hHeap!=INVALID_HANDLE_VALUE );
 31881  31889   #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
 31882  31890     assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
 31883  31891   #endif
 31884  31892     if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
 31885  31893     if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
 31886         -    sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
        31894  +    sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%lu), heap=%p",
 31887  31895                   pPrior, osGetLastError(), (void*)hHeap);
 31888  31896     }
 31889  31897   }
 31890  31898   
 31891  31899   /*
 31892  31900   ** Change the size of an existing memory allocation
 31893  31901   */
................................................................................
 31905  31913     assert( nBytes>=0 );
 31906  31914     if( !pPrior ){
 31907  31915       p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
 31908  31916     }else{
 31909  31917       p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
 31910  31918     }
 31911  31919     if( !p ){
 31912         -    sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p",
        31920  +    sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%lu), heap=%p",
 31913  31921                   pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, osGetLastError(),
 31914  31922                   (void*)hHeap);
 31915  31923     }
 31916  31924     return p;
 31917  31925   }
 31918  31926   
 31919  31927   /*
................................................................................
 31929  31937     assert( hHeap!=INVALID_HANDLE_VALUE );
 31930  31938   #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
 31931  31939     assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
 31932  31940   #endif
 31933  31941     if( !p ) return 0;
 31934  31942     n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
 31935  31943     if( n==(SIZE_T)-1 ){
 31936         -    sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p",
        31944  +    sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%lu), heap=%p",
 31937  31945                   p, osGetLastError(), (void*)hHeap);
 31938  31946       return 0;
 31939  31947     }
 31940  31948     return (int)n;
 31941  31949   }
 31942  31950   
 31943  31951   /*
................................................................................
 31959  31967   #if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
 31960  31968     if( !pWinMemData->hHeap ){
 31961  31969       pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
 31962  31970                                         SQLITE_WIN32_HEAP_INIT_SIZE,
 31963  31971                                         SQLITE_WIN32_HEAP_MAX_SIZE);
 31964  31972       if( !pWinMemData->hHeap ){
 31965  31973         sqlite3_log(SQLITE_NOMEM,
 31966         -          "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u",
        31974  +          "failed to HeapCreate (%lu), flags=%u, initSize=%u, maxSize=%u",
 31967  31975             osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
 31968  31976             SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
 31969  31977         return SQLITE_NOMEM;
 31970  31978       }
 31971  31979       pWinMemData->bOwned = TRUE;
 31972  31980       assert( pWinMemData->bOwned );
 31973  31981     }
 31974  31982   #else
 31975  31983     pWinMemData->hHeap = osGetProcessHeap();
 31976  31984     if( !pWinMemData->hHeap ){
 31977  31985       sqlite3_log(SQLITE_NOMEM,
 31978         -        "failed to GetProcessHeap (%d)", osGetLastError());
        31986  +        "failed to GetProcessHeap (%lu)", osGetLastError());
 31979  31987       return SQLITE_NOMEM;
 31980  31988     }
 31981  31989     pWinMemData->bOwned = FALSE;
 31982  31990     assert( !pWinMemData->bOwned );
 31983  31991   #endif
 31984  31992     assert( pWinMemData->hHeap!=0 );
 31985  31993     assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
................................................................................
 31999  32007     if( pWinMemData->hHeap ){
 32000  32008       assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
 32001  32009   #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
 32002  32010       assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
 32003  32011   #endif
 32004  32012       if( pWinMemData->bOwned ){
 32005  32013         if( !osHeapDestroy(pWinMemData->hHeap) ){
 32006         -        sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
        32014  +        sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%lu), heap=%p",
 32007  32015                       osGetLastError(), (void*)pWinMemData->hHeap);
 32008  32016         }
 32009  32017         pWinMemData->bOwned = FALSE;
 32010  32018       }
 32011  32019       pWinMemData->hHeap = NULL;
 32012  32020     }
 32013  32021   }
................................................................................
 33884  33892   **
 33885  33893   ** This is not a VFS shared-memory method; it is a utility function called
 33886  33894   ** by VFS shared-memory methods.
 33887  33895   */
 33888  33896   static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
 33889  33897     winShmNode **pp;
 33890  33898     winShmNode *p;
 33891         -  BOOL bRc;
 33892  33899     assert( winShmMutexHeld() );
 33893  33900     OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n",
 33894  33901              osGetCurrentProcessId(), deleteFlag));
 33895  33902     pp = &winShmNodeList;
 33896  33903     while( (p = *pp)!=0 ){
 33897  33904       if( p->nRef==0 ){
 33898  33905         int i;
 33899  33906         if( p->mutex ) sqlite3_mutex_free(p->mutex);
 33900  33907         for(i=0; i<p->nRegion; i++){
 33901         -        bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
        33908  +        BOOL bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
 33902  33909           OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n",
 33903  33910                    osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
        33911  +        UNUSED_VARIABLE_VALUE(bRc);
 33904  33912           bRc = osCloseHandle(p->aRegion[i].hMap);
 33905  33913           OSTRACE(("SHM-PURGE-CLOSE pid=%lu, region=%d, rc=%s\n",
 33906  33914                    osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
        33915  +        UNUSED_VARIABLE_VALUE(bRc);
 33907  33916         }
 33908  33917         if( p->hFile.h!=NULL && p->hFile.h!=INVALID_HANDLE_VALUE ){
 33909  33918           SimulateIOErrorBenign(1);
 33910  33919           winClose((sqlite3_file *)&p->hFile);
 33911  33920           SimulateIOErrorBenign(0);
 33912  33921         }
 33913  33922         if( deleteFlag ){
................................................................................
 34618  34627   /****************************************************************************
 34619  34628   **************************** sqlite3_vfs methods ****************************
 34620  34629   **
 34621  34630   ** This division contains the implementation of methods on the
 34622  34631   ** sqlite3_vfs object.
 34623  34632   */
 34624  34633   
        34634  +#if 0
 34625  34635   /*
 34626  34636   ** Convert a filename from whatever the underlying operating system
 34627  34637   ** supports for filenames into UTF-8.  Space to hold the result is
 34628  34638   ** obtained from malloc and must be freed by the calling function.
 34629  34639   */
 34630  34640   static char *winConvertToUtf8Filename(const void *zFilename){
 34631  34641     char *zConverted = 0;
................................................................................
 34636  34646     else{
 34637  34647       zConverted = sqlite3_win32_mbcs_to_utf8(zFilename);
 34638  34648     }
 34639  34649   #endif
 34640  34650     /* caller will handle out of memory */
 34641  34651     return zConverted;
 34642  34652   }
        34653  +#endif
 34643  34654   
 34644  34655   /*
 34645  34656   ** Convert a UTF-8 filename into whatever form the underlying
 34646  34657   ** operating system wants filenames in.  Space to hold the result
 34647  34658   ** is obtained from malloc and must be freed by the calling
 34648  34659   ** function.
 34649  34660   */
................................................................................
 60402  60413     Expr *pExpr,                    /* The expression to extract a value from */
 60403  60414     u8 affinity,                    /* Affinity to use */
 60404  60415     int iVal,                       /* Array element to populate */
 60405  60416     int *pbOk                       /* OUT: True if value was extracted */
 60406  60417   ){
 60407  60418     int rc = SQLITE_OK;
 60408  60419     sqlite3_value *pVal = 0;
        60420  +  sqlite3 *db = pParse->db;
        60421  +
 60409  60422   
 60410  60423     struct ValueNewStat4Ctx alloc;
 60411  60424     alloc.pParse = pParse;
 60412  60425     alloc.pIdx = pIdx;
 60413  60426     alloc.ppRec = ppRec;
 60414  60427     alloc.iVal = iVal;
 60415  60428   
 60416  60429     /* Skip over any TK_COLLATE nodes */
 60417  60430     pExpr = sqlite3ExprSkipCollate(pExpr);
 60418  60431   
 60419  60432     if( !pExpr ){
 60420         -    pVal = valueNew(pParse->db, &alloc);
        60433  +    pVal = valueNew(db, &alloc);
 60421  60434       if( pVal ){
 60422  60435         sqlite3VdbeMemSetNull((Mem*)pVal);
 60423  60436         *pbOk = 1;
 60424  60437       }
 60425  60438     }else if( pExpr->op==TK_VARIABLE
 60426  60439           || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
 60427  60440     ){
 60428  60441       Vdbe *v;
 60429  60442       int iBindVar = pExpr->iColumn;
 60430  60443       sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar);
 60431  60444       if( (v = pParse->pReprepare)!=0 ){
 60432         -      pVal = valueNew(pParse->db, &alloc);
        60445  +      pVal = valueNew(db, &alloc);
 60433  60446         if( pVal ){
 60434  60447           rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
 60435  60448           if( rc==SQLITE_OK ){
 60436         -          sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
        60449  +          sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
 60437  60450           }
 60438  60451           pVal->db = pParse->db;
 60439  60452           *pbOk = 1;
 60440  60453           sqlite3VdbeMemStoreType((Mem*)pVal);
 60441  60454         }
 60442  60455       }else{
 60443  60456         *pbOk = 0;
 60444  60457       }
 60445  60458     }else{
 60446         -    sqlite3 *db = pParse->db;
 60447  60459       rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
 60448  60460       *pbOk = (pVal!=0);
 60449  60461     }
 60450  60462   
 60451         -  assert( pVal==0 || pVal->db==pParse->db );
        60463  +  assert( pVal==0 || pVal->db==db );
 60452  60464     return rc;
 60453  60465   }
 60454  60466   
 60455  60467   /*
 60456  60468   ** Unless it is NULL, the argument must be an UnpackedRecord object returned
 60457  60469   ** by an earlier call to sqlite3Stat4ProbeSetValue(). This call deletes
 60458  60470   ** the object.
................................................................................
 61112  61124   
 61113  61125   
 61114  61126   /*
 61115  61127   ** If the input FuncDef structure is ephemeral, then free it.  If
 61116  61128   ** the FuncDef is not ephermal, then do nothing.
 61117  61129   */
 61118  61130   static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
 61119         -  if( ALWAYS(pDef) && (pDef->flags & SQLITE_FUNC_EPHEM)!=0 ){
        61131  +  if( ALWAYS(pDef) && (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
 61120  61132       sqlite3DbFree(db, pDef);
 61121  61133     }
 61122  61134   }
 61123  61135   
 61124  61136   static void vdbeFreeOpArray(sqlite3 *, Op *, int);
 61125  61137   
 61126  61138   /*
................................................................................
 67404  67416     ** the pointer to u.ai.ctx.s so in case the user-function can use
 67405  67417     ** the already allocated buffer instead of allocating a new one.
 67406  67418     */
 67407  67419     sqlite3VdbeMemMove(&u.ai.ctx.s, pOut);
 67408  67420     MemSetTypeFlag(&u.ai.ctx.s, MEM_Null);
 67409  67421   
 67410  67422     u.ai.ctx.fErrorOrAux = 0;
 67411         -  if( u.ai.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
        67423  +  if( u.ai.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
 67412  67424       assert( pOp>aOp );
 67413  67425       assert( pOp[-1].p4type==P4_COLLSEQ );
 67414  67426       assert( pOp[-1].opcode==OP_CollSeq );
 67415  67427       u.ai.ctx.pColl = pOp[-1].p4.pColl;
 67416  67428     }
 67417  67429     db->lastRowid = lastRowid;
 67418  67430     (*u.ai.ctx.pFunc->xFunc)(&u.ai.ctx, u.ai.n, u.ai.apVal); /* IMP: R-24505-23230 */
................................................................................
 71504  71516     u.cg.ctx.s.z = 0;
 71505  71517     u.cg.ctx.s.zMalloc = 0;
 71506  71518     u.cg.ctx.s.xDel = 0;
 71507  71519     u.cg.ctx.s.db = db;
 71508  71520     u.cg.ctx.isError = 0;
 71509  71521     u.cg.ctx.pColl = 0;
 71510  71522     u.cg.ctx.skipFlag = 0;
 71511         -  if( u.cg.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
        71523  +  if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
 71512  71524       assert( pOp>p->aOp );
 71513  71525       assert( pOp[-1].p4type==P4_COLLSEQ );
 71514  71526       assert( pOp[-1].opcode==OP_CollSeq );
 71515  71527       u.cg.ctx.pColl = pOp[-1].p4.pColl;
 71516  71528     }
 71517  71529     (u.cg.ctx.pFunc->xStep)(&u.cg.ctx, u.cg.n, u.cg.apVal); /* IMP: R-24505-23230 */
 71518  71530     if( u.cg.ctx.isError ){
................................................................................
 78600  78612           break;
 78601  78613         }
 78602  78614   
 78603  78615         /* Attempt a direct implementation of the built-in COALESCE() and
 78604  78616         ** IFNULL() functions.  This avoids unnecessary evalation of
 78605  78617         ** arguments past the first non-NULL argument.
 78606  78618         */
 78607         -      if( pDef->flags & SQLITE_FUNC_COALESCE ){
        78619  +      if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
 78608  78620           int endCoalesce = sqlite3VdbeMakeLabel(v);
 78609  78621           assert( nFarg>=2 );
 78610  78622           sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
 78611  78623           for(i=1; i<nFarg; i++){
 78612  78624             sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
 78613  78625             sqlite3ExprCacheRemove(pParse, target, 1);
 78614  78626             sqlite3ExprCachePush(pParse);
................................................................................
 78624  78636           r1 = sqlite3GetTempRange(pParse, nFarg);
 78625  78637   
 78626  78638           /* For length() and typeof() functions with a column argument,
 78627  78639           ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
 78628  78640           ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
 78629  78641           ** loading.
 78630  78642           */
 78631         -        if( (pDef->flags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
        78643  +        if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
 78632  78644             u8 exprOp;
 78633  78645             assert( nFarg==1 );
 78634  78646             assert( pFarg->a[0].pExpr!=0 );
 78635  78647             exprOp = pFarg->a[0].pExpr->op;
 78636  78648             if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
 78637  78649               assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
 78638  78650               assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
 78639         -            testcase( pDef->flags==SQLITE_FUNC_LENGTH );
 78640         -            pFarg->a[0].pExpr->op2 = pDef->flags;
        78651  +            testcase( (pDef->funcFlags&~SQLITE_FUNC_ENCMASK)
        78652  +                       ==SQLITE_FUNC_LENGTH );
        78653  +            pFarg->a[0].pExpr->op2 = pDef->funcFlags&~SQLITE_FUNC_ENCMASK;
 78641  78654             }
 78642  78655           }
 78643  78656   
 78644  78657           sqlite3ExprCachePush(pParse);     /* Ticket 2ea2425d34be */
 78645  78658           sqlite3ExprCodeExprList(pParse, pFarg, r1, 1);
 78646  78659           sqlite3ExprCachePop(pParse, 1);   /* Ticket 2ea2425d34be */
 78647  78660         }else{
................................................................................
 78666  78679           pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
 78667  78680         }
 78668  78681   #endif
 78669  78682         for(i=0; i<nFarg; i++){
 78670  78683           if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
 78671  78684             constMask |= (1<<i);
 78672  78685           }
 78673         -        if( (pDef->flags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
        78686  +        if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
 78674  78687             pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
 78675  78688           }
 78676  78689         }
 78677         -      if( pDef->flags & SQLITE_FUNC_NEEDCOLL ){
        78690  +      if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
 78678  78691           if( !pColl ) pColl = db->pDfltColl; 
 78679  78692           sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
 78680  78693         }
 78681  78694         sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
 78682  78695                           (char*)pDef, P4_FUNCDEF);
 78683  78696         sqlite3VdbeChangeP5(v, (u8)nFarg);
 78684  78697         if( nFarg ){
................................................................................
 81392  81405       u8 *pSpace;                     /* Allocated space not yet assigned */
 81393  81406       int i;                          /* Used to iterate through p->aSample[] */
 81394  81407   
 81395  81408       p->iGet = -1;
 81396  81409       p->mxSample = mxSample;
 81397  81410       p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[1])/(mxSample/3+1) + 1);
 81398  81411       p->current.anLt = &p->current.anEq[nColUp];
 81399         -    sqlite3_randomness(sizeof(p->iPrn), &p->iPrn);
        81412  +    p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[1])*0xd0944565;
 81400  81413     
 81401  81414       /* Set up the Stat4Accum.a[] and aBest[] arrays */
 81402  81415       p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
 81403  81416       p->aBest = &p->a[mxSample];
 81404  81417       pSpace = (u8*)(&p->a[mxSample+nCol]);
 81405  81418       for(i=0; i<(mxSample+nCol); i++){
 81406  81419         p->a[i].anEq = (tRowcnt *)pSpace; pSpace += (sizeof(tRowcnt) * nColUp);
................................................................................
 81416  81429   #endif
 81417  81430   
 81418  81431     /* Return a pointer to the allocated object to the caller */
 81419  81432     sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
 81420  81433   }
 81421  81434   static const FuncDef statInitFuncdef = {
 81422  81435     1+IsStat34,      /* nArg */
 81423         -  SQLITE_UTF8,     /* iPrefEnc */
 81424         -  0,               /* flags */
        81436  +  SQLITE_UTF8,     /* funcFlags */
 81425  81437     0,               /* pUserData */
 81426  81438     0,               /* pNext */
 81427  81439     statInit,        /* xFunc */
 81428  81440     0,               /* xStep */
 81429  81441     0,               /* xFinalize */
 81430  81442     "stat_init",     /* zName */
 81431  81443     0,               /* pHash */
................................................................................
 81713  81725         }
 81714  81726       }
 81715  81727     }
 81716  81728   #endif
 81717  81729   }
 81718  81730   static const FuncDef statPushFuncdef = {
 81719  81731     2+IsStat34,      /* nArg */
 81720         -  SQLITE_UTF8,     /* iPrefEnc */
 81721         -  0,               /* flags */
        81732  +  SQLITE_UTF8,     /* funcFlags */
 81722  81733     0,               /* pUserData */
 81723  81734     0,               /* pNext */
 81724  81735     statPush,        /* xFunc */
 81725  81736     0,               /* xStep */
 81726  81737     0,               /* xFinalize */
 81727  81738     "stat_push",     /* zName */
 81728  81739     0,               /* pHash */
................................................................................
 81849  81860         }
 81850  81861       }
 81851  81862     }
 81852  81863   #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
 81853  81864   }
 81854  81865   static const FuncDef statGetFuncdef = {
 81855  81866     1+IsStat34,      /* nArg */
 81856         -  SQLITE_UTF8,     /* iPrefEnc */
 81857         -  0,               /* flags */
        81867  +  SQLITE_UTF8,     /* funcFlags */
 81858  81868     0,               /* pUserData */
 81859  81869     0,               /* pNext */
 81860  81870     statGet,         /* xFunc */
 81861  81871     0,               /* xStep */
 81862  81872     0,               /* xFinalize */
 81863  81873     "stat_get",      /* zName */
 81864  81874     0,               /* pHash */
................................................................................
 83054  83064   ** Called by the parser to compile a DETACH statement.
 83055  83065   **
 83056  83066   **     DETACH pDbname
 83057  83067   */
 83058  83068   SQLITE_PRIVATE void sqlite3Detach(Parse *pParse, Expr *pDbname){
 83059  83069     static const FuncDef detach_func = {
 83060  83070       1,                /* nArg */
 83061         -    SQLITE_UTF8,      /* iPrefEnc */
 83062         -    0,                /* flags */
        83071  +    SQLITE_UTF8,      /* funcFlags */
 83063  83072       0,                /* pUserData */
 83064  83073       0,                /* pNext */
 83065  83074       detachFunc,       /* xFunc */
 83066  83075       0,                /* xStep */
 83067  83076       0,                /* xFinalize */
 83068  83077       "sqlite_detach",  /* zName */
 83069  83078       0,                /* pHash */
................................................................................
 83076  83085   ** Called by the parser to compile an ATTACH statement.
 83077  83086   **
 83078  83087   **     ATTACH p AS pDbname KEY pKey
 83079  83088   */
 83080  83089   SQLITE_PRIVATE void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
 83081  83090     static const FuncDef attach_func = {
 83082  83091       3,                /* nArg */
 83083         -    SQLITE_UTF8,      /* iPrefEnc */
 83084         -    0,                /* flags */
        83092  +    SQLITE_UTF8,      /* funcFlags */
 83085  83093       0,                /* pUserData */
 83086  83094       0,                /* pNext */
 83087  83095       attachFunc,       /* xFunc */
 83088  83096       0,                /* xStep */
 83089  83097       0,                /* xFinalize */
 83090  83098       "sqlite_attach",  /* zName */
 83091  83099       0,                /* pHash */
................................................................................
 87587  87595     if( p->nArg==nArg ){
 87588  87596       match = 4;
 87589  87597     }else{
 87590  87598       match = 1;
 87591  87599     }
 87592  87600   
 87593  87601     /* Bonus points if the text encoding matches */
 87594         -  if( enc==p->iPrefEnc ){
        87602  +  if( enc==(p->funcFlags & SQLITE_FUNC_ENCMASK) ){
 87595  87603       match += 2;  /* Exact encoding match */
 87596         -  }else if( (enc & p->iPrefEnc & 2)!=0 ){
        87604  +  }else if( (enc & p->funcFlags & 2)!=0 ){
 87597  87605       match += 1;  /* Both are UTF16, but with different byte orders */
 87598  87606     }
 87599  87607   
 87600  87608     return match;
 87601  87609   }
 87602  87610   
 87603  87611   /*
................................................................................
 87723  87731     ** exact match for the name, number of arguments and encoding, then add a
 87724  87732     ** new entry to the hash table and return it.
 87725  87733     */
 87726  87734     if( createFlag && bestScore<FUNC_PERFECT_MATCH && 
 87727  87735         (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
 87728  87736       pBest->zName = (char *)&pBest[1];
 87729  87737       pBest->nArg = (u16)nArg;
 87730         -    pBest->iPrefEnc = enc;
        87738  +    pBest->funcFlags = enc;
 87731  87739       memcpy(pBest->zName, zName, nName);
 87732  87740       pBest->zName[nName] = 0;
 87733  87741       sqlite3FuncDefInsert(&db->aFunc, pBest);
 87734  87742     }
 87735  87743   
 87736  87744     if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){
 87737  87745       return pBest;
................................................................................
 88333  88341       ** being deleted. Do not attempt to delete the row a second time, and 
 88334  88342       ** do not fire AFTER triggers.  */
 88335  88343       sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);
 88336  88344   
 88337  88345       /* Do FK processing. This call checks that any FK constraints that
 88338  88346       ** refer to this table (i.e. constraints attached to other tables) 
 88339  88347       ** are not violated by deleting this row.  */
 88340         -    sqlite3FkCheck(pParse, pTab, iOld, 0);
        88348  +    sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
 88341  88349     }
 88342  88350   
 88343  88351     /* Delete the index and table entries. Skip this step if pTab is really
 88344  88352     ** a view (in which case the only effect of the DELETE statement is to
 88345  88353     ** fire the INSTEAD OF triggers).  */ 
 88346  88354     if( pTab->pSelect==0 ){
 88347  88355       sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);
................................................................................
 88350  88358         sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
 88351  88359       }
 88352  88360     }
 88353  88361   
 88354  88362     /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
 88355  88363     ** handle rows (possibly in other tables) that refer via a foreign key
 88356  88364     ** to the row just deleted. */ 
 88357         -  sqlite3FkActions(pParse, pTab, 0, iOld);
        88365  +  sqlite3FkActions(pParse, pTab, 0, iOld, 0, 0);
 88358  88366   
 88359  88367     /* Invoke AFTER DELETE trigger programs. */
 88360  88368     sqlite3CodeRowTrigger(pParse, pTrigger, 
 88361  88369         TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
 88362  88370     );
 88363  88371   
 88364  88372     /* Jump here if the row had already been deleted before any BEFORE
................................................................................
 90025  90033   ** Set the LIKEOPT flag on the 2-argument function with the given name.
 90026  90034   */
 90027  90035   static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
 90028  90036     FuncDef *pDef;
 90029  90037     pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
 90030  90038                                2, SQLITE_UTF8, 0);
 90031  90039     if( ALWAYS(pDef) ){
 90032         -    pDef->flags = flagVal;
        90040  +    pDef->funcFlags |= flagVal;
 90033  90041     }
 90034  90042   }
 90035  90043   
 90036  90044   /*
 90037  90045   ** Register the built-in LIKE and GLOB functions.  The caseSensitive
 90038  90046   ** parameter determines whether or not the LIKE operator is case
 90039  90047   ** sensitive.  GLOB is always case sensitive.
................................................................................
 90069  90077     ){
 90070  90078       return 0;
 90071  90079     }
 90072  90080     assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
 90073  90081     pDef = sqlite3FindFunction(db, pExpr->u.zToken, 
 90074  90082                                sqlite3Strlen30(pExpr->u.zToken),
 90075  90083                                2, SQLITE_UTF8, 0);
 90076         -  if( NEVER(pDef==0) || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
        90084  +  if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
 90077  90085       return 0;
 90078  90086     }
 90079  90087   
 90080  90088     /* The memcpy() statement assumes that the wildcard characters are
 90081  90089     ** the first three statements in the compareInfo structure.  The
 90082  90090     ** asserts() that follow verify that assumption
 90083  90091     */
 90084  90092     memcpy(aWc, pDef->pUserData, 3);
 90085  90093     assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
 90086  90094     assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
 90087  90095     assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
 90088         -  *pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0;
        90096  +  *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
 90089  90097     return 1;
 90090  90098   }
 90091  90099   
 90092  90100   /*
 90093  90101   ** All all of the FuncDef structures in the aBuiltinFunc[] array above
 90094  90102   ** to the global function hash table.  This occurs at start-time (as
 90095  90103   ** a consequence of calling sqlite3_initialize()).
................................................................................
 90160  90168       FUNCTION(load_extension,     1, 0, 0, loadExt          ),
 90161  90169       FUNCTION(load_extension,     2, 0, 0, loadExt          ),
 90162  90170     #endif
 90163  90171       AGGREGATE(sum,               1, 0, 0, sumStep,         sumFinalize    ),
 90164  90172       AGGREGATE(total,             1, 0, 0, sumStep,         totalFinalize    ),
 90165  90173       AGGREGATE(avg,               1, 0, 0, sumStep,         avgFinalize    ),
 90166  90174    /* AGGREGATE(count,             0, 0, 0, countStep,       countFinalize  ), */
 90167         -    {0,SQLITE_UTF8,SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
        90175  +    {0,SQLITE_UTF8|SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
 90168  90176       AGGREGATE(count,             1, 0, 0, countStep,       countFinalize  ),
 90169  90177       AGGREGATE(group_concat,      1, 0, 0, groupConcatStep, groupConcatFinalize),
 90170  90178       AGGREGATE(group_concat,      2, 0, 0, groupConcatStep, groupConcatFinalize),
 90171  90179     
 90172  90180       LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
 90173  90181     #ifdef SQLITE_CASE_SENSITIVE_LIKE
 90174  90182       LIKEFUNC(like, 2, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
................................................................................
 90876  90884   
 90877  90885       if( iSkip ){
 90878  90886         sqlite3VdbeResolveLabel(v, iSkip);
 90879  90887       }
 90880  90888     }
 90881  90889   }
 90882  90890   
        90891  +
        90892  +/*
        90893  +** The second argument points to an FKey object representing a foreign key
        90894  +** for which pTab is the child table. An UPDATE statement against pTab
        90895  +** is currently being processed. For each column of the table that is 
        90896  +** actually updated, the corresponding element in the aChange[] array
        90897  +** is zero or greater (if a column is unmodified the corresponding element
        90898  +** is set to -1). If the rowid column is modified by the UPDATE statement
        90899  +** the bChngRowid argument is non-zero.
        90900  +**
        90901  +** This function returns true if any of the columns that are part of the
        90902  +** child key for FK constraint *p are modified.
        90903  +*/
        90904  +static int fkChildIsModified(
        90905  +  Table *pTab,                    /* Table being updated */
        90906  +  FKey *p,                        /* Foreign key for which pTab is the child */
        90907  +  int *aChange,                   /* Array indicating modified columns */
        90908  +  int bChngRowid                  /* True if rowid is modified by this update */
        90909  +){
        90910  +  int i;
        90911  +  for(i=0; i<p->nCol; i++){
        90912  +    int iChildKey = p->aCol[i].iFrom;
        90913  +    if( aChange[iChildKey]>=0 ) return 1;
        90914  +    if( iChildKey==pTab->iPKey && bChngRowid ) return 1;
        90915  +  }
        90916  +  return 0;
        90917  +}
        90918  +
        90919  +/*
        90920  +** The second argument points to an FKey object representing a foreign key
        90921  +** for which pTab is the parent table. An UPDATE statement against pTab
        90922  +** is currently being processed. For each column of the table that is 
        90923  +** actually updated, the corresponding element in the aChange[] array
        90924  +** is zero or greater (if a column is unmodified the corresponding element
        90925  +** is set to -1). If the rowid column is modified by the UPDATE statement
        90926  +** the bChngRowid argument is non-zero.
        90927  +**
        90928  +** This function returns true if any of the columns that are part of the
        90929  +** parent key for FK constraint *p are modified.
        90930  +*/
        90931  +static int fkParentIsModified(
        90932  +  Table *pTab, 
        90933  +  FKey *p, 
        90934  +  int *aChange, 
        90935  +  int bChngRowid
        90936  +){
        90937  +  int i;
        90938  +  for(i=0; i<p->nCol; i++){
        90939  +    char *zKey = p->aCol[i].zCol;
        90940  +    int iKey;
        90941  +    for(iKey=0; iKey<pTab->nCol; iKey++){
        90942  +      if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
        90943  +        Column *pCol = &pTab->aCol[iKey];
        90944  +        if( zKey ){
        90945  +          if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1;
        90946  +        }else if( pCol->colFlags & COLFLAG_PRIMKEY ){
        90947  +          return 1;
        90948  +        }
        90949  +      }
        90950  +    }
        90951  +  }
        90952  +  return 0;
        90953  +}
        90954  +
 90883  90955   /*
 90884  90956   ** This function is called when inserting, deleting or updating a row of
 90885  90957   ** table pTab to generate VDBE code to perform foreign key constraint 
 90886  90958   ** processing for the operation.
 90887  90959   **
 90888  90960   ** For a DELETE operation, parameter regOld is passed the index of the
 90889  90961   ** first register in an array of (pTab->nCol+1) registers containing the
................................................................................
 90900  90972   ** described for DELETE. Then again after the original record is deleted
 90901  90973   ** but before the new record is inserted using the INSERT convention. 
 90902  90974   */
 90903  90975   SQLITE_PRIVATE void sqlite3FkCheck(
 90904  90976     Parse *pParse,                  /* Parse context */
 90905  90977     Table *pTab,                    /* Row is being deleted from this table */ 
 90906  90978     int regOld,                     /* Previous row data is stored here */
 90907         -  int regNew                      /* New row data is stored here */
        90979  +  int regNew,                     /* New row data is stored here */
        90980  +  int *aChange,                   /* Array indicating UPDATEd columns (or 0) */
        90981  +  int bChngRowid                  /* True if rowid is UPDATEd */
 90908  90982   ){
 90909  90983     sqlite3 *db = pParse->db;       /* Database handle */
 90910  90984     FKey *pFKey;                    /* Used to iterate through FKs */
 90911  90985     int iDb;                        /* Index of database containing pTab */
 90912  90986     const char *zDb;                /* Name of database containing pTab */
 90913  90987     int isIgnoreErrors = pParse->disableTriggers;
 90914  90988   
................................................................................
 90927  91001       Table *pTo;                   /* Parent table of foreign key pFKey */
 90928  91002       Index *pIdx = 0;              /* Index on key columns in pTo */
 90929  91003       int *aiFree = 0;
 90930  91004       int *aiCol;
 90931  91005       int iCol;
 90932  91006       int i;
 90933  91007       int isIgnore = 0;
        91008  +
        91009  +    if( aChange 
        91010  +     && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
        91011  +     && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0 
        91012  +    ){
        91013  +      continue;
        91014  +    }
 90934  91015   
 90935  91016       /* Find the parent table of this foreign key. Also find a unique index 
 90936  91017       ** on the parent key columns in the parent table. If either of these 
 90937  91018       ** schema items cannot be located, set an error in pParse and return 
 90938  91019       ** early.  */
 90939  91020       if( pParse->disableTriggers ){
 90940  91021         pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
................................................................................
 91009  91090     }
 91010  91091   
 91011  91092     /* Loop through all the foreign key constraints that refer to this table */
 91012  91093     for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
 91013  91094       Index *pIdx = 0;              /* Foreign key index for pFKey */
 91014  91095       SrcList *pSrc;
 91015  91096       int *aiCol = 0;
        91097  +
        91098  +    if( aChange && fkParentIsModified(pTab, pFKey, aChange, bChngRowid)==0 ){
        91099  +      continue;
        91100  +    }
 91016  91101   
 91017  91102       if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs) 
 91018  91103        && !pParse->pToplevel && !pParse->isMultiWrite 
 91019  91104       ){
 91020  91105         assert( regOld==0 && regNew!=0 );
 91021  91106         /* Inserting a single row into a parent table cannot cause an immediate
 91022  91107         ** foreign key violation. So do nothing in this case.  */
................................................................................
 91082  91167         if( pIdx ){
 91083  91168           for(i=0; i<pIdx->nColumn; i++) mask |= COLUMN_MASK(pIdx->aiColumn[i]);
 91084  91169         }
 91085  91170       }
 91086  91171     }
 91087  91172     return mask;
 91088  91173   }
        91174  +
 91089  91175   
 91090  91176   /*
 91091  91177   ** This function is called before generating code to update or delete a 
 91092  91178   ** row contained in table pTab. If the operation is a DELETE, then
 91093  91179   ** parameter aChange is passed a NULL value. For an UPDATE, aChange points
 91094  91180   ** to an array of size N, where N is the number of columns in table pTab.
 91095  91181   ** If the i'th column is not modified by the UPDATE, then the corresponding 
................................................................................
 91112  91198         /* A DELETE operation. Foreign key processing is required if the 
 91113  91199         ** table in question is either the child or parent table for any 
 91114  91200         ** foreign key constraint.  */
 91115  91201         return (sqlite3FkReferences(pTab) || pTab->pFKey);
 91116  91202       }else{
 91117  91203         /* This is an UPDATE. Foreign key processing is only required if the
 91118  91204         ** operation modifies one or more child or parent key columns. */
 91119         -      int i;
 91120  91205         FKey *p;
 91121  91206   
 91122  91207         /* Check if any child key columns are being modified. */
 91123  91208         for(p=pTab->pFKey; p; p=p->pNextFrom){
 91124         -        for(i=0; i<p->nCol; i++){
 91125         -          int iChildKey = p->aCol[i].iFrom;
 91126         -          if( aChange[iChildKey]>=0 ) return 1;
 91127         -          if( iChildKey==pTab->iPKey && chngRowid ) return 1;
 91128         -        }
        91209  +        if( fkChildIsModified(pTab, p, aChange, chngRowid) ) return 1;
 91129  91210         }
 91130  91211   
 91131  91212         /* Check if any parent key columns are being modified. */
 91132  91213         for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
 91133         -        for(i=0; i<p->nCol; i++){
 91134         -          char *zKey = p->aCol[i].zCol;
 91135         -          int iKey;
 91136         -          for(iKey=0; iKey<pTab->nCol; iKey++){
 91137         -            Column *pCol = &pTab->aCol[iKey];
 91138         -            if( (zKey ? !sqlite3StrICmp(pCol->zName, zKey)
 91139         -                      : (pCol->colFlags & COLFLAG_PRIMKEY)!=0) ){
 91140         -              if( aChange[iKey]>=0 ) return 1;
 91141         -              if( iKey==pTab->iPKey && chngRowid ) return 1;
 91142         -            }
 91143         -          }
 91144         -        }
        91214  +        if( fkParentIsModified(pTab, p, aChange, chngRowid) ) return 1;
 91145  91215         }
 91146  91216       }
 91147  91217     }
 91148  91218     return 0;
 91149  91219   }
 91150  91220   
 91151  91221   /*
................................................................................
 91363  91433   ** This function is called when deleting or updating a row to implement
 91364  91434   ** any required CASCADE, SET NULL or SET DEFAULT actions.
 91365  91435   */
 91366  91436   SQLITE_PRIVATE void sqlite3FkActions(
 91367  91437     Parse *pParse,                  /* Parse context */
 91368  91438     Table *pTab,                    /* Table being updated or deleted from */
 91369  91439     ExprList *pChanges,             /* Change-list for UPDATE, NULL for DELETE */
 91370         -  int regOld                      /* Address of array containing old row */
        91440  +  int regOld,                     /* Address of array containing old row */
        91441  +  int *aChange,                   /* Array indicating UPDATEd columns (or 0) */
        91442  +  int bChngRowid                  /* True if rowid is UPDATEd */
 91371  91443   ){
 91372  91444     /* If foreign-key support is enabled, iterate through all FKs that 
 91373  91445     ** refer to table pTab. If there is an action associated with the FK 
 91374  91446     ** for this operation (either update or delete), invoke the associated 
 91375  91447     ** trigger sub-program.  */
 91376  91448     if( pParse->db->flags&SQLITE_ForeignKeys ){
 91377  91449       FKey *pFKey;                  /* Iterator variable */
 91378  91450       for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
 91379         -      Trigger *pAction = fkActionTrigger(pParse, pTab, pFKey, pChanges);
 91380         -      if( pAction ){
 91381         -        sqlite3CodeRowTriggerDirect(pParse, pAction, pTab, regOld, OE_Abort, 0);
        91451  +      if( aChange==0 || fkParentIsModified(pTab, pFKey, aChange, bChngRowid) ){
        91452  +        Trigger *pAct = fkActionTrigger(pParse, pTab, pFKey, pChanges);
        91453  +        if( pAct ){
        91454  +          sqlite3CodeRowTriggerDirect(pParse, pAct, pTab, regOld, OE_Abort, 0);
        91455  +        }
 91382  91456         }
 91383  91457       }
 91384  91458     }
 91385  91459   }
 91386  91460   
 91387  91461   #endif /* ifndef SQLITE_OMIT_TRIGGER */
 91388  91462   
................................................................................
 92459  92533       }else
 92460  92534   #endif
 92461  92535       {
 92462  92536         int isReplace;    /* Set to true if constraints may cause a replace */
 92463  92537         sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
 92464  92538             keyColumn>=0, 0, onError, endOfLoop, &isReplace
 92465  92539         );
 92466         -      sqlite3FkCheck(pParse, pTab, 0, regIns);
        92540  +      sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
 92467  92541         sqlite3CompleteInsertion(
 92468  92542             pParse, pTab, baseCur, regIns, aRegIdx, 0, appendFlag, isReplace==0
 92469  92543         );
 92470  92544       }
 92471  92545     }
 92472  92546   
 92473  92547     /* Update the count of rows that are inserted
................................................................................
100698 100772     pTab = p->pSrc->a[0].pTab;
100699 100773     pExpr = p->pEList->a[0].pExpr;
100700 100774     assert( pTab && !pTab->pSelect && pExpr );
100701 100775   
100702 100776     if( IsVirtual(pTab) ) return 0;
100703 100777     if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
100704 100778     if( NEVER(pAggInfo->nFunc==0) ) return 0;
100705         -  if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
       100779  +  if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
100706 100780     if( pExpr->flags&EP_Distinct ) return 0;
100707 100781   
100708 100782     return pTab;
100709 100783   }
100710 100784   
100711 100785   /*
100712 100786   ** If the source-list item passed as an argument was augmented with an
................................................................................
101295 101369         regAgg = 0;
101296 101370       }
101297 101371       if( pF->iDistinct>=0 ){
101298 101372         addrNext = sqlite3VdbeMakeLabel(v);
101299 101373         assert( nArg==1 );
101300 101374         codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
101301 101375       }
101302         -    if( pF->pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
       101376  +    if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
101303 101377         CollSeq *pColl = 0;
101304 101378         struct ExprList_item *pItem;
101305 101379         int j;
101306 101380         assert( pList!=0 );  /* pList!=0 if pF->pFunc has NEEDCOLL */
101307 101381         for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
101308 101382           pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
101309 101383         }
................................................................................
104138 104212   
104139 104213       /* Do constraint checks. */
104140 104214       sqlite3GenerateConstraintChecks(pParse, pTab, iCur, regNewRowid,
104141 104215           aRegIdx, (chngRowid?regOldRowid:0), 1, onError, addr, 0);
104142 104216   
104143 104217       /* Do FK constraint checks. */
104144 104218       if( hasFK ){
104145         -      sqlite3FkCheck(pParse, pTab, regOldRowid, 0);
       104219  +      sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngRowid);
104146 104220       }
104147 104221   
104148 104222       /* Delete the index entries associated with the current record.  */
104149 104223       j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regOldRowid);
104150 104224       sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, aRegIdx);
104151 104225     
104152 104226       /* If changing the record number, delete the old record.  */
104153 104227       if( hasFK || chngRowid ){
104154 104228         sqlite3VdbeAddOp2(v, OP_Delete, iCur, 0);
104155 104229       }
104156 104230       sqlite3VdbeJumpHere(v, j1);
104157 104231   
104158 104232       if( hasFK ){
104159         -      sqlite3FkCheck(pParse, pTab, 0, regNewRowid);
       104233  +      sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngRowid);
104160 104234       }
104161 104235     
104162 104236       /* Insert the new index entries and the new record. */
104163 104237       sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, 0, 0);
104164 104238   
104165 104239       /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
104166 104240       ** handle rows (possibly in other tables) that refer via a foreign key
104167 104241       ** to the row just updated. */ 
104168 104242       if( hasFK ){
104169         -      sqlite3FkActions(pParse, pTab, pChanges, regOldRowid);
       104243  +      sqlite3FkActions(pParse, pTab, pChanges, regOldRowid, aXRef, chngRowid);
104170 104244       }
104171 104245     }
104172 104246   
104173 104247     /* Increment the row counter 
104174 104248     */
104175 104249     if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
104176 104250       sqlite3VdbeAddOp2(v, OP_AddImm, regRowCount, 1);
................................................................................
105690 105764       return pDef;
105691 105765     }
105692 105766     *pNew = *pDef;
105693 105767     pNew->zName = (char *)&pNew[1];
105694 105768     memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1);
105695 105769     pNew->xFunc = xFunc;
105696 105770     pNew->pUserData = pArg;
105697         -  pNew->flags |= SQLITE_FUNC_EPHEM;
       105771  +  pNew->funcFlags |= SQLITE_FUNC_EPHEM;
105698 105772     return pNew;
105699 105773   }
105700 105774   
105701 105775   /*
105702 105776   ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
105703 105777   ** array so that an OP_VBegin will get generated for it.  Add pTab to the
105704 105778   ** array if it is missing.  If pTab is already in the array, this routine
................................................................................
105881 105955           int addrInTop;         /* Top of the IN loop */
105882 105956           u8 eEndLoopOp;         /* IN Loop terminator. OP_Next or OP_Prev */
105883 105957         } *aInLoop;           /* Information about each nested IN operator */
105884 105958       } in;                 /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
105885 105959       Index *pCovidx;       /* Possible covering index for WHERE_MULTI_OR */
105886 105960     } u;
105887 105961     struct WhereLoop *pWLoop;  /* The selected WhereLoop object */
       105962  +  Bitmask notReady;          /* FROM entries not usable at this level */
105888 105963   };
105889 105964   
105890 105965   /*
105891 105966   ** Each instance of this object represents an algorithm for evaluating one
105892 105967   ** term of a join.  Every term of the FROM clause will have at least
105893 105968   ** one corresponding WhereLoop object (unless INDEXED BY constraints
105894 105969   ** prevent a query solution - which is an error) and many terms of the
................................................................................
108324 108399     int rc = SQLITE_OK;
108325 108400     int nOut = (int)*pnOut;
108326 108401   
108327 108402   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
108328 108403     Index *p = pBuilder->pNew->u.btree.pIndex;
108329 108404     int nEq = pBuilder->pNew->u.btree.nEq;
108330 108405   
108331         -  if( nEq==pBuilder->nRecValid
       108406  +  if( p->nSample>0
       108407  +   && nEq==pBuilder->nRecValid
108332 108408      && nEq<p->nSampleCol
108333         -   && p->nSample 
108334 108409      && OptimizationEnabled(pParse->db, SQLITE_Stat3) 
108335 108410     ){
108336 108411       UnpackedRecord *pRec = pBuilder->pRec;
108337 108412       tRowcnt a[2];
108338 108413       u8 aff;
108339 108414   
108340 108415       /* Variable iLower will be set to the estimate of the number of rows in 
................................................................................
108574 108649   ** as we can without disabling too much.  If we disabled in (1), we'd get
108575 108650   ** the wrong answer.  See ticket #813.
108576 108651   */
108577 108652   static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
108578 108653     if( pTerm
108579 108654         && (pTerm->wtFlags & TERM_CODED)==0
108580 108655         && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
       108656  +      && (pLevel->notReady & pTerm->prereqAll)==0
108581 108657     ){
108582 108658       pTerm->wtFlags |= TERM_CODED;
108583 108659       if( pTerm->iParent>=0 ){
108584 108660         WhereTerm *pOther = &pTerm->pWC->a[pTerm->iParent];
108585 108661         if( (--pOther->nChild)==0 ){
108586 108662           disableTerm(pLevel, pOther);
108587 108663         }
................................................................................
108999 109075     sqlite3 *db;                    /* Database connection */
109000 109076     Vdbe *v;                        /* The prepared stmt under constructions */
109001 109077     struct SrcList_item *pTabItem;  /* FROM clause term being coded */
109002 109078     int addrBrk;                    /* Jump here to break out of the loop */
109003 109079     int addrCont;                   /* Jump here to continue with next cycle */
109004 109080     int iRowidReg = 0;        /* Rowid is stored in this register, if not zero */
109005 109081     int iReleaseReg = 0;      /* Temp register to free before returning */
109006         -  Bitmask newNotReady;      /* Return value */
109007 109082   
109008 109083     pParse = pWInfo->pParse;
109009 109084     v = pParse->pVdbe;
109010 109085     pWC = &pWInfo->sWC;
109011 109086     db = pParse->db;
109012 109087     pLevel = &pWInfo->a[iLevel];
109013 109088     pLoop = pLevel->pWLoop;
109014 109089     pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
109015 109090     iCur = pTabItem->iCursor;
       109091  +  pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
109016 109092     bRev = (pWInfo->revMask>>iLevel)&1;
109017 109093     omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0 
109018 109094              && (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
109019 109095     VdbeNoopComment((v, "Begin Join Loop %d", iLevel));
109020 109096   
109021 109097     /* Create labels for the "break" and "continue" instructions
109022 109098     ** for the current loop.  Jump to addrBrk to break out of a loop.
................................................................................
109661 109737       static const u8 aStart[] = { OP_Rewind, OP_Last };
109662 109738       assert( bRev==0 || bRev==1 );
109663 109739       pLevel->op = aStep[bRev];
109664 109740       pLevel->p1 = iCur;
109665 109741       pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
109666 109742       pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
109667 109743     }
109668         -  newNotReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
109669 109744   
109670 109745     /* Insert code to test every subexpression that can be completely
109671 109746     ** computed using the current set of tables.
109672 109747     */
109673 109748     for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
109674 109749       Expr *pE;
109675 109750       testcase( pTerm->wtFlags & TERM_VIRTUAL );
109676 109751       testcase( pTerm->wtFlags & TERM_CODED );
109677 109752       if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
109678         -    if( (pTerm->prereqAll & newNotReady)!=0 ){
       109753  +    if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
109679 109754         testcase( pWInfo->untestedTerms==0
109680 109755                  && (pWInfo->wctrlFlags & WHERE_ONETABLE_ONLY)!=0 );
109681 109756         pWInfo->untestedTerms = 1;
109682 109757         continue;
109683 109758       }
109684 109759       pE = pTerm->pExpr;
109685 109760       assert( pE!=0 );
................................................................................
109703 109778       WhereTerm *pAlt;
109704 109779       if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
109705 109780       if( pTerm->eOperator!=(WO_EQUIV|WO_EQ) ) continue;
109706 109781       if( pTerm->leftCursor!=iCur ) continue;
109707 109782       if( pLevel->iLeftJoin ) continue;
109708 109783       pE = pTerm->pExpr;
109709 109784       assert( !ExprHasProperty(pE, EP_FromJoin) );
109710         -    assert( (pTerm->prereqRight & newNotReady)!=0 );
       109785  +    assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
109711 109786       pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
109712 109787       if( pAlt==0 ) continue;
109713 109788       if( pAlt->wtFlags & (TERM_CODED) ) continue;
109714 109789       testcase( pAlt->eOperator & WO_EQ );
109715 109790       testcase( pAlt->eOperator & WO_IN );
109716 109791       VdbeNoopComment((v, "begin transitive constraint"));
109717 109792       pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
................................................................................
109731 109806       sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
109732 109807       VdbeComment((v, "record LEFT JOIN hit"));
109733 109808       sqlite3ExprCacheClear(pParse);
109734 109809       for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
109735 109810         testcase( pTerm->wtFlags & TERM_VIRTUAL );
109736 109811         testcase( pTerm->wtFlags & TERM_CODED );
109737 109812         if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
109738         -      if( (pTerm->prereqAll & newNotReady)!=0 ){
       109813  +      if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
109739 109814           assert( pWInfo->untestedTerms );
109740 109815           continue;
109741 109816         }
109742 109817         assert( pTerm->pExpr );
109743 109818         sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
109744 109819         pTerm->wtFlags |= TERM_CODED;
109745 109820       }
109746 109821     }
109747 109822     sqlite3ReleaseTempReg(pParse, iReleaseReg);
109748 109823   
109749         -  return newNotReady;
       109824  +  return pLevel->notReady;
109750 109825   }
109751 109826   
109752 109827   #ifdef WHERETRACE_ENABLED
109753 109828   /*
109754 109829   ** Print a WhereLoop object for debugging purposes
109755 109830   */
109756 109831   static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
................................................................................
109843 109918     return SQLITE_OK;
109844 109919   }
109845 109920   
109846 109921   /*
109847 109922   ** Transfer content from the second pLoop into the first.
109848 109923   */
109849 109924   static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
109850         -  if( whereLoopResize(db, pTo, pFrom->nLTerm) ) return SQLITE_NOMEM;
109851 109925     whereLoopClearUnion(db, pTo);
       109926  +  if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
       109927  +    memset(&pTo->u, 0, sizeof(pTo->u));
       109928  +    return SQLITE_NOMEM;
       109929  +  }
109852 109930     memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
109853 109931     memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
109854 109932     if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
109855 109933       pFrom->u.vtab.needFree = 0;
109856 109934     }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
109857 109935       pFrom->u.btree.pIndex = 0;
109858 109936     }
................................................................................
118018 118096     
118019 118097     /* Check if an existing function is being overridden or deleted. If so,
118020 118098     ** and there are active VMs, then return SQLITE_BUSY. If a function
118021 118099     ** is being overridden/deleted but there are no active VMs, allow the
118022 118100     ** operation to continue but invalidate all precompiled statements.
118023 118101     */
118024 118102     p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
118025         -  if( p && p->iPrefEnc==enc && p->nArg==nArg ){
       118103  +  if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==enc && p->nArg==nArg ){
118026 118104       if( db->nVdbeActive ){
118027 118105         sqlite3Error(db, SQLITE_BUSY, 
118028 118106           "unable to delete/modify user-function due to active statements");
118029 118107         assert( !db->mallocFailed );
118030 118108         return SQLITE_BUSY;
118031 118109       }else{
118032 118110         sqlite3ExpirePreparedStatements(db);
................................................................................
118043 118121     ** being replaced invoke the destructor function here. */
118044 118122     functionDestroy(db, p);
118045 118123   
118046 118124     if( pDestructor ){
118047 118125       pDestructor->nRef++;
118048 118126     }
118049 118127     p->pDestructor = pDestructor;
118050         -  p->flags = 0;
       118128  +  p->funcFlags &= SQLITE_FUNC_ENCMASK;
118051 118129     p->xFunc = xFunc;
118052 118130     p->xStep = xStep;
118053 118131     p->xFinalize = xFinal;
118054 118132     p->pUserData = pUserData;
118055 118133     p->nArg = (u16)nArg;
118056 118134     return SQLITE_OK;
118057 118135   }

Changes to SQLite.Interop/src/core/sqlite3.h.

   105    105   **
   106    106   ** See also: [sqlite3_libversion()],
   107    107   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   108    108   ** [sqlite_version()] and [sqlite_source_id()].
   109    109   */
   110    110   #define SQLITE_VERSION        "3.8.1"
   111    111   #define SQLITE_VERSION_NUMBER 3008001
   112         -#define SQLITE_SOURCE_ID      "2013-09-04 04:04:08 8df95bb0b3f72222cf262174247a467c234f9939"
          112  +#define SQLITE_SOURCE_ID      "2013-09-12 02:09:05 75a8a8c1b39725d36db627536d0c69401f8e0815"
   113    113   
   114    114   /*
   115    115   ** CAPI3REF: Run-Time Library Version Numbers
   116    116   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   117    117   **
   118    118   ** These interfaces provide the same information as the [SQLITE_VERSION],
   119    119   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros

Changes to SQLite.Interop/src/win/interop.c.

     1      1   /********************************************************
     2      2    * ADO.NET 2.0 Data Provider for SQLite Version 3.X
     3      3    * Written by Robert Simpson (robert@blackcastlesoft.com)
     4         - * 
            4  + *
     5      5    * Released to the public domain, use at your own risk!
     6      6    ********************************************************/
     7      7   
     8      8   #define SQLITE_API __declspec(dllexport)
     9      9   
    10     10   #include "../core/sqlite3.c"
    11     11   
................................................................................
   120    120       and forcibly close the database.  The reason is simple -- a lot of people don't Dispose() of their objects correctly and let the garbage collector
   121    121       do it.  This leads to unexpected behavior when a user thinks they've closed a database, but it's still open because not all the statements have
   122    122       hit the GC yet.
   123    123   
   124    124       So, here we have a problem ... .NET has a pointer to any number of sqlite3_stmt objects.  We can't call sqlite3_finalize() on these because
   125    125       their memory is freed and can be used for something else.  The GC thread could potentially try and call finalize again on the statement after
   126    126       that memory was deallocated.  BAD.  So, what we need to do is make a copy of each statement, and call finalize() on the copy -- so that the original
   127         -    statement's memory is preserved, and marked as BAD, but we can still manage to finalize everything and forcibly close the database.  Later when the 
          127  +    statement's memory is preserved, and marked as BAD, but we can still manage to finalize everything and forcibly close the database.  Later when the
   128    128       GC gets around to calling finalize_interop() on the "bad" statement, we detect that and finish deallocating the pointer.
   129    129   */
   130    130   SQLITE_API int WINAPI sqlite3_close_interop(sqlite3 *db)
   131    131   {
   132    132     int ret;
   133    133   #if !defined(INTEROP_LEGACY_CLOSE) && SQLITE_VERSION_NUMBER >= 3007014
   134    134   
................................................................................
   158    158   
   159    159       while (db->pVdbe)
   160    160       {
   161    161         /* Make a copy of the first prepared statement */
   162    162         Vdbe *p = (Vdbe *)sqlite3DbMallocZero_interop(db, sizeof(Vdbe));
   163    163         Vdbe *po = db->pVdbe;
   164    164   
   165         -      if (!p) 
          165  +      if (!p)
   166    166         {
   167    167           ret = SQLITE_NOMEM;
   168    168           break;
   169    169         }
   170    170   
   171    171         CopyMemory(p, po, sizeof(Vdbe));
   172    172   
................................................................................
   577    577     if (n == SQLITE_OK)
   578    578     {
   579    579       if (needCollSeq)
   580    580       {
   581    581         FuncDef *pFunc = sqlite3FindFunction(psql, zFunctionName, strlen(zFunctionName), nArg, eTextRep, 0);
   582    582         if( pFunc )
   583    583         {
          584  +#if SQLITE_VERSION_NUMBER >= 3008001
          585  +        pFunc->funcFlags |= SQLITE_FUNC_NEEDCOLL;
          586  +#else
   584    587           pFunc->flags |= SQLITE_FUNC_NEEDCOLL;
          588  +#endif
   585    589         }
   586    590       }
   587    591     }
   588    592   
   589    593     return n;
   590    594   }
   591    595   
................................................................................
   621    625   SQLITE_API void WINAPI sqlite3_result_int64_interop(sqlite3_context *pctx, sqlite_int64 *val)
   622    626   {
   623    627     sqlite3_result_int64(pctx, *val);
   624    628   }
   625    629   
   626    630   SQLITE_API int WINAPI sqlite3_context_collcompare_interop(sqlite3_context *ctx, const void *p1, int p1len, const void *p2, int p2len)
   627    631   {
          632  +#if SQLITE_VERSION_NUMBER >= 3008001
          633  +  if ((ctx->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) == 0) return 2;
          634  +#else
   628    635     if ((ctx->pFunc->flags & SQLITE_FUNC_NEEDCOLL) == 0) return 2;
          636  +#endif
   629    637     return ctx->pColl->xCmp(ctx->pColl->pUser, p1len, p1, p2len, p2);
   630    638   }
   631    639   
   632    640   SQLITE_API const char * WINAPI sqlite3_context_collseq_interop(sqlite3_context *ctx, int *ptype, int *enc, int *plen)
   633    641   {
   634    642     CollSeq *pColl = ctx->pColl;
   635    643     *ptype = 0;
   636    644     *plen = 0;
   637    645     *enc = 0;
   638    646   
          647  +#if SQLITE_VERSION_NUMBER >= 3008001
          648  +  if ((ctx->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) == 0) return NULL;
          649  +#else
   639    650     if ((ctx->pFunc->flags & SQLITE_FUNC_NEEDCOLL) == 0) return NULL;
          651  +#endif
   640    652   
   641    653     if (pColl)
   642    654     {
   643    655       *enc = pColl->enc;
   644    656   #if SQLITE_VERSION_NUMBER < 3007010
   645    657       *ptype = pColl->type;
   646    658   #endif
................................................................................
   692    704     *plen = (pval != 0) ? wcslen((wchar_t *)pval) * sizeof(wchar_t) : 0;
   693    705     return pval;
   694    706   }
   695    707   
   696    708   SQLITE_API int WINAPI sqlite3_table_column_metadata_interop(sqlite3 *db, const char *zDbName, const char *zTableName, const char *zColumnName, char **pzDataType, char **pzCollSeq, int *pNotNull, int *pPrimaryKey, int *pAutoinc, int *pdtLen, int *pcsLen)
   697    709   {
   698    710     int n;
   699         -  
          711  +
   700    712     n = sqlite3_table_column_metadata(db, zDbName, zTableName, zColumnName, pzDataType, pzCollSeq, pNotNull, pPrimaryKey, pAutoinc);
   701    713     *pdtLen = (*pzDataType != 0) ? strlen(*pzDataType) : 0;
   702    714     *pcsLen = (*pzCollSeq != 0) ? strlen(*pzCollSeq) : 0;
   703    715   
   704    716     return n;
   705    717   }
   706    718