mingodad пре 10 година
родитељ
комит
faa7e255b7
3 измењених фајлова са 216 додато и 67 уклоњено
  1. 21 0
      SquiLu-ext/sq_sqlite3.cpp
  2. 194 66
      SquiLu-ext/sqlite3.c
  3. 1 1
      SquiLu-ext/sqlite3.h

+ 21 - 0
SquiLu-ext/sq_sqlite3.cpp

@@ -2262,6 +2262,25 @@ static SQRESULT sq_sqlite3_context_result_text(HSQUIRRELVM v)
     return 0;
     return 0;
 }
 }
 
 
+static SQRESULT sq_sqlite3_context_result_subtype(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS_NO_TOP(v);
+    GET_sqlite3_context_INSTANCE();
+    SQ_GET_INTEGER(v, 2, subtype);
+    sqlite3_result_subtype(self->ctx, subtype);
+    return 0;
+}
+/* no way to recover parameter value after function call
+static SQRESULT sq_sqlite3_context_value_subtype(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS_NO_TOP(v);
+    GET_sqlite3_context_INSTANCE();
+    SQ_GET_INTEGER(v, 2, param_idx);
+    sq_pushinteger(v, sqlite3_value_subtype(self->ctx, subtype));
+    return 1;
+}
+*/
+
 #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),  sq_sqlite3_context_##name,nparams,tycheck}
 #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),  sq_sqlite3_context_##name,nparams,tycheck}
 static SQRegFunction sq_sqlite3_context_methods[] =
 static SQRegFunction sq_sqlite3_context_methods[] =
 {
 {
@@ -2276,6 +2295,8 @@ static SQRegFunction sq_sqlite3_context_methods[] =
     _DECL_FUNC(result_text,  2, _SC("xs")),
     _DECL_FUNC(result_text,  2, _SC("xs")),
     _DECL_FUNC(result_blob,  2, _SC("xs")),
     _DECL_FUNC(result_blob,  2, _SC("xs")),
     _DECL_FUNC(result_error,  2, _SC("xs")),
     _DECL_FUNC(result_error,  2, _SC("xs")),
+    _DECL_FUNC(result_subtype,  2, _SC("xi")),
+    //_DECL_FUNC(value_subtype,  2, _SC("xi")),
     _DECL_FUNC(_tostring,  -1, _SC("x")),
     _DECL_FUNC(_tostring,  -1, _SC("x")),
     {0,0}
     {0,0}
 };
 };

+ 194 - 66
SquiLu-ext/sqlite3.c

@@ -327,7 +327,7 @@ extern "C" {
 */
 */
 #define SQLITE_VERSION        "3.10.0"
 #define SQLITE_VERSION        "3.10.0"
 #define SQLITE_VERSION_NUMBER 3010000
 #define SQLITE_VERSION_NUMBER 3010000
-#define SQLITE_SOURCE_ID      "2015-12-11 14:59:49 d8a12023be32bdc6df18b0a5f38b917799854342"
+#define SQLITE_SOURCE_ID      "2015-12-30 01:07:02 7f386a9332237100a345035ca213327e21d95855"
 
 
 /*
 /*
 ** CAPI3REF: Run-Time Library Version Numbers
 ** CAPI3REF: Run-Time Library Version Numbers
@@ -9708,6 +9708,8 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
 */
 */
 #ifdef SQLITE_OMIT_FLOATING_POINT
 #ifdef SQLITE_OMIT_FLOATING_POINT
 # define sqlite_double sqlite_int64
 # define sqlite_double sqlite_int64
+# define TO_SQLITE_DOUBLE(x)  (x)
+# define LITDBL(n) n
 # define float sqlite_int64
 # define float sqlite_int64
 # define LONGDOUBLE_TYPE sqlite_int64
 # define LONGDOUBLE_TYPE sqlite_int64
 # ifndef SQLITE_BIG_DBL
 # ifndef SQLITE_BIG_DBL
@@ -9717,7 +9719,6 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
 # define SQLITE_OMIT_TRACE 1
 # define SQLITE_OMIT_TRACE 1
 # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
 # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
 # undef SQLITE_HAVE_ISNAN
 # undef SQLITE_HAVE_ISNAN
-# define LITDBL(n) n
 #else
 #else
 # ifdef SQLITE_USE_DECIMAL
 # ifdef SQLITE_USE_DECIMAL
 # define sqlite_double  _Decimal64
 # define sqlite_double  _Decimal64
@@ -9958,11 +9959,6 @@ typedef INT16_TYPE LogEst;
 ** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
 ** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
 ** at run-time.
 ** at run-time.
 */
 */
-#ifdef SQLITE_AMALGAMATION
-SQLITE_PRIVATE const int sqlite3one = 1;
-#else
-SQLITE_PRIVATE const int sqlite3one;
-#endif
 #if (defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
 #if (defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
      defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)  ||    \
      defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)  ||    \
      defined(_M_AMD64) || defined(_M_ARM)     || defined(__x86)   ||    \
      defined(_M_AMD64) || defined(_M_ARM)     || defined(__x86)   ||    \
@@ -9980,6 +9976,11 @@ SQLITE_PRIVATE const int sqlite3one;
 # define SQLITE_UTF16NATIVE  SQLITE_UTF16BE
 # define SQLITE_UTF16NATIVE  SQLITE_UTF16BE
 #endif
 #endif
 #if !defined(SQLITE_BYTEORDER)
 #if !defined(SQLITE_BYTEORDER)
