Fossil SCM
Latest upstream sqlite3 shell.c, primarily to squelch warnings on cygwin.
Commit
4d34e18c213827effeafd3c7f05aa0ac1ca8ddb90b49f8453e503c54dd47aca4
Parent
007fd18d69950eb…
1 file changed
+81
-37
+81
-37
| --- extsrc/shell.c | ||
| +++ extsrc/shell.c | ||
| @@ -234,10 +234,12 @@ | ||
| 234 | 234 | |
| 235 | 235 | /* ctype macros that work with signed characters */ |
| 236 | 236 | #define IsSpace(X) isspace((unsigned char)X) |
| 237 | 237 | #define IsDigit(X) isdigit((unsigned char)X) |
| 238 | 238 | #define ToLower(X) (char)tolower((unsigned char)X) |
| 239 | +#define IsAlnum(X) isalnum((unsigned char)X) | |
| 240 | +#define IsAlpha(X) isalpha((unsigned char)X) | |
| 239 | 241 | |
| 240 | 242 | #if defined(_WIN32) || defined(WIN32) |
| 241 | 243 | #if SQLITE_OS_WINRT |
| 242 | 244 | #include <intrin.h> |
| 243 | 245 | #endif |
| @@ -1506,13 +1508,13 @@ | ||
| 1506 | 1508 | ** Return '"' if quoting is required. Return 0 if no quoting is required. |
| 1507 | 1509 | */ |
| 1508 | 1510 | static char quoteChar(const char *zName){ |
| 1509 | 1511 | int i; |
| 1510 | 1512 | if( zName==0 ) return '"'; |
| 1511 | - if( !isalpha((unsigned char)zName[0]) && zName[0]!='_' ) return '"'; | |
| 1513 | + if( !IsAlpha(zName[0]) && zName[0]!='_' ) return '"'; | |
| 1512 | 1514 | for(i=0; zName[i]; i++){ |
| 1513 | - if( !isalnum((unsigned char)zName[i]) && zName[i]!='_' ) return '"'; | |
| 1515 | + if( !IsAlnum(zName[i]) && zName[i]!='_' ) return '"'; | |
| 1514 | 1516 | } |
| 1515 | 1517 | return sqlite3_keyword_check(zName, i) ? '"' : 0; |
| 1516 | 1518 | } |
| 1517 | 1519 | |
| 1518 | 1520 | /* |
| @@ -2425,11 +2427,11 @@ | ||
| 2425 | 2427 | ** content in cases where the content starts |
| 2426 | 2428 | ** with a digit. |
| 2427 | 2429 | ** |
| 2428 | 2430 | ** typeof(Y)='blob' The hash is taken over prefix "Bnnn:" followed |
| 2429 | 2431 | ** by the binary content of the blob. The "nnn" |
| 2430 | -** in the prefix is the mimimum-length decimal | |
| 2432 | +** in the prefix is the minimum-length decimal | |
| 2431 | 2433 | ** representation of the byte-length of the blob. |
| 2432 | 2434 | ** |
| 2433 | 2435 | ** According to the rules above, all of the following SELECT statements |
| 2434 | 2436 | ** should return TRUE: |
| 2435 | 2437 | ** |
| @@ -3646,11 +3648,11 @@ | ||
| 3646 | 3648 | ** |
| 3647 | 3649 | ** UINT works like BINARY for text, except that embedded strings |
| 3648 | 3650 | ** of digits compare in numeric order. |
| 3649 | 3651 | ** |
| 3650 | 3652 | ** * Leading zeros are handled properly, in the sense that |
| 3651 | -** they do not mess of the maginitude comparison of embedded | |
| 3653 | +** they do not mess of the magnitude comparison of embedded | |
| 3652 | 3654 | ** strings of digits. "x00123y" is equal to "x123y". |
| 3653 | 3655 | ** |
| 3654 | 3656 | ** * Only unsigned integers are recognized. Plus and minus |
| 3655 | 3657 | ** signs are ignored. Decimal points and exponential notation |
| 3656 | 3658 | ** are ignored. |
| @@ -3752,10 +3754,13 @@ | ||
| 3752 | 3754 | ** warnings. */ |
| 3753 | 3755 | #ifndef UNUSED_PARAMETER |
| 3754 | 3756 | # define UNUSED_PARAMETER(X) (void)(X) |
| 3755 | 3757 | #endif |
| 3756 | 3758 | |
| 3759 | +#ifndef IsSpace | |
| 3760 | +#define IsSpace(X) isspace((unsigned char)X) | |
| 3761 | +#endif | |
| 3757 | 3762 | |
| 3758 | 3763 | /* A decimal object */ |
| 3759 | 3764 | typedef struct Decimal Decimal; |
| 3760 | 3765 | struct Decimal { |
| 3761 | 3766 | char sign; /* 0 for positive, 1 for negative */ |
| @@ -3801,11 +3806,11 @@ | ||
| 3801 | 3806 | p->isNull = 0; |
| 3802 | 3807 | p->nDigit = 0; |
| 3803 | 3808 | p->nFrac = 0; |
| 3804 | 3809 | p->a = sqlite3_malloc64( n+1 ); |
| 3805 | 3810 | if( p->a==0 ) goto new_from_text_failed; |
| 3806 | - for(i=0; isspace(zIn[i]); i++){} | |
| 3811 | + for(i=0; IsSpace(zIn[i]); i++){} | |
| 3807 | 3812 | if( zIn[i]=='-' ){ |
| 3808 | 3813 | p->sign = 1; |
| 3809 | 3814 | i++; |
| 3810 | 3815 | }else if( zIn[i]=='+' ){ |
| 3811 | 3816 | i++; |
| @@ -4456,11 +4461,11 @@ | ||
| 4456 | 4461 | } |
| 4457 | 4462 | decimal_free(pA); |
| 4458 | 4463 | decimal_free(pB); |
| 4459 | 4464 | } |
| 4460 | 4465 | |
| 4461 | -/* Aggregate funcion: decimal_sum(X) | |
| 4466 | +/* Aggregate function: decimal_sum(X) | |
| 4462 | 4467 | ** |
| 4463 | 4468 | ** Works like sum() except that it uses decimal arithmetic for unlimited |
| 4464 | 4469 | ** precision. |
| 4465 | 4470 | */ |
| 4466 | 4471 | static void decimalSumStep( |
| @@ -4817,11 +4822,11 @@ | ||
| 4817 | 4822 | } |
| 4818 | 4823 | |
| 4819 | 4824 | /* |
| 4820 | 4825 | ** Generate an error for a percentile function. |
| 4821 | 4826 | ** |
| 4822 | -** The error format string must have exactly one occurrance of "%%s()" | |
| 4827 | +** The error format string must have exactly one occurrence of "%%s()" | |
| 4823 | 4828 | ** (with two '%' characters). That substring will be replaced by the name |
| 4824 | 4829 | ** of the function. |
| 4825 | 4830 | */ |
| 4826 | 4831 | static void percentError(sqlite3_context *pCtx, const char *zFormat, ...){ |
| 4827 | 4832 | PercentileFunc *pFunc = (PercentileFunc*)sqlite3_user_data(pCtx); |
| @@ -5957,11 +5962,11 @@ | ||
| 5957 | 5962 | ** number format: |
| 5958 | 5963 | ** |
| 5959 | 5964 | ** WITH c(name,bin) AS (VALUES |
| 5960 | 5965 | ** ('minimum positive value', x'0000000000000001'), |
| 5961 | 5966 | ** ('maximum subnormal value', x'000fffffffffffff'), |
| 5962 | -** ('mininum positive nornal value', x'0010000000000000'), | |
| 5967 | +** ('minimum positive normal value', x'0010000000000000'), | |
| 5963 | 5968 | ** ('maximum value', x'7fefffffffffffff')) |
| 5964 | 5969 | ** SELECT c.name, decimal_mul(ieee754_mantissa(c.bin),pow2.v) |
| 5965 | 5970 | ** FROM pow2, c WHERE pow2.x=ieee754_exponent(c.bin); |
| 5966 | 5971 | ** |
| 5967 | 5972 | */ |
| @@ -6344,11 +6349,11 @@ | ||
| 6344 | 6349 | * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */ |
| 6345 | 6350 | smBase += (mxI64/2) * smStep; |
| 6346 | 6351 | smBase += (mxI64 - mxI64/2) * smStep; |
| 6347 | 6352 | } |
| 6348 | 6353 | /* Under UBSAN (or on 1's complement machines), must do this last term |
| 6349 | - * in steps to avoid the dreaded (and harmless) signed multiply overlow. */ | |
| 6354 | + * in steps to avoid the dreaded (and harmless) signed multiply overflow. */ | |
| 6350 | 6355 | if( ix>=2 ){ |
| 6351 | 6356 | sqlite3_int64 ix2 = (sqlite3_int64)ix/2; |
| 6352 | 6357 | smBase += ix2*smStep; |
| 6353 | 6358 | ix -= ix2; |
| 6354 | 6359 | } |
| @@ -9024,10 +9029,15 @@ | ||
| 9024 | 9029 | #include <assert.h> |
| 9025 | 9030 | #include <string.h> |
| 9026 | 9031 | #include <ctype.h> |
| 9027 | 9032 | |
| 9028 | 9033 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 9034 | + | |
| 9035 | +#ifndef IsAlnum | |
| 9036 | +#define IsAlnum(X) isalnum((unsigned char)X) | |
| 9037 | +#endif | |
| 9038 | + | |
| 9029 | 9039 | |
| 9030 | 9040 | /* completion_vtab is a subclass of sqlite3_vtab which will |
| 9031 | 9041 | ** serve as the underlying representation of a completion virtual table |
| 9032 | 9042 | */ |
| 9033 | 9043 | typedef struct completion_vtab completion_vtab; |
| @@ -9361,11 +9371,11 @@ | ||
| 9361 | 9371 | if( pCur->zLine==0 ) return SQLITE_NOMEM; |
| 9362 | 9372 | } |
| 9363 | 9373 | } |
| 9364 | 9374 | if( pCur->zLine!=0 && pCur->zPrefix==0 ){ |
| 9365 | 9375 | int i = pCur->nLine; |
| 9366 | - while( i>0 && (isalnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){ | |
| 9376 | + while( i>0 && (IsAlnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){ | |
| 9367 | 9377 | i--; |
| 9368 | 9378 | } |
| 9369 | 9379 | pCur->nPrefix = pCur->nLine - i; |
| 9370 | 9380 | if( pCur->nPrefix>0 ){ |
| 9371 | 9381 | pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i); |
| @@ -14768,11 +14778,11 @@ | ||
| 14768 | 14778 | /* Register the auth callback with dbv */ |
| 14769 | 14779 | if( rc==SQLITE_OK ){ |
| 14770 | 14780 | sqlite3_set_authorizer(pNew->dbv, idxAuthCallback, (void*)pNew); |
| 14771 | 14781 | } |
| 14772 | 14782 | |
| 14773 | - /* If an error has occurred, free the new object and reutrn NULL. Otherwise, | |
| 14783 | + /* If an error has occurred, free the new object and return NULL. Otherwise, | |
| 14774 | 14784 | ** return the new sqlite3expert handle. */ |
| 14775 | 14785 | if( rc!=SQLITE_OK ){ |
| 14776 | 14786 | sqlite3_expert_destroy(pNew); |
| 14777 | 14787 | pNew = 0; |
| 14778 | 14788 | } |
| @@ -16290,11 +16300,11 @@ | ||
| 16290 | 16300 | ** |
| 16291 | 16301 | ** PRAGMA vfstrace('+all'); |
| 16292 | 16302 | ** |
| 16293 | 16303 | ** Individual APIs can be enabled or disabled by name, with or without |
| 16294 | 16304 | ** the initial "x" character. For example, to set up for tracing lock |
| 16295 | -** primatives only: | |
| 16305 | +** primitives only: | |
| 16296 | 16306 | ** |
| 16297 | 16307 | ** PRAGMA vfstrace('-all, +Lock,Unlock,ShmLock'); |
| 16298 | 16308 | ** |
| 16299 | 16309 | ** The argument to the vfstrace pragma ignores capitalization and any |
| 16300 | 16310 | ** characters other than alphabetics, '+', and '-'. |
| @@ -21241,41 +21251,57 @@ | ||
| 21241 | 21251 | ** function is called. |
| 21242 | 21252 | */ |
| 21243 | 21253 | static void recoverStep(sqlite3_recover *p){ |
| 21244 | 21254 | assert( p && p->errCode==SQLITE_OK ); |
| 21245 | 21255 | switch( p->eState ){ |
| 21246 | - case RECOVER_STATE_INIT: | |
| 21256 | + case RECOVER_STATE_INIT: { | |
| 21257 | + int bUseWrapper = 1; | |
| 21247 | 21258 | /* This is the very first call to sqlite3_recover_step() on this object. |
| 21248 | 21259 | */ |
| 21249 | 21260 | recoverSqlCallback(p, "BEGIN"); |
| 21250 | 21261 | recoverSqlCallback(p, "PRAGMA writable_schema = on"); |
| 21262 | + recoverSqlCallback(p, "PRAGMA foreign_keys = off"); | |
| 21251 | 21263 | |
| 21252 | 21264 | recoverEnterMutex(); |
| 21253 | - recoverInstallWrapper(p); | |
| 21254 | 21265 | |
| 21255 | 21266 | /* Open the output database. And register required virtual tables and |
| 21256 | 21267 | ** user functions with the new handle. */ |
| 21257 | 21268 | recoverOpenOutput(p); |
| 21258 | 21269 | |
| 21259 | - /* Open transactions on both the input and output databases. */ | |
| 21260 | - sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0); | |
| 21261 | - recoverExec(p, p->dbIn, "PRAGMA writable_schema = on"); | |
| 21262 | - recoverExec(p, p->dbIn, "BEGIN"); | |
| 21263 | - if( p->errCode==SQLITE_OK ) p->bCloseTransaction = 1; | |
| 21264 | - recoverExec(p, p->dbIn, "SELECT 1 FROM sqlite_schema"); | |
| 21265 | - recoverTransferSettings(p); | |
| 21266 | - recoverOpenRecovery(p); | |
| 21267 | - recoverCacheSchema(p); | |
| 21268 | - | |
| 21269 | - recoverUninstallWrapper(p); | |
| 21270 | + /* Attempt to open a transaction and read page 1 of the input database. | |
| 21271 | + ** Two attempts may be made - one with a wrapper installed to ensure | |
| 21272 | + ** that the database header is sane, and then if that attempt returns | |
| 21273 | + ** SQLITE_NOTADB, then again with no wrapper. The second attempt is | |
| 21274 | + ** required for encrypted databases. */ | |
| 21275 | + if( p->errCode==SQLITE_OK ){ | |
| 21276 | + do{ | |
| 21277 | + p->errCode = SQLITE_OK; | |
| 21278 | + if( bUseWrapper ) recoverInstallWrapper(p); | |
| 21279 | + | |
| 21280 | + /* Open a transaction on the input database. */ | |
| 21281 | + sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0); | |
| 21282 | + recoverExec(p, p->dbIn, "PRAGMA writable_schema = on"); | |
| 21283 | + recoverExec(p, p->dbIn, "BEGIN"); | |
| 21284 | + if( p->errCode==SQLITE_OK ) p->bCloseTransaction = 1; | |
| 21285 | + recoverExec(p, p->dbIn, "SELECT 1 FROM sqlite_schema"); | |
| 21286 | + recoverTransferSettings(p); | |
| 21287 | + recoverOpenRecovery(p); | |
| 21288 | + recoverCacheSchema(p); | |
| 21289 | + | |
| 21290 | + if( bUseWrapper ) recoverUninstallWrapper(p); | |
| 21291 | + }while( p->errCode==SQLITE_NOTADB | |
| 21292 | + && (bUseWrapper--) | |
| 21293 | + && SQLITE_OK==sqlite3_exec(p->dbIn, "ROLLBACK", 0, 0, 0) | |
| 21294 | + ); | |
| 21295 | + } | |
| 21296 | + | |
| 21270 | 21297 | recoverLeaveMutex(); |
| 21271 | - | |
| 21272 | 21298 | recoverExec(p, p->dbOut, "BEGIN"); |
| 21273 | - | |
| 21274 | 21299 | recoverWriteSchema1(p); |
| 21275 | 21300 | p->eState = RECOVER_STATE_WRITING; |
| 21276 | 21301 | break; |
| 21302 | + } | |
| 21277 | 21303 | |
| 21278 | 21304 | case RECOVER_STATE_WRITING: { |
| 21279 | 21305 | if( p->w1.pTbls==0 ){ |
| 21280 | 21306 | recoverWriteDataInit(p); |
| 21281 | 21307 | } |
| @@ -21711,17 +21737,18 @@ | ||
| 21711 | 21737 | #define SHELL_PROGRESS_RESET 0x02 /* Reset the count when the progress |
| 21712 | 21738 | ** callback limit is reached, and for each |
| 21713 | 21739 | ** top-level SQL statement */ |
| 21714 | 21740 | #define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */ |
| 21715 | 21741 | |
| 21716 | -/* Allowed values for ShellState.eEscMode | |
| 21742 | +/* Allowed values for ShellState.eEscMode. The default value should | |
| 21743 | +** be 0, so to change the default, reorder the names. | |
| 21717 | 21744 | */ |
| 21718 | -#define SHELL_ESC_SYMBOL 0 /* Substitute U+2400 graphics */ | |
| 21719 | -#define SHELL_ESC_ASCII 1 /* Substitute ^Y for X where Y=X+0x40 */ | |
| 21745 | +#define SHELL_ESC_ASCII 0 /* Substitute ^Y for X where Y=X+0x40 */ | |
| 21746 | +#define SHELL_ESC_SYMBOL 1 /* Substitute U+2400 graphics */ | |
| 21720 | 21747 | #define SHELL_ESC_OFF 2 /* Send characters verbatim */ |
| 21721 | 21748 | |
| 21722 | -static const char *shell_EscModeNames[] = { "symbol", "ascii", "off" }; | |
| 21749 | +static const char *shell_EscModeNames[] = { "ascii", "symbol", "off" }; | |
| 21723 | 21750 | |
| 21724 | 21751 | /* |
| 21725 | 21752 | ** These are the allowed shellFlgs values |
| 21726 | 21753 | */ |
| 21727 | 21754 | #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */ |
| @@ -22902,18 +22929,22 @@ | ||
| 22902 | 22929 | int j; |
| 22903 | 22930 | int nParen = 0; |
| 22904 | 22931 | char cEnd = 0; |
| 22905 | 22932 | char c; |
| 22906 | 22933 | int nLine = 0; |
| 22934 | + int isIndex; | |
| 22935 | + int isWhere = 0; | |
| 22907 | 22936 | assert( nArg==1 ); |
| 22908 | 22937 | if( azArg[0]==0 ) break; |
| 22909 | 22938 | if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0 |
| 22910 | 22939 | || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0 |
| 22911 | 22940 | ){ |
| 22912 | 22941 | sqlite3_fprintf(p->out, "%s;\n", azArg[0]); |
| 22913 | 22942 | break; |
| 22914 | 22943 | } |
| 22944 | + isIndex = sqlite3_strlike("CREATE INDEX%", azArg[0], 0)==0 | |
| 22945 | + || sqlite3_strlike("CREATE UNIQUE INDEX%", azArg[0], 0)==0; | |
| 22915 | 22946 | z = sqlite3_mprintf("%s", azArg[0]); |
| 22916 | 22947 | shell_check_oom(z); |
| 22917 | 22948 | j = 0; |
| 22918 | 22949 | for(i=0; IsSpace(z[i]); i++){} |
| 22919 | 22950 | for(; (c = z[i])!=0; i++){ |
| @@ -22939,18 +22970,30 @@ | ||
| 22939 | 22970 | cEnd = '\n'; |
| 22940 | 22971 | }else if( c=='(' ){ |
| 22941 | 22972 | nParen++; |
| 22942 | 22973 | }else if( c==')' ){ |
| 22943 | 22974 | nParen--; |
| 22944 | - if( nLine>0 && nParen==0 && j>0 ){ | |
| 22975 | + if( nLine>0 && nParen==0 && j>0 && !isWhere ){ | |
| 22945 | 22976 | printSchemaLineN(p->out, z, j, "\n"); |
| 22946 | 22977 | j = 0; |
| 22947 | 22978 | } |
| 22979 | + }else if( (c=='w' || c=='W') | |
| 22980 | + && nParen==0 && isIndex | |
| 22981 | + && sqlite3_strnicmp("WHERE",&z[i],5)==0 | |
| 22982 | + && !IsAlnum(z[i+5]) && z[i+5]!='_' ){ | |
| 22983 | + isWhere = 1; | |
| 22984 | + }else if( isWhere && (c=='A' || c=='a') | |
| 22985 | + && nParen==0 | |
| 22986 | + && sqlite3_strnicmp("AND",&z[i],3)==0 | |
| 22987 | + && !IsAlnum(z[i+3]) && z[i+3]!='_' ){ | |
| 22988 | + printSchemaLineN(p->out, z, j, "\n "); | |
| 22989 | + j = 0; | |
| 22948 | 22990 | } |
| 22949 | 22991 | z[j++] = c; |
| 22950 | 22992 | if( nParen==1 && cEnd==0 |
| 22951 | 22993 | && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1))) |
| 22994 | + && !isWhere | |
| 22952 | 22995 | ){ |
| 22953 | 22996 | if( c=='\n' ) j--; |
| 22954 | 22997 | printSchemaLineN(p->out, z, j, "\n "); |
| 22955 | 22998 | j = 0; |
| 22956 | 22999 | nLine++; |
| @@ -24150,15 +24193,15 @@ | ||
| 24150 | 24193 | i++; |
| 24151 | 24194 | } |
| 24152 | 24195 | if( n>=mxWidth && bWordWrap ){ |
| 24153 | 24196 | /* Perhaps try to back up to a better place to break the line */ |
| 24154 | 24197 | for(k=i; k>i/2; k--){ |
| 24155 | - if( isspace(z[k-1]) ) break; | |
| 24198 | + if( IsSpace(z[k-1]) ) break; | |
| 24156 | 24199 | } |
| 24157 | 24200 | if( k<=i/2 ){ |
| 24158 | 24201 | for(k=i; k>i/2; k--){ |
| 24159 | - if( isalnum(z[k-1])!=isalnum(z[k]) && (z[k]&0xc0)!=0x80 ) break; | |
| 24202 | + if( IsAlnum(z[k-1])!=IsAlnum(z[k]) && (z[k]&0xc0)!=0x80 ) break; | |
| 24160 | 24203 | } |
| 24161 | 24204 | } |
| 24162 | 24205 | if( k<=i/2 ){ |
| 24163 | 24206 | k = i; |
| 24164 | 24207 | }else{ |
| @@ -26088,11 +26131,11 @@ | ||
| 26088 | 26131 | #if HAVE_LINENOISE==2 |
| 26089 | 26132 | UNUSED_PARAMETER(pUserData); |
| 26090 | 26133 | #endif |
| 26091 | 26134 | if( nLine>(i64)sizeof(zBuf)-30 ) return; |
| 26092 | 26135 | if( zLine[0]=='.' || zLine[0]=='#') return; |
| 26093 | - for(i=nLine-1; i>=0 && (isalnum(zLine[i]) || zLine[i]=='_'); i--){} | |
| 26136 | + for(i=nLine-1; i>=0 && (IsAlnum(zLine[i]) || zLine[i]=='_'); i--){} | |
| 26094 | 26137 | if( i==nLine-1 ) return; |
| 26095 | 26138 | iStart = i+1; |
| 26096 | 26139 | memcpy(zBuf, zLine, iStart); |
| 26097 | 26140 | zSql = sqlite3_mprintf("SELECT DISTINCT candidate COLLATE nocase" |
| 26098 | 26141 | " FROM completion(%Q,%Q) ORDER BY 1", |
| @@ -28328,10 +28371,11 @@ | ||
| 28328 | 28371 | sqlite3_recover_config(p, 789, (void*)zRecoveryDb); /* Debug use only */ |
| 28329 | 28372 | sqlite3_recover_config(p, SQLITE_RECOVER_LOST_AND_FOUND, (void*)zLAF); |
| 28330 | 28373 | sqlite3_recover_config(p, SQLITE_RECOVER_ROWIDS, (void*)&bRowids); |
| 28331 | 28374 | sqlite3_recover_config(p, SQLITE_RECOVER_FREELIST_CORRUPT,(void*)&bFreelist); |
| 28332 | 28375 | |
| 28376 | + sqlite3_fprintf(pState->out, ".dbconfig defensive off\n"); | |
| 28333 | 28377 | sqlite3_recover_run(p); |
| 28334 | 28378 | if( sqlite3_recover_errcode(p)!=SQLITE_OK ){ |
| 28335 | 28379 | const char *zErr = sqlite3_recover_errmsg(p); |
| 28336 | 28380 | int errCode = sqlite3_recover_errcode(p); |
| 28337 | 28381 | sqlite3_fprintf(stderr,"sql error: %s (%d)\n", zErr, errCode); |
| @@ -32419,11 +32463,11 @@ | ||
| 32419 | 32463 | /* |
| 32420 | 32464 | ** The CLI needs a working sqlite3_complete() to work properly. So error |
| 32421 | 32465 | ** out of the build if compiling with SQLITE_OMIT_COMPLETE. |
| 32422 | 32466 | */ |
| 32423 | 32467 | #ifdef SQLITE_OMIT_COMPLETE |
| 32424 | -# error the CLI application is imcompatable with SQLITE_OMIT_COMPLETE. | |
| 32468 | +# error the CLI application is incompatable with SQLITE_OMIT_COMPLETE. | |
| 32425 | 32469 | #endif |
| 32426 | 32470 | |
| 32427 | 32471 | /* |
| 32428 | 32472 | ** Return true if zSql is a complete SQL statement. Return false if it |
| 32429 | 32473 | ** ends in the middle of a string literal or C-style comment. |
| @@ -32598,11 +32642,11 @@ | ||
| 32598 | 32642 | UNUSED_PARAMETER(in); |
| 32599 | 32643 | UNUSED_PARAMETER(isContinuation); |
| 32600 | 32644 | if(!z || !*z){ |
| 32601 | 32645 | return 0; |
| 32602 | 32646 | } |
| 32603 | - while(*z && isspace(*z)) ++z; | |
| 32647 | + while(*z && IsSpace(*z)) ++z; | |
| 32604 | 32648 | zBegin = z; |
| 32605 | 32649 | for(; *z && '\n'!=*z; ++nZ, ++z){} |
| 32606 | 32650 | if(nZ>0 && '\r'==zBegin[nZ-1]){ |
| 32607 | 32651 | --nZ; |
| 32608 | 32652 | } |
| 32609 | 32653 |
| --- extsrc/shell.c | |
| +++ extsrc/shell.c | |
| @@ -234,10 +234,12 @@ | |
| 234 | |
| 235 | /* ctype macros that work with signed characters */ |
| 236 | #define IsSpace(X) isspace((unsigned char)X) |
| 237 | #define IsDigit(X) isdigit((unsigned char)X) |
| 238 | #define ToLower(X) (char)tolower((unsigned char)X) |
| 239 | |
| 240 | #if defined(_WIN32) || defined(WIN32) |
| 241 | #if SQLITE_OS_WINRT |
| 242 | #include <intrin.h> |
| 243 | #endif |
| @@ -1506,13 +1508,13 @@ | |
| 1506 | ** Return '"' if quoting is required. Return 0 if no quoting is required. |
| 1507 | */ |
| 1508 | static char quoteChar(const char *zName){ |
| 1509 | int i; |
| 1510 | if( zName==0 ) return '"'; |
| 1511 | if( !isalpha((unsigned char)zName[0]) && zName[0]!='_' ) return '"'; |
| 1512 | for(i=0; zName[i]; i++){ |
| 1513 | if( !isalnum((unsigned char)zName[i]) && zName[i]!='_' ) return '"'; |
| 1514 | } |
| 1515 | return sqlite3_keyword_check(zName, i) ? '"' : 0; |
| 1516 | } |
| 1517 | |
| 1518 | /* |
| @@ -2425,11 +2427,11 @@ | |
| 2425 | ** content in cases where the content starts |
| 2426 | ** with a digit. |
| 2427 | ** |
| 2428 | ** typeof(Y)='blob' The hash is taken over prefix "Bnnn:" followed |
| 2429 | ** by the binary content of the blob. The "nnn" |
| 2430 | ** in the prefix is the mimimum-length decimal |
| 2431 | ** representation of the byte-length of the blob. |
| 2432 | ** |
| 2433 | ** According to the rules above, all of the following SELECT statements |
| 2434 | ** should return TRUE: |
| 2435 | ** |
| @@ -3646,11 +3648,11 @@ | |
| 3646 | ** |
| 3647 | ** UINT works like BINARY for text, except that embedded strings |
| 3648 | ** of digits compare in numeric order. |
| 3649 | ** |
| 3650 | ** * Leading zeros are handled properly, in the sense that |
| 3651 | ** they do not mess of the maginitude comparison of embedded |
| 3652 | ** strings of digits. "x00123y" is equal to "x123y". |
| 3653 | ** |
| 3654 | ** * Only unsigned integers are recognized. Plus and minus |
| 3655 | ** signs are ignored. Decimal points and exponential notation |
| 3656 | ** are ignored. |
| @@ -3752,10 +3754,13 @@ | |
| 3752 | ** warnings. */ |
| 3753 | #ifndef UNUSED_PARAMETER |
| 3754 | # define UNUSED_PARAMETER(X) (void)(X) |
| 3755 | #endif |
| 3756 | |
| 3757 | |
| 3758 | /* A decimal object */ |
| 3759 | typedef struct Decimal Decimal; |
| 3760 | struct Decimal { |
| 3761 | char sign; /* 0 for positive, 1 for negative */ |
| @@ -3801,11 +3806,11 @@ | |
| 3801 | p->isNull = 0; |
| 3802 | p->nDigit = 0; |
| 3803 | p->nFrac = 0; |
| 3804 | p->a = sqlite3_malloc64( n+1 ); |
| 3805 | if( p->a==0 ) goto new_from_text_failed; |
| 3806 | for(i=0; isspace(zIn[i]); i++){} |
| 3807 | if( zIn[i]=='-' ){ |
| 3808 | p->sign = 1; |
| 3809 | i++; |
| 3810 | }else if( zIn[i]=='+' ){ |
| 3811 | i++; |
| @@ -4456,11 +4461,11 @@ | |
| 4456 | } |
| 4457 | decimal_free(pA); |
| 4458 | decimal_free(pB); |
| 4459 | } |
| 4460 | |
| 4461 | /* Aggregate funcion: decimal_sum(X) |
| 4462 | ** |
| 4463 | ** Works like sum() except that it uses decimal arithmetic for unlimited |
| 4464 | ** precision. |
| 4465 | */ |
| 4466 | static void decimalSumStep( |
| @@ -4817,11 +4822,11 @@ | |
| 4817 | } |
| 4818 | |
| 4819 | /* |
| 4820 | ** Generate an error for a percentile function. |
| 4821 | ** |
| 4822 | ** The error format string must have exactly one occurrance of "%%s()" |
| 4823 | ** (with two '%' characters). That substring will be replaced by the name |
| 4824 | ** of the function. |
| 4825 | */ |
| 4826 | static void percentError(sqlite3_context *pCtx, const char *zFormat, ...){ |
| 4827 | PercentileFunc *pFunc = (PercentileFunc*)sqlite3_user_data(pCtx); |
| @@ -5957,11 +5962,11 @@ | |
| 5957 | ** number format: |
| 5958 | ** |
| 5959 | ** WITH c(name,bin) AS (VALUES |
| 5960 | ** ('minimum positive value', x'0000000000000001'), |
| 5961 | ** ('maximum subnormal value', x'000fffffffffffff'), |
| 5962 | ** ('mininum positive nornal value', x'0010000000000000'), |
| 5963 | ** ('maximum value', x'7fefffffffffffff')) |
| 5964 | ** SELECT c.name, decimal_mul(ieee754_mantissa(c.bin),pow2.v) |
| 5965 | ** FROM pow2, c WHERE pow2.x=ieee754_exponent(c.bin); |
| 5966 | ** |
| 5967 | */ |
| @@ -6344,11 +6349,11 @@ | |
| 6344 | * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */ |
| 6345 | smBase += (mxI64/2) * smStep; |
| 6346 | smBase += (mxI64 - mxI64/2) * smStep; |
| 6347 | } |
| 6348 | /* Under UBSAN (or on 1's complement machines), must do this last term |
| 6349 | * in steps to avoid the dreaded (and harmless) signed multiply overlow. */ |
| 6350 | if( ix>=2 ){ |
| 6351 | sqlite3_int64 ix2 = (sqlite3_int64)ix/2; |
| 6352 | smBase += ix2*smStep; |
| 6353 | ix -= ix2; |
| 6354 | } |
| @@ -9024,10 +9029,15 @@ | |
| 9024 | #include <assert.h> |
| 9025 | #include <string.h> |
| 9026 | #include <ctype.h> |
| 9027 | |
| 9028 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 9029 | |
| 9030 | /* completion_vtab is a subclass of sqlite3_vtab which will |
| 9031 | ** serve as the underlying representation of a completion virtual table |
| 9032 | */ |
| 9033 | typedef struct completion_vtab completion_vtab; |
| @@ -9361,11 +9371,11 @@ | |
| 9361 | if( pCur->zLine==0 ) return SQLITE_NOMEM; |
| 9362 | } |
| 9363 | } |
| 9364 | if( pCur->zLine!=0 && pCur->zPrefix==0 ){ |
| 9365 | int i = pCur->nLine; |
| 9366 | while( i>0 && (isalnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){ |
| 9367 | i--; |
| 9368 | } |
| 9369 | pCur->nPrefix = pCur->nLine - i; |
| 9370 | if( pCur->nPrefix>0 ){ |
| 9371 | pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i); |
| @@ -14768,11 +14778,11 @@ | |
| 14768 | /* Register the auth callback with dbv */ |
| 14769 | if( rc==SQLITE_OK ){ |
| 14770 | sqlite3_set_authorizer(pNew->dbv, idxAuthCallback, (void*)pNew); |
| 14771 | } |
| 14772 | |
| 14773 | /* If an error has occurred, free the new object and reutrn NULL. Otherwise, |
| 14774 | ** return the new sqlite3expert handle. */ |
| 14775 | if( rc!=SQLITE_OK ){ |
| 14776 | sqlite3_expert_destroy(pNew); |
| 14777 | pNew = 0; |
| 14778 | } |
| @@ -16290,11 +16300,11 @@ | |
| 16290 | ** |
| 16291 | ** PRAGMA vfstrace('+all'); |
| 16292 | ** |
| 16293 | ** Individual APIs can be enabled or disabled by name, with or without |
| 16294 | ** the initial "x" character. For example, to set up for tracing lock |
| 16295 | ** primatives only: |
| 16296 | ** |
| 16297 | ** PRAGMA vfstrace('-all, +Lock,Unlock,ShmLock'); |
| 16298 | ** |
| 16299 | ** The argument to the vfstrace pragma ignores capitalization and any |
| 16300 | ** characters other than alphabetics, '+', and '-'. |
| @@ -21241,41 +21251,57 @@ | |
| 21241 | ** function is called. |
| 21242 | */ |
| 21243 | static void recoverStep(sqlite3_recover *p){ |
| 21244 | assert( p && p->errCode==SQLITE_OK ); |
| 21245 | switch( p->eState ){ |
| 21246 | case RECOVER_STATE_INIT: |
| 21247 | /* This is the very first call to sqlite3_recover_step() on this object. |
| 21248 | */ |
| 21249 | recoverSqlCallback(p, "BEGIN"); |
| 21250 | recoverSqlCallback(p, "PRAGMA writable_schema = on"); |
| 21251 | |
| 21252 | recoverEnterMutex(); |
| 21253 | recoverInstallWrapper(p); |
| 21254 | |
| 21255 | /* Open the output database. And register required virtual tables and |
| 21256 | ** user functions with the new handle. */ |
| 21257 | recoverOpenOutput(p); |
| 21258 | |
| 21259 | /* Open transactions on both the input and output databases. */ |
| 21260 | sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0); |
| 21261 | recoverExec(p, p->dbIn, "PRAGMA writable_schema = on"); |
| 21262 | recoverExec(p, p->dbIn, "BEGIN"); |
| 21263 | if( p->errCode==SQLITE_OK ) p->bCloseTransaction = 1; |
| 21264 | recoverExec(p, p->dbIn, "SELECT 1 FROM sqlite_schema"); |
| 21265 | recoverTransferSettings(p); |
| 21266 | recoverOpenRecovery(p); |
| 21267 | recoverCacheSchema(p); |
| 21268 | |
| 21269 | recoverUninstallWrapper(p); |
| 21270 | recoverLeaveMutex(); |
| 21271 | |
| 21272 | recoverExec(p, p->dbOut, "BEGIN"); |
| 21273 | |
| 21274 | recoverWriteSchema1(p); |
| 21275 | p->eState = RECOVER_STATE_WRITING; |
| 21276 | break; |
| 21277 | |
| 21278 | case RECOVER_STATE_WRITING: { |
| 21279 | if( p->w1.pTbls==0 ){ |
| 21280 | recoverWriteDataInit(p); |
| 21281 | } |
| @@ -21711,17 +21737,18 @@ | |
| 21711 | #define SHELL_PROGRESS_RESET 0x02 /* Reset the count when the progress |
| 21712 | ** callback limit is reached, and for each |
| 21713 | ** top-level SQL statement */ |
| 21714 | #define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */ |
| 21715 | |
| 21716 | /* Allowed values for ShellState.eEscMode |
| 21717 | */ |
| 21718 | #define SHELL_ESC_SYMBOL 0 /* Substitute U+2400 graphics */ |
| 21719 | #define SHELL_ESC_ASCII 1 /* Substitute ^Y for X where Y=X+0x40 */ |
| 21720 | #define SHELL_ESC_OFF 2 /* Send characters verbatim */ |
| 21721 | |
| 21722 | static const char *shell_EscModeNames[] = { "symbol", "ascii", "off" }; |
| 21723 | |
| 21724 | /* |
| 21725 | ** These are the allowed shellFlgs values |
| 21726 | */ |
| 21727 | #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */ |
| @@ -22902,18 +22929,22 @@ | |
| 22902 | int j; |
| 22903 | int nParen = 0; |
| 22904 | char cEnd = 0; |
| 22905 | char c; |
| 22906 | int nLine = 0; |
| 22907 | assert( nArg==1 ); |
| 22908 | if( azArg[0]==0 ) break; |
| 22909 | if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0 |
| 22910 | || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0 |
| 22911 | ){ |
| 22912 | sqlite3_fprintf(p->out, "%s;\n", azArg[0]); |
| 22913 | break; |
| 22914 | } |
| 22915 | z = sqlite3_mprintf("%s", azArg[0]); |
| 22916 | shell_check_oom(z); |
| 22917 | j = 0; |
| 22918 | for(i=0; IsSpace(z[i]); i++){} |
| 22919 | for(; (c = z[i])!=0; i++){ |
| @@ -22939,18 +22970,30 @@ | |
| 22939 | cEnd = '\n'; |
| 22940 | }else if( c=='(' ){ |
| 22941 | nParen++; |
| 22942 | }else if( c==')' ){ |
| 22943 | nParen--; |
| 22944 | if( nLine>0 && nParen==0 && j>0 ){ |
| 22945 | printSchemaLineN(p->out, z, j, "\n"); |
| 22946 | j = 0; |
| 22947 | } |
| 22948 | } |
| 22949 | z[j++] = c; |
| 22950 | if( nParen==1 && cEnd==0 |
| 22951 | && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1))) |
| 22952 | ){ |
| 22953 | if( c=='\n' ) j--; |
| 22954 | printSchemaLineN(p->out, z, j, "\n "); |
| 22955 | j = 0; |
| 22956 | nLine++; |
| @@ -24150,15 +24193,15 @@ | |
| 24150 | i++; |
| 24151 | } |
| 24152 | if( n>=mxWidth && bWordWrap ){ |
| 24153 | /* Perhaps try to back up to a better place to break the line */ |
| 24154 | for(k=i; k>i/2; k--){ |
| 24155 | if( isspace(z[k-1]) ) break; |
| 24156 | } |
| 24157 | if( k<=i/2 ){ |
| 24158 | for(k=i; k>i/2; k--){ |
| 24159 | if( isalnum(z[k-1])!=isalnum(z[k]) && (z[k]&0xc0)!=0x80 ) break; |
| 24160 | } |
| 24161 | } |
| 24162 | if( k<=i/2 ){ |
| 24163 | k = i; |
| 24164 | }else{ |
| @@ -26088,11 +26131,11 @@ | |
| 26088 | #if HAVE_LINENOISE==2 |
| 26089 | UNUSED_PARAMETER(pUserData); |
| 26090 | #endif |
| 26091 | if( nLine>(i64)sizeof(zBuf)-30 ) return; |
| 26092 | if( zLine[0]=='.' || zLine[0]=='#') return; |
| 26093 | for(i=nLine-1; i>=0 && (isalnum(zLine[i]) || zLine[i]=='_'); i--){} |
| 26094 | if( i==nLine-1 ) return; |
| 26095 | iStart = i+1; |
| 26096 | memcpy(zBuf, zLine, iStart); |
| 26097 | zSql = sqlite3_mprintf("SELECT DISTINCT candidate COLLATE nocase" |
| 26098 | " FROM completion(%Q,%Q) ORDER BY 1", |
| @@ -28328,10 +28371,11 @@ | |
| 28328 | sqlite3_recover_config(p, 789, (void*)zRecoveryDb); /* Debug use only */ |
| 28329 | sqlite3_recover_config(p, SQLITE_RECOVER_LOST_AND_FOUND, (void*)zLAF); |
| 28330 | sqlite3_recover_config(p, SQLITE_RECOVER_ROWIDS, (void*)&bRowids); |
| 28331 | sqlite3_recover_config(p, SQLITE_RECOVER_FREELIST_CORRUPT,(void*)&bFreelist); |
| 28332 | |
| 28333 | sqlite3_recover_run(p); |
| 28334 | if( sqlite3_recover_errcode(p)!=SQLITE_OK ){ |
| 28335 | const char *zErr = sqlite3_recover_errmsg(p); |
| 28336 | int errCode = sqlite3_recover_errcode(p); |
| 28337 | sqlite3_fprintf(stderr,"sql error: %s (%d)\n", zErr, errCode); |
| @@ -32419,11 +32463,11 @@ | |
| 32419 | /* |
| 32420 | ** The CLI needs a working sqlite3_complete() to work properly. So error |
| 32421 | ** out of the build if compiling with SQLITE_OMIT_COMPLETE. |
| 32422 | */ |
| 32423 | #ifdef SQLITE_OMIT_COMPLETE |
| 32424 | # error the CLI application is imcompatable with SQLITE_OMIT_COMPLETE. |
| 32425 | #endif |
| 32426 | |
| 32427 | /* |
| 32428 | ** Return true if zSql is a complete SQL statement. Return false if it |
| 32429 | ** ends in the middle of a string literal or C-style comment. |
| @@ -32598,11 +32642,11 @@ | |
| 32598 | UNUSED_PARAMETER(in); |
| 32599 | UNUSED_PARAMETER(isContinuation); |
| 32600 | if(!z || !*z){ |
| 32601 | return 0; |
| 32602 | } |
| 32603 | while(*z && isspace(*z)) ++z; |
| 32604 | zBegin = z; |
| 32605 | for(; *z && '\n'!=*z; ++nZ, ++z){} |
| 32606 | if(nZ>0 && '\r'==zBegin[nZ-1]){ |
| 32607 | --nZ; |
| 32608 | } |
| 32609 |
| --- extsrc/shell.c | |
| +++ extsrc/shell.c | |
| @@ -234,10 +234,12 @@ | |
| 234 | |
| 235 | /* ctype macros that work with signed characters */ |
| 236 | #define IsSpace(X) isspace((unsigned char)X) |
| 237 | #define IsDigit(X) isdigit((unsigned char)X) |
| 238 | #define ToLower(X) (char)tolower((unsigned char)X) |
| 239 | #define IsAlnum(X) isalnum((unsigned char)X) |
| 240 | #define IsAlpha(X) isalpha((unsigned char)X) |
| 241 | |
| 242 | #if defined(_WIN32) || defined(WIN32) |
| 243 | #if SQLITE_OS_WINRT |
| 244 | #include <intrin.h> |
| 245 | #endif |
| @@ -1506,13 +1508,13 @@ | |
| 1508 | ** Return '"' if quoting is required. Return 0 if no quoting is required. |
| 1509 | */ |
| 1510 | static char quoteChar(const char *zName){ |
| 1511 | int i; |
| 1512 | if( zName==0 ) return '"'; |
| 1513 | if( !IsAlpha(zName[0]) && zName[0]!='_' ) return '"'; |
| 1514 | for(i=0; zName[i]; i++){ |
| 1515 | if( !IsAlnum(zName[i]) && zName[i]!='_' ) return '"'; |
| 1516 | } |
| 1517 | return sqlite3_keyword_check(zName, i) ? '"' : 0; |
| 1518 | } |
| 1519 | |
| 1520 | /* |
| @@ -2425,11 +2427,11 @@ | |
| 2427 | ** content in cases where the content starts |
| 2428 | ** with a digit. |
| 2429 | ** |
| 2430 | ** typeof(Y)='blob' The hash is taken over prefix "Bnnn:" followed |
| 2431 | ** by the binary content of the blob. The "nnn" |
| 2432 | ** in the prefix is the minimum-length decimal |
| 2433 | ** representation of the byte-length of the blob. |
| 2434 | ** |
| 2435 | ** According to the rules above, all of the following SELECT statements |
| 2436 | ** should return TRUE: |
| 2437 | ** |
| @@ -3646,11 +3648,11 @@ | |
| 3648 | ** |
| 3649 | ** UINT works like BINARY for text, except that embedded strings |
| 3650 | ** of digits compare in numeric order. |
| 3651 | ** |
| 3652 | ** * Leading zeros are handled properly, in the sense that |
| 3653 | ** they do not mess of the magnitude comparison of embedded |
| 3654 | ** strings of digits. "x00123y" is equal to "x123y". |
| 3655 | ** |
| 3656 | ** * Only unsigned integers are recognized. Plus and minus |
| 3657 | ** signs are ignored. Decimal points and exponential notation |
| 3658 | ** are ignored. |
| @@ -3752,10 +3754,13 @@ | |
| 3754 | ** warnings. */ |
| 3755 | #ifndef UNUSED_PARAMETER |
| 3756 | # define UNUSED_PARAMETER(X) (void)(X) |
| 3757 | #endif |
| 3758 | |
| 3759 | #ifndef IsSpace |
| 3760 | #define IsSpace(X) isspace((unsigned char)X) |
| 3761 | #endif |
| 3762 | |
| 3763 | /* A decimal object */ |
| 3764 | typedef struct Decimal Decimal; |
| 3765 | struct Decimal { |
| 3766 | char sign; /* 0 for positive, 1 for negative */ |
| @@ -3801,11 +3806,11 @@ | |
| 3806 | p->isNull = 0; |
| 3807 | p->nDigit = 0; |
| 3808 | p->nFrac = 0; |
| 3809 | p->a = sqlite3_malloc64( n+1 ); |
| 3810 | if( p->a==0 ) goto new_from_text_failed; |
| 3811 | for(i=0; IsSpace(zIn[i]); i++){} |
| 3812 | if( zIn[i]=='-' ){ |
| 3813 | p->sign = 1; |
| 3814 | i++; |
| 3815 | }else if( zIn[i]=='+' ){ |
| 3816 | i++; |
| @@ -4456,11 +4461,11 @@ | |
| 4461 | } |
| 4462 | decimal_free(pA); |
| 4463 | decimal_free(pB); |
| 4464 | } |
| 4465 | |
| 4466 | /* Aggregate function: decimal_sum(X) |
| 4467 | ** |
| 4468 | ** Works like sum() except that it uses decimal arithmetic for unlimited |
| 4469 | ** precision. |
| 4470 | */ |
| 4471 | static void decimalSumStep( |
| @@ -4817,11 +4822,11 @@ | |
| 4822 | } |
| 4823 | |
| 4824 | /* |
| 4825 | ** Generate an error for a percentile function. |
| 4826 | ** |
| 4827 | ** The error format string must have exactly one occurrence of "%%s()" |
| 4828 | ** (with two '%' characters). That substring will be replaced by the name |
| 4829 | ** of the function. |
| 4830 | */ |
| 4831 | static void percentError(sqlite3_context *pCtx, const char *zFormat, ...){ |
| 4832 | PercentileFunc *pFunc = (PercentileFunc*)sqlite3_user_data(pCtx); |
| @@ -5957,11 +5962,11 @@ | |
| 5962 | ** number format: |
| 5963 | ** |
| 5964 | ** WITH c(name,bin) AS (VALUES |
| 5965 | ** ('minimum positive value', x'0000000000000001'), |
| 5966 | ** ('maximum subnormal value', x'000fffffffffffff'), |
| 5967 | ** ('minimum positive normal value', x'0010000000000000'), |
| 5968 | ** ('maximum value', x'7fefffffffffffff')) |
| 5969 | ** SELECT c.name, decimal_mul(ieee754_mantissa(c.bin),pow2.v) |
| 5970 | ** FROM pow2, c WHERE pow2.x=ieee754_exponent(c.bin); |
| 5971 | ** |
| 5972 | */ |
| @@ -6344,11 +6349,11 @@ | |
| 6349 | * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */ |
| 6350 | smBase += (mxI64/2) * smStep; |
| 6351 | smBase += (mxI64 - mxI64/2) * smStep; |
| 6352 | } |
| 6353 | /* Under UBSAN (or on 1's complement machines), must do this last term |
| 6354 | * in steps to avoid the dreaded (and harmless) signed multiply overflow. */ |
| 6355 | if( ix>=2 ){ |
| 6356 | sqlite3_int64 ix2 = (sqlite3_int64)ix/2; |
| 6357 | smBase += ix2*smStep; |
| 6358 | ix -= ix2; |
| 6359 | } |
| @@ -9024,10 +9029,15 @@ | |
| 9029 | #include <assert.h> |
| 9030 | #include <string.h> |
| 9031 | #include <ctype.h> |
| 9032 | |
| 9033 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 9034 | |
| 9035 | #ifndef IsAlnum |
| 9036 | #define IsAlnum(X) isalnum((unsigned char)X) |
| 9037 | #endif |
| 9038 | |
| 9039 | |
| 9040 | /* completion_vtab is a subclass of sqlite3_vtab which will |
| 9041 | ** serve as the underlying representation of a completion virtual table |
| 9042 | */ |
| 9043 | typedef struct completion_vtab completion_vtab; |
| @@ -9361,11 +9371,11 @@ | |
| 9371 | if( pCur->zLine==0 ) return SQLITE_NOMEM; |
| 9372 | } |
| 9373 | } |
| 9374 | if( pCur->zLine!=0 && pCur->zPrefix==0 ){ |
| 9375 | int i = pCur->nLine; |
| 9376 | while( i>0 && (IsAlnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){ |
| 9377 | i--; |
| 9378 | } |
| 9379 | pCur->nPrefix = pCur->nLine - i; |
| 9380 | if( pCur->nPrefix>0 ){ |
| 9381 | pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i); |
| @@ -14768,11 +14778,11 @@ | |
| 14778 | /* Register the auth callback with dbv */ |
| 14779 | if( rc==SQLITE_OK ){ |
| 14780 | sqlite3_set_authorizer(pNew->dbv, idxAuthCallback, (void*)pNew); |
| 14781 | } |
| 14782 | |
| 14783 | /* If an error has occurred, free the new object and return NULL. Otherwise, |
| 14784 | ** return the new sqlite3expert handle. */ |
| 14785 | if( rc!=SQLITE_OK ){ |
| 14786 | sqlite3_expert_destroy(pNew); |
| 14787 | pNew = 0; |
| 14788 | } |
| @@ -16290,11 +16300,11 @@ | |
| 16300 | ** |
| 16301 | ** PRAGMA vfstrace('+all'); |
| 16302 | ** |
| 16303 | ** Individual APIs can be enabled or disabled by name, with or without |
| 16304 | ** the initial "x" character. For example, to set up for tracing lock |
| 16305 | ** primitives only: |
| 16306 | ** |
| 16307 | ** PRAGMA vfstrace('-all, +Lock,Unlock,ShmLock'); |
| 16308 | ** |
| 16309 | ** The argument to the vfstrace pragma ignores capitalization and any |
| 16310 | ** characters other than alphabetics, '+', and '-'. |
| @@ -21241,41 +21251,57 @@ | |
| 21251 | ** function is called. |
| 21252 | */ |
| 21253 | static void recoverStep(sqlite3_recover *p){ |
| 21254 | assert( p && p->errCode==SQLITE_OK ); |
| 21255 | switch( p->eState ){ |
| 21256 | case RECOVER_STATE_INIT: { |
| 21257 | int bUseWrapper = 1; |
| 21258 | /* This is the very first call to sqlite3_recover_step() on this object. |
| 21259 | */ |
| 21260 | recoverSqlCallback(p, "BEGIN"); |
| 21261 | recoverSqlCallback(p, "PRAGMA writable_schema = on"); |
| 21262 | recoverSqlCallback(p, "PRAGMA foreign_keys = off"); |
| 21263 | |
| 21264 | recoverEnterMutex(); |
| 21265 | |
| 21266 | /* Open the output database. And register required virtual tables and |
| 21267 | ** user functions with the new handle. */ |
| 21268 | recoverOpenOutput(p); |
| 21269 | |
| 21270 | /* Attempt to open a transaction and read page 1 of the input database. |
| 21271 | ** Two attempts may be made - one with a wrapper installed to ensure |
| 21272 | ** that the database header is sane, and then if that attempt returns |
| 21273 | ** SQLITE_NOTADB, then again with no wrapper. The second attempt is |
| 21274 | ** required for encrypted databases. */ |
| 21275 | if( p->errCode==SQLITE_OK ){ |
| 21276 | do{ |
| 21277 | p->errCode = SQLITE_OK; |
| 21278 | if( bUseWrapper ) recoverInstallWrapper(p); |
| 21279 | |
| 21280 | /* Open a transaction on the input database. */ |
| 21281 | sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0); |
| 21282 | recoverExec(p, p->dbIn, "PRAGMA writable_schema = on"); |
| 21283 | recoverExec(p, p->dbIn, "BEGIN"); |
| 21284 | if( p->errCode==SQLITE_OK ) p->bCloseTransaction = 1; |
| 21285 | recoverExec(p, p->dbIn, "SELECT 1 FROM sqlite_schema"); |
| 21286 | recoverTransferSettings(p); |
| 21287 | recoverOpenRecovery(p); |
| 21288 | recoverCacheSchema(p); |
| 21289 | |
| 21290 | if( bUseWrapper ) recoverUninstallWrapper(p); |
| 21291 | }while( p->errCode==SQLITE_NOTADB |
| 21292 | && (bUseWrapper--) |
| 21293 | && SQLITE_OK==sqlite3_exec(p->dbIn, "ROLLBACK", 0, 0, 0) |
| 21294 | ); |
| 21295 | } |
| 21296 | |
| 21297 | recoverLeaveMutex(); |
| 21298 | recoverExec(p, p->dbOut, "BEGIN"); |
| 21299 | recoverWriteSchema1(p); |
| 21300 | p->eState = RECOVER_STATE_WRITING; |
| 21301 | break; |
| 21302 | } |
| 21303 | |
| 21304 | case RECOVER_STATE_WRITING: { |
| 21305 | if( p->w1.pTbls==0 ){ |
| 21306 | recoverWriteDataInit(p); |
| 21307 | } |
| @@ -21711,17 +21737,18 @@ | |
| 21737 | #define SHELL_PROGRESS_RESET 0x02 /* Reset the count when the progress |
| 21738 | ** callback limit is reached, and for each |
| 21739 | ** top-level SQL statement */ |
| 21740 | #define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */ |
| 21741 | |
| 21742 | /* Allowed values for ShellState.eEscMode. The default value should |
| 21743 | ** be 0, so to change the default, reorder the names. |
| 21744 | */ |
| 21745 | #define SHELL_ESC_ASCII 0 /* Substitute ^Y for X where Y=X+0x40 */ |
| 21746 | #define SHELL_ESC_SYMBOL 1 /* Substitute U+2400 graphics */ |
| 21747 | #define SHELL_ESC_OFF 2 /* Send characters verbatim */ |
| 21748 | |
| 21749 | static const char *shell_EscModeNames[] = { "ascii", "symbol", "off" }; |
| 21750 | |
| 21751 | /* |
| 21752 | ** These are the allowed shellFlgs values |
| 21753 | */ |
| 21754 | #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */ |
| @@ -22902,18 +22929,22 @@ | |
| 22929 | int j; |
| 22930 | int nParen = 0; |
| 22931 | char cEnd = 0; |
| 22932 | char c; |
| 22933 | int nLine = 0; |
| 22934 | int isIndex; |
| 22935 | int isWhere = 0; |
| 22936 | assert( nArg==1 ); |
| 22937 | if( azArg[0]==0 ) break; |
| 22938 | if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0 |
| 22939 | || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0 |
| 22940 | ){ |
| 22941 | sqlite3_fprintf(p->out, "%s;\n", azArg[0]); |
| 22942 | break; |
| 22943 | } |
| 22944 | isIndex = sqlite3_strlike("CREATE INDEX%", azArg[0], 0)==0 |
| 22945 | || sqlite3_strlike("CREATE UNIQUE INDEX%", azArg[0], 0)==0; |
| 22946 | z = sqlite3_mprintf("%s", azArg[0]); |
| 22947 | shell_check_oom(z); |
| 22948 | j = 0; |
| 22949 | for(i=0; IsSpace(z[i]); i++){} |
| 22950 | for(; (c = z[i])!=0; i++){ |
| @@ -22939,18 +22970,30 @@ | |
| 22970 | cEnd = '\n'; |
| 22971 | }else if( c=='(' ){ |
| 22972 | nParen++; |
| 22973 | }else if( c==')' ){ |
| 22974 | nParen--; |
| 22975 | if( nLine>0 && nParen==0 && j>0 && !isWhere ){ |
| 22976 | printSchemaLineN(p->out, z, j, "\n"); |
| 22977 | j = 0; |
| 22978 | } |
| 22979 | }else if( (c=='w' || c=='W') |
| 22980 | && nParen==0 && isIndex |
| 22981 | && sqlite3_strnicmp("WHERE",&z[i],5)==0 |
| 22982 | && !IsAlnum(z[i+5]) && z[i+5]!='_' ){ |
| 22983 | isWhere = 1; |
| 22984 | }else if( isWhere && (c=='A' || c=='a') |
| 22985 | && nParen==0 |
| 22986 | && sqlite3_strnicmp("AND",&z[i],3)==0 |
| 22987 | && !IsAlnum(z[i+3]) && z[i+3]!='_' ){ |
| 22988 | printSchemaLineN(p->out, z, j, "\n "); |
| 22989 | j = 0; |
| 22990 | } |
| 22991 | z[j++] = c; |
| 22992 | if( nParen==1 && cEnd==0 |
| 22993 | && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1))) |
| 22994 | && !isWhere |
| 22995 | ){ |
| 22996 | if( c=='\n' ) j--; |
| 22997 | printSchemaLineN(p->out, z, j, "\n "); |
| 22998 | j = 0; |
| 22999 | nLine++; |
| @@ -24150,15 +24193,15 @@ | |
| 24193 | i++; |
| 24194 | } |
| 24195 | if( n>=mxWidth && bWordWrap ){ |
| 24196 | /* Perhaps try to back up to a better place to break the line */ |
| 24197 | for(k=i; k>i/2; k--){ |
| 24198 | if( IsSpace(z[k-1]) ) break; |
| 24199 | } |
| 24200 | if( k<=i/2 ){ |
| 24201 | for(k=i; k>i/2; k--){ |
| 24202 | if( IsAlnum(z[k-1])!=IsAlnum(z[k]) && (z[k]&0xc0)!=0x80 ) break; |
| 24203 | } |
| 24204 | } |
| 24205 | if( k<=i/2 ){ |
| 24206 | k = i; |
| 24207 | }else{ |
| @@ -26088,11 +26131,11 @@ | |
| 26131 | #if HAVE_LINENOISE==2 |
| 26132 | UNUSED_PARAMETER(pUserData); |
| 26133 | #endif |
| 26134 | if( nLine>(i64)sizeof(zBuf)-30 ) return; |
| 26135 | if( zLine[0]=='.' || zLine[0]=='#') return; |
| 26136 | for(i=nLine-1; i>=0 && (IsAlnum(zLine[i]) || zLine[i]=='_'); i--){} |
| 26137 | if( i==nLine-1 ) return; |
| 26138 | iStart = i+1; |
| 26139 | memcpy(zBuf, zLine, iStart); |
| 26140 | zSql = sqlite3_mprintf("SELECT DISTINCT candidate COLLATE nocase" |
| 26141 | " FROM completion(%Q,%Q) ORDER BY 1", |
| @@ -28328,10 +28371,11 @@ | |
| 28371 | sqlite3_recover_config(p, 789, (void*)zRecoveryDb); /* Debug use only */ |
| 28372 | sqlite3_recover_config(p, SQLITE_RECOVER_LOST_AND_FOUND, (void*)zLAF); |
| 28373 | sqlite3_recover_config(p, SQLITE_RECOVER_ROWIDS, (void*)&bRowids); |
| 28374 | sqlite3_recover_config(p, SQLITE_RECOVER_FREELIST_CORRUPT,(void*)&bFreelist); |
| 28375 | |
| 28376 | sqlite3_fprintf(pState->out, ".dbconfig defensive off\n"); |
| 28377 | sqlite3_recover_run(p); |
| 28378 | if( sqlite3_recover_errcode(p)!=SQLITE_OK ){ |
| 28379 | const char *zErr = sqlite3_recover_errmsg(p); |
| 28380 | int errCode = sqlite3_recover_errcode(p); |
| 28381 | sqlite3_fprintf(stderr,"sql error: %s (%d)\n", zErr, errCode); |
| @@ -32419,11 +32463,11 @@ | |
| 32463 | /* |
| 32464 | ** The CLI needs a working sqlite3_complete() to work properly. So error |
| 32465 | ** out of the build if compiling with SQLITE_OMIT_COMPLETE. |
| 32466 | */ |
| 32467 | #ifdef SQLITE_OMIT_COMPLETE |
| 32468 | # error the CLI application is incompatable with SQLITE_OMIT_COMPLETE. |
| 32469 | #endif |
| 32470 | |
| 32471 | /* |
| 32472 | ** Return true if zSql is a complete SQL statement. Return false if it |
| 32473 | ** ends in the middle of a string literal or C-style comment. |
| @@ -32598,11 +32642,11 @@ | |
| 32642 | UNUSED_PARAMETER(in); |
| 32643 | UNUSED_PARAMETER(isContinuation); |
| 32644 | if(!z || !*z){ |
| 32645 | return 0; |
| 32646 | } |
| 32647 | while(*z && IsSpace(*z)) ++z; |
| 32648 | zBegin = z; |
| 32649 | for(; *z && '\n'!=*z; ++nZ, ++z){} |
| 32650 | if(nZ>0 && '\r'==zBegin[nZ-1]){ |
| 32651 | --nZ; |
| 32652 | } |
| 32653 |