Fossil SCM
Update the built-in SQLite to the first 3.19.0 beta.
Commit
d6a0debd8c986dc25a71357f1e7b940179a41e38153097788b10cdeba3fd43d1
Parent
a53beaabdf08054…
2 files changed
+167
-54
+19
-7
+167
-54
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -398,11 +398,11 @@ | ||
| 398 | 398 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 399 | 399 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 400 | 400 | */ |
| 401 | 401 | #define SQLITE_VERSION "3.19.0" |
| 402 | 402 | #define SQLITE_VERSION_NUMBER 3019000 |
| 403 | -#define SQLITE_SOURCE_ID "2017-05-10 16:12:00 92ab1f7257d2866c69eaaf4cf85990677b911ef425e9c5a36a96978cccfb551c" | |
| 403 | +#define SQLITE_SOURCE_ID "2017-05-11 19:09:19 339df63f4064f3b9c8d4e8b82e72d00b49d9406bc350b14809a4caf7ddc4b736" | |
| 404 | 404 | |
| 405 | 405 | /* |
| 406 | 406 | ** CAPI3REF: Run-Time Library Version Numbers |
| 407 | 407 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 408 | 408 | ** |
| @@ -2948,10 +2948,11 @@ | ||
| 2948 | 2948 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2949 | 2949 | |
| 2950 | 2950 | /* |
| 2951 | 2951 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2952 | 2952 | ** METHOD: sqlite3 |
| 2953 | +** KEYWORDS: {authorizer callback} | |
| 2953 | 2954 | ** |
| 2954 | 2955 | ** ^This routine registers an authorizer callback with a particular |
| 2955 | 2956 | ** [database connection], supplied in the first argument. |
| 2956 | 2957 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2957 | 2958 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2975,20 +2976,26 @@ | ||
| 2975 | 2976 | ** |
| 2976 | 2977 | ** ^The first parameter to the authorizer callback is a copy of the third |
| 2977 | 2978 | ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter |
| 2978 | 2979 | ** to the callback is an integer [SQLITE_COPY | action code] that specifies |
| 2979 | 2980 | ** the particular action to be authorized. ^The third through sixth parameters |
| 2980 | -** to the callback are zero-terminated strings that contain additional | |
| 2981 | -** details about the action to be authorized. | |
| 2981 | +** to the callback are either NULL pointers or zero-terminated strings | |
| 2982 | +** that contain additional details about the action to be authorized. | |
| 2983 | +** Applications must always be prepared to encounter a NULL pointer in any | |
| 2984 | +** of the third through the sixth parameters of the authorization callback. | |
| 2982 | 2985 | ** |
| 2983 | 2986 | ** ^If the action code is [SQLITE_READ] |
| 2984 | 2987 | ** and the callback returns [SQLITE_IGNORE] then the |
| 2985 | 2988 | ** [prepared statement] statement is constructed to substitute |
| 2986 | 2989 | ** a NULL value in place of the table column that would have |
| 2987 | 2990 | ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] |
| 2988 | 2991 | ** return can be used to deny an untrusted user access to individual |
| 2989 | 2992 | ** columns of a table. |
| 2993 | +** ^When a table is referenced by a [SELECT] but no column values are | |
| 2994 | +** extracted from that table (for example in a query like | |
| 2995 | +** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback | |
| 2996 | +** is invoked once for that table with a column name that is an empty string. | |
| 2990 | 2997 | ** ^If the action code is [SQLITE_DELETE] and the callback returns |
| 2991 | 2998 | ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the |
| 2992 | 2999 | ** [truncate optimization] is disabled and all rows are deleted individually. |
| 2993 | 3000 | ** |
| 2994 | 3001 | ** An authorizer is used when [sqlite3_prepare | preparing] |
| @@ -5031,14 +5038,15 @@ | ||
| 5031 | 5038 | ** metadata associated with the pattern string. |
| 5032 | 5039 | ** Then as long as the pattern string remains the same, |
| 5033 | 5040 | ** the compiled regular expression can be reused on multiple |
| 5034 | 5041 | ** invocations of the same function. |
| 5035 | 5042 | ** |
| 5036 | -** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata | |
| 5037 | -** associated by the sqlite3_set_auxdata() function with the Nth argument | |
| 5038 | -** value to the application-defined function. ^If there is no metadata | |
| 5039 | -** associated with the function argument, this sqlite3_get_auxdata() interface | |
| 5043 | +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata | |
| 5044 | +** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument | |
| 5045 | +** value to the application-defined function. ^N is zero for the left-most | |
| 5046 | +** function argument. ^If there is no metadata | |
| 5047 | +** associated with the function argument, the sqlite3_get_auxdata(C,N) interface | |
| 5040 | 5048 | ** returns a NULL pointer. |
| 5041 | 5049 | ** |
| 5042 | 5050 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 5043 | 5051 | ** argument of the application-defined function. ^Subsequent |
| 5044 | 5052 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| @@ -5064,10 +5072,14 @@ | ||
| 5064 | 5072 | ** sqlite3_set_auxdata() has been called. |
| 5065 | 5073 | ** |
| 5066 | 5074 | ** ^(In practice, metadata is preserved between function calls for |
| 5067 | 5075 | ** function parameters that are compile-time constants, including literal |
| 5068 | 5076 | ** values and [parameters] and expressions composed from the same.)^ |
| 5077 | +** | |
| 5078 | +** The value of the N parameter to these interfaces should be non-negative. | |
| 5079 | +** Future enhancements may make use of negative N values to define new | |
| 5080 | +** kinds of function caching behavior. | |
| 5069 | 5081 | ** |
| 5070 | 5082 | ** These routines must be called from the same thread in which |
| 5071 | 5083 | ** the SQL function is running. |
| 5072 | 5084 | */ |
| 5073 | 5085 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
| @@ -18207,15 +18219,15 @@ | ||
| 18207 | 18219 | ** of this structure. All such structures associated with a single VM |
| 18208 | 18220 | ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed |
| 18209 | 18221 | ** when the VM is halted (if not before). |
| 18210 | 18222 | */ |
| 18211 | 18223 | struct AuxData { |
| 18212 | - int iOp; /* Instruction number of OP_Function opcode */ | |
| 18213 | - int iArg; /* Index of function argument. */ | |
| 18224 | + int iAuxOp; /* Instruction number of OP_Function opcode */ | |
| 18225 | + int iAuxArg; /* Index of function argument. */ | |
| 18214 | 18226 | void *pAux; /* Aux data pointer */ |
| 18215 | - void (*xDelete)(void *); /* Destructor for the aux data */ | |
| 18216 | - AuxData *pNext; /* Next element in list */ | |
| 18227 | + void (*xDeleteAux)(void*); /* Destructor for the aux data */ | |
| 18228 | + AuxData *pNextAux; /* Next element in list */ | |
| 18217 | 18229 | }; |
| 18218 | 18230 | |
| 18219 | 18231 | /* |
| 18220 | 18232 | ** The "context" argument for an installable function. A pointer to an |
| 18221 | 18233 | ** instance of this structure is the first argument to the routines used |
| @@ -74368,20 +74380,22 @@ | ||
| 74368 | 74380 | */ |
| 74369 | 74381 | SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *db, AuxData **pp, int iOp, int mask){ |
| 74370 | 74382 | while( *pp ){ |
| 74371 | 74383 | AuxData *pAux = *pp; |
| 74372 | 74384 | if( (iOp<0) |
| 74373 | - || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & MASKBIT32(pAux->iArg)))) | |
| 74385 | + || (pAux->iAuxOp==iOp | |
| 74386 | + && pAux->iAuxArg>=0 | |
| 74387 | + && (pAux->iAuxArg>31 || !(mask & MASKBIT32(pAux->iAuxArg)))) | |
| 74374 | 74388 | ){ |
| 74375 | - testcase( pAux->iArg==31 ); | |
| 74376 | - if( pAux->xDelete ){ | |
| 74377 | - pAux->xDelete(pAux->pAux); | |
| 74389 | + testcase( pAux->iAuxArg==31 ); | |
| 74390 | + if( pAux->xDeleteAux ){ | |
| 74391 | + pAux->xDeleteAux(pAux->pAux); | |
| 74378 | 74392 | } |
| 74379 | - *pp = pAux->pNext; | |
| 74393 | + *pp = pAux->pNextAux; | |
| 74380 | 74394 | sqlite3DbFree(db, pAux); |
| 74381 | 74395 | }else{ |
| 74382 | - pp= &pAux->pNext; | |
| 74396 | + pp= &pAux->pNextAux; | |
| 74383 | 74397 | } |
| 74384 | 74398 | } |
| 74385 | 74399 | } |
| 74386 | 74400 | |
| 74387 | 74401 | /* |
| @@ -76878,10 +76892,16 @@ | ||
| 76878 | 76892 | } |
| 76879 | 76893 | |
| 76880 | 76894 | /* |
| 76881 | 76895 | ** Return the auxiliary data pointer, if any, for the iArg'th argument to |
| 76882 | 76896 | ** the user-function defined by pCtx. |
| 76897 | +** | |
| 76898 | +** The left-most argument is 0. | |
| 76899 | +** | |
| 76900 | +** Undocumented behavior: If iArg is negative then access a cache of | |
| 76901 | +** auxiliary data pointers that is available to all functions within a | |
| 76902 | +** single prepared statement. The iArg values must match. | |
| 76883 | 76903 | */ |
| 76884 | 76904 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
| 76885 | 76905 | AuxData *pAuxData; |
| 76886 | 76906 | |
| 76887 | 76907 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| @@ -76888,21 +76908,28 @@ | ||
| 76888 | 76908 | #if SQLITE_ENABLE_STAT3_OR_STAT4 |
| 76889 | 76909 | if( pCtx->pVdbe==0 ) return 0; |
| 76890 | 76910 | #else |
| 76891 | 76911 | assert( pCtx->pVdbe!=0 ); |
| 76892 | 76912 | #endif |
| 76893 | - for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){ | |
| 76894 | - if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break; | |
| 76913 | + for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){ | |
| 76914 | + if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){ | |
| 76915 | + return pAuxData->pAux; | |
| 76916 | + } | |
| 76895 | 76917 | } |
| 76896 | - | |
| 76897 | - return (pAuxData ? pAuxData->pAux : 0); | |
| 76918 | + return 0; | |
| 76898 | 76919 | } |
| 76899 | 76920 | |
| 76900 | 76921 | /* |
| 76901 | 76922 | ** Set the auxiliary data pointer and delete function, for the iArg'th |
| 76902 | 76923 | ** argument to the user-function defined by pCtx. Any previous value is |
| 76903 | 76924 | ** deleted by calling the delete function specified when it was set. |
| 76925 | +** | |
| 76926 | +** The left-most argument is 0. | |
| 76927 | +** | |
| 76928 | +** Undocumented behavior: If iArg is negative then make the data available | |
| 76929 | +** to all functions within the current prepared statement using iArg as an | |
| 76930 | +** access code. | |
| 76904 | 76931 | */ |
| 76905 | 76932 | SQLITE_API void sqlite3_set_auxdata( |
| 76906 | 76933 | sqlite3_context *pCtx, |
| 76907 | 76934 | int iArg, |
| 76908 | 76935 | void *pAux, |
| @@ -76910,37 +76937,38 @@ | ||
| 76910 | 76937 | ){ |
| 76911 | 76938 | AuxData *pAuxData; |
| 76912 | 76939 | Vdbe *pVdbe = pCtx->pVdbe; |
| 76913 | 76940 | |
| 76914 | 76941 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 76915 | - if( iArg<0 ) goto failed; | |
| 76916 | 76942 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 76917 | 76943 | if( pVdbe==0 ) goto failed; |
| 76918 | 76944 | #else |
| 76919 | 76945 | assert( pVdbe!=0 ); |
| 76920 | 76946 | #endif |
| 76921 | 76947 | |
| 76922 | - for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){ | |
| 76923 | - if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break; | |
| 76948 | + for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){ | |
| 76949 | + if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){ | |
| 76950 | + break; | |
| 76951 | + } | |
| 76924 | 76952 | } |
| 76925 | 76953 | if( pAuxData==0 ){ |
| 76926 | 76954 | pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData)); |
| 76927 | 76955 | if( !pAuxData ) goto failed; |
| 76928 | - pAuxData->iOp = pCtx->iOp; | |
| 76929 | - pAuxData->iArg = iArg; | |
| 76930 | - pAuxData->pNext = pVdbe->pAuxData; | |
| 76956 | + pAuxData->iAuxOp = pCtx->iOp; | |
| 76957 | + pAuxData->iAuxArg = iArg; | |
| 76958 | + pAuxData->pNextAux = pVdbe->pAuxData; | |
| 76931 | 76959 | pVdbe->pAuxData = pAuxData; |
| 76932 | 76960 | if( pCtx->fErrorOrAux==0 ){ |
| 76933 | 76961 | pCtx->isError = 0; |
| 76934 | 76962 | pCtx->fErrorOrAux = 1; |
| 76935 | 76963 | } |
| 76936 | - }else if( pAuxData->xDelete ){ | |
| 76937 | - pAuxData->xDelete(pAuxData->pAux); | |
| 76964 | + }else if( pAuxData->xDeleteAux ){ | |
| 76965 | + pAuxData->xDeleteAux(pAuxData->pAux); | |
| 76938 | 76966 | } |
| 76939 | 76967 | |
| 76940 | 76968 | pAuxData->pAux = pAux; |
| 76941 | - pAuxData->xDelete = xDelete; | |
| 76969 | + pAuxData->xDeleteAux = xDelete; | |
| 76942 | 76970 | return; |
| 76943 | 76971 | |
| 76944 | 76972 | failed: |
| 76945 | 76973 | if( xDelete ){ |
| 76946 | 76974 | xDelete(pAux); |
| @@ -99595,10 +99623,22 @@ | ||
| 99595 | 99623 | } |
| 99596 | 99624 | |
| 99597 | 99625 | if( db->xAuth==0 ){ |
| 99598 | 99626 | return SQLITE_OK; |
| 99599 | 99627 | } |
| 99628 | + | |
| 99629 | + /* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the | |
| 99630 | + ** callback are either NULL pointers or zero-terminated strings that | |
| 99631 | + ** contain additional details about the action to be authorized. | |
| 99632 | + ** | |
| 99633 | + ** The following testcase() macros show that any of the 3rd through 6th | |
| 99634 | + ** parameters can be either NULL or a string. */ | |
| 99635 | + testcase( zArg1==0 ); | |
| 99636 | + testcase( zArg2==0 ); | |
| 99637 | + testcase( zArg3==0 ); | |
| 99638 | + testcase( pParse->zAuthContext==0 ); | |
| 99639 | + | |
| 99600 | 99640 | rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext |
| 99601 | 99641 | #ifdef SQLITE_USER_AUTHENTICATION |
| 99602 | 99642 | ,db->auth.zAuthUser |
| 99603 | 99643 | #endif |
| 99604 | 99644 | ); |
| @@ -104930,11 +104970,18 @@ | ||
| 104930 | 104970 | |
| 104931 | 104971 | #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 104932 | 104972 | /* Special case: A DELETE without a WHERE clause deletes everything. |
| 104933 | 104973 | ** It is easier just to erase the whole table. Prior to version 3.6.5, |
| 104934 | 104974 | ** this optimization caused the row change count (the value returned by |
| 104935 | - ** API function sqlite3_count_changes) to be set incorrectly. */ | |
| 104975 | + ** API function sqlite3_count_changes) to be set incorrectly. | |
| 104976 | + ** | |
| 104977 | + ** The "rcauth==SQLITE_OK" terms is the | |
| 104978 | + ** IMPLEMENATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and | |
| 104979 | + ** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but | |
| 104980 | + ** the truncate optimization is disabled and all rows are deleted | |
| 104981 | + ** individually. | |
| 104982 | + */ | |
| 104936 | 104983 | if( rcauth==SQLITE_OK |
| 104937 | 104984 | && pWhere==0 |
| 104938 | 104985 | && !bComplex |
| 104939 | 104986 | && !IsVirtual(pTab) |
| 104940 | 104987 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| @@ -121585,19 +121632,27 @@ | ||
| 121585 | 121632 | for(i=0; i<pTabList->nSrc; i++){ |
| 121586 | 121633 | struct SrcList_item *pItem = &pTabList->a[i]; |
| 121587 | 121634 | SelectDest dest; |
| 121588 | 121635 | Select *pSub; |
| 121589 | 121636 | |
| 121590 | - /* Issue SQLITE_READ authorizations with a NULL column name for any tables that | |
| 121637 | + /* Issue SQLITE_READ authorizations with a fake column name for any tables that | |
| 121591 | 121638 | ** are referenced but from which no values are extracted. Examples of where these |
| 121592 | 121639 | ** kinds of null SQLITE_READ authorizations would occur: |
| 121593 | 121640 | ** |
| 121594 | - ** SELECT count(*) FROM t1; -- SQLITE_READ t1 null | |
| 121595 | - ** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2 null | |
| 121641 | + ** SELECT count(*) FROM t1; -- SQLITE_READ t1."" | |
| 121642 | + ** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2."" | |
| 121643 | + ** | |
| 121644 | + ** The fake column name is an empty string. It is possible for a table to | |
| 121645 | + ** have a column named by the empty string, in which case there is no way to | |
| 121646 | + ** distinguish between an unreferenced table and an actual reference to the | |
| 121647 | + ** "" column. The original design was for the fake column name to be a NULL, | |
| 121648 | + ** which would be unambiguous. But legacy authorization callbacks might | |
| 121649 | + ** assume the column name is non-NULL and segfault. The use of an empty string | |
| 121650 | + ** for the fake column name seems safer. | |
| 121596 | 121651 | */ |
| 121597 | 121652 | if( pItem->colUsed==0 ){ |
| 121598 | - sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, pItem->zDatabase, 0); | |
| 121653 | + sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, "", pItem->zDatabase); | |
| 121599 | 121654 | } |
| 121600 | 121655 | |
| 121601 | 121656 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 121602 | 121657 | /* Generate code for all sub-queries in the FROM clause |
| 121603 | 121658 | */ |
| @@ -179491,10 +179546,11 @@ | ||
| 179491 | 179546 | const char *zJson; /* Original JSON string */ |
| 179492 | 179547 | u32 *aUp; /* Index of parent of each node */ |
| 179493 | 179548 | u8 oom; /* Set to true if out of memory */ |
| 179494 | 179549 | u8 nErr; /* Number of errors seen */ |
| 179495 | 179550 | u16 iDepth; /* Nesting depth */ |
| 179551 | + int nJson; /* Length of the zJson string in bytes */ | |
| 179496 | 179552 | }; |
| 179497 | 179553 | |
| 179498 | 179554 | /* |
| 179499 | 179555 | ** Maximum nesting depth of JSON for this implementation. |
| 179500 | 179556 | ** |
| @@ -179732,10 +179788,18 @@ | ||
| 179732 | 179788 | pParse->nNode = 0; |
| 179733 | 179789 | pParse->nAlloc = 0; |
| 179734 | 179790 | sqlite3_free(pParse->aUp); |
| 179735 | 179791 | pParse->aUp = 0; |
| 179736 | 179792 | } |
| 179793 | + | |
| 179794 | +/* | |
| 179795 | +** Free a JsonParse object that was obtained from sqlite3_malloc(). | |
| 179796 | +*/ | |
| 179797 | +static void jsonParseFree(JsonParse *pParse){ | |
| 179798 | + jsonParseReset(pParse); | |
| 179799 | + sqlite3_free(pParse); | |
| 179800 | +} | |
| 179737 | 179801 | |
| 179738 | 179802 | /* |
| 179739 | 179803 | ** Convert the JsonNode pNode into a pure JSON string and |
| 179740 | 179804 | ** append to pOut. Subsubstructure is also included. Return |
| 179741 | 179805 | ** the number of JsonNode objects that are encoded. |
| @@ -180283,10 +180347,53 @@ | ||
| 180283 | 180347 | return SQLITE_NOMEM; |
| 180284 | 180348 | } |
| 180285 | 180349 | jsonParseFillInParentage(pParse, 0, 0); |
| 180286 | 180350 | return SQLITE_OK; |
| 180287 | 180351 | } |
| 180352 | + | |
| 180353 | +/* | |
| 180354 | +** Magic number used for the JSON parse cache in sqlite3_get_auxdata() | |
| 180355 | +*/ | |
| 180356 | +#define JSON_CACHE_ID (-429938) | |
| 180357 | + | |
| 180358 | +/* | |
| 180359 | +** Obtain a complete parse of the JSON found in the first argument | |
| 180360 | +** of the argv array. Use the sqlite3_get_auxdata() cache for this | |
| 180361 | +** parse if it is available. If the cache is not available or if it | |
| 180362 | +** is no longer valid, parse the JSON again and return the new parse, | |
| 180363 | +** and also register the new parse so that it will be available for | |
| 180364 | +** future sqlite3_get_auxdata() calls. | |
| 180365 | +*/ | |
| 180366 | +static JsonParse *jsonParseCached( | |
| 180367 | + sqlite3_context *pCtx, | |
| 180368 | + sqlite3_value **argv | |
| 180369 | +){ | |
| 180370 | + const char *zJson = (const char*)sqlite3_value_text(argv[0]); | |
| 180371 | + int nJson = sqlite3_value_bytes(argv[0]); | |
| 180372 | + JsonParse *p; | |
| 180373 | + if( zJson==0 ) return 0; | |
| 180374 | + p = (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID); | |
| 180375 | + if( p && p->nJson==nJson && memcmp(p->zJson,zJson,nJson)==0 ){ | |
| 180376 | + p->nErr = 0; | |
| 180377 | + return p; /* The cached entry matches, so return it */ | |
| 180378 | + } | |
| 180379 | + p = sqlite3_malloc( sizeof(*p) + nJson + 1 ); | |
| 180380 | + if( p==0 ){ | |
| 180381 | + sqlite3_result_error_nomem(pCtx); | |
| 180382 | + return 0; | |
| 180383 | + } | |
| 180384 | + memset(p, 0, sizeof(*p)); | |
| 180385 | + p->zJson = (char*)&p[1]; | |
| 180386 | + memcpy((char*)p->zJson, zJson, nJson+1); | |
| 180387 | + if( jsonParse(p, pCtx, p->zJson) ){ | |
| 180388 | + sqlite3_free(p); | |
| 180389 | + return 0; | |
| 180390 | + } | |
| 180391 | + p->nJson = nJson; | |
| 180392 | + sqlite3_set_auxdata(pCtx, JSON_CACHE_ID, p, (void(*)(void*))jsonParseFree); | |
| 180393 | + return (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID); | |
| 180394 | +} | |
| 180288 | 180395 | |
| 180289 | 180396 | /* |
| 180290 | 180397 | ** Compare the OBJECT label at pNode against zKey,nKey. Return true on |
| 180291 | 180398 | ** a match. |
| 180292 | 180399 | */ |
| @@ -180649,33 +180756,34 @@ | ||
| 180649 | 180756 | static void jsonArrayLengthFunc( |
| 180650 | 180757 | sqlite3_context *ctx, |
| 180651 | 180758 | int argc, |
| 180652 | 180759 | sqlite3_value **argv |
| 180653 | 180760 | ){ |
| 180654 | - JsonParse x; /* The parse */ | |
| 180761 | + JsonParse *p; /* The parse */ | |
| 180655 | 180762 | sqlite3_int64 n = 0; |
| 180656 | 180763 | u32 i; |
| 180657 | 180764 | JsonNode *pNode; |
| 180658 | 180765 | |
| 180659 | - if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; | |
| 180660 | - assert( x.nNode ); | |
| 180766 | + p = jsonParseCached(ctx, argv); | |
| 180767 | + if( p==0 ) return; | |
| 180768 | + assert( p->nNode ); | |
| 180661 | 180769 | if( argc==2 ){ |
| 180662 | 180770 | const char *zPath = (const char*)sqlite3_value_text(argv[1]); |
| 180663 | - pNode = jsonLookup(&x, zPath, 0, ctx); | |
| 180771 | + pNode = jsonLookup(p, zPath, 0, ctx); | |
| 180664 | 180772 | }else{ |
| 180665 | - pNode = x.aNode; | |
| 180773 | + pNode = p->aNode; | |
| 180666 | 180774 | } |
| 180667 | 180775 | if( pNode==0 ){ |
| 180668 | - x.nErr = 1; | |
| 180669 | - }else if( pNode->eType==JSON_ARRAY ){ | |
| 180776 | + return; | |
| 180777 | + } | |
| 180778 | + if( pNode->eType==JSON_ARRAY ){ | |
| 180670 | 180779 | assert( (pNode->jnFlags & JNODE_APPEND)==0 ); |
| 180671 | 180780 | for(i=1; i<=pNode->n; n++){ |
| 180672 | 180781 | i += jsonNodeSize(&pNode[i]); |
| 180673 | 180782 | } |
| 180674 | 180783 | } |
| 180675 | - if( x.nErr==0 ) sqlite3_result_int64(ctx, n); | |
| 180676 | - jsonParseReset(&x); | |
| 180784 | + sqlite3_result_int64(ctx, n); | |
| 180677 | 180785 | } |
| 180678 | 180786 | |
| 180679 | 180787 | /* |
| 180680 | 180788 | ** json_extract(JSON, PATH, ...) |
| 180681 | 180789 | ** |
| @@ -180687,24 +180795,25 @@ | ||
| 180687 | 180795 | static void jsonExtractFunc( |
| 180688 | 180796 | sqlite3_context *ctx, |
| 180689 | 180797 | int argc, |
| 180690 | 180798 | sqlite3_value **argv |
| 180691 | 180799 | ){ |
| 180692 | - JsonParse x; /* The parse */ | |
| 180800 | + JsonParse *p; /* The parse */ | |
| 180693 | 180801 | JsonNode *pNode; |
| 180694 | 180802 | const char *zPath; |
| 180695 | 180803 | JsonString jx; |
| 180696 | 180804 | int i; |
| 180697 | 180805 | |
| 180698 | 180806 | if( argc<2 ) return; |
| 180699 | - if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; | |
| 180807 | + p = jsonParseCached(ctx, argv); | |
| 180808 | + if( p==0 ) return; | |
| 180700 | 180809 | jsonInit(&jx, ctx); |
| 180701 | 180810 | jsonAppendChar(&jx, '['); |
| 180702 | 180811 | for(i=1; i<argc; i++){ |
| 180703 | 180812 | zPath = (const char*)sqlite3_value_text(argv[i]); |
| 180704 | - pNode = jsonLookup(&x, zPath, 0, ctx); | |
| 180705 | - if( x.nErr ) break; | |
| 180813 | + pNode = jsonLookup(p, zPath, 0, ctx); | |
| 180814 | + if( p->nErr ) break; | |
| 180706 | 180815 | if( argc>2 ){ |
| 180707 | 180816 | jsonAppendSeparator(&jx); |
| 180708 | 180817 | if( pNode ){ |
| 180709 | 180818 | jsonRenderNode(pNode, &jx, 0); |
| 180710 | 180819 | }else{ |
| @@ -180718,11 +180827,10 @@ | ||
| 180718 | 180827 | jsonAppendChar(&jx, ']'); |
| 180719 | 180828 | jsonResult(&jx); |
| 180720 | 180829 | sqlite3_result_subtype(ctx, JSON_SUBTYPE); |
| 180721 | 180830 | } |
| 180722 | 180831 | jsonReset(&jx); |
| 180723 | - jsonParseReset(&x); | |
| 180724 | 180832 | } |
| 180725 | 180833 | |
| 180726 | 180834 | /* This is the RFC 7396 MergePatch algorithm. |
| 180727 | 180835 | */ |
| 180728 | 180836 | static JsonNode *jsonMergePatch( |
| @@ -193984,10 +194092,11 @@ | ||
| 193984 | 194092 | Fts5StructureSegment *pSeg; /* Output segment */ |
| 193985 | 194093 | Fts5Buffer term; |
| 193986 | 194094 | int bOldest; /* True if the output segment is the oldest */ |
| 193987 | 194095 | int eDetail = p->pConfig->eDetail; |
| 193988 | 194096 | const int flags = FTS5INDEX_QUERY_NOOUTPUT; |
| 194097 | + int bTermWritten = 0; /* True if current term already output */ | |
| 193989 | 194098 | |
| 193990 | 194099 | assert( iLvl<pStruct->nLevel ); |
| 193991 | 194100 | assert( pLvl->nMerge<=pLvl->nSeg ); |
| 193992 | 194101 | |
| 193993 | 194102 | memset(&writer, 0, sizeof(Fts5SegWriter)); |
| @@ -194037,22 +194146,26 @@ | ||
| 194037 | 194146 | Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; |
| 194038 | 194147 | int nPos; /* position-list size field value */ |
| 194039 | 194148 | int nTerm; |
| 194040 | 194149 | const u8 *pTerm; |
| 194041 | 194150 | |
| 194042 | - /* Check for key annihilation. */ | |
| 194043 | - if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue; | |
| 194044 | - | |
| 194045 | 194151 | pTerm = fts5MultiIterTerm(pIter, &nTerm); |
| 194046 | 194152 | if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){ |
| 194047 | 194153 | if( pnRem && writer.nLeafWritten>nRem ){ |
| 194048 | 194154 | break; |
| 194049 | 194155 | } |
| 194156 | + fts5BufferSet(&p->rc, &term, nTerm, pTerm); | |
| 194157 | + bTermWritten =0; | |
| 194158 | + } | |
| 194050 | 194159 | |
| 194160 | + /* Check for key annihilation. */ | |
| 194161 | + if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue; | |
| 194162 | + | |
| 194163 | + if( p->rc==SQLITE_OK && bTermWritten==0 ){ | |
| 194051 | 194164 | /* This is a new term. Append a term to the output segment. */ |
| 194052 | 194165 | fts5WriteAppendTerm(p, &writer, nTerm, pTerm); |
| 194053 | - fts5BufferSet(&p->rc, &term, nTerm, pTerm); | |
| 194166 | + bTermWritten = 1; | |
| 194054 | 194167 | } |
| 194055 | 194168 | |
| 194056 | 194169 | /* Append the rowid to the output */ |
| 194057 | 194170 | /* WRITEPOSLISTSIZE */ |
| 194058 | 194171 | fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter)); |
| @@ -198908,11 +199021,11 @@ | ||
| 198908 | 199021 | int nArg, /* Number of args */ |
| 198909 | 199022 | sqlite3_value **apUnused /* Function arguments */ |
| 198910 | 199023 | ){ |
| 198911 | 199024 | assert( nArg==0 ); |
| 198912 | 199025 | UNUSED_PARAM2(nArg, apUnused); |
| 198913 | - sqlite3_result_text(pCtx, "fts5: 2017-05-10 16:12:00 92ab1f7257d2866c69eaaf4cf85990677b911ef425e9c5a36a96978cccfb551c", -1, SQLITE_TRANSIENT); | |
| 199026 | + sqlite3_result_text(pCtx, "fts5: 2017-05-11 19:09:19 339df63f4064f3b9c8d4e8b82e72d00b49d9406bc350b14809a4caf7ddc4b736", -1, SQLITE_TRANSIENT); | |
| 198914 | 199027 | } |
| 198915 | 199028 | |
| 198916 | 199029 | static int fts5Init(sqlite3 *db){ |
| 198917 | 199030 | static const sqlite3_module fts5Mod = { |
| 198918 | 199031 | /* iVersion */ 2, |
| 198919 | 199032 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -398,11 +398,11 @@ | |
| 398 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 399 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 400 | */ |
| 401 | #define SQLITE_VERSION "3.19.0" |
| 402 | #define SQLITE_VERSION_NUMBER 3019000 |
| 403 | #define SQLITE_SOURCE_ID "2017-05-10 16:12:00 92ab1f7257d2866c69eaaf4cf85990677b911ef425e9c5a36a96978cccfb551c" |
| 404 | |
| 405 | /* |
| 406 | ** CAPI3REF: Run-Time Library Version Numbers |
| 407 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 408 | ** |
| @@ -2948,10 +2948,11 @@ | |
| 2948 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2949 | |
| 2950 | /* |
| 2951 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2952 | ** METHOD: sqlite3 |
| 2953 | ** |
| 2954 | ** ^This routine registers an authorizer callback with a particular |
| 2955 | ** [database connection], supplied in the first argument. |
| 2956 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2957 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2975,20 +2976,26 @@ | |
| 2975 | ** |
| 2976 | ** ^The first parameter to the authorizer callback is a copy of the third |
| 2977 | ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter |
| 2978 | ** to the callback is an integer [SQLITE_COPY | action code] that specifies |
| 2979 | ** the particular action to be authorized. ^The third through sixth parameters |
| 2980 | ** to the callback are zero-terminated strings that contain additional |
| 2981 | ** details about the action to be authorized. |
| 2982 | ** |
| 2983 | ** ^If the action code is [SQLITE_READ] |
| 2984 | ** and the callback returns [SQLITE_IGNORE] then the |
| 2985 | ** [prepared statement] statement is constructed to substitute |
| 2986 | ** a NULL value in place of the table column that would have |
| 2987 | ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] |
| 2988 | ** return can be used to deny an untrusted user access to individual |
| 2989 | ** columns of a table. |
| 2990 | ** ^If the action code is [SQLITE_DELETE] and the callback returns |
| 2991 | ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the |
| 2992 | ** [truncate optimization] is disabled and all rows are deleted individually. |
| 2993 | ** |
| 2994 | ** An authorizer is used when [sqlite3_prepare | preparing] |
| @@ -5031,14 +5038,15 @@ | |
| 5031 | ** metadata associated with the pattern string. |
| 5032 | ** Then as long as the pattern string remains the same, |
| 5033 | ** the compiled regular expression can be reused on multiple |
| 5034 | ** invocations of the same function. |
| 5035 | ** |
| 5036 | ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata |
| 5037 | ** associated by the sqlite3_set_auxdata() function with the Nth argument |
| 5038 | ** value to the application-defined function. ^If there is no metadata |
| 5039 | ** associated with the function argument, this sqlite3_get_auxdata() interface |
| 5040 | ** returns a NULL pointer. |
| 5041 | ** |
| 5042 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 5043 | ** argument of the application-defined function. ^Subsequent |
| 5044 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| @@ -5064,10 +5072,14 @@ | |
| 5064 | ** sqlite3_set_auxdata() has been called. |
| 5065 | ** |
| 5066 | ** ^(In practice, metadata is preserved between function calls for |
| 5067 | ** function parameters that are compile-time constants, including literal |
| 5068 | ** values and [parameters] and expressions composed from the same.)^ |
| 5069 | ** |
| 5070 | ** These routines must be called from the same thread in which |
| 5071 | ** the SQL function is running. |
| 5072 | */ |
| 5073 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
| @@ -18207,15 +18219,15 @@ | |
| 18207 | ** of this structure. All such structures associated with a single VM |
| 18208 | ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed |
| 18209 | ** when the VM is halted (if not before). |
| 18210 | */ |
| 18211 | struct AuxData { |
| 18212 | int iOp; /* Instruction number of OP_Function opcode */ |
| 18213 | int iArg; /* Index of function argument. */ |
| 18214 | void *pAux; /* Aux data pointer */ |
| 18215 | void (*xDelete)(void *); /* Destructor for the aux data */ |
| 18216 | AuxData *pNext; /* Next element in list */ |
| 18217 | }; |
| 18218 | |
| 18219 | /* |
| 18220 | ** The "context" argument for an installable function. A pointer to an |
| 18221 | ** instance of this structure is the first argument to the routines used |
| @@ -74368,20 +74380,22 @@ | |
| 74368 | */ |
| 74369 | SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *db, AuxData **pp, int iOp, int mask){ |
| 74370 | while( *pp ){ |
| 74371 | AuxData *pAux = *pp; |
| 74372 | if( (iOp<0) |
| 74373 | || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & MASKBIT32(pAux->iArg)))) |
| 74374 | ){ |
| 74375 | testcase( pAux->iArg==31 ); |
| 74376 | if( pAux->xDelete ){ |
| 74377 | pAux->xDelete(pAux->pAux); |
| 74378 | } |
| 74379 | *pp = pAux->pNext; |
| 74380 | sqlite3DbFree(db, pAux); |
| 74381 | }else{ |
| 74382 | pp= &pAux->pNext; |
| 74383 | } |
| 74384 | } |
| 74385 | } |
| 74386 | |
| 74387 | /* |
| @@ -76878,10 +76892,16 @@ | |
| 76878 | } |
| 76879 | |
| 76880 | /* |
| 76881 | ** Return the auxiliary data pointer, if any, for the iArg'th argument to |
| 76882 | ** the user-function defined by pCtx. |
| 76883 | */ |
| 76884 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
| 76885 | AuxData *pAuxData; |
| 76886 | |
| 76887 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| @@ -76888,21 +76908,28 @@ | |
| 76888 | #if SQLITE_ENABLE_STAT3_OR_STAT4 |
| 76889 | if( pCtx->pVdbe==0 ) return 0; |
| 76890 | #else |
| 76891 | assert( pCtx->pVdbe!=0 ); |
| 76892 | #endif |
| 76893 | for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){ |
| 76894 | if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break; |
| 76895 | } |
| 76896 | |
| 76897 | return (pAuxData ? pAuxData->pAux : 0); |
| 76898 | } |
| 76899 | |
| 76900 | /* |
| 76901 | ** Set the auxiliary data pointer and delete function, for the iArg'th |
| 76902 | ** argument to the user-function defined by pCtx. Any previous value is |
| 76903 | ** deleted by calling the delete function specified when it was set. |
| 76904 | */ |
| 76905 | SQLITE_API void sqlite3_set_auxdata( |
| 76906 | sqlite3_context *pCtx, |
| 76907 | int iArg, |
| 76908 | void *pAux, |
| @@ -76910,37 +76937,38 @@ | |
| 76910 | ){ |
| 76911 | AuxData *pAuxData; |
| 76912 | Vdbe *pVdbe = pCtx->pVdbe; |
| 76913 | |
| 76914 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 76915 | if( iArg<0 ) goto failed; |
| 76916 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 76917 | if( pVdbe==0 ) goto failed; |
| 76918 | #else |
| 76919 | assert( pVdbe!=0 ); |
| 76920 | #endif |
| 76921 | |
| 76922 | for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){ |
| 76923 | if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break; |
| 76924 | } |
| 76925 | if( pAuxData==0 ){ |
| 76926 | pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData)); |
| 76927 | if( !pAuxData ) goto failed; |
| 76928 | pAuxData->iOp = pCtx->iOp; |
| 76929 | pAuxData->iArg = iArg; |
| 76930 | pAuxData->pNext = pVdbe->pAuxData; |
| 76931 | pVdbe->pAuxData = pAuxData; |
| 76932 | if( pCtx->fErrorOrAux==0 ){ |
| 76933 | pCtx->isError = 0; |
| 76934 | pCtx->fErrorOrAux = 1; |
| 76935 | } |
| 76936 | }else if( pAuxData->xDelete ){ |
| 76937 | pAuxData->xDelete(pAuxData->pAux); |
| 76938 | } |
| 76939 | |
| 76940 | pAuxData->pAux = pAux; |
| 76941 | pAuxData->xDelete = xDelete; |
| 76942 | return; |
| 76943 | |
| 76944 | failed: |
| 76945 | if( xDelete ){ |
| 76946 | xDelete(pAux); |
| @@ -99595,10 +99623,22 @@ | |
| 99595 | } |
| 99596 | |
| 99597 | if( db->xAuth==0 ){ |
| 99598 | return SQLITE_OK; |
| 99599 | } |
| 99600 | rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext |
| 99601 | #ifdef SQLITE_USER_AUTHENTICATION |
| 99602 | ,db->auth.zAuthUser |
| 99603 | #endif |
| 99604 | ); |
| @@ -104930,11 +104970,18 @@ | |
| 104930 | |
| 104931 | #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 104932 | /* Special case: A DELETE without a WHERE clause deletes everything. |
| 104933 | ** It is easier just to erase the whole table. Prior to version 3.6.5, |
| 104934 | ** this optimization caused the row change count (the value returned by |
| 104935 | ** API function sqlite3_count_changes) to be set incorrectly. */ |
| 104936 | if( rcauth==SQLITE_OK |
| 104937 | && pWhere==0 |
| 104938 | && !bComplex |
| 104939 | && !IsVirtual(pTab) |
| 104940 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| @@ -121585,19 +121632,27 @@ | |
| 121585 | for(i=0; i<pTabList->nSrc; i++){ |
| 121586 | struct SrcList_item *pItem = &pTabList->a[i]; |
| 121587 | SelectDest dest; |
| 121588 | Select *pSub; |
| 121589 | |
| 121590 | /* Issue SQLITE_READ authorizations with a NULL column name for any tables that |
| 121591 | ** are referenced but from which no values are extracted. Examples of where these |
| 121592 | ** kinds of null SQLITE_READ authorizations would occur: |
| 121593 | ** |
| 121594 | ** SELECT count(*) FROM t1; -- SQLITE_READ t1 null |
| 121595 | ** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2 null |
| 121596 | */ |
| 121597 | if( pItem->colUsed==0 ){ |
| 121598 | sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, pItem->zDatabase, 0); |
| 121599 | } |
| 121600 | |
| 121601 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 121602 | /* Generate code for all sub-queries in the FROM clause |
| 121603 | */ |
| @@ -179491,10 +179546,11 @@ | |
| 179491 | const char *zJson; /* Original JSON string */ |
| 179492 | u32 *aUp; /* Index of parent of each node */ |
| 179493 | u8 oom; /* Set to true if out of memory */ |
| 179494 | u8 nErr; /* Number of errors seen */ |
| 179495 | u16 iDepth; /* Nesting depth */ |
| 179496 | }; |
| 179497 | |
| 179498 | /* |
| 179499 | ** Maximum nesting depth of JSON for this implementation. |
| 179500 | ** |
| @@ -179732,10 +179788,18 @@ | |
| 179732 | pParse->nNode = 0; |
| 179733 | pParse->nAlloc = 0; |
| 179734 | sqlite3_free(pParse->aUp); |
| 179735 | pParse->aUp = 0; |
| 179736 | } |
| 179737 | |
| 179738 | /* |
| 179739 | ** Convert the JsonNode pNode into a pure JSON string and |
| 179740 | ** append to pOut. Subsubstructure is also included. Return |
| 179741 | ** the number of JsonNode objects that are encoded. |
| @@ -180283,10 +180347,53 @@ | |
| 180283 | return SQLITE_NOMEM; |
| 180284 | } |
| 180285 | jsonParseFillInParentage(pParse, 0, 0); |
| 180286 | return SQLITE_OK; |
| 180287 | } |
| 180288 | |
| 180289 | /* |
| 180290 | ** Compare the OBJECT label at pNode against zKey,nKey. Return true on |
| 180291 | ** a match. |
| 180292 | */ |
| @@ -180649,33 +180756,34 @@ | |
| 180649 | static void jsonArrayLengthFunc( |
| 180650 | sqlite3_context *ctx, |
| 180651 | int argc, |
| 180652 | sqlite3_value **argv |
| 180653 | ){ |
| 180654 | JsonParse x; /* The parse */ |
| 180655 | sqlite3_int64 n = 0; |
| 180656 | u32 i; |
| 180657 | JsonNode *pNode; |
| 180658 | |
| 180659 | if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; |
| 180660 | assert( x.nNode ); |
| 180661 | if( argc==2 ){ |
| 180662 | const char *zPath = (const char*)sqlite3_value_text(argv[1]); |
| 180663 | pNode = jsonLookup(&x, zPath, 0, ctx); |
| 180664 | }else{ |
| 180665 | pNode = x.aNode; |
| 180666 | } |
| 180667 | if( pNode==0 ){ |
| 180668 | x.nErr = 1; |
| 180669 | }else if( pNode->eType==JSON_ARRAY ){ |
| 180670 | assert( (pNode->jnFlags & JNODE_APPEND)==0 ); |
| 180671 | for(i=1; i<=pNode->n; n++){ |
| 180672 | i += jsonNodeSize(&pNode[i]); |
| 180673 | } |
| 180674 | } |
| 180675 | if( x.nErr==0 ) sqlite3_result_int64(ctx, n); |
| 180676 | jsonParseReset(&x); |
| 180677 | } |
| 180678 | |
| 180679 | /* |
| 180680 | ** json_extract(JSON, PATH, ...) |
| 180681 | ** |
| @@ -180687,24 +180795,25 @@ | |
| 180687 | static void jsonExtractFunc( |
| 180688 | sqlite3_context *ctx, |
| 180689 | int argc, |
| 180690 | sqlite3_value **argv |
| 180691 | ){ |
| 180692 | JsonParse x; /* The parse */ |
| 180693 | JsonNode *pNode; |
| 180694 | const char *zPath; |
| 180695 | JsonString jx; |
| 180696 | int i; |
| 180697 | |
| 180698 | if( argc<2 ) return; |
| 180699 | if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; |
| 180700 | jsonInit(&jx, ctx); |
| 180701 | jsonAppendChar(&jx, '['); |
| 180702 | for(i=1; i<argc; i++){ |
| 180703 | zPath = (const char*)sqlite3_value_text(argv[i]); |
| 180704 | pNode = jsonLookup(&x, zPath, 0, ctx); |
| 180705 | if( x.nErr ) break; |
| 180706 | if( argc>2 ){ |
| 180707 | jsonAppendSeparator(&jx); |
| 180708 | if( pNode ){ |
| 180709 | jsonRenderNode(pNode, &jx, 0); |
| 180710 | }else{ |
| @@ -180718,11 +180827,10 @@ | |
| 180718 | jsonAppendChar(&jx, ']'); |
| 180719 | jsonResult(&jx); |
| 180720 | sqlite3_result_subtype(ctx, JSON_SUBTYPE); |
| 180721 | } |
| 180722 | jsonReset(&jx); |
| 180723 | jsonParseReset(&x); |
| 180724 | } |
| 180725 | |
| 180726 | /* This is the RFC 7396 MergePatch algorithm. |
| 180727 | */ |
| 180728 | static JsonNode *jsonMergePatch( |
| @@ -193984,10 +194092,11 @@ | |
| 193984 | Fts5StructureSegment *pSeg; /* Output segment */ |
| 193985 | Fts5Buffer term; |
| 193986 | int bOldest; /* True if the output segment is the oldest */ |
| 193987 | int eDetail = p->pConfig->eDetail; |
| 193988 | const int flags = FTS5INDEX_QUERY_NOOUTPUT; |
| 193989 | |
| 193990 | assert( iLvl<pStruct->nLevel ); |
| 193991 | assert( pLvl->nMerge<=pLvl->nSeg ); |
| 193992 | |
| 193993 | memset(&writer, 0, sizeof(Fts5SegWriter)); |
| @@ -194037,22 +194146,26 @@ | |
| 194037 | Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; |
| 194038 | int nPos; /* position-list size field value */ |
| 194039 | int nTerm; |
| 194040 | const u8 *pTerm; |
| 194041 | |
| 194042 | /* Check for key annihilation. */ |
| 194043 | if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue; |
| 194044 | |
| 194045 | pTerm = fts5MultiIterTerm(pIter, &nTerm); |
| 194046 | if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){ |
| 194047 | if( pnRem && writer.nLeafWritten>nRem ){ |
| 194048 | break; |
| 194049 | } |
| 194050 | |
| 194051 | /* This is a new term. Append a term to the output segment. */ |
| 194052 | fts5WriteAppendTerm(p, &writer, nTerm, pTerm); |
| 194053 | fts5BufferSet(&p->rc, &term, nTerm, pTerm); |
| 194054 | } |
| 194055 | |
| 194056 | /* Append the rowid to the output */ |
| 194057 | /* WRITEPOSLISTSIZE */ |
| 194058 | fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter)); |
| @@ -198908,11 +199021,11 @@ | |
| 198908 | int nArg, /* Number of args */ |
| 198909 | sqlite3_value **apUnused /* Function arguments */ |
| 198910 | ){ |
| 198911 | assert( nArg==0 ); |
| 198912 | UNUSED_PARAM2(nArg, apUnused); |
| 198913 | sqlite3_result_text(pCtx, "fts5: 2017-05-10 16:12:00 92ab1f7257d2866c69eaaf4cf85990677b911ef425e9c5a36a96978cccfb551c", -1, SQLITE_TRANSIENT); |
| 198914 | } |
| 198915 | |
| 198916 | static int fts5Init(sqlite3 *db){ |
| 198917 | static const sqlite3_module fts5Mod = { |
| 198918 | /* iVersion */ 2, |
| 198919 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -398,11 +398,11 @@ | |
| 398 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 399 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 400 | */ |
| 401 | #define SQLITE_VERSION "3.19.0" |
| 402 | #define SQLITE_VERSION_NUMBER 3019000 |
| 403 | #define SQLITE_SOURCE_ID "2017-05-11 19:09:19 339df63f4064f3b9c8d4e8b82e72d00b49d9406bc350b14809a4caf7ddc4b736" |
| 404 | |
| 405 | /* |
| 406 | ** CAPI3REF: Run-Time Library Version Numbers |
| 407 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 408 | ** |
| @@ -2948,10 +2948,11 @@ | |
| 2948 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2949 | |
| 2950 | /* |
| 2951 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2952 | ** METHOD: sqlite3 |
| 2953 | ** KEYWORDS: {authorizer callback} |
| 2954 | ** |
| 2955 | ** ^This routine registers an authorizer callback with a particular |
| 2956 | ** [database connection], supplied in the first argument. |
| 2957 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2958 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2975,20 +2976,26 @@ | |
| 2976 | ** |
| 2977 | ** ^The first parameter to the authorizer callback is a copy of the third |
| 2978 | ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter |
| 2979 | ** to the callback is an integer [SQLITE_COPY | action code] that specifies |
| 2980 | ** the particular action to be authorized. ^The third through sixth parameters |
| 2981 | ** to the callback are either NULL pointers or zero-terminated strings |
| 2982 | ** that contain additional details about the action to be authorized. |
| 2983 | ** Applications must always be prepared to encounter a NULL pointer in any |
| 2984 | ** of the third through the sixth parameters of the authorization callback. |
| 2985 | ** |
| 2986 | ** ^If the action code is [SQLITE_READ] |
| 2987 | ** and the callback returns [SQLITE_IGNORE] then the |
| 2988 | ** [prepared statement] statement is constructed to substitute |
| 2989 | ** a NULL value in place of the table column that would have |
| 2990 | ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] |
| 2991 | ** return can be used to deny an untrusted user access to individual |
| 2992 | ** columns of a table. |
| 2993 | ** ^When a table is referenced by a [SELECT] but no column values are |
| 2994 | ** extracted from that table (for example in a query like |
| 2995 | ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback |
| 2996 | ** is invoked once for that table with a column name that is an empty string. |
| 2997 | ** ^If the action code is [SQLITE_DELETE] and the callback returns |
| 2998 | ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the |
| 2999 | ** [truncate optimization] is disabled and all rows are deleted individually. |
| 3000 | ** |
| 3001 | ** An authorizer is used when [sqlite3_prepare | preparing] |
| @@ -5031,14 +5038,15 @@ | |
| 5038 | ** metadata associated with the pattern string. |
| 5039 | ** Then as long as the pattern string remains the same, |
| 5040 | ** the compiled regular expression can be reused on multiple |
| 5041 | ** invocations of the same function. |
| 5042 | ** |
| 5043 | ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata |
| 5044 | ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument |
| 5045 | ** value to the application-defined function. ^N is zero for the left-most |
| 5046 | ** function argument. ^If there is no metadata |
| 5047 | ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface |
| 5048 | ** returns a NULL pointer. |
| 5049 | ** |
| 5050 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 5051 | ** argument of the application-defined function. ^Subsequent |
| 5052 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| @@ -5064,10 +5072,14 @@ | |
| 5072 | ** sqlite3_set_auxdata() has been called. |
| 5073 | ** |
| 5074 | ** ^(In practice, metadata is preserved between function calls for |
| 5075 | ** function parameters that are compile-time constants, including literal |
| 5076 | ** values and [parameters] and expressions composed from the same.)^ |
| 5077 | ** |
| 5078 | ** The value of the N parameter to these interfaces should be non-negative. |
| 5079 | ** Future enhancements may make use of negative N values to define new |
| 5080 | ** kinds of function caching behavior. |
| 5081 | ** |
| 5082 | ** These routines must be called from the same thread in which |
| 5083 | ** the SQL function is running. |
| 5084 | */ |
| 5085 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
| @@ -18207,15 +18219,15 @@ | |
| 18219 | ** of this structure. All such structures associated with a single VM |
| 18220 | ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed |
| 18221 | ** when the VM is halted (if not before). |
| 18222 | */ |
| 18223 | struct AuxData { |
| 18224 | int iAuxOp; /* Instruction number of OP_Function opcode */ |
| 18225 | int iAuxArg; /* Index of function argument. */ |
| 18226 | void *pAux; /* Aux data pointer */ |
| 18227 | void (*xDeleteAux)(void*); /* Destructor for the aux data */ |
| 18228 | AuxData *pNextAux; /* Next element in list */ |
| 18229 | }; |
| 18230 | |
| 18231 | /* |
| 18232 | ** The "context" argument for an installable function. A pointer to an |
| 18233 | ** instance of this structure is the first argument to the routines used |
| @@ -74368,20 +74380,22 @@ | |
| 74380 | */ |
| 74381 | SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *db, AuxData **pp, int iOp, int mask){ |
| 74382 | while( *pp ){ |
| 74383 | AuxData *pAux = *pp; |
| 74384 | if( (iOp<0) |
| 74385 | || (pAux->iAuxOp==iOp |
| 74386 | && pAux->iAuxArg>=0 |
| 74387 | && (pAux->iAuxArg>31 || !(mask & MASKBIT32(pAux->iAuxArg)))) |
| 74388 | ){ |
| 74389 | testcase( pAux->iAuxArg==31 ); |
| 74390 | if( pAux->xDeleteAux ){ |
| 74391 | pAux->xDeleteAux(pAux->pAux); |
| 74392 | } |
| 74393 | *pp = pAux->pNextAux; |
| 74394 | sqlite3DbFree(db, pAux); |
| 74395 | }else{ |
| 74396 | pp= &pAux->pNextAux; |
| 74397 | } |
| 74398 | } |
| 74399 | } |
| 74400 | |
| 74401 | /* |
| @@ -76878,10 +76892,16 @@ | |
| 76892 | } |
| 76893 | |
| 76894 | /* |
| 76895 | ** Return the auxiliary data pointer, if any, for the iArg'th argument to |
| 76896 | ** the user-function defined by pCtx. |
| 76897 | ** |
| 76898 | ** The left-most argument is 0. |
| 76899 | ** |
| 76900 | ** Undocumented behavior: If iArg is negative then access a cache of |
| 76901 | ** auxiliary data pointers that is available to all functions within a |
| 76902 | ** single prepared statement. The iArg values must match. |
| 76903 | */ |
| 76904 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
| 76905 | AuxData *pAuxData; |
| 76906 | |
| 76907 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| @@ -76888,21 +76908,28 @@ | |
| 76908 | #if SQLITE_ENABLE_STAT3_OR_STAT4 |
| 76909 | if( pCtx->pVdbe==0 ) return 0; |
| 76910 | #else |
| 76911 | assert( pCtx->pVdbe!=0 ); |
| 76912 | #endif |
| 76913 | for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){ |
| 76914 | if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){ |
| 76915 | return pAuxData->pAux; |
| 76916 | } |
| 76917 | } |
| 76918 | return 0; |
| 76919 | } |
| 76920 | |
| 76921 | /* |
| 76922 | ** Set the auxiliary data pointer and delete function, for the iArg'th |
| 76923 | ** argument to the user-function defined by pCtx. Any previous value is |
| 76924 | ** deleted by calling the delete function specified when it was set. |
| 76925 | ** |
| 76926 | ** The left-most argument is 0. |
| 76927 | ** |
| 76928 | ** Undocumented behavior: If iArg is negative then make the data available |
| 76929 | ** to all functions within the current prepared statement using iArg as an |
| 76930 | ** access code. |
| 76931 | */ |
| 76932 | SQLITE_API void sqlite3_set_auxdata( |
| 76933 | sqlite3_context *pCtx, |
| 76934 | int iArg, |
| 76935 | void *pAux, |
| @@ -76910,37 +76937,38 @@ | |
| 76937 | ){ |
| 76938 | AuxData *pAuxData; |
| 76939 | Vdbe *pVdbe = pCtx->pVdbe; |
| 76940 | |
| 76941 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 76942 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 76943 | if( pVdbe==0 ) goto failed; |
| 76944 | #else |
| 76945 | assert( pVdbe!=0 ); |
| 76946 | #endif |
| 76947 | |
| 76948 | for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){ |
| 76949 | if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){ |
| 76950 | break; |
| 76951 | } |
| 76952 | } |
| 76953 | if( pAuxData==0 ){ |
| 76954 | pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData)); |
| 76955 | if( !pAuxData ) goto failed; |
| 76956 | pAuxData->iAuxOp = pCtx->iOp; |
| 76957 | pAuxData->iAuxArg = iArg; |
| 76958 | pAuxData->pNextAux = pVdbe->pAuxData; |
| 76959 | pVdbe->pAuxData = pAuxData; |
| 76960 | if( pCtx->fErrorOrAux==0 ){ |
| 76961 | pCtx->isError = 0; |
| 76962 | pCtx->fErrorOrAux = 1; |
| 76963 | } |
| 76964 | }else if( pAuxData->xDeleteAux ){ |
| 76965 | pAuxData->xDeleteAux(pAuxData->pAux); |
| 76966 | } |
| 76967 | |
| 76968 | pAuxData->pAux = pAux; |
| 76969 | pAuxData->xDeleteAux = xDelete; |
| 76970 | return; |
| 76971 | |
| 76972 | failed: |
| 76973 | if( xDelete ){ |
| 76974 | xDelete(pAux); |
| @@ -99595,10 +99623,22 @@ | |
| 99623 | } |
| 99624 | |
| 99625 | if( db->xAuth==0 ){ |
| 99626 | return SQLITE_OK; |
| 99627 | } |
| 99628 | |
| 99629 | /* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the |
| 99630 | ** callback are either NULL pointers or zero-terminated strings that |
| 99631 | ** contain additional details about the action to be authorized. |
| 99632 | ** |
| 99633 | ** The following testcase() macros show that any of the 3rd through 6th |
| 99634 | ** parameters can be either NULL or a string. */ |
| 99635 | testcase( zArg1==0 ); |
| 99636 | testcase( zArg2==0 ); |
| 99637 | testcase( zArg3==0 ); |
| 99638 | testcase( pParse->zAuthContext==0 ); |
| 99639 | |
| 99640 | rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext |
| 99641 | #ifdef SQLITE_USER_AUTHENTICATION |
| 99642 | ,db->auth.zAuthUser |
| 99643 | #endif |
| 99644 | ); |
| @@ -104930,11 +104970,18 @@ | |
| 104970 | |
| 104971 | #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 104972 | /* Special case: A DELETE without a WHERE clause deletes everything. |
| 104973 | ** It is easier just to erase the whole table. Prior to version 3.6.5, |
| 104974 | ** this optimization caused the row change count (the value returned by |
| 104975 | ** API function sqlite3_count_changes) to be set incorrectly. |
| 104976 | ** |
| 104977 | ** The "rcauth==SQLITE_OK" terms is the |
| 104978 | ** IMPLEMENATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and |
| 104979 | ** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but |
| 104980 | ** the truncate optimization is disabled and all rows are deleted |
| 104981 | ** individually. |
| 104982 | */ |
| 104983 | if( rcauth==SQLITE_OK |
| 104984 | && pWhere==0 |
| 104985 | && !bComplex |
| 104986 | && !IsVirtual(pTab) |
| 104987 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| @@ -121585,19 +121632,27 @@ | |
| 121632 | for(i=0; i<pTabList->nSrc; i++){ |
| 121633 | struct SrcList_item *pItem = &pTabList->a[i]; |
| 121634 | SelectDest dest; |
| 121635 | Select *pSub; |
| 121636 | |
| 121637 | /* Issue SQLITE_READ authorizations with a fake column name for any tables that |
| 121638 | ** are referenced but from which no values are extracted. Examples of where these |
| 121639 | ** kinds of null SQLITE_READ authorizations would occur: |
| 121640 | ** |
| 121641 | ** SELECT count(*) FROM t1; -- SQLITE_READ t1."" |
| 121642 | ** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2."" |
| 121643 | ** |
| 121644 | ** The fake column name is an empty string. It is possible for a table to |
| 121645 | ** have a column named by the empty string, in which case there is no way to |
| 121646 | ** distinguish between an unreferenced table and an actual reference to the |
| 121647 | ** "" column. The original design was for the fake column name to be a NULL, |
| 121648 | ** which would be unambiguous. But legacy authorization callbacks might |
| 121649 | ** assume the column name is non-NULL and segfault. The use of an empty string |
| 121650 | ** for the fake column name seems safer. |
| 121651 | */ |
| 121652 | if( pItem->colUsed==0 ){ |
| 121653 | sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, "", pItem->zDatabase); |
| 121654 | } |
| 121655 | |
| 121656 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 121657 | /* Generate code for all sub-queries in the FROM clause |
| 121658 | */ |
| @@ -179491,10 +179546,11 @@ | |
| 179546 | const char *zJson; /* Original JSON string */ |
| 179547 | u32 *aUp; /* Index of parent of each node */ |
| 179548 | u8 oom; /* Set to true if out of memory */ |
| 179549 | u8 nErr; /* Number of errors seen */ |
| 179550 | u16 iDepth; /* Nesting depth */ |
| 179551 | int nJson; /* Length of the zJson string in bytes */ |
| 179552 | }; |
| 179553 | |
| 179554 | /* |
| 179555 | ** Maximum nesting depth of JSON for this implementation. |
| 179556 | ** |
| @@ -179732,10 +179788,18 @@ | |
| 179788 | pParse->nNode = 0; |
| 179789 | pParse->nAlloc = 0; |
| 179790 | sqlite3_free(pParse->aUp); |
| 179791 | pParse->aUp = 0; |
| 179792 | } |
| 179793 | |
| 179794 | /* |
| 179795 | ** Free a JsonParse object that was obtained from sqlite3_malloc(). |
| 179796 | */ |
| 179797 | static void jsonParseFree(JsonParse *pParse){ |
| 179798 | jsonParseReset(pParse); |
| 179799 | sqlite3_free(pParse); |
| 179800 | } |
| 179801 | |
| 179802 | /* |
| 179803 | ** Convert the JsonNode pNode into a pure JSON string and |
| 179804 | ** append to pOut. Subsubstructure is also included. Return |
| 179805 | ** the number of JsonNode objects that are encoded. |
| @@ -180283,10 +180347,53 @@ | |
| 180347 | return SQLITE_NOMEM; |
| 180348 | } |
| 180349 | jsonParseFillInParentage(pParse, 0, 0); |
| 180350 | return SQLITE_OK; |
| 180351 | } |
| 180352 | |
| 180353 | /* |
| 180354 | ** Magic number used for the JSON parse cache in sqlite3_get_auxdata() |
| 180355 | */ |
| 180356 | #define JSON_CACHE_ID (-429938) |
| 180357 | |
| 180358 | /* |
| 180359 | ** Obtain a complete parse of the JSON found in the first argument |
| 180360 | ** of the argv array. Use the sqlite3_get_auxdata() cache for this |
| 180361 | ** parse if it is available. If the cache is not available or if it |
| 180362 | ** is no longer valid, parse the JSON again and return the new parse, |
| 180363 | ** and also register the new parse so that it will be available for |
| 180364 | ** future sqlite3_get_auxdata() calls. |
| 180365 | */ |
| 180366 | static JsonParse *jsonParseCached( |
| 180367 | sqlite3_context *pCtx, |
| 180368 | sqlite3_value **argv |
| 180369 | ){ |
| 180370 | const char *zJson = (const char*)sqlite3_value_text(argv[0]); |
| 180371 | int nJson = sqlite3_value_bytes(argv[0]); |
| 180372 | JsonParse *p; |
| 180373 | if( zJson==0 ) return 0; |
| 180374 | p = (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID); |
| 180375 | if( p && p->nJson==nJson && memcmp(p->zJson,zJson,nJson)==0 ){ |
| 180376 | p->nErr = 0; |
| 180377 | return p; /* The cached entry matches, so return it */ |
| 180378 | } |
| 180379 | p = sqlite3_malloc( sizeof(*p) + nJson + 1 ); |
| 180380 | if( p==0 ){ |
| 180381 | sqlite3_result_error_nomem(pCtx); |
| 180382 | return 0; |
| 180383 | } |
| 180384 | memset(p, 0, sizeof(*p)); |
| 180385 | p->zJson = (char*)&p[1]; |
| 180386 | memcpy((char*)p->zJson, zJson, nJson+1); |
| 180387 | if( jsonParse(p, pCtx, p->zJson) ){ |
| 180388 | sqlite3_free(p); |
| 180389 | return 0; |
| 180390 | } |
| 180391 | p->nJson = nJson; |
| 180392 | sqlite3_set_auxdata(pCtx, JSON_CACHE_ID, p, (void(*)(void*))jsonParseFree); |
| 180393 | return (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID); |
| 180394 | } |
| 180395 | |
| 180396 | /* |
| 180397 | ** Compare the OBJECT label at pNode against zKey,nKey. Return true on |
| 180398 | ** a match. |
| 180399 | */ |
| @@ -180649,33 +180756,34 @@ | |
| 180756 | static void jsonArrayLengthFunc( |
| 180757 | sqlite3_context *ctx, |
| 180758 | int argc, |
| 180759 | sqlite3_value **argv |
| 180760 | ){ |
| 180761 | JsonParse *p; /* The parse */ |
| 180762 | sqlite3_int64 n = 0; |
| 180763 | u32 i; |
| 180764 | JsonNode *pNode; |
| 180765 | |
| 180766 | p = jsonParseCached(ctx, argv); |
| 180767 | if( p==0 ) return; |
| 180768 | assert( p->nNode ); |
| 180769 | if( argc==2 ){ |
| 180770 | const char *zPath = (const char*)sqlite3_value_text(argv[1]); |
| 180771 | pNode = jsonLookup(p, zPath, 0, ctx); |
| 180772 | }else{ |
| 180773 | pNode = p->aNode; |
| 180774 | } |
| 180775 | if( pNode==0 ){ |
| 180776 | return; |
| 180777 | } |
| 180778 | if( pNode->eType==JSON_ARRAY ){ |
| 180779 | assert( (pNode->jnFlags & JNODE_APPEND)==0 ); |
| 180780 | for(i=1; i<=pNode->n; n++){ |
| 180781 | i += jsonNodeSize(&pNode[i]); |
| 180782 | } |
| 180783 | } |
| 180784 | sqlite3_result_int64(ctx, n); |
| 180785 | } |
| 180786 | |
| 180787 | /* |
| 180788 | ** json_extract(JSON, PATH, ...) |
| 180789 | ** |
| @@ -180687,24 +180795,25 @@ | |
| 180795 | static void jsonExtractFunc( |
| 180796 | sqlite3_context *ctx, |
| 180797 | int argc, |
| 180798 | sqlite3_value **argv |
| 180799 | ){ |
| 180800 | JsonParse *p; /* The parse */ |
| 180801 | JsonNode *pNode; |
| 180802 | const char *zPath; |
| 180803 | JsonString jx; |
| 180804 | int i; |
| 180805 | |
| 180806 | if( argc<2 ) return; |
| 180807 | p = jsonParseCached(ctx, argv); |
| 180808 | if( p==0 ) return; |
| 180809 | jsonInit(&jx, ctx); |
| 180810 | jsonAppendChar(&jx, '['); |
| 180811 | for(i=1; i<argc; i++){ |
| 180812 | zPath = (const char*)sqlite3_value_text(argv[i]); |
| 180813 | pNode = jsonLookup(p, zPath, 0, ctx); |
| 180814 | if( p->nErr ) break; |
| 180815 | if( argc>2 ){ |
| 180816 | jsonAppendSeparator(&jx); |
| 180817 | if( pNode ){ |
| 180818 | jsonRenderNode(pNode, &jx, 0); |
| 180819 | }else{ |
| @@ -180718,11 +180827,10 @@ | |
| 180827 | jsonAppendChar(&jx, ']'); |
| 180828 | jsonResult(&jx); |
| 180829 | sqlite3_result_subtype(ctx, JSON_SUBTYPE); |
| 180830 | } |
| 180831 | jsonReset(&jx); |
| 180832 | } |
| 180833 | |
| 180834 | /* This is the RFC 7396 MergePatch algorithm. |
| 180835 | */ |
| 180836 | static JsonNode *jsonMergePatch( |
| @@ -193984,10 +194092,11 @@ | |
| 194092 | Fts5StructureSegment *pSeg; /* Output segment */ |
| 194093 | Fts5Buffer term; |
| 194094 | int bOldest; /* True if the output segment is the oldest */ |
| 194095 | int eDetail = p->pConfig->eDetail; |
| 194096 | const int flags = FTS5INDEX_QUERY_NOOUTPUT; |
| 194097 | int bTermWritten = 0; /* True if current term already output */ |
| 194098 | |
| 194099 | assert( iLvl<pStruct->nLevel ); |
| 194100 | assert( pLvl->nMerge<=pLvl->nSeg ); |
| 194101 | |
| 194102 | memset(&writer, 0, sizeof(Fts5SegWriter)); |
| @@ -194037,22 +194146,26 @@ | |
| 194146 | Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; |
| 194147 | int nPos; /* position-list size field value */ |
| 194148 | int nTerm; |
| 194149 | const u8 *pTerm; |
| 194150 | |
| 194151 | pTerm = fts5MultiIterTerm(pIter, &nTerm); |
| 194152 | if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){ |
| 194153 | if( pnRem && writer.nLeafWritten>nRem ){ |
| 194154 | break; |
| 194155 | } |
| 194156 | fts5BufferSet(&p->rc, &term, nTerm, pTerm); |
| 194157 | bTermWritten =0; |
| 194158 | } |
| 194159 | |
| 194160 | /* Check for key annihilation. */ |
| 194161 | if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue; |
| 194162 | |
| 194163 | if( p->rc==SQLITE_OK && bTermWritten==0 ){ |
| 194164 | /* This is a new term. Append a term to the output segment. */ |
| 194165 | fts5WriteAppendTerm(p, &writer, nTerm, pTerm); |
| 194166 | bTermWritten = 1; |
| 194167 | } |
| 194168 | |
| 194169 | /* Append the rowid to the output */ |
| 194170 | /* WRITEPOSLISTSIZE */ |
| 194171 | fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter)); |
| @@ -198908,11 +199021,11 @@ | |
| 199021 | int nArg, /* Number of args */ |
| 199022 | sqlite3_value **apUnused /* Function arguments */ |
| 199023 | ){ |
| 199024 | assert( nArg==0 ); |
| 199025 | UNUSED_PARAM2(nArg, apUnused); |
| 199026 | sqlite3_result_text(pCtx, "fts5: 2017-05-11 19:09:19 339df63f4064f3b9c8d4e8b82e72d00b49d9406bc350b14809a4caf7ddc4b736", -1, SQLITE_TRANSIENT); |
| 199027 | } |
| 199028 | |
| 199029 | static int fts5Init(sqlite3 *db){ |
| 199030 | static const sqlite3_module fts5Mod = { |
| 199031 | /* iVersion */ 2, |
| 199032 |
+19
-7
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -121,11 +121,11 @@ | ||
| 121 | 121 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 122 | 122 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 123 | 123 | */ |
| 124 | 124 | #define SQLITE_VERSION "3.19.0" |
| 125 | 125 | #define SQLITE_VERSION_NUMBER 3019000 |
| 126 | -#define SQLITE_SOURCE_ID "2017-05-10 16:12:00 92ab1f7257d2866c69eaaf4cf85990677b911ef425e9c5a36a96978cccfb551c" | |
| 126 | +#define SQLITE_SOURCE_ID "2017-05-11 19:09:19 339df63f4064f3b9c8d4e8b82e72d00b49d9406bc350b14809a4caf7ddc4b736" | |
| 127 | 127 | |
| 128 | 128 | /* |
| 129 | 129 | ** CAPI3REF: Run-Time Library Version Numbers |
| 130 | 130 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 131 | 131 | ** |
| @@ -2671,10 +2671,11 @@ | ||
| 2671 | 2671 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2672 | 2672 | |
| 2673 | 2673 | /* |
| 2674 | 2674 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2675 | 2675 | ** METHOD: sqlite3 |
| 2676 | +** KEYWORDS: {authorizer callback} | |
| 2676 | 2677 | ** |
| 2677 | 2678 | ** ^This routine registers an authorizer callback with a particular |
| 2678 | 2679 | ** [database connection], supplied in the first argument. |
| 2679 | 2680 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2680 | 2681 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2698,20 +2699,26 @@ | ||
| 2698 | 2699 | ** |
| 2699 | 2700 | ** ^The first parameter to the authorizer callback is a copy of the third |
| 2700 | 2701 | ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter |
| 2701 | 2702 | ** to the callback is an integer [SQLITE_COPY | action code] that specifies |
| 2702 | 2703 | ** the particular action to be authorized. ^The third through sixth parameters |
| 2703 | -** to the callback are zero-terminated strings that contain additional | |
| 2704 | -** details about the action to be authorized. | |
| 2704 | +** to the callback are either NULL pointers or zero-terminated strings | |
| 2705 | +** that contain additional details about the action to be authorized. | |
| 2706 | +** Applications must always be prepared to encounter a NULL pointer in any | |
| 2707 | +** of the third through the sixth parameters of the authorization callback. | |
| 2705 | 2708 | ** |
| 2706 | 2709 | ** ^If the action code is [SQLITE_READ] |
| 2707 | 2710 | ** and the callback returns [SQLITE_IGNORE] then the |
| 2708 | 2711 | ** [prepared statement] statement is constructed to substitute |
| 2709 | 2712 | ** a NULL value in place of the table column that would have |
| 2710 | 2713 | ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] |
| 2711 | 2714 | ** return can be used to deny an untrusted user access to individual |
| 2712 | 2715 | ** columns of a table. |
| 2716 | +** ^When a table is referenced by a [SELECT] but no column values are | |
| 2717 | +** extracted from that table (for example in a query like | |
| 2718 | +** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback | |
| 2719 | +** is invoked once for that table with a column name that is an empty string. | |
| 2713 | 2720 | ** ^If the action code is [SQLITE_DELETE] and the callback returns |
| 2714 | 2721 | ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the |
| 2715 | 2722 | ** [truncate optimization] is disabled and all rows are deleted individually. |
| 2716 | 2723 | ** |
| 2717 | 2724 | ** An authorizer is used when [sqlite3_prepare | preparing] |
| @@ -4754,14 +4761,15 @@ | ||
| 4754 | 4761 | ** metadata associated with the pattern string. |
| 4755 | 4762 | ** Then as long as the pattern string remains the same, |
| 4756 | 4763 | ** the compiled regular expression can be reused on multiple |
| 4757 | 4764 | ** invocations of the same function. |
| 4758 | 4765 | ** |
| 4759 | -** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata | |
| 4760 | -** associated by the sqlite3_set_auxdata() function with the Nth argument | |
| 4761 | -** value to the application-defined function. ^If there is no metadata | |
| 4762 | -** associated with the function argument, this sqlite3_get_auxdata() interface | |
| 4766 | +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata | |
| 4767 | +** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument | |
| 4768 | +** value to the application-defined function. ^N is zero for the left-most | |
| 4769 | +** function argument. ^If there is no metadata | |
| 4770 | +** associated with the function argument, the sqlite3_get_auxdata(C,N) interface | |
| 4763 | 4771 | ** returns a NULL pointer. |
| 4764 | 4772 | ** |
| 4765 | 4773 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 4766 | 4774 | ** argument of the application-defined function. ^Subsequent |
| 4767 | 4775 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| @@ -4787,10 +4795,14 @@ | ||
| 4787 | 4795 | ** sqlite3_set_auxdata() has been called. |
| 4788 | 4796 | ** |
| 4789 | 4797 | ** ^(In practice, metadata is preserved between function calls for |
| 4790 | 4798 | ** function parameters that are compile-time constants, including literal |
| 4791 | 4799 | ** values and [parameters] and expressions composed from the same.)^ |
| 4800 | +** | |
| 4801 | +** The value of the N parameter to these interfaces should be non-negative. | |
| 4802 | +** Future enhancements may make use of negative N values to define new | |
| 4803 | +** kinds of function caching behavior. | |
| 4792 | 4804 | ** |
| 4793 | 4805 | ** These routines must be called from the same thread in which |
| 4794 | 4806 | ** the SQL function is running. |
| 4795 | 4807 | */ |
| 4796 | 4808 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
| 4797 | 4809 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -121,11 +121,11 @@ | |
| 121 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 122 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 123 | */ |
| 124 | #define SQLITE_VERSION "3.19.0" |
| 125 | #define SQLITE_VERSION_NUMBER 3019000 |
| 126 | #define SQLITE_SOURCE_ID "2017-05-10 16:12:00 92ab1f7257d2866c69eaaf4cf85990677b911ef425e9c5a36a96978cccfb551c" |
| 127 | |
| 128 | /* |
| 129 | ** CAPI3REF: Run-Time Library Version Numbers |
| 130 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 131 | ** |
| @@ -2671,10 +2671,11 @@ | |
| 2671 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2672 | |
| 2673 | /* |
| 2674 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2675 | ** METHOD: sqlite3 |
| 2676 | ** |
| 2677 | ** ^This routine registers an authorizer callback with a particular |
| 2678 | ** [database connection], supplied in the first argument. |
| 2679 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2680 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2698,20 +2699,26 @@ | |
| 2698 | ** |
| 2699 | ** ^The first parameter to the authorizer callback is a copy of the third |
| 2700 | ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter |
| 2701 | ** to the callback is an integer [SQLITE_COPY | action code] that specifies |
| 2702 | ** the particular action to be authorized. ^The third through sixth parameters |
| 2703 | ** to the callback are zero-terminated strings that contain additional |
| 2704 | ** details about the action to be authorized. |
| 2705 | ** |
| 2706 | ** ^If the action code is [SQLITE_READ] |
| 2707 | ** and the callback returns [SQLITE_IGNORE] then the |
| 2708 | ** [prepared statement] statement is constructed to substitute |
| 2709 | ** a NULL value in place of the table column that would have |
| 2710 | ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] |
| 2711 | ** return can be used to deny an untrusted user access to individual |
| 2712 | ** columns of a table. |
| 2713 | ** ^If the action code is [SQLITE_DELETE] and the callback returns |
| 2714 | ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the |
| 2715 | ** [truncate optimization] is disabled and all rows are deleted individually. |
| 2716 | ** |
| 2717 | ** An authorizer is used when [sqlite3_prepare | preparing] |
| @@ -4754,14 +4761,15 @@ | |
| 4754 | ** metadata associated with the pattern string. |
| 4755 | ** Then as long as the pattern string remains the same, |
| 4756 | ** the compiled regular expression can be reused on multiple |
| 4757 | ** invocations of the same function. |
| 4758 | ** |
| 4759 | ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata |
| 4760 | ** associated by the sqlite3_set_auxdata() function with the Nth argument |
| 4761 | ** value to the application-defined function. ^If there is no metadata |
| 4762 | ** associated with the function argument, this sqlite3_get_auxdata() interface |
| 4763 | ** returns a NULL pointer. |
| 4764 | ** |
| 4765 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 4766 | ** argument of the application-defined function. ^Subsequent |
| 4767 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| @@ -4787,10 +4795,14 @@ | |
| 4787 | ** sqlite3_set_auxdata() has been called. |
| 4788 | ** |
| 4789 | ** ^(In practice, metadata is preserved between function calls for |
| 4790 | ** function parameters that are compile-time constants, including literal |
| 4791 | ** values and [parameters] and expressions composed from the same.)^ |
| 4792 | ** |
| 4793 | ** These routines must be called from the same thread in which |
| 4794 | ** the SQL function is running. |
| 4795 | */ |
| 4796 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
| 4797 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -121,11 +121,11 @@ | |
| 121 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 122 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 123 | */ |
| 124 | #define SQLITE_VERSION "3.19.0" |
| 125 | #define SQLITE_VERSION_NUMBER 3019000 |
| 126 | #define SQLITE_SOURCE_ID "2017-05-11 19:09:19 339df63f4064f3b9c8d4e8b82e72d00b49d9406bc350b14809a4caf7ddc4b736" |
| 127 | |
| 128 | /* |
| 129 | ** CAPI3REF: Run-Time Library Version Numbers |
| 130 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 131 | ** |
| @@ -2671,10 +2671,11 @@ | |
| 2671 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2672 | |
| 2673 | /* |
| 2674 | ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2675 | ** METHOD: sqlite3 |
| 2676 | ** KEYWORDS: {authorizer callback} |
| 2677 | ** |
| 2678 | ** ^This routine registers an authorizer callback with a particular |
| 2679 | ** [database connection], supplied in the first argument. |
| 2680 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2681 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| @@ -2698,20 +2699,26 @@ | |
| 2699 | ** |
| 2700 | ** ^The first parameter to the authorizer callback is a copy of the third |
| 2701 | ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter |
| 2702 | ** to the callback is an integer [SQLITE_COPY | action code] that specifies |
| 2703 | ** the particular action to be authorized. ^The third through sixth parameters |
| 2704 | ** to the callback are either NULL pointers or zero-terminated strings |
| 2705 | ** that contain additional details about the action to be authorized. |
| 2706 | ** Applications must always be prepared to encounter a NULL pointer in any |
| 2707 | ** of the third through the sixth parameters of the authorization callback. |
| 2708 | ** |
| 2709 | ** ^If the action code is [SQLITE_READ] |
| 2710 | ** and the callback returns [SQLITE_IGNORE] then the |
| 2711 | ** [prepared statement] statement is constructed to substitute |
| 2712 | ** a NULL value in place of the table column that would have |
| 2713 | ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] |
| 2714 | ** return can be used to deny an untrusted user access to individual |
| 2715 | ** columns of a table. |
| 2716 | ** ^When a table is referenced by a [SELECT] but no column values are |
| 2717 | ** extracted from that table (for example in a query like |
| 2718 | ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback |
| 2719 | ** is invoked once for that table with a column name that is an empty string. |
| 2720 | ** ^If the action code is [SQLITE_DELETE] and the callback returns |
| 2721 | ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the |
| 2722 | ** [truncate optimization] is disabled and all rows are deleted individually. |
| 2723 | ** |
| 2724 | ** An authorizer is used when [sqlite3_prepare | preparing] |
| @@ -4754,14 +4761,15 @@ | |
| 4761 | ** metadata associated with the pattern string. |
| 4762 | ** Then as long as the pattern string remains the same, |
| 4763 | ** the compiled regular expression can be reused on multiple |
| 4764 | ** invocations of the same function. |
| 4765 | ** |
| 4766 | ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata |
| 4767 | ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument |
| 4768 | ** value to the application-defined function. ^N is zero for the left-most |
| 4769 | ** function argument. ^If there is no metadata |
| 4770 | ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface |
| 4771 | ** returns a NULL pointer. |
| 4772 | ** |
| 4773 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 4774 | ** argument of the application-defined function. ^Subsequent |
| 4775 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| @@ -4787,10 +4795,14 @@ | |
| 4795 | ** sqlite3_set_auxdata() has been called. |
| 4796 | ** |
| 4797 | ** ^(In practice, metadata is preserved between function calls for |
| 4798 | ** function parameters that are compile-time constants, including literal |
| 4799 | ** values and [parameters] and expressions composed from the same.)^ |
| 4800 | ** |
| 4801 | ** The value of the N parameter to these interfaces should be non-negative. |
| 4802 | ** Future enhancements may make use of negative N values to define new |
| 4803 | ** kinds of function caching behavior. |
| 4804 | ** |
| 4805 | ** These routines must be called from the same thread in which |
| 4806 | ** the SQL function is running. |
| 4807 | */ |
| 4808 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
| 4809 |