+# ifdef SQLITE_AMALGAMATION
+  const int sqlite3one = 1;
+# else
+  extern const int sqlite3one;
+# endif
 # define SQLITE_BYTEORDER    0     /* 0 means "unknown at compile-time" */
 # define SQLITE_BYTEORDER    0     /* 0 means "unknown at compile-time" */
 # define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
 # define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
@@ -14315,6 +14316,7 @@ SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
+SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
@@ -16549,6 +16551,7 @@ struct DateTime {
   char validHMS;     /* True (1) if h,m,s are valid */
   char validHMS;     /* True (1) if h,m,s are valid */
   char validJD;      /* True (1) if iJD is valid */
   char validJD;      /* True (1) if iJD is valid */
   char validTZ;      /* True (1) if tz is valid */
   char validTZ;      /* True (1) if tz is valid */
+  char tzSet;        /* Timezone was set explicitly */
 };
 };
 
 
 
 
@@ -16642,6 +16645,7 @@ static int parseTimezone(const char *zDate, DateTime *p){
   p->tz = sgn*(nMn + nHr*60);
   p->tz = sgn*(nMn + nHr*60);
 zulu_time:
 zulu_time:
   while( sqlite3Isspace(*zDate) ){ zDate++; }
   while( sqlite3Isspace(*zDate) ){ zDate++; }
+  p->tzSet = 1;
   return *zDate!=0;
   return *zDate!=0;
 }
 }
 
 
@@ -17074,13 +17078,18 @@ static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){
       }
       }
 #ifndef SQLITE_OMIT_LOCALTIME
 #ifndef SQLITE_OMIT_LOCALTIME
       else if( strcmp(z, "utc")==0 ){
       else if( strcmp(z, "utc")==0 ){
-        sqlite3_int64 c1;
-        computeJD(p);
-        c1 = localtimeOffset(p, pCtx, &rc);
-        if( rc==SQLITE_OK ){
-          p->iJD -= c1;
-          clearYMD_HMS_TZ(p);
-          p->iJD += c1 - localtimeOffset(p, pCtx, &rc);
+        if( p->tzSet==0 ){
+          sqlite3_int64 c1;
+          computeJD(p);
+          c1 = localtimeOffset(p, pCtx, &rc);
+          if( rc==SQLITE_OK ){
+            p->iJD -= c1;
+            clearYMD_HMS_TZ(p);
+            p->iJD += c1 - localtimeOffset(p, pCtx, &rc);
+          }
+          p->tzSet = 1;
+        }else{
+          rc = SQLITE_OK;
         }
         }
       }
       }
 #endif
 #endif
