Fossil SCM
Update the built-in SQLite to a newer version that fixes C89-isms in FTS5.
Commit
0d120a6102c662b469f4ac44c199bdfbfb531ec1
Parent
d0cabcb617b05ce…
2 files changed
+680
-568
+1
-1
+680
-568
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -327,11 +327,11 @@ | ||
| 327 | 327 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 328 | 328 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 329 | 329 | */ |
| 330 | 330 | #define SQLITE_VERSION "3.11.0" |
| 331 | 331 | #define SQLITE_VERSION_NUMBER 3011000 |
| 332 | -#define SQLITE_SOURCE_ID "2016-01-14 14:19:50 d17bc2c92f4d086280e49a3cc72993be7fee2da7" | |
| 332 | +#define SQLITE_SOURCE_ID "2016-01-18 17:48:28 acaf426449bf6fd3140fd63141750ff69d1119a5" | |
| 333 | 333 | |
| 334 | 334 | /* |
| 335 | 335 | ** CAPI3REF: Run-Time Library Version Numbers |
| 336 | 336 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 337 | 337 | ** |
| @@ -9406,10 +9406,25 @@ | ||
| 9406 | 9406 | #else |
| 9407 | 9407 | # define ALWAYS(X) (X) |
| 9408 | 9408 | # define NEVER(X) (X) |
| 9409 | 9409 | #endif |
| 9410 | 9410 | |
| 9411 | +/* | |
| 9412 | +** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is | |
| 9413 | +** defined. We need to defend against those failures when testing with | |
| 9414 | +** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches | |
| 9415 | +** during a normal build. The following macro can be used to disable tests | |
| 9416 | +** that are always false except when SQLITE_TEST_REALLOC_STRESS is set. | |
| 9417 | +*/ | |
| 9418 | +#if defined(SQLITE_TEST_REALLOC_STRESS) | |
| 9419 | +# define ONLY_IF_REALLOC_STRESS(X) (X) | |
| 9420 | +#elif !defined(NDEBUG) | |
| 9421 | +# define ONLY_IF_REALLOC_STRESS(X) ((X)?(assert(0),1):0) | |
| 9422 | +#else | |
| 9423 | +# define ONLY_IF_REALLOC_STRESS(X) (0) | |
| 9424 | +#endif | |
| 9425 | + | |
| 9411 | 9426 | /* |
| 9412 | 9427 | ** Declarations used for tracing the operating system interfaces. |
| 9413 | 9428 | */ |
| 9414 | 9429 | #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \ |
| 9415 | 9430 | (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) |
| @@ -10961,19 +10976,24 @@ | ||
| 10961 | 10976 | SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...); |
| 10962 | 10977 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int); |
| 10963 | 10978 | SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int); |
| 10964 | 10979 | SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int); |
| 10965 | 10980 | SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int); |
| 10966 | -SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno); | |
| 10981 | +#if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS) | |
| 10982 | +SQLITE_PRIVATE void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N); | |
| 10983 | +#else | |
| 10984 | +# define sqlite3VdbeVerifyNoMallocRequired(A,B) | |
| 10985 | +#endif | |
| 10986 | +SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno); | |
| 10967 | 10987 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*); |
| 10968 | 10988 | SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8); |
| 10969 | 10989 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1); |
| 10970 | 10990 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 10971 | 10991 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 10972 | 10992 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 10973 | 10993 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 10974 | -SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr); | |
| 10994 | +SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); | |
| 10975 | 10995 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 10976 | 10996 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 10977 | 10997 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 10978 | 10998 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 10979 | 10999 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| @@ -12227,13 +12247,12 @@ | ||
| 12227 | 12247 | struct FuncDef { |
| 12228 | 12248 | i16 nArg; /* Number of arguments. -1 means unlimited */ |
| 12229 | 12249 | u16 funcFlags; /* Some combination of SQLITE_FUNC_* */ |
| 12230 | 12250 | void *pUserData; /* User data parameter */ |
| 12231 | 12251 | FuncDef *pNext; /* Next function with same name */ |
| 12232 | - void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ | |
| 12233 | - void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */ | |
| 12234 | - void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */ | |
| 12252 | + void (*xSFunc)(sqlite3_context*,int,sqlite3_value**); /* func or agg-step */ | |
| 12253 | + void (*xFinalize)(sqlite3_context*); /* Agg finalizer */ | |
| 12235 | 12254 | char *zName; /* SQL name of the function. */ |
| 12236 | 12255 | FuncDef *pHash; /* Next with a different name but the same hash */ |
| 12237 | 12256 | FuncDestructor *pDestructor; /* Reference counted destructor function */ |
| 12238 | 12257 | }; |
| 12239 | 12258 | |
| @@ -12312,32 +12331,32 @@ | ||
| 12312 | 12331 | ** FuncDef.flags variable is set to the value passed as the flags |
| 12313 | 12332 | ** parameter. |
| 12314 | 12333 | */ |
| 12315 | 12334 | #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 12316 | 12335 | {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12317 | - SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} | |
| 12336 | + SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0} | |
| 12318 | 12337 | #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 12319 | 12338 | {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12320 | - SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} | |
| 12339 | + SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0} | |
| 12321 | 12340 | #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 12322 | 12341 | {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12323 | - SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} | |
| 12342 | + SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0} | |
| 12324 | 12343 | #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ |
| 12325 | 12344 | {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ |
| 12326 | - SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} | |
| 12345 | + SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0} | |
| 12327 | 12346 | #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ |
| 12328 | 12347 | {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12329 | - pArg, 0, xFunc, 0, 0, #zName, 0, 0} | |
| 12348 | + pArg, 0, xFunc, 0, #zName, 0, 0} | |
| 12330 | 12349 | #define LIKEFUNC(zName, nArg, arg, flags) \ |
| 12331 | 12350 | {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ |
| 12332 | - (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0} | |
| 12351 | + (void *)arg, 0, likeFunc, 0, #zName, 0, 0} | |
| 12333 | 12352 | #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ |
| 12334 | 12353 | {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \ |
| 12335 | - SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} | |
| 12354 | + SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName,0,0} | |
| 12336 | 12355 | #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \ |
| 12337 | 12356 | {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ |
| 12338 | - SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} | |
| 12357 | + SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName,0,0} | |
| 12339 | 12358 | |
| 12340 | 12359 | /* |
| 12341 | 12360 | ** All current savepoints are stored in a linked list starting at |
| 12342 | 12361 | ** sqlite3.pSavepoint. The first element in the list is the most recently |
| 12343 | 12362 | ** opened savepoint. Savepoints are added to the list by the vdbe |
| @@ -16576,52 +16595,68 @@ | ||
| 16576 | 16595 | char tzSet; /* Timezone was set explicitly */ |
| 16577 | 16596 | }; |
| 16578 | 16597 | |
| 16579 | 16598 | |
| 16580 | 16599 | /* |
| 16581 | -** Convert zDate into one or more integers. Additional arguments | |
| 16582 | -** come in groups of 5 as follows: | |
| 16583 | -** | |
| 16584 | -** N number of digits in the integer | |
| 16585 | -** min minimum allowed value of the integer | |
| 16586 | -** max maximum allowed value of the integer | |
| 16587 | -** nextC first character after the integer | |
| 16588 | -** pVal where to write the integers value. | |
| 16589 | -** | |
| 16590 | -** Conversions continue until one with nextC==0 is encountered. | |
| 16600 | +** Convert zDate into one or more integers according to the conversion | |
| 16601 | +** specifier zFormat. | |
| 16602 | +** | |
| 16603 | +** zFormat[] contains 4 characters for each integer converted, except for | |
| 16604 | +** the last integer which is specified by three characters. The meaning | |
| 16605 | +** of a four-character format specifiers ABCD is: | |
| 16606 | +** | |
| 16607 | +** A: number of digits to convert. Always "2" or "4". | |
| 16608 | +** B: minimum value. Always "0" or "1". | |
| 16609 | +** C: maximum value, decoded as: | |
| 16610 | +** a: 12 | |
| 16611 | +** b: 14 | |
| 16612 | +** c: 24 | |
| 16613 | +** d: 31 | |
| 16614 | +** e: 59 | |
| 16615 | +** f: 9999 | |
| 16616 | +** D: the separator character, or \000 to indicate this is the | |
| 16617 | +** last number to convert. | |
| 16618 | +** | |
| 16619 | +** Example: To translate an ISO-8601 date YYYY-MM-DD, the format would | |
| 16620 | +** be "40f-21a-20c". The "40f-" indicates the 4-digit year followed by "-". | |
| 16621 | +** The "21a-" indicates the 2-digit month followed by "-". The "20c" indicates | |
| 16622 | +** the 2-digit day which is the last integer in the set. | |
| 16623 | +** | |
| 16591 | 16624 | ** The function returns the number of successful conversions. |
| 16592 | 16625 | */ |
| 16593 | -static int getDigits(const char *zDate, ...){ | |
| 16626 | +static int getDigits(const char *zDate, const char *zFormat, ...){ | |
| 16627 | + /* The aMx[] array translates the 3rd character of each format | |
| 16628 | + ** spec into a max size: a b c d e f */ | |
| 16629 | + static const u16 aMx[] = { 12, 14, 24, 31, 59, 9999 }; | |
| 16594 | 16630 | va_list ap; |
| 16595 | - int val; | |
| 16596 | - int N; | |
| 16597 | - int min; | |
| 16598 | - int max; | |
| 16599 | - int nextC; | |
| 16600 | - int *pVal; | |
| 16601 | 16631 | int cnt = 0; |
| 16602 | - va_start(ap, zDate); | |
| 16632 | + char nextC; | |
| 16633 | + va_start(ap, zFormat); | |
| 16603 | 16634 | do{ |
| 16604 | - N = va_arg(ap, int); | |
| 16605 | - min = va_arg(ap, int); | |
| 16606 | - max = va_arg(ap, int); | |
| 16607 | - nextC = va_arg(ap, int); | |
| 16608 | - pVal = va_arg(ap, int*); | |
| 16635 | + char N = zFormat[0] - '0'; | |
| 16636 | + char min = zFormat[1] - '0'; | |
| 16637 | + int val = 0; | |
| 16638 | + u16 max; | |
| 16639 | + | |
| 16640 | + assert( zFormat[2]>='a' && zFormat[2]<='f' ); | |
| 16641 | + max = aMx[zFormat[2] - 'a']; | |
| 16642 | + nextC = zFormat[3]; | |
| 16609 | 16643 | val = 0; |
| 16610 | 16644 | while( N-- ){ |
| 16611 | 16645 | if( !sqlite3Isdigit(*zDate) ){ |
| 16612 | 16646 | goto end_getDigits; |
| 16613 | 16647 | } |
| 16614 | 16648 | val = val*10 + *zDate - '0'; |
| 16615 | 16649 | zDate++; |
| 16616 | 16650 | } |
| 16617 | - if( val<min || val>max || (nextC!=0 && nextC!=*zDate) ){ | |
| 16651 | + if( val<(int)min || val>(int)max || (nextC!=0 && nextC!=*zDate) ){ | |
| 16618 | 16652 | goto end_getDigits; |
| 16619 | 16653 | } |
| 16620 | - *pVal = val; | |
| 16654 | + *va_arg(ap,int*) = val; | |
| 16621 | 16655 | zDate++; |
| 16622 | 16656 | cnt++; |
| 16657 | + zFormat += 4; | |
| 16623 | 16658 | }while( nextC ); |
| 16624 | 16659 | end_getDigits: |
| 16625 | 16660 | va_end(ap); |
| 16626 | 16661 | return cnt; |
| 16627 | 16662 | } |
| @@ -16658,11 +16693,11 @@ | ||
| 16658 | 16693 | goto zulu_time; |
| 16659 | 16694 | }else{ |
| 16660 | 16695 | return c!=0; |
| 16661 | 16696 | } |
| 16662 | 16697 | zDate++; |
| 16663 | - if( getDigits(zDate, 2, 0, 14, ':', &nHr, 2, 0, 59, 0, &nMn)!=2 ){ | |
| 16698 | + if( getDigits(zDate, "20b:20e", &nHr, &nMn)!=2 ){ | |
| 16664 | 16699 | return 1; |
| 16665 | 16700 | } |
| 16666 | 16701 | zDate += 5; |
| 16667 | 16702 | p->tz = sgn*(nMn + nHr*60); |
| 16668 | 16703 | zulu_time: |
| @@ -16679,17 +16714,17 @@ | ||
| 16679 | 16714 | ** Return 1 if there is a parsing error and 0 on success. |
| 16680 | 16715 | */ |
| 16681 | 16716 | static int parseHhMmSs(const char *zDate, DateTime *p){ |
| 16682 | 16717 | int h, m, s; |
| 16683 | 16718 | double ms = 0.0; |
| 16684 | - if( getDigits(zDate, 2, 0, 24, ':', &h, 2, 0, 59, 0, &m)!=2 ){ | |
| 16719 | + if( getDigits(zDate, "20c:20e", &h, &m)!=2 ){ | |
| 16685 | 16720 | return 1; |
| 16686 | 16721 | } |
| 16687 | 16722 | zDate += 5; |
| 16688 | 16723 | if( *zDate==':' ){ |
| 16689 | 16724 | zDate++; |
| 16690 | - if( getDigits(zDate, 2, 0, 59, 0, &s)!=1 ){ | |
| 16725 | + if( getDigits(zDate, "20e", &s)!=1 ){ | |
| 16691 | 16726 | return 1; |
| 16692 | 16727 | } |
| 16693 | 16728 | zDate += 2; |
| 16694 | 16729 | if( *zDate=='.' && sqlite3Isdigit(zDate[1]) ){ |
| 16695 | 16730 | double rScale = 1.0; |
| @@ -16773,11 +16808,11 @@ | ||
| 16773 | 16808 | zDate++; |
| 16774 | 16809 | neg = 1; |
| 16775 | 16810 | }else{ |
| 16776 | 16811 | neg = 0; |
| 16777 | 16812 | } |
| 16778 | - if( getDigits(zDate,4,0,9999,'-',&Y,2,1,12,'-',&M,2,1,31,0,&D)!=3 ){ | |
| 16813 | + if( getDigits(zDate, "40f-21a-21d", &Y, &M, &D)!=3 ){ | |
| 16779 | 16814 | return 1; |
| 16780 | 16815 | } |
| 16781 | 16816 | zDate += 10; |
| 16782 | 16817 | while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; } |
| 16783 | 16818 | if( parseHhMmSs(zDate, p)==0 ){ |
| @@ -63843,10 +63878,18 @@ | ||
| 63843 | 63878 | */ |
| 63844 | 63879 | if( NEVER(pBt->pCursor) ){ |
| 63845 | 63880 | sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db); |
| 63846 | 63881 | return SQLITE_LOCKED_SHAREDCACHE; |
| 63847 | 63882 | } |
| 63883 | + | |
| 63884 | + /* | |
| 63885 | + ** It is illegal to drop the sqlite_master table on page 1. But again, | |
| 63886 | + ** this error is caught long before reaching this point. | |
| 63887 | + */ | |
| 63888 | + if( NEVER(iTable<2) ){ | |
| 63889 | + return SQLITE_CORRUPT_BKPT; | |
| 63890 | + } | |
| 63848 | 63891 | |
| 63849 | 63892 | rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); |
| 63850 | 63893 | if( rc ) return rc; |
| 63851 | 63894 | rc = sqlite3BtreeClearTable(p, iTable, 0); |
| 63852 | 63895 | if( rc ){ |
| @@ -63854,80 +63897,71 @@ | ||
| 63854 | 63897 | return rc; |
| 63855 | 63898 | } |
| 63856 | 63899 | |
| 63857 | 63900 | *piMoved = 0; |
| 63858 | 63901 | |
| 63859 | - if( iTable>1 ){ | |
| 63860 | -#ifdef SQLITE_OMIT_AUTOVACUUM | |
| 63861 | - freePage(pPage, &rc); | |
| 63862 | - releasePage(pPage); | |
| 63863 | -#else | |
| 63864 | - if( pBt->autoVacuum ){ | |
| 63865 | - Pgno maxRootPgno; | |
| 63866 | - sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &maxRootPgno); | |
| 63867 | - | |
| 63868 | - if( iTable==maxRootPgno ){ | |
| 63869 | - /* If the table being dropped is the table with the largest root-page | |
| 63870 | - ** number in the database, put the root page on the free list. | |
| 63871 | - */ | |
| 63872 | - freePage(pPage, &rc); | |
| 63873 | - releasePage(pPage); | |
| 63874 | - if( rc!=SQLITE_OK ){ | |
| 63875 | - return rc; | |
| 63876 | - } | |
| 63877 | - }else{ | |
| 63878 | - /* The table being dropped does not have the largest root-page | |
| 63879 | - ** number in the database. So move the page that does into the | |
| 63880 | - ** gap left by the deleted root-page. | |
| 63881 | - */ | |
| 63882 | - MemPage *pMove; | |
| 63883 | - releasePage(pPage); | |
| 63884 | - rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); | |
| 63885 | - if( rc!=SQLITE_OK ){ | |
| 63886 | - return rc; | |
| 63887 | - } | |
| 63888 | - rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0); | |
| 63889 | - releasePage(pMove); | |
| 63890 | - if( rc!=SQLITE_OK ){ | |
| 63891 | - return rc; | |
| 63892 | - } | |
| 63893 | - pMove = 0; | |
| 63894 | - rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); | |
| 63895 | - freePage(pMove, &rc); | |
| 63896 | - releasePage(pMove); | |
| 63897 | - if( rc!=SQLITE_OK ){ | |
| 63898 | - return rc; | |
| 63899 | - } | |
| 63900 | - *piMoved = maxRootPgno; | |
| 63901 | - } | |
| 63902 | - | |
| 63903 | - /* Set the new 'max-root-page' value in the database header. This | |
| 63904 | - ** is the old value less one, less one more if that happens to | |
| 63905 | - ** be a root-page number, less one again if that is the | |
| 63906 | - ** PENDING_BYTE_PAGE. | |
| 63907 | - */ | |
| 63908 | - maxRootPgno--; | |
| 63909 | - while( maxRootPgno==PENDING_BYTE_PAGE(pBt) | |
| 63910 | - || PTRMAP_ISPAGE(pBt, maxRootPgno) ){ | |
| 63911 | - maxRootPgno--; | |
| 63912 | - } | |
| 63913 | - assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) ); | |
| 63914 | - | |
| 63915 | - rc = sqlite3BtreeUpdateMeta(p, 4, maxRootPgno); | |
| 63916 | - }else{ | |
| 63917 | - freePage(pPage, &rc); | |
| 63918 | - releasePage(pPage); | |
| 63919 | - } | |
| 63920 | -#endif | |
| 63921 | - }else{ | |
| 63922 | - /* If sqlite3BtreeDropTable was called on page 1. | |
| 63923 | - ** This really never should happen except in a corrupt | |
| 63924 | - ** database. | |
| 63925 | - */ | |
| 63926 | - zeroPage(pPage, PTF_INTKEY|PTF_LEAF ); | |
| 63927 | - releasePage(pPage); | |
| 63928 | - } | |
| 63902 | +#ifdef SQLITE_OMIT_AUTOVACUUM | |
| 63903 | + freePage(pPage, &rc); | |
| 63904 | + releasePage(pPage); | |
| 63905 | +#else | |
| 63906 | + if( pBt->autoVacuum ){ | |
| 63907 | + Pgno maxRootPgno; | |
| 63908 | + sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &maxRootPgno); | |
| 63909 | + | |
| 63910 | + if( iTable==maxRootPgno ){ | |
| 63911 | + /* If the table being dropped is the table with the largest root-page | |
| 63912 | + ** number in the database, put the root page on the free list. | |
| 63913 | + */ | |
| 63914 | + freePage(pPage, &rc); | |
| 63915 | + releasePage(pPage); | |
| 63916 | + if( rc!=SQLITE_OK ){ | |
| 63917 | + return rc; | |
| 63918 | + } | |
| 63919 | + }else{ | |
| 63920 | + /* The table being dropped does not have the largest root-page | |
| 63921 | + ** number in the database. So move the page that does into the | |
| 63922 | + ** gap left by the deleted root-page. | |
| 63923 | + */ | |
| 63924 | + MemPage *pMove; | |
| 63925 | + releasePage(pPage); | |
| 63926 | + rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); | |
| 63927 | + if( rc!=SQLITE_OK ){ | |
| 63928 | + return rc; | |
| 63929 | + } | |
| 63930 | + rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0); | |
| 63931 | + releasePage(pMove); | |
| 63932 | + if( rc!=SQLITE_OK ){ | |
| 63933 | + return rc; | |
| 63934 | + } | |
| 63935 | + pMove = 0; | |
| 63936 | + rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); | |
| 63937 | + freePage(pMove, &rc); | |
| 63938 | + releasePage(pMove); | |
| 63939 | + if( rc!=SQLITE_OK ){ | |
| 63940 | + return rc; | |
| 63941 | + } | |
| 63942 | + *piMoved = maxRootPgno; | |
| 63943 | + } | |
| 63944 | + | |
| 63945 | + /* Set the new 'max-root-page' value in the database header. This | |
| 63946 | + ** is the old value less one, less one more if that happens to | |
| 63947 | + ** be a root-page number, less one again if that is the | |
| 63948 | + ** PENDING_BYTE_PAGE. | |
| 63949 | + */ | |
| 63950 | + maxRootPgno--; | |
| 63951 | + while( maxRootPgno==PENDING_BYTE_PAGE(pBt) | |
| 63952 | + || PTRMAP_ISPAGE(pBt, maxRootPgno) ){ | |
| 63953 | + maxRootPgno--; | |
| 63954 | + } | |
| 63955 | + assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) ); | |
| 63956 | + | |
| 63957 | + rc = sqlite3BtreeUpdateMeta(p, 4, maxRootPgno); | |
| 63958 | + }else{ | |
| 63959 | + freePage(pPage, &rc); | |
| 63960 | + releasePage(pPage); | |
| 63961 | + } | |
| 63962 | +#endif | |
| 63929 | 63963 | return rc; |
| 63930 | 63964 | } |
| 63931 | 63965 | SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree *p, int iTable, int *piMoved){ |
| 63932 | 63966 | int rc; |
| 63933 | 63967 | sqlite3BtreeEnter(p); |
| @@ -67010,11 +67044,11 @@ | ||
| 67010 | 67044 | |
| 67011 | 67045 | assert( pCtx->pParse->rc==SQLITE_OK ); |
| 67012 | 67046 | memset(&ctx, 0, sizeof(ctx)); |
| 67013 | 67047 | ctx.pOut = pVal; |
| 67014 | 67048 | ctx.pFunc = pFunc; |
| 67015 | - pFunc->xFunc(&ctx, nVal, apVal); | |
| 67049 | + pFunc->xSFunc(&ctx, nVal, apVal); | |
| 67016 | 67050 | if( ctx.isError ){ |
| 67017 | 67051 | rc = ctx.isError; |
| 67018 | 67052 | sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); |
| 67019 | 67053 | }else{ |
| 67020 | 67054 | sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); |
| @@ -67757,12 +67791,11 @@ | ||
| 67757 | 67791 | char c; |
| 67758 | 67792 | va_start(ap, zTypes); |
| 67759 | 67793 | for(i=0; (c = zTypes[i])!=0; i++){ |
| 67760 | 67794 | if( c=='s' ){ |
| 67761 | 67795 | const char *z = va_arg(ap, const char*); |
| 67762 | - int addr = sqlite3VdbeAddOp2(p, z==0 ? OP_Null : OP_String8, 0, iDest++); | |
| 67763 | - if( z ) sqlite3VdbeChangeP4(p, addr, z, 0); | |
| 67796 | + sqlite3VdbeAddOp4(p, z==0 ? OP_Null : OP_String8, 0, iDest++, 0, z, 0); | |
| 67764 | 67797 | }else{ |
| 67765 | 67798 | assert( c=='i' ); |
| 67766 | 67799 | sqlite3VdbeAddOp2(p, OP_Integer, va_arg(ap, int), iDest++); |
| 67767 | 67800 | } |
| 67768 | 67801 | } |
| @@ -68113,10 +68146,24 @@ | ||
| 68113 | 68146 | SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){ |
| 68114 | 68147 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 68115 | 68148 | return p->nOp; |
| 68116 | 68149 | } |
| 68117 | 68150 | |
| 68151 | +/* | |
| 68152 | +** Verify that at least N opcode slots are available in p without | |
| 68153 | +** having to malloc for more space (except when compiled using | |
| 68154 | +** SQLITE_TEST_REALLOC_STRESS). This interface is used during testing | |
| 68155 | +** to verify that certain calls to sqlite3VdbeAddOpList() can never | |
| 68156 | +** fail due to a OOM fault and hence that the return value from | |
| 68157 | +** sqlite3VdbeAddOpList() will always be non-NULL. | |
| 68158 | +*/ | |
| 68159 | +#if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS) | |
| 68160 | +SQLITE_PRIVATE void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N){ | |
| 68161 | + assert( p->nOp + N <= p->pParse->nOpAlloc ); | |
| 68162 | +} | |
| 68163 | +#endif | |
| 68164 | + | |
| 68118 | 68165 | /* |
| 68119 | 68166 | ** This function returns a pointer to the array of opcodes associated with |
| 68120 | 68167 | ** the Vdbe passed as the first argument. It is the callers responsibility |
| 68121 | 68168 | ** to arrange for the returned array to be eventually freed using the |
| 68122 | 68169 | ** vdbeFreeOpArray() function. |
| @@ -68138,23 +68185,27 @@ | ||
| 68138 | 68185 | p->aOp = 0; |
| 68139 | 68186 | return aOp; |
| 68140 | 68187 | } |
| 68141 | 68188 | |
| 68142 | 68189 | /* |
| 68143 | -** Add a whole list of operations to the operation stack. Return the | |
| 68144 | -** address of the first operation added. | |
| 68190 | +** Add a whole list of operations to the operation stack. Return a | |
| 68191 | +** pointer to the first operation inserted. | |
| 68145 | 68192 | */ |
| 68146 | -SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){ | |
| 68147 | - int addr, i; | |
| 68148 | - VdbeOp *pOut; | |
| 68193 | +SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList( | |
| 68194 | + Vdbe *p, /* Add opcodes to the prepared statement */ | |
| 68195 | + int nOp, /* Number of opcodes to add */ | |
| 68196 | + VdbeOpList const *aOp, /* The opcodes to be added */ | |
| 68197 | + int iLineno /* Source-file line number of first opcode */ | |
| 68198 | +){ | |
| 68199 | + int i; | |
| 68200 | + VdbeOp *pOut, *pFirst; | |
| 68149 | 68201 | assert( nOp>0 ); |
| 68150 | 68202 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 68151 | 68203 | if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){ |
| 68152 | 68204 | return 0; |
| 68153 | 68205 | } |
| 68154 | - addr = p->nOp; | |
| 68155 | - pOut = &p->aOp[addr]; | |
| 68206 | + pFirst = pOut = &p->aOp[p->nOp]; | |
| 68156 | 68207 | for(i=0; i<nOp; i++, aOp++, pOut++){ |
| 68157 | 68208 | pOut->opcode = aOp->opcode; |
| 68158 | 68209 | pOut->p1 = aOp->p1; |
| 68159 | 68210 | pOut->p2 = aOp->p2; |
| 68160 | 68211 | assert( aOp->p2>=0 ); |
| @@ -68170,16 +68221,16 @@ | ||
| 68170 | 68221 | #else |
| 68171 | 68222 | (void)iLineno; |
| 68172 | 68223 | #endif |
| 68173 | 68224 | #ifdef SQLITE_DEBUG |
| 68174 | 68225 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 68175 | - sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]); | |
| 68226 | + sqlite3VdbePrintOp(0, i+p->nOp, &p->aOp[i+p->nOp]); | |
| 68176 | 68227 | } |
| 68177 | 68228 | #endif |
| 68178 | 68229 | } |
| 68179 | 68230 | p->nOp += nOp; |
| 68180 | - return addr; | |
| 68231 | + return pFirst; | |
| 68181 | 68232 | } |
| 68182 | 68233 | |
| 68183 | 68234 | #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) |
| 68184 | 68235 | /* |
| 68185 | 68236 | ** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus(). |
| @@ -68223,11 +68274,11 @@ | ||
| 68223 | 68274 | } |
| 68224 | 68275 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){ |
| 68225 | 68276 | sqlite3VdbeGetOp(p,addr)->p3 = val; |
| 68226 | 68277 | } |
| 68227 | 68278 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){ |
| 68228 | - sqlite3VdbeGetOp(p,-1)->p5 = p5; | |
| 68279 | + if( !p->db->mallocFailed ) p->aOp[p->nOp-1].p5 = p5; | |
| 68229 | 68280 | } |
| 68230 | 68281 | |
| 68231 | 68282 | /* |
| 68232 | 68283 | ** Change the P2 operand of instruction addr so that it points to |
| 68233 | 68284 | ** the address of the next instruction to be coded. |
| @@ -68333,28 +68384,28 @@ | ||
| 68333 | 68384 | } |
| 68334 | 68385 | |
| 68335 | 68386 | /* |
| 68336 | 68387 | ** Change the opcode at addr into OP_Noop |
| 68337 | 68388 | */ |
| 68338 | -SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe *p, int addr){ | |
| 68339 | - if( addr<p->nOp ){ | |
| 68340 | - VdbeOp *pOp = &p->aOp[addr]; | |
| 68341 | - sqlite3 *db = p->db; | |
| 68342 | - freeP4(db, pOp->p4type, pOp->p4.p); | |
| 68343 | - memset(pOp, 0, sizeof(pOp[0])); | |
| 68344 | - pOp->opcode = OP_Noop; | |
| 68345 | - } | |
| 68389 | +SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe *p, int addr){ | |
| 68390 | + VdbeOp *pOp; | |
| 68391 | + if( p->db->mallocFailed ) return 0; | |
| 68392 | + assert( addr>=0 && addr<p->nOp ); | |
| 68393 | + pOp = &p->aOp[addr]; | |
| 68394 | + freeP4(p->db, pOp->p4type, pOp->p4.p); | |
| 68395 | + memset(pOp, 0, sizeof(pOp[0])); | |
| 68396 | + pOp->opcode = OP_Noop; | |
| 68397 | + return 1; | |
| 68346 | 68398 | } |
| 68347 | 68399 | |
| 68348 | 68400 | /* |
| 68349 | 68401 | ** If the last opcode is "op" and it is not a jump destination, |
| 68350 | 68402 | ** then remove it. Return true if and only if an opcode was removed. |
| 68351 | 68403 | */ |
| 68352 | 68404 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe *p, u8 op){ |
| 68353 | 68405 | if( (p->nOp-1)>(p->pParse->iFixedOp) && p->aOp[p->nOp-1].opcode==op ){ |
| 68354 | - sqlite3VdbeChangeToNoop(p, p->nOp-1); | |
| 68355 | - return 1; | |
| 68406 | + return sqlite3VdbeChangeToNoop(p, p->nOp-1); | |
| 68356 | 68407 | }else{ |
| 68357 | 68408 | return 0; |
| 68358 | 68409 | } |
| 68359 | 68410 | } |
| 68360 | 68411 | |
| @@ -72726,11 +72777,11 @@ | ||
| 72726 | 72777 | ** Allocate or return the aggregate context for a user function. A new |
| 72727 | 72778 | ** context is allocated on the first call. Subsequent calls return the |
| 72728 | 72779 | ** same context that was returned on prior calls. |
| 72729 | 72780 | */ |
| 72730 | 72781 | SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context *p, int nByte){ |
| 72731 | - assert( p && p->pFunc && p->pFunc->xStep ); | |
| 72782 | + assert( p && p->pFunc && p->pFunc->xFinalize ); | |
| 72732 | 72783 | assert( sqlite3_mutex_held(p->pOut->db->mutex) ); |
| 72733 | 72784 | testcase( nByte<0 ); |
| 72734 | 72785 | if( (p->pMem->flags & MEM_Agg)==0 ){ |
| 72735 | 72786 | return createAggContext(p, nByte); |
| 72736 | 72787 | }else{ |
| @@ -72817,11 +72868,11 @@ | ||
| 72817 | 72868 | ** provide only to avoid breaking legacy code. New aggregate function |
| 72818 | 72869 | ** implementations should keep their own counts within their aggregate |
| 72819 | 72870 | ** context. |
| 72820 | 72871 | */ |
| 72821 | 72872 | SQLITE_API int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context *p){ |
| 72822 | - assert( p && p->pMem && p->pFunc && p->pFunc->xStep ); | |
| 72873 | + assert( p && p->pMem && p->pFunc && p->pFunc->xFinalize ); | |
| 72823 | 72874 | return p->pMem->n; |
| 72824 | 72875 | } |
| 72825 | 72876 | #endif |
| 72826 | 72877 | |
| 72827 | 72878 | /* |
| @@ -75560,12 +75611,12 @@ | ||
| 75560 | 75611 | } |
| 75561 | 75612 | #endif |
| 75562 | 75613 | MemSetTypeFlag(pCtx->pOut, MEM_Null); |
| 75563 | 75614 | pCtx->fErrorOrAux = 0; |
| 75564 | 75615 | db->lastRowid = lastRowid; |
| 75565 | - (*pCtx->pFunc->xFunc)(pCtx, pCtx->argc, pCtx->argv); /* IMP: R-24505-23230 */ | |
| 75566 | - lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */ | |
| 75616 | + (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */ | |
| 75617 | + lastRowid = db->lastRowid; /* Remember rowid changes made by xSFunc */ | |
| 75567 | 75618 | |
| 75568 | 75619 | /* If the function returned an error, throw an exception */ |
| 75569 | 75620 | if( pCtx->fErrorOrAux ){ |
| 75570 | 75621 | if( pCtx->isError ){ |
| 75571 | 75622 | sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); |
| @@ -78997,10 +79048,11 @@ | ||
| 78997 | 79048 | case OP_Destroy: { /* out2 */ |
| 78998 | 79049 | int iMoved; |
| 78999 | 79050 | int iDb; |
| 79000 | 79051 | |
| 79001 | 79052 | assert( p->readOnly==0 ); |
| 79053 | + assert( pOp->p1>1 ); | |
| 79002 | 79054 | pOut = out2Prerelease(p, pOp); |
| 79003 | 79055 | pOut->flags = MEM_Null; |
| 79004 | 79056 | if( db->nVdbeRead > db->nVDestroy+1 ){ |
| 79005 | 79057 | rc = SQLITE_LOCKED; |
| 79006 | 79058 | p->errorAction = OE_Abort; |
| @@ -79801,11 +79853,11 @@ | ||
| 79801 | 79853 | pMem->n++; |
| 79802 | 79854 | sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 79803 | 79855 | pCtx->pOut = &t; |
| 79804 | 79856 | pCtx->fErrorOrAux = 0; |
| 79805 | 79857 | pCtx->skipFlag = 0; |
| 79806 | - (pCtx->pFunc->xStep)(pCtx,pCtx->argc,pCtx->argv); /* IMP: R-24505-23230 */ | |
| 79858 | + (pCtx->pFunc->xSFunc)(pCtx,pCtx->argc,pCtx->argv); /* IMP: R-24505-23230 */ | |
| 79807 | 79859 | if( pCtx->fErrorOrAux ){ |
| 79808 | 79860 | if( pCtx->isError ){ |
| 79809 | 79861 | sqlite3VdbeError(p, "%s", sqlite3_value_text(&t)); |
| 79810 | 79862 | rc = pCtx->isError; |
| 79811 | 79863 | } |
| @@ -80799,42 +80851,10 @@ | ||
| 80799 | 80851 | int flags, /* True -> read/write access, false -> read-only */ |
| 80800 | 80852 | sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */ |
| 80801 | 80853 | ){ |
| 80802 | 80854 | int nAttempt = 0; |
| 80803 | 80855 | int iCol; /* Index of zColumn in row-record */ |
| 80804 | - | |
| 80805 | - /* This VDBE program seeks a btree cursor to the identified | |
| 80806 | - ** db/table/row entry. The reason for using a vdbe program instead | |
| 80807 | - ** of writing code to use the b-tree layer directly is that the | |
| 80808 | - ** vdbe program will take advantage of the various transaction, | |
| 80809 | - ** locking and error handling infrastructure built into the vdbe. | |
| 80810 | - ** | |
| 80811 | - ** After seeking the cursor, the vdbe executes an OP_ResultRow. | |
| 80812 | - ** Code external to the Vdbe then "borrows" the b-tree cursor and | |
| 80813 | - ** uses it to implement the blob_read(), blob_write() and | |
| 80814 | - ** blob_bytes() functions. | |
| 80815 | - ** | |
| 80816 | - ** The sqlite3_blob_close() function finalizes the vdbe program, | |
| 80817 | - ** which closes the b-tree cursor and (possibly) commits the | |
| 80818 | - ** transaction. | |
| 80819 | - */ | |
| 80820 | - static const int iLn = VDBE_OFFSET_LINENO(4); | |
| 80821 | - static const VdbeOpList openBlob[] = { | |
| 80822 | - /* {OP_Transaction, 0, 0, 0}, // 0: Inserted separately */ | |
| 80823 | - {OP_TableLock, 0, 0, 0}, /* 1: Acquire a read or write lock */ | |
| 80824 | - /* One of the following two instructions is replaced by an OP_Noop. */ | |
| 80825 | - {OP_OpenRead, 0, 0, 0}, /* 2: Open cursor 0 for reading */ | |
| 80826 | - {OP_OpenWrite, 0, 0, 0}, /* 3: Open cursor 0 for read/write */ | |
| 80827 | - {OP_Variable, 1, 1, 1}, /* 4: Push the rowid to the stack */ | |
| 80828 | - {OP_NotExists, 0, 10, 1}, /* 5: Seek the cursor */ | |
| 80829 | - {OP_Column, 0, 0, 1}, /* 6 */ | |
| 80830 | - {OP_ResultRow, 1, 0, 0}, /* 7 */ | |
| 80831 | - {OP_Goto, 0, 4, 0}, /* 8 */ | |
| 80832 | - {OP_Close, 0, 0, 0}, /* 9 */ | |
| 80833 | - {OP_Halt, 0, 0, 0}, /* 10 */ | |
| 80834 | - }; | |
| 80835 | - | |
| 80836 | 80856 | int rc = SQLITE_OK; |
| 80837 | 80857 | char *zErr = 0; |
| 80838 | 80858 | Table *pTab; |
| 80839 | 80859 | Parse *pParse = 0; |
| 80840 | 80860 | Incrblob *pBlob = 0; |
| @@ -80949,49 +80969,84 @@ | ||
| 80949 | 80969 | } |
| 80950 | 80970 | |
| 80951 | 80971 | pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse); |
| 80952 | 80972 | assert( pBlob->pStmt || db->mallocFailed ); |
| 80953 | 80973 | if( pBlob->pStmt ){ |
| 80974 | + | |
| 80975 | + /* This VDBE program seeks a btree cursor to the identified | |
| 80976 | + ** db/table/row entry. The reason for using a vdbe program instead | |
| 80977 | + ** of writing code to use the b-tree layer directly is that the | |
| 80978 | + ** vdbe program will take advantage of the various transaction, | |
| 80979 | + ** locking and error handling infrastructure built into the vdbe. | |
| 80980 | + ** | |
| 80981 | + ** After seeking the cursor, the vdbe executes an OP_ResultRow. | |
| 80982 | + ** Code external to the Vdbe then "borrows" the b-tree cursor and | |
| 80983 | + ** uses it to implement the blob_read(), blob_write() and | |
| 80984 | + ** blob_bytes() functions. | |
| 80985 | + ** | |
| 80986 | + ** The sqlite3_blob_close() function finalizes the vdbe program, | |
| 80987 | + ** which closes the b-tree cursor and (possibly) commits the | |
| 80988 | + ** transaction. | |
| 80989 | + */ | |
| 80990 | + static const int iLn = VDBE_OFFSET_LINENO(4); | |
| 80991 | + static const VdbeOpList openBlob[] = { | |
| 80992 | + /* addr/ofst */ | |
| 80993 | + /* {OP_Transaction, 0, 0, 0}, // 0/ inserted separately */ | |
| 80994 | + {OP_TableLock, 0, 0, 0}, /* 1/0: Acquire a read or write lock */ | |
| 80995 | + {OP_OpenRead, 0, 0, 0}, /* 2/1: Open a cursor */ | |
| 80996 | + {OP_Variable, 1, 1, 0}, /* 3/2: Move ?1 into reg[1] */ | |
| 80997 | + {OP_NotExists, 0, 8, 1}, /* 4/3: Seek the cursor */ | |
| 80998 | + {OP_Column, 0, 0, 1}, /* 5/4 */ | |
| 80999 | + {OP_ResultRow, 1, 0, 0}, /* 6/5 */ | |
| 81000 | + {OP_Goto, 0, 3, 0}, /* 7/6 */ | |
| 81001 | + {OP_Close, 0, 0, 0}, /* 8/7 */ | |
| 81002 | + {OP_Halt, 0, 0, 0}, /* 9/8 */ | |
| 81003 | + }; | |
| 80954 | 81004 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 80955 | 81005 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 80956 | - | |
| 81006 | + VdbeOp *aOp; | |
| 80957 | 81007 | |
| 80958 | 81008 | sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags, |
| 80959 | 81009 | pTab->pSchema->schema_cookie, |
| 80960 | 81010 | pTab->pSchema->iGeneration); |
| 80961 | 81011 | sqlite3VdbeChangeP5(v, 1); |
| 80962 | - sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn); | |
| 81012 | + aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn); | |
| 80963 | 81013 | |
| 80964 | 81014 | /* Make sure a mutex is held on the table to be accessed */ |
| 80965 | 81015 | sqlite3VdbeUsesBtree(v, iDb); |
| 80966 | 81016 | |
| 80967 | - /* Configure the OP_TableLock instruction */ | |
| 81017 | + if( db->mallocFailed==0 ){ | |
| 81018 | + assert( aOp!=0 ); | |
| 81019 | + /* Configure the OP_TableLock instruction */ | |
| 80968 | 81020 | #ifdef SQLITE_OMIT_SHARED_CACHE |
| 80969 | - sqlite3VdbeChangeToNoop(v, 1); | |
| 81021 | + aOp[0].opcode = OP_Noop; | |
| 80970 | 81022 | #else |
| 80971 | - sqlite3VdbeChangeP1(v, 1, iDb); | |
| 80972 | - sqlite3VdbeChangeP2(v, 1, pTab->tnum); | |
| 80973 | - sqlite3VdbeChangeP3(v, 1, flags); | |
| 80974 | - sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT); | |
| 81023 | + aOp[0].p1 = iDb; | |
| 81024 | + aOp[0].p2 = pTab->tnum; | |
| 81025 | + aOp[0].p3 = flags; | |
| 81026 | + sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT); | |
| 81027 | + } | |
| 81028 | + if( db->mallocFailed==0 ){ | |
| 80975 | 81029 | #endif |
| 80976 | 81030 | |
| 80977 | - /* Remove either the OP_OpenWrite or OpenRead. Set the P2 | |
| 80978 | - ** parameter of the other to pTab->tnum. */ | |
| 80979 | - sqlite3VdbeChangeToNoop(v, 3 - flags); | |
| 80980 | - sqlite3VdbeChangeP2(v, 2 + flags, pTab->tnum); | |
| 80981 | - sqlite3VdbeChangeP3(v, 2 + flags, iDb); | |
| 80982 | - | |
| 80983 | - /* Configure the number of columns. Configure the cursor to | |
| 80984 | - ** think that the table has one more column than it really | |
| 80985 | - ** does. An OP_Column to retrieve this imaginary column will | |
| 80986 | - ** always return an SQL NULL. This is useful because it means | |
| 80987 | - ** we can invoke OP_Column to fill in the vdbe cursors type | |
| 80988 | - ** and offset cache without causing any IO. | |
| 80989 | - */ | |
| 80990 | - sqlite3VdbeChangeP4(v, 2+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32); | |
| 80991 | - sqlite3VdbeChangeP2(v, 6, pTab->nCol); | |
| 80992 | - if( !db->mallocFailed ){ | |
| 81031 | + /* Remove either the OP_OpenWrite or OpenRead. Set the P2 | |
| 81032 | + ** parameter of the other to pTab->tnum. */ | |
| 81033 | + if( flags ) aOp[1].opcode = OP_OpenWrite; | |
| 81034 | + aOp[1].p2 = pTab->tnum; | |
| 81035 | + aOp[1].p3 = iDb; | |
| 81036 | + | |
| 81037 | + /* Configure the number of columns. Configure the cursor to | |
| 81038 | + ** think that the table has one more column than it really | |
| 81039 | + ** does. An OP_Column to retrieve this imaginary column will | |
| 81040 | + ** always return an SQL NULL. This is useful because it means | |
| 81041 | + ** we can invoke OP_Column to fill in the vdbe cursors type | |
| 81042 | + ** and offset cache without causing any IO. | |
| 81043 | + */ | |
| 81044 | + aOp[1].p4type = P4_INT32; | |
| 81045 | + aOp[1].p4.i = pTab->nCol+1; | |
| 81046 | + aOp[4].p2 = pTab->nCol; | |
| 81047 | + | |
| 80993 | 81048 | pParse->nVar = 1; |
| 80994 | 81049 | pParse->nMem = 1; |
| 80995 | 81050 | pParse->nTab = 1; |
| 80996 | 81051 | sqlite3VdbeMakeReady(v, pParse); |
| 80997 | 81052 | } |
| @@ -85251,11 +85306,11 @@ | ||
| 85251 | 85306 | no_such_func = 1; |
| 85252 | 85307 | }else{ |
| 85253 | 85308 | wrong_num_args = 1; |
| 85254 | 85309 | } |
| 85255 | 85310 | }else{ |
| 85256 | - is_agg = pDef->xFunc==0; | |
| 85311 | + is_agg = pDef->xFinalize!=0; | |
| 85257 | 85312 | if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){ |
| 85258 | 85313 | ExprSetProperty(pExpr, EP_Unlikely|EP_Skip); |
| 85259 | 85314 | if( n==2 ){ |
| 85260 | 85315 | pExpr->iTable = exprProbability(pList->a[1].pExpr); |
| 85261 | 85316 | if( pExpr->iTable<0 ){ |
| @@ -87218,14 +87273,15 @@ | ||
| 87218 | 87273 | ExprList *pList, /* List to which to append. Might be NULL */ |
| 87219 | 87274 | Expr *pExpr /* Expression to be appended. Might be NULL */ |
| 87220 | 87275 | ){ |
| 87221 | 87276 | sqlite3 *db = pParse->db; |
| 87222 | 87277 | if( pList==0 ){ |
| 87223 | - pList = sqlite3DbMallocZero(db, sizeof(ExprList) ); | |
| 87278 | + pList = sqlite3DbMallocRaw(db, sizeof(ExprList) ); | |
| 87224 | 87279 | if( pList==0 ){ |
| 87225 | 87280 | goto no_mem; |
| 87226 | 87281 | } |
| 87282 | + pList->nExpr = 0; | |
| 87227 | 87283 | pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0])); |
| 87228 | 87284 | if( pList->a==0 ) goto no_mem; |
| 87229 | 87285 | }else if( (pList->nExpr & (pList->nExpr-1))==0 ){ |
| 87230 | 87286 | struct ExprList_item *a; |
| 87231 | 87287 | assert( pList->nExpr>0 ); |
| @@ -88979,11 +89035,11 @@ | ||
| 88979 | 89035 | nFarg = pFarg ? pFarg->nExpr : 0; |
| 88980 | 89036 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 88981 | 89037 | zId = pExpr->u.zToken; |
| 88982 | 89038 | nId = sqlite3Strlen30(zId); |
| 88983 | 89039 | pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0); |
| 88984 | - if( pDef==0 || pDef->xFunc==0 ){ | |
| 89040 | + if( pDef==0 || pDef->xFinalize!=0 ){ | |
| 88985 | 89041 | sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId); |
| 88986 | 89042 | break; |
| 88987 | 89043 | } |
| 88988 | 89044 | |
| 88989 | 89045 | /* Attempt a direct implementation of the built-in COALESCE() and |
| @@ -91651,12 +91707,11 @@ | ||
| 91651 | 91707 | static const FuncDef statInitFuncdef = { |
| 91652 | 91708 | 2+IsStat34, /* nArg */ |
| 91653 | 91709 | SQLITE_UTF8, /* funcFlags */ |
| 91654 | 91710 | 0, /* pUserData */ |
| 91655 | 91711 | 0, /* pNext */ |
| 91656 | - statInit, /* xFunc */ | |
| 91657 | - 0, /* xStep */ | |
| 91712 | + statInit, /* xSFunc */ | |
| 91658 | 91713 | 0, /* xFinalize */ |
| 91659 | 91714 | "stat_init", /* zName */ |
| 91660 | 91715 | 0, /* pHash */ |
| 91661 | 91716 | 0 /* pDestructor */ |
| 91662 | 91717 | }; |
| @@ -91952,12 +92007,11 @@ | ||
| 91952 | 92007 | static const FuncDef statPushFuncdef = { |
| 91953 | 92008 | 2+IsStat34, /* nArg */ |
| 91954 | 92009 | SQLITE_UTF8, /* funcFlags */ |
| 91955 | 92010 | 0, /* pUserData */ |
| 91956 | 92011 | 0, /* pNext */ |
| 91957 | - statPush, /* xFunc */ | |
| 91958 | - 0, /* xStep */ | |
| 92012 | + statPush, /* xSFunc */ | |
| 91959 | 92013 | 0, /* xFinalize */ |
| 91960 | 92014 | "stat_push", /* zName */ |
| 91961 | 92015 | 0, /* pHash */ |
| 91962 | 92016 | 0 /* pDestructor */ |
| 91963 | 92017 | }; |
| @@ -92099,12 +92153,11 @@ | ||
| 92099 | 92153 | static const FuncDef statGetFuncdef = { |
| 92100 | 92154 | 1+IsStat34, /* nArg */ |
| 92101 | 92155 | SQLITE_UTF8, /* funcFlags */ |
| 92102 | 92156 | 0, /* pUserData */ |
| 92103 | 92157 | 0, /* pNext */ |
| 92104 | - statGet, /* xFunc */ | |
| 92105 | - 0, /* xStep */ | |
| 92158 | + statGet, /* xSFunc */ | |
| 92106 | 92159 | 0, /* xFinalize */ |
| 92107 | 92160 | "stat_get", /* zName */ |
| 92108 | 92161 | 0, /* pHash */ |
| 92109 | 92162 | 0 /* pDestructor */ |
| 92110 | 92163 | }; |
| @@ -92116,12 +92169,12 @@ | ||
| 92116 | 92169 | #elif SQLITE_DEBUG |
| 92117 | 92170 | assert( iParam==STAT_GET_STAT1 ); |
| 92118 | 92171 | #else |
| 92119 | 92172 | UNUSED_PARAMETER( iParam ); |
| 92120 | 92173 | #endif |
| 92121 | - sqlite3VdbeAddOp3(v, OP_Function0, 0, regStat4, regOut); | |
| 92122 | - sqlite3VdbeChangeP4(v, -1, (char*)&statGetFuncdef, P4_FUNCDEF); | |
| 92174 | + sqlite3VdbeAddOp4(v, OP_Function0, 0, regStat4, regOut, | |
| 92175 | + (char*)&statGetFuncdef, P4_FUNCDEF); | |
| 92123 | 92176 | sqlite3VdbeChangeP5(v, 1 + IsStat34); |
| 92124 | 92177 | } |
| 92125 | 92178 | |
| 92126 | 92179 | /* |
| 92127 | 92180 | ** Generate code to do an analysis of all indices associated with |
| @@ -92271,12 +92324,12 @@ | ||
| 92271 | 92324 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 92272 | 92325 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+3); |
| 92273 | 92326 | #endif |
| 92274 | 92327 | sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat4+1); |
| 92275 | 92328 | sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regStat4+2); |
| 92276 | - sqlite3VdbeAddOp3(v, OP_Function0, 0, regStat4+1, regStat4); | |
| 92277 | - sqlite3VdbeChangeP4(v, -1, (char*)&statInitFuncdef, P4_FUNCDEF); | |
| 92329 | + sqlite3VdbeAddOp4(v, OP_Function0, 0, regStat4+1, regStat4, | |
| 92330 | + (char*)&statInitFuncdef, P4_FUNCDEF); | |
| 92278 | 92331 | sqlite3VdbeChangeP5(v, 2+IsStat34); |
| 92279 | 92332 | |
| 92280 | 92333 | /* Implementation of the following: |
| 92281 | 92334 | ** |
| 92282 | 92335 | ** Rewind csr |
| @@ -92368,12 +92421,12 @@ | ||
| 92368 | 92421 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid); |
| 92369 | 92422 | sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol); |
| 92370 | 92423 | } |
| 92371 | 92424 | #endif |
| 92372 | 92425 | assert( regChng==(regStat4+1) ); |
| 92373 | - sqlite3VdbeAddOp3(v, OP_Function0, 1, regStat4, regTemp); | |
| 92374 | - sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF); | |
| 92426 | + sqlite3VdbeAddOp4(v, OP_Function0, 1, regStat4, regTemp, | |
| 92427 | + (char*)&statPushFuncdef, P4_FUNCDEF); | |
| 92375 | 92428 | sqlite3VdbeChangeP5(v, 2+IsStat34); |
| 92376 | 92429 | sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v); |
| 92377 | 92430 | |
| 92378 | 92431 | /* Add the entry to the stat1 table. */ |
| 92379 | 92432 | callStatGet(v, regStat4, STAT_GET_STAT1, regStat1); |
| @@ -93426,15 +93479,15 @@ | ||
| 93426 | 93479 | sqlite3ExprCode(pParse, pDbname, regArgs+1); |
| 93427 | 93480 | sqlite3ExprCode(pParse, pKey, regArgs+2); |
| 93428 | 93481 | |
| 93429 | 93482 | assert( v || db->mallocFailed ); |
| 93430 | 93483 | if( v ){ |
| 93431 | - sqlite3VdbeAddOp3(v, OP_Function0, 0, regArgs+3-pFunc->nArg, regArgs+3); | |
| 93484 | + sqlite3VdbeAddOp4(v, OP_Function0, 0, regArgs+3-pFunc->nArg, regArgs+3, | |
| 93485 | + (char *)pFunc, P4_FUNCDEF); | |
| 93432 | 93486 | assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg ); |
| 93433 | 93487 | sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg)); |
| 93434 | - sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF); | |
| 93435 | - | |
| 93488 | + | |
| 93436 | 93489 | /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this |
| 93437 | 93490 | ** statement only). For DETACH, set it to false (expire all existing |
| 93438 | 93491 | ** statements). |
| 93439 | 93492 | */ |
| 93440 | 93493 | sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH)); |
| @@ -93455,12 +93508,11 @@ | ||
| 93455 | 93508 | static const FuncDef detach_func = { |
| 93456 | 93509 | 1, /* nArg */ |
| 93457 | 93510 | SQLITE_UTF8, /* funcFlags */ |
| 93458 | 93511 | 0, /* pUserData */ |
| 93459 | 93512 | 0, /* pNext */ |
| 93460 | - detachFunc, /* xFunc */ | |
| 93461 | - 0, /* xStep */ | |
| 93513 | + detachFunc, /* xSFunc */ | |
| 93462 | 93514 | 0, /* xFinalize */ |
| 93463 | 93515 | "sqlite_detach", /* zName */ |
| 93464 | 93516 | 0, /* pHash */ |
| 93465 | 93517 | 0 /* pDestructor */ |
| 93466 | 93518 | }; |
| @@ -93476,12 +93528,11 @@ | ||
| 93476 | 93528 | static const FuncDef attach_func = { |
| 93477 | 93529 | 3, /* nArg */ |
| 93478 | 93530 | SQLITE_UTF8, /* funcFlags */ |
| 93479 | 93531 | 0, /* pUserData */ |
| 93480 | 93532 | 0, /* pNext */ |
| 93481 | - attachFunc, /* xFunc */ | |
| 93482 | - 0, /* xStep */ | |
| 93533 | + attachFunc, /* xSFunc */ | |
| 93483 | 93534 | 0, /* xFinalize */ |
| 93484 | 93535 | "sqlite_attach", /* zName */ |
| 93485 | 93536 | 0, /* pHash */ |
| 93486 | 93537 | 0 /* pDestructor */ |
| 93487 | 93538 | }; |
| @@ -94145,19 +94196,23 @@ | ||
| 94145 | 94196 | /* A minimum of one cursor is required if autoincrement is used |
| 94146 | 94197 | * See ticket [a696379c1f08866] */ |
| 94147 | 94198 | if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1; |
| 94148 | 94199 | sqlite3VdbeMakeReady(v, pParse); |
| 94149 | 94200 | pParse->rc = SQLITE_DONE; |
| 94150 | - pParse->colNamesSet = 0; | |
| 94151 | 94201 | }else{ |
| 94152 | 94202 | pParse->rc = SQLITE_ERROR; |
| 94153 | 94203 | } |
| 94204 | + | |
| 94205 | + /* We are done with this Parse object. There is no need to de-initialize it */ | |
| 94206 | +#if 0 | |
| 94207 | + pParse->colNamesSet = 0; | |
| 94154 | 94208 | pParse->nTab = 0; |
| 94155 | 94209 | pParse->nMem = 0; |
| 94156 | 94210 | pParse->nSet = 0; |
| 94157 | 94211 | pParse->nVar = 0; |
| 94158 | 94212 | DbMaskZero(pParse->cookieMask); |
| 94213 | +#endif | |
| 94159 | 94214 | } |
| 94160 | 94215 | |
| 94161 | 94216 | /* |
| 94162 | 94217 | ** Run the parser and code generator recursively in order to generate |
| 94163 | 94218 | ** code for the SQL statement given onto the end of the pParse context |
| @@ -94412,11 +94467,10 @@ | ||
| 94412 | 94467 | if( j<i ){ |
| 94413 | 94468 | db->aDb[j] = db->aDb[i]; |
| 94414 | 94469 | } |
| 94415 | 94470 | j++; |
| 94416 | 94471 | } |
| 94417 | - memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j])); | |
| 94418 | 94472 | db->nDb = j; |
| 94419 | 94473 | if( db->nDb<=2 && db->aDb!=db->aDbStatic ){ |
| 94420 | 94474 | memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0])); |
| 94421 | 94475 | sqlite3DbFree(db, db->aDb); |
| 94422 | 94476 | db->aDb = db->aDbStatic; |
| @@ -94675,11 +94729,12 @@ | ||
| 94675 | 94729 | Token **pUnqual /* Write the unqualified object name here */ |
| 94676 | 94730 | ){ |
| 94677 | 94731 | int iDb; /* Database holding the object */ |
| 94678 | 94732 | sqlite3 *db = pParse->db; |
| 94679 | 94733 | |
| 94680 | - if( ALWAYS(pName2!=0) && pName2->n>0 ){ | |
| 94734 | + assert( pName2!=0 ); | |
| 94735 | + if( pName2->n>0 ){ | |
| 94681 | 94736 | if( db->init.busy ) { |
| 94682 | 94737 | sqlite3ErrorMsg(pParse, "corrupt database"); |
| 94683 | 94738 | return -1; |
| 94684 | 94739 | } |
| 94685 | 94740 | *pUnqual = pName2; |
| @@ -94764,66 +94819,50 @@ | ||
| 94764 | 94819 | sqlite3 *db = pParse->db; |
| 94765 | 94820 | Vdbe *v; |
| 94766 | 94821 | int iDb; /* Database number to create the table in */ |
| 94767 | 94822 | Token *pName; /* Unqualified name of the table to create */ |
| 94768 | 94823 | |
| 94769 | - /* The table or view name to create is passed to this routine via tokens | |
| 94770 | - ** pName1 and pName2. If the table name was fully qualified, for example: | |
| 94771 | - ** | |
| 94772 | - ** CREATE TABLE xxx.yyy (...); | |
| 94773 | - ** | |
| 94774 | - ** Then pName1 is set to "xxx" and pName2 "yyy". On the other hand if | |
| 94775 | - ** the table name is not fully qualified, i.e.: | |
| 94776 | - ** | |
| 94777 | - ** CREATE TABLE yyy(...); | |
| 94778 | - ** | |
| 94779 | - ** Then pName1 is set to "yyy" and pName2 is "". | |
| 94780 | - ** | |
| 94781 | - ** The call below sets the pName pointer to point at the token (pName1 or | |
| 94782 | - ** pName2) that stores the unqualified table name. The variable iDb is | |
| 94783 | - ** set to the index of the database that the table or view is to be | |
| 94784 | - ** created in. | |
| 94785 | - */ | |
| 94786 | - iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName); | |
| 94787 | - if( iDb<0 ) return; | |
| 94788 | - if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){ | |
| 94789 | - /* If creating a temp table, the name may not be qualified. Unless | |
| 94790 | - ** the database name is "temp" anyway. */ | |
| 94791 | - sqlite3ErrorMsg(pParse, "temporary table name must be unqualified"); | |
| 94792 | - return; | |
| 94793 | - } | |
| 94794 | - if( !OMIT_TEMPDB && isTemp ) iDb = 1; | |
| 94795 | - | |
| 94796 | - pParse->sNameToken = *pName; | |
| 94797 | - zName = sqlite3NameFromToken(db, pName); | |
| 94824 | + if( db->init.busy && db->init.newTnum==1 ){ | |
| 94825 | + /* Special case: Parsing the sqlite_master or sqlite_temp_master schema */ | |
| 94826 | + iDb = db->init.iDb; | |
| 94827 | + zName = sqlite3DbStrDup(db, SCHEMA_TABLE(iDb)); | |
| 94828 | + pName = pName1; | |
| 94829 | + }else{ | |
| 94830 | + /* The common case */ | |
| 94831 | + iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName); | |
| 94832 | + if( iDb<0 ) return; | |
| 94833 | + if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){ | |
| 94834 | + /* If creating a temp table, the name may not be qualified. Unless | |
| 94835 | + ** the database name is "temp" anyway. */ | |
| 94836 | + sqlite3ErrorMsg(pParse, "temporary table name must be unqualified"); | |
| 94837 | + return; | |
| 94838 | + } | |
| 94839 | + if( !OMIT_TEMPDB && isTemp ) iDb = 1; | |
| 94840 | + zName = sqlite3NameFromToken(db, pName); | |
| 94841 | + } | |
| 94842 | + pParse->sNameToken = *pName; | |
| 94798 | 94843 | if( zName==0 ) return; |
| 94799 | 94844 | if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ |
| 94800 | 94845 | goto begin_table_error; |
| 94801 | 94846 | } |
| 94802 | 94847 | if( db->init.iDb==1 ) isTemp = 1; |
| 94803 | 94848 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 94804 | - assert( (isTemp & 1)==isTemp ); | |
| 94849 | + assert( isTemp==0 || isTemp==1 ); | |
| 94850 | + assert( isView==0 || isView==1 ); | |
| 94805 | 94851 | { |
| 94806 | - int code; | |
| 94852 | + static const u8 aCode[] = { | |
| 94853 | + SQLITE_CREATE_TABLE, | |
| 94854 | + SQLITE_CREATE_TEMP_TABLE, | |
| 94855 | + SQLITE_CREATE_VIEW, | |
| 94856 | + SQLITE_CREATE_TEMP_VIEW | |
| 94857 | + }; | |
| 94807 | 94858 | char *zDb = db->aDb[iDb].zName; |
| 94808 | 94859 | if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){ |
| 94809 | 94860 | goto begin_table_error; |
| 94810 | 94861 | } |
| 94811 | - if( isView ){ | |
| 94812 | - if( !OMIT_TEMPDB && isTemp ){ | |
| 94813 | - code = SQLITE_CREATE_TEMP_VIEW; | |
| 94814 | - }else{ | |
| 94815 | - code = SQLITE_CREATE_VIEW; | |
| 94816 | - } | |
| 94817 | - }else{ | |
| 94818 | - if( !OMIT_TEMPDB && isTemp ){ | |
| 94819 | - code = SQLITE_CREATE_TEMP_TABLE; | |
| 94820 | - }else{ | |
| 94821 | - code = SQLITE_CREATE_TABLE; | |
| 94822 | - } | |
| 94823 | - } | |
| 94824 | - if( !isVirtual && sqlite3AuthCheck(pParse, code, zName, 0, zDb) ){ | |
| 94862 | + if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView], | |
| 94863 | + zName, 0, zDb) ){ | |
| 94825 | 94864 | goto begin_table_error; |
| 94826 | 94865 | } |
| 94827 | 94866 | } |
| 94828 | 94867 | #endif |
| 94829 | 94868 | |
| @@ -95781,13 +95820,17 @@ | ||
| 95781 | 95820 | /* If the db->init.busy is 1 it means we are reading the SQL off the |
| 95782 | 95821 | ** "sqlite_master" or "sqlite_temp_master" table on the disk. |
| 95783 | 95822 | ** So do not write to the disk again. Extract the root page number |
| 95784 | 95823 | ** for the table from the db->init.newTnum field. (The page number |
| 95785 | 95824 | ** should have been put there by the sqliteOpenCb routine.) |
| 95825 | + ** | |
| 95826 | + ** If the root page number is 1, that means this is the sqlite_master | |
| 95827 | + ** table itself. So mark it read-only. | |
| 95786 | 95828 | */ |
| 95787 | 95829 | if( db->init.busy ){ |
| 95788 | 95830 | p->tnum = db->init.newTnum; |
| 95831 | + if( p->tnum==1 ) p->tabFlags |= TF_Readonly; | |
| 95789 | 95832 | } |
| 95790 | 95833 | |
| 95791 | 95834 | /* Special processing for WITHOUT ROWID Tables */ |
| 95792 | 95835 | if( tabOpts & TF_WithoutRowid ){ |
| 95793 | 95836 | if( (p->tabFlags & TF_Autoincrement) ){ |
| @@ -96236,10 +96279,11 @@ | ||
| 96236 | 96279 | ** erasing iTable (this can happen with an auto-vacuum database). |
| 96237 | 96280 | */ |
| 96238 | 96281 | static void destroyRootPage(Parse *pParse, int iTable, int iDb){ |
| 96239 | 96282 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 96240 | 96283 | int r1 = sqlite3GetTempReg(pParse); |
| 96284 | + assert( iTable>1 ); | |
| 96241 | 96285 | sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb); |
| 96242 | 96286 | sqlite3MayAbort(pParse); |
| 96243 | 96287 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 96244 | 96288 | /* OP_Destroy stores an in integer r1. If this integer |
| 96245 | 96289 | ** is non-zero, then it is the root page number of a table moved to |
| @@ -97634,13 +97678,14 @@ | ||
| 97634 | 97678 | Token *pDatabase /* Database of the table */ |
| 97635 | 97679 | ){ |
| 97636 | 97680 | struct SrcList_item *pItem; |
| 97637 | 97681 | assert( pDatabase==0 || pTable!=0 ); /* Cannot have C without B */ |
| 97638 | 97682 | if( pList==0 ){ |
| 97639 | - pList = sqlite3DbMallocZero(db, sizeof(SrcList) ); | |
| 97683 | + pList = sqlite3DbMallocRaw(db, sizeof(SrcList) ); | |
| 97640 | 97684 | if( pList==0 ) return 0; |
| 97641 | 97685 | pList->nAlloc = 1; |
| 97686 | + pList->nSrc = 0; | |
| 97642 | 97687 | } |
| 97643 | 97688 | pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc); |
| 97644 | 97689 | if( db->mallocFailed ){ |
| 97645 | 97690 | sqlite3SrcListDelete(db, pList); |
| 97646 | 97691 | return 0; |
| @@ -98039,11 +98084,11 @@ | ||
| 98039 | 98084 | assert( (errCode&0xff)==SQLITE_CONSTRAINT ); |
| 98040 | 98085 | if( onError==OE_Abort ){ |
| 98041 | 98086 | sqlite3MayAbort(pParse); |
| 98042 | 98087 | } |
| 98043 | 98088 | sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type); |
| 98044 | - if( p5Errmsg ) sqlite3VdbeChangeP5(v, p5Errmsg); | |
| 98089 | + sqlite3VdbeChangeP5(v, p5Errmsg); | |
| 98045 | 98090 | } |
| 98046 | 98091 | |
| 98047 | 98092 | /* |
| 98048 | 98093 | ** Code an OP_Halt due to UNIQUE or PRIMARY KEY constraint violation. |
| 98049 | 98094 | */ |
| @@ -98580,12 +98625,12 @@ | ||
| 98580 | 98625 | ** 3: encoding matches and function takes any number of arguments |
| 98581 | 98626 | ** 4: UTF8/16 conversion required - argument count matches exactly |
| 98582 | 98627 | ** 5: UTF16 byte order conversion required - argument count matches exactly |
| 98583 | 98628 | ** 6: Perfect match: encoding and argument count match exactly. |
| 98584 | 98629 | ** |
| 98585 | -** If nArg==(-2) then any function with a non-null xStep or xFunc is | |
| 98586 | -** a perfect match and any function with both xStep and xFunc NULL is | |
| 98630 | +** If nArg==(-2) then any function with a non-null xSFunc is | |
| 98631 | +** a perfect match and any function with xSFunc NULL is | |
| 98587 | 98632 | ** a non-match. |
| 98588 | 98633 | */ |
| 98589 | 98634 | #define FUNC_PERFECT_MATCH 6 /* The score for a perfect match */ |
| 98590 | 98635 | static int matchQuality( |
| 98591 | 98636 | FuncDef *p, /* The function we are evaluating for match quality */ |
| @@ -98593,11 +98638,11 @@ | ||
| 98593 | 98638 | u8 enc /* Desired text encoding */ |
| 98594 | 98639 | ){ |
| 98595 | 98640 | int match; |
| 98596 | 98641 | |
| 98597 | 98642 | /* nArg of -2 is a special case */ |
| 98598 | - if( nArg==(-2) ) return (p->xFunc==0 && p->xStep==0) ? 0 : FUNC_PERFECT_MATCH; | |
| 98643 | + if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH; | |
| 98599 | 98644 | |
| 98600 | 98645 | /* Wrong number of arguments means "no match" */ |
| 98601 | 98646 | if( p->nArg!=nArg && p->nArg>=0 ) return 0; |
| 98602 | 98647 | |
| 98603 | 98648 | /* Give a better score to a function with a specific number of arguments |
| @@ -98671,11 +98716,11 @@ | ||
| 98671 | 98716 | ** If the createFlag argument is true, then a new (blank) FuncDef |
| 98672 | 98717 | ** structure is created and liked into the "db" structure if a |
| 98673 | 98718 | ** no matching function previously existed. |
| 98674 | 98719 | ** |
| 98675 | 98720 | ** If nArg is -2, then the first valid function found is returned. A |
| 98676 | -** function is valid if either xFunc or xStep is non-zero. The nArg==(-2) | |
| 98721 | +** function is valid if xSFunc is non-zero. The nArg==(-2) | |
| 98677 | 98722 | ** case is used to see if zName is a valid function name for some number |
| 98678 | 98723 | ** of arguments. If nArg is -2, then createFlag must be 0. |
| 98679 | 98724 | ** |
| 98680 | 98725 | ** If createFlag is false, then a function with the required name and |
| 98681 | 98726 | ** number of arguments may be returned even if the eTextRep flag does not |
| @@ -98748,11 +98793,11 @@ | ||
| 98748 | 98793 | memcpy(pBest->zName, zName, nName); |
| 98749 | 98794 | pBest->zName[nName] = 0; |
| 98750 | 98795 | sqlite3FuncDefInsert(&db->aFunc, pBest); |
| 98751 | 98796 | } |
| 98752 | 98797 | |
| 98753 | - if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){ | |
| 98798 | + if( pBest && (pBest->xSFunc || createFlag) ){ | |
| 98754 | 98799 | return pBest; |
| 98755 | 98800 | } |
| 98756 | 98801 | return 0; |
| 98757 | 98802 | } |
| 98758 | 98803 | |
| @@ -104530,11 +104575,11 @@ | ||
| 104530 | 104575 | if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT; |
| 104531 | 104576 | if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){ |
| 104532 | 104577 | assert( pParse->nested==0 ); |
| 104533 | 104578 | pik_flags |= OPFLAG_NCHANGE; |
| 104534 | 104579 | } |
| 104535 | - if( pik_flags ) sqlite3VdbeChangeP5(v, pik_flags); | |
| 104580 | + sqlite3VdbeChangeP5(v, pik_flags); | |
| 104536 | 104581 | } |
| 104537 | 104582 | if( !HasRowid(pTab) ) return; |
| 104538 | 104583 | regData = regNewData + 1; |
| 104539 | 104584 | regRec = sqlite3GetTempReg(pParse); |
| 104540 | 104585 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec); |
| @@ -104946,13 +104991,13 @@ | ||
| 104946 | 104991 | }else{ |
| 104947 | 104992 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 104948 | 104993 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 104949 | 104994 | } |
| 104950 | 104995 | sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); |
| 104951 | - sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid); | |
| 104996 | + sqlite3VdbeAddOp4(v, OP_Insert, iDest, regData, regRowid, | |
| 104997 | + pDest->zName, 0); | |
| 104952 | 104998 | sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND); |
| 104953 | - sqlite3VdbeChangeP4(v, -1, pDest->zName, 0); | |
| 104954 | 104999 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v); |
| 104955 | 105000 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| 104956 | 105001 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 104957 | 105002 | }else{ |
| 104958 | 105003 | sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName); |
| @@ -107401,19 +107446,21 @@ | ||
| 107401 | 107446 | { OP_IfPos, 1, 8, 0}, |
| 107402 | 107447 | { OP_Integer, 0, 1, 0}, /* 6 */ |
| 107403 | 107448 | { OP_Noop, 0, 0, 0}, |
| 107404 | 107449 | { OP_ResultRow, 1, 1, 0}, |
| 107405 | 107450 | }; |
| 107406 | - int addr; | |
| 107451 | + VdbeOp *aOp; | |
| 107407 | 107452 | sqlite3VdbeUsesBtree(v, iDb); |
| 107408 | 107453 | if( !zRight ){ |
| 107409 | 107454 | setOneColumnName(v, "cache_size"); |
| 107410 | 107455 | pParse->nMem += 2; |
| 107411 | - addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn); | |
| 107412 | - sqlite3VdbeChangeP1(v, addr, iDb); | |
| 107413 | - sqlite3VdbeChangeP1(v, addr+1, iDb); | |
| 107414 | - sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE); | |
| 107456 | + sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(getCacheSize)); | |
| 107457 | + aOp = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize, iLn); | |
| 107458 | + if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; | |
| 107459 | + aOp[0].p1 = iDb; | |
| 107460 | + aOp[1].p1 = iDb; | |
| 107461 | + aOp[6].p1 = SQLITE_DEFAULT_CACHE_SIZE; | |
| 107415 | 107462 | }else{ |
| 107416 | 107463 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| 107417 | 107464 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 107418 | 107465 | sqlite3VdbeAddOp2(v, OP_Integer, size, 1); |
| 107419 | 107466 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); |
| @@ -107655,17 +107702,20 @@ | ||
| 107655 | 107702 | { OP_If, 1, 0, 0}, /* 2 */ |
| 107656 | 107703 | { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
| 107657 | 107704 | { OP_Integer, 0, 1, 0}, /* 4 */ |
| 107658 | 107705 | { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ |
| 107659 | 107706 | }; |
| 107660 | - int iAddr; | |
| 107661 | - iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn); | |
| 107662 | - sqlite3VdbeChangeP1(v, iAddr, iDb); | |
| 107663 | - sqlite3VdbeChangeP1(v, iAddr+1, iDb); | |
| 107664 | - sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4); | |
| 107665 | - sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); | |
| 107666 | - sqlite3VdbeChangeP1(v, iAddr+5, iDb); | |
| 107707 | + VdbeOp *aOp; | |
| 107708 | + int iAddr = sqlite3VdbeCurrentAddr(v); | |
| 107709 | + sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setMeta6)); | |
| 107710 | + aOp = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn); | |
| 107711 | + if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; | |
| 107712 | + aOp[0].p1 = iDb; | |
| 107713 | + aOp[1].p1 = iDb; | |
| 107714 | + aOp[2].p2 = iAddr+4; | |
| 107715 | + aOp[4].p1 = eAuto - 1; | |
| 107716 | + aOp[5].p1 = iDb; | |
| 107667 | 107717 | sqlite3VdbeUsesBtree(v, iDb); |
| 107668 | 107718 | } |
| 107669 | 107719 | } |
| 107670 | 107720 | break; |
| 107671 | 107721 | } |
| @@ -108367,22 +108417,10 @@ | ||
| 108367 | 108417 | ** without most of the overhead of a full integrity-check. |
| 108368 | 108418 | */ |
| 108369 | 108419 | case PragTyp_INTEGRITY_CHECK: { |
| 108370 | 108420 | int i, j, addr, mxErr; |
| 108371 | 108421 | |
| 108372 | - /* Code that appears at the end of the integrity check. If no error | |
| 108373 | - ** messages have been generated, output OK. Otherwise output the | |
| 108374 | - ** error message | |
| 108375 | - */ | |
| 108376 | - static const int iLn = VDBE_OFFSET_LINENO(2); | |
| 108377 | - static const VdbeOpList endCode[] = { | |
| 108378 | - { OP_AddImm, 1, 0, 0}, /* 0 */ | |
| 108379 | - { OP_If, 1, 0, 0}, /* 1 */ | |
| 108380 | - { OP_String8, 0, 3, 0}, /* 2 */ | |
| 108381 | - { OP_ResultRow, 3, 1, 0}, | |
| 108382 | - }; | |
| 108383 | - | |
| 108384 | 108422 | int isQuick = (sqlite3Tolower(zLeft[0])=='q'); |
| 108385 | 108423 | |
| 108386 | 108424 | /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check", |
| 108387 | 108425 | ** then iDb is set to the index of the database identified by <db>. |
| 108388 | 108426 | ** In this case, the integrity of database iDb only is verified by |
| @@ -108575,14 +108613,28 @@ | ||
| 108575 | 108613 | sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1); |
| 108576 | 108614 | } |
| 108577 | 108615 | #endif /* SQLITE_OMIT_BTREECOUNT */ |
| 108578 | 108616 | } |
| 108579 | 108617 | } |
| 108580 | - addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); | |
| 108581 | - sqlite3VdbeChangeP2(v, addr, -mxErr); | |
| 108582 | - sqlite3VdbeJumpHere(v, addr+1); | |
| 108583 | - sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC); | |
| 108618 | + { | |
| 108619 | + static const int iLn = VDBE_OFFSET_LINENO(2); | |
| 108620 | + static const VdbeOpList endCode[] = { | |
| 108621 | + { OP_AddImm, 1, 0, 0}, /* 0 */ | |
| 108622 | + { OP_If, 1, 0, 0}, /* 1 */ | |
| 108623 | + { OP_String8, 0, 3, 0}, /* 2 */ | |
| 108624 | + { OP_ResultRow, 3, 1, 0}, | |
| 108625 | + }; | |
| 108626 | + VdbeOp *aOp; | |
| 108627 | + | |
| 108628 | + aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); | |
| 108629 | + if( aOp ){ | |
| 108630 | + aOp[0].p2 = -mxErr; | |
| 108631 | + aOp[1].p2 = sqlite3VdbeCurrentAddr(v); | |
| 108632 | + aOp[2].p4type = P4_STATIC; | |
| 108633 | + aOp[2].p4.z = "ok"; | |
| 108634 | + } | |
| 108635 | + } | |
| 108584 | 108636 | } |
| 108585 | 108637 | break; |
| 108586 | 108638 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 108587 | 108639 | |
| 108588 | 108640 | #ifndef SQLITE_OMIT_UTF16 |
| @@ -108695,26 +108747,32 @@ | ||
| 108695 | 108747 | static const VdbeOpList setCookie[] = { |
| 108696 | 108748 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 108697 | 108749 | { OP_Integer, 0, 1, 0}, /* 1 */ |
| 108698 | 108750 | { OP_SetCookie, 0, 0, 1}, /* 2 */ |
| 108699 | 108751 | }; |
| 108700 | - int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); | |
| 108701 | - sqlite3VdbeChangeP1(v, addr, iDb); | |
| 108702 | - sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight)); | |
| 108703 | - sqlite3VdbeChangeP1(v, addr+2, iDb); | |
| 108704 | - sqlite3VdbeChangeP2(v, addr+2, iCookie); | |
| 108752 | + VdbeOp *aOp; | |
| 108753 | + sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setCookie)); | |
| 108754 | + aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); | |
| 108755 | + if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; | |
| 108756 | + aOp[0].p1 = iDb; | |
| 108757 | + aOp[1].p1 = sqlite3Atoi(zRight); | |
| 108758 | + aOp[2].p1 = iDb; | |
| 108759 | + aOp[2].p2 = iCookie; | |
| 108705 | 108760 | }else{ |
| 108706 | 108761 | /* Read the specified cookie value */ |
| 108707 | 108762 | static const VdbeOpList readCookie[] = { |
| 108708 | 108763 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 108709 | 108764 | { OP_ReadCookie, 0, 1, 0}, /* 1 */ |
| 108710 | 108765 | { OP_ResultRow, 1, 1, 0} |
| 108711 | 108766 | }; |
| 108712 | - int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0); | |
| 108713 | - sqlite3VdbeChangeP1(v, addr, iDb); | |
| 108714 | - sqlite3VdbeChangeP1(v, addr+1, iDb); | |
| 108715 | - sqlite3VdbeChangeP3(v, addr+1, iCookie); | |
| 108767 | + VdbeOp *aOp; | |
| 108768 | + sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(readCookie)); | |
| 108769 | + aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0); | |
| 108770 | + if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; | |
| 108771 | + aOp[0].p1 = iDb; | |
| 108772 | + aOp[1].p1 = iDb; | |
| 108773 | + aOp[1].p3 = iCookie; | |
| 108716 | 108774 | sqlite3VdbeSetNumCols(v, 1); |
| 108717 | 108775 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); |
| 108718 | 108776 | } |
| 108719 | 108777 | } |
| 108720 | 108778 | break; |
| @@ -109077,65 +109135,31 @@ | ||
| 109077 | 109135 | int rc; |
| 109078 | 109136 | int i; |
| 109079 | 109137 | #ifndef SQLITE_OMIT_DEPRECATED |
| 109080 | 109138 | int size; |
| 109081 | 109139 | #endif |
| 109082 | - Table *pTab; | |
| 109083 | 109140 | Db *pDb; |
| 109084 | 109141 | char const *azArg[4]; |
| 109085 | 109142 | int meta[5]; |
| 109086 | 109143 | InitData initData; |
| 109087 | - char const *zMasterSchema; | |
| 109088 | - char const *zMasterName; | |
| 109144 | + const char *zMasterName; | |
| 109089 | 109145 | int openedTransaction = 0; |
| 109090 | 109146 | |
| 109091 | - /* | |
| 109092 | - ** The master database table has a structure like this | |
| 109093 | - */ | |
| 109094 | - static const char master_schema[] = | |
| 109095 | - "CREATE TABLE sqlite_master(\n" | |
| 109096 | - " type text,\n" | |
| 109097 | - " name text,\n" | |
| 109098 | - " tbl_name text,\n" | |
| 109099 | - " rootpage integer,\n" | |
| 109100 | - " sql text\n" | |
| 109101 | - ")" | |
| 109102 | - ; | |
| 109103 | -#ifndef SQLITE_OMIT_TEMPDB | |
| 109104 | - static const char temp_master_schema[] = | |
| 109105 | - "CREATE TEMP TABLE sqlite_temp_master(\n" | |
| 109106 | - " type text,\n" | |
| 109107 | - " name text,\n" | |
| 109108 | - " tbl_name text,\n" | |
| 109109 | - " rootpage integer,\n" | |
| 109110 | - " sql text\n" | |
| 109111 | - ")" | |
| 109112 | - ; | |
| 109113 | -#else | |
| 109114 | - #define temp_master_schema 0 | |
| 109115 | -#endif | |
| 109116 | - | |
| 109117 | 109147 | assert( iDb>=0 && iDb<db->nDb ); |
| 109118 | 109148 | assert( db->aDb[iDb].pSchema ); |
| 109119 | 109149 | assert( sqlite3_mutex_held(db->mutex) ); |
| 109120 | 109150 | assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 109121 | 109151 | |
| 109122 | - /* zMasterSchema and zInitScript are set to point at the master schema | |
| 109123 | - ** and initialisation script appropriate for the database being | |
| 109124 | - ** initialized. zMasterName is the name of the master table. | |
| 109125 | - */ | |
| 109126 | - if( !OMIT_TEMPDB && iDb==1 ){ | |
| 109127 | - zMasterSchema = temp_master_schema; | |
| 109128 | - }else{ | |
| 109129 | - zMasterSchema = master_schema; | |
| 109130 | - } | |
| 109131 | - zMasterName = SCHEMA_TABLE(iDb); | |
| 109132 | - | |
| 109133 | - /* Construct the schema tables. */ | |
| 109134 | - azArg[0] = zMasterName; | |
| 109152 | + /* Construct the in-memory representation schema tables (sqlite_master or | |
| 109153 | + ** sqlite_temp_master) by invoking the parser directly. The appropriate | |
| 109154 | + ** table name will be inserted automatically by the parser so we can just | |
| 109155 | + ** use the abbreviation "x" here. The parser will also automatically tag | |
| 109156 | + ** the schema table as read-only. */ | |
| 109157 | + azArg[0] = zMasterName = SCHEMA_TABLE(iDb); | |
| 109135 | 109158 | azArg[1] = "1"; |
| 109136 | - azArg[2] = zMasterSchema; | |
| 109159 | + azArg[2] = "CREATE TABLE x(type text,name text,tbl_name text," | |
| 109160 | + "rootpage integer,sql text)"; | |
| 109137 | 109161 | azArg[3] = 0; |
| 109138 | 109162 | initData.db = db; |
| 109139 | 109163 | initData.iDb = iDb; |
| 109140 | 109164 | initData.rc = SQLITE_OK; |
| 109141 | 109165 | initData.pzErrMsg = pzErrMsg; |
| @@ -109142,14 +109166,10 @@ | ||
| 109142 | 109166 | sqlite3InitCallback(&initData, 3, (char **)azArg, 0); |
| 109143 | 109167 | if( initData.rc ){ |
| 109144 | 109168 | rc = initData.rc; |
| 109145 | 109169 | goto error_out; |
| 109146 | 109170 | } |
| 109147 | - pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName); | |
| 109148 | - if( ALWAYS(pTab) ){ | |
| 109149 | - pTab->tabFlags |= TF_Readonly; | |
| 109150 | - } | |
| 109151 | 109171 | |
| 109152 | 109172 | /* Create a cursor to hold the database open |
| 109153 | 109173 | */ |
| 109154 | 109174 | pDb = &db->aDb[iDb]; |
| 109155 | 109175 | if( pDb->pBt==0 ){ |
| @@ -109264,11 +109284,11 @@ | ||
| 109264 | 109284 | */ |
| 109265 | 109285 | assert( db->init.busy ); |
| 109266 | 109286 | { |
| 109267 | 109287 | char *zSql; |
| 109268 | 109288 | zSql = sqlite3MPrintf(db, |
| 109269 | - "SELECT name, rootpage, sql FROM '%q'.%s ORDER BY rowid", | |
| 109289 | + "SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid", | |
| 109270 | 109290 | db->aDb[iDb].zName, zMasterName); |
| 109271 | 109291 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 109272 | 109292 | { |
| 109273 | 109293 | sqlite3_xauth xAuth; |
| 109274 | 109294 | xAuth = db->xAuth; |
| @@ -110841,19 +110861,20 @@ | ||
| 110841 | 110861 | /* |
| 110842 | 110862 | ** Allocate a KeyInfo object sufficient for an index of N key columns and |
| 110843 | 110863 | ** X extra columns. |
| 110844 | 110864 | */ |
| 110845 | 110865 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){ |
| 110846 | - KeyInfo *p = sqlite3DbMallocZero(0, | |
| 110847 | - sizeof(KeyInfo) + (N+X)*(sizeof(CollSeq*)+1)); | |
| 110866 | + int nExtra = (N+X)*(sizeof(CollSeq*)+1); | |
| 110867 | + KeyInfo *p = sqlite3Malloc(sizeof(KeyInfo) + nExtra); | |
| 110848 | 110868 | if( p ){ |
| 110849 | 110869 | p->aSortOrder = (u8*)&p->aColl[N+X]; |
| 110850 | 110870 | p->nField = (u16)N; |
| 110851 | 110871 | p->nXField = (u16)X; |
| 110852 | 110872 | p->enc = ENC(db); |
| 110853 | 110873 | p->db = db; |
| 110854 | 110874 | p->nRef = 1; |
| 110875 | + memset(&p[1], 0, nExtra); | |
| 110855 | 110876 | }else{ |
| 110856 | 110877 | db->mallocFailed = 1; |
| 110857 | 110878 | } |
| 110858 | 110879 | return p; |
| 110859 | 110880 | } |
| @@ -116638,12 +116659,12 @@ | ||
| 116638 | 116659 | /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program |
| 116639 | 116660 | ** is a pointer to the sub-vdbe containing the trigger program. */ |
| 116640 | 116661 | if( pPrg ){ |
| 116641 | 116662 | int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers)); |
| 116642 | 116663 | |
| 116643 | - sqlite3VdbeAddOp3(v, OP_Program, reg, ignoreJump, ++pParse->nMem); | |
| 116644 | - sqlite3VdbeChangeP4(v, -1, (const char *)pPrg->pProgram, P4_SUBPROGRAM); | |
| 116664 | + sqlite3VdbeAddOp4(v, OP_Program, reg, ignoreJump, ++pParse->nMem, | |
| 116665 | + (const char *)pPrg->pProgram, P4_SUBPROGRAM); | |
| 116645 | 116666 | VdbeComment( |
| 116646 | 116667 | (v, "Call: %s.%s", (p->zName?p->zName:"fkey"), onErrorText(orconf))); |
| 116647 | 116668 | |
| 116648 | 116669 | /* Set the P5 operand of the OP_Program instruction to non-zero if |
| 116649 | 116670 | ** recursive invocation of this trigger program is disallowed. Recursive |
| @@ -118993,11 +119014,11 @@ | ||
| 118993 | 119014 | Expr *pExpr /* First argument to the function */ |
| 118994 | 119015 | ){ |
| 118995 | 119016 | Table *pTab; |
| 118996 | 119017 | sqlite3_vtab *pVtab; |
| 118997 | 119018 | sqlite3_module *pMod; |
| 118998 | - void (*xFunc)(sqlite3_context*,int,sqlite3_value**) = 0; | |
| 119019 | + void (*xSFunc)(sqlite3_context*,int,sqlite3_value**) = 0; | |
| 118999 | 119020 | void *pArg = 0; |
| 119000 | 119021 | FuncDef *pNew; |
| 119001 | 119022 | int rc = 0; |
| 119002 | 119023 | char *zLowerName; |
| 119003 | 119024 | unsigned char *z; |
| @@ -119021,11 +119042,11 @@ | ||
| 119021 | 119042 | zLowerName = sqlite3DbStrDup(db, pDef->zName); |
| 119022 | 119043 | if( zLowerName ){ |
| 119023 | 119044 | for(z=(unsigned char*)zLowerName; *z; z++){ |
| 119024 | 119045 | *z = sqlite3UpperToLower[*z]; |
| 119025 | 119046 | } |
| 119026 | - rc = pMod->xFindFunction(pVtab, nArg, zLowerName, &xFunc, &pArg); | |
| 119047 | + rc = pMod->xFindFunction(pVtab, nArg, zLowerName, &xSFunc, &pArg); | |
| 119027 | 119048 | sqlite3DbFree(db, zLowerName); |
| 119028 | 119049 | } |
| 119029 | 119050 | if( rc==0 ){ |
| 119030 | 119051 | return pDef; |
| 119031 | 119052 | } |
| @@ -119038,11 +119059,11 @@ | ||
| 119038 | 119059 | return pDef; |
| 119039 | 119060 | } |
| 119040 | 119061 | *pNew = *pDef; |
| 119041 | 119062 | pNew->zName = (char *)&pNew[1]; |
| 119042 | 119063 | memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1); |
| 119043 | - pNew->xFunc = xFunc; | |
| 119064 | + pNew->xSFunc = xSFunc; | |
| 119044 | 119065 | pNew->pUserData = pArg; |
| 119045 | 119066 | pNew->funcFlags |= SQLITE_FUNC_EPHEM; |
| 119046 | 119067 | return pNew; |
| 119047 | 119068 | } |
| 119048 | 119069 | |
| @@ -120058,12 +120079,11 @@ | ||
| 120058 | 120079 | n--; |
| 120059 | 120080 | } |
| 120060 | 120081 | |
| 120061 | 120082 | /* Code the OP_Affinity opcode if there is anything left to do. */ |
| 120062 | 120083 | if( n>0 ){ |
| 120063 | - sqlite3VdbeAddOp2(v, OP_Affinity, base, n); | |
| 120064 | - sqlite3VdbeChangeP4(v, -1, zAff, n); | |
| 120084 | + sqlite3VdbeAddOp4(v, OP_Affinity, base, n, 0, zAff, n); | |
| 120065 | 120085 | sqlite3ExprCacheAffinityChange(pParse, base, n); |
| 120066 | 120086 | } |
| 120067 | 120087 | } |
| 120068 | 120088 | |
| 120069 | 120089 | |
| @@ -133811,11 +133831,11 @@ | ||
| 133811 | 133831 | sqlite3 *db, |
| 133812 | 133832 | const char *zFunctionName, |
| 133813 | 133833 | int nArg, |
| 133814 | 133834 | int enc, |
| 133815 | 133835 | void *pUserData, |
| 133816 | - void (*xFunc)(sqlite3_context*,int,sqlite3_value **), | |
| 133836 | + void (*xSFunc)(sqlite3_context*,int,sqlite3_value **), | |
| 133817 | 133837 | void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 133818 | 133838 | void (*xFinal)(sqlite3_context*), |
| 133819 | 133839 | FuncDestructor *pDestructor |
| 133820 | 133840 | ){ |
| 133821 | 133841 | FuncDef *p; |
| @@ -133822,13 +133842,13 @@ | ||
| 133822 | 133842 | int nName; |
| 133823 | 133843 | int extraFlags; |
| 133824 | 133844 | |
| 133825 | 133845 | assert( sqlite3_mutex_held(db->mutex) ); |
| 133826 | 133846 | if( zFunctionName==0 || |
| 133827 | - (xFunc && (xFinal || xStep)) || | |
| 133828 | - (!xFunc && (xFinal && !xStep)) || | |
| 133829 | - (!xFunc && (!xFinal && xStep)) || | |
| 133847 | + (xSFunc && (xFinal || xStep)) || | |
| 133848 | + (!xSFunc && (xFinal && !xStep)) || | |
| 133849 | + (!xSFunc && (!xFinal && xStep)) || | |
| 133830 | 133850 | (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || |
| 133831 | 133851 | (255<(nName = sqlite3Strlen30( zFunctionName))) ){ |
| 133832 | 133852 | return SQLITE_MISUSE_BKPT; |
| 133833 | 133853 | } |
| 133834 | 133854 | |
| @@ -133847,14 +133867,14 @@ | ||
| 133847 | 133867 | if( enc==SQLITE_UTF16 ){ |
| 133848 | 133868 | enc = SQLITE_UTF16NATIVE; |
| 133849 | 133869 | }else if( enc==SQLITE_ANY ){ |
| 133850 | 133870 | int rc; |
| 133851 | 133871 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags, |
| 133852 | - pUserData, xFunc, xStep, xFinal, pDestructor); | |
| 133872 | + pUserData, xSFunc, xStep, xFinal, pDestructor); | |
| 133853 | 133873 | if( rc==SQLITE_OK ){ |
| 133854 | 133874 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags, |
| 133855 | - pUserData, xFunc, xStep, xFinal, pDestructor); | |
| 133875 | + pUserData, xSFunc, xStep, xFinal, pDestructor); | |
| 133856 | 133876 | } |
| 133857 | 133877 | if( rc!=SQLITE_OK ){ |
| 133858 | 133878 | return rc; |
| 133859 | 133879 | } |
| 133860 | 133880 | enc = SQLITE_UTF16BE; |
| @@ -133894,12 +133914,11 @@ | ||
| 133894 | 133914 | pDestructor->nRef++; |
| 133895 | 133915 | } |
| 133896 | 133916 | p->pDestructor = pDestructor; |
| 133897 | 133917 | p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags; |
| 133898 | 133918 | testcase( p->funcFlags & SQLITE_DETERMINISTIC ); |
| 133899 | - p->xFunc = xFunc; | |
| 133900 | - p->xStep = xStep; | |
| 133919 | + p->xSFunc = xSFunc ? xSFunc : xStep; | |
| 133901 | 133920 | p->xFinalize = xFinal; |
| 133902 | 133921 | p->pUserData = pUserData; |
| 133903 | 133922 | p->nArg = (u16)nArg; |
| 133904 | 133923 | return SQLITE_OK; |
| 133905 | 133924 | } |
| @@ -133911,25 +133930,25 @@ | ||
| 133911 | 133930 | sqlite3 *db, |
| 133912 | 133931 | const char *zFunc, |
| 133913 | 133932 | int nArg, |
| 133914 | 133933 | int enc, |
| 133915 | 133934 | void *p, |
| 133916 | - void (*xFunc)(sqlite3_context*,int,sqlite3_value **), | |
| 133935 | + void (*xSFunc)(sqlite3_context*,int,sqlite3_value **), | |
| 133917 | 133936 | void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 133918 | 133937 | void (*xFinal)(sqlite3_context*) |
| 133919 | 133938 | ){ |
| 133920 | - return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep, | |
| 133939 | + return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xSFunc, xStep, | |
| 133921 | 133940 | xFinal, 0); |
| 133922 | 133941 | } |
| 133923 | 133942 | |
| 133924 | 133943 | SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2( |
| 133925 | 133944 | sqlite3 *db, |
| 133926 | 133945 | const char *zFunc, |
| 133927 | 133946 | int nArg, |
| 133928 | 133947 | int enc, |
| 133929 | 133948 | void *p, |
| 133930 | - void (*xFunc)(sqlite3_context*,int,sqlite3_value **), | |
| 133949 | + void (*xSFunc)(sqlite3_context*,int,sqlite3_value **), | |
| 133931 | 133950 | void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 133932 | 133951 | void (*xFinal)(sqlite3_context*), |
| 133933 | 133952 | void (*xDestroy)(void *) |
| 133934 | 133953 | ){ |
| 133935 | 133954 | int rc = SQLITE_ERROR; |
| @@ -133948,11 +133967,11 @@ | ||
| 133948 | 133967 | goto out; |
| 133949 | 133968 | } |
| 133950 | 133969 | pArg->xDestroy = xDestroy; |
| 133951 | 133970 | pArg->pUserData = p; |
| 133952 | 133971 | } |
| 133953 | - rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg); | |
| 133972 | + rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xSFunc, xStep, xFinal, pArg); | |
| 133954 | 133973 | if( pArg && pArg->nRef==0 ){ |
| 133955 | 133974 | assert( rc!=SQLITE_OK ); |
| 133956 | 133975 | xDestroy(p); |
| 133957 | 133976 | sqlite3DbFree(db, pArg); |
| 133958 | 133977 | } |
| @@ -133968,11 +133987,11 @@ | ||
| 133968 | 133987 | sqlite3 *db, |
| 133969 | 133988 | const void *zFunctionName, |
| 133970 | 133989 | int nArg, |
| 133971 | 133990 | int eTextRep, |
| 133972 | 133991 | void *p, |
| 133973 | - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), | |
| 133992 | + void (*xSFunc)(sqlite3_context*,int,sqlite3_value**), | |
| 133974 | 133993 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 133975 | 133994 | void (*xFinal)(sqlite3_context*) |
| 133976 | 133995 | ){ |
| 133977 | 133996 | int rc; |
| 133978 | 133997 | char *zFunc8; |
| @@ -133981,11 +134000,11 @@ | ||
| 133981 | 134000 | if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT; |
| 133982 | 134001 | #endif |
| 133983 | 134002 | sqlite3_mutex_enter(db->mutex); |
| 133984 | 134003 | assert( !db->mallocFailed ); |
| 133985 | 134004 | zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); |
| 133986 | - rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0); | |
| 134005 | + rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xSFunc,xStep,xFinal,0); | |
| 133987 | 134006 | sqlite3DbFree(db, zFunc8); |
| 133988 | 134007 | rc = sqlite3ApiExit(db, rc); |
| 133989 | 134008 | sqlite3_mutex_leave(db->mutex); |
| 133990 | 134009 | return rc; |
| 133991 | 134010 | } |
| @@ -135206,11 +135225,10 @@ | ||
| 135206 | 135225 | sqlite3GlobalConfig.nLookaside); |
| 135207 | 135226 | |
| 135208 | 135227 | sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| 135209 | 135228 | |
| 135210 | 135229 | opendb_out: |
| 135211 | - sqlite3_free(zOpen); | |
| 135212 | 135230 | if( db ){ |
| 135213 | 135231 | assert( db->mutex!=0 || isThreadsafe==0 |
| 135214 | 135232 | || sqlite3GlobalConfig.bFullMutex==0 ); |
| 135215 | 135233 | sqlite3_mutex_leave(db->mutex); |
| 135216 | 135234 | } |
| @@ -135243,10 +135261,11 @@ | ||
| 135243 | 135261 | } |
| 135244 | 135262 | sqlite3_key_v2(db, 0, zKey, i/2); |
| 135245 | 135263 | } |
| 135246 | 135264 | } |
| 135247 | 135265 | #endif |
| 135266 | + sqlite3_free(zOpen); | |
| 135248 | 135267 | return rc & 0xff; |
| 135249 | 135268 | } |
| 135250 | 135269 | |
| 135251 | 135270 | /* |
| 135252 | 135271 | ** Open a new database handle. |
| @@ -168108,17 +168127,17 @@ | ||
| 168108 | 168127 | ** Buffer object for the incremental building of string data. |
| 168109 | 168128 | */ |
| 168110 | 168129 | typedef struct Fts5Buffer Fts5Buffer; |
| 168111 | 168130 | struct Fts5Buffer { |
| 168112 | 168131 | u8 *p; |
| 168113 | - int n; | |
| 168114 | - int nSpace; | |
| 168132 | + u32 n; | |
| 168133 | + u32 nSpace; | |
| 168115 | 168134 | }; |
| 168116 | 168135 | |
| 168117 | -static int sqlite3Fts5BufferSize(int*, Fts5Buffer*, int); | |
| 168136 | +static int sqlite3Fts5BufferSize(int*, Fts5Buffer*, u32); | |
| 168118 | 168137 | static void sqlite3Fts5BufferAppendVarint(int*, Fts5Buffer*, i64); |
| 168119 | -static void sqlite3Fts5BufferAppendBlob(int*, Fts5Buffer*, int, const u8*); | |
| 168138 | +static void sqlite3Fts5BufferAppendBlob(int*, Fts5Buffer*, u32, const u8*); | |
| 168120 | 168139 | static void sqlite3Fts5BufferAppendString(int *, Fts5Buffer*, const char*); |
| 168121 | 168140 | static void sqlite3Fts5BufferFree(Fts5Buffer*); |
| 168122 | 168141 | static void sqlite3Fts5BufferZero(Fts5Buffer*); |
| 168123 | 168142 | static void sqlite3Fts5BufferSet(int*, Fts5Buffer*, int, const u8*); |
| 168124 | 168143 | static void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...); |
| @@ -168221,10 +168240,33 @@ | ||
| 168221 | 168240 | ** sqlite3Fts5IterNext(pIter) |
| 168222 | 168241 | ** ){ |
| 168223 | 168242 | ** i64 iRowid = sqlite3Fts5IterRowid(pIter); |
| 168224 | 168243 | ** } |
| 168225 | 168244 | */ |
| 168245 | + | |
| 168246 | +/* | |
| 168247 | +** Return a simple checksum value based on the arguments. | |
| 168248 | +*/ | |
| 168249 | +static u64 sqlite3Fts5IndexEntryCksum( | |
| 168250 | + i64 iRowid, | |
| 168251 | + int iCol, | |
| 168252 | + int iPos, | |
| 168253 | + int iIdx, | |
| 168254 | + const char *pTerm, | |
| 168255 | + int nTerm | |
| 168256 | +); | |
| 168257 | + | |
| 168258 | +/* | |
| 168259 | +** Argument p points to a buffer containing utf-8 text that is n bytes in | |
| 168260 | +** size. Return the number of bytes in the nChar character prefix of the | |
| 168261 | +** buffer, or 0 if there are less than nChar characters in total. | |
| 168262 | +*/ | |
| 168263 | +static int sqlite3Fts5IndexCharlenToBytelen( | |
| 168264 | + const char *p, | |
| 168265 | + int nByte, | |
| 168266 | + int nChar | |
| 168267 | +); | |
| 168226 | 168268 | |
| 168227 | 168269 | /* |
| 168228 | 168270 | ** Open a new iterator to iterate though all rowids that match the |
| 168229 | 168271 | ** specified token or token prefix. |
| 168230 | 168272 | */ |
| @@ -168446,11 +168488,11 @@ | ||
| 168446 | 168488 | static int sqlite3Fts5StorageRename(Fts5Storage*, const char *zName); |
| 168447 | 168489 | |
| 168448 | 168490 | static int sqlite3Fts5DropAll(Fts5Config*); |
| 168449 | 168491 | static int sqlite3Fts5CreateTable(Fts5Config*, const char*, const char*, int, char **); |
| 168450 | 168492 | |
| 168451 | -static int sqlite3Fts5StorageDelete(Fts5Storage *p, i64); | |
| 168493 | +static int sqlite3Fts5StorageDelete(Fts5Storage *p, i64, sqlite3_value**); | |
| 168452 | 168494 | static int sqlite3Fts5StorageContentInsert(Fts5Storage *p, sqlite3_value**, i64*); |
| 168453 | 168495 | static int sqlite3Fts5StorageIndexInsert(Fts5Storage *p, sqlite3_value**, i64); |
| 168454 | 168496 | |
| 168455 | 168497 | static int sqlite3Fts5StorageIntegrity(Fts5Storage *p); |
| 168456 | 168498 | |
| @@ -168466,12 +168508,10 @@ | ||
| 168466 | 168508 | |
| 168467 | 168509 | static int sqlite3Fts5StorageConfigValue( |
| 168468 | 168510 | Fts5Storage *p, const char*, sqlite3_value*, int |
| 168469 | 168511 | ); |
| 168470 | 168512 | |
| 168471 | -static int sqlite3Fts5StorageSpecialDelete(Fts5Storage *p, i64 iDel, sqlite3_value**); | |
| 168472 | - | |
| 168473 | 168513 | static int sqlite3Fts5StorageDeleteAll(Fts5Storage *p); |
| 168474 | 168514 | static int sqlite3Fts5StorageRebuild(Fts5Storage *p); |
| 168475 | 168515 | static int sqlite3Fts5StorageOptimize(Fts5Storage *p); |
| 168476 | 168516 | static int sqlite3Fts5StorageMerge(Fts5Storage *p, int nMerge); |
| 168477 | 168517 | |
| @@ -170414,12 +170454,12 @@ | ||
| 170414 | 170454 | |
| 170415 | 170455 | |
| 170416 | 170456 | |
| 170417 | 170457 | /* #include "fts5Int.h" */ |
| 170418 | 170458 | |
| 170419 | -static int sqlite3Fts5BufferSize(int *pRc, Fts5Buffer *pBuf, int nByte){ | |
| 170420 | - int nNew = pBuf->nSpace ? pBuf->nSpace*2 : 64; | |
| 170459 | +static int sqlite3Fts5BufferSize(int *pRc, Fts5Buffer *pBuf, u32 nByte){ | |
| 170460 | + u32 nNew = pBuf->nSpace ? pBuf->nSpace*2 : 64; | |
| 170421 | 170461 | u8 *pNew; |
| 170422 | 170462 | while( nNew<nByte ){ |
| 170423 | 170463 | nNew = nNew * 2; |
| 170424 | 170464 | } |
| 170425 | 170465 | pNew = sqlite3_realloc(pBuf->p, nNew); |
| @@ -170460,14 +170500,14 @@ | ||
| 170460 | 170500 | ** is called, it is a no-op. |
| 170461 | 170501 | */ |
| 170462 | 170502 | static void sqlite3Fts5BufferAppendBlob( |
| 170463 | 170503 | int *pRc, |
| 170464 | 170504 | Fts5Buffer *pBuf, |
| 170465 | - int nData, | |
| 170505 | + u32 nData, | |
| 170466 | 170506 | const u8 *pData |
| 170467 | 170507 | ){ |
| 170468 | - assert( *pRc || nData>=0 ); | |
| 170508 | + assert_nc( *pRc || nData>=0 ); | |
| 170469 | 170509 | if( fts5BufferGrow(pRc, pBuf, nData) ) return; |
| 170470 | 170510 | memcpy(&pBuf->p[pBuf->n], pData, nData); |
| 170471 | 170511 | pBuf->n += nData; |
| 170472 | 170512 | } |
| 170473 | 170513 | |
| @@ -170721,18 +170761,21 @@ | ||
| 170721 | 170761 | ){ |
| 170722 | 170762 | int rc = SQLITE_OK; |
| 170723 | 170763 | *pbPresent = 0; |
| 170724 | 170764 | if( p ){ |
| 170725 | 170765 | int i; |
| 170726 | - int hash; | |
| 170766 | + int hash = 13; | |
| 170727 | 170767 | Fts5TermsetEntry *pEntry; |
| 170728 | 170768 | |
| 170729 | - /* Calculate a hash value for this term */ | |
| 170730 | - hash = 104 + iIdx; | |
| 170731 | - for(i=0; i<nTerm; i++){ | |
| 170732 | - hash += (hash << 3) + (int)pTerm[i]; | |
| 170769 | + /* Calculate a hash value for this term. This is the same hash checksum | |
| 170770 | + ** used by the fts5_hash.c module. This is not important for correct | |
| 170771 | + ** operation of the module, but is necessary to ensure that some tests | |
| 170772 | + ** designed to produce hash table collisions really do work. */ | |
| 170773 | + for(i=nTerm-1; i>=0; i--){ | |
| 170774 | + hash = (hash << 3) ^ hash ^ pTerm[i]; | |
| 170733 | 170775 | } |
| 170776 | + hash = (hash << 3) ^ hash ^ iIdx; | |
| 170734 | 170777 | hash = hash % ArraySize(p->apHash); |
| 170735 | 170778 | |
| 170736 | 170779 | for(pEntry=p->apHash[hash]; pEntry; pEntry=pEntry->pNext){ |
| 170737 | 170780 | if( pEntry->iIdx==iIdx |
| 170738 | 170781 | && pEntry->nTerm==nTerm |
| @@ -171055,11 +171098,11 @@ | ||
| 171055 | 171098 | while( p[0]>='0' && p[0]<='9' && nPre<1000 ){ |
| 171056 | 171099 | nPre = nPre*10 + (p[0] - '0'); |
| 171057 | 171100 | p++; |
| 171058 | 171101 | } |
| 171059 | 171102 | |
| 171060 | - if( rc==SQLITE_OK && (nPre<=0 || nPre>=1000) ){ | |
| 171103 | + if( nPre<=0 || nPre>=1000 ){ | |
| 171061 | 171104 | *pzErr = sqlite3_mprintf("prefix length out of range (max 999)"); |
| 171062 | 171105 | rc = SQLITE_ERROR; |
| 171063 | 171106 | break; |
| 171064 | 171107 | } |
| 171065 | 171108 | |
| @@ -172558,11 +172601,11 @@ | ||
| 172558 | 172601 | assert( pNode->eType==FTS5_TERM ); |
| 172559 | 172602 | assert( pNear->nPhrase==1 && pPhrase->nTerm==1 ); |
| 172560 | 172603 | assert( pPhrase->aTerm[0].pSynonym==0 ); |
| 172561 | 172604 | |
| 172562 | 172605 | rc = sqlite3Fts5IterPoslist(pIter, pColset, |
| 172563 | - (const u8**)&pPhrase->poslist.p, &pPhrase->poslist.n, &pNode->iRowid | |
| 172606 | + (const u8**)&pPhrase->poslist.p, (int*)&pPhrase->poslist.n, &pNode->iRowid | |
| 172564 | 172607 | ); |
| 172565 | 172608 | pNode->bNomatch = (pPhrase->poslist.n==0); |
| 172566 | 172609 | return rc; |
| 172567 | 172610 | } |
| 172568 | 172611 | |
| @@ -174120,11 +174163,11 @@ | ||
| 174120 | 174163 | aPopulator[i].bOk = 1; |
| 174121 | 174164 | } |
| 174122 | 174165 | } |
| 174123 | 174166 | |
| 174124 | 174167 | return sqlite3Fts5Tokenize(pConfig, |
| 174125 | - FTS5_TOKENIZE_AUX, z, n, (void*)&sCtx, fts5ExprPopulatePoslistsCb | |
| 174168 | + FTS5_TOKENIZE_DOCUMENT, z, n, (void*)&sCtx, fts5ExprPopulatePoslistsCb | |
| 174126 | 174169 | ); |
| 174127 | 174170 | } |
| 174128 | 174171 | |
| 174129 | 174172 | static void fts5ExprClearPoslists(Fts5ExprNode *pNode){ |
| 174130 | 174173 | if( pNode->eType==FTS5_TERM || pNode->eType==FTS5_STRING ){ |
| @@ -174136,53 +174179,48 @@ | ||
| 174136 | 174179 | } |
| 174137 | 174180 | } |
| 174138 | 174181 | } |
| 174139 | 174182 | |
| 174140 | 174183 | static int fts5ExprCheckPoslists(Fts5ExprNode *pNode, i64 iRowid){ |
| 174141 | - if( pNode ){ | |
| 174142 | - pNode->iRowid = iRowid; | |
| 174143 | - pNode->bEof = 0; | |
| 174144 | - switch( pNode->eType ){ | |
| 174145 | - case FTS5_TERM: | |
| 174146 | - case FTS5_STRING: | |
| 174147 | - return (pNode->pNear->apPhrase[0]->poslist.n>0); | |
| 174148 | - | |
| 174149 | - case FTS5_AND: { | |
| 174150 | - int i; | |
| 174151 | - for(i=0; i<pNode->nChild; i++){ | |
| 174152 | - if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid)==0 ){ | |
| 174153 | - fts5ExprClearPoslists(pNode); | |
| 174154 | - return 0; | |
| 174155 | - } | |
| 174156 | - } | |
| 174157 | - break; | |
| 174158 | - } | |
| 174159 | - | |
| 174160 | - case FTS5_OR: { | |
| 174161 | - int i; | |
| 174162 | - int bRet = 0; | |
| 174163 | - for(i=0; i<pNode->nChild; i++){ | |
| 174164 | - if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid) ){ | |
| 174165 | - bRet = 1; | |
| 174166 | - } | |
| 174167 | - } | |
| 174168 | - if( bRet==0 ){ | |
| 174169 | - fts5ExprClearPoslists(pNode); | |
| 174170 | - } | |
| 174171 | - return bRet; | |
| 174172 | - } | |
| 174173 | - | |
| 174174 | - default: { | |
| 174175 | - assert( pNode->eType==FTS5_NOT ); | |
| 174176 | - if( 0==fts5ExprCheckPoslists(pNode->apChild[0], iRowid) | |
| 174177 | - || 0!=fts5ExprCheckPoslists(pNode->apChild[1], iRowid) | |
| 174178 | - ){ | |
| 174179 | - fts5ExprClearPoslists(pNode); | |
| 174180 | - return 0; | |
| 174181 | - } | |
| 174182 | - break; | |
| 174183 | - } | |
| 174184 | + pNode->iRowid = iRowid; | |
| 174185 | + pNode->bEof = 0; | |
| 174186 | + switch( pNode->eType ){ | |
| 174187 | + case FTS5_TERM: | |
| 174188 | + case FTS5_STRING: | |
| 174189 | + return (pNode->pNear->apPhrase[0]->poslist.n>0); | |
| 174190 | + | |
| 174191 | + case FTS5_AND: { | |
| 174192 | + int i; | |
| 174193 | + for(i=0; i<pNode->nChild; i++){ | |
| 174194 | + if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid)==0 ){ | |
| 174195 | + fts5ExprClearPoslists(pNode); | |
| 174196 | + return 0; | |
| 174197 | + } | |
| 174198 | + } | |
| 174199 | + break; | |
| 174200 | + } | |
| 174201 | + | |
| 174202 | + case FTS5_OR: { | |
| 174203 | + int i; | |
| 174204 | + int bRet = 0; | |
| 174205 | + for(i=0; i<pNode->nChild; i++){ | |
| 174206 | + if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid) ){ | |
| 174207 | + bRet = 1; | |
| 174208 | + } | |
| 174209 | + } | |
| 174210 | + return bRet; | |
| 174211 | + } | |
| 174212 | + | |
| 174213 | + default: { | |
| 174214 | + assert( pNode->eType==FTS5_NOT ); | |
| 174215 | + if( 0==fts5ExprCheckPoslists(pNode->apChild[0], iRowid) | |
| 174216 | + || 0!=fts5ExprCheckPoslists(pNode->apChild[1], iRowid) | |
| 174217 | + ){ | |
| 174218 | + fts5ExprClearPoslists(pNode); | |
| 174219 | + return 0; | |
| 174220 | + } | |
| 174221 | + break; | |
| 174184 | 174222 | } |
| 174185 | 174223 | } |
| 174186 | 174224 | return 1; |
| 174187 | 174225 | } |
| 174188 | 174226 | |
| @@ -176647,17 +176685,19 @@ | ||
| 176647 | 176685 | ){ |
| 176648 | 176686 | Fts5Data *pLeaf = pIter->pLeaf; |
| 176649 | 176687 | int iOff; |
| 176650 | 176688 | int bNewTerm = 0; |
| 176651 | 176689 | int nKeep = 0; |
| 176690 | + u8 *a; | |
| 176691 | + int n; | |
| 176652 | 176692 | |
| 176653 | 176693 | assert( pbNewTerm==0 || *pbNewTerm==0 ); |
| 176654 | 176694 | assert( p->pConfig->eDetail!=FTS5_DETAIL_NONE ); |
| 176655 | 176695 | |
| 176656 | 176696 | /* Search for the end of the position list within the current page. */ |
| 176657 | - u8 *a = pLeaf->p; | |
| 176658 | - int n = pLeaf->szLeaf; | |
| 176697 | + a = pLeaf->p; | |
| 176698 | + n = pLeaf->szLeaf; | |
| 176659 | 176699 | |
| 176660 | 176700 | ASSERT_SZLEAF_OK(pLeaf); |
| 176661 | 176701 | iOff = pIter->iLeafOffset + pIter->nPos; |
| 176662 | 176702 | |
| 176663 | 176703 | if( iOff<n ){ |
| @@ -180673,10 +180713,51 @@ | ||
| 180673 | 180713 | } |
| 180674 | 180714 | } |
| 180675 | 180715 | |
| 180676 | 180716 | return iOff; |
| 180677 | 180717 | } |
| 180718 | + | |
| 180719 | +/* | |
| 180720 | +** This function is part of the fts5_decode() debugging function. It is | |
| 180721 | +** only ever used with detail=none tables. | |
| 180722 | +** | |
| 180723 | +** Buffer (pData/nData) contains a doclist in the format used by detail=none | |
| 180724 | +** tables. This function appends a human-readable version of that list to | |
| 180725 | +** buffer pBuf. | |
| 180726 | +** | |
| 180727 | +** If *pRc is other than SQLITE_OK when this function is called, it is a | |
| 180728 | +** no-op. If an OOM or other error occurs within this function, *pRc is | |
| 180729 | +** set to an SQLite error code before returning. The final state of buffer | |
| 180730 | +** pBuf is undefined in this case. | |
| 180731 | +*/ | |
| 180732 | +static void fts5DecodeRowidList( | |
| 180733 | + int *pRc, /* IN/OUT: Error code */ | |
| 180734 | + Fts5Buffer *pBuf, /* Buffer to append text to */ | |
| 180735 | + const u8 *pData, int nData /* Data to decode list-of-rowids from */ | |
| 180736 | +){ | |
| 180737 | + int i = 0; | |
| 180738 | + i64 iRowid = 0; | |
| 180739 | + | |
| 180740 | + while( i<nData ){ | |
| 180741 | + const char *zApp = ""; | |
| 180742 | + u64 iVal; | |
| 180743 | + i += sqlite3Fts5GetVarint(&pData[i], &iVal); | |
| 180744 | + iRowid += iVal; | |
| 180745 | + | |
| 180746 | + if( i<nData && pData[i]==0x00 ){ | |
| 180747 | + i++; | |
| 180748 | + if( i<nData && pData[i]==0x00 ){ | |
| 180749 | + i++; | |
| 180750 | + zApp = "+"; | |
| 180751 | + }else{ | |
| 180752 | + zApp = "*"; | |
| 180753 | + } | |
| 180754 | + } | |
| 180755 | + | |
| 180756 | + sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %lld%s", iRowid, zApp); | |
| 180757 | + } | |
| 180758 | +} | |
| 180678 | 180759 | |
| 180679 | 180760 | /* |
| 180680 | 180761 | ** The implementation of user-defined scalar function fts5_decode(). |
| 180681 | 180762 | */ |
| 180682 | 180763 | static void fts5DecodeFunction( |
| @@ -180689,10 +180770,11 @@ | ||
| 180689 | 180770 | const u8 *aBlob; int n; /* Record to decode */ |
| 180690 | 180771 | u8 *a = 0; |
| 180691 | 180772 | Fts5Buffer s; /* Build up text to return here */ |
| 180692 | 180773 | int rc = SQLITE_OK; /* Return code */ |
| 180693 | 180774 | int nSpace = 0; |
| 180775 | + int eDetailNone = (sqlite3_user_data(pCtx)!=0); | |
| 180694 | 180776 | |
| 180695 | 180777 | assert( nArg==2 ); |
| 180696 | 180778 | memset(&s, 0, sizeof(Fts5Buffer)); |
| 180697 | 180779 | iRowid = sqlite3_value_int64(apVal[0]); |
| 180698 | 180780 | |
| @@ -180730,10 +180812,58 @@ | ||
| 180730 | 180812 | if( iRowid==FTS5_AVERAGES_ROWID ){ |
| 180731 | 180813 | fts5DecodeAverages(&rc, &s, a, n); |
| 180732 | 180814 | }else{ |
| 180733 | 180815 | fts5DecodeStructure(&rc, &s, a, n); |
| 180734 | 180816 | } |
| 180817 | + }else if( eDetailNone ){ | |
| 180818 | + Fts5Buffer term; /* Current term read from page */ | |
| 180819 | + int szLeaf; | |
| 180820 | + int iPgidxOff = szLeaf = fts5GetU16(&a[2]); | |
| 180821 | + int iTermOff; | |
| 180822 | + int nKeep = 0; | |
| 180823 | + int iOff; | |
| 180824 | + | |
| 180825 | + memset(&term, 0, sizeof(Fts5Buffer)); | |
| 180826 | + | |
| 180827 | + /* Decode any entries that occur before the first term. */ | |
| 180828 | + if( szLeaf<n ){ | |
| 180829 | + iPgidxOff += fts5GetVarint32(&a[iPgidxOff], iTermOff); | |
| 180830 | + }else{ | |
| 180831 | + iTermOff = szLeaf; | |
| 180832 | + } | |
| 180833 | + fts5DecodeRowidList(&rc, &s, &a[4], iTermOff-4); | |
| 180834 | + | |
| 180835 | + iOff = iTermOff; | |
| 180836 | + while( iOff<szLeaf ){ | |
| 180837 | + int nAppend; | |
| 180838 | + | |
| 180839 | + /* Read the term data for the next term*/ | |
| 180840 | + iOff += fts5GetVarint32(&a[iOff], nAppend); | |
| 180841 | + term.n = nKeep; | |
| 180842 | + fts5BufferAppendBlob(&rc, &term, nAppend, &a[iOff]); | |
| 180843 | + sqlite3Fts5BufferAppendPrintf( | |
| 180844 | + &rc, &s, " term=%.*s", term.n, (const char*)term.p | |
| 180845 | + ); | |
| 180846 | + iOff += nAppend; | |
| 180847 | + | |
| 180848 | + /* Figure out where the doclist for this term ends */ | |
| 180849 | + if( iPgidxOff<n ){ | |
| 180850 | + int nIncr; | |
| 180851 | + iPgidxOff += fts5GetVarint32(&a[iPgidxOff], nIncr); | |
| 180852 | + iTermOff += nIncr; | |
| 180853 | + }else{ | |
| 180854 | + iTermOff = szLeaf; | |
| 180855 | + } | |
| 180856 | + | |
| 180857 | + fts5DecodeRowidList(&rc, &s, &a[iOff], iTermOff-iOff); | |
| 180858 | + iOff = iTermOff; | |
| 180859 | + if( iOff<szLeaf ){ | |
| 180860 | + iOff += fts5GetVarint32(&a[iOff], nKeep); | |
| 180861 | + } | |
| 180862 | + } | |
| 180863 | + | |
| 180864 | + fts5BufferFree(&term); | |
| 180735 | 180865 | }else{ |
| 180736 | 180866 | Fts5Buffer term; /* Current term read from page */ |
| 180737 | 180867 | int szLeaf; /* Offset of pgidx in a[] */ |
| 180738 | 180868 | int iPgidxOff; |
| 180739 | 180869 | int iPgidxPrev = 0; /* Previous value read from pgidx */ |
| @@ -180857,18 +180987,25 @@ | ||
| 180857 | 180987 | */ |
| 180858 | 180988 | static int sqlite3Fts5IndexInit(sqlite3 *db){ |
| 180859 | 180989 | int rc = sqlite3_create_function( |
| 180860 | 180990 | db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0 |
| 180861 | 180991 | ); |
| 180992 | + | |
| 180993 | + if( rc==SQLITE_OK ){ | |
| 180994 | + rc = sqlite3_create_function( | |
| 180995 | + db, "fts5_decode_none", 2, | |
| 180996 | + SQLITE_UTF8, (void*)db, fts5DecodeFunction, 0, 0 | |
| 180997 | + ); | |
| 180998 | + } | |
| 180999 | + | |
| 180862 | 181000 | if( rc==SQLITE_OK ){ |
| 180863 | 181001 | rc = sqlite3_create_function( |
| 180864 | 181002 | db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0 |
| 180865 | 181003 | ); |
| 180866 | 181004 | } |
| 180867 | 181005 | return rc; |
| 180868 | 181006 | } |
| 180869 | - | |
| 180870 | 181007 | |
| 180871 | 181008 | /* |
| 180872 | 181009 | ** 2014 Jun 09 |
| 180873 | 181010 | ** |
| 180874 | 181011 | ** The author disclaims copyright to this source code. In place of |
| @@ -181712,45 +181849,44 @@ | ||
| 181712 | 181849 | |
| 181713 | 181850 | return rc; |
| 181714 | 181851 | } |
| 181715 | 181852 | |
| 181716 | 181853 | |
| 181717 | -static sqlite3_stmt *fts5PrepareStatement( | |
| 181718 | - int *pRc, | |
| 181854 | +static int fts5PrepareStatement( | |
| 181855 | + sqlite3_stmt **ppStmt, | |
| 181719 | 181856 | Fts5Config *pConfig, |
| 181720 | 181857 | const char *zFmt, |
| 181721 | 181858 | ... |
| 181722 | 181859 | ){ |
| 181723 | 181860 | sqlite3_stmt *pRet = 0; |
| 181861 | + int rc; | |
| 181862 | + char *zSql; | |
| 181724 | 181863 | va_list ap; |
| 181864 | + | |
| 181725 | 181865 | va_start(ap, zFmt); |
| 181726 | - | |
| 181727 | - if( *pRc==SQLITE_OK ){ | |
| 181728 | - int rc; | |
| 181729 | - char *zSql = sqlite3_vmprintf(zFmt, ap); | |
| 181730 | - if( zSql==0 ){ | |
| 181731 | - rc = SQLITE_NOMEM; | |
| 181732 | - }else{ | |
| 181733 | - rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pRet, 0); | |
| 181734 | - if( rc!=SQLITE_OK ){ | |
| 181735 | - *pConfig->pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(pConfig->db)); | |
| 181736 | - } | |
| 181737 | - sqlite3_free(zSql); | |
| 181738 | - } | |
| 181739 | - *pRc = rc; | |
| 181866 | + zSql = sqlite3_vmprintf(zFmt, ap); | |
| 181867 | + if( zSql==0 ){ | |
| 181868 | + rc = SQLITE_NOMEM; | |
| 181869 | + }else{ | |
| 181870 | + rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pRet, 0); | |
| 181871 | + if( rc!=SQLITE_OK ){ | |
| 181872 | + *pConfig->pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(pConfig->db)); | |
| 181873 | + } | |
| 181874 | + sqlite3_free(zSql); | |
| 181740 | 181875 | } |
| 181741 | 181876 | |
| 181742 | 181877 | va_end(ap); |
| 181743 | - return pRet; | |
| 181878 | + *ppStmt = pRet; | |
| 181879 | + return rc; | |
| 181744 | 181880 | } |
| 181745 | 181881 | |
| 181746 | 181882 | static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){ |
| 181747 | 181883 | Fts5Config *pConfig = pTab->pConfig; |
| 181748 | 181884 | Fts5Sorter *pSorter; |
| 181749 | 181885 | int nPhrase; |
| 181750 | 181886 | int nByte; |
| 181751 | - int rc = SQLITE_OK; | |
| 181887 | + int rc; | |
| 181752 | 181888 | const char *zRank = pCsr->zRank; |
| 181753 | 181889 | const char *zRankArgs = pCsr->zRankArgs; |
| 181754 | 181890 | |
| 181755 | 181891 | nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr); |
| 181756 | 181892 | nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1); |
| @@ -181764,11 +181900,11 @@ | ||
| 181764 | 181900 | ** is not possible as SQLite reference counts the virtual table objects. |
| 181765 | 181901 | ** And since the statement required here reads from this very virtual |
| 181766 | 181902 | ** table, saving it creates a circular reference. |
| 181767 | 181903 | ** |
| 181768 | 181904 | ** If SQLite a built-in statement cache, this wouldn't be a problem. */ |
| 181769 | - pSorter->pStmt = fts5PrepareStatement(&rc, pConfig, | |
| 181905 | + rc = fts5PrepareStatement(&pSorter->pStmt, pConfig, | |
| 181770 | 181906 | "SELECT rowid, rank FROM %Q.%Q ORDER BY %s(%s%s%s) %s", |
| 181771 | 181907 | pConfig->zDb, pConfig->zName, zRank, pConfig->zName, |
| 181772 | 181908 | (zRankArgs ? ", " : ""), |
| 181773 | 181909 | (zRankArgs ? zRankArgs : ""), |
| 181774 | 181910 | bDesc ? "DESC" : "ASC" |
| @@ -182273,11 +182409,11 @@ | ||
| 182273 | 182409 | ){ |
| 182274 | 182410 | int rc = SQLITE_OK; |
| 182275 | 182411 | int eType1 = sqlite3_value_type(apVal[1]); |
| 182276 | 182412 | if( eType1==SQLITE_INTEGER ){ |
| 182277 | 182413 | sqlite3_int64 iDel = sqlite3_value_int64(apVal[1]); |
| 182278 | - rc = sqlite3Fts5StorageSpecialDelete(pTab->pStorage, iDel, &apVal[2]); | |
| 182414 | + rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, &apVal[2]); | |
| 182279 | 182415 | } |
| 182280 | 182416 | return rc; |
| 182281 | 182417 | } |
| 182282 | 182418 | |
| 182283 | 182419 | static void fts5StorageInsert( |
| @@ -182380,21 +182516,21 @@ | ||
| 182380 | 182516 | } |
| 182381 | 182517 | |
| 182382 | 182518 | /* Case 1: DELETE */ |
| 182383 | 182519 | else if( nArg==1 ){ |
| 182384 | 182520 | i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */ |
| 182385 | - rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel); | |
| 182521 | + rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0); | |
| 182386 | 182522 | } |
| 182387 | 182523 | |
| 182388 | 182524 | /* Case 2: INSERT */ |
| 182389 | 182525 | else if( eType0!=SQLITE_INTEGER ){ |
| 182390 | 182526 | /* If this is a REPLACE, first remove the current entry (if any) */ |
| 182391 | 182527 | if( eConflict==SQLITE_REPLACE |
| 182392 | 182528 | && sqlite3_value_type(apVal[1])==SQLITE_INTEGER |
| 182393 | 182529 | ){ |
| 182394 | 182530 | i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */ |
| 182395 | - rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew); | |
| 182531 | + rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0); | |
| 182396 | 182532 | } |
| 182397 | 182533 | fts5StorageInsert(&rc, pTab, apVal, pRowid); |
| 182398 | 182534 | } |
| 182399 | 182535 | |
| 182400 | 182536 | /* Case 2: UPDATE */ |
| @@ -182401,26 +182537,26 @@ | ||
| 182401 | 182537 | else{ |
| 182402 | 182538 | i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */ |
| 182403 | 182539 | i64 iNew = sqlite3_value_int64(apVal[1]); /* New rowid */ |
| 182404 | 182540 | if( iOld!=iNew ){ |
| 182405 | 182541 | if( eConflict==SQLITE_REPLACE ){ |
| 182406 | - rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld); | |
| 182542 | + rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0); | |
| 182407 | 182543 | if( rc==SQLITE_OK ){ |
| 182408 | - rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew); | |
| 182544 | + rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0); | |
| 182409 | 182545 | } |
| 182410 | 182546 | fts5StorageInsert(&rc, pTab, apVal, pRowid); |
| 182411 | 182547 | }else{ |
| 182412 | 182548 | rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, pRowid); |
| 182413 | 182549 | if( rc==SQLITE_OK ){ |
| 182414 | - rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld); | |
| 182550 | + rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0); | |
| 182415 | 182551 | } |
| 182416 | 182552 | if( rc==SQLITE_OK ){ |
| 182417 | 182553 | rc = sqlite3Fts5StorageIndexInsert(pTab->pStorage, apVal, *pRowid); |
| 182418 | 182554 | } |
| 182419 | 182555 | } |
| 182420 | 182556 | }else{ |
| 182421 | - rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld); | |
| 182557 | + rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0); | |
| 182422 | 182558 | fts5StorageInsert(&rc, pTab, apVal, pRowid); |
| 182423 | 182559 | } |
| 182424 | 182560 | } |
| 182425 | 182561 | } |
| 182426 | 182562 | |
| @@ -182615,11 +182751,13 @@ | ||
| 182615 | 182751 | /* Initialize all iterators */ |
| 182616 | 182752 | for(i=0; i<nIter && rc==SQLITE_OK; i++){ |
| 182617 | 182753 | const u8 *a; |
| 182618 | 182754 | int n; |
| 182619 | 182755 | rc = fts5CsrPoslist(pCsr, i, &a, &n); |
| 182620 | - sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]); | |
| 182756 | + if( rc==SQLITE_OK ){ | |
| 182757 | + sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]); | |
| 182758 | + } | |
| 182621 | 182759 | } |
| 182622 | 182760 | |
| 182623 | 182761 | if( rc==SQLITE_OK ){ |
| 182624 | 182762 | while( 1 ){ |
| 182625 | 182763 | int *aInst; |
| @@ -182905,12 +183043,19 @@ | ||
| 182905 | 183043 | int rc = SQLITE_OK; |
| 182906 | 183044 | Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; |
| 182907 | 183045 | Fts5Config *pConfig = ((Fts5Table*)(pCsr->base.pVtab))->pConfig; |
| 182908 | 183046 | |
| 182909 | 183047 | if( pConfig->eDetail==FTS5_DETAIL_COLUMNS ){ |
| 183048 | + Fts5Sorter *pSorter = pCsr->pSorter; | |
| 182910 | 183049 | int n; |
| 182911 | - rc = sqlite3Fts5ExprPhraseCollist(pCsr->pExpr, iPhrase, &pIter->a, &n); | |
| 183050 | + if( pSorter ){ | |
| 183051 | + int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]); | |
| 183052 | + n = pSorter->aIdx[iPhrase] - i1; | |
| 183053 | + pIter->a = &pSorter->aPoslist[i1]; | |
| 183054 | + }else{ | |
| 183055 | + rc = sqlite3Fts5ExprPhraseCollist(pCsr->pExpr, iPhrase, &pIter->a, &n); | |
| 183056 | + } | |
| 182912 | 183057 | if( rc==SQLITE_OK ){ |
| 182913 | 183058 | pIter->b = &pIter->a[n]; |
| 182914 | 183059 | *piCol = 0; |
| 182915 | 183060 | fts5ApiPhraseNextColumn(pCtx, pIter, piCol); |
| 182916 | 183061 | } |
| @@ -183451,11 +183596,11 @@ | ||
| 183451 | 183596 | sqlite3_context *pCtx, /* Function call context */ |
| 183452 | 183597 | int nArg, /* Number of args */ |
| 183453 | 183598 | sqlite3_value **apVal /* Function arguments */ |
| 183454 | 183599 | ){ |
| 183455 | 183600 | assert( nArg==0 ); |
| 183456 | - sqlite3_result_text(pCtx, "fts5: 2016-01-14 14:19:50 d17bc2c92f4d086280e49a3cc72993be7fee2da7", -1, SQLITE_TRANSIENT); | |
| 183601 | + sqlite3_result_text(pCtx, "fts5: 2016-01-18 17:48:28 acaf426449bf6fd3140fd63141750ff69d1119a5", -1, SQLITE_TRANSIENT); | |
| 183457 | 183602 | } |
| 183458 | 183603 | |
| 183459 | 183604 | static int fts5Init(sqlite3 *db){ |
| 183460 | 183605 | static const sqlite3_module fts5Mod = { |
| 183461 | 183606 | /* iVersion */ 2, |
| @@ -183936,43 +184081,56 @@ | ||
| 183936 | 184081 | /* |
| 183937 | 184082 | ** If a row with rowid iDel is present in the %_content table, add the |
| 183938 | 184083 | ** delete-markers to the FTS index necessary to delete it. Do not actually |
| 183939 | 184084 | ** remove the %_content row at this time though. |
| 183940 | 184085 | */ |
| 183941 | -static int fts5StorageDeleteFromIndex(Fts5Storage *p, i64 iDel){ | |
| 184086 | +static int fts5StorageDeleteFromIndex( | |
| 184087 | + Fts5Storage *p, | |
| 184088 | + i64 iDel, | |
| 184089 | + sqlite3_value **apVal | |
| 184090 | +){ | |
| 183942 | 184091 | Fts5Config *pConfig = p->pConfig; |
| 183943 | - sqlite3_stmt *pSeek; /* SELECT to read row iDel from %_data */ | |
| 184092 | + sqlite3_stmt *pSeek = 0; /* SELECT to read row iDel from %_data */ | |
| 183944 | 184093 | int rc; /* Return code */ |
| 184094 | + int rc2; /* sqlite3_reset() return code */ | |
| 184095 | + int iCol; | |
| 184096 | + Fts5InsertCtx ctx; | |
| 183945 | 184097 | |
| 183946 | - rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP, &pSeek, 0); | |
| 183947 | - if( rc==SQLITE_OK ){ | |
| 183948 | - int rc2; | |
| 184098 | + if( apVal==0 ){ | |
| 184099 | + rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP, &pSeek, 0); | |
| 184100 | + if( rc!=SQLITE_OK ) return rc; | |
| 183949 | 184101 | sqlite3_bind_int64(pSeek, 1, iDel); |
| 183950 | - if( sqlite3_step(pSeek)==SQLITE_ROW ){ | |
| 183951 | - int iCol; | |
| 183952 | - Fts5InsertCtx ctx; | |
| 183953 | - ctx.pStorage = p; | |
| 183954 | - ctx.iCol = -1; | |
| 183955 | - rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel); | |
| 183956 | - for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){ | |
| 183957 | - if( pConfig->abUnindexed[iCol-1] ) continue; | |
| 183958 | - ctx.szCol = 0; | |
| 183959 | - rc = sqlite3Fts5Tokenize(pConfig, | |
| 183960 | - FTS5_TOKENIZE_DOCUMENT, | |
| 183961 | - (const char*)sqlite3_column_text(pSeek, iCol), | |
| 183962 | - sqlite3_column_bytes(pSeek, iCol), | |
| 183963 | - (void*)&ctx, | |
| 183964 | - fts5StorageInsertCallback | |
| 183965 | - ); | |
| 183966 | - p->aTotalSize[iCol-1] -= (i64)ctx.szCol; | |
| 183967 | - } | |
| 183968 | - p->nTotalRow--; | |
| 183969 | - } | |
| 183970 | - rc2 = sqlite3_reset(pSeek); | |
| 183971 | - if( rc==SQLITE_OK ) rc = rc2; | |
| 183972 | - } | |
| 183973 | - | |
| 184102 | + if( sqlite3_step(pSeek)!=SQLITE_ROW ){ | |
| 184103 | + return sqlite3_reset(pSeek); | |
| 184104 | + } | |
| 184105 | + } | |
| 184106 | + | |
| 184107 | + ctx.pStorage = p; | |
| 184108 | + ctx.iCol = -1; | |
| 184109 | + rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel); | |
| 184110 | + for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){ | |
| 184111 | + if( pConfig->abUnindexed[iCol-1]==0 ){ | |
| 184112 | + const char *zText; | |
| 184113 | + int nText; | |
| 184114 | + if( pSeek ){ | |
| 184115 | + zText = (const char*)sqlite3_column_text(pSeek, iCol); | |
| 184116 | + nText = sqlite3_column_bytes(pSeek, iCol); | |
| 184117 | + }else{ | |
| 184118 | + zText = (const char*)sqlite3_value_text(apVal[iCol-1]); | |
| 184119 | + nText = sqlite3_value_bytes(apVal[iCol-1]); | |
| 184120 | + } | |
| 184121 | + ctx.szCol = 0; | |
| 184122 | + rc = sqlite3Fts5Tokenize(pConfig, FTS5_TOKENIZE_DOCUMENT, | |
| 184123 | + zText, nText, (void*)&ctx, fts5StorageInsertCallback | |
| 184124 | + ); | |
| 184125 | + p->aTotalSize[iCol-1] -= (i64)ctx.szCol; | |
| 184126 | + } | |
| 184127 | + } | |
| 184128 | + p->nTotalRow--; | |
| 184129 | + | |
| 184130 | + rc2 = sqlite3_reset(pSeek); | |
| 184131 | + if( rc==SQLITE_OK ) rc = rc2; | |
| 183974 | 184132 | return rc; |
| 183975 | 184133 | } |
| 183976 | 184134 | |
| 183977 | 184135 | |
| 183978 | 184136 | /* |
| @@ -184048,20 +184206,21 @@ | ||
| 184048 | 184206 | } |
| 184049 | 184207 | |
| 184050 | 184208 | /* |
| 184051 | 184209 | ** Remove a row from the FTS table. |
| 184052 | 184210 | */ |
| 184053 | -static int sqlite3Fts5StorageDelete(Fts5Storage *p, i64 iDel){ | |
| 184211 | +static int sqlite3Fts5StorageDelete(Fts5Storage *p, i64 iDel, sqlite3_value **apVal){ | |
| 184054 | 184212 | Fts5Config *pConfig = p->pConfig; |
| 184055 | 184213 | int rc; |
| 184056 | 184214 | sqlite3_stmt *pDel = 0; |
| 184057 | 184215 | |
| 184216 | + assert( pConfig->eContent!=FTS5_CONTENT_NORMAL || apVal==0 ); | |
| 184058 | 184217 | rc = fts5StorageLoadTotals(p, 1); |
| 184059 | 184218 | |
| 184060 | 184219 | /* Delete the index records */ |
| 184061 | 184220 | if( rc==SQLITE_OK ){ |
| 184062 | - rc = fts5StorageDeleteFromIndex(p, iDel); | |
| 184221 | + rc = fts5StorageDeleteFromIndex(p, iDel, apVal); | |
| 184063 | 184222 | } |
| 184064 | 184223 | |
| 184065 | 184224 | /* Delete the %_docsize record */ |
| 184066 | 184225 | if( rc==SQLITE_OK && pConfig->bColumnsize ){ |
| 184067 | 184226 | rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_DOCSIZE, &pDel, 0); |
| @@ -184075,65 +184234,10 @@ | ||
| 184075 | 184234 | /* Delete the %_content record */ |
| 184076 | 184235 | if( pConfig->eContent==FTS5_CONTENT_NORMAL ){ |
| 184077 | 184236 | if( rc==SQLITE_OK ){ |
| 184078 | 184237 | rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_CONTENT, &pDel, 0); |
| 184079 | 184238 | } |
| 184080 | - if( rc==SQLITE_OK ){ | |
| 184081 | - sqlite3_bind_int64(pDel, 1, iDel); | |
| 184082 | - sqlite3_step(pDel); | |
| 184083 | - rc = sqlite3_reset(pDel); | |
| 184084 | - } | |
| 184085 | - } | |
| 184086 | - | |
| 184087 | - /* Write the averages record */ | |
| 184088 | - if( rc==SQLITE_OK ){ | |
| 184089 | - rc = fts5StorageSaveTotals(p); | |
| 184090 | - } | |
| 184091 | - | |
| 184092 | - return rc; | |
| 184093 | -} | |
| 184094 | - | |
| 184095 | -static int sqlite3Fts5StorageSpecialDelete( | |
| 184096 | - Fts5Storage *p, | |
| 184097 | - i64 iDel, | |
| 184098 | - sqlite3_value **apVal | |
| 184099 | -){ | |
| 184100 | - Fts5Config *pConfig = p->pConfig; | |
| 184101 | - int rc; | |
| 184102 | - sqlite3_stmt *pDel = 0; | |
| 184103 | - | |
| 184104 | - assert( pConfig->eContent!=FTS5_CONTENT_NORMAL ); | |
| 184105 | - rc = fts5StorageLoadTotals(p, 1); | |
| 184106 | - | |
| 184107 | - /* Delete the index records */ | |
| 184108 | - if( rc==SQLITE_OK ){ | |
| 184109 | - int iCol; | |
| 184110 | - Fts5InsertCtx ctx; | |
| 184111 | - ctx.pStorage = p; | |
| 184112 | - ctx.iCol = -1; | |
| 184113 | - | |
| 184114 | - rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel); | |
| 184115 | - for(iCol=0; rc==SQLITE_OK && iCol<pConfig->nCol; iCol++){ | |
| 184116 | - if( pConfig->abUnindexed[iCol] ) continue; | |
| 184117 | - ctx.szCol = 0; | |
| 184118 | - rc = sqlite3Fts5Tokenize(pConfig, | |
| 184119 | - FTS5_TOKENIZE_DOCUMENT, | |
| 184120 | - (const char*)sqlite3_value_text(apVal[iCol]), | |
| 184121 | - sqlite3_value_bytes(apVal[iCol]), | |
| 184122 | - (void*)&ctx, | |
| 184123 | - fts5StorageInsertCallback | |
| 184124 | - ); | |
| 184125 | - p->aTotalSize[iCol] -= (i64)ctx.szCol; | |
| 184126 | - } | |
| 184127 | - p->nTotalRow--; | |
| 184128 | - } | |
| 184129 | - | |
| 184130 | - /* Delete the %_docsize record */ | |
| 184131 | - if( pConfig->bColumnsize ){ | |
| 184132 | - if( rc==SQLITE_OK ){ | |
| 184133 | - rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_DOCSIZE, &pDel, 0); | |
| 184134 | - } | |
| 184135 | 184239 | if( rc==SQLITE_OK ){ |
| 184136 | 184240 | sqlite3_bind_int64(pDel, 1, iDel); |
| 184137 | 184241 | sqlite3_step(pDel); |
| 184138 | 184242 | rc = sqlite3_reset(pDel); |
| 184139 | 184243 | } |
| @@ -187089,10 +187193,14 @@ | ||
| 187089 | 187193 | int iCol = -1; |
| 187090 | 187194 | while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){ |
| 187091 | 187195 | int ii = FTS5_POS2COLUMN(iPos); |
| 187092 | 187196 | pCsr->aCnt[ii]++; |
| 187093 | 187197 | if( iCol!=ii ){ |
| 187198 | + if( ii>=nCol ){ | |
| 187199 | + rc = FTS5_CORRUPT; | |
| 187200 | + break; | |
| 187201 | + } | |
| 187094 | 187202 | pCsr->aDoc[ii]++; |
| 187095 | 187203 | iCol = ii; |
| 187096 | 187204 | } |
| 187097 | 187205 | } |
| 187098 | 187206 | } |
| @@ -187106,11 +187214,15 @@ | ||
| 187106 | 187214 | Fts5Buffer buf = {0, 0, 0}; |
| 187107 | 187215 | rc = sqlite3Fts5IterPoslistBuffer(pCsr->pIter, &buf); |
| 187108 | 187216 | if( rc==SQLITE_OK ){ |
| 187109 | 187217 | while( 0==sqlite3Fts5PoslistNext64(buf.p, buf.n, &iOff,&iPos) ){ |
| 187110 | 187218 | assert_nc( iPos>=0 && iPos<nCol ); |
| 187111 | - if( iPos<nCol ) pCsr->aDoc[iPos]++; | |
| 187219 | + if( iPos>=nCol ){ | |
| 187220 | + rc = FTS5_CORRUPT; | |
| 187221 | + break; | |
| 187222 | + } | |
| 187223 | + pCsr->aDoc[iPos]++; | |
| 187112 | 187224 | } |
| 187113 | 187225 | } |
| 187114 | 187226 | sqlite3Fts5BufferFree(&buf); |
| 187115 | 187227 | } |
| 187116 | 187228 | break; |
| @@ -187134,11 +187246,11 @@ | ||
| 187134 | 187246 | } |
| 187135 | 187247 | } |
| 187136 | 187248 | } |
| 187137 | 187249 | } |
| 187138 | 187250 | |
| 187139 | - if( pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){ | |
| 187251 | + if( rc==SQLITE_OK && pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){ | |
| 187140 | 187252 | while( pCsr->aDoc[pCsr->iCol]==0 ) pCsr->iCol++; |
| 187141 | 187253 | assert( pCsr->iCol<pCsr->pConfig->nCol ); |
| 187142 | 187254 | } |
| 187143 | 187255 | return rc; |
| 187144 | 187256 | } |
| 187145 | 187257 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -327,11 +327,11 @@ | |
| 327 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 328 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 329 | */ |
| 330 | #define SQLITE_VERSION "3.11.0" |
| 331 | #define SQLITE_VERSION_NUMBER 3011000 |
| 332 | #define SQLITE_SOURCE_ID "2016-01-14 14:19:50 d17bc2c92f4d086280e49a3cc72993be7fee2da7" |
| 333 | |
| 334 | /* |
| 335 | ** CAPI3REF: Run-Time Library Version Numbers |
| 336 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 337 | ** |
| @@ -9406,10 +9406,25 @@ | |
| 9406 | #else |
| 9407 | # define ALWAYS(X) (X) |
| 9408 | # define NEVER(X) (X) |
| 9409 | #endif |
| 9410 | |
| 9411 | /* |
| 9412 | ** Declarations used for tracing the operating system interfaces. |
| 9413 | */ |
| 9414 | #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \ |
| 9415 | (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) |
| @@ -10961,19 +10976,24 @@ | |
| 10961 | SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...); |
| 10962 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int); |
| 10963 | SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int); |
| 10964 | SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int); |
| 10965 | SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int); |
| 10966 | SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno); |
| 10967 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*); |
| 10968 | SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8); |
| 10969 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1); |
| 10970 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 10971 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 10972 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 10973 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 10974 | SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 10975 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 10976 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 10977 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 10978 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 10979 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| @@ -12227,13 +12247,12 @@ | |
| 12227 | struct FuncDef { |
| 12228 | i16 nArg; /* Number of arguments. -1 means unlimited */ |
| 12229 | u16 funcFlags; /* Some combination of SQLITE_FUNC_* */ |
| 12230 | void *pUserData; /* User data parameter */ |
| 12231 | FuncDef *pNext; /* Next function with same name */ |
| 12232 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ |
| 12233 | void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */ |
| 12234 | void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */ |
| 12235 | char *zName; /* SQL name of the function. */ |
| 12236 | FuncDef *pHash; /* Next with a different name but the same hash */ |
| 12237 | FuncDestructor *pDestructor; /* Reference counted destructor function */ |
| 12238 | }; |
| 12239 | |
| @@ -12312,32 +12331,32 @@ | |
| 12312 | ** FuncDef.flags variable is set to the value passed as the flags |
| 12313 | ** parameter. |
| 12314 | */ |
| 12315 | #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 12316 | {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12317 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} |
| 12318 | #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 12319 | {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12320 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} |
| 12321 | #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 12322 | {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12323 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} |
| 12324 | #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ |
| 12325 | {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ |
| 12326 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} |
| 12327 | #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ |
| 12328 | {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12329 | pArg, 0, xFunc, 0, 0, #zName, 0, 0} |
| 12330 | #define LIKEFUNC(zName, nArg, arg, flags) \ |
| 12331 | {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ |
| 12332 | (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0} |
| 12333 | #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ |
| 12334 | {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \ |
| 12335 | SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} |
| 12336 | #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \ |
| 12337 | {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ |
| 12338 | SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} |
| 12339 | |
| 12340 | /* |
| 12341 | ** All current savepoints are stored in a linked list starting at |
| 12342 | ** sqlite3.pSavepoint. The first element in the list is the most recently |
| 12343 | ** opened savepoint. Savepoints are added to the list by the vdbe |
| @@ -16576,52 +16595,68 @@ | |
| 16576 | char tzSet; /* Timezone was set explicitly */ |
| 16577 | }; |
| 16578 | |
| 16579 | |
| 16580 | /* |
| 16581 | ** Convert zDate into one or more integers. Additional arguments |
| 16582 | ** come in groups of 5 as follows: |
| 16583 | ** |
| 16584 | ** N number of digits in the integer |
| 16585 | ** min minimum allowed value of the integer |
| 16586 | ** max maximum allowed value of the integer |
| 16587 | ** nextC first character after the integer |
| 16588 | ** pVal where to write the integers value. |
| 16589 | ** |
| 16590 | ** Conversions continue until one with nextC==0 is encountered. |
| 16591 | ** The function returns the number of successful conversions. |
| 16592 | */ |
| 16593 | static int getDigits(const char *zDate, ...){ |
| 16594 | va_list ap; |
| 16595 | int val; |
| 16596 | int N; |
| 16597 | int min; |
| 16598 | int max; |
| 16599 | int nextC; |
| 16600 | int *pVal; |
| 16601 | int cnt = 0; |
| 16602 | va_start(ap, zDate); |
| 16603 | do{ |
| 16604 | N = va_arg(ap, int); |
| 16605 | min = va_arg(ap, int); |
| 16606 | max = va_arg(ap, int); |
| 16607 | nextC = va_arg(ap, int); |
| 16608 | pVal = va_arg(ap, int*); |
| 16609 | val = 0; |
| 16610 | while( N-- ){ |
| 16611 | if( !sqlite3Isdigit(*zDate) ){ |
| 16612 | goto end_getDigits; |
| 16613 | } |
| 16614 | val = val*10 + *zDate - '0'; |
| 16615 | zDate++; |
| 16616 | } |
| 16617 | if( val<min || val>max || (nextC!=0 && nextC!=*zDate) ){ |
| 16618 | goto end_getDigits; |
| 16619 | } |
| 16620 | *pVal = val; |
| 16621 | zDate++; |
| 16622 | cnt++; |
| 16623 | }while( nextC ); |
| 16624 | end_getDigits: |
| 16625 | va_end(ap); |
| 16626 | return cnt; |
| 16627 | } |
| @@ -16658,11 +16693,11 @@ | |
| 16658 | goto zulu_time; |
| 16659 | }else{ |
| 16660 | return c!=0; |
| 16661 | } |
| 16662 | zDate++; |
| 16663 | if( getDigits(zDate, 2, 0, 14, ':', &nHr, 2, 0, 59, 0, &nMn)!=2 ){ |
| 16664 | return 1; |
| 16665 | } |
| 16666 | zDate += 5; |
| 16667 | p->tz = sgn*(nMn + nHr*60); |
| 16668 | zulu_time: |
| @@ -16679,17 +16714,17 @@ | |
| 16679 | ** Return 1 if there is a parsing error and 0 on success. |
| 16680 | */ |
| 16681 | static int parseHhMmSs(const char *zDate, DateTime *p){ |
| 16682 | int h, m, s; |
| 16683 | double ms = 0.0; |
| 16684 | if( getDigits(zDate, 2, 0, 24, ':', &h, 2, 0, 59, 0, &m)!=2 ){ |
| 16685 | return 1; |
| 16686 | } |
| 16687 | zDate += 5; |
| 16688 | if( *zDate==':' ){ |
| 16689 | zDate++; |
| 16690 | if( getDigits(zDate, 2, 0, 59, 0, &s)!=1 ){ |
| 16691 | return 1; |
| 16692 | } |
| 16693 | zDate += 2; |
| 16694 | if( *zDate=='.' && sqlite3Isdigit(zDate[1]) ){ |
| 16695 | double rScale = 1.0; |
| @@ -16773,11 +16808,11 @@ | |
| 16773 | zDate++; |
| 16774 | neg = 1; |
| 16775 | }else{ |
| 16776 | neg = 0; |
| 16777 | } |
| 16778 | if( getDigits(zDate,4,0,9999,'-',&Y,2,1,12,'-',&M,2,1,31,0,&D)!=3 ){ |
| 16779 | return 1; |
| 16780 | } |
| 16781 | zDate += 10; |
| 16782 | while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; } |
| 16783 | if( parseHhMmSs(zDate, p)==0 ){ |
| @@ -63843,10 +63878,18 @@ | |
| 63843 | */ |
| 63844 | if( NEVER(pBt->pCursor) ){ |
| 63845 | sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db); |
| 63846 | return SQLITE_LOCKED_SHAREDCACHE; |
| 63847 | } |
| 63848 | |
| 63849 | rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); |
| 63850 | if( rc ) return rc; |
| 63851 | rc = sqlite3BtreeClearTable(p, iTable, 0); |
| 63852 | if( rc ){ |
| @@ -63854,80 +63897,71 @@ | |
| 63854 | return rc; |
| 63855 | } |
| 63856 | |
| 63857 | *piMoved = 0; |
| 63858 | |
| 63859 | if( iTable>1 ){ |
| 63860 | #ifdef SQLITE_OMIT_AUTOVACUUM |
| 63861 | freePage(pPage, &rc); |
| 63862 | releasePage(pPage); |
| 63863 | #else |
| 63864 | if( pBt->autoVacuum ){ |
| 63865 | Pgno maxRootPgno; |
| 63866 | sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &maxRootPgno); |
| 63867 | |
| 63868 | if( iTable==maxRootPgno ){ |
| 63869 | /* If the table being dropped is the table with the largest root-page |
| 63870 | ** number in the database, put the root page on the free list. |
| 63871 | */ |
| 63872 | freePage(pPage, &rc); |
| 63873 | releasePage(pPage); |
| 63874 | if( rc!=SQLITE_OK ){ |
| 63875 | return rc; |
| 63876 | } |
| 63877 | }else{ |
| 63878 | /* The table being dropped does not have the largest root-page |
| 63879 | ** number in the database. So move the page that does into the |
| 63880 | ** gap left by the deleted root-page. |
| 63881 | */ |
| 63882 | MemPage *pMove; |
| 63883 | releasePage(pPage); |
| 63884 | rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); |
| 63885 | if( rc!=SQLITE_OK ){ |
| 63886 | return rc; |
| 63887 | } |
| 63888 | rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0); |
| 63889 | releasePage(pMove); |
| 63890 | if( rc!=SQLITE_OK ){ |
| 63891 | return rc; |
| 63892 | } |
| 63893 | pMove = 0; |
| 63894 | rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); |
| 63895 | freePage(pMove, &rc); |
| 63896 | releasePage(pMove); |
| 63897 | if( rc!=SQLITE_OK ){ |
| 63898 | return rc; |
| 63899 | } |
| 63900 | *piMoved = maxRootPgno; |
| 63901 | } |
| 63902 | |
| 63903 | /* Set the new 'max-root-page' value in the database header. This |
| 63904 | ** is the old value less one, less one more if that happens to |
| 63905 | ** be a root-page number, less one again if that is the |
| 63906 | ** PENDING_BYTE_PAGE. |
| 63907 | */ |
| 63908 | maxRootPgno--; |
| 63909 | while( maxRootPgno==PENDING_BYTE_PAGE(pBt) |
| 63910 | || PTRMAP_ISPAGE(pBt, maxRootPgno) ){ |
| 63911 | maxRootPgno--; |
| 63912 | } |
| 63913 | assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) ); |
| 63914 | |
| 63915 | rc = sqlite3BtreeUpdateMeta(p, 4, maxRootPgno); |
| 63916 | }else{ |
| 63917 | freePage(pPage, &rc); |
| 63918 | releasePage(pPage); |
| 63919 | } |
| 63920 | #endif |
| 63921 | }else{ |
| 63922 | /* If sqlite3BtreeDropTable was called on page 1. |
| 63923 | ** This really never should happen except in a corrupt |
| 63924 | ** database. |
| 63925 | */ |
| 63926 | zeroPage(pPage, PTF_INTKEY|PTF_LEAF ); |
| 63927 | releasePage(pPage); |
| 63928 | } |
| 63929 | return rc; |
| 63930 | } |
| 63931 | SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree *p, int iTable, int *piMoved){ |
| 63932 | int rc; |
| 63933 | sqlite3BtreeEnter(p); |
| @@ -67010,11 +67044,11 @@ | |
| 67010 | |
| 67011 | assert( pCtx->pParse->rc==SQLITE_OK ); |
| 67012 | memset(&ctx, 0, sizeof(ctx)); |
| 67013 | ctx.pOut = pVal; |
| 67014 | ctx.pFunc = pFunc; |
| 67015 | pFunc->xFunc(&ctx, nVal, apVal); |
| 67016 | if( ctx.isError ){ |
| 67017 | rc = ctx.isError; |
| 67018 | sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); |
| 67019 | }else{ |
| 67020 | sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); |
| @@ -67757,12 +67791,11 @@ | |
| 67757 | char c; |
| 67758 | va_start(ap, zTypes); |
| 67759 | for(i=0; (c = zTypes[i])!=0; i++){ |
| 67760 | if( c=='s' ){ |
| 67761 | const char *z = va_arg(ap, const char*); |
| 67762 | int addr = sqlite3VdbeAddOp2(p, z==0 ? OP_Null : OP_String8, 0, iDest++); |
| 67763 | if( z ) sqlite3VdbeChangeP4(p, addr, z, 0); |
| 67764 | }else{ |
| 67765 | assert( c=='i' ); |
| 67766 | sqlite3VdbeAddOp2(p, OP_Integer, va_arg(ap, int), iDest++); |
| 67767 | } |
| 67768 | } |
| @@ -68113,10 +68146,24 @@ | |
| 68113 | SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){ |
| 68114 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 68115 | return p->nOp; |
| 68116 | } |
| 68117 | |
| 68118 | /* |
| 68119 | ** This function returns a pointer to the array of opcodes associated with |
| 68120 | ** the Vdbe passed as the first argument. It is the callers responsibility |
| 68121 | ** to arrange for the returned array to be eventually freed using the |
| 68122 | ** vdbeFreeOpArray() function. |
| @@ -68138,23 +68185,27 @@ | |
| 68138 | p->aOp = 0; |
| 68139 | return aOp; |
| 68140 | } |
| 68141 | |
| 68142 | /* |
| 68143 | ** Add a whole list of operations to the operation stack. Return the |
| 68144 | ** address of the first operation added. |
| 68145 | */ |
| 68146 | SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){ |
| 68147 | int addr, i; |
| 68148 | VdbeOp *pOut; |
| 68149 | assert( nOp>0 ); |
| 68150 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 68151 | if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){ |
| 68152 | return 0; |
| 68153 | } |
| 68154 | addr = p->nOp; |
| 68155 | pOut = &p->aOp[addr]; |
| 68156 | for(i=0; i<nOp; i++, aOp++, pOut++){ |
| 68157 | pOut->opcode = aOp->opcode; |
| 68158 | pOut->p1 = aOp->p1; |
| 68159 | pOut->p2 = aOp->p2; |
| 68160 | assert( aOp->p2>=0 ); |
| @@ -68170,16 +68221,16 @@ | |
| 68170 | #else |
| 68171 | (void)iLineno; |
| 68172 | #endif |
| 68173 | #ifdef SQLITE_DEBUG |
| 68174 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 68175 | sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]); |
| 68176 | } |
| 68177 | #endif |
| 68178 | } |
| 68179 | p->nOp += nOp; |
| 68180 | return addr; |
| 68181 | } |
| 68182 | |
| 68183 | #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) |
| 68184 | /* |
| 68185 | ** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus(). |
| @@ -68223,11 +68274,11 @@ | |
| 68223 | } |
| 68224 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){ |
| 68225 | sqlite3VdbeGetOp(p,addr)->p3 = val; |
| 68226 | } |
| 68227 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){ |
| 68228 | sqlite3VdbeGetOp(p,-1)->p5 = p5; |
| 68229 | } |
| 68230 | |
| 68231 | /* |
| 68232 | ** Change the P2 operand of instruction addr so that it points to |
| 68233 | ** the address of the next instruction to be coded. |
| @@ -68333,28 +68384,28 @@ | |
| 68333 | } |
| 68334 | |
| 68335 | /* |
| 68336 | ** Change the opcode at addr into OP_Noop |
| 68337 | */ |
| 68338 | SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe *p, int addr){ |
| 68339 | if( addr<p->nOp ){ |
| 68340 | VdbeOp *pOp = &p->aOp[addr]; |
| 68341 | sqlite3 *db = p->db; |
| 68342 | freeP4(db, pOp->p4type, pOp->p4.p); |
| 68343 | memset(pOp, 0, sizeof(pOp[0])); |
| 68344 | pOp->opcode = OP_Noop; |
| 68345 | } |
| 68346 | } |
| 68347 | |
| 68348 | /* |
| 68349 | ** If the last opcode is "op" and it is not a jump destination, |
| 68350 | ** then remove it. Return true if and only if an opcode was removed. |
| 68351 | */ |
| 68352 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe *p, u8 op){ |
| 68353 | if( (p->nOp-1)>(p->pParse->iFixedOp) && p->aOp[p->nOp-1].opcode==op ){ |
| 68354 | sqlite3VdbeChangeToNoop(p, p->nOp-1); |
| 68355 | return 1; |
| 68356 | }else{ |
| 68357 | return 0; |
| 68358 | } |
| 68359 | } |
| 68360 | |
| @@ -72726,11 +72777,11 @@ | |
| 72726 | ** Allocate or return the aggregate context for a user function. A new |
| 72727 | ** context is allocated on the first call. Subsequent calls return the |
| 72728 | ** same context that was returned on prior calls. |
| 72729 | */ |
| 72730 | SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context *p, int nByte){ |
| 72731 | assert( p && p->pFunc && p->pFunc->xStep ); |
| 72732 | assert( sqlite3_mutex_held(p->pOut->db->mutex) ); |
| 72733 | testcase( nByte<0 ); |
| 72734 | if( (p->pMem->flags & MEM_Agg)==0 ){ |
| 72735 | return createAggContext(p, nByte); |
| 72736 | }else{ |
| @@ -72817,11 +72868,11 @@ | |
| 72817 | ** provide only to avoid breaking legacy code. New aggregate function |
| 72818 | ** implementations should keep their own counts within their aggregate |
| 72819 | ** context. |
| 72820 | */ |
| 72821 | SQLITE_API int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context *p){ |
| 72822 | assert( p && p->pMem && p->pFunc && p->pFunc->xStep ); |
| 72823 | return p->pMem->n; |
| 72824 | } |
| 72825 | #endif |
| 72826 | |
| 72827 | /* |
| @@ -75560,12 +75611,12 @@ | |
| 75560 | } |
| 75561 | #endif |
| 75562 | MemSetTypeFlag(pCtx->pOut, MEM_Null); |
| 75563 | pCtx->fErrorOrAux = 0; |
| 75564 | db->lastRowid = lastRowid; |
| 75565 | (*pCtx->pFunc->xFunc)(pCtx, pCtx->argc, pCtx->argv); /* IMP: R-24505-23230 */ |
| 75566 | lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */ |
| 75567 | |
| 75568 | /* If the function returned an error, throw an exception */ |
| 75569 | if( pCtx->fErrorOrAux ){ |
| 75570 | if( pCtx->isError ){ |
| 75571 | sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); |
| @@ -78997,10 +79048,11 @@ | |
| 78997 | case OP_Destroy: { /* out2 */ |
| 78998 | int iMoved; |
| 78999 | int iDb; |
| 79000 | |
| 79001 | assert( p->readOnly==0 ); |
| 79002 | pOut = out2Prerelease(p, pOp); |
| 79003 | pOut->flags = MEM_Null; |
| 79004 | if( db->nVdbeRead > db->nVDestroy+1 ){ |
| 79005 | rc = SQLITE_LOCKED; |
| 79006 | p->errorAction = OE_Abort; |
| @@ -79801,11 +79853,11 @@ | |
| 79801 | pMem->n++; |
| 79802 | sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 79803 | pCtx->pOut = &t; |
| 79804 | pCtx->fErrorOrAux = 0; |
| 79805 | pCtx->skipFlag = 0; |
| 79806 | (pCtx->pFunc->xStep)(pCtx,pCtx->argc,pCtx->argv); /* IMP: R-24505-23230 */ |
| 79807 | if( pCtx->fErrorOrAux ){ |
| 79808 | if( pCtx->isError ){ |
| 79809 | sqlite3VdbeError(p, "%s", sqlite3_value_text(&t)); |
| 79810 | rc = pCtx->isError; |
| 79811 | } |
| @@ -80799,42 +80851,10 @@ | |
| 80799 | int flags, /* True -> read/write access, false -> read-only */ |
| 80800 | sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */ |
| 80801 | ){ |
| 80802 | int nAttempt = 0; |
| 80803 | int iCol; /* Index of zColumn in row-record */ |
| 80804 | |
| 80805 | /* This VDBE program seeks a btree cursor to the identified |
| 80806 | ** db/table/row entry. The reason for using a vdbe program instead |
| 80807 | ** of writing code to use the b-tree layer directly is that the |
| 80808 | ** vdbe program will take advantage of the various transaction, |
| 80809 | ** locking and error handling infrastructure built into the vdbe. |
| 80810 | ** |
| 80811 | ** After seeking the cursor, the vdbe executes an OP_ResultRow. |
| 80812 | ** Code external to the Vdbe then "borrows" the b-tree cursor and |
| 80813 | ** uses it to implement the blob_read(), blob_write() and |
| 80814 | ** blob_bytes() functions. |
| 80815 | ** |
| 80816 | ** The sqlite3_blob_close() function finalizes the vdbe program, |
| 80817 | ** which closes the b-tree cursor and (possibly) commits the |
| 80818 | ** transaction. |
| 80819 | */ |
| 80820 | static const int iLn = VDBE_OFFSET_LINENO(4); |
| 80821 | static const VdbeOpList openBlob[] = { |
| 80822 | /* {OP_Transaction, 0, 0, 0}, // 0: Inserted separately */ |
| 80823 | {OP_TableLock, 0, 0, 0}, /* 1: Acquire a read or write lock */ |
| 80824 | /* One of the following two instructions is replaced by an OP_Noop. */ |
| 80825 | {OP_OpenRead, 0, 0, 0}, /* 2: Open cursor 0 for reading */ |
| 80826 | {OP_OpenWrite, 0, 0, 0}, /* 3: Open cursor 0 for read/write */ |
| 80827 | {OP_Variable, 1, 1, 1}, /* 4: Push the rowid to the stack */ |
| 80828 | {OP_NotExists, 0, 10, 1}, /* 5: Seek the cursor */ |
| 80829 | {OP_Column, 0, 0, 1}, /* 6 */ |
| 80830 | {OP_ResultRow, 1, 0, 0}, /* 7 */ |
| 80831 | {OP_Goto, 0, 4, 0}, /* 8 */ |
| 80832 | {OP_Close, 0, 0, 0}, /* 9 */ |
| 80833 | {OP_Halt, 0, 0, 0}, /* 10 */ |
| 80834 | }; |
| 80835 | |
| 80836 | int rc = SQLITE_OK; |
| 80837 | char *zErr = 0; |
| 80838 | Table *pTab; |
| 80839 | Parse *pParse = 0; |
| 80840 | Incrblob *pBlob = 0; |
| @@ -80949,49 +80969,84 @@ | |
| 80949 | } |
| 80950 | |
| 80951 | pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse); |
| 80952 | assert( pBlob->pStmt || db->mallocFailed ); |
| 80953 | if( pBlob->pStmt ){ |
| 80954 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 80955 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 80956 | |
| 80957 | |
| 80958 | sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags, |
| 80959 | pTab->pSchema->schema_cookie, |
| 80960 | pTab->pSchema->iGeneration); |
| 80961 | sqlite3VdbeChangeP5(v, 1); |
| 80962 | sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn); |
| 80963 | |
| 80964 | /* Make sure a mutex is held on the table to be accessed */ |
| 80965 | sqlite3VdbeUsesBtree(v, iDb); |
| 80966 | |
| 80967 | /* Configure the OP_TableLock instruction */ |
| 80968 | #ifdef SQLITE_OMIT_SHARED_CACHE |
| 80969 | sqlite3VdbeChangeToNoop(v, 1); |
| 80970 | #else |
| 80971 | sqlite3VdbeChangeP1(v, 1, iDb); |
| 80972 | sqlite3VdbeChangeP2(v, 1, pTab->tnum); |
| 80973 | sqlite3VdbeChangeP3(v, 1, flags); |
| 80974 | sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT); |
| 80975 | #endif |
| 80976 | |
| 80977 | /* Remove either the OP_OpenWrite or OpenRead. Set the P2 |
| 80978 | ** parameter of the other to pTab->tnum. */ |
| 80979 | sqlite3VdbeChangeToNoop(v, 3 - flags); |
| 80980 | sqlite3VdbeChangeP2(v, 2 + flags, pTab->tnum); |
| 80981 | sqlite3VdbeChangeP3(v, 2 + flags, iDb); |
| 80982 | |
| 80983 | /* Configure the number of columns. Configure the cursor to |
| 80984 | ** think that the table has one more column than it really |
| 80985 | ** does. An OP_Column to retrieve this imaginary column will |
| 80986 | ** always return an SQL NULL. This is useful because it means |
| 80987 | ** we can invoke OP_Column to fill in the vdbe cursors type |
| 80988 | ** and offset cache without causing any IO. |
| 80989 | */ |
| 80990 | sqlite3VdbeChangeP4(v, 2+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32); |
| 80991 | sqlite3VdbeChangeP2(v, 6, pTab->nCol); |
| 80992 | if( !db->mallocFailed ){ |
| 80993 | pParse->nVar = 1; |
| 80994 | pParse->nMem = 1; |
| 80995 | pParse->nTab = 1; |
| 80996 | sqlite3VdbeMakeReady(v, pParse); |
| 80997 | } |
| @@ -85251,11 +85306,11 @@ | |
| 85251 | no_such_func = 1; |
| 85252 | }else{ |
| 85253 | wrong_num_args = 1; |
| 85254 | } |
| 85255 | }else{ |
| 85256 | is_agg = pDef->xFunc==0; |
| 85257 | if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){ |
| 85258 | ExprSetProperty(pExpr, EP_Unlikely|EP_Skip); |
| 85259 | if( n==2 ){ |
| 85260 | pExpr->iTable = exprProbability(pList->a[1].pExpr); |
| 85261 | if( pExpr->iTable<0 ){ |
| @@ -87218,14 +87273,15 @@ | |
| 87218 | ExprList *pList, /* List to which to append. Might be NULL */ |
| 87219 | Expr *pExpr /* Expression to be appended. Might be NULL */ |
| 87220 | ){ |
| 87221 | sqlite3 *db = pParse->db; |
| 87222 | if( pList==0 ){ |
| 87223 | pList = sqlite3DbMallocZero(db, sizeof(ExprList) ); |
| 87224 | if( pList==0 ){ |
| 87225 | goto no_mem; |
| 87226 | } |
| 87227 | pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0])); |
| 87228 | if( pList->a==0 ) goto no_mem; |
| 87229 | }else if( (pList->nExpr & (pList->nExpr-1))==0 ){ |
| 87230 | struct ExprList_item *a; |
| 87231 | assert( pList->nExpr>0 ); |
| @@ -88979,11 +89035,11 @@ | |
| 88979 | nFarg = pFarg ? pFarg->nExpr : 0; |
| 88980 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 88981 | zId = pExpr->u.zToken; |
| 88982 | nId = sqlite3Strlen30(zId); |
| 88983 | pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0); |
| 88984 | if( pDef==0 || pDef->xFunc==0 ){ |
| 88985 | sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId); |
| 88986 | break; |
| 88987 | } |
| 88988 | |
| 88989 | /* Attempt a direct implementation of the built-in COALESCE() and |
| @@ -91651,12 +91707,11 @@ | |
| 91651 | static const FuncDef statInitFuncdef = { |
| 91652 | 2+IsStat34, /* nArg */ |
| 91653 | SQLITE_UTF8, /* funcFlags */ |
| 91654 | 0, /* pUserData */ |
| 91655 | 0, /* pNext */ |
| 91656 | statInit, /* xFunc */ |
| 91657 | 0, /* xStep */ |
| 91658 | 0, /* xFinalize */ |
| 91659 | "stat_init", /* zName */ |
| 91660 | 0, /* pHash */ |
| 91661 | 0 /* pDestructor */ |
| 91662 | }; |
| @@ -91952,12 +92007,11 @@ | |
| 91952 | static const FuncDef statPushFuncdef = { |
| 91953 | 2+IsStat34, /* nArg */ |
| 91954 | SQLITE_UTF8, /* funcFlags */ |
| 91955 | 0, /* pUserData */ |
| 91956 | 0, /* pNext */ |
| 91957 | statPush, /* xFunc */ |
| 91958 | 0, /* xStep */ |
| 91959 | 0, /* xFinalize */ |
| 91960 | "stat_push", /* zName */ |
| 91961 | 0, /* pHash */ |
| 91962 | 0 /* pDestructor */ |
| 91963 | }; |
| @@ -92099,12 +92153,11 @@ | |
| 92099 | static const FuncDef statGetFuncdef = { |
| 92100 | 1+IsStat34, /* nArg */ |
| 92101 | SQLITE_UTF8, /* funcFlags */ |
| 92102 | 0, /* pUserData */ |
| 92103 | 0, /* pNext */ |
| 92104 | statGet, /* xFunc */ |
| 92105 | 0, /* xStep */ |
| 92106 | 0, /* xFinalize */ |
| 92107 | "stat_get", /* zName */ |
| 92108 | 0, /* pHash */ |
| 92109 | 0 /* pDestructor */ |
| 92110 | }; |
| @@ -92116,12 +92169,12 @@ | |
| 92116 | #elif SQLITE_DEBUG |
| 92117 | assert( iParam==STAT_GET_STAT1 ); |
| 92118 | #else |
| 92119 | UNUSED_PARAMETER( iParam ); |
| 92120 | #endif |
| 92121 | sqlite3VdbeAddOp3(v, OP_Function0, 0, regStat4, regOut); |
| 92122 | sqlite3VdbeChangeP4(v, -1, (char*)&statGetFuncdef, P4_FUNCDEF); |
| 92123 | sqlite3VdbeChangeP5(v, 1 + IsStat34); |
| 92124 | } |
| 92125 | |
| 92126 | /* |
| 92127 | ** Generate code to do an analysis of all indices associated with |
| @@ -92271,12 +92324,12 @@ | |
| 92271 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 92272 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+3); |
| 92273 | #endif |
| 92274 | sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat4+1); |
| 92275 | sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regStat4+2); |
| 92276 | sqlite3VdbeAddOp3(v, OP_Function0, 0, regStat4+1, regStat4); |
| 92277 | sqlite3VdbeChangeP4(v, -1, (char*)&statInitFuncdef, P4_FUNCDEF); |
| 92278 | sqlite3VdbeChangeP5(v, 2+IsStat34); |
| 92279 | |
| 92280 | /* Implementation of the following: |
| 92281 | ** |
| 92282 | ** Rewind csr |
| @@ -92368,12 +92421,12 @@ | |
| 92368 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid); |
| 92369 | sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol); |
| 92370 | } |
| 92371 | #endif |
| 92372 | assert( regChng==(regStat4+1) ); |
| 92373 | sqlite3VdbeAddOp3(v, OP_Function0, 1, regStat4, regTemp); |
| 92374 | sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF); |
| 92375 | sqlite3VdbeChangeP5(v, 2+IsStat34); |
| 92376 | sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v); |
| 92377 | |
| 92378 | /* Add the entry to the stat1 table. */ |
| 92379 | callStatGet(v, regStat4, STAT_GET_STAT1, regStat1); |
| @@ -93426,15 +93479,15 @@ | |
| 93426 | sqlite3ExprCode(pParse, pDbname, regArgs+1); |
| 93427 | sqlite3ExprCode(pParse, pKey, regArgs+2); |
| 93428 | |
| 93429 | assert( v || db->mallocFailed ); |
| 93430 | if( v ){ |
| 93431 | sqlite3VdbeAddOp3(v, OP_Function0, 0, regArgs+3-pFunc->nArg, regArgs+3); |
| 93432 | assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg ); |
| 93433 | sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg)); |
| 93434 | sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF); |
| 93435 | |
| 93436 | /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this |
| 93437 | ** statement only). For DETACH, set it to false (expire all existing |
| 93438 | ** statements). |
| 93439 | */ |
| 93440 | sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH)); |
| @@ -93455,12 +93508,11 @@ | |
| 93455 | static const FuncDef detach_func = { |
| 93456 | 1, /* nArg */ |
| 93457 | SQLITE_UTF8, /* funcFlags */ |
| 93458 | 0, /* pUserData */ |
| 93459 | 0, /* pNext */ |
| 93460 | detachFunc, /* xFunc */ |
| 93461 | 0, /* xStep */ |
| 93462 | 0, /* xFinalize */ |
| 93463 | "sqlite_detach", /* zName */ |
| 93464 | 0, /* pHash */ |
| 93465 | 0 /* pDestructor */ |
| 93466 | }; |
| @@ -93476,12 +93528,11 @@ | |
| 93476 | static const FuncDef attach_func = { |
| 93477 | 3, /* nArg */ |
| 93478 | SQLITE_UTF8, /* funcFlags */ |
| 93479 | 0, /* pUserData */ |
| 93480 | 0, /* pNext */ |
| 93481 | attachFunc, /* xFunc */ |
| 93482 | 0, /* xStep */ |
| 93483 | 0, /* xFinalize */ |
| 93484 | "sqlite_attach", /* zName */ |
| 93485 | 0, /* pHash */ |
| 93486 | 0 /* pDestructor */ |
| 93487 | }; |
| @@ -94145,19 +94196,23 @@ | |
| 94145 | /* A minimum of one cursor is required if autoincrement is used |
| 94146 | * See ticket [a696379c1f08866] */ |
| 94147 | if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1; |
| 94148 | sqlite3VdbeMakeReady(v, pParse); |
| 94149 | pParse->rc = SQLITE_DONE; |
| 94150 | pParse->colNamesSet = 0; |
| 94151 | }else{ |
| 94152 | pParse->rc = SQLITE_ERROR; |
| 94153 | } |
| 94154 | pParse->nTab = 0; |
| 94155 | pParse->nMem = 0; |
| 94156 | pParse->nSet = 0; |
| 94157 | pParse->nVar = 0; |
| 94158 | DbMaskZero(pParse->cookieMask); |
| 94159 | } |
| 94160 | |
| 94161 | /* |
| 94162 | ** Run the parser and code generator recursively in order to generate |
| 94163 | ** code for the SQL statement given onto the end of the pParse context |
| @@ -94412,11 +94467,10 @@ | |
| 94412 | if( j<i ){ |
| 94413 | db->aDb[j] = db->aDb[i]; |
| 94414 | } |
| 94415 | j++; |
| 94416 | } |
| 94417 | memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j])); |
| 94418 | db->nDb = j; |
| 94419 | if( db->nDb<=2 && db->aDb!=db->aDbStatic ){ |
| 94420 | memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0])); |
| 94421 | sqlite3DbFree(db, db->aDb); |
| 94422 | db->aDb = db->aDbStatic; |
| @@ -94675,11 +94729,12 @@ | |
| 94675 | Token **pUnqual /* Write the unqualified object name here */ |
| 94676 | ){ |
| 94677 | int iDb; /* Database holding the object */ |
| 94678 | sqlite3 *db = pParse->db; |
| 94679 | |
| 94680 | if( ALWAYS(pName2!=0) && pName2->n>0 ){ |
| 94681 | if( db->init.busy ) { |
| 94682 | sqlite3ErrorMsg(pParse, "corrupt database"); |
| 94683 | return -1; |
| 94684 | } |
| 94685 | *pUnqual = pName2; |
| @@ -94764,66 +94819,50 @@ | |
| 94764 | sqlite3 *db = pParse->db; |
| 94765 | Vdbe *v; |
| 94766 | int iDb; /* Database number to create the table in */ |
| 94767 | Token *pName; /* Unqualified name of the table to create */ |
| 94768 | |
| 94769 | /* The table or view name to create is passed to this routine via tokens |
| 94770 | ** pName1 and pName2. If the table name was fully qualified, for example: |
| 94771 | ** |
| 94772 | ** CREATE TABLE xxx.yyy (...); |
| 94773 | ** |
| 94774 | ** Then pName1 is set to "xxx" and pName2 "yyy". On the other hand if |
| 94775 | ** the table name is not fully qualified, i.e.: |
| 94776 | ** |
| 94777 | ** CREATE TABLE yyy(...); |
| 94778 | ** |
| 94779 | ** Then pName1 is set to "yyy" and pName2 is "". |
| 94780 | ** |
| 94781 | ** The call below sets the pName pointer to point at the token (pName1 or |
| 94782 | ** pName2) that stores the unqualified table name. The variable iDb is |
| 94783 | ** set to the index of the database that the table or view is to be |
| 94784 | ** created in. |
| 94785 | */ |
| 94786 | iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName); |
| 94787 | if( iDb<0 ) return; |
| 94788 | if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){ |
| 94789 | /* If creating a temp table, the name may not be qualified. Unless |
| 94790 | ** the database name is "temp" anyway. */ |
| 94791 | sqlite3ErrorMsg(pParse, "temporary table name must be unqualified"); |
| 94792 | return; |
| 94793 | } |
| 94794 | if( !OMIT_TEMPDB && isTemp ) iDb = 1; |
| 94795 | |
| 94796 | pParse->sNameToken = *pName; |
| 94797 | zName = sqlite3NameFromToken(db, pName); |
| 94798 | if( zName==0 ) return; |
| 94799 | if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ |
| 94800 | goto begin_table_error; |
| 94801 | } |
| 94802 | if( db->init.iDb==1 ) isTemp = 1; |
| 94803 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 94804 | assert( (isTemp & 1)==isTemp ); |
| 94805 | { |
| 94806 | int code; |
| 94807 | char *zDb = db->aDb[iDb].zName; |
| 94808 | if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){ |
| 94809 | goto begin_table_error; |
| 94810 | } |
| 94811 | if( isView ){ |
| 94812 | if( !OMIT_TEMPDB && isTemp ){ |
| 94813 | code = SQLITE_CREATE_TEMP_VIEW; |
| 94814 | }else{ |
| 94815 | code = SQLITE_CREATE_VIEW; |
| 94816 | } |
| 94817 | }else{ |
| 94818 | if( !OMIT_TEMPDB && isTemp ){ |
| 94819 | code = SQLITE_CREATE_TEMP_TABLE; |
| 94820 | }else{ |
| 94821 | code = SQLITE_CREATE_TABLE; |
| 94822 | } |
| 94823 | } |
| 94824 | if( !isVirtual && sqlite3AuthCheck(pParse, code, zName, 0, zDb) ){ |
| 94825 | goto begin_table_error; |
| 94826 | } |
| 94827 | } |
| 94828 | #endif |
| 94829 | |
| @@ -95781,13 +95820,17 @@ | |
| 95781 | /* If the db->init.busy is 1 it means we are reading the SQL off the |
| 95782 | ** "sqlite_master" or "sqlite_temp_master" table on the disk. |
| 95783 | ** So do not write to the disk again. Extract the root page number |
| 95784 | ** for the table from the db->init.newTnum field. (The page number |
| 95785 | ** should have been put there by the sqliteOpenCb routine.) |
| 95786 | */ |
| 95787 | if( db->init.busy ){ |
| 95788 | p->tnum = db->init.newTnum; |
| 95789 | } |
| 95790 | |
| 95791 | /* Special processing for WITHOUT ROWID Tables */ |
| 95792 | if( tabOpts & TF_WithoutRowid ){ |
| 95793 | if( (p->tabFlags & TF_Autoincrement) ){ |
| @@ -96236,10 +96279,11 @@ | |
| 96236 | ** erasing iTable (this can happen with an auto-vacuum database). |
| 96237 | */ |
| 96238 | static void destroyRootPage(Parse *pParse, int iTable, int iDb){ |
| 96239 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 96240 | int r1 = sqlite3GetTempReg(pParse); |
| 96241 | sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb); |
| 96242 | sqlite3MayAbort(pParse); |
| 96243 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 96244 | /* OP_Destroy stores an in integer r1. If this integer |
| 96245 | ** is non-zero, then it is the root page number of a table moved to |
| @@ -97634,13 +97678,14 @@ | |
| 97634 | Token *pDatabase /* Database of the table */ |
| 97635 | ){ |
| 97636 | struct SrcList_item *pItem; |
| 97637 | assert( pDatabase==0 || pTable!=0 ); /* Cannot have C without B */ |
| 97638 | if( pList==0 ){ |
| 97639 | pList = sqlite3DbMallocZero(db, sizeof(SrcList) ); |
| 97640 | if( pList==0 ) return 0; |
| 97641 | pList->nAlloc = 1; |
| 97642 | } |
| 97643 | pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc); |
| 97644 | if( db->mallocFailed ){ |
| 97645 | sqlite3SrcListDelete(db, pList); |
| 97646 | return 0; |
| @@ -98039,11 +98084,11 @@ | |
| 98039 | assert( (errCode&0xff)==SQLITE_CONSTRAINT ); |
| 98040 | if( onError==OE_Abort ){ |
| 98041 | sqlite3MayAbort(pParse); |
| 98042 | } |
| 98043 | sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type); |
| 98044 | if( p5Errmsg ) sqlite3VdbeChangeP5(v, p5Errmsg); |
| 98045 | } |
| 98046 | |
| 98047 | /* |
| 98048 | ** Code an OP_Halt due to UNIQUE or PRIMARY KEY constraint violation. |
| 98049 | */ |
| @@ -98580,12 +98625,12 @@ | |
| 98580 | ** 3: encoding matches and function takes any number of arguments |
| 98581 | ** 4: UTF8/16 conversion required - argument count matches exactly |
| 98582 | ** 5: UTF16 byte order conversion required - argument count matches exactly |
| 98583 | ** 6: Perfect match: encoding and argument count match exactly. |
| 98584 | ** |
| 98585 | ** If nArg==(-2) then any function with a non-null xStep or xFunc is |
| 98586 | ** a perfect match and any function with both xStep and xFunc NULL is |
| 98587 | ** a non-match. |
| 98588 | */ |
| 98589 | #define FUNC_PERFECT_MATCH 6 /* The score for a perfect match */ |
| 98590 | static int matchQuality( |
| 98591 | FuncDef *p, /* The function we are evaluating for match quality */ |
| @@ -98593,11 +98638,11 @@ | |
| 98593 | u8 enc /* Desired text encoding */ |
| 98594 | ){ |
| 98595 | int match; |
| 98596 | |
| 98597 | /* nArg of -2 is a special case */ |
| 98598 | if( nArg==(-2) ) return (p->xFunc==0 && p->xStep==0) ? 0 : FUNC_PERFECT_MATCH; |
| 98599 | |
| 98600 | /* Wrong number of arguments means "no match" */ |
| 98601 | if( p->nArg!=nArg && p->nArg>=0 ) return 0; |
| 98602 | |
| 98603 | /* Give a better score to a function with a specific number of arguments |
| @@ -98671,11 +98716,11 @@ | |
| 98671 | ** If the createFlag argument is true, then a new (blank) FuncDef |
| 98672 | ** structure is created and liked into the "db" structure if a |
| 98673 | ** no matching function previously existed. |
| 98674 | ** |
| 98675 | ** If nArg is -2, then the first valid function found is returned. A |
| 98676 | ** function is valid if either xFunc or xStep is non-zero. The nArg==(-2) |
| 98677 | ** case is used to see if zName is a valid function name for some number |
| 98678 | ** of arguments. If nArg is -2, then createFlag must be 0. |
| 98679 | ** |
| 98680 | ** If createFlag is false, then a function with the required name and |
| 98681 | ** number of arguments may be returned even if the eTextRep flag does not |
| @@ -98748,11 +98793,11 @@ | |
| 98748 | memcpy(pBest->zName, zName, nName); |
| 98749 | pBest->zName[nName] = 0; |
| 98750 | sqlite3FuncDefInsert(&db->aFunc, pBest); |
| 98751 | } |
| 98752 | |
| 98753 | if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){ |
| 98754 | return pBest; |
| 98755 | } |
| 98756 | return 0; |
| 98757 | } |
| 98758 | |
| @@ -104530,11 +104575,11 @@ | |
| 104530 | if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT; |
| 104531 | if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){ |
| 104532 | assert( pParse->nested==0 ); |
| 104533 | pik_flags |= OPFLAG_NCHANGE; |
| 104534 | } |
| 104535 | if( pik_flags ) sqlite3VdbeChangeP5(v, pik_flags); |
| 104536 | } |
| 104537 | if( !HasRowid(pTab) ) return; |
| 104538 | regData = regNewData + 1; |
| 104539 | regRec = sqlite3GetTempReg(pParse); |
| 104540 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec); |
| @@ -104946,13 +104991,13 @@ | |
| 104946 | }else{ |
| 104947 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 104948 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 104949 | } |
| 104950 | sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); |
| 104951 | sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid); |
| 104952 | sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND); |
| 104953 | sqlite3VdbeChangeP4(v, -1, pDest->zName, 0); |
| 104954 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v); |
| 104955 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| 104956 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 104957 | }else{ |
| 104958 | sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName); |
| @@ -107401,19 +107446,21 @@ | |
| 107401 | { OP_IfPos, 1, 8, 0}, |
| 107402 | { OP_Integer, 0, 1, 0}, /* 6 */ |
| 107403 | { OP_Noop, 0, 0, 0}, |
| 107404 | { OP_ResultRow, 1, 1, 0}, |
| 107405 | }; |
| 107406 | int addr; |
| 107407 | sqlite3VdbeUsesBtree(v, iDb); |
| 107408 | if( !zRight ){ |
| 107409 | setOneColumnName(v, "cache_size"); |
| 107410 | pParse->nMem += 2; |
| 107411 | addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn); |
| 107412 | sqlite3VdbeChangeP1(v, addr, iDb); |
| 107413 | sqlite3VdbeChangeP1(v, addr+1, iDb); |
| 107414 | sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE); |
| 107415 | }else{ |
| 107416 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| 107417 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 107418 | sqlite3VdbeAddOp2(v, OP_Integer, size, 1); |
| 107419 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); |
| @@ -107655,17 +107702,20 @@ | |
| 107655 | { OP_If, 1, 0, 0}, /* 2 */ |
| 107656 | { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
| 107657 | { OP_Integer, 0, 1, 0}, /* 4 */ |
| 107658 | { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ |
| 107659 | }; |
| 107660 | int iAddr; |
| 107661 | iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn); |
| 107662 | sqlite3VdbeChangeP1(v, iAddr, iDb); |
| 107663 | sqlite3VdbeChangeP1(v, iAddr+1, iDb); |
| 107664 | sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4); |
| 107665 | sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); |
| 107666 | sqlite3VdbeChangeP1(v, iAddr+5, iDb); |
| 107667 | sqlite3VdbeUsesBtree(v, iDb); |
| 107668 | } |
| 107669 | } |
| 107670 | break; |
| 107671 | } |
| @@ -108367,22 +108417,10 @@ | |
| 108367 | ** without most of the overhead of a full integrity-check. |
| 108368 | */ |
| 108369 | case PragTyp_INTEGRITY_CHECK: { |
| 108370 | int i, j, addr, mxErr; |
| 108371 | |
| 108372 | /* Code that appears at the end of the integrity check. If no error |
| 108373 | ** messages have been generated, output OK. Otherwise output the |
| 108374 | ** error message |
| 108375 | */ |
| 108376 | static const int iLn = VDBE_OFFSET_LINENO(2); |
| 108377 | static const VdbeOpList endCode[] = { |
| 108378 | { OP_AddImm, 1, 0, 0}, /* 0 */ |
| 108379 | { OP_If, 1, 0, 0}, /* 1 */ |
| 108380 | { OP_String8, 0, 3, 0}, /* 2 */ |
| 108381 | { OP_ResultRow, 3, 1, 0}, |
| 108382 | }; |
| 108383 | |
| 108384 | int isQuick = (sqlite3Tolower(zLeft[0])=='q'); |
| 108385 | |
| 108386 | /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check", |
| 108387 | ** then iDb is set to the index of the database identified by <db>. |
| 108388 | ** In this case, the integrity of database iDb only is verified by |
| @@ -108575,14 +108613,28 @@ | |
| 108575 | sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1); |
| 108576 | } |
| 108577 | #endif /* SQLITE_OMIT_BTREECOUNT */ |
| 108578 | } |
| 108579 | } |
| 108580 | addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); |
| 108581 | sqlite3VdbeChangeP2(v, addr, -mxErr); |
| 108582 | sqlite3VdbeJumpHere(v, addr+1); |
| 108583 | sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC); |
| 108584 | } |
| 108585 | break; |
| 108586 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 108587 | |
| 108588 | #ifndef SQLITE_OMIT_UTF16 |
| @@ -108695,26 +108747,32 @@ | |
| 108695 | static const VdbeOpList setCookie[] = { |
| 108696 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 108697 | { OP_Integer, 0, 1, 0}, /* 1 */ |
| 108698 | { OP_SetCookie, 0, 0, 1}, /* 2 */ |
| 108699 | }; |
| 108700 | int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); |
| 108701 | sqlite3VdbeChangeP1(v, addr, iDb); |
| 108702 | sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight)); |
| 108703 | sqlite3VdbeChangeP1(v, addr+2, iDb); |
| 108704 | sqlite3VdbeChangeP2(v, addr+2, iCookie); |
| 108705 | }else{ |
| 108706 | /* Read the specified cookie value */ |
| 108707 | static const VdbeOpList readCookie[] = { |
| 108708 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 108709 | { OP_ReadCookie, 0, 1, 0}, /* 1 */ |
| 108710 | { OP_ResultRow, 1, 1, 0} |
| 108711 | }; |
| 108712 | int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0); |
| 108713 | sqlite3VdbeChangeP1(v, addr, iDb); |
| 108714 | sqlite3VdbeChangeP1(v, addr+1, iDb); |
| 108715 | sqlite3VdbeChangeP3(v, addr+1, iCookie); |
| 108716 | sqlite3VdbeSetNumCols(v, 1); |
| 108717 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); |
| 108718 | } |
| 108719 | } |
| 108720 | break; |
| @@ -109077,65 +109135,31 @@ | |
| 109077 | int rc; |
| 109078 | int i; |
| 109079 | #ifndef SQLITE_OMIT_DEPRECATED |
| 109080 | int size; |
| 109081 | #endif |
| 109082 | Table *pTab; |
| 109083 | Db *pDb; |
| 109084 | char const *azArg[4]; |
| 109085 | int meta[5]; |
| 109086 | InitData initData; |
| 109087 | char const *zMasterSchema; |
| 109088 | char const *zMasterName; |
| 109089 | int openedTransaction = 0; |
| 109090 | |
| 109091 | /* |
| 109092 | ** The master database table has a structure like this |
| 109093 | */ |
| 109094 | static const char master_schema[] = |
| 109095 | "CREATE TABLE sqlite_master(\n" |
| 109096 | " type text,\n" |
| 109097 | " name text,\n" |
| 109098 | " tbl_name text,\n" |
| 109099 | " rootpage integer,\n" |
| 109100 | " sql text\n" |
| 109101 | ")" |
| 109102 | ; |
| 109103 | #ifndef SQLITE_OMIT_TEMPDB |
| 109104 | static const char temp_master_schema[] = |
| 109105 | "CREATE TEMP TABLE sqlite_temp_master(\n" |
| 109106 | " type text,\n" |
| 109107 | " name text,\n" |
| 109108 | " tbl_name text,\n" |
| 109109 | " rootpage integer,\n" |
| 109110 | " sql text\n" |
| 109111 | ")" |
| 109112 | ; |
| 109113 | #else |
| 109114 | #define temp_master_schema 0 |
| 109115 | #endif |
| 109116 | |
| 109117 | assert( iDb>=0 && iDb<db->nDb ); |
| 109118 | assert( db->aDb[iDb].pSchema ); |
| 109119 | assert( sqlite3_mutex_held(db->mutex) ); |
| 109120 | assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 109121 | |
| 109122 | /* zMasterSchema and zInitScript are set to point at the master schema |
| 109123 | ** and initialisation script appropriate for the database being |
| 109124 | ** initialized. zMasterName is the name of the master table. |
| 109125 | */ |
| 109126 | if( !OMIT_TEMPDB && iDb==1 ){ |
| 109127 | zMasterSchema = temp_master_schema; |
| 109128 | }else{ |
| 109129 | zMasterSchema = master_schema; |
| 109130 | } |
| 109131 | zMasterName = SCHEMA_TABLE(iDb); |
| 109132 | |
| 109133 | /* Construct the schema tables. */ |
| 109134 | azArg[0] = zMasterName; |
| 109135 | azArg[1] = "1"; |
| 109136 | azArg[2] = zMasterSchema; |
| 109137 | azArg[3] = 0; |
| 109138 | initData.db = db; |
| 109139 | initData.iDb = iDb; |
| 109140 | initData.rc = SQLITE_OK; |
| 109141 | initData.pzErrMsg = pzErrMsg; |
| @@ -109142,14 +109166,10 @@ | |
| 109142 | sqlite3InitCallback(&initData, 3, (char **)azArg, 0); |
| 109143 | if( initData.rc ){ |
| 109144 | rc = initData.rc; |
| 109145 | goto error_out; |
| 109146 | } |
| 109147 | pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName); |
| 109148 | if( ALWAYS(pTab) ){ |
| 109149 | pTab->tabFlags |= TF_Readonly; |
| 109150 | } |
| 109151 | |
| 109152 | /* Create a cursor to hold the database open |
| 109153 | */ |
| 109154 | pDb = &db->aDb[iDb]; |
| 109155 | if( pDb->pBt==0 ){ |
| @@ -109264,11 +109284,11 @@ | |
| 109264 | */ |
| 109265 | assert( db->init.busy ); |
| 109266 | { |
| 109267 | char *zSql; |
| 109268 | zSql = sqlite3MPrintf(db, |
| 109269 | "SELECT name, rootpage, sql FROM '%q'.%s ORDER BY rowid", |
| 109270 | db->aDb[iDb].zName, zMasterName); |
| 109271 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 109272 | { |
| 109273 | sqlite3_xauth xAuth; |
| 109274 | xAuth = db->xAuth; |
| @@ -110841,19 +110861,20 @@ | |
| 110841 | /* |
| 110842 | ** Allocate a KeyInfo object sufficient for an index of N key columns and |
| 110843 | ** X extra columns. |
| 110844 | */ |
| 110845 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){ |
| 110846 | KeyInfo *p = sqlite3DbMallocZero(0, |
| 110847 | sizeof(KeyInfo) + (N+X)*(sizeof(CollSeq*)+1)); |
| 110848 | if( p ){ |
| 110849 | p->aSortOrder = (u8*)&p->aColl[N+X]; |
| 110850 | p->nField = (u16)N; |
| 110851 | p->nXField = (u16)X; |
| 110852 | p->enc = ENC(db); |
| 110853 | p->db = db; |
| 110854 | p->nRef = 1; |
| 110855 | }else{ |
| 110856 | db->mallocFailed = 1; |
| 110857 | } |
| 110858 | return p; |
| 110859 | } |
| @@ -116638,12 +116659,12 @@ | |
| 116638 | /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program |
| 116639 | ** is a pointer to the sub-vdbe containing the trigger program. */ |
| 116640 | if( pPrg ){ |
| 116641 | int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers)); |
| 116642 | |
| 116643 | sqlite3VdbeAddOp3(v, OP_Program, reg, ignoreJump, ++pParse->nMem); |
| 116644 | sqlite3VdbeChangeP4(v, -1, (const char *)pPrg->pProgram, P4_SUBPROGRAM); |
| 116645 | VdbeComment( |
| 116646 | (v, "Call: %s.%s", (p->zName?p->zName:"fkey"), onErrorText(orconf))); |
| 116647 | |
| 116648 | /* Set the P5 operand of the OP_Program instruction to non-zero if |
| 116649 | ** recursive invocation of this trigger program is disallowed. Recursive |
| @@ -118993,11 +119014,11 @@ | |
| 118993 | Expr *pExpr /* First argument to the function */ |
| 118994 | ){ |
| 118995 | Table *pTab; |
| 118996 | sqlite3_vtab *pVtab; |
| 118997 | sqlite3_module *pMod; |
| 118998 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**) = 0; |
| 118999 | void *pArg = 0; |
| 119000 | FuncDef *pNew; |
| 119001 | int rc = 0; |
| 119002 | char *zLowerName; |
| 119003 | unsigned char *z; |
| @@ -119021,11 +119042,11 @@ | |
| 119021 | zLowerName = sqlite3DbStrDup(db, pDef->zName); |
| 119022 | if( zLowerName ){ |
| 119023 | for(z=(unsigned char*)zLowerName; *z; z++){ |
| 119024 | *z = sqlite3UpperToLower[*z]; |
| 119025 | } |
| 119026 | rc = pMod->xFindFunction(pVtab, nArg, zLowerName, &xFunc, &pArg); |
| 119027 | sqlite3DbFree(db, zLowerName); |
| 119028 | } |
| 119029 | if( rc==0 ){ |
| 119030 | return pDef; |
| 119031 | } |
| @@ -119038,11 +119059,11 @@ | |
| 119038 | return pDef; |
| 119039 | } |
| 119040 | *pNew = *pDef; |
| 119041 | pNew->zName = (char *)&pNew[1]; |
| 119042 | memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1); |
| 119043 | pNew->xFunc = xFunc; |
| 119044 | pNew->pUserData = pArg; |
| 119045 | pNew->funcFlags |= SQLITE_FUNC_EPHEM; |
| 119046 | return pNew; |
| 119047 | } |
| 119048 | |
| @@ -120058,12 +120079,11 @@ | |
| 120058 | n--; |
| 120059 | } |
| 120060 | |
| 120061 | /* Code the OP_Affinity opcode if there is anything left to do. */ |
| 120062 | if( n>0 ){ |
| 120063 | sqlite3VdbeAddOp2(v, OP_Affinity, base, n); |
| 120064 | sqlite3VdbeChangeP4(v, -1, zAff, n); |
| 120065 | sqlite3ExprCacheAffinityChange(pParse, base, n); |
| 120066 | } |
| 120067 | } |
| 120068 | |
| 120069 | |
| @@ -133811,11 +133831,11 @@ | |
| 133811 | sqlite3 *db, |
| 133812 | const char *zFunctionName, |
| 133813 | int nArg, |
| 133814 | int enc, |
| 133815 | void *pUserData, |
| 133816 | void (*xFunc)(sqlite3_context*,int,sqlite3_value **), |
| 133817 | void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 133818 | void (*xFinal)(sqlite3_context*), |
| 133819 | FuncDestructor *pDestructor |
| 133820 | ){ |
| 133821 | FuncDef *p; |
| @@ -133822,13 +133842,13 @@ | |
| 133822 | int nName; |
| 133823 | int extraFlags; |
| 133824 | |
| 133825 | assert( sqlite3_mutex_held(db->mutex) ); |
| 133826 | if( zFunctionName==0 || |
| 133827 | (xFunc && (xFinal || xStep)) || |
| 133828 | (!xFunc && (xFinal && !xStep)) || |
| 133829 | (!xFunc && (!xFinal && xStep)) || |
| 133830 | (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || |
| 133831 | (255<(nName = sqlite3Strlen30( zFunctionName))) ){ |
| 133832 | return SQLITE_MISUSE_BKPT; |
| 133833 | } |
| 133834 | |
| @@ -133847,14 +133867,14 @@ | |
| 133847 | if( enc==SQLITE_UTF16 ){ |
| 133848 | enc = SQLITE_UTF16NATIVE; |
| 133849 | }else if( enc==SQLITE_ANY ){ |
| 133850 | int rc; |
| 133851 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags, |
| 133852 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 133853 | if( rc==SQLITE_OK ){ |
| 133854 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags, |
| 133855 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 133856 | } |
| 133857 | if( rc!=SQLITE_OK ){ |
| 133858 | return rc; |
| 133859 | } |
| 133860 | enc = SQLITE_UTF16BE; |
| @@ -133894,12 +133914,11 @@ | |
| 133894 | pDestructor->nRef++; |
| 133895 | } |
| 133896 | p->pDestructor = pDestructor; |
| 133897 | p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags; |
| 133898 | testcase( p->funcFlags & SQLITE_DETERMINISTIC ); |
| 133899 | p->xFunc = xFunc; |
| 133900 | p->xStep = xStep; |
| 133901 | p->xFinalize = xFinal; |
| 133902 | p->pUserData = pUserData; |
| 133903 | p->nArg = (u16)nArg; |
| 133904 | return SQLITE_OK; |
| 133905 | } |
| @@ -133911,25 +133930,25 @@ | |
| 133911 | sqlite3 *db, |
| 133912 | const char *zFunc, |
| 133913 | int nArg, |
| 133914 | int enc, |
| 133915 | void *p, |
| 133916 | void (*xFunc)(sqlite3_context*,int,sqlite3_value **), |
| 133917 | void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 133918 | void (*xFinal)(sqlite3_context*) |
| 133919 | ){ |
| 133920 | return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep, |
| 133921 | xFinal, 0); |
| 133922 | } |
| 133923 | |
| 133924 | SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2( |
| 133925 | sqlite3 *db, |
| 133926 | const char *zFunc, |
| 133927 | int nArg, |
| 133928 | int enc, |
| 133929 | void *p, |
| 133930 | void (*xFunc)(sqlite3_context*,int,sqlite3_value **), |
| 133931 | void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 133932 | void (*xFinal)(sqlite3_context*), |
| 133933 | void (*xDestroy)(void *) |
| 133934 | ){ |
| 133935 | int rc = SQLITE_ERROR; |
| @@ -133948,11 +133967,11 @@ | |
| 133948 | goto out; |
| 133949 | } |
| 133950 | pArg->xDestroy = xDestroy; |
| 133951 | pArg->pUserData = p; |
| 133952 | } |
| 133953 | rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg); |
| 133954 | if( pArg && pArg->nRef==0 ){ |
| 133955 | assert( rc!=SQLITE_OK ); |
| 133956 | xDestroy(p); |
| 133957 | sqlite3DbFree(db, pArg); |
| 133958 | } |
| @@ -133968,11 +133987,11 @@ | |
| 133968 | sqlite3 *db, |
| 133969 | const void *zFunctionName, |
| 133970 | int nArg, |
| 133971 | int eTextRep, |
| 133972 | void *p, |
| 133973 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
| 133974 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 133975 | void (*xFinal)(sqlite3_context*) |
| 133976 | ){ |
| 133977 | int rc; |
| 133978 | char *zFunc8; |
| @@ -133981,11 +134000,11 @@ | |
| 133981 | if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT; |
| 133982 | #endif |
| 133983 | sqlite3_mutex_enter(db->mutex); |
| 133984 | assert( !db->mallocFailed ); |
| 133985 | zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); |
| 133986 | rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0); |
| 133987 | sqlite3DbFree(db, zFunc8); |
| 133988 | rc = sqlite3ApiExit(db, rc); |
| 133989 | sqlite3_mutex_leave(db->mutex); |
| 133990 | return rc; |
| 133991 | } |
| @@ -135206,11 +135225,10 @@ | |
| 135206 | sqlite3GlobalConfig.nLookaside); |
| 135207 | |
| 135208 | sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| 135209 | |
| 135210 | opendb_out: |
| 135211 | sqlite3_free(zOpen); |
| 135212 | if( db ){ |
| 135213 | assert( db->mutex!=0 || isThreadsafe==0 |
| 135214 | || sqlite3GlobalConfig.bFullMutex==0 ); |
| 135215 | sqlite3_mutex_leave(db->mutex); |
| 135216 | } |
| @@ -135243,10 +135261,11 @@ | |
| 135243 | } |
| 135244 | sqlite3_key_v2(db, 0, zKey, i/2); |
| 135245 | } |
| 135246 | } |
| 135247 | #endif |
| 135248 | return rc & 0xff; |
| 135249 | } |
| 135250 | |
| 135251 | /* |
| 135252 | ** Open a new database handle. |
| @@ -168108,17 +168127,17 @@ | |
| 168108 | ** Buffer object for the incremental building of string data. |
| 168109 | */ |
| 168110 | typedef struct Fts5Buffer Fts5Buffer; |
| 168111 | struct Fts5Buffer { |
| 168112 | u8 *p; |
| 168113 | int n; |
| 168114 | int nSpace; |
| 168115 | }; |
| 168116 | |
| 168117 | static int sqlite3Fts5BufferSize(int*, Fts5Buffer*, int); |
| 168118 | static void sqlite3Fts5BufferAppendVarint(int*, Fts5Buffer*, i64); |
| 168119 | static void sqlite3Fts5BufferAppendBlob(int*, Fts5Buffer*, int, const u8*); |
| 168120 | static void sqlite3Fts5BufferAppendString(int *, Fts5Buffer*, const char*); |
| 168121 | static void sqlite3Fts5BufferFree(Fts5Buffer*); |
| 168122 | static void sqlite3Fts5BufferZero(Fts5Buffer*); |
| 168123 | static void sqlite3Fts5BufferSet(int*, Fts5Buffer*, int, const u8*); |
| 168124 | static void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...); |
| @@ -168221,10 +168240,33 @@ | |
| 168221 | ** sqlite3Fts5IterNext(pIter) |
| 168222 | ** ){ |
| 168223 | ** i64 iRowid = sqlite3Fts5IterRowid(pIter); |
| 168224 | ** } |
| 168225 | */ |
| 168226 | |
| 168227 | /* |
| 168228 | ** Open a new iterator to iterate though all rowids that match the |
| 168229 | ** specified token or token prefix. |
| 168230 | */ |
| @@ -168446,11 +168488,11 @@ | |
| 168446 | static int sqlite3Fts5StorageRename(Fts5Storage*, const char *zName); |
| 168447 | |
| 168448 | static int sqlite3Fts5DropAll(Fts5Config*); |
| 168449 | static int sqlite3Fts5CreateTable(Fts5Config*, const char*, const char*, int, char **); |
| 168450 | |
| 168451 | static int sqlite3Fts5StorageDelete(Fts5Storage *p, i64); |
| 168452 | static int sqlite3Fts5StorageContentInsert(Fts5Storage *p, sqlite3_value**, i64*); |
| 168453 | static int sqlite3Fts5StorageIndexInsert(Fts5Storage *p, sqlite3_value**, i64); |
| 168454 | |
| 168455 | static int sqlite3Fts5StorageIntegrity(Fts5Storage *p); |
| 168456 | |
| @@ -168466,12 +168508,10 @@ | |
| 168466 | |
| 168467 | static int sqlite3Fts5StorageConfigValue( |
| 168468 | Fts5Storage *p, const char*, sqlite3_value*, int |
| 168469 | ); |
| 168470 | |
| 168471 | static int sqlite3Fts5StorageSpecialDelete(Fts5Storage *p, i64 iDel, sqlite3_value**); |
| 168472 | |
| 168473 | static int sqlite3Fts5StorageDeleteAll(Fts5Storage *p); |
| 168474 | static int sqlite3Fts5StorageRebuild(Fts5Storage *p); |
| 168475 | static int sqlite3Fts5StorageOptimize(Fts5Storage *p); |
| 168476 | static int sqlite3Fts5StorageMerge(Fts5Storage *p, int nMerge); |
| 168477 | |
| @@ -170414,12 +170454,12 @@ | |
| 170414 | |
| 170415 | |
| 170416 | |
| 170417 | /* #include "fts5Int.h" */ |
| 170418 | |
| 170419 | static int sqlite3Fts5BufferSize(int *pRc, Fts5Buffer *pBuf, int nByte){ |
| 170420 | int nNew = pBuf->nSpace ? pBuf->nSpace*2 : 64; |
| 170421 | u8 *pNew; |
| 170422 | while( nNew<nByte ){ |
| 170423 | nNew = nNew * 2; |
| 170424 | } |
| 170425 | pNew = sqlite3_realloc(pBuf->p, nNew); |
| @@ -170460,14 +170500,14 @@ | |
| 170460 | ** is called, it is a no-op. |
| 170461 | */ |
| 170462 | static void sqlite3Fts5BufferAppendBlob( |
| 170463 | int *pRc, |
| 170464 | Fts5Buffer *pBuf, |
| 170465 | int nData, |
| 170466 | const u8 *pData |
| 170467 | ){ |
| 170468 | assert( *pRc || nData>=0 ); |
| 170469 | if( fts5BufferGrow(pRc, pBuf, nData) ) return; |
| 170470 | memcpy(&pBuf->p[pBuf->n], pData, nData); |
| 170471 | pBuf->n += nData; |
| 170472 | } |
| 170473 | |
| @@ -170721,18 +170761,21 @@ | |
| 170721 | ){ |
| 170722 | int rc = SQLITE_OK; |
| 170723 | *pbPresent = 0; |
| 170724 | if( p ){ |
| 170725 | int i; |
| 170726 | int hash; |
| 170727 | Fts5TermsetEntry *pEntry; |
| 170728 | |
| 170729 | /* Calculate a hash value for this term */ |
| 170730 | hash = 104 + iIdx; |
| 170731 | for(i=0; i<nTerm; i++){ |
| 170732 | hash += (hash << 3) + (int)pTerm[i]; |
| 170733 | } |
| 170734 | hash = hash % ArraySize(p->apHash); |
| 170735 | |
| 170736 | for(pEntry=p->apHash[hash]; pEntry; pEntry=pEntry->pNext){ |
| 170737 | if( pEntry->iIdx==iIdx |
| 170738 | && pEntry->nTerm==nTerm |
| @@ -171055,11 +171098,11 @@ | |
| 171055 | while( p[0]>='0' && p[0]<='9' && nPre<1000 ){ |
| 171056 | nPre = nPre*10 + (p[0] - '0'); |
| 171057 | p++; |
| 171058 | } |
| 171059 | |
| 171060 | if( rc==SQLITE_OK && (nPre<=0 || nPre>=1000) ){ |
| 171061 | *pzErr = sqlite3_mprintf("prefix length out of range (max 999)"); |
| 171062 | rc = SQLITE_ERROR; |
| 171063 | break; |
| 171064 | } |
| 171065 | |
| @@ -172558,11 +172601,11 @@ | |
| 172558 | assert( pNode->eType==FTS5_TERM ); |
| 172559 | assert( pNear->nPhrase==1 && pPhrase->nTerm==1 ); |
| 172560 | assert( pPhrase->aTerm[0].pSynonym==0 ); |
| 172561 | |
| 172562 | rc = sqlite3Fts5IterPoslist(pIter, pColset, |
| 172563 | (const u8**)&pPhrase->poslist.p, &pPhrase->poslist.n, &pNode->iRowid |
| 172564 | ); |
| 172565 | pNode->bNomatch = (pPhrase->poslist.n==0); |
| 172566 | return rc; |
| 172567 | } |
| 172568 | |
| @@ -174120,11 +174163,11 @@ | |
| 174120 | aPopulator[i].bOk = 1; |
| 174121 | } |
| 174122 | } |
| 174123 | |
| 174124 | return sqlite3Fts5Tokenize(pConfig, |
| 174125 | FTS5_TOKENIZE_AUX, z, n, (void*)&sCtx, fts5ExprPopulatePoslistsCb |
| 174126 | ); |
| 174127 | } |
| 174128 | |
| 174129 | static void fts5ExprClearPoslists(Fts5ExprNode *pNode){ |
| 174130 | if( pNode->eType==FTS5_TERM || pNode->eType==FTS5_STRING ){ |
| @@ -174136,53 +174179,48 @@ | |
| 174136 | } |
| 174137 | } |
| 174138 | } |
| 174139 | |
| 174140 | static int fts5ExprCheckPoslists(Fts5ExprNode *pNode, i64 iRowid){ |
| 174141 | if( pNode ){ |
| 174142 | pNode->iRowid = iRowid; |
| 174143 | pNode->bEof = 0; |
| 174144 | switch( pNode->eType ){ |
| 174145 | case FTS5_TERM: |
| 174146 | case FTS5_STRING: |
| 174147 | return (pNode->pNear->apPhrase[0]->poslist.n>0); |
| 174148 | |
| 174149 | case FTS5_AND: { |
| 174150 | int i; |
| 174151 | for(i=0; i<pNode->nChild; i++){ |
| 174152 | if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid)==0 ){ |
| 174153 | fts5ExprClearPoslists(pNode); |
| 174154 | return 0; |
| 174155 | } |
| 174156 | } |
| 174157 | break; |
| 174158 | } |
| 174159 | |
| 174160 | case FTS5_OR: { |
| 174161 | int i; |
| 174162 | int bRet = 0; |
| 174163 | for(i=0; i<pNode->nChild; i++){ |
| 174164 | if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid) ){ |
| 174165 | bRet = 1; |
| 174166 | } |
| 174167 | } |
| 174168 | if( bRet==0 ){ |
| 174169 | fts5ExprClearPoslists(pNode); |
| 174170 | } |
| 174171 | return bRet; |
| 174172 | } |
| 174173 | |
| 174174 | default: { |
| 174175 | assert( pNode->eType==FTS5_NOT ); |
| 174176 | if( 0==fts5ExprCheckPoslists(pNode->apChild[0], iRowid) |
| 174177 | || 0!=fts5ExprCheckPoslists(pNode->apChild[1], iRowid) |
| 174178 | ){ |
| 174179 | fts5ExprClearPoslists(pNode); |
| 174180 | return 0; |
| 174181 | } |
| 174182 | break; |
| 174183 | } |
| 174184 | } |
| 174185 | } |
| 174186 | return 1; |
| 174187 | } |
| 174188 | |
| @@ -176647,17 +176685,19 @@ | |
| 176647 | ){ |
| 176648 | Fts5Data *pLeaf = pIter->pLeaf; |
| 176649 | int iOff; |
| 176650 | int bNewTerm = 0; |
| 176651 | int nKeep = 0; |
| 176652 | |
| 176653 | assert( pbNewTerm==0 || *pbNewTerm==0 ); |
| 176654 | assert( p->pConfig->eDetail!=FTS5_DETAIL_NONE ); |
| 176655 | |
| 176656 | /* Search for the end of the position list within the current page. */ |
| 176657 | u8 *a = pLeaf->p; |
| 176658 | int n = pLeaf->szLeaf; |
| 176659 | |
| 176660 | ASSERT_SZLEAF_OK(pLeaf); |
| 176661 | iOff = pIter->iLeafOffset + pIter->nPos; |
| 176662 | |
| 176663 | if( iOff<n ){ |
| @@ -180673,10 +180713,51 @@ | |
| 180673 | } |
| 180674 | } |
| 180675 | |
| 180676 | return iOff; |
| 180677 | } |
| 180678 | |
| 180679 | /* |
| 180680 | ** The implementation of user-defined scalar function fts5_decode(). |
| 180681 | */ |
| 180682 | static void fts5DecodeFunction( |
| @@ -180689,10 +180770,11 @@ | |
| 180689 | const u8 *aBlob; int n; /* Record to decode */ |
| 180690 | u8 *a = 0; |
| 180691 | Fts5Buffer s; /* Build up text to return here */ |
| 180692 | int rc = SQLITE_OK; /* Return code */ |
| 180693 | int nSpace = 0; |
| 180694 | |
| 180695 | assert( nArg==2 ); |
| 180696 | memset(&s, 0, sizeof(Fts5Buffer)); |
| 180697 | iRowid = sqlite3_value_int64(apVal[0]); |
| 180698 | |
| @@ -180730,10 +180812,58 @@ | |
| 180730 | if( iRowid==FTS5_AVERAGES_ROWID ){ |
| 180731 | fts5DecodeAverages(&rc, &s, a, n); |
| 180732 | }else{ |
| 180733 | fts5DecodeStructure(&rc, &s, a, n); |
| 180734 | } |
| 180735 | }else{ |
| 180736 | Fts5Buffer term; /* Current term read from page */ |
| 180737 | int szLeaf; /* Offset of pgidx in a[] */ |
| 180738 | int iPgidxOff; |
| 180739 | int iPgidxPrev = 0; /* Previous value read from pgidx */ |
| @@ -180857,18 +180987,25 @@ | |
| 180857 | */ |
| 180858 | static int sqlite3Fts5IndexInit(sqlite3 *db){ |
| 180859 | int rc = sqlite3_create_function( |
| 180860 | db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0 |
| 180861 | ); |
| 180862 | if( rc==SQLITE_OK ){ |
| 180863 | rc = sqlite3_create_function( |
| 180864 | db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0 |
| 180865 | ); |
| 180866 | } |
| 180867 | return rc; |
| 180868 | } |
| 180869 | |
| 180870 | |
| 180871 | /* |
| 180872 | ** 2014 Jun 09 |
| 180873 | ** |
| 180874 | ** The author disclaims copyright to this source code. In place of |
| @@ -181712,45 +181849,44 @@ | |
| 181712 | |
| 181713 | return rc; |
| 181714 | } |
| 181715 | |
| 181716 | |
| 181717 | static sqlite3_stmt *fts5PrepareStatement( |
| 181718 | int *pRc, |
| 181719 | Fts5Config *pConfig, |
| 181720 | const char *zFmt, |
| 181721 | ... |
| 181722 | ){ |
| 181723 | sqlite3_stmt *pRet = 0; |
| 181724 | va_list ap; |
| 181725 | va_start(ap, zFmt); |
| 181726 | |
| 181727 | if( *pRc==SQLITE_OK ){ |
| 181728 | int rc; |
| 181729 | char *zSql = sqlite3_vmprintf(zFmt, ap); |
| 181730 | if( zSql==0 ){ |
| 181731 | rc = SQLITE_NOMEM; |
| 181732 | }else{ |
| 181733 | rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pRet, 0); |
| 181734 | if( rc!=SQLITE_OK ){ |
| 181735 | *pConfig->pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(pConfig->db)); |
| 181736 | } |
| 181737 | sqlite3_free(zSql); |
| 181738 | } |
| 181739 | *pRc = rc; |
| 181740 | } |
| 181741 | |
| 181742 | va_end(ap); |
| 181743 | return pRet; |
| 181744 | } |
| 181745 | |
| 181746 | static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){ |
| 181747 | Fts5Config *pConfig = pTab->pConfig; |
| 181748 | Fts5Sorter *pSorter; |
| 181749 | int nPhrase; |
| 181750 | int nByte; |
| 181751 | int rc = SQLITE_OK; |
| 181752 | const char *zRank = pCsr->zRank; |
| 181753 | const char *zRankArgs = pCsr->zRankArgs; |
| 181754 | |
| 181755 | nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr); |
| 181756 | nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1); |
| @@ -181764,11 +181900,11 @@ | |
| 181764 | ** is not possible as SQLite reference counts the virtual table objects. |
| 181765 | ** And since the statement required here reads from this very virtual |
| 181766 | ** table, saving it creates a circular reference. |
| 181767 | ** |
| 181768 | ** If SQLite a built-in statement cache, this wouldn't be a problem. */ |
| 181769 | pSorter->pStmt = fts5PrepareStatement(&rc, pConfig, |
| 181770 | "SELECT rowid, rank FROM %Q.%Q ORDER BY %s(%s%s%s) %s", |
| 181771 | pConfig->zDb, pConfig->zName, zRank, pConfig->zName, |
| 181772 | (zRankArgs ? ", " : ""), |
| 181773 | (zRankArgs ? zRankArgs : ""), |
| 181774 | bDesc ? "DESC" : "ASC" |
| @@ -182273,11 +182409,11 @@ | |
| 182273 | ){ |
| 182274 | int rc = SQLITE_OK; |
| 182275 | int eType1 = sqlite3_value_type(apVal[1]); |
| 182276 | if( eType1==SQLITE_INTEGER ){ |
| 182277 | sqlite3_int64 iDel = sqlite3_value_int64(apVal[1]); |
| 182278 | rc = sqlite3Fts5StorageSpecialDelete(pTab->pStorage, iDel, &apVal[2]); |
| 182279 | } |
| 182280 | return rc; |
| 182281 | } |
| 182282 | |
| 182283 | static void fts5StorageInsert( |
| @@ -182380,21 +182516,21 @@ | |
| 182380 | } |
| 182381 | |
| 182382 | /* Case 1: DELETE */ |
| 182383 | else if( nArg==1 ){ |
| 182384 | i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */ |
| 182385 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel); |
| 182386 | } |
| 182387 | |
| 182388 | /* Case 2: INSERT */ |
| 182389 | else if( eType0!=SQLITE_INTEGER ){ |
| 182390 | /* If this is a REPLACE, first remove the current entry (if any) */ |
| 182391 | if( eConflict==SQLITE_REPLACE |
| 182392 | && sqlite3_value_type(apVal[1])==SQLITE_INTEGER |
| 182393 | ){ |
| 182394 | i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */ |
| 182395 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew); |
| 182396 | } |
| 182397 | fts5StorageInsert(&rc, pTab, apVal, pRowid); |
| 182398 | } |
| 182399 | |
| 182400 | /* Case 2: UPDATE */ |
| @@ -182401,26 +182537,26 @@ | |
| 182401 | else{ |
| 182402 | i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */ |
| 182403 | i64 iNew = sqlite3_value_int64(apVal[1]); /* New rowid */ |
| 182404 | if( iOld!=iNew ){ |
| 182405 | if( eConflict==SQLITE_REPLACE ){ |
| 182406 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld); |
| 182407 | if( rc==SQLITE_OK ){ |
| 182408 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew); |
| 182409 | } |
| 182410 | fts5StorageInsert(&rc, pTab, apVal, pRowid); |
| 182411 | }else{ |
| 182412 | rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, pRowid); |
| 182413 | if( rc==SQLITE_OK ){ |
| 182414 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld); |
| 182415 | } |
| 182416 | if( rc==SQLITE_OK ){ |
| 182417 | rc = sqlite3Fts5StorageIndexInsert(pTab->pStorage, apVal, *pRowid); |
| 182418 | } |
| 182419 | } |
| 182420 | }else{ |
| 182421 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld); |
| 182422 | fts5StorageInsert(&rc, pTab, apVal, pRowid); |
| 182423 | } |
| 182424 | } |
| 182425 | } |
| 182426 | |
| @@ -182615,11 +182751,13 @@ | |
| 182615 | /* Initialize all iterators */ |
| 182616 | for(i=0; i<nIter && rc==SQLITE_OK; i++){ |
| 182617 | const u8 *a; |
| 182618 | int n; |
| 182619 | rc = fts5CsrPoslist(pCsr, i, &a, &n); |
| 182620 | sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]); |
| 182621 | } |
| 182622 | |
| 182623 | if( rc==SQLITE_OK ){ |
| 182624 | while( 1 ){ |
| 182625 | int *aInst; |
| @@ -182905,12 +183043,19 @@ | |
| 182905 | int rc = SQLITE_OK; |
| 182906 | Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; |
| 182907 | Fts5Config *pConfig = ((Fts5Table*)(pCsr->base.pVtab))->pConfig; |
| 182908 | |
| 182909 | if( pConfig->eDetail==FTS5_DETAIL_COLUMNS ){ |
| 182910 | int n; |
| 182911 | rc = sqlite3Fts5ExprPhraseCollist(pCsr->pExpr, iPhrase, &pIter->a, &n); |
| 182912 | if( rc==SQLITE_OK ){ |
| 182913 | pIter->b = &pIter->a[n]; |
| 182914 | *piCol = 0; |
| 182915 | fts5ApiPhraseNextColumn(pCtx, pIter, piCol); |
| 182916 | } |
| @@ -183451,11 +183596,11 @@ | |
| 183451 | sqlite3_context *pCtx, /* Function call context */ |
| 183452 | int nArg, /* Number of args */ |
| 183453 | sqlite3_value **apVal /* Function arguments */ |
| 183454 | ){ |
| 183455 | assert( nArg==0 ); |
| 183456 | sqlite3_result_text(pCtx, "fts5: 2016-01-14 14:19:50 d17bc2c92f4d086280e49a3cc72993be7fee2da7", -1, SQLITE_TRANSIENT); |
| 183457 | } |
| 183458 | |
| 183459 | static int fts5Init(sqlite3 *db){ |
| 183460 | static const sqlite3_module fts5Mod = { |
| 183461 | /* iVersion */ 2, |
| @@ -183936,43 +184081,56 @@ | |
| 183936 | /* |
| 183937 | ** If a row with rowid iDel is present in the %_content table, add the |
| 183938 | ** delete-markers to the FTS index necessary to delete it. Do not actually |
| 183939 | ** remove the %_content row at this time though. |
| 183940 | */ |
| 183941 | static int fts5StorageDeleteFromIndex(Fts5Storage *p, i64 iDel){ |
| 183942 | Fts5Config *pConfig = p->pConfig; |
| 183943 | sqlite3_stmt *pSeek; /* SELECT to read row iDel from %_data */ |
| 183944 | int rc; /* Return code */ |
| 183945 | |
| 183946 | rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP, &pSeek, 0); |
| 183947 | if( rc==SQLITE_OK ){ |
| 183948 | int rc2; |
| 183949 | sqlite3_bind_int64(pSeek, 1, iDel); |
| 183950 | if( sqlite3_step(pSeek)==SQLITE_ROW ){ |
| 183951 | int iCol; |
| 183952 | Fts5InsertCtx ctx; |
| 183953 | ctx.pStorage = p; |
| 183954 | ctx.iCol = -1; |
| 183955 | rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel); |
| 183956 | for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){ |
| 183957 | if( pConfig->abUnindexed[iCol-1] ) continue; |
| 183958 | ctx.szCol = 0; |
| 183959 | rc = sqlite3Fts5Tokenize(pConfig, |
| 183960 | FTS5_TOKENIZE_DOCUMENT, |
| 183961 | (const char*)sqlite3_column_text(pSeek, iCol), |
| 183962 | sqlite3_column_bytes(pSeek, iCol), |
| 183963 | (void*)&ctx, |
| 183964 | fts5StorageInsertCallback |
| 183965 | ); |
| 183966 | p->aTotalSize[iCol-1] -= (i64)ctx.szCol; |
| 183967 | } |
| 183968 | p->nTotalRow--; |
| 183969 | } |
| 183970 | rc2 = sqlite3_reset(pSeek); |
| 183971 | if( rc==SQLITE_OK ) rc = rc2; |
| 183972 | } |
| 183973 | |
| 183974 | return rc; |
| 183975 | } |
| 183976 | |
| 183977 | |
| 183978 | /* |
| @@ -184048,20 +184206,21 @@ | |
| 184048 | } |
| 184049 | |
| 184050 | /* |
| 184051 | ** Remove a row from the FTS table. |
| 184052 | */ |
| 184053 | static int sqlite3Fts5StorageDelete(Fts5Storage *p, i64 iDel){ |
| 184054 | Fts5Config *pConfig = p->pConfig; |
| 184055 | int rc; |
| 184056 | sqlite3_stmt *pDel = 0; |
| 184057 | |
| 184058 | rc = fts5StorageLoadTotals(p, 1); |
| 184059 | |
| 184060 | /* Delete the index records */ |
| 184061 | if( rc==SQLITE_OK ){ |
| 184062 | rc = fts5StorageDeleteFromIndex(p, iDel); |
| 184063 | } |
| 184064 | |
| 184065 | /* Delete the %_docsize record */ |
| 184066 | if( rc==SQLITE_OK && pConfig->bColumnsize ){ |
| 184067 | rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_DOCSIZE, &pDel, 0); |
| @@ -184075,65 +184234,10 @@ | |
| 184075 | /* Delete the %_content record */ |
| 184076 | if( pConfig->eContent==FTS5_CONTENT_NORMAL ){ |
| 184077 | if( rc==SQLITE_OK ){ |
| 184078 | rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_CONTENT, &pDel, 0); |
| 184079 | } |
| 184080 | if( rc==SQLITE_OK ){ |
| 184081 | sqlite3_bind_int64(pDel, 1, iDel); |
| 184082 | sqlite3_step(pDel); |
| 184083 | rc = sqlite3_reset(pDel); |
| 184084 | } |
| 184085 | } |
| 184086 | |
| 184087 | /* Write the averages record */ |
| 184088 | if( rc==SQLITE_OK ){ |
| 184089 | rc = fts5StorageSaveTotals(p); |
| 184090 | } |
| 184091 | |
| 184092 | return rc; |
| 184093 | } |
| 184094 | |
| 184095 | static int sqlite3Fts5StorageSpecialDelete( |
| 184096 | Fts5Storage *p, |
| 184097 | i64 iDel, |
| 184098 | sqlite3_value **apVal |
| 184099 | ){ |
| 184100 | Fts5Config *pConfig = p->pConfig; |
| 184101 | int rc; |
| 184102 | sqlite3_stmt *pDel = 0; |
| 184103 | |
| 184104 | assert( pConfig->eContent!=FTS5_CONTENT_NORMAL ); |
| 184105 | rc = fts5StorageLoadTotals(p, 1); |
| 184106 | |
| 184107 | /* Delete the index records */ |
| 184108 | if( rc==SQLITE_OK ){ |
| 184109 | int iCol; |
| 184110 | Fts5InsertCtx ctx; |
| 184111 | ctx.pStorage = p; |
| 184112 | ctx.iCol = -1; |
| 184113 | |
| 184114 | rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel); |
| 184115 | for(iCol=0; rc==SQLITE_OK && iCol<pConfig->nCol; iCol++){ |
| 184116 | if( pConfig->abUnindexed[iCol] ) continue; |
| 184117 | ctx.szCol = 0; |
| 184118 | rc = sqlite3Fts5Tokenize(pConfig, |
| 184119 | FTS5_TOKENIZE_DOCUMENT, |
| 184120 | (const char*)sqlite3_value_text(apVal[iCol]), |
| 184121 | sqlite3_value_bytes(apVal[iCol]), |
| 184122 | (void*)&ctx, |
| 184123 | fts5StorageInsertCallback |
| 184124 | ); |
| 184125 | p->aTotalSize[iCol] -= (i64)ctx.szCol; |
| 184126 | } |
| 184127 | p->nTotalRow--; |
| 184128 | } |
| 184129 | |
| 184130 | /* Delete the %_docsize record */ |
| 184131 | if( pConfig->bColumnsize ){ |
| 184132 | if( rc==SQLITE_OK ){ |
| 184133 | rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_DOCSIZE, &pDel, 0); |
| 184134 | } |
| 184135 | if( rc==SQLITE_OK ){ |
| 184136 | sqlite3_bind_int64(pDel, 1, iDel); |
| 184137 | sqlite3_step(pDel); |
| 184138 | rc = sqlite3_reset(pDel); |
| 184139 | } |
| @@ -187089,10 +187193,14 @@ | |
| 187089 | int iCol = -1; |
| 187090 | while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){ |
| 187091 | int ii = FTS5_POS2COLUMN(iPos); |
| 187092 | pCsr->aCnt[ii]++; |
| 187093 | if( iCol!=ii ){ |
| 187094 | pCsr->aDoc[ii]++; |
| 187095 | iCol = ii; |
| 187096 | } |
| 187097 | } |
| 187098 | } |
| @@ -187106,11 +187214,15 @@ | |
| 187106 | Fts5Buffer buf = {0, 0, 0}; |
| 187107 | rc = sqlite3Fts5IterPoslistBuffer(pCsr->pIter, &buf); |
| 187108 | if( rc==SQLITE_OK ){ |
| 187109 | while( 0==sqlite3Fts5PoslistNext64(buf.p, buf.n, &iOff,&iPos) ){ |
| 187110 | assert_nc( iPos>=0 && iPos<nCol ); |
| 187111 | if( iPos<nCol ) pCsr->aDoc[iPos]++; |
| 187112 | } |
| 187113 | } |
| 187114 | sqlite3Fts5BufferFree(&buf); |
| 187115 | } |
| 187116 | break; |
| @@ -187134,11 +187246,11 @@ | |
| 187134 | } |
| 187135 | } |
| 187136 | } |
| 187137 | } |
| 187138 | |
| 187139 | if( pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){ |
| 187140 | while( pCsr->aDoc[pCsr->iCol]==0 ) pCsr->iCol++; |
| 187141 | assert( pCsr->iCol<pCsr->pConfig->nCol ); |
| 187142 | } |
| 187143 | return rc; |
| 187144 | } |
| 187145 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -327,11 +327,11 @@ | |
| 327 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 328 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 329 | */ |
| 330 | #define SQLITE_VERSION "3.11.0" |
| 331 | #define SQLITE_VERSION_NUMBER 3011000 |
| 332 | #define SQLITE_SOURCE_ID "2016-01-18 17:48:28 acaf426449bf6fd3140fd63141750ff69d1119a5" |
| 333 | |
| 334 | /* |
| 335 | ** CAPI3REF: Run-Time Library Version Numbers |
| 336 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 337 | ** |
| @@ -9406,10 +9406,25 @@ | |
| 9406 | #else |
| 9407 | # define ALWAYS(X) (X) |
| 9408 | # define NEVER(X) (X) |
| 9409 | #endif |
| 9410 | |
| 9411 | /* |
| 9412 | ** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is |
| 9413 | ** defined. We need to defend against those failures when testing with |
| 9414 | ** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches |
| 9415 | ** during a normal build. The following macro can be used to disable tests |
| 9416 | ** that are always false except when SQLITE_TEST_REALLOC_STRESS is set. |
| 9417 | */ |
| 9418 | #if defined(SQLITE_TEST_REALLOC_STRESS) |
| 9419 | # define ONLY_IF_REALLOC_STRESS(X) (X) |
| 9420 | #elif !defined(NDEBUG) |
| 9421 | # define ONLY_IF_REALLOC_STRESS(X) ((X)?(assert(0),1):0) |
| 9422 | #else |
| 9423 | # define ONLY_IF_REALLOC_STRESS(X) (0) |
| 9424 | #endif |
| 9425 | |
| 9426 | /* |
| 9427 | ** Declarations used for tracing the operating system interfaces. |
| 9428 | */ |
| 9429 | #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \ |
| 9430 | (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) |
| @@ -10961,19 +10976,24 @@ | |
| 10976 | SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...); |
| 10977 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int); |
| 10978 | SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int); |
| 10979 | SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int); |
| 10980 | SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int); |
| 10981 | #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS) |
| 10982 | SQLITE_PRIVATE void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N); |
| 10983 | #else |
| 10984 | # define sqlite3VdbeVerifyNoMallocRequired(A,B) |
| 10985 | #endif |
| 10986 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno); |
| 10987 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*); |
| 10988 | SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8); |
| 10989 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1); |
| 10990 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 10991 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 10992 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 10993 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 10994 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 10995 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 10996 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 10997 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 10998 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 10999 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| @@ -12227,13 +12247,12 @@ | |
| 12247 | struct FuncDef { |
| 12248 | i16 nArg; /* Number of arguments. -1 means unlimited */ |
| 12249 | u16 funcFlags; /* Some combination of SQLITE_FUNC_* */ |
| 12250 | void *pUserData; /* User data parameter */ |
| 12251 | FuncDef *pNext; /* Next function with same name */ |
| 12252 | void (*xSFunc)(sqlite3_context*,int,sqlite3_value**); /* func or agg-step */ |
| 12253 | void (*xFinalize)(sqlite3_context*); /* Agg finalizer */ |
| 12254 | char *zName; /* SQL name of the function. */ |
| 12255 | FuncDef *pHash; /* Next with a different name but the same hash */ |
| 12256 | FuncDestructor *pDestructor; /* Reference counted destructor function */ |
| 12257 | }; |
| 12258 | |
| @@ -12312,32 +12331,32 @@ | |
| 12331 | ** FuncDef.flags variable is set to the value passed as the flags |
| 12332 | ** parameter. |
| 12333 | */ |
| 12334 | #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 12335 | {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12336 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0} |
| 12337 | #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 12338 | {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12339 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0} |
| 12340 | #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 12341 | {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12342 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0} |
| 12343 | #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ |
| 12344 | {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ |
| 12345 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0} |
| 12346 | #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ |
| 12347 | {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 12348 | pArg, 0, xFunc, 0, #zName, 0, 0} |
| 12349 | #define LIKEFUNC(zName, nArg, arg, flags) \ |
| 12350 | {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ |
| 12351 | (void *)arg, 0, likeFunc, 0, #zName, 0, 0} |
| 12352 | #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ |
| 12353 | {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \ |
| 12354 | SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName,0,0} |
| 12355 | #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \ |
| 12356 | {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ |
| 12357 | SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName,0,0} |
| 12358 | |
| 12359 | /* |
| 12360 | ** All current savepoints are stored in a linked list starting at |
| 12361 | ** sqlite3.pSavepoint. The first element in the list is the most recently |
| 12362 | ** opened savepoint. Savepoints are added to the list by the vdbe |
| @@ -16576,52 +16595,68 @@ | |
| 16595 | char tzSet; /* Timezone was set explicitly */ |
| 16596 | }; |
| 16597 | |
| 16598 | |
| 16599 | /* |
| 16600 | ** Convert zDate into one or more integers according to the conversion |
| 16601 | ** specifier zFormat. |
| 16602 | ** |
| 16603 | ** zFormat[] contains 4 characters for each integer converted, except for |
| 16604 | ** the last integer which is specified by three characters. The meaning |
| 16605 | ** of a four-character format specifiers ABCD is: |
| 16606 | ** |
| 16607 | ** A: number of digits to convert. Always "2" or "4". |
| 16608 | ** B: minimum value. Always "0" or "1". |
| 16609 | ** C: maximum value, decoded as: |
| 16610 | ** a: 12 |
| 16611 | ** b: 14 |
| 16612 | ** c: 24 |
| 16613 | ** d: 31 |
| 16614 | ** e: 59 |
| 16615 | ** f: 9999 |
| 16616 | ** D: the separator character, or \000 to indicate this is the |
| 16617 | ** last number to convert. |
| 16618 | ** |
| 16619 | ** Example: To translate an ISO-8601 date YYYY-MM-DD, the format would |
| 16620 | ** be "40f-21a-20c". The "40f-" indicates the 4-digit year followed by "-". |
| 16621 | ** The "21a-" indicates the 2-digit month followed by "-". The "20c" indicates |
| 16622 | ** the 2-digit day which is the last integer in the set. |
| 16623 | ** |
| 16624 | ** The function returns the number of successful conversions. |
| 16625 | */ |
| 16626 | static int getDigits(const char *zDate, const char *zFormat, ...){ |
| 16627 | /* The aMx[] array translates the 3rd character of each format |
| 16628 | ** spec into a max size: a b c d e f */ |
| 16629 | static const u16 aMx[] = { 12, 14, 24, 31, 59, 9999 }; |
| 16630 | va_list ap; |
| 16631 | int cnt = 0; |
| 16632 | char nextC; |
| 16633 | va_start(ap, zFormat); |
| 16634 | do{ |
| 16635 | char N = zFormat[0] - '0'; |
| 16636 | char min = zFormat[1] - '0'; |
| 16637 | int val = 0; |
| 16638 | u16 max; |
| 16639 | |
| 16640 | assert( zFormat[2]>='a' && zFormat[2]<='f' ); |
| 16641 | max = aMx[zFormat[2] - 'a']; |
| 16642 | nextC = zFormat[3]; |
| 16643 | val = 0; |
| 16644 | while( N-- ){ |
| 16645 | if( !sqlite3Isdigit(*zDate) ){ |
| 16646 | goto end_getDigits; |
| 16647 | } |
| 16648 | val = val*10 + *zDate - '0'; |
| 16649 | zDate++; |
| 16650 | } |
| 16651 | if( val<(int)min || val>(int)max || (nextC!=0 && nextC!=*zDate) ){ |
| 16652 | goto end_getDigits; |
| 16653 | } |
| 16654 | *va_arg(ap,int*) = val; |
| 16655 | zDate++; |
| 16656 | cnt++; |
| 16657 | zFormat += 4; |
| 16658 | }while( nextC ); |
| 16659 | end_getDigits: |
| 16660 | va_end(ap); |
| 16661 | return cnt; |
| 16662 | } |
| @@ -16658,11 +16693,11 @@ | |
| 16693 | goto zulu_time; |
| 16694 | }else{ |
| 16695 | return c!=0; |
| 16696 | } |
| 16697 | zDate++; |
| 16698 | if( getDigits(zDate, "20b:20e", &nHr, &nMn)!=2 ){ |
| 16699 | return 1; |
| 16700 | } |
| 16701 | zDate += 5; |
| 16702 | p->tz = sgn*(nMn + nHr*60); |
| 16703 | zulu_time: |
| @@ -16679,17 +16714,17 @@ | |
| 16714 | ** Return 1 if there is a parsing error and 0 on success. |
| 16715 | */ |
| 16716 | static int parseHhMmSs(const char *zDate, DateTime *p){ |
| 16717 | int h, m, s; |
| 16718 | double ms = 0.0; |
| 16719 | if( getDigits(zDate, "20c:20e", &h, &m)!=2 ){ |
| 16720 | return 1; |
| 16721 | } |
| 16722 | zDate += 5; |
| 16723 | if( *zDate==':' ){ |
| 16724 | zDate++; |
| 16725 | if( getDigits(zDate, "20e", &s)!=1 ){ |
| 16726 | return 1; |
| 16727 | } |
| 16728 | zDate += 2; |
| 16729 | if( *zDate=='.' && sqlite3Isdigit(zDate[1]) ){ |
| 16730 | double rScale = 1.0; |
| @@ -16773,11 +16808,11 @@ | |
| 16808 | zDate++; |
| 16809 | neg = 1; |
| 16810 | }else{ |
| 16811 | neg = 0; |
| 16812 | } |
| 16813 | if( getDigits(zDate, "40f-21a-21d", &Y, &M, &D)!=3 ){ |
| 16814 | return 1; |
| 16815 | } |
| 16816 | zDate += 10; |
| 16817 | while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; } |
| 16818 | if( parseHhMmSs(zDate, p)==0 ){ |
| @@ -63843,10 +63878,18 @@ | |
| 63878 | */ |
| 63879 | if( NEVER(pBt->pCursor) ){ |
| 63880 | sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db); |
| 63881 | return SQLITE_LOCKED_SHAREDCACHE; |
| 63882 | } |
| 63883 | |
| 63884 | /* |
| 63885 | ** It is illegal to drop the sqlite_master table on page 1. But again, |
| 63886 | ** this error is caught long before reaching this point. |
| 63887 | */ |
| 63888 | if( NEVER(iTable<2) ){ |
| 63889 | return SQLITE_CORRUPT_BKPT; |
| 63890 | } |
| 63891 | |
| 63892 | rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); |
| 63893 | if( rc ) return rc; |
| 63894 | rc = sqlite3BtreeClearTable(p, iTable, 0); |
| 63895 | if( rc ){ |
| @@ -63854,80 +63897,71 @@ | |
| 63897 | return rc; |
| 63898 | } |
| 63899 | |
| 63900 | *piMoved = 0; |
| 63901 | |
| 63902 | #ifdef SQLITE_OMIT_AUTOVACUUM |
| 63903 | freePage(pPage, &rc); |
| 63904 | releasePage(pPage); |
| 63905 | #else |
| 63906 | if( pBt->autoVacuum ){ |
| 63907 | Pgno maxRootPgno; |
| 63908 | sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &maxRootPgno); |
| 63909 | |
| 63910 | if( iTable==maxRootPgno ){ |
| 63911 | /* If the table being dropped is the table with the largest root-page |
| 63912 | ** number in the database, put the root page on the free list. |
| 63913 | */ |
| 63914 | freePage(pPage, &rc); |
| 63915 | releasePage(pPage); |
| 63916 | if( rc!=SQLITE_OK ){ |
| 63917 | return rc; |
| 63918 | } |
| 63919 | }else{ |
| 63920 | /* The table being dropped does not have the largest root-page |
| 63921 | ** number in the database. So move the page that does into the |
| 63922 | ** gap left by the deleted root-page. |
| 63923 | */ |
| 63924 | MemPage *pMove; |
| 63925 | releasePage(pPage); |
| 63926 | rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); |
| 63927 | if( rc!=SQLITE_OK ){ |
| 63928 | return rc; |
| 63929 | } |
| 63930 | rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0); |
| 63931 | releasePage(pMove); |
| 63932 | if( rc!=SQLITE_OK ){ |
| 63933 | return rc; |
| 63934 | } |
| 63935 | pMove = 0; |
| 63936 | rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); |
| 63937 | freePage(pMove, &rc); |
| 63938 | releasePage(pMove); |
| 63939 | if( rc!=SQLITE_OK ){ |
| 63940 | return rc; |
| 63941 | } |
| 63942 | *piMoved = maxRootPgno; |
| 63943 | } |
| 63944 | |
| 63945 | /* Set the new 'max-root-page' value in the database header. This |
| 63946 | ** is the old value less one, less one more if that happens to |
| 63947 | ** be a root-page number, less one again if that is the |
| 63948 | ** PENDING_BYTE_PAGE. |
| 63949 | */ |
| 63950 | maxRootPgno--; |
| 63951 | while( maxRootPgno==PENDING_BYTE_PAGE(pBt) |
| 63952 | || PTRMAP_ISPAGE(pBt, maxRootPgno) ){ |
| 63953 | maxRootPgno--; |
| 63954 | } |
| 63955 | assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) ); |
| 63956 | |
| 63957 | rc = sqlite3BtreeUpdateMeta(p, 4, maxRootPgno); |
| 63958 | }else{ |
| 63959 | freePage(pPage, &rc); |
| 63960 | releasePage(pPage); |
| 63961 | } |
| 63962 | #endif |
| 63963 | return rc; |
| 63964 | } |
| 63965 | SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree *p, int iTable, int *piMoved){ |
| 63966 | int rc; |
| 63967 | sqlite3BtreeEnter(p); |
| @@ -67010,11 +67044,11 @@ | |
| 67044 | |
| 67045 | assert( pCtx->pParse->rc==SQLITE_OK ); |
| 67046 | memset(&ctx, 0, sizeof(ctx)); |
| 67047 | ctx.pOut = pVal; |
| 67048 | ctx.pFunc = pFunc; |
| 67049 | pFunc->xSFunc(&ctx, nVal, apVal); |
| 67050 | if( ctx.isError ){ |
| 67051 | rc = ctx.isError; |
| 67052 | sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); |
| 67053 | }else{ |
| 67054 | sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); |
| @@ -67757,12 +67791,11 @@ | |
| 67791 | char c; |
| 67792 | va_start(ap, zTypes); |
| 67793 | for(i=0; (c = zTypes[i])!=0; i++){ |
| 67794 | if( c=='s' ){ |
| 67795 | const char *z = va_arg(ap, const char*); |
| 67796 | sqlite3VdbeAddOp4(p, z==0 ? OP_Null : OP_String8, 0, iDest++, 0, z, 0); |
| 67797 | }else{ |
| 67798 | assert( c=='i' ); |
| 67799 | sqlite3VdbeAddOp2(p, OP_Integer, va_arg(ap, int), iDest++); |
| 67800 | } |
| 67801 | } |
| @@ -68113,10 +68146,24 @@ | |
| 68146 | SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){ |
| 68147 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 68148 | return p->nOp; |
| 68149 | } |
| 68150 | |
| 68151 | /* |
| 68152 | ** Verify that at least N opcode slots are available in p without |
| 68153 | ** having to malloc for more space (except when compiled using |
| 68154 | ** SQLITE_TEST_REALLOC_STRESS). This interface is used during testing |
| 68155 | ** to verify that certain calls to sqlite3VdbeAddOpList() can never |
| 68156 | ** fail due to a OOM fault and hence that the return value from |
| 68157 | ** sqlite3VdbeAddOpList() will always be non-NULL. |
| 68158 | */ |
| 68159 | #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS) |
| 68160 | SQLITE_PRIVATE void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N){ |
| 68161 | assert( p->nOp + N <= p->pParse->nOpAlloc ); |
| 68162 | } |
| 68163 | #endif |
| 68164 | |
| 68165 | /* |
| 68166 | ** This function returns a pointer to the array of opcodes associated with |
| 68167 | ** the Vdbe passed as the first argument. It is the callers responsibility |
| 68168 | ** to arrange for the returned array to be eventually freed using the |
| 68169 | ** vdbeFreeOpArray() function. |
| @@ -68138,23 +68185,27 @@ | |
| 68185 | p->aOp = 0; |
| 68186 | return aOp; |
| 68187 | } |
| 68188 | |
| 68189 | /* |
| 68190 | ** Add a whole list of operations to the operation stack. Return a |
| 68191 | ** pointer to the first operation inserted. |
| 68192 | */ |
| 68193 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList( |
| 68194 | Vdbe *p, /* Add opcodes to the prepared statement */ |
| 68195 | int nOp, /* Number of opcodes to add */ |
| 68196 | VdbeOpList const *aOp, /* The opcodes to be added */ |
| 68197 | int iLineno /* Source-file line number of first opcode */ |
| 68198 | ){ |
| 68199 | int i; |
| 68200 | VdbeOp *pOut, *pFirst; |
| 68201 | assert( nOp>0 ); |
| 68202 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 68203 | if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){ |
| 68204 | return 0; |
| 68205 | } |
| 68206 | pFirst = pOut = &p->aOp[p->nOp]; |
| 68207 | for(i=0; i<nOp; i++, aOp++, pOut++){ |
| 68208 | pOut->opcode = aOp->opcode; |
| 68209 | pOut->p1 = aOp->p1; |
| 68210 | pOut->p2 = aOp->p2; |
| 68211 | assert( aOp->p2>=0 ); |
| @@ -68170,16 +68221,16 @@ | |
| 68221 | #else |
| 68222 | (void)iLineno; |
| 68223 | #endif |
| 68224 | #ifdef SQLITE_DEBUG |
| 68225 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 68226 | sqlite3VdbePrintOp(0, i+p->nOp, &p->aOp[i+p->nOp]); |
| 68227 | } |
| 68228 | #endif |
| 68229 | } |
| 68230 | p->nOp += nOp; |
| 68231 | return pFirst; |
| 68232 | } |
| 68233 | |
| 68234 | #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) |
| 68235 | /* |
| 68236 | ** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus(). |
| @@ -68223,11 +68274,11 @@ | |
| 68274 | } |
| 68275 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){ |
| 68276 | sqlite3VdbeGetOp(p,addr)->p3 = val; |
| 68277 | } |
| 68278 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){ |
| 68279 | if( !p->db->mallocFailed ) p->aOp[p->nOp-1].p5 = p5; |
| 68280 | } |
| 68281 | |
| 68282 | /* |
| 68283 | ** Change the P2 operand of instruction addr so that it points to |
| 68284 | ** the address of the next instruction to be coded. |
| @@ -68333,28 +68384,28 @@ | |
| 68384 | } |
| 68385 | |
| 68386 | /* |
| 68387 | ** Change the opcode at addr into OP_Noop |
| 68388 | */ |
| 68389 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe *p, int addr){ |
| 68390 | VdbeOp *pOp; |
| 68391 | if( p->db->mallocFailed ) return 0; |
| 68392 | assert( addr>=0 && addr<p->nOp ); |
| 68393 | pOp = &p->aOp[addr]; |
| 68394 | freeP4(p->db, pOp->p4type, pOp->p4.p); |
| 68395 | memset(pOp, 0, sizeof(pOp[0])); |
| 68396 | pOp->opcode = OP_Noop; |
| 68397 | return 1; |
| 68398 | } |
| 68399 | |
| 68400 | /* |
| 68401 | ** If the last opcode is "op" and it is not a jump destination, |
| 68402 | ** then remove it. Return true if and only if an opcode was removed. |
| 68403 | */ |
| 68404 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe *p, u8 op){ |
| 68405 | if( (p->nOp-1)>(p->pParse->iFixedOp) && p->aOp[p->nOp-1].opcode==op ){ |
| 68406 | return sqlite3VdbeChangeToNoop(p, p->nOp-1); |
| 68407 | }else{ |
| 68408 | return 0; |
| 68409 | } |
| 68410 | } |
| 68411 | |
| @@ -72726,11 +72777,11 @@ | |
| 72777 | ** Allocate or return the aggregate context for a user function. A new |
| 72778 | ** context is allocated on the first call. Subsequent calls return the |
| 72779 | ** same context that was returned on prior calls. |
| 72780 | */ |
| 72781 | SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context *p, int nByte){ |
| 72782 | assert( p && p->pFunc && p->pFunc->xFinalize ); |
| 72783 | assert( sqlite3_mutex_held(p->pOut->db->mutex) ); |
| 72784 | testcase( nByte<0 ); |
| 72785 | if( (p->pMem->flags & MEM_Agg)==0 ){ |
| 72786 | return createAggContext(p, nByte); |
| 72787 | }else{ |
| @@ -72817,11 +72868,11 @@ | |
| 72868 | ** provide only to avoid breaking legacy code. New aggregate function |
| 72869 | ** implementations should keep their own counts within their aggregate |
| 72870 | ** context. |
| 72871 | */ |
| 72872 | SQLITE_API int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context *p){ |
| 72873 | assert( p && p->pMem && p->pFunc && p->pFunc->xFinalize ); |
| 72874 | return p->pMem->n; |
| 72875 | } |
| 72876 | #endif |
| 72877 | |
| 72878 | /* |
| @@ -75560,12 +75611,12 @@ | |
| 75611 | } |
| 75612 | #endif |
| 75613 | MemSetTypeFlag(pCtx->pOut, MEM_Null); |
| 75614 | pCtx->fErrorOrAux = 0; |
| 75615 | db->lastRowid = lastRowid; |
| 75616 | (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */ |
| 75617 | lastRowid = db->lastRowid; /* Remember rowid changes made by xSFunc */ |
| 75618 | |
| 75619 | /* If the function returned an error, throw an exception */ |
| 75620 | if( pCtx->fErrorOrAux ){ |
| 75621 | if( pCtx->isError ){ |
| 75622 | sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); |
| @@ -78997,10 +79048,11 @@ | |
| 79048 | case OP_Destroy: { /* out2 */ |
| 79049 | int iMoved; |
| 79050 | int iDb; |
| 79051 | |
| 79052 | assert( p->readOnly==0 ); |
| 79053 | assert( pOp->p1>1 ); |
| 79054 | pOut = out2Prerelease(p, pOp); |
| 79055 | pOut->flags = MEM_Null; |
| 79056 | if( db->nVdbeRead > db->nVDestroy+1 ){ |
| 79057 | rc = SQLITE_LOCKED; |
| 79058 | p->errorAction = OE_Abort; |
| @@ -79801,11 +79853,11 @@ | |
| 79853 | pMem->n++; |
| 79854 | sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 79855 | pCtx->pOut = &t; |
| 79856 | pCtx->fErrorOrAux = 0; |
| 79857 | pCtx->skipFlag = 0; |
| 79858 | (pCtx->pFunc->xSFunc)(pCtx,pCtx->argc,pCtx->argv); /* IMP: R-24505-23230 */ |
| 79859 | if( pCtx->fErrorOrAux ){ |
| 79860 | if( pCtx->isError ){ |
| 79861 | sqlite3VdbeError(p, "%s", sqlite3_value_text(&t)); |
| 79862 | rc = pCtx->isError; |
| 79863 | } |
| @@ -80799,42 +80851,10 @@ | |
| 80851 | int flags, /* True -> read/write access, false -> read-only */ |
| 80852 | sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */ |
| 80853 | ){ |
| 80854 | int nAttempt = 0; |
| 80855 | int iCol; /* Index of zColumn in row-record */ |
| 80856 | int rc = SQLITE_OK; |
| 80857 | char *zErr = 0; |
| 80858 | Table *pTab; |
| 80859 | Parse *pParse = 0; |
| 80860 | Incrblob *pBlob = 0; |
| @@ -80949,49 +80969,84 @@ | |
| 80969 | } |
| 80970 | |
| 80971 | pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse); |
| 80972 | assert( pBlob->pStmt || db->mallocFailed ); |
| 80973 | if( pBlob->pStmt ){ |
| 80974 | |
| 80975 | /* This VDBE program seeks a btree cursor to the identified |
| 80976 | ** db/table/row entry. The reason for using a vdbe program instead |
| 80977 | ** of writing code to use the b-tree layer directly is that the |
| 80978 | ** vdbe program will take advantage of the various transaction, |
| 80979 | ** locking and error handling infrastructure built into the vdbe. |
| 80980 | ** |
| 80981 | ** After seeking the cursor, the vdbe executes an OP_ResultRow. |
| 80982 | ** Code external to the Vdbe then "borrows" the b-tree cursor and |
| 80983 | ** uses it to implement the blob_read(), blob_write() and |
| 80984 | ** blob_bytes() functions. |
| 80985 | ** |
| 80986 | ** The sqlite3_blob_close() function finalizes the vdbe program, |
| 80987 | ** which closes the b-tree cursor and (possibly) commits the |
| 80988 | ** transaction. |
| 80989 | */ |
| 80990 | static const int iLn = VDBE_OFFSET_LINENO(4); |
| 80991 | static const VdbeOpList openBlob[] = { |
| 80992 | /* addr/ofst */ |
| 80993 | /* {OP_Transaction, 0, 0, 0}, // 0/ inserted separately */ |
| 80994 | {OP_TableLock, 0, 0, 0}, /* 1/0: Acquire a read or write lock */ |
| 80995 | {OP_OpenRead, 0, 0, 0}, /* 2/1: Open a cursor */ |
| 80996 | {OP_Variable, 1, 1, 0}, /* 3/2: Move ?1 into reg[1] */ |
| 80997 | {OP_NotExists, 0, 8, 1}, /* 4/3: Seek the cursor */ |
| 80998 | {OP_Column, 0, 0, 1}, /* 5/4 */ |
| 80999 | {OP_ResultRow, 1, 0, 0}, /* 6/5 */ |
| 81000 | {OP_Goto, 0, 3, 0}, /* 7/6 */ |
| 81001 | {OP_Close, 0, 0, 0}, /* 8/7 */ |
| 81002 | {OP_Halt, 0, 0, 0}, /* 9/8 */ |
| 81003 | }; |
| 81004 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 81005 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 81006 | VdbeOp *aOp; |
| 81007 | |
| 81008 | sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags, |
| 81009 | pTab->pSchema->schema_cookie, |
| 81010 | pTab->pSchema->iGeneration); |
| 81011 | sqlite3VdbeChangeP5(v, 1); |
| 81012 | aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn); |
| 81013 | |
| 81014 | /* Make sure a mutex is held on the table to be accessed */ |
| 81015 | sqlite3VdbeUsesBtree(v, iDb); |
| 81016 | |
| 81017 | if( db->mallocFailed==0 ){ |
| 81018 | assert( aOp!=0 ); |
| 81019 | /* Configure the OP_TableLock instruction */ |
| 81020 | #ifdef SQLITE_OMIT_SHARED_CACHE |
| 81021 | aOp[0].opcode = OP_Noop; |
| 81022 | #else |
| 81023 | aOp[0].p1 = iDb; |
| 81024 | aOp[0].p2 = pTab->tnum; |
| 81025 | aOp[0].p3 = flags; |
| 81026 | sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT); |
| 81027 | } |
| 81028 | if( db->mallocFailed==0 ){ |
| 81029 | #endif |
| 81030 | |
| 81031 | /* Remove either the OP_OpenWrite or OpenRead. Set the P2 |
| 81032 | ** parameter of the other to pTab->tnum. */ |
| 81033 | if( flags ) aOp[1].opcode = OP_OpenWrite; |
| 81034 | aOp[1].p2 = pTab->tnum; |
| 81035 | aOp[1].p3 = iDb; |
| 81036 | |
| 81037 | /* Configure the number of columns. Configure the cursor to |
| 81038 | ** think that the table has one more column than it really |
| 81039 | ** does. An OP_Column to retrieve this imaginary column will |
| 81040 | ** always return an SQL NULL. This is useful because it means |
| 81041 | ** we can invoke OP_Column to fill in the vdbe cursors type |
| 81042 | ** and offset cache without causing any IO. |
| 81043 | */ |
| 81044 | aOp[1].p4type = P4_INT32; |
| 81045 | aOp[1].p4.i = pTab->nCol+1; |
| 81046 | aOp[4].p2 = pTab->nCol; |
| 81047 | |
| 81048 | pParse->nVar = 1; |
| 81049 | pParse->nMem = 1; |
| 81050 | pParse->nTab = 1; |
| 81051 | sqlite3VdbeMakeReady(v, pParse); |
| 81052 | } |
| @@ -85251,11 +85306,11 @@ | |
| 85306 | no_such_func = 1; |
| 85307 | }else{ |
| 85308 | wrong_num_args = 1; |
| 85309 | } |
| 85310 | }else{ |
| 85311 | is_agg = pDef->xFinalize!=0; |
| 85312 | if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){ |
| 85313 | ExprSetProperty(pExpr, EP_Unlikely|EP_Skip); |
| 85314 | if( n==2 ){ |
| 85315 | pExpr->iTable = exprProbability(pList->a[1].pExpr); |
| 85316 | if( pExpr->iTable<0 ){ |
| @@ -87218,14 +87273,15 @@ | |
| 87273 | ExprList *pList, /* List to which to append. Might be NULL */ |
| 87274 | Expr *pExpr /* Expression to be appended. Might be NULL */ |
| 87275 | ){ |
| 87276 | sqlite3 *db = pParse->db; |
| 87277 | if( pList==0 ){ |
| 87278 | pList = sqlite3DbMallocRaw(db, sizeof(ExprList) ); |
| 87279 | if( pList==0 ){ |
| 87280 | goto no_mem; |
| 87281 | } |
| 87282 | pList->nExpr = 0; |
| 87283 | pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0])); |
| 87284 | if( pList->a==0 ) goto no_mem; |
| 87285 | }else if( (pList->nExpr & (pList->nExpr-1))==0 ){ |
| 87286 | struct ExprList_item *a; |
| 87287 | assert( pList->nExpr>0 ); |
| @@ -88979,11 +89035,11 @@ | |
| 89035 | nFarg = pFarg ? pFarg->nExpr : 0; |
| 89036 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 89037 | zId = pExpr->u.zToken; |
| 89038 | nId = sqlite3Strlen30(zId); |
| 89039 | pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0); |
| 89040 | if( pDef==0 || pDef->xFinalize!=0 ){ |
| 89041 | sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId); |
| 89042 | break; |
| 89043 | } |
| 89044 | |
| 89045 | /* Attempt a direct implementation of the built-in COALESCE() and |
| @@ -91651,12 +91707,11 @@ | |
| 91707 | static const FuncDef statInitFuncdef = { |
| 91708 | 2+IsStat34, /* nArg */ |
| 91709 | SQLITE_UTF8, /* funcFlags */ |
| 91710 | 0, /* pUserData */ |
| 91711 | 0, /* pNext */ |
| 91712 | statInit, /* xSFunc */ |
| 91713 | 0, /* xFinalize */ |
| 91714 | "stat_init", /* zName */ |
| 91715 | 0, /* pHash */ |
| 91716 | 0 /* pDestructor */ |
| 91717 | }; |
| @@ -91952,12 +92007,11 @@ | |
| 92007 | static const FuncDef statPushFuncdef = { |
| 92008 | 2+IsStat34, /* nArg */ |
| 92009 | SQLITE_UTF8, /* funcFlags */ |
| 92010 | 0, /* pUserData */ |
| 92011 | 0, /* pNext */ |
| 92012 | statPush, /* xSFunc */ |
| 92013 | 0, /* xFinalize */ |
| 92014 | "stat_push", /* zName */ |
| 92015 | 0, /* pHash */ |
| 92016 | 0 /* pDestructor */ |
| 92017 | }; |
| @@ -92099,12 +92153,11 @@ | |
| 92153 | static const FuncDef statGetFuncdef = { |
| 92154 | 1+IsStat34, /* nArg */ |
| 92155 | SQLITE_UTF8, /* funcFlags */ |
| 92156 | 0, /* pUserData */ |
| 92157 | 0, /* pNext */ |
| 92158 | statGet, /* xSFunc */ |
| 92159 | 0, /* xFinalize */ |
| 92160 | "stat_get", /* zName */ |
| 92161 | 0, /* pHash */ |
| 92162 | 0 /* pDestructor */ |
| 92163 | }; |
| @@ -92116,12 +92169,12 @@ | |
| 92169 | #elif SQLITE_DEBUG |
| 92170 | assert( iParam==STAT_GET_STAT1 ); |
| 92171 | #else |
| 92172 | UNUSED_PARAMETER( iParam ); |
| 92173 | #endif |
| 92174 | sqlite3VdbeAddOp4(v, OP_Function0, 0, regStat4, regOut, |
| 92175 | (char*)&statGetFuncdef, P4_FUNCDEF); |
| 92176 | sqlite3VdbeChangeP5(v, 1 + IsStat34); |
| 92177 | } |
| 92178 | |
| 92179 | /* |
| 92180 | ** Generate code to do an analysis of all indices associated with |
| @@ -92271,12 +92324,12 @@ | |
| 92324 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 92325 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+3); |
| 92326 | #endif |
| 92327 | sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat4+1); |
| 92328 | sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regStat4+2); |
| 92329 | sqlite3VdbeAddOp4(v, OP_Function0, 0, regStat4+1, regStat4, |
| 92330 | (char*)&statInitFuncdef, P4_FUNCDEF); |
| 92331 | sqlite3VdbeChangeP5(v, 2+IsStat34); |
| 92332 | |
| 92333 | /* Implementation of the following: |
| 92334 | ** |
| 92335 | ** Rewind csr |
| @@ -92368,12 +92421,12 @@ | |
| 92421 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid); |
| 92422 | sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol); |
| 92423 | } |
| 92424 | #endif |
| 92425 | assert( regChng==(regStat4+1) ); |
| 92426 | sqlite3VdbeAddOp4(v, OP_Function0, 1, regStat4, regTemp, |
| 92427 | (char*)&statPushFuncdef, P4_FUNCDEF); |
| 92428 | sqlite3VdbeChangeP5(v, 2+IsStat34); |
| 92429 | sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v); |
| 92430 | |
| 92431 | /* Add the entry to the stat1 table. */ |
| 92432 | callStatGet(v, regStat4, STAT_GET_STAT1, regStat1); |
| @@ -93426,15 +93479,15 @@ | |
| 93479 | sqlite3ExprCode(pParse, pDbname, regArgs+1); |
| 93480 | sqlite3ExprCode(pParse, pKey, regArgs+2); |
| 93481 | |
| 93482 | assert( v || db->mallocFailed ); |
| 93483 | if( v ){ |
| 93484 | sqlite3VdbeAddOp4(v, OP_Function0, 0, regArgs+3-pFunc->nArg, regArgs+3, |
| 93485 | (char *)pFunc, P4_FUNCDEF); |
| 93486 | assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg ); |
| 93487 | sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg)); |
| 93488 | |
| 93489 | /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this |
| 93490 | ** statement only). For DETACH, set it to false (expire all existing |
| 93491 | ** statements). |
| 93492 | */ |
| 93493 | sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH)); |
| @@ -93455,12 +93508,11 @@ | |
| 93508 | static const FuncDef detach_func = { |
| 93509 | 1, /* nArg */ |
| 93510 | SQLITE_UTF8, /* funcFlags */ |
| 93511 | 0, /* pUserData */ |
| 93512 | 0, /* pNext */ |
| 93513 | detachFunc, /* xSFunc */ |
| 93514 | 0, /* xFinalize */ |
| 93515 | "sqlite_detach", /* zName */ |
| 93516 | 0, /* pHash */ |
| 93517 | 0 /* pDestructor */ |
| 93518 | }; |
| @@ -93476,12 +93528,11 @@ | |
| 93528 | static const FuncDef attach_func = { |
| 93529 | 3, /* nArg */ |
| 93530 | SQLITE_UTF8, /* funcFlags */ |
| 93531 | 0, /* pUserData */ |
| 93532 | 0, /* pNext */ |
| 93533 | attachFunc, /* xSFunc */ |
| 93534 | 0, /* xFinalize */ |
| 93535 | "sqlite_attach", /* zName */ |
| 93536 | 0, /* pHash */ |
| 93537 | 0 /* pDestructor */ |
| 93538 | }; |
| @@ -94145,19 +94196,23 @@ | |
| 94196 | /* A minimum of one cursor is required if autoincrement is used |
| 94197 | * See ticket [a696379c1f08866] */ |
| 94198 | if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1; |
| 94199 | sqlite3VdbeMakeReady(v, pParse); |
| 94200 | pParse->rc = SQLITE_DONE; |
| 94201 | }else{ |
| 94202 | pParse->rc = SQLITE_ERROR; |
| 94203 | } |
| 94204 | |
| 94205 | /* We are done with this Parse object. There is no need to de-initialize it */ |
| 94206 | #if 0 |
| 94207 | pParse->colNamesSet = 0; |
| 94208 | pParse->nTab = 0; |
| 94209 | pParse->nMem = 0; |
| 94210 | pParse->nSet = 0; |
| 94211 | pParse->nVar = 0; |
| 94212 | DbMaskZero(pParse->cookieMask); |
| 94213 | #endif |
| 94214 | } |
| 94215 | |
| 94216 | /* |
| 94217 | ** Run the parser and code generator recursively in order to generate |
| 94218 | ** code for the SQL statement given onto the end of the pParse context |
| @@ -94412,11 +94467,10 @@ | |
| 94467 | if( j<i ){ |
| 94468 | db->aDb[j] = db->aDb[i]; |
| 94469 | } |
| 94470 | j++; |
| 94471 | } |
| 94472 | db->nDb = j; |
| 94473 | if( db->nDb<=2 && db->aDb!=db->aDbStatic ){ |
| 94474 | memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0])); |
| 94475 | sqlite3DbFree(db, db->aDb); |
| 94476 | db->aDb = db->aDbStatic; |
| @@ -94675,11 +94729,12 @@ | |
| 94729 | Token **pUnqual /* Write the unqualified object name here */ |
| 94730 | ){ |
| 94731 | int iDb; /* Database holding the object */ |
| 94732 | sqlite3 *db = pParse->db; |
| 94733 | |
| 94734 | assert( pName2!=0 ); |
| 94735 | if( pName2->n>0 ){ |
| 94736 | if( db->init.busy ) { |
| 94737 | sqlite3ErrorMsg(pParse, "corrupt database"); |
| 94738 | return -1; |
| 94739 | } |
| 94740 | *pUnqual = pName2; |
| @@ -94764,66 +94819,50 @@ | |
| 94819 | sqlite3 *db = pParse->db; |
| 94820 | Vdbe *v; |
| 94821 | int iDb; /* Database number to create the table in */ |
| 94822 | Token *pName; /* Unqualified name of the table to create */ |
| 94823 | |
| 94824 | if( db->init.busy && db->init.newTnum==1 ){ |
| 94825 | /* Special case: Parsing the sqlite_master or sqlite_temp_master schema */ |
| 94826 | iDb = db->init.iDb; |
| 94827 | zName = sqlite3DbStrDup(db, SCHEMA_TABLE(iDb)); |
| 94828 | pName = pName1; |
| 94829 | }else{ |
| 94830 | /* The common case */ |
| 94831 | iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName); |
| 94832 | if( iDb<0 ) return; |
| 94833 | if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){ |
| 94834 | /* If creating a temp table, the name may not be qualified. Unless |
| 94835 | ** the database name is "temp" anyway. */ |
| 94836 | sqlite3ErrorMsg(pParse, "temporary table name must be unqualified"); |
| 94837 | return; |
| 94838 | } |
| 94839 | if( !OMIT_TEMPDB && isTemp ) iDb = 1; |
| 94840 | zName = sqlite3NameFromToken(db, pName); |
| 94841 | } |
| 94842 | pParse->sNameToken = *pName; |
| 94843 | if( zName==0 ) return; |
| 94844 | if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ |
| 94845 | goto begin_table_error; |
| 94846 | } |
| 94847 | if( db->init.iDb==1 ) isTemp = 1; |
| 94848 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 94849 | assert( isTemp==0 || isTemp==1 ); |
| 94850 | assert( isView==0 || isView==1 ); |
| 94851 | { |
| 94852 | static const u8 aCode[] = { |
| 94853 | SQLITE_CREATE_TABLE, |
| 94854 | SQLITE_CREATE_TEMP_TABLE, |
| 94855 | SQLITE_CREATE_VIEW, |
| 94856 | SQLITE_CREATE_TEMP_VIEW |
| 94857 | }; |
| 94858 | char *zDb = db->aDb[iDb].zName; |
| 94859 | if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){ |
| 94860 | goto begin_table_error; |
| 94861 | } |
| 94862 | if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView], |
| 94863 | zName, 0, zDb) ){ |
| 94864 | goto begin_table_error; |
| 94865 | } |
| 94866 | } |
| 94867 | #endif |
| 94868 | |
| @@ -95781,13 +95820,17 @@ | |
| 95820 | /* If the db->init.busy is 1 it means we are reading the SQL off the |
| 95821 | ** "sqlite_master" or "sqlite_temp_master" table on the disk. |
| 95822 | ** So do not write to the disk again. Extract the root page number |
| 95823 | ** for the table from the db->init.newTnum field. (The page number |
| 95824 | ** should have been put there by the sqliteOpenCb routine.) |
| 95825 | ** |
| 95826 | ** If the root page number is 1, that means this is the sqlite_master |
| 95827 | ** table itself. So mark it read-only. |
| 95828 | */ |
| 95829 | if( db->init.busy ){ |
| 95830 | p->tnum = db->init.newTnum; |
| 95831 | if( p->tnum==1 ) p->tabFlags |= TF_Readonly; |
| 95832 | } |
| 95833 | |
| 95834 | /* Special processing for WITHOUT ROWID Tables */ |
| 95835 | if( tabOpts & TF_WithoutRowid ){ |
| 95836 | if( (p->tabFlags & TF_Autoincrement) ){ |
| @@ -96236,10 +96279,11 @@ | |
| 96279 | ** erasing iTable (this can happen with an auto-vacuum database). |
| 96280 | */ |
| 96281 | static void destroyRootPage(Parse *pParse, int iTable, int iDb){ |
| 96282 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 96283 | int r1 = sqlite3GetTempReg(pParse); |
| 96284 | assert( iTable>1 ); |
| 96285 | sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb); |
| 96286 | sqlite3MayAbort(pParse); |
| 96287 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 96288 | /* OP_Destroy stores an in integer r1. If this integer |
| 96289 | ** is non-zero, then it is the root page number of a table moved to |
| @@ -97634,13 +97678,14 @@ | |
| 97678 | Token *pDatabase /* Database of the table */ |
| 97679 | ){ |
| 97680 | struct SrcList_item *pItem; |
| 97681 | assert( pDatabase==0 || pTable!=0 ); /* Cannot have C without B */ |
| 97682 | if( pList==0 ){ |
| 97683 | pList = sqlite3DbMallocRaw(db, sizeof(SrcList) ); |
| 97684 | if( pList==0 ) return 0; |
| 97685 | pList->nAlloc = 1; |
| 97686 | pList->nSrc = 0; |
| 97687 | } |
| 97688 | pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc); |
| 97689 | if( db->mallocFailed ){ |
| 97690 | sqlite3SrcListDelete(db, pList); |
| 97691 | return 0; |
| @@ -98039,11 +98084,11 @@ | |
| 98084 | assert( (errCode&0xff)==SQLITE_CONSTRAINT ); |
| 98085 | if( onError==OE_Abort ){ |
| 98086 | sqlite3MayAbort(pParse); |
| 98087 | } |
| 98088 | sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type); |
| 98089 | sqlite3VdbeChangeP5(v, p5Errmsg); |
| 98090 | } |
| 98091 | |
| 98092 | /* |
| 98093 | ** Code an OP_Halt due to UNIQUE or PRIMARY KEY constraint violation. |
| 98094 | */ |
| @@ -98580,12 +98625,12 @@ | |
| 98625 | ** 3: encoding matches and function takes any number of arguments |
| 98626 | ** 4: UTF8/16 conversion required - argument count matches exactly |
| 98627 | ** 5: UTF16 byte order conversion required - argument count matches exactly |
| 98628 | ** 6: Perfect match: encoding and argument count match exactly. |
| 98629 | ** |
| 98630 | ** If nArg==(-2) then any function with a non-null xSFunc is |
| 98631 | ** a perfect match and any function with xSFunc NULL is |
| 98632 | ** a non-match. |
| 98633 | */ |
| 98634 | #define FUNC_PERFECT_MATCH 6 /* The score for a perfect match */ |
| 98635 | static int matchQuality( |
| 98636 | FuncDef *p, /* The function we are evaluating for match quality */ |
| @@ -98593,11 +98638,11 @@ | |
| 98638 | u8 enc /* Desired text encoding */ |
| 98639 | ){ |
| 98640 | int match; |
| 98641 | |
| 98642 | /* nArg of -2 is a special case */ |
| 98643 | if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH; |
| 98644 | |
| 98645 | /* Wrong number of arguments means "no match" */ |
| 98646 | if( p->nArg!=nArg && p->nArg>=0 ) return 0; |
| 98647 | |
| 98648 | /* Give a better score to a function with a specific number of arguments |
| @@ -98671,11 +98716,11 @@ | |
| 98716 | ** If the createFlag argument is true, then a new (blank) FuncDef |
| 98717 | ** structure is created and liked into the "db" structure if a |
| 98718 | ** no matching function previously existed. |
| 98719 | ** |
| 98720 | ** If nArg is -2, then the first valid function found is returned. A |
| 98721 | ** function is valid if xSFunc is non-zero. The nArg==(-2) |
| 98722 | ** case is used to see if zName is a valid function name for some number |
| 98723 | ** of arguments. If nArg is -2, then createFlag must be 0. |
| 98724 | ** |
| 98725 | ** If createFlag is false, then a function with the required name and |
| 98726 | ** number of arguments may be returned even if the eTextRep flag does not |
| @@ -98748,11 +98793,11 @@ | |
| 98793 | memcpy(pBest->zName, zName, nName); |
| 98794 | pBest->zName[nName] = 0; |
| 98795 | sqlite3FuncDefInsert(&db->aFunc, pBest); |
| 98796 | } |
| 98797 | |
| 98798 | if( pBest && (pBest->xSFunc || createFlag) ){ |
| 98799 | return pBest; |
| 98800 | } |
| 98801 | return 0; |
| 98802 | } |
| 98803 | |
| @@ -104530,11 +104575,11 @@ | |
| 104575 | if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT; |
| 104576 | if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){ |
| 104577 | assert( pParse->nested==0 ); |
| 104578 | pik_flags |= OPFLAG_NCHANGE; |
| 104579 | } |
| 104580 | sqlite3VdbeChangeP5(v, pik_flags); |
| 104581 | } |
| 104582 | if( !HasRowid(pTab) ) return; |
| 104583 | regData = regNewData + 1; |
| 104584 | regRec = sqlite3GetTempReg(pParse); |
| 104585 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec); |
| @@ -104946,13 +104991,13 @@ | |
| 104991 | }else{ |
| 104992 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 104993 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 104994 | } |
| 104995 | sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); |
| 104996 | sqlite3VdbeAddOp4(v, OP_Insert, iDest, regData, regRowid, |
| 104997 | pDest->zName, 0); |
| 104998 | sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND); |
| 104999 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v); |
| 105000 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| 105001 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 105002 | }else{ |
| 105003 | sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName); |
| @@ -107401,19 +107446,21 @@ | |
| 107446 | { OP_IfPos, 1, 8, 0}, |
| 107447 | { OP_Integer, 0, 1, 0}, /* 6 */ |
| 107448 | { OP_Noop, 0, 0, 0}, |
| 107449 | { OP_ResultRow, 1, 1, 0}, |
| 107450 | }; |
| 107451 | VdbeOp *aOp; |
| 107452 | sqlite3VdbeUsesBtree(v, iDb); |
| 107453 | if( !zRight ){ |
| 107454 | setOneColumnName(v, "cache_size"); |
| 107455 | pParse->nMem += 2; |
| 107456 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(getCacheSize)); |
| 107457 | aOp = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize, iLn); |
| 107458 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
| 107459 | aOp[0].p1 = iDb; |
| 107460 | aOp[1].p1 = iDb; |
| 107461 | aOp[6].p1 = SQLITE_DEFAULT_CACHE_SIZE; |
| 107462 | }else{ |
| 107463 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| 107464 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 107465 | sqlite3VdbeAddOp2(v, OP_Integer, size, 1); |
| 107466 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); |
| @@ -107655,17 +107702,20 @@ | |
| 107702 | { OP_If, 1, 0, 0}, /* 2 */ |
| 107703 | { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
| 107704 | { OP_Integer, 0, 1, 0}, /* 4 */ |
| 107705 | { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ |
| 107706 | }; |
| 107707 | VdbeOp *aOp; |
| 107708 | int iAddr = sqlite3VdbeCurrentAddr(v); |
| 107709 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setMeta6)); |
| 107710 | aOp = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn); |
| 107711 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
| 107712 | aOp[0].p1 = iDb; |
| 107713 | aOp[1].p1 = iDb; |
| 107714 | aOp[2].p2 = iAddr+4; |
| 107715 | aOp[4].p1 = eAuto - 1; |
| 107716 | aOp[5].p1 = iDb; |
| 107717 | sqlite3VdbeUsesBtree(v, iDb); |
| 107718 | } |
| 107719 | } |
| 107720 | break; |
| 107721 | } |
| @@ -108367,22 +108417,10 @@ | |
| 108417 | ** without most of the overhead of a full integrity-check. |
| 108418 | */ |
| 108419 | case PragTyp_INTEGRITY_CHECK: { |
| 108420 | int i, j, addr, mxErr; |
| 108421 | |
| 108422 | int isQuick = (sqlite3Tolower(zLeft[0])=='q'); |
| 108423 | |
| 108424 | /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check", |
| 108425 | ** then iDb is set to the index of the database identified by <db>. |
| 108426 | ** In this case, the integrity of database iDb only is verified by |
| @@ -108575,14 +108613,28 @@ | |
| 108613 | sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1); |
| 108614 | } |
| 108615 | #endif /* SQLITE_OMIT_BTREECOUNT */ |
| 108616 | } |
| 108617 | } |
| 108618 | { |
| 108619 | static const int iLn = VDBE_OFFSET_LINENO(2); |
| 108620 | static const VdbeOpList endCode[] = { |
| 108621 | { OP_AddImm, 1, 0, 0}, /* 0 */ |
| 108622 | { OP_If, 1, 0, 0}, /* 1 */ |
| 108623 | { OP_String8, 0, 3, 0}, /* 2 */ |
| 108624 | { OP_ResultRow, 3, 1, 0}, |
| 108625 | }; |
| 108626 | VdbeOp *aOp; |
| 108627 | |
| 108628 | aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); |
| 108629 | if( aOp ){ |
| 108630 | aOp[0].p2 = -mxErr; |
| 108631 | aOp[1].p2 = sqlite3VdbeCurrentAddr(v); |
| 108632 | aOp[2].p4type = P4_STATIC; |
| 108633 | aOp[2].p4.z = "ok"; |
| 108634 | } |
| 108635 | } |
| 108636 | } |
| 108637 | break; |
| 108638 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 108639 | |
| 108640 | #ifndef SQLITE_OMIT_UTF16 |
| @@ -108695,26 +108747,32 @@ | |
| 108747 | static const VdbeOpList setCookie[] = { |
| 108748 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 108749 | { OP_Integer, 0, 1, 0}, /* 1 */ |
| 108750 | { OP_SetCookie, 0, 0, 1}, /* 2 */ |
| 108751 | }; |
| 108752 | VdbeOp *aOp; |
| 108753 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setCookie)); |
| 108754 | aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); |
| 108755 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
| 108756 | aOp[0].p1 = iDb; |
| 108757 | aOp[1].p1 = sqlite3Atoi(zRight); |
| 108758 | aOp[2].p1 = iDb; |
| 108759 | aOp[2].p2 = iCookie; |
| 108760 | }else{ |
| 108761 | /* Read the specified cookie value */ |
| 108762 | static const VdbeOpList readCookie[] = { |
| 108763 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 108764 | { OP_ReadCookie, 0, 1, 0}, /* 1 */ |
| 108765 | { OP_ResultRow, 1, 1, 0} |
| 108766 | }; |
| 108767 | VdbeOp *aOp; |
| 108768 | sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(readCookie)); |
| 108769 | aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0); |
| 108770 | if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; |
| 108771 | aOp[0].p1 = iDb; |
| 108772 | aOp[1].p1 = iDb; |
| 108773 | aOp[1].p3 = iCookie; |
| 108774 | sqlite3VdbeSetNumCols(v, 1); |
| 108775 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); |
| 108776 | } |
| 108777 | } |
| 108778 | break; |
| @@ -109077,65 +109135,31 @@ | |
| 109135 | int rc; |
| 109136 | int i; |
| 109137 | #ifndef SQLITE_OMIT_DEPRECATED |
| 109138 | int size; |
| 109139 | #endif |
| 109140 | Db *pDb; |
| 109141 | char const *azArg[4]; |
| 109142 | int meta[5]; |
| 109143 | InitData initData; |
| 109144 | const char *zMasterName; |
| 109145 | int openedTransaction = 0; |
| 109146 | |
| 109147 | assert( iDb>=0 && iDb<db->nDb ); |
| 109148 | assert( db->aDb[iDb].pSchema ); |
| 109149 | assert( sqlite3_mutex_held(db->mutex) ); |
| 109150 | assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 109151 | |
| 109152 | /* Construct the in-memory representation schema tables (sqlite_master or |
| 109153 | ** sqlite_temp_master) by invoking the parser directly. The appropriate |
| 109154 | ** table name will be inserted automatically by the parser so we can just |
| 109155 | ** use the abbreviation "x" here. The parser will also automatically tag |
| 109156 | ** the schema table as read-only. */ |
| 109157 | azArg[0] = zMasterName = SCHEMA_TABLE(iDb); |
| 109158 | azArg[1] = "1"; |
| 109159 | azArg[2] = "CREATE TABLE x(type text,name text,tbl_name text," |
| 109160 | "rootpage integer,sql text)"; |
| 109161 | azArg[3] = 0; |
| 109162 | initData.db = db; |
| 109163 | initData.iDb = iDb; |
| 109164 | initData.rc = SQLITE_OK; |
| 109165 | initData.pzErrMsg = pzErrMsg; |
| @@ -109142,14 +109166,10 @@ | |
| 109166 | sqlite3InitCallback(&initData, 3, (char **)azArg, 0); |
| 109167 | if( initData.rc ){ |
| 109168 | rc = initData.rc; |
| 109169 | goto error_out; |
| 109170 | } |
| 109171 | |
| 109172 | /* Create a cursor to hold the database open |
| 109173 | */ |
| 109174 | pDb = &db->aDb[iDb]; |
| 109175 | if( pDb->pBt==0 ){ |
| @@ -109264,11 +109284,11 @@ | |
| 109284 | */ |
| 109285 | assert( db->init.busy ); |
| 109286 | { |
| 109287 | char *zSql; |
| 109288 | zSql = sqlite3MPrintf(db, |
| 109289 | "SELECT name, rootpage, sql FROM \"%w\".%s ORDER BY rowid", |
| 109290 | db->aDb[iDb].zName, zMasterName); |
| 109291 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 109292 | { |
| 109293 | sqlite3_xauth xAuth; |
| 109294 | xAuth = db->xAuth; |
| @@ -110841,19 +110861,20 @@ | |
| 110861 | /* |
| 110862 | ** Allocate a KeyInfo object sufficient for an index of N key columns and |
| 110863 | ** X extra columns. |
| 110864 | */ |
| 110865 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){ |
| 110866 | int nExtra = (N+X)*(sizeof(CollSeq*)+1); |
| 110867 | KeyInfo *p = sqlite3Malloc(sizeof(KeyInfo) + nExtra); |
| 110868 | if( p ){ |
| 110869 | p->aSortOrder = (u8*)&p->aColl[N+X]; |
| 110870 | p->nField = (u16)N; |
| 110871 | p->nXField = (u16)X; |
| 110872 | p->enc = ENC(db); |
| 110873 | p->db = db; |
| 110874 | p->nRef = 1; |
| 110875 | memset(&p[1], 0, nExtra); |
| 110876 | }else{ |
| 110877 | db->mallocFailed = 1; |
| 110878 | } |
| 110879 | return p; |
| 110880 | } |
| @@ -116638,12 +116659,12 @@ | |
| 116659 | /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program |
| 116660 | ** is a pointer to the sub-vdbe containing the trigger program. */ |
| 116661 | if( pPrg ){ |
| 116662 | int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers)); |
| 116663 | |
| 116664 | sqlite3VdbeAddOp4(v, OP_Program, reg, ignoreJump, ++pParse->nMem, |
| 116665 | (const char *)pPrg->pProgram, P4_SUBPROGRAM); |
| 116666 | VdbeComment( |
| 116667 | (v, "Call: %s.%s", (p->zName?p->zName:"fkey"), onErrorText(orconf))); |
| 116668 | |
| 116669 | /* Set the P5 operand of the OP_Program instruction to non-zero if |
| 116670 | ** recursive invocation of this trigger program is disallowed. Recursive |
| @@ -118993,11 +119014,11 @@ | |
| 119014 | Expr *pExpr /* First argument to the function */ |
| 119015 | ){ |
| 119016 | Table *pTab; |
| 119017 | sqlite3_vtab *pVtab; |
| 119018 | sqlite3_module *pMod; |
| 119019 | void (*xSFunc)(sqlite3_context*,int,sqlite3_value**) = 0; |
| 119020 | void *pArg = 0; |
| 119021 | FuncDef *pNew; |
| 119022 | int rc = 0; |
| 119023 | char *zLowerName; |
| 119024 | unsigned char *z; |
| @@ -119021,11 +119042,11 @@ | |
| 119042 | zLowerName = sqlite3DbStrDup(db, pDef->zName); |
| 119043 | if( zLowerName ){ |
| 119044 | for(z=(unsigned char*)zLowerName; *z; z++){ |
| 119045 | *z = sqlite3UpperToLower[*z]; |
| 119046 | } |
| 119047 | rc = pMod->xFindFunction(pVtab, nArg, zLowerName, &xSFunc, &pArg); |
| 119048 | sqlite3DbFree(db, zLowerName); |
| 119049 | } |
| 119050 | if( rc==0 ){ |
| 119051 | return pDef; |
| 119052 | } |
| @@ -119038,11 +119059,11 @@ | |
| 119059 | return pDef; |
| 119060 | } |
| 119061 | *pNew = *pDef; |
| 119062 | pNew->zName = (char *)&pNew[1]; |
| 119063 | memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1); |
| 119064 | pNew->xSFunc = xSFunc; |
| 119065 | pNew->pUserData = pArg; |
| 119066 | pNew->funcFlags |= SQLITE_FUNC_EPHEM; |
| 119067 | return pNew; |
| 119068 | } |
| 119069 | |
| @@ -120058,12 +120079,11 @@ | |
| 120079 | n--; |
| 120080 | } |
| 120081 | |
| 120082 | /* Code the OP_Affinity opcode if there is anything left to do. */ |
| 120083 | if( n>0 ){ |
| 120084 | sqlite3VdbeAddOp4(v, OP_Affinity, base, n, 0, zAff, n); |
| 120085 | sqlite3ExprCacheAffinityChange(pParse, base, n); |
| 120086 | } |
| 120087 | } |
| 120088 | |
| 120089 | |
| @@ -133811,11 +133831,11 @@ | |
| 133831 | sqlite3 *db, |
| 133832 | const char *zFunctionName, |
| 133833 | int nArg, |
| 133834 | int enc, |
| 133835 | void *pUserData, |
| 133836 | void (*xSFunc)(sqlite3_context*,int,sqlite3_value **), |
| 133837 | void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 133838 | void (*xFinal)(sqlite3_context*), |
| 133839 | FuncDestructor *pDestructor |
| 133840 | ){ |
| 133841 | FuncDef *p; |
| @@ -133822,13 +133842,13 @@ | |
| 133842 | int nName; |
| 133843 | int extraFlags; |
| 133844 | |
| 133845 | assert( sqlite3_mutex_held(db->mutex) ); |
| 133846 | if( zFunctionName==0 || |
| 133847 | (xSFunc && (xFinal || xStep)) || |
| 133848 | (!xSFunc && (xFinal && !xStep)) || |
| 133849 | (!xSFunc && (!xFinal && xStep)) || |
| 133850 | (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || |
| 133851 | (255<(nName = sqlite3Strlen30( zFunctionName))) ){ |
| 133852 | return SQLITE_MISUSE_BKPT; |
| 133853 | } |
| 133854 | |
| @@ -133847,14 +133867,14 @@ | |
| 133867 | if( enc==SQLITE_UTF16 ){ |
| 133868 | enc = SQLITE_UTF16NATIVE; |
| 133869 | }else if( enc==SQLITE_ANY ){ |
| 133870 | int rc; |
| 133871 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags, |
| 133872 | pUserData, xSFunc, xStep, xFinal, pDestructor); |
| 133873 | if( rc==SQLITE_OK ){ |
| 133874 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags, |
| 133875 | pUserData, xSFunc, xStep, xFinal, pDestructor); |
| 133876 | } |
| 133877 | if( rc!=SQLITE_OK ){ |
| 133878 | return rc; |
| 133879 | } |
| 133880 | enc = SQLITE_UTF16BE; |
| @@ -133894,12 +133914,11 @@ | |
| 133914 | pDestructor->nRef++; |
| 133915 | } |
| 133916 | p->pDestructor = pDestructor; |
| 133917 | p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags; |
| 133918 | testcase( p->funcFlags & SQLITE_DETERMINISTIC ); |
| 133919 | p->xSFunc = xSFunc ? xSFunc : xStep; |
| 133920 | p->xFinalize = xFinal; |
| 133921 | p->pUserData = pUserData; |
| 133922 | p->nArg = (u16)nArg; |
| 133923 | return SQLITE_OK; |
| 133924 | } |
| @@ -133911,25 +133930,25 @@ | |
| 133930 | sqlite3 *db, |
| 133931 | const char *zFunc, |
| 133932 | int nArg, |
| 133933 | int enc, |
| 133934 | void *p, |
| 133935 | void (*xSFunc)(sqlite3_context*,int,sqlite3_value **), |
| 133936 | void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 133937 | void (*xFinal)(sqlite3_context*) |
| 133938 | ){ |
| 133939 | return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xSFunc, xStep, |
| 133940 | xFinal, 0); |
| 133941 | } |
| 133942 | |
| 133943 | SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2( |
| 133944 | sqlite3 *db, |
| 133945 | const char *zFunc, |
| 133946 | int nArg, |
| 133947 | int enc, |
| 133948 | void *p, |
| 133949 | void (*xSFunc)(sqlite3_context*,int,sqlite3_value **), |
| 133950 | void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 133951 | void (*xFinal)(sqlite3_context*), |
| 133952 | void (*xDestroy)(void *) |
| 133953 | ){ |
| 133954 | int rc = SQLITE_ERROR; |
| @@ -133948,11 +133967,11 @@ | |
| 133967 | goto out; |
| 133968 | } |
| 133969 | pArg->xDestroy = xDestroy; |
| 133970 | pArg->pUserData = p; |
| 133971 | } |
| 133972 | rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xSFunc, xStep, xFinal, pArg); |
| 133973 | if( pArg && pArg->nRef==0 ){ |
| 133974 | assert( rc!=SQLITE_OK ); |
| 133975 | xDestroy(p); |
| 133976 | sqlite3DbFree(db, pArg); |
| 133977 | } |
| @@ -133968,11 +133987,11 @@ | |
| 133987 | sqlite3 *db, |
| 133988 | const void *zFunctionName, |
| 133989 | int nArg, |
| 133990 | int eTextRep, |
| 133991 | void *p, |
| 133992 | void (*xSFunc)(sqlite3_context*,int,sqlite3_value**), |
| 133993 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 133994 | void (*xFinal)(sqlite3_context*) |
| 133995 | ){ |
| 133996 | int rc; |
| 133997 | char *zFunc8; |
| @@ -133981,11 +134000,11 @@ | |
| 134000 | if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT; |
| 134001 | #endif |
| 134002 | sqlite3_mutex_enter(db->mutex); |
| 134003 | assert( !db->mallocFailed ); |
| 134004 | zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); |
| 134005 | rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xSFunc,xStep,xFinal,0); |
| 134006 | sqlite3DbFree(db, zFunc8); |
| 134007 | rc = sqlite3ApiExit(db, rc); |
| 134008 | sqlite3_mutex_leave(db->mutex); |
| 134009 | return rc; |
| 134010 | } |
| @@ -135206,11 +135225,10 @@ | |
| 135225 | sqlite3GlobalConfig.nLookaside); |
| 135226 | |
| 135227 | sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| 135228 | |
| 135229 | opendb_out: |
| 135230 | if( db ){ |
| 135231 | assert( db->mutex!=0 || isThreadsafe==0 |
| 135232 | || sqlite3GlobalConfig.bFullMutex==0 ); |
| 135233 | sqlite3_mutex_leave(db->mutex); |
| 135234 | } |
| @@ -135243,10 +135261,11 @@ | |
| 135261 | } |
| 135262 | sqlite3_key_v2(db, 0, zKey, i/2); |
| 135263 | } |
| 135264 | } |
| 135265 | #endif |
| 135266 | sqlite3_free(zOpen); |
| 135267 | return rc & 0xff; |
| 135268 | } |
| 135269 | |
| 135270 | /* |
| 135271 | ** Open a new database handle. |
| @@ -168108,17 +168127,17 @@ | |
| 168127 | ** Buffer object for the incremental building of string data. |
| 168128 | */ |
| 168129 | typedef struct Fts5Buffer Fts5Buffer; |
| 168130 | struct Fts5Buffer { |
| 168131 | u8 *p; |
| 168132 | u32 n; |
| 168133 | u32 nSpace; |
| 168134 | }; |
| 168135 | |
| 168136 | static int sqlite3Fts5BufferSize(int*, Fts5Buffer*, u32); |
| 168137 | static void sqlite3Fts5BufferAppendVarint(int*, Fts5Buffer*, i64); |
| 168138 | static void sqlite3Fts5BufferAppendBlob(int*, Fts5Buffer*, u32, const u8*); |
| 168139 | static void sqlite3Fts5BufferAppendString(int *, Fts5Buffer*, const char*); |
| 168140 | static void sqlite3Fts5BufferFree(Fts5Buffer*); |
| 168141 | static void sqlite3Fts5BufferZero(Fts5Buffer*); |
| 168142 | static void sqlite3Fts5BufferSet(int*, Fts5Buffer*, int, const u8*); |
| 168143 | static void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...); |
| @@ -168221,10 +168240,33 @@ | |
| 168240 | ** sqlite3Fts5IterNext(pIter) |
| 168241 | ** ){ |
| 168242 | ** i64 iRowid = sqlite3Fts5IterRowid(pIter); |
| 168243 | ** } |
| 168244 | */ |
| 168245 | |
| 168246 | /* |
| 168247 | ** Return a simple checksum value based on the arguments. |
| 168248 | */ |
| 168249 | static u64 sqlite3Fts5IndexEntryCksum( |
| 168250 | i64 iRowid, |
| 168251 | int iCol, |
| 168252 | int iPos, |
| 168253 | int iIdx, |
| 168254 | const char *pTerm, |
| 168255 | int nTerm |
| 168256 | ); |
| 168257 | |
| 168258 | /* |
| 168259 | ** Argument p points to a buffer containing utf-8 text that is n bytes in |
| 168260 | ** size. Return the number of bytes in the nChar character prefix of the |
| 168261 | ** buffer, or 0 if there are less than nChar characters in total. |
| 168262 | */ |
| 168263 | static int sqlite3Fts5IndexCharlenToBytelen( |
| 168264 | const char *p, |
| 168265 | int nByte, |
| 168266 | int nChar |
| 168267 | ); |
| 168268 | |
| 168269 | /* |
| 168270 | ** Open a new iterator to iterate though all rowids that match the |
| 168271 | ** specified token or token prefix. |
| 168272 | */ |
| @@ -168446,11 +168488,11 @@ | |
| 168488 | static int sqlite3Fts5StorageRename(Fts5Storage*, const char *zName); |
| 168489 | |
| 168490 | static int sqlite3Fts5DropAll(Fts5Config*); |
| 168491 | static int sqlite3Fts5CreateTable(Fts5Config*, const char*, const char*, int, char **); |
| 168492 | |
| 168493 | static int sqlite3Fts5StorageDelete(Fts5Storage *p, i64, sqlite3_value**); |
| 168494 | static int sqlite3Fts5StorageContentInsert(Fts5Storage *p, sqlite3_value**, i64*); |
| 168495 | static int sqlite3Fts5StorageIndexInsert(Fts5Storage *p, sqlite3_value**, i64); |
| 168496 | |
| 168497 | static int sqlite3Fts5StorageIntegrity(Fts5Storage *p); |
| 168498 | |
| @@ -168466,12 +168508,10 @@ | |
| 168508 | |
| 168509 | static int sqlite3Fts5StorageConfigValue( |
| 168510 | Fts5Storage *p, const char*, sqlite3_value*, int |
| 168511 | ); |
| 168512 | |
| 168513 | static int sqlite3Fts5StorageDeleteAll(Fts5Storage *p); |
| 168514 | static int sqlite3Fts5StorageRebuild(Fts5Storage *p); |
| 168515 | static int sqlite3Fts5StorageOptimize(Fts5Storage *p); |
| 168516 | static int sqlite3Fts5StorageMerge(Fts5Storage *p, int nMerge); |
| 168517 | |
| @@ -170414,12 +170454,12 @@ | |
| 170454 | |
| 170455 | |
| 170456 | |
| 170457 | /* #include "fts5Int.h" */ |
| 170458 | |
| 170459 | static int sqlite3Fts5BufferSize(int *pRc, Fts5Buffer *pBuf, u32 nByte){ |
| 170460 | u32 nNew = pBuf->nSpace ? pBuf->nSpace*2 : 64; |
| 170461 | u8 *pNew; |
| 170462 | while( nNew<nByte ){ |
| 170463 | nNew = nNew * 2; |
| 170464 | } |
| 170465 | pNew = sqlite3_realloc(pBuf->p, nNew); |
| @@ -170460,14 +170500,14 @@ | |
| 170500 | ** is called, it is a no-op. |
| 170501 | */ |
| 170502 | static void sqlite3Fts5BufferAppendBlob( |
| 170503 | int *pRc, |
| 170504 | Fts5Buffer *pBuf, |
| 170505 | u32 nData, |
| 170506 | const u8 *pData |
| 170507 | ){ |
| 170508 | assert_nc( *pRc || nData>=0 ); |
| 170509 | if( fts5BufferGrow(pRc, pBuf, nData) ) return; |
| 170510 | memcpy(&pBuf->p[pBuf->n], pData, nData); |
| 170511 | pBuf->n += nData; |
| 170512 | } |
| 170513 | |
| @@ -170721,18 +170761,21 @@ | |
| 170761 | ){ |
| 170762 | int rc = SQLITE_OK; |
| 170763 | *pbPresent = 0; |
| 170764 | if( p ){ |
| 170765 | int i; |
| 170766 | int hash = 13; |
| 170767 | Fts5TermsetEntry *pEntry; |
| 170768 | |
| 170769 | /* Calculate a hash value for this term. This is the same hash checksum |
| 170770 | ** used by the fts5_hash.c module. This is not important for correct |
| 170771 | ** operation of the module, but is necessary to ensure that some tests |
| 170772 | ** designed to produce hash table collisions really do work. */ |
| 170773 | for(i=nTerm-1; i>=0; i--){ |
| 170774 | hash = (hash << 3) ^ hash ^ pTerm[i]; |
| 170775 | } |
| 170776 | hash = (hash << 3) ^ hash ^ iIdx; |
| 170777 | hash = hash % ArraySize(p->apHash); |
| 170778 | |
| 170779 | for(pEntry=p->apHash[hash]; pEntry; pEntry=pEntry->pNext){ |
| 170780 | if( pEntry->iIdx==iIdx |
| 170781 | && pEntry->nTerm==nTerm |
| @@ -171055,11 +171098,11 @@ | |
| 171098 | while( p[0]>='0' && p[0]<='9' && nPre<1000 ){ |
| 171099 | nPre = nPre*10 + (p[0] - '0'); |
| 171100 | p++; |
| 171101 | } |
| 171102 | |
| 171103 | if( nPre<=0 || nPre>=1000 ){ |
| 171104 | *pzErr = sqlite3_mprintf("prefix length out of range (max 999)"); |
| 171105 | rc = SQLITE_ERROR; |
| 171106 | break; |
| 171107 | } |
| 171108 | |
| @@ -172558,11 +172601,11 @@ | |
| 172601 | assert( pNode->eType==FTS5_TERM ); |
| 172602 | assert( pNear->nPhrase==1 && pPhrase->nTerm==1 ); |
| 172603 | assert( pPhrase->aTerm[0].pSynonym==0 ); |
| 172604 | |
| 172605 | rc = sqlite3Fts5IterPoslist(pIter, pColset, |
| 172606 | (const u8**)&pPhrase->poslist.p, (int*)&pPhrase->poslist.n, &pNode->iRowid |
| 172607 | ); |
| 172608 | pNode->bNomatch = (pPhrase->poslist.n==0); |
| 172609 | return rc; |
| 172610 | } |
| 172611 | |
| @@ -174120,11 +174163,11 @@ | |
| 174163 | aPopulator[i].bOk = 1; |
| 174164 | } |
| 174165 | } |
| 174166 | |
| 174167 | return sqlite3Fts5Tokenize(pConfig, |
| 174168 | FTS5_TOKENIZE_DOCUMENT, z, n, (void*)&sCtx, fts5ExprPopulatePoslistsCb |
| 174169 | ); |
| 174170 | } |
| 174171 | |
| 174172 | static void fts5ExprClearPoslists(Fts5ExprNode *pNode){ |
| 174173 | if( pNode->eType==FTS5_TERM || pNode->eType==FTS5_STRING ){ |
| @@ -174136,53 +174179,48 @@ | |
| 174179 | } |
| 174180 | } |
| 174181 | } |
| 174182 | |
| 174183 | static int fts5ExprCheckPoslists(Fts5ExprNode *pNode, i64 iRowid){ |
| 174184 | pNode->iRowid = iRowid; |
| 174185 | pNode->bEof = 0; |
| 174186 | switch( pNode->eType ){ |
| 174187 | case FTS5_TERM: |
| 174188 | case FTS5_STRING: |
| 174189 | return (pNode->pNear->apPhrase[0]->poslist.n>0); |
| 174190 | |
| 174191 | case FTS5_AND: { |
| 174192 | int i; |
| 174193 | for(i=0; i<pNode->nChild; i++){ |
| 174194 | if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid)==0 ){ |
| 174195 | fts5ExprClearPoslists(pNode); |
| 174196 | return 0; |
| 174197 | } |
| 174198 | } |
| 174199 | break; |
| 174200 | } |
| 174201 | |
| 174202 | case FTS5_OR: { |
| 174203 | int i; |
| 174204 | int bRet = 0; |
| 174205 | for(i=0; i<pNode->nChild; i++){ |
| 174206 | if( fts5ExprCheckPoslists(pNode->apChild[i], iRowid) ){ |
| 174207 | bRet = 1; |
| 174208 | } |
| 174209 | } |
| 174210 | return bRet; |
| 174211 | } |
| 174212 | |
| 174213 | default: { |
| 174214 | assert( pNode->eType==FTS5_NOT ); |
| 174215 | if( 0==fts5ExprCheckPoslists(pNode->apChild[0], iRowid) |
| 174216 | || 0!=fts5ExprCheckPoslists(pNode->apChild[1], iRowid) |
| 174217 | ){ |
| 174218 | fts5ExprClearPoslists(pNode); |
| 174219 | return 0; |
| 174220 | } |
| 174221 | break; |
| 174222 | } |
| 174223 | } |
| 174224 | return 1; |
| 174225 | } |
| 174226 | |
| @@ -176647,17 +176685,19 @@ | |
| 176685 | ){ |
| 176686 | Fts5Data *pLeaf = pIter->pLeaf; |
| 176687 | int iOff; |
| 176688 | int bNewTerm = 0; |
| 176689 | int nKeep = 0; |
| 176690 | u8 *a; |
| 176691 | int n; |
| 176692 | |
| 176693 | assert( pbNewTerm==0 || *pbNewTerm==0 ); |
| 176694 | assert( p->pConfig->eDetail!=FTS5_DETAIL_NONE ); |
| 176695 | |
| 176696 | /* Search for the end of the position list within the current page. */ |
| 176697 | a = pLeaf->p; |
| 176698 | n = pLeaf->szLeaf; |
| 176699 | |
| 176700 | ASSERT_SZLEAF_OK(pLeaf); |
| 176701 | iOff = pIter->iLeafOffset + pIter->nPos; |
| 176702 | |
| 176703 | if( iOff<n ){ |
| @@ -180673,10 +180713,51 @@ | |
| 180713 | } |
| 180714 | } |
| 180715 | |
| 180716 | return iOff; |
| 180717 | } |
| 180718 | |
| 180719 | /* |
| 180720 | ** This function is part of the fts5_decode() debugging function. It is |
| 180721 | ** only ever used with detail=none tables. |
| 180722 | ** |
| 180723 | ** Buffer (pData/nData) contains a doclist in the format used by detail=none |
| 180724 | ** tables. This function appends a human-readable version of that list to |
| 180725 | ** buffer pBuf. |
| 180726 | ** |
| 180727 | ** If *pRc is other than SQLITE_OK when this function is called, it is a |
| 180728 | ** no-op. If an OOM or other error occurs within this function, *pRc is |
| 180729 | ** set to an SQLite error code before returning. The final state of buffer |
| 180730 | ** pBuf is undefined in this case. |
| 180731 | */ |
| 180732 | static void fts5DecodeRowidList( |
| 180733 | int *pRc, /* IN/OUT: Error code */ |
| 180734 | Fts5Buffer *pBuf, /* Buffer to append text to */ |
| 180735 | const u8 *pData, int nData /* Data to decode list-of-rowids from */ |
| 180736 | ){ |
| 180737 | int i = 0; |
| 180738 | i64 iRowid = 0; |
| 180739 | |
| 180740 | while( i<nData ){ |
| 180741 | const char *zApp = ""; |
| 180742 | u64 iVal; |
| 180743 | i += sqlite3Fts5GetVarint(&pData[i], &iVal); |
| 180744 | iRowid += iVal; |
| 180745 | |
| 180746 | if( i<nData && pData[i]==0x00 ){ |
| 180747 | i++; |
| 180748 | if( i<nData && pData[i]==0x00 ){ |
| 180749 | i++; |
| 180750 | zApp = "+"; |
| 180751 | }else{ |
| 180752 | zApp = "*"; |
| 180753 | } |
| 180754 | } |
| 180755 | |
| 180756 | sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %lld%s", iRowid, zApp); |
| 180757 | } |
| 180758 | } |
| 180759 | |
| 180760 | /* |
| 180761 | ** The implementation of user-defined scalar function fts5_decode(). |
| 180762 | */ |
| 180763 | static void fts5DecodeFunction( |
| @@ -180689,10 +180770,11 @@ | |
| 180770 | const u8 *aBlob; int n; /* Record to decode */ |
| 180771 | u8 *a = 0; |
| 180772 | Fts5Buffer s; /* Build up text to return here */ |
| 180773 | int rc = SQLITE_OK; /* Return code */ |
| 180774 | int nSpace = 0; |
| 180775 | int eDetailNone = (sqlite3_user_data(pCtx)!=0); |
| 180776 | |
| 180777 | assert( nArg==2 ); |
| 180778 | memset(&s, 0, sizeof(Fts5Buffer)); |
| 180779 | iRowid = sqlite3_value_int64(apVal[0]); |
| 180780 | |
| @@ -180730,10 +180812,58 @@ | |
| 180812 | if( iRowid==FTS5_AVERAGES_ROWID ){ |
| 180813 | fts5DecodeAverages(&rc, &s, a, n); |
| 180814 | }else{ |
| 180815 | fts5DecodeStructure(&rc, &s, a, n); |
| 180816 | } |
| 180817 | }else if( eDetailNone ){ |
| 180818 | Fts5Buffer term; /* Current term read from page */ |
| 180819 | int szLeaf; |
| 180820 | int iPgidxOff = szLeaf = fts5GetU16(&a[2]); |
| 180821 | int iTermOff; |
| 180822 | int nKeep = 0; |
| 180823 | int iOff; |
| 180824 | |
| 180825 | memset(&term, 0, sizeof(Fts5Buffer)); |
| 180826 | |
| 180827 | /* Decode any entries that occur before the first term. */ |
| 180828 | if( szLeaf<n ){ |
| 180829 | iPgidxOff += fts5GetVarint32(&a[iPgidxOff], iTermOff); |
| 180830 | }else{ |
| 180831 | iTermOff = szLeaf; |
| 180832 | } |
| 180833 | fts5DecodeRowidList(&rc, &s, &a[4], iTermOff-4); |
| 180834 | |
| 180835 | iOff = iTermOff; |
| 180836 | while( iOff<szLeaf ){ |
| 180837 | int nAppend; |
| 180838 | |
| 180839 | /* Read the term data for the next term*/ |
| 180840 | iOff += fts5GetVarint32(&a[iOff], nAppend); |
| 180841 | term.n = nKeep; |
| 180842 | fts5BufferAppendBlob(&rc, &term, nAppend, &a[iOff]); |
| 180843 | sqlite3Fts5BufferAppendPrintf( |
| 180844 | &rc, &s, " term=%.*s", term.n, (const char*)term.p |
| 180845 | ); |
| 180846 | iOff += nAppend; |
| 180847 | |
| 180848 | /* Figure out where the doclist for this term ends */ |
| 180849 | if( iPgidxOff<n ){ |
| 180850 | int nIncr; |
| 180851 | iPgidxOff += fts5GetVarint32(&a[iPgidxOff], nIncr); |
| 180852 | iTermOff += nIncr; |
| 180853 | }else{ |
| 180854 | iTermOff = szLeaf; |
| 180855 | } |
| 180856 | |
| 180857 | fts5DecodeRowidList(&rc, &s, &a[iOff], iTermOff-iOff); |
| 180858 | iOff = iTermOff; |
| 180859 | if( iOff<szLeaf ){ |
| 180860 | iOff += fts5GetVarint32(&a[iOff], nKeep); |
| 180861 | } |
| 180862 | } |
| 180863 | |
| 180864 | fts5BufferFree(&term); |
| 180865 | }else{ |
| 180866 | Fts5Buffer term; /* Current term read from page */ |
| 180867 | int szLeaf; /* Offset of pgidx in a[] */ |
| 180868 | int iPgidxOff; |
| 180869 | int iPgidxPrev = 0; /* Previous value read from pgidx */ |
| @@ -180857,18 +180987,25 @@ | |
| 180987 | */ |
| 180988 | static int sqlite3Fts5IndexInit(sqlite3 *db){ |
| 180989 | int rc = sqlite3_create_function( |
| 180990 | db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0 |
| 180991 | ); |
| 180992 | |
| 180993 | if( rc==SQLITE_OK ){ |
| 180994 | rc = sqlite3_create_function( |
| 180995 | db, "fts5_decode_none", 2, |
| 180996 | SQLITE_UTF8, (void*)db, fts5DecodeFunction, 0, 0 |
| 180997 | ); |
| 180998 | } |
| 180999 | |
| 181000 | if( rc==SQLITE_OK ){ |
| 181001 | rc = sqlite3_create_function( |
| 181002 | db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0 |
| 181003 | ); |
| 181004 | } |
| 181005 | return rc; |
| 181006 | } |
| 181007 | |
| 181008 | /* |
| 181009 | ** 2014 Jun 09 |
| 181010 | ** |
| 181011 | ** The author disclaims copyright to this source code. In place of |
| @@ -181712,45 +181849,44 @@ | |
| 181849 | |
| 181850 | return rc; |
| 181851 | } |
| 181852 | |
| 181853 | |
| 181854 | static int fts5PrepareStatement( |
| 181855 | sqlite3_stmt **ppStmt, |
| 181856 | Fts5Config *pConfig, |
| 181857 | const char *zFmt, |
| 181858 | ... |
| 181859 | ){ |
| 181860 | sqlite3_stmt *pRet = 0; |
| 181861 | int rc; |
| 181862 | char *zSql; |
| 181863 | va_list ap; |
| 181864 | |
| 181865 | va_start(ap, zFmt); |
| 181866 | zSql = sqlite3_vmprintf(zFmt, ap); |
| 181867 | if( zSql==0 ){ |
| 181868 | rc = SQLITE_NOMEM; |
| 181869 | }else{ |
| 181870 | rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pRet, 0); |
| 181871 | if( rc!=SQLITE_OK ){ |
| 181872 | *pConfig->pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(pConfig->db)); |
| 181873 | } |
| 181874 | sqlite3_free(zSql); |
| 181875 | } |
| 181876 | |
| 181877 | va_end(ap); |
| 181878 | *ppStmt = pRet; |
| 181879 | return rc; |
| 181880 | } |
| 181881 | |
| 181882 | static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){ |
| 181883 | Fts5Config *pConfig = pTab->pConfig; |
| 181884 | Fts5Sorter *pSorter; |
| 181885 | int nPhrase; |
| 181886 | int nByte; |
| 181887 | int rc; |
| 181888 | const char *zRank = pCsr->zRank; |
| 181889 | const char *zRankArgs = pCsr->zRankArgs; |
| 181890 | |
| 181891 | nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr); |
| 181892 | nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1); |
| @@ -181764,11 +181900,11 @@ | |
| 181900 | ** is not possible as SQLite reference counts the virtual table objects. |
| 181901 | ** And since the statement required here reads from this very virtual |
| 181902 | ** table, saving it creates a circular reference. |
| 181903 | ** |
| 181904 | ** If SQLite a built-in statement cache, this wouldn't be a problem. */ |
| 181905 | rc = fts5PrepareStatement(&pSorter->pStmt, pConfig, |
| 181906 | "SELECT rowid, rank FROM %Q.%Q ORDER BY %s(%s%s%s) %s", |
| 181907 | pConfig->zDb, pConfig->zName, zRank, pConfig->zName, |
| 181908 | (zRankArgs ? ", " : ""), |
| 181909 | (zRankArgs ? zRankArgs : ""), |
| 181910 | bDesc ? "DESC" : "ASC" |
| @@ -182273,11 +182409,11 @@ | |
| 182409 | ){ |
| 182410 | int rc = SQLITE_OK; |
| 182411 | int eType1 = sqlite3_value_type(apVal[1]); |
| 182412 | if( eType1==SQLITE_INTEGER ){ |
| 182413 | sqlite3_int64 iDel = sqlite3_value_int64(apVal[1]); |
| 182414 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, &apVal[2]); |
| 182415 | } |
| 182416 | return rc; |
| 182417 | } |
| 182418 | |
| 182419 | static void fts5StorageInsert( |
| @@ -182380,21 +182516,21 @@ | |
| 182516 | } |
| 182517 | |
| 182518 | /* Case 1: DELETE */ |
| 182519 | else if( nArg==1 ){ |
| 182520 | i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */ |
| 182521 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0); |
| 182522 | } |
| 182523 | |
| 182524 | /* Case 2: INSERT */ |
| 182525 | else if( eType0!=SQLITE_INTEGER ){ |
| 182526 | /* If this is a REPLACE, first remove the current entry (if any) */ |
| 182527 | if( eConflict==SQLITE_REPLACE |
| 182528 | && sqlite3_value_type(apVal[1])==SQLITE_INTEGER |
| 182529 | ){ |
| 182530 | i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */ |
| 182531 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0); |
| 182532 | } |
| 182533 | fts5StorageInsert(&rc, pTab, apVal, pRowid); |
| 182534 | } |
| 182535 | |
| 182536 | /* Case 2: UPDATE */ |
| @@ -182401,26 +182537,26 @@ | |
| 182537 | else{ |
| 182538 | i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */ |
| 182539 | i64 iNew = sqlite3_value_int64(apVal[1]); /* New rowid */ |
| 182540 | if( iOld!=iNew ){ |
| 182541 | if( eConflict==SQLITE_REPLACE ){ |
| 182542 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0); |
| 182543 | if( rc==SQLITE_OK ){ |
| 182544 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0); |
| 182545 | } |
| 182546 | fts5StorageInsert(&rc, pTab, apVal, pRowid); |
| 182547 | }else{ |
| 182548 | rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, pRowid); |
| 182549 | if( rc==SQLITE_OK ){ |
| 182550 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0); |
| 182551 | } |
| 182552 | if( rc==SQLITE_OK ){ |
| 182553 | rc = sqlite3Fts5StorageIndexInsert(pTab->pStorage, apVal, *pRowid); |
| 182554 | } |
| 182555 | } |
| 182556 | }else{ |
| 182557 | rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0); |
| 182558 | fts5StorageInsert(&rc, pTab, apVal, pRowid); |
| 182559 | } |
| 182560 | } |
| 182561 | } |
| 182562 | |
| @@ -182615,11 +182751,13 @@ | |
| 182751 | /* Initialize all iterators */ |
| 182752 | for(i=0; i<nIter && rc==SQLITE_OK; i++){ |
| 182753 | const u8 *a; |
| 182754 | int n; |
| 182755 | rc = fts5CsrPoslist(pCsr, i, &a, &n); |
| 182756 | if( rc==SQLITE_OK ){ |
| 182757 | sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]); |
| 182758 | } |
| 182759 | } |
| 182760 | |
| 182761 | if( rc==SQLITE_OK ){ |
| 182762 | while( 1 ){ |
| 182763 | int *aInst; |
| @@ -182905,12 +183043,19 @@ | |
| 183043 | int rc = SQLITE_OK; |
| 183044 | Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; |
| 183045 | Fts5Config *pConfig = ((Fts5Table*)(pCsr->base.pVtab))->pConfig; |
| 183046 | |
| 183047 | if( pConfig->eDetail==FTS5_DETAIL_COLUMNS ){ |
| 183048 | Fts5Sorter *pSorter = pCsr->pSorter; |
| 183049 | int n; |
| 183050 | if( pSorter ){ |
| 183051 | int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]); |
| 183052 | n = pSorter->aIdx[iPhrase] - i1; |
| 183053 | pIter->a = &pSorter->aPoslist[i1]; |
| 183054 | }else{ |
| 183055 | rc = sqlite3Fts5ExprPhraseCollist(pCsr->pExpr, iPhrase, &pIter->a, &n); |
| 183056 | } |
| 183057 | if( rc==SQLITE_OK ){ |
| 183058 | pIter->b = &pIter->a[n]; |
| 183059 | *piCol = 0; |
| 183060 | fts5ApiPhraseNextColumn(pCtx, pIter, piCol); |
| 183061 | } |
| @@ -183451,11 +183596,11 @@ | |
| 183596 | sqlite3_context *pCtx, /* Function call context */ |
| 183597 | int nArg, /* Number of args */ |
| 183598 | sqlite3_value **apVal /* Function arguments */ |
| 183599 | ){ |
| 183600 | assert( nArg==0 ); |
| 183601 | sqlite3_result_text(pCtx, "fts5: 2016-01-18 17:48:28 acaf426449bf6fd3140fd63141750ff69d1119a5", -1, SQLITE_TRANSIENT); |
| 183602 | } |
| 183603 | |
| 183604 | static int fts5Init(sqlite3 *db){ |
| 183605 | static const sqlite3_module fts5Mod = { |
| 183606 | /* iVersion */ 2, |
| @@ -183936,43 +184081,56 @@ | |
| 184081 | /* |
| 184082 | ** If a row with rowid iDel is present in the %_content table, add the |
| 184083 | ** delete-markers to the FTS index necessary to delete it. Do not actually |
| 184084 | ** remove the %_content row at this time though. |
| 184085 | */ |
| 184086 | static int fts5StorageDeleteFromIndex( |
| 184087 | Fts5Storage *p, |
| 184088 | i64 iDel, |
| 184089 | sqlite3_value **apVal |
| 184090 | ){ |
| 184091 | Fts5Config *pConfig = p->pConfig; |
| 184092 | sqlite3_stmt *pSeek = 0; /* SELECT to read row iDel from %_data */ |
| 184093 | int rc; /* Return code */ |
| 184094 | int rc2; /* sqlite3_reset() return code */ |
| 184095 | int iCol; |
| 184096 | Fts5InsertCtx ctx; |
| 184097 | |
| 184098 | if( apVal==0 ){ |
| 184099 | rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP, &pSeek, 0); |
| 184100 | if( rc!=SQLITE_OK ) return rc; |
| 184101 | sqlite3_bind_int64(pSeek, 1, iDel); |
| 184102 | if( sqlite3_step(pSeek)!=SQLITE_ROW ){ |
| 184103 | return sqlite3_reset(pSeek); |
| 184104 | } |
| 184105 | } |
| 184106 | |
| 184107 | ctx.pStorage = p; |
| 184108 | ctx.iCol = -1; |
| 184109 | rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel); |
| 184110 | for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){ |
| 184111 | if( pConfig->abUnindexed[iCol-1]==0 ){ |
| 184112 | const char *zText; |
| 184113 | int nText; |
| 184114 | if( pSeek ){ |
| 184115 | zText = (const char*)sqlite3_column_text(pSeek, iCol); |
| 184116 | nText = sqlite3_column_bytes(pSeek, iCol); |
| 184117 | }else{ |
| 184118 | zText = (const char*)sqlite3_value_text(apVal[iCol-1]); |
| 184119 | nText = sqlite3_value_bytes(apVal[iCol-1]); |
| 184120 | } |
| 184121 | ctx.szCol = 0; |
| 184122 | rc = sqlite3Fts5Tokenize(pConfig, FTS5_TOKENIZE_DOCUMENT, |
| 184123 | zText, nText, (void*)&ctx, fts5StorageInsertCallback |
| 184124 | ); |
| 184125 | p->aTotalSize[iCol-1] -= (i64)ctx.szCol; |
| 184126 | } |
| 184127 | } |
| 184128 | p->nTotalRow--; |
| 184129 | |
| 184130 | rc2 = sqlite3_reset(pSeek); |
| 184131 | if( rc==SQLITE_OK ) rc = rc2; |
| 184132 | return rc; |
| 184133 | } |
| 184134 | |
| 184135 | |
| 184136 | /* |
| @@ -184048,20 +184206,21 @@ | |
| 184206 | } |
| 184207 | |
| 184208 | /* |
| 184209 | ** Remove a row from the FTS table. |
| 184210 | */ |
| 184211 | static int sqlite3Fts5StorageDelete(Fts5Storage *p, i64 iDel, sqlite3_value **apVal){ |
| 184212 | Fts5Config *pConfig = p->pConfig; |
| 184213 | int rc; |
| 184214 | sqlite3_stmt *pDel = 0; |
| 184215 | |
| 184216 | assert( pConfig->eContent!=FTS5_CONTENT_NORMAL || apVal==0 ); |
| 184217 | rc = fts5StorageLoadTotals(p, 1); |
| 184218 | |
| 184219 | /* Delete the index records */ |
| 184220 | if( rc==SQLITE_OK ){ |
| 184221 | rc = fts5StorageDeleteFromIndex(p, iDel, apVal); |
| 184222 | } |
| 184223 | |
| 184224 | /* Delete the %_docsize record */ |
| 184225 | if( rc==SQLITE_OK && pConfig->bColumnsize ){ |
| 184226 | rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_DOCSIZE, &pDel, 0); |
| @@ -184075,65 +184234,10 @@ | |
| 184234 | /* Delete the %_content record */ |
| 184235 | if( pConfig->eContent==FTS5_CONTENT_NORMAL ){ |
| 184236 | if( rc==SQLITE_OK ){ |
| 184237 | rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_CONTENT, &pDel, 0); |
| 184238 | } |
| 184239 | if( rc==SQLITE_OK ){ |
| 184240 | sqlite3_bind_int64(pDel, 1, iDel); |
| 184241 | sqlite3_step(pDel); |
| 184242 | rc = sqlite3_reset(pDel); |
| 184243 | } |
| @@ -187089,10 +187193,14 @@ | |
| 187193 | int iCol = -1; |
| 187194 | while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){ |
| 187195 | int ii = FTS5_POS2COLUMN(iPos); |
| 187196 | pCsr->aCnt[ii]++; |
| 187197 | if( iCol!=ii ){ |
| 187198 | if( ii>=nCol ){ |
| 187199 | rc = FTS5_CORRUPT; |
| 187200 | break; |
| 187201 | } |
| 187202 | pCsr->aDoc[ii]++; |
| 187203 | iCol = ii; |
| 187204 | } |
| 187205 | } |
| 187206 | } |
| @@ -187106,11 +187214,15 @@ | |
| 187214 | Fts5Buffer buf = {0, 0, 0}; |
| 187215 | rc = sqlite3Fts5IterPoslistBuffer(pCsr->pIter, &buf); |
| 187216 | if( rc==SQLITE_OK ){ |
| 187217 | while( 0==sqlite3Fts5PoslistNext64(buf.p, buf.n, &iOff,&iPos) ){ |
| 187218 | assert_nc( iPos>=0 && iPos<nCol ); |
| 187219 | if( iPos>=nCol ){ |
| 187220 | rc = FTS5_CORRUPT; |
| 187221 | break; |
| 187222 | } |
| 187223 | pCsr->aDoc[iPos]++; |
| 187224 | } |
| 187225 | } |
| 187226 | sqlite3Fts5BufferFree(&buf); |
| 187227 | } |
| 187228 | break; |
| @@ -187134,11 +187246,11 @@ | |
| 187246 | } |
| 187247 | } |
| 187248 | } |
| 187249 | } |
| 187250 | |
| 187251 | if( rc==SQLITE_OK && pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){ |
| 187252 | while( pCsr->aDoc[pCsr->iCol]==0 ) pCsr->iCol++; |
| 187253 | assert( pCsr->iCol<pCsr->pConfig->nCol ); |
| 187254 | } |
| 187255 | return rc; |
| 187256 | } |
| 187257 |
+1
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -111,11 +111,11 @@ | ||
| 111 | 111 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 112 | 112 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 113 | 113 | */ |
| 114 | 114 | #define SQLITE_VERSION "3.11.0" |
| 115 | 115 | #define SQLITE_VERSION_NUMBER 3011000 |
| 116 | -#define SQLITE_SOURCE_ID "2016-01-14 14:19:50 d17bc2c92f4d086280e49a3cc72993be7fee2da7" | |
| 116 | +#define SQLITE_SOURCE_ID "2016-01-18 17:48:28 acaf426449bf6fd3140fd63141750ff69d1119a5" | |
| 117 | 117 | |
| 118 | 118 | /* |
| 119 | 119 | ** CAPI3REF: Run-Time Library Version Numbers |
| 120 | 120 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 121 | 121 | ** |
| 122 | 122 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -111,11 +111,11 @@ | |
| 111 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 112 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 113 | */ |
| 114 | #define SQLITE_VERSION "3.11.0" |
| 115 | #define SQLITE_VERSION_NUMBER 3011000 |
| 116 | #define SQLITE_SOURCE_ID "2016-01-14 14:19:50 d17bc2c92f4d086280e49a3cc72993be7fee2da7" |
| 117 | |
| 118 | /* |
| 119 | ** CAPI3REF: Run-Time Library Version Numbers |
| 120 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 121 | ** |
| 122 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -111,11 +111,11 @@ | |
| 111 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 112 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 113 | */ |
| 114 | #define SQLITE_VERSION "3.11.0" |
| 115 | #define SQLITE_VERSION_NUMBER 3011000 |
| 116 | #define SQLITE_SOURCE_ID "2016-01-18 17:48:28 acaf426449bf6fd3140fd63141750ff69d1119a5" |
| 117 | |
| 118 | /* |
| 119 | ** CAPI3REF: Run-Time Library Version Numbers |
| 120 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 121 | ** |
| 122 |