@@ -19720,7 +19729,7 @@ SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys3(void){
 **
 **
 ** This memory allocator uses the following algorithm:
 ** This memory allocator uses the following algorithm:
 **
 **
-**   1.  All memory allocations sizes are rounded up to a power of 2.
+**   1.  All memory allocation sizes are rounded up to a power of 2.
 **
 **
 **   2.  If two adjacent free blocks are the halves of a larger block,
 **   2.  If two adjacent free blocks are the halves of a larger block,
 **       then the two blocks are coalesced into the single larger block.
 **       then the two blocks are coalesced into the single larger block.
@@ -19812,7 +19821,7 @@ static SQLITE_WSD struct Mem5Global {
   /*
   /*
   ** Lists of free blocks.  aiFreelist[0] is a list of free blocks of
   ** Lists of free blocks.  aiFreelist[0] is a list of free blocks of
   ** size mem5.szAtom.  aiFreelist[1] holds blocks of size szAtom*2.
   ** size mem5.szAtom.  aiFreelist[1] holds blocks of size szAtom*2.
-  ** and so forth.
+  ** aiFreelist[2] holds free blocks of size szAtom*4.  And so forth.
   */
   */
   int aiFreelist[LOGMAX+1];
   int aiFreelist[LOGMAX+1];
 
 
@@ -19878,9 +19887,7 @@ static void memsys5Link(int i, int iLogsize){
 }
 }
 
 
 /*
 /*
-** If the STATIC_MEM mutex is not already held, obtain it now. The mutex
-** will already be held (obtained by code in malloc.c) if
-** sqlite3GlobalConfig.bMemStat is true.
+** Obtain or release the mutex needed to access global data structures.
 */
 */
 static void memsys5Enter(void){
 static void memsys5Enter(void){
   sqlite3_mutex_enter(mem5.mutex);
   sqlite3_mutex_enter(mem5.mutex);
@@ -19890,9 +19897,8 @@ static void memsys5Leave(void){
 }
 }
 
 
 /*
 /*
-** Return the size of an outstanding allocation, in bytes.  The
-** size returned omits the 8-byte header overhead.  This only
-** works for chunks that are currently checked out.
+** Return the size of an outstanding allocation, in bytes.
+** This only works for chunks that are currently checked out.
 */
 */
 static int memsys5Size(void *p){
 static int memsys5Size(void *p){
   int iSize, i;
   int iSize, i;
@@ -19925,16 +19931,12 @@ static void *memsys5MallocUnsafe(int nByte){
   /* Keep track of the maximum allocation request.  Even unfulfilled
   /* Keep track of the maximum allocation request.  Even unfulfilled
   ** requests are counted */
   ** requests are counted */
   if( (u32)nByte>mem5.maxRequest ){
   if( (u32)nByte>mem5.maxRequest ){
+    /* Abort if the requested allocation size is larger than the largest
+    ** power of two that we can represent using 32-bit signed integers. */
+    if( nByte > 0x40000000 ) return 0;
     mem5.maxRequest = nByte;
     mem5.maxRequest = nByte;
   }
   }
 
 
-  /* Abort if the requested allocation size is larger than the largest
-  ** power of two that we can represent using 32-bit signed integers.
-  */
-  if( nByte > 0x40000000 ){
-    return 0;
-  }
-
   /* Round nByte up to the next valid power of two */
   /* Round nByte up to the next valid power of two */
   for(iFullSz=mem5.szAtom,iLogsize=0; iFullSz<nByte; iFullSz*=2,iLogsize++){}
   for(iFullSz=mem5.szAtom,iLogsize=0; iFullSz<nByte; iFullSz*=2,iLogsize++){}
 
 
@@ -20093,13 +20095,11 @@ static void *memsys5Realloc(void *pPrior, int nBytes){
   if( nBytes<=nOld ){
   if( nBytes<=nOld ){
     return pPrior;
     return pPrior;
   }
   }
-  memsys5Enter();
-  p = memsys5MallocUnsafe(nBytes);
+  p = memsys5Malloc(nBytes);
   if( p ){
   if( p ){
     memcpy(p, pPrior, nOld);
     memcpy(p, pPrior, nOld);
-    memsys5FreeUnsafe(pPrior);
+    memsys5Free(pPrior);
   }
   }
-  memsys5Leave();
   return p;
   return p;
 }
 }
 
 
@@ -20714,6 +20714,8 @@ struct sqlite3_mutex {
 };
 };
 #if SQLITE_MUTEX_NREF
 #if SQLITE_MUTEX_NREF
 #define SQLITE3_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER,0,0,(pthread_t)0,0}
 #define SQLITE3_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER,0,0,(pthread_t)0,0}
+#elif defined(SQLITE_ENABLE_API_ARMOR)
+#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0 }
 #else
 #else
 #define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
 #define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
 #endif
 #endif
@@ -24679,13 +24681,13 @@ SQLITE_PRIVATE int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
 /* #include <assert.h> */
 /* #include <assert.h> */
 /* #include "vdbeInt.h" */
 /* #include "vdbeInt.h" */
 
 
-#ifndef SQLITE_AMALGAMATION
+#if !defined(SQLITE_AMALGAMATION) && SQLITE_BYTEORDER==0
 /*
 /*
 ** The following constant value is used by the SQLITE_BIGENDIAN and
 ** The following constant value is used by the SQLITE_BIGENDIAN and
 ** SQLITE_LITTLEENDIAN macros.
 ** SQLITE_LITTLEENDIAN macros.
 */
 */
 SQLITE_PRIVATE const int sqlite3one = 1;
 SQLITE_PRIVATE const int sqlite3one = 1;
-#endif /* SQLITE_AMALGAMATION */
+#endif /* SQLITE_AMALGAMATION && SQLITE_BYTEORDER==0 */
 
 
 /*
 /*
 ** This lookup table is used to help decode the first byte of
 ** This lookup table is used to help decode the first byte of
@@ -42052,7 +42054,7 @@ static void *pcache1Alloc(int nByte){
 static void pcache1Free(void *p){
 static void pcache1Free(void *p){
   int nFreed = 0;
   int nFreed = 0;
   if( p==0 ) return;
   if( p==0 ) return;
-  if( p>=pcache1.pStart && p<pcache1.pEnd ){
+  if( SQLITE_WITHIN(p, pcache1.pStart, pcache1.pEnd) ){
     PgFreeslot *pSlot;
     PgFreeslot *pSlot;
     sqlite3_mutex_enter(pcache1.mutex);
     sqlite3_mutex_enter(pcache1.mutex);
     sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_USED, 1);
     sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_USED, 1);
@@ -61754,7 +61756,7 @@ static int rebuildPage(
   pData = pEnd;
   pData = pEnd;
   for(i=0; i<nCell; i++){
   for(i=0; i<nCell; i++){
     u8 *pCell = apCell[i];
     u8 *pCell = apCell[i];
-    if( pCell>aData && pCell<pEnd ){
+    if( SQLITE_WITHIN(pCell,aData,pEnd) ){
       pCell = &pTmp[pCell - aData];
       pCell = &pTmp[pCell - aData];
     }
     }
     pData -= szCell[i];
     pData -= szCell[i];
@@ -61865,7 +61867,7 @@ static int pageFreeArray(
 
 
   for(i=iFirst; i<iEnd; i++){
   for(i=iFirst; i<iEnd; i++){
     u8 *pCell = pCArray->apCell[i];
     u8 *pCell = pCArray->apCell[i];
-    if( pCell>=pStart && pCell<pEnd ){
+    if( SQLITE_WITHIN(pCell, pStart, pEnd) ){
       int sz;
       int sz;
       /* No need to use cachedCellSize() here.  The sizes of all cells that
       /* No need to use cachedCellSize() here.  The sizes of all cells that
       ** are to be freed have already been computing while deciding which
       ** are to be freed have already been computing while deciding which
@@ -75859,6 +75861,7 @@ case OP_Ge: {             /* same as TK_GE, jump, in1, in3 */
       */
       */
       if( pOp->p5 & SQLITE_STOREP2 ){
       if( pOp->p5 & SQLITE_STOREP2 ){
         pOut = &aMem[pOp->p2];
         pOut = &aMem[pOp->p2];
+        memAboutToChange(p, pOut);
         MemSetTypeFlag(pOut, MEM_Null);
         MemSetTypeFlag(pOut, MEM_Null);
         REGISTER_TRACE(pOp->p2, pOut);
         REGISTER_TRACE(pOp->p2, pOut);
       }else{
       }else{
@@ -76401,6 +76404,8 @@ case OP_Column: {
         rc = SQLITE_CORRUPT_BKPT;
         rc = SQLITE_CORRUPT_BKPT;
         goto op_column_error;
         goto op_column_error;
       }
       }
+    }else{
+      VVA_ONLY( t = 0; ) /* Only needed by assert() statements */
     }
     }
 
 
     /* If after trying to extract new entries from the header, nHdrParsed is
     /* If after trying to extract new entries from the header, nHdrParsed is
@@ -86946,7 +86951,7 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
         assert( ExprHasProperty(p, EP_Reduced)==0 );
         assert( ExprHasProperty(p, EP_Reduced)==0 );
         memcpy(zAlloc, p, nNewSize);
         memcpy(zAlloc, p, nNewSize);
       }else{
       }else{
-        int nSize = exprStructSize(p);
+        u32 nSize = (u32)exprStructSize(p);
         memcpy(zAlloc, p, nSize);
         memcpy(zAlloc, p, nSize);
         if( nSize<EXPR_FULLSIZE ){ 
         if( nSize<EXPR_FULLSIZE ){ 
           memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
           memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
@@ -88526,7 +88531,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(
     assert( pIdx->aColExpr );
     assert( pIdx->aColExpr );
     assert( pIdx->aColExpr->nExpr>iIdxCol );
     assert( pIdx->aColExpr->nExpr>iIdxCol );
     pParse->iSelfTab = iTabCur;
     pParse->iSelfTab = iTabCur;
-    sqlite3ExprCode(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
+    sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
   }else{
   }else{
     sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
     sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
                                     iTabCol, regOut);
                                     iTabCol, regOut);
@@ -89379,13 +89384,25 @@ SQLITE_PRIVATE void sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
     sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
     sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
   }else{
   }else{
     inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
     inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
-    assert( pParse->pVdbe || pParse->db->mallocFailed );
+    assert( pParse->pVdbe!=0 || pParse->db->mallocFailed );
     if( inReg!=target && pParse->pVdbe ){
     if( inReg!=target && pParse->pVdbe ){
       sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
       sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
     }
     }
   }
   }
 }
 }
 
 
+/*
+** Make a transient copy of expression pExpr and then code it using
+** sqlite3ExprCode().  This routine works just like sqlite3ExprCode()
+** except that the input expression is guaranteed to be unchanged.
+*/
+SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse *pParse, Expr *pExpr, int target){
+  sqlite3 *db = pParse->db;
+  pExpr = sqlite3ExprDup(db, pExpr, 0);
+  if( !db->mallocFailed ) sqlite3ExprCode(pParse, pExpr, target);
+  sqlite3ExprDelete(db, pExpr);
+}
+
 /*
 /*
 ** Generate code that will evaluate expression pExpr and store the
 ** Generate code that will evaluate expression pExpr and store the
 ** results in register target.  The results are guaranteed to appear
 ** results in register target.  The results are guaranteed to appear
@@ -104395,7 +104412,7 @@ SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(
       int x;
       int x;
       if( iField==XN_EXPR ){
       if( iField==XN_EXPR ){
         pParse->ckBase = regNewData+1;
         pParse->ckBase = regNewData+1;
-        sqlite3ExprCode(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
+        sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
         pParse->ckBase = 0;
         pParse->ckBase = 0;
         VdbeComment((v, "%s column %d", pIdx->zName, i));
         VdbeComment((v, "%s column %d", pIdx->zName, i));
       }else{
       }else{
@@ -106912,7 +106929,7 @@ static const struct sPragmaNames {
     /* ePragFlag: */ 0,
     /* ePragFlag: */ 0,
     /* iArg:      */ 0 },
     /* iArg:      */ 0 },
 #endif
 #endif
-#if defined(SQLITE_DEBUG)
+#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
   { /* zName:     */ "parser_trace",
   { /* zName:     */ "parser_trace",
     /* ePragTyp:  */ PragTyp_PARSER_TRACE,
     /* ePragTyp:  */ PragTyp_PARSER_TRACE,
     /* ePragFlag: */ 0,
     /* ePragFlag: */ 0,
@@ -168321,7 +168338,7 @@ static void jsonTest1Func(
 #endif /* SQLITE_DEBUG */
 #endif /* SQLITE_DEBUG */
 
 
 /****************************************************************************
 /****************************************************************************
-** SQL function implementations
+** Scalar SQL function implementations
 ****************************************************************************/
 ****************************************************************************/
 
 
 /*
 /*
@@ -168654,6 +168671,102 @@ static void jsonValidFunc(
   sqlite3_result_int(ctx, rc);
   sqlite3_result_int(ctx, rc);
 }
 }
 
 
+
+/****************************************************************************
+** Aggregate SQL function implementations
+****************************************************************************/
+/*
+** json_group_array(VALUE)
+**
+** Return a JSON array composed of all values in the aggregate.
+*/
+static void jsonArrayStep(
+  sqlite3_context *ctx,
+  int argc,
+  sqlite3_value **argv
+){
+  JsonString *pStr;
+  pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr));
+  if( pStr ){
+    if( pStr->zBuf==0 ){
+      jsonInit(pStr, ctx);
+      jsonAppendChar(pStr, '[');
+    }else{
+      jsonAppendChar(pStr, ',');
+      pStr->pCtx = ctx;
+    }
+    jsonAppendValue(pStr, argv[0]);
+  }
+}
+static void jsonArrayFinal(sqlite3_context *ctx){
+  JsonString *pStr;
+  pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
+  if( pStr ){
+    pStr->pCtx = ctx;
+    jsonAppendChar(pStr, ']');
+    if( pStr->bErr ){
+      sqlite3_result_error_nomem(ctx);
+      if( !pStr->bStatic ) sqlite3_free(pStr->zBuf);
+    }else{
+      sqlite3_result_text(ctx, pStr->zBuf, pStr->nUsed,
+                          pStr->bStatic ? SQLITE_TRANSIENT : sqlite3_free);
+      pStr->bStatic = 1;
+    }
+  }else{
+    sqlite3_result_text(ctx, "[]", 2, SQLITE_STATIC);
+  }
+  sqlite3_result_subtype(ctx, JSON_SUBTYPE);
+}
+
+/*
+** json_group_obj(NAME,VALUE)
+**
+** Return a JSON object composed of all names and values in the aggregate.
+*/
+static void jsonObjectStep(
+  sqlite3_context *ctx,
+  int argc,
+  sqlite3_value **argv
+){
+  JsonString *pStr;
+  const char *z;
+  u32 n;
+  pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr));
+  if( pStr ){
+    if( pStr->zBuf==0 ){
+      jsonInit(pStr, ctx);
+      jsonAppendChar(pStr, '{');
+    }else{
+      jsonAppendChar(pStr, ',');
+      pStr->pCtx = ctx;
+    }
+    z = (const char*)sqlite3_value_text(argv[0]);
+    n = (u32)sqlite3_value_bytes(argv[0]);
+    jsonAppendString(pStr, z, n);
+    jsonAppendChar(pStr, ':');
+    jsonAppendValue(pStr, argv[1]);
+  }
+}
+static void jsonObjectFinal(sqlite3_context *ctx){
+  JsonString *pStr;
+  pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
+  if( pStr ){
+    jsonAppendChar(pStr, '}');
+    if( pStr->bErr ){
+      sqlite3_result_error_nomem(ctx);
+      if( !pStr->bStatic ) sqlite3_free(pStr->zBuf);
+    }else{
+      sqlite3_result_text(ctx, pStr->zBuf, pStr->nUsed,
+                          pStr->bStatic ? SQLITE_TRANSIENT : sqlite3_free);
+      pStr->bStatic = 1;
+    }
+  }else{
+    sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC);
+  }
+  sqlite3_result_subtype(ctx, JSON_SUBTYPE);
+}
+
+
 #ifndef SQLITE_OMIT_VIRTUALTABLE
 #ifndef SQLITE_OMIT_VIRTUALTABLE
 /****************************************************************************
 /****************************************************************************
 ** The json_each virtual table
 ** The json_each virtual table
@@ -169152,6 +169265,15 @@ SQLITE_PRIVATE int sqlite3Json1Init(sqlite3 *db){
     { "json_test1",           1, 0,   jsonTest1Func         },
     { "json_test1",           1, 0,   jsonTest1Func         },
 #endif
 #endif
   };
   };
+  static const struct {
+     const char *zName;
+     int nArg;
+     void (*xStep)(sqlite3_context*,int,sqlite3_value**);
+     void (*xFinal)(sqlite3_context*);
+  } aAgg[] = {
+    { "json_group_array",     1,   jsonArrayStep,   jsonArrayFinal  },
+    { "json_group_object",    2,   jsonObjectStep,  jsonObjectFinal },
+  };
 #ifndef SQLITE_OMIT_VIRTUALTABLE
 #ifndef SQLITE_OMIT_VIRTUALTABLE
   static const struct {
   static const struct {
      const char *zName;
      const char *zName;
@@ -169167,6 +169289,11 @@ SQLITE_PRIVATE int sqlite3Json1Init(sqlite3 *db){
                                  (void*)&aFunc[i].flag,
                                  (void*)&aFunc[i].flag,
                                  aFunc[i].xFunc, 0, 0);
                                  aFunc[i].xFunc, 0, 0);
   }
   }
+  for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){
+    rc = sqlite3_create_function(db, aAgg[i].zName, aAgg[i].nArg,
+                                 SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0,
+                                 0, aAgg[i].xStep, aAgg[i].xFinal);
+  }
 #ifndef SQLITE_OMIT_VIRTUALTABLE
 #ifndef SQLITE_OMIT_VIRTUALTABLE
   for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
   for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
     rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
     rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
@@ -172206,7 +172333,7 @@ static int sqlite3Fts5AuxInit(fts5_api *pApi){
   int rc = SQLITE_OK;             /* Return code */
   int rc = SQLITE_OK;             /* Return code */
   int i;                          /* To iterate through builtin functions */
   int i;                          /* To iterate through builtin functions */
 
 
-  for(i=0; rc==SQLITE_OK && i<sizeof(aBuiltin)/sizeof(aBuiltin[0]); i++){
+  for(i=0; rc==SQLITE_OK && i<(int)ArraySize(aBuiltin); i++){
     rc = pApi->xCreateFunction(pApi,
     rc = pApi->xCreateFunction(pApi,
         aBuiltin[i].zFunc,
         aBuiltin[i].zFunc,
         aBuiltin[i].pUserData,
         aBuiltin[i].pUserData,
@@ -173830,7 +173957,7 @@ static int fts5ExprPhraseIsMatch(
 
 
   /* If the aStatic[] array is not large enough, allocate a large array
   /* If the aStatic[] array is not large enough, allocate a large array
   ** using sqlite3_malloc(). This approach could be improved upon. */
   ** using sqlite3_malloc(). This approach could be improved upon. */
-  if( pPhrase->nTerm>(sizeof(aStatic) / sizeof(aStatic[0])) ){
+  if( pPhrase->nTerm>(int)ArraySize(aStatic) ){
     int nByte = sizeof(Fts5PoslistReader) * pPhrase->nTerm;
     int nByte = sizeof(Fts5PoslistReader) * pPhrase->nTerm;
     aIter = (Fts5PoslistReader*)sqlite3_malloc(nByte);
     aIter = (Fts5PoslistReader*)sqlite3_malloc(nByte);
     if( !aIter ) return SQLITE_NOMEM;
     if( !aIter ) return SQLITE_NOMEM;
@@ -173853,7 +173980,7 @@ static int fts5ExprPhraseIsMatch(
     }
     }
     if( rc!=SQLITE_OK ) goto ismatch_out;
     if( rc!=SQLITE_OK ) goto ismatch_out;
     sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]);
     sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]);
-    aIter[i].bFlag = bFlag;
+    aIter[i].bFlag = (u8)bFlag;
     if( aIter[i].bEof ) goto ismatch_out;
     if( aIter[i].bEof ) goto ismatch_out;
   }
   }
 
 
@@ -173966,7 +174093,7 @@ static int fts5ExprNearIsMatch(int *pRc, Fts5ExprNearset *pNear){
 
 
   /* If the aStatic[] array is not large enough, allocate a large array
   /* If the aStatic[] array is not large enough, allocate a large array
   ** using sqlite3_malloc(). This approach could be improved upon. */
   ** using sqlite3_malloc(). This approach could be improved upon. */
-  if( pNear->nPhrase>(sizeof(aStatic) / sizeof(aStatic[0])) ){
+  if( pNear->nPhrase>(int)ArraySize(aStatic) ){
     int nByte = sizeof(Fts5NearTrimmer) * pNear->nPhrase;
     int nByte = sizeof(Fts5NearTrimmer) * pNear->nPhrase;
     a = (Fts5NearTrimmer*)sqlite3Fts5MallocZero(&rc, nByte);
     a = (Fts5NearTrimmer*)sqlite3Fts5MallocZero(&rc, nByte);
   }else{
   }else{
@@ -175613,7 +175740,7 @@ static int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){
   int rc = SQLITE_OK;
   int rc = SQLITE_OK;
   void *pCtx = (void*)pGlobal;
   void *pCtx = (void*)pGlobal;
 
 
-  for(i=0; rc==SQLITE_OK && i<(sizeof(aFunc) / sizeof(aFunc[0])); i++){
+  for(i=0; rc==SQLITE_OK && i<(int)ArraySize(aFunc); i++){
     struct Fts5ExprFunc *p = &aFunc[i];
     struct Fts5ExprFunc *p = &aFunc[i];
     rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
     rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
   }
   }
@@ -175851,7 +175978,7 @@ static void fts5HashAddPoslistSize(Fts5HashEntry *p){
 
 
     assert( p->bDel==0 || p->bDel==1 );
     assert( p->bDel==0 || p->bDel==1 );
     if( nPos<=127 ){
     if( nPos<=127 ){
-      pPtr[p->iSzPoslist] = nPos;
+      pPtr[p->iSzPoslist] = (u8)nPos;
     }else{
     }else{
       int nByte = sqlite3Fts5GetVarintLen((u32)nPos);
       int nByte = sqlite3Fts5GetVarintLen((u32)nPos);
       memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz);
       memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz);
@@ -178527,7 +178654,7 @@ static int fts5MultiIterDoCompare(Fts5IndexIter *pIter, int iOut){
     }
     }
   }
   }
 
 
-  pRes->iFirst = iRes;
+  pRes->iFirst = (u16)iRes;
   return 0;
   return 0;
 }
 }
 
 
@@ -178694,7 +178821,7 @@ static int fts5MultiIterAdvanceRowid(
           pIter->iSwitchRowid = pOther->iRowid;
           pIter->iSwitchRowid = pOther->iRowid;
         }
         }
       }
       }
-      pRes->iFirst = (pNew - pIter->aSeg);
+      pRes->iFirst = (u16)(pNew - pIter->aSeg);
       if( i==1 ) break;
       if( i==1 ) break;
 
 
       pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
       pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
@@ -178845,7 +178972,7 @@ static void fts5MultiIterNew(
   *ppOut = pNew = fts5MultiIterAlloc(p, nSeg);
   *ppOut = pNew = fts5MultiIterAlloc(p, nSeg);
   if( pNew==0 ) return;
   if( pNew==0 ) return;
   pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC));
   pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC));
-  pNew->bSkipEmpty = bSkipEmpty;
+  pNew->bSkipEmpty = (u8)bSkipEmpty;
   pNew->pStruct = pStruct;
   pNew->pStruct = pStruct;
   fts5StructureRef(pStruct);
   fts5StructureRef(pStruct);
 
 
@@ -179308,7 +179435,7 @@ static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
 
 
   /* Set the szLeaf header field. */
   /* Set the szLeaf header field. */
   assert( 0==fts5GetU16(&pPage->buf.p[2]) );
   assert( 0==fts5GetU16(&pPage->buf.p[2]) );
-  fts5PutU16(&pPage->buf.p[2], pPage->buf.n);
+  fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n);
 
 
   if( pWriter->bFirstTermInPage ){
   if( pWriter->bFirstTermInPage ){
     /* No term was written to this page. */
     /* No term was written to this page. */
@@ -179440,7 +179567,7 @@ static void fts5WriteAppendRowid(
     ** rowid-pointer in the page-header. Also append a value to the dlidx
     ** rowid-pointer in the page-header. Also append a value to the dlidx
     ** buffer, in case a doclist-index is required.  */
     ** buffer, in case a doclist-index is required.  */
     if( pWriter->bFirstRowidInPage ){
     if( pWriter->bFirstRowidInPage ){
-      fts5PutU16(pPage->buf.p, pPage->buf.n);
+      fts5PutU16(pPage->buf.p, (u16)pPage->buf.n);
       fts5WriteDlidxAppend(p, pWriter, iRowid);
       fts5WriteDlidxAppend(p, pWriter, iRowid);
     }
     }
 
 
@@ -179598,7 +179725,7 @@ static void fts5TrimSegments(Fts5Index *p, Fts5IndexIter *pIter){
         fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff, &pData->p[iOff]);
         fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff, &pData->p[iOff]);
         if( p->rc==SQLITE_OK ){
         if( p->rc==SQLITE_OK ){
           /* Set the szLeaf field */
           /* Set the szLeaf field */
-          fts5PutU16(&buf.p[2], buf.n);
+          fts5PutU16(&buf.p[2], (u16)buf.n);
         }
         }
 
 
         /* Set up the new page-index array */
         /* Set up the new page-index array */
@@ -179964,7 +180091,7 @@ static void fts5FlushOneHash(Fts5Index *p){
           iRowid += iDelta;
           iRowid += iDelta;
           
           
           if( writer.bFirstRowidInPage ){
           if( writer.bFirstRowidInPage ){
-            fts5PutU16(&pBuf->p[0], pBuf->n);   /* first rowid on page */
+            fts5PutU16(&pBuf->p[0], (u16)pBuf->n);   /* first rowid on page */
             pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
             pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
             writer.bFirstRowidInPage = 0;
             writer.bFirstRowidInPage = 0;
             fts5WriteDlidxAppend(p, &writer, iRowid);
             fts5WriteDlidxAppend(p, &writer, iRowid);
@@ -180761,7 +180888,8 @@ static int sqlite3Fts5IndexWrite(
     int nByte = fts5IndexCharlenToBytelen(pToken, nToken, pConfig->aPrefix[i]);
     int nByte = fts5IndexCharlenToBytelen(pToken, nToken, pConfig->aPrefix[i]);
     if( nByte ){
     if( nByte ){
       rc = sqlite3Fts5HashWrite(p->pHash, 
       rc = sqlite3Fts5HashWrite(p->pHash, 
-          p->iWriteRowid, iCol, iPos, FTS5_MAIN_PREFIX+i+1, pToken, nByte
+          p->iWriteRowid, iCol, iPos, (char)(FTS5_MAIN_PREFIX+i+1), pToken,
+          nByte
       );
       );
     }
     }
   }
   }
@@ -180811,7 +180939,7 @@ static int sqlite3Fts5IndexQuery(
 
 
     if( iIdx<=pConfig->nPrefix ){
     if( iIdx<=pConfig->nPrefix ){
       Fts5Structure *pStruct = fts5StructureRead(p);
       Fts5Structure *pStruct = fts5StructureRead(p);
-      buf.p[0] = FTS5_MAIN_PREFIX + iIdx;
+      buf.p[0] = (u8)(FTS5_MAIN_PREFIX + iIdx);
       if( pStruct ){
       if( pStruct ){
         fts5MultiIterNew(p, pStruct, 1, flags, buf.p, nToken+1, -1, 0, &pRet);
         fts5MultiIterNew(p, pStruct, 1, flags, buf.p, nToken+1, -1, 0, &pRet);
         fts5StructureRelease(pStruct);
         fts5StructureRelease(pStruct);
@@ -182466,7 +182594,7 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
   for(i=0; i<pInfo->nConstraint; i++){
   for(i=0; i<pInfo->nConstraint; i++){
     struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
     struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
     int j;
     int j;
-    for(j=0; j<sizeof(aConstraint)/sizeof(aConstraint[0]); j++){
+    for(j=0; j<(int)ArraySize(aConstraint); j++){
       struct Constraint *pC = &aConstraint[j];
       struct Constraint *pC = &aConstraint[j];
       if( p->iColumn==aColMap[pC->iCol] && p->op & pC->op ){
       if( p->iColumn==aColMap[pC->iCol] && p->op & pC->op ){
         if( p->usable ){
         if( p->usable ){
@@ -182513,11 +182641,11 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
 
 
   /* Assign argvIndex values to each constraint in use. */
   /* Assign argvIndex values to each constraint in use. */
   iNext = 1;
   iNext = 1;
-  for(i=0; i<sizeof(aConstraint)/sizeof(aConstraint[0]); i++){
+  for(i=0; i<(int)ArraySize(aConstraint); i++){
     struct Constraint *pC = &aConstraint[i];
     struct Constraint *pC = &aConstraint[i];
     if( pC->iConsIndex>=0 ){
     if( pC->iConsIndex>=0 ){
       pInfo->aConstraintUsage[pC->iConsIndex].argvIndex = iNext++;
       pInfo->aConstraintUsage[pC->iConsIndex].argvIndex = iNext++;
-      pInfo->aConstraintUsage[pC->iConsIndex].omit = pC->omit;
+      pInfo->aConstraintUsage[pC->iConsIndex].omit = (unsigned char)pC->omit;
     }
     }
   }
   }
 
 
@@ -184363,7 +184491,7 @@ static void fts5SourceIdFunc(
   sqlite3_value **apVal           /* Function arguments */
   sqlite3_value **apVal           /* Function arguments */
 ){
 ){
   assert( nArg==0 );
   assert( nArg==0 );
-  sqlite3_result_text(pCtx, "fts5: 2015-11-26 15:51:55 8b15621952889b4ba53b2ea3171fef7ef0479ddb", -1, SQLITE_TRANSIENT);
+  sqlite3_result_text(pCtx, "fts5: 2015-12-30 01:07:02 7f386a9332237100a345035ca213327e21d95855", -1, SQLITE_TRANSIENT);
 }
 }
 
 
 static int fts5Init(sqlite3 *db){
 static int fts5Init(sqlite3 *db){
@@ -184808,7 +184936,7 @@ static int sqlite3Fts5StorageClose(Fts5Storage *p){
     int i;
     int i;
 
 
     /* Finalize all SQL statements */
     /* Finalize all SQL statements */
-    for(i=0; i<ArraySize(p->aStmt); i++){
+    for(i=0; i<(int)ArraySize(p->aStmt); i++){
       sqlite3_finalize(p->aStmt[i]);
       sqlite3_finalize(p->aStmt[i]);
     }
     }
 
 
@@ -185830,7 +185958,7 @@ static int fts5UnicodeAddExceptions(
         int bToken;
         int bToken;
         READ_UTF8(zCsr, zTerm, iCode);
         READ_UTF8(zCsr, zTerm, iCode);
         if( iCode<128 ){
         if( iCode<128 ){
-          p->aTokenChar[iCode] = bTokenChars;
+          p->aTokenChar[iCode] = (unsigned char)bTokenChars;
         }else{
         }else{
           bToken = sqlite3Fts5UnicodeIsalnum(iCode);
           bToken = sqlite3Fts5UnicodeIsalnum(iCode);
           assert( (bToken==0 || bToken==1) ); 
           assert( (bToken==0 || bToken==1) ); 
@@ -186794,7 +186922,7 @@ static int sqlite3Fts5TokenizerInit(fts5_api *pApi){
   int rc = SQLITE_OK;             /* Return code */
   int rc = SQLITE_OK;             /* Return code */
   int i;                          /* To iterate through builtin functions */
   int i;                          /* To iterate through builtin functions */
 
 
-  for(i=0; rc==SQLITE_OK && i<sizeof(aBuiltin)/sizeof(aBuiltin[0]); i++){
+  for(i=0; rc==SQLITE_OK && i<(int)ArraySize(aBuiltin); i++){
     rc = pApi->xCreateTokenizer(pApi,
     rc = pApi->xCreateTokenizer(pApi,
         aBuiltin[i].zName,
         aBuiltin[i].zName,
         (void*)pApi,
         (void*)pApi,

+ 1 - 1
SquiLu-ext/sqlite3.h

@@ -113,7 +113,7 @@ extern "C" {
 */
 */
 #define SQLITE_VERSION        "3.10.0"
 #define SQLITE_VERSION        "3.10.0"
 #define SQLITE_VERSION_NUMBER 3010000
 #define SQLITE_VERSION_NUMBER 3010000
-#define SQLITE_SOURCE_ID      "2015-12-11 14:59:49 d8a12023be32bdc6df18b0a5f38b917799854342"
+#define SQLITE_SOURCE_ID      "2015-12-30 01:07:02 7f386a9332237100a345035ca213327e21d95855"
 
 
 /*
 /*
 ** CAPI3REF: Run-Time Library Version Numbers
 ** CAPI3REF: Run-Time Library Version Numbers