• Home
  • Raw
  • Download

Lines Matching +full:d3 +full:- +full:hierarchy

5 ** "shell.c" file used to implement the SQLite command-line shell.
13 ** source file to help make the command-line program easier to compile.
41 ** Optionally #include a user-defined header, whereby compilation options
64 ** the browser-mode build has much different user input requirements
98 ** Enable large-file support for fopen() and friends on unix.
233 /* Windows CE (arm-wince-mingw32ce-gcc) does not provide isatty()
235 * overridden with the -batch command line option.
294 /* Return the current wall-clock time */
300 if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){ in timeOfDay()
301 clockVfs->xCurrentTimeInt64(clockVfs, &t); in timeOfDay()
304 clockVfs->xCurrentTime(clockVfs, &r); in timeOfDay()
325 static sqlite3_int64 iBegin; /* Wall-clock time at start */
339 return (pEnd->tv_usec - pStart->tv_usec)*0.000001 + in timeDiff()
340 (double)(pEnd->tv_sec - pStart->tv_sec); in timeDiff()
352 (iEnd - iBegin)*0.001, in endTimer()
419 return (double) ((i64End - i64Start) / 10000000.0); in timeDiff()
431 (ftWallEnd - ftWallBegin)*0.001, in endTimer()
478 ** Setup console for UTF-8 input/output when following variable true.
485 ** in order to translate UTF-8 into MBCS. The following variable is
498 ** True if an interrupt (Control-C) has been received.
518 /* This is variant of the standard-library strncpy() routine with the
519 ** one change that the destination string is always zero-terminated, even
520 ** if there is no zero-terminator in the first n-1 characters of the source
525 for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i]; in shell_strncpy()
533 ** or open parentheses level if non-zero, or continuation prompt as set.
569 p->inParenLevel += ni; in trackParenLevel()
570 if( ni==0 ) p->inParenLevel = 0; in trackParenLevel()
571 p->zScannerAwaits = 0; in trackParenLevel()
577 p->zScannerAwaits = s; in setLexemeOpen()
578 p->acAwait[0] = 0; in setLexemeOpen()
580 p->acAwait[0] = c; in setLexemeOpen()
581 p->zScannerAwaits = p->acAwait; in setLexemeOpen()
594 if( ndp > ncp-3 ) return continuePrompt; in dynamicContinuePrompt()
598 PROMPT_LEN_MAX-4); in dynamicContinuePrompt()
608 shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4); in dynamicContinuePrompt()
616 /* Following struct is used for -utf8 operation. */
631 ** Prepare console, (if known to be a WIN32 console), for UTF-8
633 ** UTF-8 rendering. This may "fail" with a message to stderr, where
642 fprintf(stderr, "Cannot use UTF-8 code page.\n"); in console_prepare()
682 ** startup option, -utf8, has not been provided or taken effect.
693 while( noc<ncmax-7-1 && !lend ){ in utf8_fgets()
694 /* There is room for at least 2 more characters and a 0-terminator. */ in utf8_fgets()
696 ? SQLITE_IALIM : (ncmax-1 - noc)/4; in utf8_fgets()
709 /* Fixup line-ends as coded by Windows for CR (or "Enter".)*/ in utf8_fgets()
711 if( buf[noc-1]=='\n' ){ in utf8_fgets()
713 if( noc > 1 && buf[noc-2]=='\r' ){ in utf8_fgets()
714 buf[noc-2] = '\n'; in utf8_fgets()
715 --noc; in utf8_fgets()
731 /* If got nothing, (after ^Z chop), must be at end-of-file. */ in utf8_fgets()
745 ** console and if this is running on a Windows machine, and if the -utf8
747 ** output from UTF-8 into MBCS for output through 8-bit stdout stream.
748 ** (With -utf8 active, no translation is needed and must not be done.)
781 /* Indicate out-of-memory and exit. */
788 ** out-of-memory error.
822 ** then right-justify the text. W is the width in UTF-8 characters, not
829 int aw = w<0 ? -w : w; in utf8_width_print()
843 utf8_printf(pOut, "%*s%s", aw-n, "", zUtf); in utf8_width_print()
845 utf8_printf(pOut, "%s%*s", zUtf, aw-n, ""); in utf8_width_print()
854 if( *z=='-' || *z=='+' ) z++; in isNumber()
869 if( *z=='+' || *z=='-' ) z++; in isNumber()
879 ** lower 30 bits of a 32-bit signed integer.
884 return 0x3fffffff & (int)(z2 - z); in strlen30()
952 if( fgets(&zLine[n], nLine - n, in)==0 ){ in local_getline()
961 if( n>0 && zLine[n-1]=='\n' ){ in local_getline()
962 n--; in local_getline()
963 if( n>0 && zLine[n-1]=='\r' ) n--; in local_getline()
969 /* For interactive input on Windows systems, without -utf8, in local_getline()
970 ** translate the multi-byte characterset characters into UTF-8. in local_getline()
971 ** This is the translation that predates the -utf8 option. */ in local_getline()
1040 ** Return the value of a hexadecimal digit. Return -1 if the input
1044 if( c>='0' && c<='9' ) return c - '0'; in hexDigitValue()
1045 if( c>='a' && c<='f' ) return c - 'a' + 10; in hexDigitValue()
1046 if( c>='A' && c<='F' ) return c - 'A' + 10; in hexDigitValue()
1047 return -1; in hexDigitValue()
1068 if( zArg[0]=='-' ){ in integerValue()
1083 v = v*10 + zArg[0] - '0'; in integerValue()
1093 return isNeg? -v : v; in integerValue()
1113 free(p->z); in freeText()
1117 /* zIn is either a pointer to a NULL-terminated string in memory obtained
1130 len = nAppend+p->n+1; in appendText()
1138 if( p->z==0 || p->n+len>=p->nAlloc ){ in appendText()
1139 p->nAlloc = p->nAlloc*2 + len + 20; in appendText()
1140 p->z = realloc(p->z, p->nAlloc); in appendText()
1141 shell_check_oom(p->z); in appendText()
1145 char *zCsr = p->z+p->n; in appendText()
1152 p->n = (int)(zCsr - p->z); in appendText()
1155 memcpy(p->z+p->n, zAppend, nAppend); in appendText()
1156 p->n += nAppend; in appendText()
1157 p->z[p->n] = '\0'; in appendText()
1163 ** because it contains non-alphanumeric characters, or because it is an
1198 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); in shellFakeSchema()
1230 ** Return a fake schema for the table-valued function or eponymous virtual
1245 -1, sqlite3_free); in shellModuleSchema()
1256 ** CREATE TABLE t1(x) -> CREATE TABLE xyz.t1(x);
1314 sqlite3_result_text(pCtx, z, -1, sqlite3_free); in shellAddSchemaName()
1324 ** The source code for several run-time loadable extensions is inserted
1435 # define BAD_INTPTR_T ((intptr_t)(-1))
1477 ** function. This function is not thread-safe.
1516 ** This function is not thread-safe.
1529 ** The function call to GetEnvironmentVariableA() failed -OR- in windirent_getenv()
1536 ** -AND- the buffer contains the entire value. in windirent_getenv()
1555 /* TODO: Remove this if Unix-style root paths are not used. */ in opendir()
1562 dirp->d_handle = _findfirst(data.name, &data); in opendir()
1564 if( dirp->d_handle==BAD_INTPTR_T ){ in opendir()
1574 if( _findnext(dirp->d_handle, &data)==-1 ){ in opendir()
1583 dirp->d_first.d_attributes = data.attrib; in opendir()
1584 strncpy(dirp->d_first.d_name, data.name, NAME_MAX); in opendir()
1585 dirp->d_first.d_name[NAME_MAX] = '\0'; in opendir()
1600 if( dirp->d_first.d_ino==0 ){ in readdir()
1601 dirp->d_first.d_ino++; in readdir()
1602 dirp->d_next.d_ino++; in readdir()
1604 return &dirp->d_first; in readdir()
1610 if( _findnext(dirp->d_handle, &data)==-1 ) return NULL; in readdir()
1615 dirp->d_next.d_ino++; in readdir()
1616 dirp->d_next.d_attributes = data.attrib; in readdir()
1617 strncpy(dirp->d_next.d_name, data.name, NAME_MAX); in readdir()
1618 dirp->d_next.d_name[NAME_MAX] = '\0'; in readdir()
1620 return &dirp->d_next; in readdir()
1635 if( dirp->d_first.d_ino==0 ){ in readdir_r()
1636 dirp->d_first.d_ino++; in readdir_r()
1637 dirp->d_next.d_ino++; in readdir_r()
1639 entry->d_ino = dirp->d_first.d_ino; in readdir_r()
1640 entry->d_attributes = dirp->d_first.d_attributes; in readdir_r()
1641 strncpy(entry->d_name, dirp->d_first.d_name, NAME_MAX); in readdir_r()
1642 entry->d_name[NAME_MAX] = '\0'; in readdir_r()
1651 if( _findnext(dirp->d_handle, &data)==-1 ){ in readdir_r()
1659 entry->d_ino = (ino_t)-1; /* not available */ in readdir_r()
1660 entry->d_attributes = data.attrib; in readdir_r()
1661 strncpy(entry->d_name, data.name, NAME_MAX); in readdir_r()
1662 entry->d_name[NAME_MAX] = '\0'; in readdir_r()
1678 if( dirp->d_handle!=NULL_INTPTR_T && dirp->d_handle!=BAD_INTPTR_T ){ in closedir()
1679 result = _findclose(dirp->d_handle); in closedir()
1693 ** 2019-01-21
1712 ** This extension is used to implement the --memtrace option of the
1713 ** command-line shell.
1745 fprintf(memtraceOut, "MEMTRACE: resize %d -> %d bytes\n", in memtraceRealloc()
1804 ** 2017-03-08
1816 ** in the way described by the (U.S.) NIST FIPS 202 SHA-3 Standard.
1828 ** The SIZE argument is optional. If omitted, the SHA3-256 hash algorithm
1847 ** and whether or not that determination is run-time or compile-time.
1849 ** For best performance, an attempt is made to guess at the byte-order
1850 ** using C-preprocessor macros. If that is unsuccessful, or if
1851 ** -DSHA3_BYTEORDER=0 is set, then byte-order is determined
1852 ** at run-time.
1883 ** A single step of the Keccak mixing function for a 1600-bit state
1889 u64 d0, d1, d2, d3, d4; in KeccakF1600Step() local
1904 # define a00 (p->u.s[0]) in KeccakF1600Step()
1905 # define a01 (p->u.s[1]) in KeccakF1600Step()
1906 # define a02 (p->u.s[2]) in KeccakF1600Step()
1907 # define a03 (p->u.s[3]) in KeccakF1600Step()
1908 # define a04 (p->u.s[4]) in KeccakF1600Step()
1909 # define a10 (p->u.s[5]) in KeccakF1600Step()
1910 # define a11 (p->u.s[6]) in KeccakF1600Step()
1911 # define a12 (p->u.s[7]) in KeccakF1600Step()
1912 # define a13 (p->u.s[8]) in KeccakF1600Step()
1913 # define a14 (p->u.s[9]) in KeccakF1600Step()
1914 # define a20 (p->u.s[10]) in KeccakF1600Step()
1915 # define a21 (p->u.s[11]) in KeccakF1600Step()
1916 # define a22 (p->u.s[12]) in KeccakF1600Step()
1917 # define a23 (p->u.s[13]) in KeccakF1600Step()
1918 # define a24 (p->u.s[14]) in KeccakF1600Step()
1919 # define a30 (p->u.s[15]) in KeccakF1600Step()
1920 # define a31 (p->u.s[16]) in KeccakF1600Step()
1921 # define a32 (p->u.s[17]) in KeccakF1600Step()
1922 # define a33 (p->u.s[18]) in KeccakF1600Step()
1923 # define a34 (p->u.s[19]) in KeccakF1600Step()
1924 # define a40 (p->u.s[20]) in KeccakF1600Step()
1925 # define a41 (p->u.s[21]) in KeccakF1600Step()
1926 # define a42 (p->u.s[22]) in KeccakF1600Step()
1927 # define a43 (p->u.s[23]) in KeccakF1600Step()
1928 # define a44 (p->u.s[24]) in KeccakF1600Step()
1929 # define ROL64(a,x) ((a<<x)|(a>>(64-x))) in KeccakF1600Step()
1940 d3 = c2^ROL64(c4, 1); in KeccakF1600Step()
1946 b3 = ROL64((a33^d3), 21); in KeccakF1600Step()
1958 b0 = ROL64((a03^d3), 28); in KeccakF1600Step()
1969 b2 = ROL64((a23^d3), 25); in KeccakF1600Step()
1980 b4 = ROL64((a43^d3), 56); in KeccakF1600Step()
1991 b1 = ROL64((a13^d3), 55); in KeccakF1600Step()
2007 d3 = c2^ROL64(c4, 1); in KeccakF1600Step()
2013 b3 = ROL64((a43^d3), 21); in KeccakF1600Step()
2025 b0 = ROL64((a33^d3), 28); in KeccakF1600Step()
2036 b2 = ROL64((a23^d3), 25); in KeccakF1600Step()
2047 b4 = ROL64((a13^d3), 56); in KeccakF1600Step()
2058 b1 = ROL64((a03^d3), 55); in KeccakF1600Step()
2074 d3 = c2^ROL64(c4, 1); in KeccakF1600Step()
2080 b3 = ROL64((a13^d3), 21); in KeccakF1600Step()
2092 b0 = ROL64((a43^d3), 28); in KeccakF1600Step()
2103 b2 = ROL64((a23^d3), 25); in KeccakF1600Step()
2114 b4 = ROL64((a03^d3), 56); in KeccakF1600Step()
2125 b1 = ROL64((a33^d3), 55); in KeccakF1600Step()
2141 d3 = c2^ROL64(c4, 1); in KeccakF1600Step()
2147 b3 = ROL64((a03^d3), 21); in KeccakF1600Step()
2159 b0 = ROL64((a13^d3), 28); in KeccakF1600Step()
2170 b2 = ROL64((a23^d3), 25); in KeccakF1600Step()
2181 b4 = ROL64((a33^d3), 56); in KeccakF1600Step()
2192 b1 = ROL64((a43^d3), 55); in KeccakF1600Step()
2210 p->nRate = (1600 - ((iSize + 31)&~31)*2)/8; in SHA3Init()
2212 p->nRate = (1600 - 2*256)/8; in SHA3Init()
2215 /* Known to be little-endian at compile-time. No-op */ in SHA3Init()
2217 p->ixMask = 7; /* Big-endian */ in SHA3Init()
2223 p->ixMask = 0; in SHA3Init()
2226 p->ixMask = 7; in SHA3Init()
2244 if( (p->nLoaded % 8)==0 && ((aData - (const unsigned char*)0)&7)==0 ){ in SHA3Update()
2246 p->u.s[p->nLoaded/8] ^= *(u64*)&aData[i]; in SHA3Update()
2247 p->nLoaded += 8; in SHA3Update()
2248 if( p->nLoaded>=p->nRate ){ in SHA3Update()
2250 p->nLoaded = 0; in SHA3Update()
2257 p->u.x[p->nLoaded] ^= aData[i]; in SHA3Update()
2259 p->u.x[p->nLoaded^0x07] ^= aData[i]; in SHA3Update()
2261 p->u.x[p->nLoaded^p->ixMask] ^= aData[i]; in SHA3Update()
2263 p->nLoaded++; in SHA3Update()
2264 if( p->nLoaded==p->nRate ){ in SHA3Update()
2266 p->nLoaded = 0; in SHA3Update()
2278 if( p->nLoaded==p->nRate-1 ){ in SHA3Final()
2285 p->nLoaded = p->nRate - 1; in SHA3Final()
2288 for(i=0; i<p->nRate; i++){ in SHA3Final()
2289 p->u.x[i+p->nRate] = p->u.x[i^p->ixMask]; in SHA3Final()
2291 return &p->u.x[p->nRate]; in SHA3Final()
2299 ** Return a BLOB which is the SIZE-bit SHA3 hash of X. The default
2301 ** For all other non-NULL types of input, X is converted into a UTF-8 string
2320 "384 512", -1); in sha3Func()
2356 ** argument. The results are hashed using a SIZE-bit SHA3. The default
2365 ** F<ieee-float>
2370 ** the size of that text. The SQL text is UTF-8. A single R character
2372 ** I mean an 8-byte little-endian integer <int>. F is a floating point
2373 ** number with an 8-byte little-endian IEEE floating point value <ieee-float>.
2375 ** bytes of UTF-8. The <n> and <size> values are expressed as an ASCII
2406 "384 512", -1); in sha3QueryFunc()
2413 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zSql); in sha3QueryFunc()
2418 sqlite3_result_error(context, zMsg, -1); in sha3QueryFunc()
2423 char *zMsg = sqlite3_mprintf("non-query: [%s]", sqlite3_sql(pStmt)); in sha3QueryFunc()
2425 sqlite3_result_error(context, zMsg, -1); in sha3QueryFunc()
2452 for(j=8; j>=1; j--){ in sha3QueryFunc()
2466 for(j=8; j>=1; j--){ in sha3QueryFunc()
2532 ** 2020-04-14
2558 ** 64-bit machine integer.
2580 x = zA[i] - zB[j]; in uintCollFunc()
2594 return -1; in uintCollFunc()
2608 return (nKey1 - i) - (nKey2 - j); in uintCollFunc()
2627 ** 2020-06-22
2638 ** Routines to implement arbitrary-precision decimal math.
2672 sqlite3_free(p->a); in decimal_clear()
2701 p->sign = 0; in decimal_new()
2702 p->oom = 0; in decimal_new()
2703 p->isInit = 1; in decimal_new()
2704 p->isNull = 0; in decimal_new()
2705 p->nDigit = 0; in decimal_new()
2706 p->nFrac = 0; in decimal_new()
2712 p->a = 0; in decimal_new()
2713 p->isNull = 1; in decimal_new()
2719 p->a = sqlite3_malloc64( n+1 ); in decimal_new()
2720 if( p->a==0 ) goto new_no_mem; in decimal_new()
2722 if( zIn[i]=='-' ){ in decimal_new()
2723 p->sign = 1; in decimal_new()
2732 p->a[p->nDigit++] = c - '0'; in decimal_new()
2734 p->nFrac = p->nDigit + 1; in decimal_new()
2739 if( zIn[j]=='-' ){ in decimal_new()
2747 iExp = iExp*10 + zIn[j] - '0'; in decimal_new()
2751 if( neg ) iExp = -iExp; in decimal_new()
2756 if( p->nFrac ){ in decimal_new()
2757 p->nFrac = p->nDigit - (p->nFrac - 1); in decimal_new()
2760 if( p->nFrac>0 ){ in decimal_new()
2761 if( iExp<=p->nFrac ){ in decimal_new()
2762 p->nFrac -= iExp; in decimal_new()
2765 iExp -= p->nFrac; in decimal_new()
2766 p->nFrac = 0; in decimal_new()
2770 p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 ); in decimal_new()
2771 if( p->a==0 ) goto new_no_mem; in decimal_new()
2772 memset(p->a+p->nDigit, 0, iExp); in decimal_new()
2773 p->nDigit += iExp; in decimal_new()
2777 iExp = -iExp; in decimal_new()
2778 nExtra = p->nDigit - p->nFrac - 1; in decimal_new()
2781 p->nFrac += iExp; in decimal_new()
2784 iExp -= nExtra; in decimal_new()
2785 p->nFrac = p->nDigit - 1; in decimal_new()
2789 p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 ); in decimal_new()
2790 if( p->a==0 ) goto new_no_mem; in decimal_new()
2791 memmove(p->a+iExp, p->a, p->nDigit); in decimal_new()
2792 memset(p->a, 0, iExp); in decimal_new()
2793 p->nDigit += iExp; in decimal_new()
2794 p->nFrac += iExp; in decimal_new()
2812 if( p==0 || p->oom ){ in decimal_result()
2816 if( p->isNull ){ in decimal_result()
2820 z = sqlite3_malloc( p->nDigit+4 ); in decimal_result()
2826 if( p->nDigit==0 || (p->nDigit==1 && p->a[0]==0) ){ in decimal_result()
2827 p->sign = 0; in decimal_result()
2829 if( p->sign ){ in decimal_result()
2830 z[0] = '-'; in decimal_result()
2833 n = p->nDigit - p->nFrac; in decimal_result()
2838 while( n>1 && p->a[j]==0 ){ in decimal_result()
2840 n--; in decimal_result()
2843 z[i++] = p->a[j] + '0'; in decimal_result()
2845 n--; in decimal_result()
2847 if( p->nFrac ){ in decimal_result()
2850 z[i++] = p->a[j] + '0'; in decimal_result()
2852 }while( j<p->nDigit ); in decimal_result()
2881 ** pA->isNull==0
2883 ** pB->isNull==0
2887 if( pA->sign!=pB->sign ){ in decimal_cmp()
2888 return pA->sign ? -1 : +1; in decimal_cmp()
2890 if( pA->sign ){ in decimal_cmp()
2895 nASig = pA->nDigit - pA->nFrac; in decimal_cmp()
2896 nBSig = pB->nDigit - pB->nFrac; in decimal_cmp()
2898 return nASig - nBSig; in decimal_cmp()
2900 n = pA->nDigit; in decimal_cmp()
2901 if( n>pB->nDigit ) n = pB->nDigit; in decimal_cmp()
2902 rc = memcmp(pA->a, pB->a, n); in decimal_cmp()
2904 rc = pA->nDigit - pB->nDigit; in decimal_cmp()
2925 if( pA==0 || pA->isNull ) goto cmp_done; in decimalCmpFunc()
2927 if( pB==0 || pB->isNull ) goto cmp_done; in decimalCmpFunc()
2929 if( rc<0 ) rc = -1; in decimalCmpFunc()
2945 nAddFrac = nFrac - p->nFrac; in decimal_expand()
2946 nAddSig = (nDigit - p->nDigit) - nAddFrac; in decimal_expand()
2948 p->a = sqlite3_realloc64(p->a, nDigit+1); in decimal_expand()
2949 if( p->a==0 ){ in decimal_expand()
2950 p->oom = 1; in decimal_expand()
2954 memmove(p->a+nAddSig, p->a, p->nDigit); in decimal_expand()
2955 memset(p->a, 0, nAddSig); in decimal_expand()
2956 p->nDigit += nAddSig; in decimal_expand()
2959 memset(p->a+p->nDigit, 0, nAddFrac); in decimal_expand()
2960 p->nDigit += nAddFrac; in decimal_expand()
2961 p->nFrac += nAddFrac; in decimal_expand()
2976 if( pA->oom || pB==0 || pB->oom ){ in decimal_add()
2977 pA->oom = 1; in decimal_add()
2980 if( pA->isNull || pB->isNull ){ in decimal_add()
2981 pA->isNull = 1; in decimal_add()
2984 nSig = pA->nDigit - pA->nFrac; in decimal_add()
2985 if( nSig && pA->a[0]==0 ) nSig--; in decimal_add()
2986 if( nSig<pB->nDigit-pB->nFrac ){ in decimal_add()
2987 nSig = pB->nDigit - pB->nFrac; in decimal_add()
2989 nFrac = pA->nFrac; in decimal_add()
2990 if( nFrac<pB->nFrac ) nFrac = pB->nFrac; in decimal_add()
2994 if( pA->oom || pB->oom ){ in decimal_add()
2995 pA->oom = 1; in decimal_add()
2997 if( pA->sign==pB->sign ){ in decimal_add()
2999 for(i=nDigit-1; i>=0; i--){ in decimal_add()
3000 int x = pA->a[i] + pB->a[i] + carry; in decimal_add()
3003 pA->a[i] = x - 10; in decimal_add()
3006 pA->a[i] = x; in decimal_add()
3012 rc = memcmp(pA->a, pB->a, nDigit); in decimal_add()
3014 aA = pB->a; in decimal_add()
3015 aB = pA->a; in decimal_add()
3016 pA->sign = !pA->sign; in decimal_add()
3018 aA = pA->a; in decimal_add()
3019 aB = pB->a; in decimal_add()
3021 for(i=nDigit-1; i>=0; i--){ in decimal_add()
3022 int x = aA[i] - aB[i] - borrow; in decimal_add()
3024 pA->a[i] = x+10; in decimal_add()
3027 pA->a[i] = x; in decimal_add()
3088 pB->sign = !pB->sign; in decimalSubFunc()
3111 if( !p->isInit ){ in decimalSumStep()
3112 p->isInit = 1; in decimalSumStep()
3113 p->a = sqlite3_malloc(2); in decimalSumStep()
3114 if( p->a==0 ){ in decimalSumStep()
3115 p->oom = 1; in decimalSumStep()
3117 p->a[0] = 0; in decimalSumStep()
3119 p->nDigit = 1; in decimalSumStep()
3120 p->nFrac = 0; in decimalSumStep()
3139 if( pArg ) pArg->sign = !pArg->sign; in decimalSumInverse()
3176 if( pA==0 || pA->oom || pA->isNull in decimalMulFunc()
3177 || pB==0 || pB->oom || pB->isNull in decimalMulFunc()
3181 acc = sqlite3_malloc64( pA->nDigit + pB->nDigit + 2 ); in decimalMulFunc()
3186 memset(acc, 0, pA->nDigit + pB->nDigit + 2); in decimalMulFunc()
3187 minFrac = pA->nFrac; in decimalMulFunc()
3188 if( pB->nFrac<minFrac ) minFrac = pB->nFrac; in decimalMulFunc()
3189 for(i=pA->nDigit-1; i>=0; i--){ in decimalMulFunc()
3190 signed char f = pA->a[i]; in decimalMulFunc()
3192 for(j=pB->nDigit-1, k=i+j+3; j>=0; j--, k--){ in decimalMulFunc()
3193 x = acc[k] + f*pB->a[j] + carry; in decimalMulFunc()
3199 acc[k-1] += x/10; in decimalMulFunc()
3201 sqlite3_free(pA->a); in decimalMulFunc()
3202 pA->a = acc; in decimalMulFunc()
3204 pA->nDigit += pB->nDigit + 2; in decimalMulFunc()
3205 pA->nFrac += pB->nFrac; in decimalMulFunc()
3206 pA->sign ^= pB->sign; in decimalMulFunc()
3207 while( pA->nFrac>minFrac && pA->a[pA->nDigit-1]==0 ){ in decimalMulFunc()
3208 pA->nFrac--; in decimalMulFunc()
3209 pA->nDigit--; in decimalMulFunc()
3267 ** 2022-11-18
3281 ** written as TCL brace-enclosed literals or SQL string literals,
3282 ** and can be used unmodified in XML-like documents.
3289 ** C source specifies that line-feeds are included in the encoded
3291 ** terminate any encoded blob having non-zero length.
3296 ** Generated base64 sequences, with their line-feeds included,
3305 ** This code relies on UTF-8 encoding only with respect to the
3306 ** meaning of the first 128 (7-bit) codes matching that of USASCII.
3308 ** Because it is table-driven, it could be enhanced to handle that,
3313 ** *Nix: gcc -O2 -shared -I$SQDIR -fPIC -o base64.so base64.c
3314 ** OSX: gcc -O2 -dynamiclib -fPIC -I$SQDIR -o base64.dylib base64.c
3315 ** Win32: gcc -O2 -shared -I%SQDIR% -o base64.dll base64.c
3316 ** Win32: cl /Os -I%SQDIR% base64.c -link -dll -out:base64.dll
3336 #define ND 0x82 /* Not above or digit-value */
3344 /* Decoding table, ASCII (7-bit) value to base 64 digit value or other */
3382 /* Do the bit-shuffle, exploiting unsigned input to avoid masking. */ in toBase64()
3388 nbIn -= 3; in toBase64()
3403 for( nbe=3; nbe>=0; --nbe ){ in toBase64()
3418 while( nc-- > 0 && (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s; in skipNonB64()
3424 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn; in fromBase64()
3430 ncIn -= (pUse - pIn); in fromBase64()
3433 ncIn -= nti; in fromBase64()
3441 /* Treat dark non-digits as pad, but they terminate decode too. */ in fromBase64()
3450 --nbo; in fromBase64()
3474 SQLITE_LIMIT_LENGTH, -1); in base64()
3482 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */ in base64()
3484 sqlite3_result_error(context, "blob expanded to base64 too big", -1); in base64()
3492 sqlite3_result_text(context,"",-1,SQLITE_STATIC); in base64()
3497 nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf); in base64()
3504 sqlite3_result_error(context, "blob from base64 may be too big", -1); in base64()
3519 nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf); in base64()
3523 sqlite3_result_error(context, "base64 accepts only blob or text", -1); in base64()
3528 sqlite3_result_error(context, "base64 OOM", -1); in base64()
3565 ** 2022-11-16
3576 ** This is a utility for converting binary to base85 or vice-versa.
3581 ** written as TCL brace-enclosed literals or SQL string literals.
3582 ** It is not suited for unmodified use in XML-like documents.
3590 ** Base85 numerals are taken from the set of 7-bit USASCII codes,
3594 ** Groups of 4 bytes, interpreted as big-endian 32-bit values,
3595 ** are represented as 5-digit base85 numbers with MS to LS digit
3596 ** order. Groups of 1-3 bytes are represented with 2-4 digits,
3597 ** still big-endian but 8-24 bit values. (Using big-endian yields
3599 ** These byte groups can also be considered base-256 numbers.)
3600 ** Groups of 0 bytes are represented with 0 digits and vice-versa.
3602 ** (aka "group") length maps 1-to-1 to the decoded binary length.
3606 ** size, newline is used to separate it into sub-sequences of no
3613 ** a non-base85 character; the conversion to binary will then
3629 ** and variable OPTS to -DOMIT_BASE85_CHECKER if is_base85() unwanted.
3630 ** *Nix: gcc -O2 -shared -I$SQDIR $OPTS -fPIC -o base85.so base85.c
3631 ** OSX: gcc -O2 -dynamiclib -fPIC -I$SQDIR $OPTS -o base85.dylib base85.c
3632 ** Win32: gcc -O2 -shared -I%SQDIR% %OPTS% -o base85.dll base85.c
3633 ** Win32: cl /Os -I%SQDIR% %OPTS% base85.c -link -dll -out:base85.dll
3636 ** *Nix or OSX: gcc -O2 -DBASE85_STANDALONE base85.c -o base85
3637 ** Win32: gcc -O2 -DBASE85_STANDALONE -o base85.exe base85.c
3638 ** Win32: cl /Os /MD -DBASE85_STANDALONE base85.c
3666 " <dirFlag> is either -r to read or -w to write <binFile>,\n"
3669 " Or, the name '-' refers to the stdin or stdout stream.\n"
3688 static u8 b85_cOffset[] = { 0, '#', 0, '*'-4, 0 };
3696 u8 dv = (u8)(c - '#');
3698 return (dv > 3)? dv-3 : dv;
3708 while( nc-- > 0 && (c = *s) && !IS_B85(c) ) ++s; in skipNonB85()
3713 * Do not use the macro form with argument expression having a side-effect.*/
3716 return (b < 4)? (char)(b + '#') : (char)(b - 4 + '*');
3720 ((char)(((dn) < 4)? (char)((dn) + '#') : (char)((dn) - 4 + '*')))
3741 unsigned char dv = qbv - 85UL*nqv; in toBase85()
3743 pOut[--nco] = base85Numeral(dv); in toBase85()
3745 nbIn -= 4; in toBase85()
3764 pOut[--nco] = base85Numeral(dv); in toBase85()
3775 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn; in fromBase85()
3781 ncIn -= (pUse - pIn); in fromBase85()
3789 --ncIn; in fromBase85()
3791 qv = 85 * qv + (c - cdo); in fromBase85()
3792 --nti; in fromBase85()
3794 nbo -= nti; /* Adjust for early (non-digit) end of group. */ in fromBase85()
3815 while( len-- > 0 && (c = *p++) != 0 ){ in allBase85()
3840 sqlite3_result_error(context, "is_base85 accepts only text or NULL", -1); in is_base85()
3850 SQLITE_LIMIT_LENGTH, -1); in base85()
3860 sqlite3_result_error(context, "blob expanded to base85 too big", -1); in base85()
3868 sqlite3_result_text(context,"",-1,SQLITE_STATIC); in base85()
3873 nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf); in base85()
3880 sqlite3_result_error(context, "blob from base85 may be too big", -1); in base85()
3895 nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf); in base85()
3899 sqlite3_result_error(context, "base85 accepts only blob or text.", -1); in base85()
3904 sqlite3_result_error(context, "base85 OOM", -1); in base85()
3958 if( na < 3 || av[1][0]!='-' || (rw = av[1][1])==0 || (rw!='r' && rw!='w') ){ in main()
3963 if( av[2][0]=='-' && av[2][1]==0 ){ in main()
3992 size_t nbo = fromBase85( cBuf, nc, bBuf ) - bBuf; in main()
4007 fprintf(stderr, "Base85 input had non-base85 dark or control content.\n"); in main()
4018 ** 2013-04-17
4030 ** and input of IEEE754 Binary64 floating-point numbers.
4035 ** In the first form, the value X should be a floating-point number.
4040 ** base-2 exponent of a new floating point number. The function returns
4041 ** a floating-point value equal to Y*pow(2,Z).
4045 ** ieee754(2.0) -> 'ieee754(2,0)'
4046 ** ieee754(45.25) -> 'ieee754(181,-2)'
4047 ** ieee754(2, 0) -> 2.0
4048 ** ieee754(181, -2) -> 45.25
4050 ** Two additional functions break apart the one-argument ieee754()
4053 ** ieee754_mantissa(45.25) -> 181
4054 ** ieee754_exponent(45.25) -> -2
4058 ** ieee754_from_blob(x'3ff0000000000000') -> 1.0
4059 ** ieee754_to_blob(1.0) -> x'3ff0000000000000'
4061 ** In all single-argument functions, if the argument is an 8-byte blob
4062 ** then that blob is interpreted as a big-endian binary64 value.
4066 ** -----------------------------------------------
4079 ** VALUES(-1,'0.5')
4081 ** SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075
4088 ** ---------------^^^^^---- Replace with whatever you want
4145 r = -r; in ieee754func()
4155 m = a & ((((sqlite3_int64)1)<<52)-1); in ieee754func()
4165 if( isNeg ) m = -m; in ieee754func()
4170 m, e-1075); in ieee754func()
4171 sqlite3_result_text(context, zResult, -1, SQLITE_TRANSIENT); in ieee754func()
4177 sqlite3_result_int(context, e-1075); in ieee754func()
4187 /* Limit the range of e. Ticket 22dea1cfdb9151e4 2021-03-02 */ in ieee754func()
4190 }else if( e<-10000 ){ in ieee754func()
4191 e = -10000; in ieee754func()
4196 m = -m; in ieee754func()
4198 }else if( m==0 && e>-1000 && e<1000 ){ in ieee754func()
4208 e--; in ieee754func()
4213 if( 1-e >= 64 ){ in ieee754func()
4216 m >>= 1-e; in ieee754func()
4222 a = m & ((((sqlite3_int64)1)<<52)-1); in ieee754func()
4268 a[sizeof(r)-i] = v&0xff; in ieee754func_to_blob()
4314 ** 2015-08-18, 2023-04-28
4325 ** This file demonstrates how to create a table-valued-function using
4328 ** within the limitation that its arguments are signed 64-bit integers.
4332 ** ( V[n] == start + n * step && sgn(V[n] - stop) * sgn(step) >= 0 )
4337 ** The stop parameter defaults to (1<<32)-1 (aka 4294967295 or 0xffffffff)
4355 ** SELECT * FROM generate_series(0,-100,-5);
4357 ** Integers 0 -5 -10 ... -100.
4359 ** SELECT * FROM generate_series(0,-1);
4404 ** series are well-defined.
4414 ** Return that member of a generate_series(...) sequence whose 0-based
4423 ix -= (sqlite3_uint64)LLONG_MAX; in genSeqMember()
4427 smBase += (LLONG_MAX - LLONG_MAX/2) * smStep; in genSeqMember()
4434 ix -= ix2; in genSeqMember()
4459 pss->uSeqIndexMax = 0; in setupSequence()
4460 pss->isNotEOF = 0; in setupSequence()
4461 bSameSigns = (pss->iBase < 0)==(pss->iTerm < 0); in setupSequence()
4462 if( pss->iTerm < pss->iBase ){ in setupSequence()
4465 nuspan = (sqlite3_uint64)(pss->iBase - pss->iTerm); in setupSequence()
4470 nuspan += pss->iBase; in setupSequence()
4471 nuspan += -(pss->iTerm+1); in setupSequence()
4473 if( pss->iStep<0 ){ in setupSequence()
4474 pss->isNotEOF = 1; in setupSequence()
4476 pss->uSeqIndexMax = ( pss->iStep>LLONG_MIN )? nuspan/-pss->iStep : 1; in setupSequence()
4477 }else if( pss->iStep>LLONG_MIN ){ in setupSequence()
4478 pss->uSeqIndexMax = nuspan/-pss->iStep; in setupSequence()
4481 }else if( pss->iTerm > pss->iBase ){ in setupSequence()
4484 puspan = (sqlite3_uint64)(pss->iTerm - pss->iBase); in setupSequence()
4489 puspan += pss->iTerm; in setupSequence()
4490 puspan += -(pss->iBase+1); in setupSequence()
4492 if( pss->iStep>0 ){ in setupSequence()
4493 pss->isNotEOF = 1; in setupSequence()
4494 pss->uSeqIndexMax = puspan/pss->iStep; in setupSequence()
4496 }else if( pss->iTerm == pss->iBase ){ in setupSequence()
4497 pss->isNotEOF = 1; in setupSequence()
4498 pss->uSeqIndexMax = 0; in setupSequence()
4500 pss->uSeqIndexNow = (pss->isReversing)? pss->uSeqIndexMax : 0; in setupSequence()
4501 pss->iValueNow = (pss->isReversing) in setupSequence()
4502 ? genSeqMember(pss->iBase, pss->iStep, pss->uSeqIndexMax) in setupSequence()
4503 : pss->iBase; in setupSequence()
4512 if( !pss->isNotEOF ) return 0; in progressSequence()
4513 if( pss->isReversing ){ in progressSequence()
4514 if( pss->uSeqIndexNow > 0 ){ in progressSequence()
4515 pss->uSeqIndexNow--; in progressSequence()
4516 pss->iValueNow -= pss->iStep; in progressSequence()
4518 pss->isNotEOF = 0; in progressSequence()
4521 if( pss->uSeqIndexNow < pss->uSeqIndexMax ){ in progressSequence()
4522 pss->uSeqIndexNow++; in progressSequence()
4523 pss->iValueNow += pss->iStep; in progressSequence()
4525 pss->isNotEOF = 0; in progressSequence()
4528 return pss->isNotEOF; in progressSequence()
4537 sqlite3_vtab_cursor base; /* Base class - must be first */
4602 *ppCursor = &pCur->base; in seriesOpen()
4620 progressSequence( & pCur->ss ); in seriesNext()
4636 case SERIES_COLUMN_START: x = pCur->ss.iBase; break; in seriesColumn()
4637 case SERIES_COLUMN_STOP: x = pCur->ss.iTerm; break; in seriesColumn()
4638 case SERIES_COLUMN_STEP: x = pCur->ss.iStep; break; in seriesColumn()
4639 default: x = pCur->ss.iValueNow; break; in seriesColumn()
4651 sqlite3_uint64 n = pCur->ss.uSeqIndexNow; in seriesRowid()
4662 return !pCur->ss.isNotEOF; in seriesEof()
4665 /* True to cause run-time checking of the start=, stop=, and/or step=
4704 pCur->ss.iBase = sqlite3_value_int64(argv[i++]); in seriesFilter()
4706 pCur->ss.iBase = 0; in seriesFilter()
4709 pCur->ss.iTerm = sqlite3_value_int64(argv[i++]); in seriesFilter()
4711 pCur->ss.iTerm = 0xffffffff; in seriesFilter()
4714 pCur->ss.iStep = sqlite3_value_int64(argv[i++]); in seriesFilter()
4715 if( pCur->ss.iStep==0 ){ in seriesFilter()
4716 pCur->ss.iStep = 1; in seriesFilter()
4717 }else if( pCur->ss.iStep<0 ){ in seriesFilter()
4721 pCur->ss.iStep = 1; in seriesFilter()
4727 pCur->ss.iBase = 1; in seriesFilter()
4728 pCur->ss.iTerm = 0; in seriesFilter()
4729 pCur->ss.iStep = 1; in seriesFilter()
4734 pCur->ss.isReversing = pCur->ss.iStep > 0; in seriesFilter()
4736 pCur->ss.isReversing = pCur->ss.iStep < 0; in seriesFilter()
4738 setupSequence( &pCur->ss ); in seriesFilter()
4753 ** (1) start = $value -- constraint exists
4754 ** (2) stop = $value -- constraint exists
4755 ** (4) step = $value -- constraint exists
4775 aIdx[0] = aIdx[1] = aIdx[2] = -1; in seriesBestIndex()
4776 pConstraint = pIdxInfo->aConstraint; in seriesBestIndex()
4777 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){ in seriesBestIndex()
4780 if( pConstraint->iColumn<SERIES_COLUMN_START ) continue; in seriesBestIndex()
4781 iCol = pConstraint->iColumn - SERIES_COLUMN_START; in seriesBestIndex()
4785 if( pConstraint->usable==0 ){ in seriesBestIndex()
4788 }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){ in seriesBestIndex()
4795 pIdxInfo->aConstraintUsage[j].argvIndex = ++nArg; in seriesBestIndex()
4796 pIdxInfo->aConstraintUsage[j].omit = !SQLITE_SERIES_CONSTRAINT_VERIFY; in seriesBestIndex()
4801 ** first argument was omitted. Compile with -DZERO_ARGUMENT_GENERATE_SERIES in seriesBestIndex()
4805 sqlite3_free(pVTab->zErrMsg); in seriesBestIndex()
4806 pVTab->zErrMsg = sqlite3_mprintf( in seriesBestIndex()
4820 pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0)); in seriesBestIndex()
4821 pIdxInfo->estimatedRows = 1000; in seriesBestIndex()
4822 if( pIdxInfo->nOrderBy>=1 && pIdxInfo->aOrderBy[0].iColumn==0 ){ in seriesBestIndex()
4823 if( pIdxInfo->aOrderBy[0].desc ){ in seriesBestIndex()
4828 pIdxInfo->orderByConsumed = 1; in seriesBestIndex()
4834 pIdxInfo->estimatedRows = 2147483647; in seriesBestIndex()
4836 pIdxInfo->idxNum = idxNum; in seriesBestIndex()
4851 seriesOpen, /* xOpen - open a cursor */
4852 seriesClose, /* xClose - close a cursor */
4853 seriesFilter, /* xFilter - configure scan constraints */
4854 seriesNext, /* xNext - advance a cursor */
4855 seriesEof, /* xEof - check for end of scan */
4856 seriesColumn, /* xColumn - read data */
4857 seriesRowid, /* xRowid - read data */
4897 ** 2012-11-13
4909 ** efficient regular-expression matcher for posix extended regular
4931 ** \c C-language escapes for c in afnrtv. ex: \t or \n
4936 ** [a-z] Any single character in the range a-z
4937 ** [^a-z] Any single character not in the range a-z
4939 ** \w Word character. [A-Za-z0-9_]
4940 ** \W Non-word character
4942 ** \D Non-digit
4944 ** \S Non-whitespace character
4950 ** to p copies of X following by q-p copies of X? and that the size of the
4961 ** this file to prevent name collisions with C-library functions of the
4968 /* The end-of-input character */
4970 #define RE_START 0xfffffff /* Start of input - larger than an UTF-8 */
4985 #define RE_OP_WORD 11 /* Perl word character [A-Za-z0-9_] */
4987 #define RE_OP_DIGIT 13 /* digit: [0-9] */
4991 #define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */
5061 for(i=0; i<pSet->nState; i++) if( pSet->aState[i]==newState ) return; in re_add_state()
5062 pSet->aState[pSet->nState++] = (ReStateNumber)newState; in re_add_state()
5072 if( p->i>=p->mx ) return 0; in re_next_char()
5073 c = p->z[p->i++]; in re_next_char()
5075 if( (c&0xe0)==0xc0 && p->i<p->mx && (p->z[p->i]&0xc0)==0x80 ){ in re_next_char()
5076 c = (c&0x1f)<<6 | (p->z[p->i++]&0x3f); in re_next_char()
5078 }else if( (c&0xf0)==0xe0 && p->i+1<p->mx && (p->z[p->i]&0xc0)==0x80 in re_next_char()
5079 && (p->z[p->i+1]&0xc0)==0x80 ){ in re_next_char()
5080 c = (c&0x0f)<<12 | ((p->z[p->i]&0x3f)<<6) | (p->z[p->i+1]&0x3f); in re_next_char()
5081 p->i += 2; in re_next_char()
5083 }else if( (c&0xf8)==0xf0 && p->i+2<p->mx && (p->z[p->i]&0xc0)==0x80 in re_next_char()
5084 && (p->z[p->i+1]&0xc0)==0x80 && (p->z[p->i+2]&0xc0)==0x80 ){ in re_next_char()
5085 c = (c&0x07)<<18 | ((p->z[p->i]&0x3f)<<12) | ((p->z[p->i+1]&0x3f)<<6) in re_next_char()
5086 | (p->z[p->i+2]&0x3f); in re_next_char()
5087 p->i += 3; in re_next_char()
5097 if( c>='A' && c<='Z' ) c += 'a' - 'A'; in re_next_char_nocase()
5101 /* Return true if c is a perl "word" character: [A-Za-z0-9_] */
5107 /* Return true if c is a "digit" character: [0-9] */
5117 /* Run a compiled regular expression on the zero-terminated input
5136 if( pRe->nInit ){ in re_match()
5137 unsigned char x = pRe->zInit[0]; in re_match()
5138 while( in.i+pRe->nInit<=in.mx in re_match()
5140 strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0) in re_match()
5144 if( in.i+pRe->nInit>in.mx ) return 0; in re_match()
5145 c = RE_START-1; in re_match()
5148 if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){ in re_match()
5152 pToFree = sqlite3_malloc64( sizeof(ReStateNumber)*2*pRe->nState ); in re_match()
5153 if( pToFree==0 ) return -1; in re_match()
5156 aStateSet[1].aState = &aStateSet[0].aState[pRe->nState]; in re_match()
5158 pNext->nState = 0; in re_match()
5160 while( c!=RE_EOF && pNext->nState>0 ){ in re_match()
5162 c = pRe->xNextChar(&in); in re_match()
5165 iSwap = 1 - iSwap; in re_match()
5166 pNext->nState = 0; in re_match()
5167 for(i=0; i<pThis->nState; i++){ in re_match()
5168 int x = pThis->aState[i]; in re_match()
5169 switch( pRe->aOp[x] ){ in re_match()
5171 if( pRe->aArg[x]==c ) re_add_state(pNext, x+1); in re_match()
5216 re_add_state(pThis, x+pRe->aArg[x]); in re_match()
5221 re_add_state(pThis, x+pRe->aArg[x]); in re_match()
5230 /* fall-through */ goto re_op_cc_inc; in re_match()
5234 int n = pRe->aArg[x]; in re_match()
5237 if( pRe->aOp[x+j]==RE_OP_CC_VALUE ){ in re_match()
5238 if( pRe->aArg[x+j]==c ){ in re_match()
5240 j = -1; in re_match()
5243 if( pRe->aArg[x+j]<=c && pRe->aArg[x+j+1]>=c ){ in re_match()
5245 j = -1; in re_match()
5251 if( pRe->aOp[x]==RE_OP_CC_EXC ) hit = !hit; in re_match()
5258 for(i=0; i<pNext->nState; i++){ in re_match()
5259 int x = pNext->aState[i]; in re_match()
5260 while( pRe->aOp[x]==RE_OP_GOTO ) x += pRe->aArg[x]; in re_match()
5261 if( pRe->aOp[x]==RE_OP_ACCEPT ){ rc = 1; break; } in re_match()
5273 aOp = sqlite3_realloc64(p->aOp, N*sizeof(p->aOp[0])); in re_resize()
5275 p->aOp = aOp; in re_resize()
5276 aArg = sqlite3_realloc64(p->aArg, N*sizeof(p->aArg[0])); in re_resize()
5278 p->aArg = aArg; in re_resize()
5279 p->nAlloc = N; in re_resize()
5288 if( p->nAlloc<=p->nState && re_resize(p, p->nAlloc*2) ) return 0; in re_insert()
5289 for(i=p->nState; i>iBefore; i--){ in re_insert()
5290 p->aOp[i] = p->aOp[i-1]; in re_insert()
5291 p->aArg[i] = p->aArg[i-1]; in re_insert()
5293 p->nState++; in re_insert()
5294 p->aOp[iBefore] = (char)op; in re_insert()
5295 p->aArg[iBefore] = arg; in re_insert()
5302 return re_insert(p, p->nState, op, arg); in re_append()
5309 if( p->nState+N>=p->nAlloc && re_resize(p, p->nAlloc*2+N) ) return; in re_copy()
5310 memcpy(&p->aOp[p->nState], &p->aOp[iStart], N*sizeof(p->aOp[0])); in re_copy()
5311 memcpy(&p->aArg[p->nState], &p->aArg[iStart], N*sizeof(p->aArg[0])); in re_copy()
5312 p->nState += N; in re_copy()
5315 /* Return true if c is a hexadecimal digit character: [0-9a-fA-F]
5321 c -= '0'; in re_hex()
5323 c -= 'a' - 10; in re_hex()
5325 c -= 'A' - 10; in re_hex()
5341 if( p->sIn.i>=p->sIn.mx ) return 0; in re_esc_char()
5342 c = p->sIn.z[p->sIn.i]; in re_esc_char()
5343 if( c=='u' && p->sIn.i+4<p->sIn.mx ){ in re_esc_char()
5344 const unsigned char *zIn = p->sIn.z + p->sIn.i; in re_esc_char()
5350 p->sIn.i += 5; in re_esc_char()
5354 if( c=='x' && p->sIn.i+2<p->sIn.mx ){ in re_esc_char()
5355 const unsigned char *zIn = p->sIn.z + p->sIn.i; in re_esc_char()
5359 p->sIn.i += 3; in re_esc_char()
5366 p->sIn.i++; in re_esc_char()
5368 p->zErr = "unknown \\ escape"; in re_esc_char()
5378 return p->sIn.i<p->sIn.mx ? p->sIn.z[p->sIn.i] : 0; in rePeek()
5388 iStart = p->nState; in re_subcompile_re()
5392 iEnd = p->nState; in re_subcompile_re()
5393 re_insert(p, iStart, RE_OP_FORK, iEnd + 2 - iStart); in re_subcompile_re()
5395 p->sIn.i++; in re_subcompile_re()
5398 p->aArg[iGoto] = p->nState - iGoto; in re_subcompile_re()
5408 int iPrev = -1; in re_subcompile_string()
5412 while( (c = p->xNextChar(&p->sIn))!=0 ){ in re_subcompile_string()
5413 iStart = p->nState; in re_subcompile_string()
5417 p->sIn.i--; in re_subcompile_string()
5424 p->sIn.i++; in re_subcompile_string()
5430 p->sIn.i++; in re_subcompile_string()
5438 re_insert(p, iPrev, RE_OP_GOTO, p->nState - iPrev + 1); in re_subcompile_string()
5439 re_append(p, RE_OP_FORK, iPrev - p->nState + 1); in re_subcompile_string()
5444 re_append(p, RE_OP_FORK, iPrev - p->nState); in re_subcompile_string()
5449 re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1); in re_subcompile_string()
5464 while( (c=rePeek(p))>='0' && c<='9' ){ m = m*10 + c - '0'; p->sIn.i++; } in re_subcompile_string()
5467 p->sIn.i++; in re_subcompile_string()
5469 while( (c=rePeek(p))>='0' && c<='9' ){ n = n*10 + c-'0'; p->sIn.i++; } in re_subcompile_string()
5473 p->sIn.i++; in re_subcompile_string()
5474 sz = p->nState - iPrev; in re_subcompile_string()
5479 n--; in re_subcompile_string()
5488 re_append(p, RE_OP_FORK, -sz); in re_subcompile_string()
5493 unsigned int iFirst = p->nState; in re_subcompile_string()
5496 p->sIn.i++; in re_subcompile_string()
5500 while( (c = p->xNextChar(&p->sIn))!=0 ){ in re_subcompile_string()
5505 if( rePeek(p)=='-' ){ in re_subcompile_string()
5507 p->sIn.i++; in re_subcompile_string()
5508 c = p->xNextChar(&p->sIn); in re_subcompile_string()
5514 if( rePeek(p)==']' ){ p->sIn.i++; break; } in re_subcompile_string()
5517 if( p->nState>iFirst ) p->aArg[iFirst] = p->nState - iFirst; in re_subcompile_string()
5532 p->sIn.i++; in re_subcompile_string()
5556 sqlite3_free(pRe->aOp); in re_free()
5557 sqlite3_free(pRe->aArg); in re_free()
5579 pRe->xNextChar = noCase ? re_next_char_nocase : re_next_char; in re_compile()
5589 pRe->sIn.z = (unsigned char*)zIn; in re_compile()
5590 pRe->sIn.i = 0; in re_compile()
5591 pRe->sIn.mx = (int)strlen(zIn); in re_compile()
5597 if( pRe->sIn.i>=pRe->sIn.mx ){ in re_compile()
5611 ** unicode characters beyond plane 0 - those are very rare and this is in re_compile()
5613 if( pRe->aOp[0]==RE_OP_ANYSTAR && !noCase ){ in re_compile()
5614 for(j=0, i=1; j<(int)sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){ in re_compile()
5615 unsigned x = pRe->aArg[i]; in re_compile()
5617 pRe->zInit[j++] = (unsigned char)x; in re_compile()
5619 pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6)); in re_compile()
5620 pRe->zInit[j++] = 0x80 | (x&0x3f); in re_compile()
5622 pRe->zInit[j++] = (unsigned char)(0xe0 | (x>>12)); in re_compile()
5623 pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f); in re_compile()
5624 pRe->zInit[j++] = 0x80 | (x&0x3f); in re_compile()
5629 if( j>0 && pRe->zInit[j-1]==0 ) j--; in re_compile()
5630 pRe->nInit = j; in re_compile()
5632 return pRe->zErr; in re_compile()
5637 ** the build-in REGEXP operator. The first argument to the function is the
5663 sqlite3_result_error(context, zErr, -1); in re_sql_func()
5674 sqlite3_result_int(context, re_match(pRe, zStr, -1)); in re_sql_func()
5684 ** if the SQLITE_DEBUG compile-time option is used.
5708 sqlite3_result_error(context, zErr, -1); in re_bytecode_func()
5717 if( pRe->nInit>0 ){ in re_bytecode_func()
5719 for(i=0; i<pRe->nInit; i++){ in re_bytecode_func()
5720 sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]); in re_bytecode_func()
5724 for(i=0; (unsigned)i<pRe->nState; i++){ in re_bytecode_func()
5725 sqlite3_str_appendf(pStr, "%-8s %4d\n", in re_bytecode_func()
5726 ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]); in re_bytecode_func()
5733 sqlite3_result_text(context, z, n-1, sqlite3_free); in re_bytecode_func()
5762 /* The regexpi(PATTERN,STRING) function is a case-insensitive version in sqlite3_regexp_init()
5782 ** 2014-06-13
5802 ** If the first option argument - MODE - is present, then it must
5819 ** as an integer - the number of seconds since the unix epoch. The
5820 ** modification-time of the target file is set to this value before
5840 ** file within the hierarchy rooted at $path.
5851 ** If a non-NULL value is specified for the optional $dir parameter and
5858 ** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
5895 ** Structure of the fsdir() table-valued function
5934 mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1); in readFileContents()
5981 sqlite3_result_error(ctx, zMsg, -1); in ctxErrorMsg()
5989 ** number of seconds since the Unix Epoch (1970-01-01 00:00:00 UTC).
6007 fileIntervals.LowPart = pFileTime->dwLowDateTime; in fileTimeToUnixTime()
6008 fileIntervals.HighPart = pFileTime->dwHighDateTime; in fileTimeToUnixTime()
6010 return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000; in fileTimeToUnixTime()
6020 int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0); in utf8_to_utf16()
6022 if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) ) in utf8_to_utf16()
6047 pStatBuf->st_ctime = (time_t)fileTimeToUnixTime(&fd.ftCreationTime); in statTimesToUtc()
6048 pStatBuf->st_atime = (time_t)fileTimeToUnixTime(&fd.ftLastAccessTime); in statTimesToUtc()
6049 pStatBuf->st_mtime = (time_t)fileTimeToUnixTime(&fd.ftLastWriteTime); in statTimesToUtc()
6149 sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */ in writeFile()
6162 ** be an error though - if there is already a directory at the same in writeFile()
6267 sqlite3_int64 mtime = -1; in writefileFunc()
6271 "wrong number of arguments to function writefile()", -1 in writefileFunc()
6306 ** Given a numberic st_mode from stat(), convert it into a human-readable
6307 ** text string in the style of "ls -l".
6321 z[0] = '-'; in lsModeFunc()
6328 int m = (iMode >> ((2-i)*3)); in lsModeFunc()
6330 a[0] = (m & 0x4) ? 'r' : '-'; in lsModeFunc()
6331 a[1] = (m & 0x2) ? 'w' : '-'; in lsModeFunc()
6332 a[2] = (m & 0x1) ? 'x' : '-'; in lsModeFunc()
6335 sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT); in lsModeFunc()
6348 char *zDir; /* Name of directory (nul-terminated) */
6352 sqlite3_vtab_cursor base; /* Base class - must be first */
6356 FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
6368 sqlite3_vtab base; /* Base class - must be first */
6415 pCur->iLvl = -1; in fsdirOpen()
6416 *ppCursor = &pCur->base; in fsdirOpen()
6426 for(i=0; i<=pCur->iLvl; i++){ in fsdirResetCursor()
6427 FsdirLevel *pLvl = &pCur->aLvl[i]; in fsdirResetCursor()
6428 if( pLvl->pDir ) closedir(pLvl->pDir); in fsdirResetCursor()
6429 sqlite3_free(pLvl->zDir); in fsdirResetCursor()
6431 sqlite3_free(pCur->zPath); in fsdirResetCursor()
6432 sqlite3_free(pCur->aLvl); in fsdirResetCursor()
6433 pCur->aLvl = 0; in fsdirResetCursor()
6434 pCur->zPath = 0; in fsdirResetCursor()
6435 pCur->zBase = 0; in fsdirResetCursor()
6436 pCur->nBase = 0; in fsdirResetCursor()
6437 pCur->nLvl = 0; in fsdirResetCursor()
6438 pCur->iLvl = -1; in fsdirResetCursor()
6439 pCur->iRowid = 1; in fsdirResetCursor()
6460 pCur->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap); in fsdirSetErrmsg()
6470 mode_t m = pCur->sStat.st_mode; in fsdirNext()
6472 pCur->iRowid++; in fsdirNext()
6475 int iNew = pCur->iLvl + 1; in fsdirNext()
6477 if( iNew>=pCur->nLvl ){ in fsdirNext()
6480 FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc64(pCur->aLvl, nByte); in fsdirNext()
6482 memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl)); in fsdirNext()
6483 pCur->aLvl = aNew; in fsdirNext()
6484 pCur->nLvl = nNew; in fsdirNext()
6486 pCur->iLvl = iNew; in fsdirNext()
6487 pLvl = &pCur->aLvl[iNew]; in fsdirNext()
6489 pLvl->zDir = pCur->zPath; in fsdirNext()
6490 pCur->zPath = 0; in fsdirNext()
6491 pLvl->pDir = opendir(pLvl->zDir); in fsdirNext()
6492 if( pLvl->pDir==0 ){ in fsdirNext()
6493 fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath); in fsdirNext()
6498 while( pCur->iLvl>=0 ){ in fsdirNext()
6499 FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl]; in fsdirNext()
6500 struct dirent *pEntry = readdir(pLvl->pDir); in fsdirNext()
6502 if( pEntry->d_name[0]=='.' ){ in fsdirNext()
6503 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue; in fsdirNext()
6504 if( pEntry->d_name[1]=='\0' ) continue; in fsdirNext()
6506 sqlite3_free(pCur->zPath); in fsdirNext()
6507 pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name); in fsdirNext()
6508 if( pCur->zPath==0 ) return SQLITE_NOMEM; in fsdirNext()
6509 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){ in fsdirNext()
6510 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath); in fsdirNext()
6515 closedir(pLvl->pDir); in fsdirNext()
6516 sqlite3_free(pLvl->zDir); in fsdirNext()
6517 pLvl->pDir = 0; in fsdirNext()
6518 pLvl->zDir = 0; in fsdirNext()
6519 pCur->iLvl--; in fsdirNext()
6523 sqlite3_free(pCur->zPath); in fsdirNext()
6524 pCur->zPath = 0; in fsdirNext()
6540 sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT); in fsdirColumn()
6545 sqlite3_result_int64(ctx, pCur->sStat.st_mode); in fsdirColumn()
6549 sqlite3_result_int64(ctx, pCur->sStat.st_mtime); in fsdirColumn()
6553 mode_t m = pCur->sStat.st_mode; in fsdirColumn()
6564 n = readlink(pCur->zPath, aBuf, nBuf); in fsdirColumn()
6579 readFileContents(ctx, pCur->zPath); in fsdirColumn()
6599 *pRowid = pCur->iRowid; in fsdirRowid()
6609 return (pCur->zPath==0); in fsdirEof()
6636 fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument"); in fsdirFilter()
6640 pCur->zBase = (const char*)sqlite3_value_text(argv[1]); in fsdirFilter()
6642 if( pCur->zBase ){ in fsdirFilter()
6643 pCur->nBase = (int)strlen(pCur->zBase)+1; in fsdirFilter()
6644 pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir); in fsdirFilter()
6646 pCur->zPath = sqlite3_mprintf("%s", zDir); in fsdirFilter()
6649 if( pCur->zPath==0 ){ in fsdirFilter()
6652 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){ in fsdirFilter()
6653 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath); in fsdirFilter()
6679 int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */ in fsdirBestIndex()
6680 int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */ in fsdirBestIndex()
6686 pConstraint = pIdxInfo->aConstraint; in fsdirBestIndex()
6687 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){ in fsdirBestIndex()
6688 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; in fsdirBestIndex()
6689 switch( pConstraint->iColumn ){ in fsdirBestIndex()
6691 if( pConstraint->usable ){ in fsdirBestIndex()
6700 if( pConstraint->usable ){ in fsdirBestIndex()
6716 pIdxInfo->idxNum = 0; in fsdirBestIndex()
6717 /* The pIdxInfo->estimatedCost should have been initialized to a huge in fsdirBestIndex()
6719 pIdxInfo->estimatedRows = 0x7fffffff; in fsdirBestIndex()
6721 pIdxInfo->aConstraintUsage[idxPath].omit = 1; in fsdirBestIndex()
6722 pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1; in fsdirBestIndex()
6724 pIdxInfo->aConstraintUsage[idxDir].omit = 1; in fsdirBestIndex()
6725 pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2; in fsdirBestIndex()
6726 pIdxInfo->idxNum = 2; in fsdirBestIndex()
6727 pIdxInfo->estimatedCost = 10.0; in fsdirBestIndex()
6729 pIdxInfo->idxNum = 1; in fsdirBestIndex()
6730 pIdxInfo->estimatedCost = 100.0; in fsdirBestIndex()
6748 fsdirOpen, /* xOpen - open a cursor */ in fsdirRegister()
6749 fsdirClose, /* xClose - close a cursor */ in fsdirRegister()
6750 fsdirFilter, /* xFilter - configure scan constraints */ in fsdirRegister()
6751 fsdirNext, /* xNext - advance a cursor */ in fsdirRegister()
6752 fsdirEof, /* xEof - check for end of scan */ in fsdirRegister()
6753 fsdirColumn, /* xColumn - read data */ in fsdirRegister()
6754 fsdirRowid, /* xRowid - read data */ in fsdirRegister()
6790 rc = sqlite3_create_function(db, "writefile", -1, in sqlite3_fileio_init()
6815 ** 2017-07-10
6862 sqlite3_vtab base; /* Base class - must be first */
6872 sqlite3_vtab_cursor base; /* Base class - must be first */
6882 int j; /* inter-phase counter */
6932 #define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */ in completionConnect()
6947 pNew->db = db; in completionConnect()
6968 pCur->db = ((completion_vtab*)p)->db; in completionOpen()
6969 *ppCursor = &pCur->base; in completionOpen()
6977 sqlite3_free(pCur->zPrefix); pCur->zPrefix = 0; pCur->nPrefix = 0; in completionCursorReset()
6978 sqlite3_free(pCur->zLine); pCur->zLine = 0; pCur->nLine = 0; in completionCursorReset()
6979 sqlite3_finalize(pCur->pStmt); pCur->pStmt = 0; in completionCursorReset()
6980 pCur->j = 0; in completionCursorReset()
6995 ** The ->ePhase, ->j, and ->pStmt fields of the completion_cursor object
6996 ** record the current state of the scan. This routine sets ->zCurrentRow
6998 ** then ->ePhase is set to COMPLETION_EOF which will signal the virtual
7009 int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */ in completionNext()
7010 pCur->iRowid++; in completionNext()
7011 while( pCur->ePhase!=COMPLETION_EOF ){ in completionNext()
7012 switch( pCur->ePhase ){ in completionNext()
7014 if( pCur->j >= sqlite3_keyword_count() ){ in completionNext()
7015 pCur->zCurrentRow = 0; in completionNext()
7016 pCur->ePhase = COMPLETION_DATABASES; in completionNext()
7018 sqlite3_keyword_name(pCur->j++, &pCur->zCurrentRow, &pCur->szRow); in completionNext()
7020 iCol = -1; in completionNext()
7024 if( pCur->pStmt==0 ){ in completionNext()
7025 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, in completionNext()
7026 &pCur->pStmt, 0); in completionNext()
7033 if( pCur->pStmt==0 ){ in completionNext()
7037 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0); in completionNext()
7049 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0); in completionNext()
7057 if( pCur->pStmt==0 ){ in completionNext()
7061 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0); in completionNext()
7075 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0); in completionNext()
7085 if( pCur->zCurrentRow==0 ) continue; in completionNext()
7087 if( sqlite3_step(pCur->pStmt)==SQLITE_ROW ){ in completionNext()
7089 pCur->zCurrentRow = (const char*)sqlite3_column_text(pCur->pStmt, iCol); in completionNext()
7090 pCur->szRow = sqlite3_column_bytes(pCur->pStmt, iCol); in completionNext()
7093 sqlite3_finalize(pCur->pStmt); in completionNext()
7094 pCur->pStmt = 0; in completionNext()
7095 pCur->ePhase = eNextPhase; in completionNext()
7099 if( pCur->nPrefix==0 ) break; in completionNext()
7100 if( pCur->nPrefix<=pCur->szRow in completionNext()
7101 && sqlite3_strnicmp(pCur->zPrefix, pCur->zCurrentRow, pCur->nPrefix)==0 in completionNext()
7122 sqlite3_result_text(ctx, pCur->zCurrentRow, pCur->szRow,SQLITE_TRANSIENT); in completionColumn()
7126 sqlite3_result_text(ctx, pCur->zPrefix, -1, SQLITE_TRANSIENT); in completionColumn()
7130 sqlite3_result_text(ctx, pCur->zLine, -1, SQLITE_TRANSIENT); in completionColumn()
7134 sqlite3_result_int(ctx, pCur->ePhase); in completionColumn()
7147 *pRowid = pCur->iRowid; in completionRowid()
7157 return pCur->ePhase >= COMPLETION_EOF; in completionEof()
7177 pCur->nPrefix = sqlite3_value_bytes(argv[iArg]); in completionFilter()
7178 if( pCur->nPrefix>0 ){ in completionFilter()
7179 pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg])); in completionFilter()
7180 if( pCur->zPrefix==0 ) return SQLITE_NOMEM; in completionFilter()
7185 pCur->nLine = sqlite3_value_bytes(argv[iArg]); in completionFilter()
7186 if( pCur->nLine>0 ){ in completionFilter()
7187 pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg])); in completionFilter()
7188 if( pCur->zLine==0 ) return SQLITE_NOMEM; in completionFilter()
7191 if( pCur->zLine!=0 && pCur->zPrefix==0 ){ in completionFilter()
7192 int i = pCur->nLine; in completionFilter()
7193 while( i>0 && (isalnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){ in completionFilter()
7194 i--; in completionFilter()
7196 pCur->nPrefix = pCur->nLine - i; in completionFilter()
7197 if( pCur->nPrefix>0 ){ in completionFilter()
7198 pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i); in completionFilter()
7199 if( pCur->zPrefix==0 ) return SQLITE_NOMEM; in completionFilter()
7202 pCur->iRowid = 0; in completionFilter()
7203 pCur->ePhase = COMPLETION_FIRST_PHASE; in completionFilter()
7213 ** There are two hidden parameters that act as arguments to the table-valued
7223 int prefixIdx = -1; /* Index of the start= constraint, or -1 if none */ in completionBestIndex()
7224 int wholelineIdx = -1; /* Index of the stop= constraint, or -1 if none */ in completionBestIndex()
7229 pConstraint = pIdxInfo->aConstraint; in completionBestIndex()
7230 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){ in completionBestIndex()
7231 if( pConstraint->usable==0 ) continue; in completionBestIndex()
7232 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; in completionBestIndex()
7233 switch( pConstraint->iColumn ){ in completionBestIndex()
7245 pIdxInfo->aConstraintUsage[prefixIdx].argvIndex = ++nArg; in completionBestIndex()
7246 pIdxInfo->aConstraintUsage[prefixIdx].omit = 1; in completionBestIndex()
7249 pIdxInfo->aConstraintUsage[wholelineIdx].argvIndex = ++nArg; in completionBestIndex()
7250 pIdxInfo->aConstraintUsage[wholelineIdx].omit = 1; in completionBestIndex()
7252 pIdxInfo->idxNum = idxNum; in completionBestIndex()
7253 pIdxInfo->estimatedCost = (double)5000 - 1000*nArg; in completionBestIndex()
7254 pIdxInfo->estimatedRows = 500 - 100*nArg; in completionBestIndex()
7269 completionOpen, /* xOpen - open a cursor */
7270 completionClose, /* xClose - close a cursor */
7271 completionFilter, /* xFilter - configure scan constraints */
7272 completionNext, /* xNext - advance a cursor */
7273 completionEof, /* xEof - check for end of scan */
7274 completionColumn, /* xColumn - read data */
7275 completionRowid, /* xRowid - read data */
7319 ** 2017-10-20
7347 ** "Start-Of-SQLite3-NNNNNNNN" that file is an appended database.
7364 ** this shim is a pass-through into the default underlying VFS. (rule 3)
7373 ** Start-Of-SQLite3-NNNNNNNN
7376 ** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
7379 #define APND_MARK_PREFIX "Start-Of-SQLite3-"
7385 ** Maximum size of the combined prefix + database + append-mark. This
7396 #define APND_ALIGN_MASK ((sqlite3_int64)(APND_ROUNDUP-1))
7405 /* Access to a lower-level VFS that (might) implement dynamic loading,
7408 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
7417 ** append-mark.
7421 ** +-------------+---------+----------+-------------+
7422 ** | prefix-file | padding | database | append-mark |
7423 ** +-------------+---------+----------+-------------+
7429 ** "prefix file" - file onto which the database has been appended.
7430 ** "padding" - zero or more bytes inserted so that "database"
7432 ** "database" - The SQLite database file
7433 ** "append-mark" - The 25-byte "Start-Of-SQLite3-NNNNNNNN" that indicates
7434 ** the offset from the start of prefix-file to the start
7437 ** The size of the database is iMark - iPgOne.
7439 ** The NNNNNNNN in the "Start-Of-SQLite3-NNNNNNNN" suffix is the value
7440 ** of iPgOne stored as a big-ending 64-bit integer.
7443 ** Or, iMark is -1 to indicate that it has not yet been written.
7448 sqlite3_int64 iMark; /* Offset of the append mark. -1 if unwritten */
7542 ** Close an apnd-file.
7546 return pFile->pMethods->xClose(pFile); in apndClose()
7550 ** Read data from an apnd-file.
7560 return pFile->pMethods->xRead(pFile, zBuf, iAmt, paf->iPgOne+iOfst); in apndRead()
7564 ** Add the append-mark onto what should become the end of the file.
7566 * Parameter iWriteEnd is the appendvfs-relative offset of the new mark.
7573 sqlite_int64 iPgOne = paf->iPgOne; in apndWriteMark()
7579 while( --i >= 0 ){ in apndWriteMark()
7583 iWriteEnd += paf->iPgOne; in apndWriteMark()
7584 if( SQLITE_OK==(rc = pFile->pMethods->xWrite in apndWriteMark()
7586 paf->iMark = iWriteEnd; in apndWriteMark()
7592 ** Write data to an apnd-file.
7604 /* If append-mark is absent or will be overwritten, write it. */ in apndWrite()
7605 if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){ in apndWrite()
7609 return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst); in apndWrite()
7613 ** Truncate an apnd-file.
7621 return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE); in apndTruncate()
7625 ** Sync an apnd-file.
7629 return pFile->pMethods->xSync(pFile, flags); in apndSync()
7633 ** Return the current file-size of an apnd-file.
7634 ** If the append mark is not yet there, the file-size is 0.
7638 *pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0; in apndFileSize()
7643 ** Lock an apnd-file.
7647 return pFile->pMethods->xLock(pFile, eLock); in apndLock()
7651 ** Unlock an apnd-file.
7655 return pFile->pMethods->xUnlock(pFile, eLock); in apndUnlock()
7659 ** Check if another file-handle holds a RESERVED lock on an apnd-file.
7663 return pFile->pMethods->xCheckReservedLock(pFile, pResOut); in apndCheckReservedLock()
7667 ** File control method. For custom operations on an apnd-file.
7673 if( op==SQLITE_FCNTL_SIZE_HINT ) *(sqlite3_int64*)pArg += paf->iPgOne; in apndFileControl()
7674 rc = pFile->pMethods->xFileControl(pFile, op, pArg); in apndFileControl()
7676 *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", paf->iPgOne,*(char**)pArg); in apndFileControl()
7682 ** Return the sector-size in bytes for an apnd-file.
7686 return pFile->pMethods->xSectorSize(pFile); in apndSectorSize()
7690 ** Return the device characteristic flags supported by an apnd-file.
7694 return pFile->pMethods->xDeviceCharacteristics(pFile); in apndDeviceCharacteristics()
7706 return pFile->pMethods->xShmMap(pFile,iPg,pgsz,bExtend,pp); in apndShmMap()
7709 /* Perform locking on a shared-memory segment */
7712 return pFile->pMethods->xShmLock(pFile,offset,n,flags); in apndShmLock()
7718 pFile->pMethods->xShmBarrier(pFile); in apndShmBarrier()
7724 return pFile->pMethods->xShmUnmap(pFile,deleteFlag); in apndShmUnmap()
7727 /* Fetch a page of a memory-mapped file */
7735 if( p->iMark < 0 || iOfst+iAmt > p->iMark ){ in apndFetch()
7739 return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp); in apndFetch()
7742 /* Release a memory-mapped page */
7746 return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage); in apndUnfetch()
7750 ** Try to read the append-mark off the end of a file. Return the
7751 ** start of the appended database if the append-mark is present.
7752 ** If there is no valid append-mark, return -1;
7754 ** An append-mark is only valid if the NNNNNNNN start-of-database offset
7756 ** start-of-database value must be a multiple of 512.
7761 int msbs = 8 * (APND_MARK_FOS_SZ-1); in apndReadMark()
7764 if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1; in apndReadMark()
7765 rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE); in apndReadMark()
7766 if( rc ) return -1; in apndReadMark()
7767 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1; in apndReadMark()
7770 msbs -= 8; in apndReadMark()
7773 if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1; in apndReadMark()
7774 if( iMark & 0x1ff ) return -1; in apndReadMark()
7788 /* If file has the correct end-marker, the expected odd size, and the in apndIsAppendvfsDatabase()
7789 ** SQLite DB type marker where the end-marker puts it, then it in apndIsAppendvfsDatabase()
7792 rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark); in apndIsAppendvfsDatabase()
7812 || SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0) in apndIsOrdinaryDatabaseFile()
7841 return pBaseVfs->xOpen(pBaseVfs, zName, pFile, flags, pOutFlags); in apndOpen()
7844 pFile->pMethods = &apnd_io_methods; in apndOpen()
7845 pApndFile->iMark = -1; /* Append mark not yet written */ in apndOpen()
7847 rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags); in apndOpen()
7849 rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz); in apndOpen()
7851 pBaseFile->pMethods->xClose(pBaseFile); in apndOpen()
7855 pFile->pMethods = 0; in apndOpen()
7860 ** the base dispatch-table so this instance mimics the base VFS. in apndOpen()
7862 memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile); in apndOpen()
7865 pApndFile->iPgOne = apndReadMark(sz, pFile); in apndOpen()
7866 if( pApndFile->iPgOne>=0 ){ in apndOpen()
7867 pApndFile->iMark = sz - APND_MARK_SIZE; /* Append mark found */ in apndOpen()
7871 pBaseFile->pMethods->xClose(pBaseFile); in apndOpen()
7873 pFile->pMethods = 0; in apndOpen()
7878 ** Until then, paf->iMark value indicates it is not yet written. in apndOpen()
7880 pApndFile->iPgOne = APND_START_ROUNDUP(sz); in apndOpen()
7892 return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync); in apndDelete()
7896 ** All other VFS methods are pass-thrus.
7904 return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut); in apndAccess()
7912 return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut); in apndFullPathname()
7915 return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath); in apndDlOpen()
7918 ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg); in apndDlError()
7921 return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym); in apndDlSym()
7924 ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle); in apndDlClose()
7927 return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut); in apndRandomness()
7930 return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro); in apndSleep()
7933 return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut); in apndCurrentTime()
7936 return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b); in apndGetLastError()
7939 return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p); in apndCurrentTimeInt64()
7946 return ORIGVFS(pVfs)->xSetSystemCall(ORIGVFS(pVfs),zName,pCall); in apndSetSystemCall()
7952 return ORIGVFS(pVfs)->xGetSystemCall(ORIGVFS(pVfs),zName); in apndGetSystemCall()
7955 return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName); in apndNextSystemCall()
7978 apnd_vfs.iVersion = pOrig->iVersion; in sqlite3_appendvfs_init()
7980 apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile); in sqlite3_appendvfs_init()
7996 ** 2017-12-26
8049 /* typedef UINT32_TYPE u32; // 4-byte unsigned integer // */
8050 /* typedef UINT16_TYPE u16; // 2-byte unsigned integer // */
8108 ** Use this value for the "version-made-by" field in new zip file
8111 ** This is what info-zip seems to do.
8114 ** Value for "version-required-to-extract" field of new entries.
8118 ** Value for "general-purpose-bit-flags" field of new entries. Bit
8119 ** 11 means "utf-8 filename and comment".
8139 ** The sizes of the fixed-size part of each of the three main data
8186 *** crc-32 4 bytes
8227 *** crc-32 4 bytes
8255 ZipfileEntry *pNext; /* Next element in in-memory CDS */
8263 sqlite3_vtab_cursor base; /* Base class - must be first */
8266 u8 bNoop; /* If next xNext() call is no-op */
8280 sqlite3_vtab base; /* Base class - must be first */
8305 sqlite3_result_error(ctx, zMsg, -1); in zipfileCtxErrorMsg()
8332 ** argv[0] -> module name ("zipfile")
8333 ** argv[1] -> database name
8334 ** argv[2] -> table name
8335 ** argv[...] -> "column name" and other module argument fields.
8376 pNew->db = db; in zipfileConnect()
8377 pNew->aBuffer = (u8*)&pNew[1]; in zipfileConnect()
8379 pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE]; in zipfileConnect()
8380 memcpy(pNew->zFile, zFile, nFile); in zipfileConnect()
8381 zipfileDequote(pNew->zFile); in zipfileConnect()
8394 sqlite3_free(p->cds.zFile); in zipfileEntryFree()
8407 if( pTab->pWriteFd ){ in zipfileCleanupTransaction()
8408 fclose(pTab->pWriteFd); in zipfileCleanupTransaction()
8409 pTab->pWriteFd = 0; in zipfileCleanupTransaction()
8411 for(pEntry=pTab->pFirstEntry; pEntry; pEntry=pNext){ in zipfileCleanupTransaction()
8412 pNext = pEntry->pNext; in zipfileCleanupTransaction()
8415 pTab->pFirstEntry = 0; in zipfileCleanupTransaction()
8416 pTab->pLastEntry = 0; in zipfileCleanupTransaction()
8417 pTab->szCurrent = 0; in zipfileCleanupTransaction()
8418 pTab->szOrig = 0; in zipfileCleanupTransaction()
8442 pCsr->iId = ++pTab->iNextCsrid; in zipfileOpen()
8443 pCsr->pCsrNext = pTab->pCsrList; in zipfileOpen()
8444 pTab->pCsrList = pCsr; in zipfileOpen()
8456 pCsr->bEof = 0; in zipfileResetCursor()
8457 if( pCsr->pFile ){ in zipfileResetCursor()
8458 fclose(pCsr->pFile); in zipfileResetCursor()
8459 pCsr->pFile = 0; in zipfileResetCursor()
8460 zipfileEntryFree(pCsr->pCurrent); in zipfileResetCursor()
8461 pCsr->pCurrent = 0; in zipfileResetCursor()
8464 for(p=pCsr->pFreeEntry; p; p=pNext){ in zipfileResetCursor()
8465 pNext = p->pNext; in zipfileResetCursor()
8475 ZipfileTab *pTab = (ZipfileTab*)(pCsr->base.pVtab); in zipfileClose()
8480 for(pp=&pTab->pCsrList; *pp!=pCsr; pp=&((*pp)->pCsrNext)); in zipfileClose()
8481 *pp = pCsr->pCsrNext; in zipfileClose()
8494 sqlite3_free(pTab->base.zErrMsg); in zipfileTableErr()
8495 pTab->base.zErrMsg = sqlite3_vmprintf(zFmt, ap); in zipfileTableErr()
8501 sqlite3_free(pCsr->base.pVtab->zErrMsg); in zipfileCursorErr()
8502 pCsr->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap); in zipfileCursorErr()
8540 fseek(pTab->pWriteFd, (long)pTab->szCurrent, SEEK_SET); in zipfileAppendData()
8541 n = fwrite(aWrite, 1, nWrite, pTab->pWriteFd); in zipfileAppendData()
8543 pTab->base.zErrMsg = sqlite3_mprintf("error in fwrite()"); in zipfileAppendData()
8546 pTab->szCurrent += nWrite; in zipfileAppendData()
8552 ** Read and return a 16-bit little-endian unsigned integer from buffer aBuf.
8559 ** Read and return a 32-bit little-endian unsigned integer from buffer aBuf.
8570 ** Write a 16-bit little endiate integer into buffer aBuf.
8578 ** Write a 32-bit little endiate integer into buffer aBuf.
8587 #define zipfileRead32(aBuf) ( aBuf+=4, zipfileGetU32(aBuf-4) )
8588 #define zipfileRead16(aBuf) ( aBuf+=2, zipfileGetU16(aBuf-2) )
8601 ** if the record is not well-formed, or SQLITE_OK otherwise.
8610 pCDS->iVersionMadeBy = zipfileRead16(aRead); in zipfileReadCDS()
8611 pCDS->iVersionExtract = zipfileRead16(aRead); in zipfileReadCDS()
8612 pCDS->flags = zipfileRead16(aRead); in zipfileReadCDS()
8613 pCDS->iCompression = zipfileRead16(aRead); in zipfileReadCDS()
8614 pCDS->mTime = zipfileRead16(aRead); in zipfileReadCDS()
8615 pCDS->mDate = zipfileRead16(aRead); in zipfileReadCDS()
8616 pCDS->crc32 = zipfileRead32(aRead); in zipfileReadCDS()
8617 pCDS->szCompressed = zipfileRead32(aRead); in zipfileReadCDS()
8618 pCDS->szUncompressed = zipfileRead32(aRead); in zipfileReadCDS()
8620 pCDS->nFile = zipfileRead16(aRead); in zipfileReadCDS()
8621 pCDS->nExtra = zipfileRead16(aRead); in zipfileReadCDS()
8622 pCDS->nComment = zipfileRead16(aRead); in zipfileReadCDS()
8623 pCDS->iDiskStart = zipfileRead16(aRead); in zipfileReadCDS()
8624 pCDS->iInternalAttr = zipfileRead16(aRead); in zipfileReadCDS()
8625 pCDS->iExternalAttr = zipfileRead32(aRead); in zipfileReadCDS()
8626 pCDS->iOffset = zipfileRead32(aRead); in zipfileReadCDS()
8635 ** if the record is not well-formed, or SQLITE_OK otherwise.
8648 pLFH->iVersionExtract = zipfileRead16(aRead); in zipfileReadLFH()
8649 pLFH->flags = zipfileRead16(aRead); in zipfileReadLFH()
8650 pLFH->iCompression = zipfileRead16(aRead); in zipfileReadLFH()
8651 pLFH->mTime = zipfileRead16(aRead); in zipfileReadLFH()
8652 pLFH->mDate = zipfileRead16(aRead); in zipfileReadLFH()
8653 pLFH->crc32 = zipfileRead32(aRead); in zipfileReadLFH()
8654 pLFH->szCompressed = zipfileRead32(aRead); in zipfileReadLFH()
8655 pLFH->szUncompressed = zipfileRead32(aRead); in zipfileReadLFH()
8656 pLFH->nFile = zipfileRead16(aRead); in zipfileReadLFH()
8657 pLFH->nExtra = zipfileRead16(aRead); in zipfileReadLFH()
8665 ** Scan through this buffer to find an "extra-timestamp" field. If one
8666 ** exists, extract the 32-bit modification-timestamp from it and store
8669 ** Zero is returned if no extra-timestamp record could be found (and so
8670 ** *pmTime is left unchanged), or non-zero otherwise.
8690 if( b & 0x01 ){ /* 0x01 -> modtime is present */ in zipfileScanExtra()
8704 ** Convert the standard MS-DOS timestamp stored in the mTime and mDate
8705 ** fields of the CDS structure passed as the only argument to a 32-bit
8706 ** UNIX seconds-since-the-epoch timestamp. Return the result.
8708 ** "Standard" MS-DOS time format:
8711 ** Bits 00-04: seconds divided by 2
8712 ** Bits 05-10: minute
8713 ** Bits 11-15: hour
8715 ** Bits 00-04: day
8716 ** Bits 05-08: month (1-12)
8717 ** Bits 09-15: years from 1980
8719 ** https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx
8724 Y = (1980 + ((pCDS->mDate >> 9) & 0x7F)); in zipfileMtime()
8725 M = ((pCDS->mDate >> 5) & 0x0F); in zipfileMtime()
8726 D = (pCDS->mDate & 0x1F); in zipfileMtime()
8727 sec = (pCDS->mTime & 0x1F)*2; in zipfileMtime()
8728 min = (pCDS->mTime >> 5) & 0x3F; in zipfileMtime()
8729 hr = (pCDS->mTime >> 11) & 0x1F; in zipfileMtime()
8731 Y--; in zipfileMtime()
8737 B = 2 - A + (A/4); in zipfileMtime()
8738 JDsec = (i64)((X1 + X2 + D + B - 1524.5)*86400) + hr*3600 + min*60 + sec; in zipfileMtime()
8739 return (u32)(JDsec - (i64)24405875*(i64)8640); in zipfileMtime()
8755 A = (int)((JD - 1867216.25)/36524.25); in zipfileMtimeToDos()
8756 A = (int)(JD + 1 + A - (A/4)); in zipfileMtimeToDos()
8758 C = (int)((B - 122.1)/365.25); in zipfileMtimeToDos()
8760 E = (int)((B-D)/30.6001); in zipfileMtimeToDos()
8762 day = B - D - (int)(30.6001*E); in zipfileMtimeToDos()
8763 mon = (E<14 ? E-1 : E-13); in zipfileMtimeToDos()
8764 yr = mon>2 ? C-4716 : C-4715; in zipfileMtimeToDos()
8771 pCds->mDate = (u16)(day + (mon << 5) + ((yr-1980) << 9)); in zipfileMtimeToDos()
8772 pCds->mTime = (u16)(sec/2 + (min<<5) + (hr<<11)); in zipfileMtimeToDos()
8774 pCds->mDate = pCds->mTime = 0; in zipfileMtimeToDos()
8779 || ((mUnixTime % 2) && mUnixTime-1==zipfileMtime(pCds)) in zipfileMtimeToDos()
8787 ** then pFile is a file-handle open on a zip file. In either case, this
8797 const u8 *aBlob, /* Pointer to in-memory file image */ in zipfileGetEntry()
8804 char **pzErr = &pTab->base.zErrMsg; in zipfileGetEntry()
8809 aRead = pTab->aBuffer; in zipfileGetEntry()
8833 rc = zipfileReadCDS(aRead, &pNew->cds); in zipfileGetEntry()
8846 u32 *pt = &pNew->mUnixTime; in zipfileGetEntry()
8847 pNew->cds.zFile = sqlite3_mprintf("%.*s", nFile, aRead); in zipfileGetEntry()
8848 pNew->aExtra = (u8*)&pNew[1]; in zipfileGetEntry()
8849 memcpy(pNew->aExtra, &aRead[nFile], nExtra); in zipfileGetEntry()
8850 if( pNew->cds.zFile==0 ){ in zipfileGetEntry()
8852 }else if( 0==zipfileScanExtra(&aRead[nFile], pNew->cds.nExtra, pt) ){ in zipfileGetEntry()
8853 pNew->mUnixTime = zipfileMtime(&pNew->cds); in zipfileGetEntry()
8861 rc = zipfileReadData(pFile, aRead, szFix, pNew->cds.iOffset, pzErr); in zipfileGetEntry()
8863 aRead = (u8*)&aBlob[pNew->cds.iOffset]; in zipfileGetEntry()
8868 pNew->iDataOff = pNew->cds.iOffset + ZIPFILE_LFH_FIXED_SZ; in zipfileGetEntry()
8869 pNew->iDataOff += lfh.nFile + lfh.nExtra; in zipfileGetEntry()
8870 if( aBlob && pNew->cds.szCompressed ){ in zipfileGetEntry()
8871 pNew->aData = &pNew->aExtra[nExtra]; in zipfileGetEntry()
8872 memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed); in zipfileGetEntry()
8876 (int)pNew->cds.iOffset in zipfileGetEntry()
8898 if( pCsr->pFile ){ in zipfileNext()
8899 i64 iEof = pCsr->eocd.iOffset + pCsr->eocd.nSize; in zipfileNext()
8900 zipfileEntryFree(pCsr->pCurrent); in zipfileNext()
8901 pCsr->pCurrent = 0; in zipfileNext()
8902 if( pCsr->iNextOff>=iEof ){ in zipfileNext()
8903 pCsr->bEof = 1; in zipfileNext()
8906 ZipfileTab *pTab = (ZipfileTab*)(cur->pVtab); in zipfileNext()
8907 rc = zipfileGetEntry(pTab, 0, 0, pCsr->pFile, pCsr->iNextOff, &p); in zipfileNext()
8909 pCsr->iNextOff += ZIPFILE_CDS_FIXED_SZ; in zipfileNext()
8910 pCsr->iNextOff += (int)p->cds.nExtra + p->cds.nFile + p->cds.nComment; in zipfileNext()
8912 pCsr->pCurrent = p; in zipfileNext()
8915 if( !pCsr->bNoop ){ in zipfileNext()
8916 pCsr->pCurrent = pCsr->pCurrent->pNext; in zipfileNext()
8918 if( pCsr->pCurrent==0 ){ in zipfileNext()
8919 pCsr->bEof = 1; in zipfileNext()
8923 pCsr->bNoop = 0; in zipfileNext()
8957 err = inflateInit2(&str, -15); in zipfileInflate()
8982 ** code is returned and an error message left in virtual-table handle
8999 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); in zipfileDeflate()
9035 ZipfileCDS *pCDS = &pCsr->pCurrent->cds; in zipfileColumn()
9039 sqlite3_result_text(ctx, pCDS->zFile, -1, SQLITE_TRANSIENT); in zipfileColumn()
9044 sqlite3_result_int(ctx, pCDS->iExternalAttr >> 16); in zipfileColumn()
9047 sqlite3_result_int64(ctx, pCsr->pCurrent->mUnixTime); in zipfileColumn()
9052 sqlite3_result_int64(ctx, pCDS->szUncompressed); in zipfileColumn()
9059 if( i==4 || pCDS->iCompression==0 || pCDS->iCompression==8 ){ in zipfileColumn()
9060 int sz = pCDS->szCompressed; in zipfileColumn()
9061 int szFinal = pCDS->szUncompressed; in zipfileColumn()
9065 if( pCsr->pCurrent->aData ){ in zipfileColumn()
9066 aBuf = pCsr->pCurrent->aData; in zipfileColumn()
9072 FILE *pFile = pCsr->pFile; in zipfileColumn()
9074 pFile = ((ZipfileTab*)(pCsr->base.pVtab))->pWriteFd; in zipfileColumn()
9076 rc = zipfileReadData(pFile, aBuf, sz, pCsr->pCurrent->iDataOff, in zipfileColumn()
9077 &pCsr->base.pVtab->zErrMsg in zipfileColumn()
9082 if( i==5 && pCDS->iCompression ){ in zipfileColumn()
9090 /* Figure out if this is a directory or a zero-sized file. Consider in zipfileColumn()
9093 u32 mode = pCDS->iExternalAttr >> 16; in zipfileColumn()
9095 && pCDS->nFile>=1 in zipfileColumn()
9096 && pCDS->zFile[pCDS->nFile-1]!='/' in zipfileColumn()
9105 sqlite3_result_int(ctx, pCDS->iCompression); in zipfileColumn()
9109 sqlite3_result_int64(ctx, pCsr->iId); in zipfileColumn()
9121 return pCsr->bEof; in zipfileEof()
9127 ** is guaranteed to be a file-handle open on a zip file.
9132 ** an English language error message may be left in virtual-table pTab.
9136 const u8 *aBlob, /* Pointer to in-memory file image */ in zipfileReadEOCD()
9141 u8 *aRead = pTab->aBuffer; /* Temporary buffer */ in zipfileReadEOCD()
9155 iOff = szFile - nRead; in zipfileReadEOCD()
9156 rc = zipfileReadData(pFile, aRead, nRead, iOff, &pTab->base.zErrMsg); in zipfileReadEOCD()
9159 aRead = (u8*)&aBlob[nBlob-nRead]; in zipfileReadEOCD()
9166 for(i=nRead-20; i>=0; i--){ in zipfileReadEOCD()
9174 pTab->base.zErrMsg = sqlite3_mprintf( in zipfileReadEOCD()
9181 pEOCD->iDisk = zipfileRead16(aRead); in zipfileReadEOCD()
9182 pEOCD->iFirstDisk = zipfileRead16(aRead); in zipfileReadEOCD()
9183 pEOCD->nEntry = zipfileRead16(aRead); in zipfileReadEOCD()
9184 pEOCD->nEntryTotal = zipfileRead16(aRead); in zipfileReadEOCD()
9185 pEOCD->nSize = zipfileRead32(aRead); in zipfileReadEOCD()
9186 pEOCD->iOffset = zipfileRead32(aRead); in zipfileReadEOCD()
9203 assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) ); in zipfileAddEntry()
9204 assert( pNew->pNext==0 ); in zipfileAddEntry()
9206 if( pTab->pFirstEntry==0 ){ in zipfileAddEntry()
9207 pTab->pFirstEntry = pTab->pLastEntry = pNew; in zipfileAddEntry()
9209 assert( pTab->pLastEntry->pNext==0 ); in zipfileAddEntry()
9210 pTab->pLastEntry->pNext = pNew; in zipfileAddEntry()
9211 pTab->pLastEntry = pNew; in zipfileAddEntry()
9215 for(pp=&pTab->pFirstEntry; *pp!=pBefore; pp=&((*pp)->pNext)); in zipfileAddEntry()
9216 pNew->pNext = pBefore; in zipfileAddEntry()
9227 rc = zipfileReadEOCD(pTab, aBlob, nBlob, pTab->pWriteFd, &eocd); in zipfileLoadDirectory()
9231 rc = zipfileGetEntry(pTab, aBlob, nBlob, pTab->pWriteFd, iOff, &pNew); in zipfileLoadDirectory()
9236 iOff += (int)pNew->cds.nExtra + pNew->cds.nFile + pNew->cds.nComment; in zipfileLoadDirectory()
9250 ZipfileTab *pTab = (ZipfileTab*)cur->pVtab; in zipfileFilter()
9254 int bInMemory = 0; /* True for an in-memory zipfile */ in zipfileFilter()
9261 if( pTab->zFile ){ in zipfileFilter()
9262 zFile = pTab->zFile; in zipfileFilter()
9270 assert( pTab->pFirstEntry==0 ); in zipfileFilter()
9276 pCsr->pFreeEntry = pTab->pFirstEntry; in zipfileFilter()
9277 pTab->pFirstEntry = pTab->pLastEntry = 0; in zipfileFilter()
9284 if( 0==pTab->pWriteFd && 0==bInMemory ){ in zipfileFilter()
9285 pCsr->pFile = zFile ? fopen(zFile, "rb") : 0; in zipfileFilter()
9286 if( pCsr->pFile==0 ){ in zipfileFilter()
9290 rc = zipfileReadEOCD(pTab, 0, 0, pCsr->pFile, &pCsr->eocd); in zipfileFilter()
9292 if( pCsr->eocd.nEntry==0 ){ in zipfileFilter()
9293 pCsr->bEof = 1; in zipfileFilter()
9295 pCsr->iNextOff = pCsr->eocd.iOffset; in zipfileFilter()
9301 pCsr->bNoop = 1; in zipfileFilter()
9302 pCsr->pCurrent = pCsr->pFreeEntry ? pCsr->pFreeEntry : pTab->pFirstEntry; in zipfileFilter()
9317 int idx = -1; in zipfileBestIndex()
9321 for(i=0; i<pIdxInfo->nConstraint; i++){ in zipfileBestIndex()
9322 const struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i]; in zipfileBestIndex()
9323 if( pCons->iColumn!=ZIPFILE_F_COLUMN_IDX ) continue; in zipfileBestIndex()
9324 if( pCons->usable==0 ){ in zipfileBestIndex()
9326 }else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){ in zipfileBestIndex()
9330 pIdxInfo->estimatedCost = 1000.0; in zipfileBestIndex()
9332 pIdxInfo->aConstraintUsage[idx].argvIndex = 1; in zipfileBestIndex()
9333 pIdxInfo->aConstraintUsage[idx].omit = 1; in zipfileBestIndex()
9334 pIdxInfo->idxNum = 1; in zipfileBestIndex()
9346 pNew->cds.zFile = sqlite3_mprintf("%s", zPath); in zipfileNewEntry()
9347 if( pNew->cds.zFile==0 ){ in zipfileNewEntry()
9356 ZipfileCDS *pCds = &pEntry->cds; in zipfileSerializeLFH()
9359 pCds->nExtra = 9; in zipfileSerializeLFH()
9363 zipfileWrite16(a, pCds->iVersionExtract); in zipfileSerializeLFH()
9364 zipfileWrite16(a, pCds->flags); in zipfileSerializeLFH()
9365 zipfileWrite16(a, pCds->iCompression); in zipfileSerializeLFH()
9366 zipfileWrite16(a, pCds->mTime); in zipfileSerializeLFH()
9367 zipfileWrite16(a, pCds->mDate); in zipfileSerializeLFH()
9368 zipfileWrite32(a, pCds->crc32); in zipfileSerializeLFH()
9369 zipfileWrite32(a, pCds->szCompressed); in zipfileSerializeLFH()
9370 zipfileWrite32(a, pCds->szUncompressed); in zipfileSerializeLFH()
9371 zipfileWrite16(a, (u16)pCds->nFile); in zipfileSerializeLFH()
9372 zipfileWrite16(a, pCds->nExtra); in zipfileSerializeLFH()
9376 memcpy(a, pCds->zFile, (int)pCds->nFile); in zipfileSerializeLFH()
9377 a += (int)pCds->nFile; in zipfileSerializeLFH()
9383 zipfileWrite32(a, pEntry->mUnixTime); in zipfileSerializeLFH()
9385 return a-aBuf; in zipfileSerializeLFH()
9394 u8 *aBuf = pTab->aBuffer; in zipfileAppendEntry()
9401 pEntry->iDataOff = pTab->szCurrent; in zipfileAppendEntry()
9421 const char zTemplate[11] = "-rwxrwxrwx"; in zipfileGetMode()
9425 case '-': mode |= S_IFREG; break; in zipfileGetMode()
9431 if( z[i]==zTemplate[i] ) mode |= 1 << (9-i); in zipfileGetMode()
9432 else if( z[i]!='-' ) goto parse_error; in zipfileGetMode()
9437 ** Or vice-versa - no data but "mode" is a file or symlink. */ in zipfileGetMode()
9450 ** Both (const char*) arguments point to nul-terminated strings. Argument
9455 if( nA>0 && zA[nA-1]=='/' ) nA--; in zipfileComparePath()
9456 if( nB>0 && zB[nB-1]=='/' ) nB--; in zipfileComparePath()
9465 assert( pTab->pWriteFd==0 ); in zipfileBegin()
9466 if( pTab->zFile==0 || pTab->zFile[0]==0 ){ in zipfileBegin()
9467 pTab->base.zErrMsg = sqlite3_mprintf("zipfile: missing filename"); in zipfileBegin()
9474 ** in main-memory until the transaction is committed. */ in zipfileBegin()
9475 pTab->pWriteFd = fopen(pTab->zFile, "ab+"); in zipfileBegin()
9476 if( pTab->pWriteFd==0 ){ in zipfileBegin()
9477 pTab->base.zErrMsg = sqlite3_mprintf( in zipfileBegin()
9478 "zipfile: failed to open file %s for writing", pTab->zFile in zipfileBegin()
9482 fseek(pTab->pWriteFd, 0, SEEK_END); in zipfileBegin()
9483 pTab->szCurrent = pTab->szOrig = (i64)ftell(pTab->pWriteFd); in zipfileBegin()
9495 ** Return the current time as a 32-bit timestamp in UNIX epoch format (like
9502 if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){ in zipfileTime()
9504 pVfs->xCurrentTimeInt64(pVfs, &ms); in zipfileTime()
9505 ret = (u32)((ms/1000) - ((i64)24405875 * 8640)); in zipfileTime()
9508 pVfs->xCurrentTime(pVfs, &day); in zipfileTime()
9509 ret = (u32)((day - 2440587.5) * 86400); in zipfileTime()
9515 ** Return a 32-bit timestamp in UNIX epoch format.
9519 ** cast to a 32-bit unsigned integer.
9529 ** Unless it is NULL, entry pOld is currently part of the pTab->pFirstEntry
9534 if( pTab->pFirstEntry==pOld ){ in zipfileRemoveEntryFromList()
9535 pTab->pFirstEntry = pOld->pNext; in zipfileRemoveEntryFromList()
9536 if( pTab->pLastEntry==pOld ) pTab->pLastEntry = 0; in zipfileRemoveEntryFromList()
9539 for(p=pTab->pFirstEntry; p; p=p->pNext){ in zipfileRemoveEntryFromList()
9540 if( p->pNext==pOld ){ in zipfileRemoveEntryFromList()
9541 p->pNext = pOld->pNext; in zipfileRemoveEntryFromList()
9542 if( pTab->pLastEntry==pOld ) pTab->pLastEntry = p; in zipfileRemoveEntryFromList()
9562 ZipfileEntry *pNew = 0; /* New in-memory CDS entry */ in zipfileUpdate()
9582 if( pTab->pWriteFd==0 ){ in zipfileUpdate()
9597 for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){ in zipfileUpdate()
9598 if( zipfileComparePath(pOld->cds.zFile, zDelete, nDelete)==0 ){ in zipfileUpdate()
9601 assert( pOld->pNext ); in zipfileUpdate()
9637 rc = zipfileDeflate(aIn, nIn, &pFree, &nCmp, &pTab->base.zErrMsg); in zipfileUpdate()
9652 rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg); in zipfileUpdate()
9664 ** '/'. This appears to be required for compatibility with info-zip in zipfileUpdate()
9667 if( nPath<=0 || zPath[nPath-1]!='/' ){ in zipfileUpdate()
9679 /* Check that we're not inserting a duplicate entry -OR- updating an in zipfileUpdate()
9683 for(p=pTab->pFirstEntry; p; p=p->pNext){ in zipfileUpdate()
9684 if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){ in zipfileUpdate()
9685 switch( sqlite3_vtab_on_conflict(pTab->db) ){ in zipfileUpdate()
9710 pNew->cds.iVersionMadeBy = ZIPFILE_NEWENTRY_MADEBY; in zipfileUpdate()
9711 pNew->cds.iVersionExtract = ZIPFILE_NEWENTRY_REQUIRED; in zipfileUpdate()
9712 pNew->cds.flags = ZIPFILE_NEWENTRY_FLAGS; in zipfileUpdate()
9713 pNew->cds.iCompression = (u16)iMethod; in zipfileUpdate()
9714 zipfileMtimeToDos(&pNew->cds, mTime); in zipfileUpdate()
9715 pNew->cds.crc32 = iCrc32; in zipfileUpdate()
9716 pNew->cds.szCompressed = nData; in zipfileUpdate()
9717 pNew->cds.szUncompressed = (u32)sz; in zipfileUpdate()
9718 pNew->cds.iExternalAttr = (mode<<16); in zipfileUpdate()
9719 pNew->cds.iOffset = (u32)pTab->szCurrent; in zipfileUpdate()
9720 pNew->cds.nFile = (u16)nPath; in zipfileUpdate()
9721 pNew->mUnixTime = (u32)mTime; in zipfileUpdate()
9730 for(pCsr=pTab->pCsrList; pCsr; pCsr=pCsr->pCsrNext){ in zipfileUpdate()
9731 if( pCsr->pCurrent && (pCsr->pCurrent==pOld || pCsr->pCurrent==pOld2) ){ in zipfileUpdate()
9732 pCsr->pCurrent = pCsr->pCurrent->pNext; in zipfileUpdate()
9733 pCsr->bNoop = 1; in zipfileUpdate()
9750 zipfileWrite16(a, p->iDisk); in zipfileSerializeEOCD()
9751 zipfileWrite16(a, p->iFirstDisk); in zipfileSerializeEOCD()
9752 zipfileWrite16(a, p->nEntry); in zipfileSerializeEOCD()
9753 zipfileWrite16(a, p->nEntryTotal); in zipfileSerializeEOCD()
9754 zipfileWrite32(a, p->nSize); in zipfileSerializeEOCD()
9755 zipfileWrite32(a, p->iOffset); in zipfileSerializeEOCD()
9758 return a-aBuf; in zipfileSerializeEOCD()
9762 int nBuf = zipfileSerializeEOCD(p, pTab->aBuffer); in zipfileAppendEOCD()
9764 return zipfileAppendData(pTab, pTab->aBuffer, nBuf); in zipfileAppendEOCD()
9773 ZipfileCDS *pCDS = &pEntry->cds; in zipfileSerializeCDS()
9775 if( pEntry->aExtra==0 ){ in zipfileSerializeCDS()
9776 pCDS->nExtra = 9; in zipfileSerializeCDS()
9780 zipfileWrite16(a, pCDS->iVersionMadeBy); in zipfileSerializeCDS()
9781 zipfileWrite16(a, pCDS->iVersionExtract); in zipfileSerializeCDS()
9782 zipfileWrite16(a, pCDS->flags); in zipfileSerializeCDS()
9783 zipfileWrite16(a, pCDS->iCompression); in zipfileSerializeCDS()
9784 zipfileWrite16(a, pCDS->mTime); in zipfileSerializeCDS()
9785 zipfileWrite16(a, pCDS->mDate); in zipfileSerializeCDS()
9786 zipfileWrite32(a, pCDS->crc32); in zipfileSerializeCDS()
9787 zipfileWrite32(a, pCDS->szCompressed); in zipfileSerializeCDS()
9788 zipfileWrite32(a, pCDS->szUncompressed); in zipfileSerializeCDS()
9790 zipfileWrite16(a, pCDS->nFile); in zipfileSerializeCDS()
9791 zipfileWrite16(a, pCDS->nExtra); in zipfileSerializeCDS()
9792 zipfileWrite16(a, pCDS->nComment); in zipfileSerializeCDS()
9793 zipfileWrite16(a, pCDS->iDiskStart); in zipfileSerializeCDS()
9794 zipfileWrite16(a, pCDS->iInternalAttr); in zipfileSerializeCDS()
9795 zipfileWrite32(a, pCDS->iExternalAttr); in zipfileSerializeCDS()
9796 zipfileWrite32(a, pCDS->iOffset); in zipfileSerializeCDS()
9798 memcpy(a, pCDS->zFile, pCDS->nFile); in zipfileSerializeCDS()
9799 a += pCDS->nFile; in zipfileSerializeCDS()
9801 if( pEntry->aExtra ){ in zipfileSerializeCDS()
9802 int n = (int)pCDS->nExtra + (int)pCDS->nComment; in zipfileSerializeCDS()
9803 memcpy(a, pEntry->aExtra, n); in zipfileSerializeCDS()
9806 assert( pCDS->nExtra==9 ); in zipfileSerializeCDS()
9810 zipfileWrite32(a, pEntry->mUnixTime); in zipfileSerializeCDS()
9813 return a-aBuf; in zipfileSerializeCDS()
9819 if( pTab->pWriteFd ){ in zipfileCommit()
9820 i64 iOffset = pTab->szCurrent; in zipfileCommit()
9826 for(p=pTab->pFirstEntry; rc==SQLITE_OK && p; p=p->pNext){ in zipfileCommit()
9827 int n = zipfileSerializeCDS(p, pTab->aBuffer); in zipfileCommit()
9828 rc = zipfileAppendData(pTab, pTab->aBuffer, n); in zipfileCommit()
9837 eocd.nSize = (u32)(pTab->szCurrent - iOffset); in zipfileCommit()
9852 for(pCsr=pTab->pCsrList; pCsr; pCsr=pCsr->pCsrNext){ in zipfileFindCursor()
9853 if( iId==pCsr->iId ) break; in zipfileFindCursor()
9869 ZipfileCDS *p = &pCsr->pCurrent->cds; in zipfileFunctionCds()
9871 "\"version-made-by\" : %u, " in zipfileFunctionCds()
9872 "\"version-to-extract\" : %u, " in zipfileFunctionCds()
9878 "\"compressed-size\" : %u, " in zipfileFunctionCds()
9879 "\"uncompressed-size\" : %u, " in zipfileFunctionCds()
9880 "\"file-name-length\" : %u, " in zipfileFunctionCds()
9881 "\"extra-field-length\" : %u, " in zipfileFunctionCds()
9882 "\"file-comment-length\" : %u, " in zipfileFunctionCds()
9883 "\"disk-number-start\" : %u, " in zipfileFunctionCds()
9884 "\"internal-attr\" : %u, " in zipfileFunctionCds()
9885 "\"external-attr\" : %u, " in zipfileFunctionCds()
9887 (u32)p->iVersionMadeBy, (u32)p->iVersionExtract, in zipfileFunctionCds()
9888 (u32)p->flags, (u32)p->iCompression, in zipfileFunctionCds()
9889 (u32)p->mTime, (u32)p->mDate, in zipfileFunctionCds()
9890 (u32)p->crc32, (u32)p->szCompressed, in zipfileFunctionCds()
9891 (u32)p->szUncompressed, (u32)p->nFile, in zipfileFunctionCds()
9892 (u32)p->nExtra, (u32)p->nComment, in zipfileFunctionCds()
9893 (u32)p->iDiskStart, (u32)p->iInternalAttr, in zipfileFunctionCds()
9894 (u32)p->iExternalAttr, (u32)p->iOffset in zipfileFunctionCds()
9900 sqlite3_result_text(context, zRes, -1, SQLITE_TRANSIENT); in zipfileFunctionCds()
9940 if( pBuf->n+nByte>pBuf->nAlloc ){ in zipfileBufferGrow()
9942 sqlite3_int64 nNew = pBuf->n ? pBuf->n*2 : 512; in zipfileBufferGrow()
9943 int nReq = pBuf->n + nByte; in zipfileBufferGrow()
9946 aNew = sqlite3_realloc64(pBuf->a, nNew); in zipfileBufferGrow()
9948 pBuf->a = aNew; in zipfileBufferGrow()
9949 pBuf->nAlloc = (int)nNew; in zipfileBufferGrow()
9977 int iMethod = -1; /* Compression method to use (0 or 8) */ in zipfileStep()
10016 zErr = sqlite3_mprintf("first argument to zipfile() must be non-NULL"); in zipfileStep()
10069 if( nName>0 && zName[nName-1]=='/' ){ in zipfileStep()
10070 zErr = sqlite3_mprintf("non-directory name must not end with /"); in zipfileStep()
10075 if( nName==0 || zName[nName-1]!='/' ){ in zipfileStep()
10083 while( nName>1 && zName[nName-2]=='/' ) nName--; in zipfileStep()
10097 e.cds.iOffset = p->body.n; in zipfileStep()
10103 if( (rc = zipfileBufferGrow(&p->body, nByte)) ) goto zipfile_step_out; in zipfileStep()
10104 p->body.n += zipfileSerializeLFH(&e, &p->body.a[p->body.n]); in zipfileStep()
10108 if( (rc = zipfileBufferGrow(&p->body, nData)) ) goto zipfile_step_out; in zipfileStep()
10109 memcpy(&p->body.a[p->body.n], aData, nData); in zipfileStep()
10110 p->body.n += nData; in zipfileStep()
10115 if( (rc = zipfileBufferGrow(&p->cds, nByte)) ) goto zipfile_step_out; in zipfileStep()
10116 p->cds.n += zipfileSerializeCDS(&e, &p->cds.a[p->cds.n]); in zipfileStep()
10119 p->nEntry++; in zipfileStep()
10126 sqlite3_result_error(pCtx, zErr, -1); in zipfileStep()
10145 if( p->nEntry>0 ){ in zipfileFinal()
10147 eocd.nEntry = (u16)p->nEntry; in zipfileFinal()
10148 eocd.nEntryTotal = (u16)p->nEntry; in zipfileFinal()
10149 eocd.nSize = p->cds.n; in zipfileFinal()
10150 eocd.iOffset = p->body.n; in zipfileFinal()
10152 nZip = p->body.n + p->cds.n + ZIPFILE_EOCD_FIXED_SZ; in zipfileFinal()
10157 memcpy(aZip, p->body.a, p->body.n); in zipfileFinal()
10158 memcpy(&aZip[p->body.n], p->cds.a, p->cds.n); in zipfileFinal()
10159 zipfileSerializeEOCD(&eocd, &aZip[p->body.n + p->cds.n]); in zipfileFinal()
10164 sqlite3_free(p->body.a); in zipfileFinal()
10165 sqlite3_free(p->cds.a); in zipfileFinal()
10180 zipfileOpen, /* xOpen - open a cursor */ in zipfileRegister()
10181 zipfileClose, /* xClose - close a cursor */ in zipfileRegister()
10182 zipfileFilter, /* xFilter - configure scan constraints */ in zipfileRegister()
10183 zipfileNext, /* xNext - advance a cursor */ in zipfileRegister()
10184 zipfileEof, /* xEof - check for end of scan */ in zipfileRegister()
10185 zipfileColumn, /* xColumn - read data */ in zipfileRegister()
10186 0, /* xRowid - read data */ in zipfileRegister()
10201 if( rc==SQLITE_OK ) rc = sqlite3_overload_function(db, "zipfile_cds", -1); in zipfileRegister()
10203 rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0, in zipfileRegister()
10233 ** 2017-12-17
10245 ** for working with sqlar archives and used by the shell tool's built-in
10261 ** contains a two-byte identification header and a four-byte checksum at
10286 sqlite3_result_error(context, "error in compress()", -1); in sqlarCompressFunc()
10328 sqlite3_result_error(context, "error in uncompress()", -1); in sqlarUncompressFunc()
10384 ** an English-language error message. In this case it is the responsibility
10404 ** the analysis - indexes are recommended based on the database schema only.
10428 ** is returned and (*pzErr) set to NULL. Or, if an error occurs - for example
10429 ** due to a error in the SQL - an SQLite error code is returned and (*pzErr)
10464 ** possible to add further SQL statements to the object or to re-attempt
10482 ** NULL pointer or a pointer to a buffer containing a nul-terminated string.
10490 ** If an out-of-range value (less than zero or equal to or greater than the
10524 ** sqlite3-expert_new().
10589 ** any other type of single-ended range constraint on a column).
10635 ** An object of the following type is created for each unique table/write-op
10636 ** seen. The objects are stored in a singly-linked list beginning at
10671 char *zKey; /* nul-terminated key */
10672 char *zVal; /* nul-terminated value string */
10673 char *zVal2; /* nul-terminated value string 2 */
10688 sqlite3 *dbm; /* In-memory db for this analysis */
10734 for(pEntry=pHash->aHash[i]; pEntry; pEntry=pNext){ in idxHashClear()
10735 pNext = pEntry->pHashNext; in idxHashClear()
10736 sqlite3_free(pEntry->zVal2); in idxHashClear()
10757 ** If zKey is already present in the hash table, return non-zero and do
10772 for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){ in idxHashAdd()
10773 if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){ in idxHashAdd()
10779 pEntry->zKey = (char*)&pEntry[1]; in idxHashAdd()
10780 memcpy(pEntry->zKey, zKey, nKey); in idxHashAdd()
10782 pEntry->zVal = &pEntry->zKey[nKey+1]; in idxHashAdd()
10783 memcpy(pEntry->zVal, zVal, nVal); in idxHashAdd()
10785 pEntry->pHashNext = pHash->aHash[iHash]; in idxHashAdd()
10786 pHash->aHash[iHash] = pEntry; in idxHashAdd()
10788 pEntry->pNext = pHash->pFirst; in idxHashAdd()
10789 pHash->pFirst = pEntry; in idxHashAdd()
10796 ** hash-entry object.
10804 for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){ in idxHashFind()
10805 if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){ in idxHashFind()
10820 if( pEntry ) return pEntry->zVal; in idxHashSearch()
10826 ** variable to point to a copy of nul-terminated string zColl.
10835 pNew->zColl = (char*)&pNew[1]; in idxNewConstraint()
10836 memcpy(pNew->zColl, zColl, nColl+1); in idxNewConstraint()
10861 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0); in idxPrepareStmt()
10916 assert( zIn[n-1]=='\'' ); in expertDequote()
10921 for(iIn=1; iIn<(n-1); iIn++){ in expertDequote()
10936 ** methods of the r-tree virtual table.
10938 ** argv[0] -> module name
10939 ** argv[1] -> database name
10940 ** argv[2] -> table name
10941 ** argv[...] -> column names...
10965 p->pExpert = pExpert; in expertConnect()
10966 p->pTab = pExpert->pTable; in expertConnect()
10967 assert( sqlite3_stricmp(p->pTab->zName, argv[2])==0 ); in expertConnect()
11000 pScan->pTab = p->pTab; in expertBestIndex()
11001 pScan->pNextScan = p->pExpert->pScan; in expertBestIndex()
11002 p->pExpert->pScan = pScan; in expertBestIndex()
11005 for(i=0; i<pIdxInfo->nConstraint; i++){ in expertBestIndex()
11006 struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i]; in expertBestIndex()
11007 if( pCons->usable in expertBestIndex()
11008 && pCons->iColumn>=0 in expertBestIndex()
11009 && p->pTab->aCol[pCons->iColumn].iPk==0 in expertBestIndex()
11010 && (pCons->op & opmask) in expertBestIndex()
11016 pNew->iCol = pCons->iColumn; in expertBestIndex()
11017 if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){ in expertBestIndex()
11018 pNew->pNext = pScan->pEq; in expertBestIndex()
11019 pScan->pEq = pNew; in expertBestIndex()
11021 pNew->bRange = 1; in expertBestIndex()
11022 pNew->pNext = pScan->pRange; in expertBestIndex()
11023 pScan->pRange = pNew; in expertBestIndex()
11027 pIdxInfo->aConstraintUsage[i].argvIndex = n; in expertBestIndex()
11032 for(i=pIdxInfo->nOrderBy-1; i>=0; i--){ in expertBestIndex()
11033 int iCol = pIdxInfo->aOrderBy[i].iColumn; in expertBestIndex()
11035 IdxConstraint *pNew = idxNewConstraint(&rc, p->pTab->aCol[iCol].zColl); in expertBestIndex()
11037 pNew->iCol = iCol; in expertBestIndex()
11038 pNew->bDesc = pIdxInfo->aOrderBy[i].desc; in expertBestIndex()
11039 pNew->pNext = pScan->pOrder; in expertBestIndex()
11040 pNew->pLink = pScan->pOrder; in expertBestIndex()
11041 pScan->pOrder = pNew; in expertBestIndex()
11048 pIdxInfo->estimatedCost = 1000000.0 / (n+1); in expertBestIndex()
11082 sqlite3_finalize(pCsr->pData); in expertClose()
11090 ** Return non-zero if the cursor does not currently point to a valid
11095 return pCsr->pData==0; in expertEof()
11105 assert( pCsr->pData ); in expertNext()
11106 rc = sqlite3_step(pCsr->pData); in expertNext()
11108 rc = sqlite3_finalize(pCsr->pData); in expertNext()
11109 pCsr->pData = 0; in expertNext()
11132 pVal = sqlite3_column_value(pCsr->pData, i); in expertColumn()
11148 ExpertVtab *pVtab = (ExpertVtab*)(cur->pVtab); in expertFilter()
11149 sqlite3expert *pExpert = pVtab->pExpert; in expertFilter()
11156 rc = sqlite3_finalize(pCsr->pData); in expertFilter()
11157 pCsr->pData = 0; in expertFilter()
11159 rc = idxPrintfPrepareStmt(pExpert->db, &pCsr->pData, &pVtab->base.zErrMsg, in expertFilter()
11160 "SELECT * FROM main.%Q WHERE sample()", pVtab->pTab->zName in expertFilter()
11173 expertConnect, /* xCreate - create a table */ in idxRegisterVtab()
11174 expertConnect, /* xConnect - connect to an existing table */ in idxRegisterVtab()
11175 expertBestIndex, /* xBestIndex - Determine search strategy */ in idxRegisterVtab()
11176 expertDisconnect, /* xDisconnect - Disconnect from a table */ in idxRegisterVtab()
11177 expertDisconnect, /* xDestroy - Drop a table */ in idxRegisterVtab()
11178 expertOpen, /* xOpen - open a cursor */ in idxRegisterVtab()
11179 expertClose, /* xClose - close a cursor */ in idxRegisterVtab()
11180 expertFilter, /* xFilter - configure scan constraints */ in idxRegisterVtab()
11181 expertNext, /* xNext - advance a cursor */ in idxRegisterVtab()
11183 expertColumn, /* xColumn - read data */ in idxRegisterVtab()
11184 expertRowid, /* xRowid - read data */ in idxRegisterVtab()
11185 expertUpdate, /* xUpdate - write data */ in idxRegisterVtab()
11186 0, /* xBegin - begin transaction */ in idxRegisterVtab()
11187 0, /* xSync - sync transaction */ in idxRegisterVtab()
11188 0, /* xCommit - commit transaction */ in idxRegisterVtab()
11189 0, /* xRollback - rollback transaction */ in idxRegisterVtab()
11190 0, /* xFindFunction - function overloading */ in idxRegisterVtab()
11191 0, /* xRename - rename the table */ in idxRegisterVtab()
11198 return sqlite3_create_module(p->dbv, "expert", &expertModule, (void*)p); in idxRegisterVtab()
11267 pNew->aCol = (IdxColumn*)&pNew[1]; in idxGetTableInfo()
11268 pNew->nCol = nCol; in idxGetTableInfo()
11269 pCsr = (char*)&pNew->aCol[nCol]; in idxGetTableInfo()
11279 pNew->aCol[nCol].zName = pCsr; in idxGetTableInfo()
11280 pNew->aCol[nCol].iPk = (sqlite3_column_int(p1, 5)==1 && nPk==1); in idxGetTableInfo()
11290 pNew->aCol[nCol].zColl = pCsr; in idxGetTableInfo()
11303 pNew->zName = pCsr; in idxGetTableInfo()
11304 if( ALWAYS(pNew->zName!=0) ) memcpy(pNew->zName, zTab, nTab+1); in idxGetTableInfo()
11312 ** This function is a no-op if *pRc is set to anything other than
11381 IdxColumn *p = &pTab->aCol[pCons->iCol]; in idxAppendColDefn()
11384 if( idxIdentifierRequiresQuotes(p->zName) ){ in idxAppendColDefn()
11385 zRet = idxAppendText(pRc, zRet, "%Q", p->zName); in idxAppendColDefn()
11387 zRet = idxAppendText(pRc, zRet, "%s", p->zName); in idxAppendColDefn()
11390 if( sqlite3_stricmp(p->zColl, pCons->zColl) ){ in idxAppendColDefn()
11391 if( idxIdentifierRequiresQuotes(pCons->zColl) ){ in idxAppendColDefn()
11392 zRet = idxAppendText(pRc, zRet, " COLLATE %Q", pCons->zColl); in idxAppendColDefn()
11394 zRet = idxAppendText(pRc, zRet, " COLLATE %s", pCons->zColl); in idxAppendColDefn()
11398 if( pCons->bDesc ){ in idxAppendColDefn()
11407 ** such an index is found, return non-zero. Or, if no such index is found,
11419 const char *zTbl = pScan->pTab->zName; in idxFindCompatible()
11426 for(pIter=pEq; pIter; pIter=pIter->pLink) nEq++; in idxFindCompatible()
11437 for(pIter=pEq; pIter; pIter=pIter->pLink) pIter->bFlag = 0; in idxFindCompatible()
11446 for(pIter=pEq; pIter; pIter=pIter->pLink){ in idxFindCompatible()
11447 if( pIter->bFlag ) continue; in idxFindCompatible()
11448 if( pIter->iCol!=iCol ) continue; in idxFindCompatible()
11449 if( sqlite3_stricmp(pIter->zColl, zColl) ) continue; in idxFindCompatible()
11450 pIter->bFlag = 1; in idxFindCompatible()
11459 if( pT->iCol!=iCol || sqlite3_stricmp(pT->zColl, zColl) ){ in idxFindCompatible()
11463 pT = pT->pLink; in idxFindCompatible()
11499 sqlite3 *dbm = p->dbm; in idxCreateFromCons()
11502 IdxTable *pTab = pScan->pTab; in idxCreateFromCons()
11509 for(pCons=pEq; pCons; pCons=pCons->pLink){ in idxCreateFromCons()
11512 for(pCons=pTail; pCons; pCons=pCons->pLink){ in idxCreateFromCons()
11518 const char *zTable = pScan->pTab->zName; in idxCreateFromCons()
11560 rc = sqlite3_exec(dbm, zIdx, 0, 0, p->pzErrmsg); in idxCreateFromCons()
11564 idxHashAdd(&rc, &p->hIdx, zName, zIdx); in idxCreateFromCons()
11583 for(pCmp=pList; pCmp; pCmp=pCmp->pLink){ in idxFindConstraint()
11584 if( p->iCol==pCmp->iCol ) return 1; in idxFindConstraint()
11599 for(pCon=pScan->pEq; pCon; pCon=pCon->pNext){ in idxCreateFromWhere()
11601 pCon->pLink = p1; in idxCreateFromWhere()
11613 for(pCon=pScan->pRange; rc==SQLITE_OK && pCon; pCon=pCon->pNext){ in idxCreateFromWhere()
11614 assert( pCon->pLink==0 ); in idxCreateFromWhere()
11626 ** linked-list pScan.
11632 for(pIter=p->pScan; pIter && rc==SQLITE_OK; pIter=pIter->pNextScan){ in idxCreateCandidates()
11634 if( rc==SQLITE_OK && pIter->pOrder ){ in idxCreateCandidates()
11635 rc = idxCreateFromWhere(p, pIter, pIter->pOrder); in idxCreateCandidates()
11650 pNext = p->pNext; in idxConstraintFree()
11663 pNext = p->pNextScan; in idxScanFree()
11664 idxConstraintFree(p->pOrder); in idxScanFree()
11665 idxConstraintFree(p->pEq); in idxScanFree()
11666 idxConstraintFree(p->pRange); in idxScanFree()
11679 pNext = p->pNext; in idxStatementFree()
11680 sqlite3_free(p->zEQP); in idxStatementFree()
11681 sqlite3_free(p->zIdx); in idxStatementFree()
11693 pNext = pIter->pNext; in idxTableFree()
11705 pNext = pIter->pNext; in idxWriteFree()
11722 sqlite3 *dbm = p->dbm; in idxFindIndexes()
11728 for(pStmt=p->pStatement; rc==SQLITE_OK && pStmt; pStmt=pStmt->pNext){ in idxFindIndexes()
11733 "EXPLAIN QUERY PLAN %s", pStmt->zSql in idxFindIndexes()
11761 zSql = idxHashSearch(&p->hIdx, zIdx, nIdx); in idxFindIndexes()
11770 if( zDetail[0]!='-' ){ in idxFindIndexes()
11771 pStmt->zEQP = idxAppendText(&rc, pStmt->zEQP, "%s\n", zDetail); in idxFindIndexes()
11775 for(pEntry=hIdx.pFirst; pEntry; pEntry=pEntry->pNext){ in idxFindIndexes()
11776 pStmt->zIdx = idxAppendText(&rc, pStmt->zIdx, "%s;\n", pEntry->zKey); in idxFindIndexes()
11802 for(pTab=p->pTable; pTab; pTab=pTab->pNext){ in idxAuthCallback()
11803 if( 0==sqlite3_stricmp(z3, pTab->zName) ) break; in idxAuthCallback()
11807 for(pWrite=p->pWrite; pWrite; pWrite=pWrite->pNext){ in idxAuthCallback()
11808 if( pWrite->pTab==pTab && pWrite->eOp==eOp ) break; in idxAuthCallback()
11813 pWrite->pTab = pTab; in idxAuthCallback()
11814 pWrite->eOp = eOp; in idxAuthCallback()
11815 pWrite->pNext = p->pWrite; in idxAuthCallback()
11816 p->pWrite = pWrite; in idxAuthCallback()
11832 IdxTable *pTab = pWrite->pTab; in idxProcessOneTrigger()
11833 const char *zTab = pTab->zName; in idxProcessOneTrigger()
11843 rc = idxPrintfPrepareStmt(p->db, &pSelect, pzErr, zSql, zTab, zTab); in idxProcessOneTrigger()
11847 rc = sqlite3_exec(p->dbv, zCreate, 0, 0, pzErr); in idxProcessOneTrigger()
11857 rc = sqlite3_exec(p->dbv, z, 0, 0, pzErr); in idxProcessOneTrigger()
11862 switch( pWrite->eOp ){ in idxProcessOneTrigger()
11866 for(i=0; i<pTab->nCol; i++){ in idxProcessOneTrigger()
11875 for(i=0; i<pTab->nCol; i++){ in idxProcessOneTrigger()
11877 pTab->aCol[i].zName in idxProcessOneTrigger()
11883 assert( pWrite->eOp==SQLITE_DELETE ); in idxProcessOneTrigger()
11893 rc = sqlite3_prepare_v2(p->dbv, zWrite, -1, &pX, 0); in idxProcessOneTrigger()
11896 idxDatabaseError(p->dbv, pzErr); in idxProcessOneTrigger()
11902 rc = sqlite3_exec(p->dbv, zDrop, 0, 0, pzErr); in idxProcessOneTrigger()
11911 IdxWrite *pFirst = p->pWrite; in idxProcessTriggers()
11915 for(pIter=pFirst; rc==SQLITE_OK && pIter!=pEnd; pIter=pIter->pNext){ in idxProcessTriggers()
11919 pFirst = p->pWrite; in idxProcessTriggers()
11932 ** 1) Add an entry to the p->pTable list, and in idxCreateVtabSchema()
11935 rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg, in idxCreateVtabSchema()
11951 if( zSql ) rc = sqlite3_exec(p->dbv, zSql, 0, 0, pzErrmsg); in idxCreateVtabSchema()
11954 rc = idxGetTableInfo(p->db, zName, &pTab, pzErrmsg); in idxCreateVtabSchema()
11959 pTab->pNext = p->pTable; in idxCreateVtabSchema()
11960 p->pTable = pTab; in idxCreateVtabSchema()
11964 for(i=0; i<pTab->nCol; i++){ in idxCreateVtabSchema()
11966 (i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl in idxCreateVtabSchema()
11976 rc = sqlite3_exec(p->dbv, zOuter, 0, 0, pzErrmsg); in idxCreateVtabSchema()
12004 if( p->nRow==0.0 ){ in idxSampleFunc()
12007 bRet = (p->nRet / p->nRow) <= p->target; in idxSampleFunc()
12011 bRet = ((int)rnd % 100) <= p->iTarget; in idxSampleFunc()
12016 p->nRow += 1.0; in idxSampleFunc()
12017 p->nRet += (double)bRet; in idxSampleFunc()
12046 assert( iSlot<=p->nSlot ); in idxRemFunc()
12047 pSlot = &p->aSlot[iSlot]; in idxRemFunc()
12049 switch( pSlot->eType ){ in idxRemFunc()
12051 /* no-op */ in idxRemFunc()
12055 sqlite3_result_int64(pCtx, pSlot->iVal); in idxRemFunc()
12059 sqlite3_result_double(pCtx, pSlot->rVal); in idxRemFunc()
12063 sqlite3_result_blob(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT); in idxRemFunc()
12067 sqlite3_result_text(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT); in idxRemFunc()
12071 pSlot->eType = sqlite3_value_type(argv[1]); in idxRemFunc()
12072 switch( pSlot->eType ){ in idxRemFunc()
12074 /* no-op */ in idxRemFunc()
12078 pSlot->iVal = sqlite3_value_int64(argv[1]); in idxRemFunc()
12082 pSlot->rVal = sqlite3_value_double(argv[1]); in idxRemFunc()
12089 if( nByte>pSlot->nByte ){ in idxRemFunc()
12090 char *zNew = (char*)sqlite3_realloc(pSlot->z, nByte*2); in idxRemFunc()
12095 pSlot->nByte = nByte*2; in idxRemFunc()
12096 pSlot->z = zNew; in idxRemFunc()
12098 pSlot->n = nByte; in idxRemFunc()
12099 if( pSlot->eType==SQLITE_BLOB ){ in idxRemFunc()
12101 if( pData ) memcpy(pSlot->z, pData, nByte); in idxRemFunc()
12104 memcpy(pSlot->z, pData, nByte); in idxRemFunc()
12148 assert( p->iSample>0 ); in idxPopulateOneStat1()
12151 sqlite3_bind_text(pIndexXInfo, 1, zIdx, -1, SQLITE_STATIC); in idxPopulateOneStat1()
12163 if( p->iSample==100 ){ in idxPopulateOneStat1()
12178 sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv); in idxPopulateOneStat1()
12195 for(/*no-op*/; i<nCol; i++){ in idxPopulateOneStat1()
12210 sqlite3_bind_text(pWriteStat, 1, zTab, -1, SQLITE_STATIC); in idxPopulateOneStat1()
12211 sqlite3_bind_text(pWriteStat, 2, zIdx, -1, SQLITE_STATIC); in idxPopulateOneStat1()
12212 sqlite3_bind_text(pWriteStat, 3, zStat, -1, SQLITE_STATIC); in idxPopulateOneStat1()
12217 pEntry = idxHashFind(&p->hIdx, zIdx, STRLEN(zIdx)); in idxPopulateOneStat1()
12219 assert( pEntry->zVal2==0 ); in idxPopulateOneStat1()
12220 pEntry->zVal2 = zStat; in idxPopulateOneStat1()
12235 rc = sqlite3_exec(p->dbv,"DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0); in idxBuildSampleTable()
12242 rc = sqlite3_exec(p->dbv, zSql, 0, 0, 0); in idxBuildSampleTable()
12261 i64 iPrev = -100000; in idxPopulateStat1()
12276 if( p->iSample==0 ) return SQLITE_OK; in idxPopulateStat1()
12278 rc = idxLargestIndex(p->dbm, &nMax, pzErr); in idxPopulateStat1()
12281 rc = sqlite3_exec(p->dbm, "ANALYZE; PRAGMA writable_schema=1", 0, 0, 0); in idxPopulateStat1()
12289 sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv); in idxPopulateStat1()
12296 p->db, "sample", 0, SQLITE_UTF8, (void*)&samplectx, idxSampleFunc, 0, 0 in idxPopulateStat1()
12301 pCtx->nSlot = nMax+1; in idxPopulateStat1()
12302 rc = idxPrepareStmt(p->dbm, &pAllIndex, pzErr, zAllIndex); in idxPopulateStat1()
12305 rc = idxPrepareStmt(p->dbm, &pIndexXInfo, pzErr, zIndexXInfo); in idxPopulateStat1()
12308 rc = idxPrepareStmt(p->dbm, &pWrite, pzErr, zWrite); in idxPopulateStat1()
12316 if( p->iSample<100 && iPrev!=iRowid ){ in idxPopulateStat1()
12317 samplectx.target = (double)p->iSample / 100.0; in idxPopulateStat1()
12318 samplectx.iTarget = p->iSample; in idxPopulateStat1()
12327 if( rc==SQLITE_OK && p->iSample<100 ){ in idxPopulateStat1()
12328 rc = sqlite3_exec(p->dbv, in idxPopulateStat1()
12338 for(i=0; i<pCtx->nSlot; i++){ in idxPopulateStat1()
12339 sqlite3_free(pCtx->aSlot[i].z); in idxPopulateStat1()
12345 rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_schema", 0, 0, 0); in idxPopulateStat1()
12348 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0); in idxPopulateStat1()
12361 /* Open two in-memory databases to work with. The "vtab database" (dbv) in sqlite3_expert_new()
12368 pNew->db = db; in sqlite3_expert_new()
12369 pNew->iSample = 100; in sqlite3_expert_new()
12370 rc = sqlite3_open(":memory:", &pNew->dbv); in sqlite3_expert_new()
12373 rc = sqlite3_open(":memory:", &pNew->dbm); in sqlite3_expert_new()
12375 sqlite3_db_config(pNew->dbm, SQLITE_DBCONFIG_TRIGGER_EQP, 1, (int*)0); in sqlite3_expert_new()
12383 rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg, in sqlite3_expert_new()
12389 if( zSql ) rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg); in sqlite3_expert_new()
12401 sqlite3_set_authorizer(pNew->dbv, idxAuthCallback, (void*)pNew); in sqlite3_expert_new()
12425 p->iSample = iVal; in sqlite3_expert_config()
12445 IdxScan *pScanOrig = p->pScan; in sqlite3_expert_sql()
12446 IdxStatement *pStmtOrig = p->pStatement; in sqlite3_expert_sql()
12450 if( p->bRun ) return SQLITE_MISUSE; in sqlite3_expert_sql()
12454 rc = sqlite3_prepare_v2(p->dbv, zStmt, -1, &pStmt, &zStmt); in sqlite3_expert_sql()
12462 pNew->zSql = (char*)&pNew[1]; in sqlite3_expert_sql()
12463 memcpy(pNew->zSql, z, n+1); in sqlite3_expert_sql()
12464 pNew->pNext = p->pStatement; in sqlite3_expert_sql()
12465 if( p->pStatement ) pNew->iId = p->pStatement->iId+1; in sqlite3_expert_sql()
12466 p->pStatement = pNew; in sqlite3_expert_sql()
12471 idxDatabaseError(p->dbv, pzErr); in sqlite3_expert_sql()
12476 idxScanFree(p->pScan, pScanOrig); in sqlite3_expert_sql()
12477 idxStatementFree(p->pStatement, pStmtOrig); in sqlite3_expert_sql()
12478 p->pScan = pScanOrig; in sqlite3_expert_sql()
12479 p->pStatement = pStmtOrig; in sqlite3_expert_sql()
12492 /* Create candidate indexes within the in-memory database file */ in sqlite3_expert_analyze()
12507 for(pEntry=p->hIdx.pFirst; pEntry; pEntry=pEntry->pNext){ in sqlite3_expert_analyze()
12508 p->zCandidates = idxAppendText(&rc, p->zCandidates, in sqlite3_expert_analyze()
12509 "%s;%s%s\n", pEntry->zVal, in sqlite3_expert_analyze()
12510 pEntry->zVal2 ? " -- stat1: " : "", pEntry->zVal2 in sqlite3_expert_analyze()
12521 p->bRun = 1; in sqlite3_expert_analyze()
12532 if( p->pStatement ) nRet = p->pStatement->iId+1; in sqlite3_expert_count()
12543 if( p->bRun==0 ) return 0; in sqlite3_expert_report()
12544 for(pStmt=p->pStatement; pStmt && pStmt->iId!=iStmt; pStmt=pStmt->pNext); in sqlite3_expert_report()
12547 if( pStmt ) zRet = pStmt->zSql; in sqlite3_expert_report()
12550 if( pStmt ) zRet = pStmt->zIdx; in sqlite3_expert_report()
12553 if( pStmt ) zRet = pStmt->zEQP; in sqlite3_expert_report()
12556 zRet = p->zCandidates; in sqlite3_expert_report()
12567 sqlite3_close(p->dbm); in sqlite3_expert_destroy()
12568 sqlite3_close(p->dbv); in sqlite3_expert_destroy()
12569 idxScanFree(p->pScan, 0); in sqlite3_expert_destroy()
12570 idxStatementFree(p->pStatement, 0); in sqlite3_expert_destroy()
12571 idxTableFree(p->pTable); in sqlite3_expert_destroy()
12572 idxWriteFree(p->pWrite); in sqlite3_expert_destroy()
12573 idxHashClear(&p->hIdx); in sqlite3_expert_destroy()
12574 sqlite3_free(p->zCandidates); in sqlite3_expert_destroy()
12591 ** 2022-08-27
12602 ** This file contains the public interface to the "recover" extension -
12622 ** error. If it returns some other non-SQLITE_OK value, then an error
12691 ** nul-terminated buffer containing the SQL statement formated as UTF-8 as
12696 ** If an out-of-memory error occurs, NULL may be returned instead of
12731 ** of a "lost-and-found" table in the output database, or NULL. If
12732 ** the argument is non-NULL and the database contains seemingly
12735 ** pages to add to the lost-and-found table.
12740 ** (argument is 1) and a lost-and-found table has been configured using
12760 ** module creates and populates non-UNIQUE indexes right at the end of the
12761 ** recovery operation - after all recoverable data has been inserted
12766 ** Or, if this option is set (argument is 1), then non-UNIQUE indexes
12790 ** all further such calls on the same recover handle are no-ops that return
12791 ** the same non-SQLITE_OK value.
12809 ** the error. If no error message is available, or if an out-of memory
12844 ** 2019-04-17
12860 ** sqlite_dbdata is used to extract data directly from a database b-tree
12861 ** page and its associated overflow pages, bypassing the b-tree layer.
12873 ** FUTURE NEW NON-HIDDEN COLUMNS MAY BE ADDED BETWEEN "value" AND
12877 ** a b-tree page, or if it is a b-tree page containing 0 entries, the
12880 ** each cell on the page. For intkey b-trees, the key value is stored in
12881 ** field -1.
12885 ** CREATE TABLE t1(a, b); -- root page is page 2
12893 ** (2, 0, -1, 5 ),
12896 ** (2, 1, -1, 10 ),
12913 ** It contains one entry for each b-tree pointer between a parent and
13019 pTab->db = db; in dbdataConnect()
13020 pTab->bPtr = (pAux!=0); in dbdataConnect()
13034 sqlite3_finalize(pTab->pStmt); in dbdataDisconnect()
13056 int iSchema = -1; in dbdataBestIndex()
13057 int iPgno = -1; in dbdataBestIndex()
13058 int colSchema = (pTab->bPtr ? DBPTR_COLUMN_SCHEMA : DBDATA_COLUMN_SCHEMA); in dbdataBestIndex()
13060 for(i=0; i<pIdx->nConstraint; i++){ in dbdataBestIndex()
13061 struct sqlite3_index_constraint *p = &pIdx->aConstraint[i]; in dbdataBestIndex()
13062 if( p->op==SQLITE_INDEX_CONSTRAINT_EQ ){ in dbdataBestIndex()
13063 if( p->iColumn==colSchema ){ in dbdataBestIndex()
13064 if( p->usable==0 ) return SQLITE_CONSTRAINT; in dbdataBestIndex()
13067 if( p->iColumn==DBDATA_COLUMN_PGNO && p->usable ){ in dbdataBestIndex()
13074 pIdx->aConstraintUsage[iSchema].argvIndex = 1; in dbdataBestIndex()
13075 pIdx->aConstraintUsage[iSchema].omit = 1; in dbdataBestIndex()
13078 pIdx->aConstraintUsage[iPgno].argvIndex = 1 + (iSchema>=0); in dbdataBestIndex()
13079 pIdx->aConstraintUsage[iPgno].omit = 1; in dbdataBestIndex()
13080 pIdx->estimatedCost = 100; in dbdataBestIndex()
13081 pIdx->estimatedRows = 50; in dbdataBestIndex()
13083 if( pTab->bPtr==0 && pIdx->nOrderBy && pIdx->aOrderBy[0].desc==0 ){ in dbdataBestIndex()
13084 int iCol = pIdx->aOrderBy[0].iColumn; in dbdataBestIndex()
13085 if( pIdx->nOrderBy==1 ){ in dbdataBestIndex()
13086 pIdx->orderByConsumed = (iCol==0 || iCol==1); in dbdataBestIndex()
13087 }else if( pIdx->nOrderBy==2 && pIdx->aOrderBy[1].desc==0 && iCol==0 ){ in dbdataBestIndex()
13088 pIdx->orderByConsumed = (pIdx->aOrderBy[1].iColumn==1); in dbdataBestIndex()
13093 pIdx->estimatedCost = 100000000; in dbdataBestIndex()
13094 pIdx->estimatedRows = 1000000000; in dbdataBestIndex()
13096 pIdx->idxNum = (iSchema>=0 ? 0x01 : 0x00) | (iPgno>=0 ? 0x02 : 0x00); in dbdataBestIndex()
13111 pCsr->base.pVtab = pVTab; in dbdataOpen()
13123 DbdataTable *pTab = (DbdataTable*)(pCsr->base.pVtab); in dbdataResetCursor()
13124 if( pTab->pStmt==0 ){ in dbdataResetCursor()
13125 pTab->pStmt = pCsr->pStmt; in dbdataResetCursor()
13127 sqlite3_finalize(pCsr->pStmt); in dbdataResetCursor()
13129 pCsr->pStmt = 0; in dbdataResetCursor()
13130 pCsr->iPgno = 1; in dbdataResetCursor()
13131 pCsr->iCell = 0; in dbdataResetCursor()
13132 pCsr->iField = 0; in dbdataResetCursor()
13133 pCsr->bOnePage = 0; in dbdataResetCursor()
13134 sqlite3_free(pCsr->aPage); in dbdataResetCursor()
13135 sqlite3_free(pCsr->pRec); in dbdataResetCursor()
13136 pCsr->pRec = 0; in dbdataResetCursor()
13137 pCsr->aPage = 0; in dbdataResetCursor()
13151 ** Utility methods to decode 16 and 32-bit big-endian unsigned integers.
13181 sqlite3_stmt *pStmt = pCsr->pStmt; in dbdataLoadPage()
13262 return ((eType-12) / 2); in dbdataValueBytes()
13317 int n = ((eType-12) / 2); in dbdataValue()
13345 DbdataTable *pTab = (DbdataTable*)pCursor->pVtab; in dbdataNext()
13347 pCsr->iRowid++; in dbdataNext()
13350 int iOff = (pCsr->iPgno==1 ? 100 : 0); in dbdataNext()
13353 if( pCsr->aPage==0 ){ in dbdataNext()
13355 if( pCsr->bOnePage==0 && pCsr->iPgno>pCsr->szDb ) return SQLITE_OK; in dbdataNext()
13356 rc = dbdataLoadPage(pCsr, pCsr->iPgno, &pCsr->aPage, &pCsr->nPage); in dbdataNext()
13358 if( pCsr->aPage && pCsr->nPage>=256 ) break; in dbdataNext()
13359 sqlite3_free(pCsr->aPage); in dbdataNext()
13360 pCsr->aPage = 0; in dbdataNext()
13361 if( pCsr->bOnePage ) return SQLITE_OK; in dbdataNext()
13362 pCsr->iPgno++; in dbdataNext()
13365 assert( iOff+3+2<=pCsr->nPage ); in dbdataNext()
13366 pCsr->iCell = pTab->bPtr ? -2 : 0; in dbdataNext()
13367 pCsr->nCell = get_uint16(&pCsr->aPage[iOff+3]); in dbdataNext()
13370 if( pTab->bPtr ){ in dbdataNext()
13371 if( pCsr->aPage[iOff]!=0x02 && pCsr->aPage[iOff]!=0x05 ){ in dbdataNext()
13372 pCsr->iCell = pCsr->nCell; in dbdataNext()
13374 pCsr->iCell++; in dbdataNext()
13375 if( pCsr->iCell>=pCsr->nCell ){ in dbdataNext()
13376 sqlite3_free(pCsr->aPage); in dbdataNext()
13377 pCsr->aPage = 0; in dbdataNext()
13378 if( pCsr->bOnePage ) return SQLITE_OK; in dbdataNext()
13379 pCsr->iPgno++; in dbdataNext()
13385 if( pCsr->pRec==0 ){ in dbdataNext()
13394 switch( pCsr->aPage[iOff] ){ in dbdataNext()
13404 /* This is not a b-tree page with records on it. Continue. */ in dbdataNext()
13405 pCsr->iCell = pCsr->nCell; in dbdataNext()
13409 if( pCsr->iCell>=pCsr->nCell ){ in dbdataNext()
13413 iOff += 8 + nPointer + pCsr->iCell*2; in dbdataNext()
13414 if( iOff>pCsr->nPage ){ in dbdataNext()
13417 iOff = get_uint16(&pCsr->aPage[iOff]); in dbdataNext()
13420 /* For an interior node cell, skip past the child-page number */ in dbdataNext()
13424 if( bNextPage || iOff>pCsr->nPage ){ in dbdataNext()
13427 iOff += dbdataGetVarintU32(&pCsr->aPage[iOff], &nPayload); in dbdataNext()
13431 if( bHasRowid && !bNextPage && iOff<pCsr->nPage ){ in dbdataNext()
13432 iOff += dbdataGetVarint(&pCsr->aPage[iOff], &pCsr->iIntkey); in dbdataNext()
13436 U = pCsr->nPage; in dbdataNext()
13438 X = U-35; in dbdataNext()
13440 X = ((U-12)*64/255)-23; in dbdataNext()
13446 M = ((U-12)*32/255)-23; in dbdataNext()
13447 K = M+((nPayload-M)%(U-4)); in dbdataNext()
13455 if( bNextPage || nLocal+iOff>pCsr->nPage ){ in dbdataNext()
13462 pCsr->pRec = (u8*)sqlite3_malloc64(nPayload+DBDATA_PADDING_BYTES); in dbdataNext()
13463 if( pCsr->pRec==0 ) return SQLITE_NOMEM; in dbdataNext()
13464 memset(pCsr->pRec, 0, nPayload+DBDATA_PADDING_BYTES); in dbdataNext()
13465 pCsr->nRec = nPayload; in dbdataNext()
13468 memcpy(pCsr->pRec, &pCsr->aPage[iOff], nLocal); in dbdataNext()
13473 sqlite3_int64 nRem = nPayload - nLocal; in dbdataNext()
13474 u32 pgnoOvfl = get_uint32(&pCsr->aPage[iOff]); in dbdataNext()
13480 assert( rc!=SQLITE_OK || aOvfl==0 || nOvfl==pCsr->nPage ); in dbdataNext()
13484 nCopy = U-4; in dbdataNext()
13486 memcpy(&pCsr->pRec[nPayload-nRem], &aOvfl[4], nCopy); in dbdataNext()
13487 nRem -= nCopy; in dbdataNext()
13494 iHdr = dbdataGetVarintU32(pCsr->pRec, &nHdr); in dbdataNext()
13496 pCsr->nHdr = nHdr; in dbdataNext()
13497 pCsr->pHdrPtr = &pCsr->pRec[iHdr]; in dbdataNext()
13498 pCsr->pPtr = &pCsr->pRec[pCsr->nHdr]; in dbdataNext()
13499 pCsr->iField = (bHasRowid ? -1 : 0); in dbdataNext()
13503 pCsr->iField++; in dbdataNext()
13504 if( pCsr->iField>0 ){ in dbdataNext()
13506 if( pCsr->pHdrPtr>&pCsr->pRec[pCsr->nRec] ){ in dbdataNext()
13509 pCsr->pHdrPtr += dbdataGetVarintU32(pCsr->pHdrPtr, &iType); in dbdataNext()
13510 pCsr->pPtr += dbdataValueBytes(iType); in dbdataNext()
13516 sqlite3_free(pCsr->aPage); in dbdataNext()
13517 sqlite3_free(pCsr->pRec); in dbdataNext()
13518 pCsr->aPage = 0; in dbdataNext()
13519 pCsr->pRec = 0; in dbdataNext()
13520 if( pCsr->bOnePage ) return SQLITE_OK; in dbdataNext()
13521 pCsr->iPgno++; in dbdataNext()
13523 if( pCsr->iField<0 || pCsr->pHdrPtr<&pCsr->pRec[pCsr->nHdr] ){ in dbdataNext()
13529 sqlite3_free(pCsr->pRec); in dbdataNext()
13530 pCsr->pRec = 0; in dbdataNext()
13531 pCsr->iCell++; in dbdataNext()
13545 return pCsr->aPage==0; in dbdataEof()
13549 ** Return true if nul-terminated string zSchema ends in "()". Or false
13554 if( n>2 && zSchema[n-2]=='(' && zSchema[n-1]==')' ){ in dbdataIsFunction()
13555 return (int)n-2; in dbdataIsFunction()
13563 ** pCsr->szDb accordingly. If successful, return SQLITE_OK. Otherwise,
13567 DbdataTable *pTab = (DbdataTable*)pCsr->base.pVtab; in dbdataDbsize()
13580 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0); in dbdataDbsize()
13583 pCsr->szDb = sqlite3_column_int(pStmt, 0); in dbdataDbsize()
13592 ** and inspecting the header field. If successful, set the pCsr->enc variable
13601 pCsr->enc = get_uint32(&aPg1[56]); in dbdataGetEncoding()
13617 DbdataTable *pTab = (DbdataTable*)pCursor->pVtab; in dbdataFilter()
13624 assert( pCsr->iPgno==1 ); in dbdataFilter()
13630 pCsr->iPgno = sqlite3_value_int(argv[(idxNum & 0x01)]); in dbdataFilter()
13631 pCsr->bOnePage = 1; in dbdataFilter()
13638 if( pTab->pStmt ){ in dbdataFilter()
13639 pCsr->pStmt = pTab->pStmt; in dbdataFilter()
13640 pTab->pStmt = 0; in dbdataFilter()
13646 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0); in dbdataFilter()
13650 rc = sqlite3_prepare_v2(pTab->db, in dbdataFilter()
13651 "SELECT data FROM sqlite_dbpage(?) WHERE pgno=?", -1, in dbdataFilter()
13652 &pCsr->pStmt, 0 in dbdataFilter()
13657 rc = sqlite3_bind_text(pCsr->pStmt, 1, zSchema, -1, SQLITE_TRANSIENT); in dbdataFilter()
13667 pTab->base.zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pTab->db)); in dbdataFilter()
13685 DbdataTable *pTab = (DbdataTable*)pCursor->pVtab; in dbdataColumn()
13686 if( pTab->bPtr ){ in dbdataColumn()
13689 sqlite3_result_int64(ctx, pCsr->iPgno); in dbdataColumn()
13692 int iOff = pCsr->iPgno==1 ? 100 : 0; in dbdataColumn()
13693 if( pCsr->iCell<0 ){ in dbdataColumn()
13696 iOff += 12 + pCsr->iCell*2; in dbdataColumn()
13697 if( iOff>pCsr->nPage ) return SQLITE_OK; in dbdataColumn()
13698 iOff = get_uint16(&pCsr->aPage[iOff]); in dbdataColumn()
13700 if( iOff<=pCsr->nPage ){ in dbdataColumn()
13701 sqlite3_result_int64(ctx, get_uint32(&pCsr->aPage[iOff])); in dbdataColumn()
13709 sqlite3_result_int64(ctx, pCsr->iPgno); in dbdataColumn()
13712 sqlite3_result_int(ctx, pCsr->iCell); in dbdataColumn()
13715 sqlite3_result_int(ctx, pCsr->iField); in dbdataColumn()
13718 if( pCsr->iField<0 ){ in dbdataColumn()
13719 sqlite3_result_int64(ctx, pCsr->iIntkey); in dbdataColumn()
13720 }else if( &pCsr->pRec[pCsr->nRec] >= pCsr->pPtr ){ in dbdataColumn()
13722 dbdataGetVarintU32(pCsr->pHdrPtr, &iType); in dbdataColumn()
13724 ctx, pCsr->enc, iType, pCsr->pPtr, in dbdataColumn()
13725 &pCsr->pRec[pCsr->nRec] - pCsr->pPtr in dbdataColumn()
13740 *pRowid = pCsr->iRowid; in dbdataRowid()
13756 dbdataOpen, /* xOpen - open a cursor */ in sqlite3DbdataRegister()
13757 dbdataClose, /* xClose - close a cursor */ in sqlite3DbdataRegister()
13758 dbdataFilter, /* xFilter - configure scan constraints */ in sqlite3DbdataRegister()
13759 dbdataNext, /* xNext - advance a cursor */ in sqlite3DbdataRegister()
13760 dbdataEof, /* xEof - check for end of scan */ in sqlite3DbdataRegister()
13761 dbdataColumn, /* xColumn - read data */ in sqlite3DbdataRegister()
13762 dbdataRowid, /* xRowid - read data */ in sqlite3DbdataRegister()
13801 ** 2022-08-27
13863 ** Otherwise, it contains -1. If the table does contain an INTEGER PRIMARY
13870 ** the output database, before any non-schema data are recovered. They
13871 ** are then stored in a singly-linked list linked by this variable beginning
13889 ** The index of the associated field within database records. Or -1 if
13942 u32 aElem[1]; /* Array of 32-bit bitmasks */
14001 char *zLostAndFound; /* Name of lost-and-found table (or NULL) */
14046 ** Populate the recovery.map table - used to figure out a "root" page
14051 ** Populate the lost-and-found table itself.
14087 ** recoverEnterMutex() - Enter the recovery mutex
14088 ** recoverLeaveMutex() - Leave the recovery mutex
14089 ** recoverAssertMutexHeld() - Assert that the recovery mutex is held
14120 ** This function is a no-op if the recover handle passed as the first
14121 ** argument already contains an error (if p->errCode!=SQLITE_OK).
14126 ** (p->errCode) set to SQLITE_NOMEM.
14131 if( p->errCode==SQLITE_OK ){ in recoverMalloc()
14136 p->errCode = SQLITE_NOMEM; in recoverMalloc()
14167 sqlite3_free(p->zErrMsg); in recoverError()
14168 p->zErrMsg = z; in recoverError()
14169 p->errCode = errCode; in recoverError()
14175 ** This function is a no-op if p->errCode is initially other than SQLITE_OK.
14188 pRet->nPg = nPg; in recoverBitmapAlloc()
14204 if( iPg<=pMap->nPg ){ in recoverBitmapSet()
14207 pMap->aElem[iElem] |= (((u32)1) << iBit); in recoverBitmapSet()
14217 if( iPg<=pMap->nPg && iPg>0 ){ in recoverBitmapQuery()
14220 ret = (pMap->aElem[iElem] & (((u32)1) << iBit)) ? 1 : 0; in recoverBitmapQuery()
14235 ** This function is a no-op if recover handle p already contains an error
14236 ** (if p->errCode!=SQLITE_OK).
14249 if( p->errCode==SQLITE_OK ){ in recoverPrepare()
14250 if( sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) ){ in recoverPrepare()
14258 ** This function is a no-op if recover handle p already contains an error
14259 ** (if p->errCode!=SQLITE_OK).
14264 ** the statment handle returned. Or, if an error occurs - either during
14265 ** the printf() formatting or when preparing the resulting SQL - an
14274 if( p->errCode==SQLITE_OK ){ in recoverPreparePrintf()
14281 p->errCode = SQLITE_NOMEM; in recoverPreparePrintf()
14301 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT && p->errCode==SQLITE_OK ){ in recoverReset()
14316 if( rc!=SQLITE_OK && p->errCode==SQLITE_OK ){ in recoverFinalize()
14322 ** This function is a no-op if recover handle p already contains an error
14323 ** (if p->errCode!=SQLITE_OK). A copy of p->errCode is returned in this
14331 if( p->errCode==SQLITE_OK ){ in recoverExec()
14337 return p->errCode; in recoverExec()
14351 if( p->errCode==SQLITE_OK ){ in recoverBindValue()
14358 ** This function is a no-op if recover handle p already contains an error
14359 ** (if p->errCode!=SQLITE_OK). NULL is returned in this case.
14377 if( p->errCode==SQLITE_OK ){ in recoverMPrintf()
14378 if( z==0 ) p->errCode = SQLITE_NOMEM; in recoverMPrintf()
14387 ** This function is a no-op if recover handle p already contains an error
14388 ** (if p->errCode!=SQLITE_OK). Zero is returned in this case.
14397 if( p->errCode==SQLITE_OK ){ in recoverPageCount()
14399 pStmt = recoverPreparePrintf(p, p->dbIn, "PRAGMA %Q.page_count", p->zDb); in recoverPageCount()
14411 ** this function must be a blob. The second a non-negative integer. This
14412 ** function reads and returns a 32-bit big-endian integer from byte
14444 ** lost-and-found table, and it depends on those routines having populated
14447 ** The only argument to this function is a page-number. It returns true
14461 sqlite3_result_int(pCtx, recoverBitmapQuery(p->laf.pUsed, pgno)); in recoverPageIsUsed()
14465 ** The implementation of a user-defined SQL function invoked by the
14475 ** SELECT getpage(0); -- return number of pages in db
14476 ** SELECT getpage(4); -- return page 4 of db as a blob of data
14493 if( p->pGetPage==0 ){ in recoverGetPage()
14494 pStmt = p->pGetPage = recoverPreparePrintf( in recoverGetPage()
14495 p, p->dbIn, "SELECT data FROM sqlite_dbpage(%Q) WHERE pgno=?", p->zDb in recoverGetPage()
14497 }else if( p->errCode==SQLITE_OK ){ in recoverGetPage()
14498 pStmt = p->pGetPage; in recoverGetPage()
14506 assert( p->errCode==SQLITE_OK ); in recoverGetPage()
14509 if( pgno==1 && nPg==p->pgsz && 0==memcmp(p->pPage1Cache, aPg, nPg) ){ in recoverGetPage()
14510 aPg = p->pPage1Disk; in recoverGetPage()
14512 sqlite3_result_blob(pCtx, aPg, nPg-p->nReserve, SQLITE_TRANSIENT); in recoverGetPage()
14518 if( p->errCode ){ in recoverGetPage()
14519 if( p->zErrMsg ) sqlite3_result_error(pCtx, p->zErrMsg, -1); in recoverGetPage()
14520 sqlite3_result_error_code(pCtx, p->errCode); in recoverGetPage()
14547 ** this function is the output of built-in function quote(). If the first
14636 ** This function is a no-op if recover handle p already contains an error
14637 ** (if p->errCode!=SQLITE_OK). A copy of the error code is returned in
14649 return recoverExec(p, p->dbOut, in recoverCacheSchema()
14670 ** this function is a no-op. Otherwise, issue a callback with SQL statement
14673 ** If the callback returns non-zero, set the recover handle error code to
14677 if( p->errCode==SQLITE_OK && p->xSql ){ in recoverSqlCallback()
14678 int res = p->xSql(p->pSqlCtx, zSql); in recoverSqlCallback()
14680 recoverError(p, SQLITE_ERROR, "callback returned an error - %d", res); in recoverSqlCallback()
14689 ** + page-size,
14690 ** + auto-vacuum settings,
14692 ** + user-version (PRAGMA user_version), and
14693 ** + application-id (PRAGMA application_id), and
14708 if( p->errCode==SQLITE_OK ){ in recoverTransferSettings()
14719 p1 = recoverPreparePrintf(p, p->dbIn, "PRAGMA %Q.%s", p->zDb, zPrag); in recoverTransferSettings()
14720 if( p->errCode==SQLITE_OK && sqlite3_step(p1)==SQLITE_ROW ){ in recoverTransferSettings()
14734 if( p->errCode==SQLITE_OK ){ in recoverTransferSettings()
14735 sqlite3 *db = p->dbOut; in recoverTransferSettings()
14738 sqlite3_backup_step(pBackup, -1); in recoverTransferSettings()
14739 p->errCode = sqlite3_backup_finish(pBackup); in recoverTransferSettings()
14750 ** This function is a no-op if recover handle p already contains an error
14751 ** (if p->errCode!=SQLITE_OK). A copy of the error code is returned in
14779 assert( p->dbOut==0 ); in recoverOpenOutput()
14781 if( sqlite3_open_v2(p->zUri, &db, flags, 0) ){ in recoverOpenOutput()
14786 ** These two are registered with the output database handle - this in recoverOpenOutput()
14789 if( p->errCode==SQLITE_OK ){ in recoverOpenOutput()
14790 p->errCode = sqlite3_dbdata_init(db, 0, 0); in recoverOpenOutput()
14793 /* Register the custom user-functions with the output handle. */ in recoverOpenOutput()
14795 p->errCode==SQLITE_OK && ii<(int)(sizeof(aFunc)/sizeof(aFunc[0])); in recoverOpenOutput()
14797 p->errCode = sqlite3_create_function(db, aFunc[ii].zName, in recoverOpenOutput()
14802 p->dbOut = db; in recoverOpenOutput()
14803 return p->errCode; in recoverOpenOutput()
14812 char *zSql = recoverMPrintf(p, "ATTACH %Q AS recovery;", p->zStateDb); in recoverOpenRecovery()
14813 recoverExec(p, p->dbOut, zSql); in recoverOpenRecovery()
14814 recoverExec(p, p->dbOut, in recoverOpenRecovery()
14824 ** This function is a no-op if recover handle p already contains an error
14825 ** (if p->errCode!=SQLITE_OK).
14841 sqlite3_stmt *pStmt = recoverPreparePrintf(p, p->dbOut, in recoverAddTable()
14846 int iPk = -1; in recoverAddTable()
14864 pNew->aCol = (RecoverColumn*)&pNew[1]; in recoverAddTable()
14865 pNew->zTab = csr = (char*)&pNew->aCol[nCol]; in recoverAddTable()
14866 pNew->nCol = nCol; in recoverAddTable()
14867 pNew->iRoot = iRoot; in recoverAddTable()
14878 if( iPk==-1 && iPKF==1 && !sqlite3_stricmp("integer", zType) ) iPk = i; in recoverAddTable()
14879 if( iPKF>1 ) iPk = -2; in recoverAddTable()
14880 pNew->aCol[i].zCol = csr; in recoverAddTable()
14881 pNew->aCol[i].eHidden = eHidden; in recoverAddTable()
14883 pNew->aCol[i].iField = -1; in recoverAddTable()
14885 pNew->aCol[i].iField = iField++; in recoverAddTable()
14890 pNew->aCol[i].iBind = iBind++; in recoverAddTable()
14896 pNew->pNext = p->pTblList; in recoverAddTable()
14897 p->pTblList = pNew; in recoverAddTable()
14898 pNew->bIntkey = 1; in recoverAddTable()
14903 pStmt = recoverPreparePrintf(p, p->dbOut, "PRAGMA index_xinfo(%Q)", zName); in recoverAddTable()
14908 assert( iCol<pNew->nCol ); in recoverAddTable()
14909 pNew->aCol[iCol].iField = iField; in recoverAddTable()
14911 pNew->bIntkey = 0; in recoverAddTable()
14912 iPk = -2; in recoverAddTable()
14916 if( p->errCode==SQLITE_OK ){ in recoverAddTable()
14918 pNew->aCol[iPk].bIPK = 1; in recoverAddTable()
14919 }else if( pNew->bIntkey ){ in recoverAddTable()
14920 pNew->iRowidBind = iBind++; in recoverAddTable()
14949 pSelect = recoverPrepare(p, p->dbOut, in recoverWriteSchema1()
14963 pTblname = recoverPrepare(p, p->dbOut, in recoverWriteSchema1()
14969 sqlite3_bind_int(pSelect, 1, p->bSlowIndexes); in recoverWriteSchema1()
14985 rc = sqlite3_exec(p->dbOut, zSql, 0, 0, 0); in recoverWriteSchema1()
14996 recoverDbError(p, p->dbOut); in recoverWriteSchema1()
15004 return p->errCode; in recoverWriteSchema1()
15010 ** database by recoverWriteSchema1() - everything except for tables and
15015 ** * non-UNIQUE indexes.
15023 pSelect = recoverPrepare(p, p->dbOut, in recoverWriteSchema2()
15024 p->bSlowIndexes ? in recoverWriteSchema2()
15035 int rc = sqlite3_exec(p->dbOut, zSql, 0, 0, 0); in recoverWriteSchema2()
15039 recoverDbError(p, p->dbOut); in recoverWriteSchema2()
15045 return p->errCode; in recoverWriteSchema2()
15049 ** This function is a no-op if recover handle p already contains an error
15050 ** (if p->errCode!=SQLITE_OK). In this case it returns NULL.
15072 ** a single text value - itself an SQL statement similar to the above,
15095 int bSql = p->xSql ? 1 : 0; in recoverInsertStmt()
15099 assert( nField<=pTab->nCol ); in recoverInsertStmt()
15101 zSql = recoverMPrintf(p, "INSERT OR IGNORE INTO %Q(", pTab->zTab); in recoverInsertStmt()
15103 if( pTab->iRowidBind ){ in recoverInsertStmt()
15104 assert( pTab->bIntkey ); in recoverInsertStmt()
15107 zBind = recoverMPrintf(p, "%zquote(?%d)", zBind, pTab->iRowidBind); in recoverInsertStmt()
15109 zBind = recoverMPrintf(p, "%z?%d", zBind, pTab->iRowidBind); in recoverInsertStmt()
15116 int eHidden = pTab->aCol[ii].eHidden; in recoverInsertStmt()
15120 assert( pTab->aCol[ii].iField>=0 && pTab->aCol[ii].iBind>=1 ); in recoverInsertStmt()
15121 zSql = recoverMPrintf(p, "%z%s%Q", zSql, zSep, pTab->aCol[ii].zCol); in recoverInsertStmt()
15125 "%z%sescape_crnl(quote(?%d))", zBind, zSqlSep, pTab->aCol[ii].iBind in recoverInsertStmt()
15129 zBind = recoverMPrintf(p, "%z%s?%d", zBind, zSep, pTab->aCol[ii].iBind); in recoverInsertStmt()
15143 pRet = recoverPrepare(p, p->dbOut, zFinal); in recoverInsertStmt()
15153 ** Search the list of RecoverTable objects at p->pTblList for one that
15159 for(pRet=p->pTblList; pRet && pRet->iRoot!=iRoot; pRet=pRet->pNext); in recoverFindTable()
15180 pProbe = recoverPrepare(p, p->dbOut, in recoverLostAndFoundCreate()
15183 for(ii=-1; zTbl==0 && p->errCode==SQLITE_OK && ii<1000; ii++){ in recoverLostAndFoundCreate()
15186 zTbl = recoverMPrintf(p, "%s", p->zLostAndFound); in recoverLostAndFoundCreate()
15188 zTbl = recoverMPrintf(p, "%s_%d", p->zLostAndFound, ii); in recoverLostAndFoundCreate()
15191 if( p->errCode==SQLITE_OK ){ in recoverLostAndFoundCreate()
15192 sqlite3_bind_text(pProbe, 1, zTbl, -1, SQLITE_STATIC); in recoverLostAndFoundCreate()
15213 for(ii=0; p->errCode==SQLITE_OK && ii<nField; ii++){ in recoverLostAndFoundCreate()
15221 recoverExec(p, p->dbOut, zSql); in recoverLostAndFoundCreate()
15224 }else if( p->errCode==SQLITE_OK ){ in recoverLostAndFoundCreate()
15226 p, SQLITE_ERROR, "failed to create %s output table", p->zLostAndFound in recoverLostAndFoundCreate()
15248 if( p->xSql==0 ){ in recoverLostAndFoundInsert()
15253 p, p->dbOut, "INSERT INTO %s VALUES(%s)", zTab, zBind in recoverLostAndFoundInsert()
15262 p, p->dbOut, "SELECT 'INSERT INTO %s VALUES(' || %s || ')'", zTab, zBind in recoverLostAndFoundInsert()
15272 ** lost-and-found table of the output database. This function attempts
15284 RecoverStateLAF *pLaf = &p->laf; in recoverLostAndFoundFindRoot()
15286 if( pLaf->pFindRoot==0 ){ in recoverLostAndFoundFindRoot()
15287 pLaf->pFindRoot = recoverPrepare(p, p->dbOut, in recoverLostAndFoundFindRoot()
15297 if( p->errCode==SQLITE_OK ){ in recoverLostAndFoundFindRoot()
15298 sqlite3_bind_int64(pLaf->pFindRoot, 1, iPg); in recoverLostAndFoundFindRoot()
15299 if( sqlite3_step(pLaf->pFindRoot)==SQLITE_ROW ){ in recoverLostAndFoundFindRoot()
15300 *piRoot = sqlite3_column_int64(pLaf->pFindRoot, 0); in recoverLostAndFoundFindRoot()
15304 recoverReset(p, pLaf->pFindRoot); in recoverLostAndFoundFindRoot()
15306 return p->errCode; in recoverLostAndFoundFindRoot()
15311 ** the lost-and-found table in the output database.
15314 RecoverStateLAF *pLaf = &p->laf; in recoverLostAndFoundOnePage()
15315 sqlite3_value **apVal = pLaf->apVal; in recoverLostAndFoundOnePage()
15316 sqlite3_stmt *pPageData = pLaf->pPageData; in recoverLostAndFoundOnePage()
15317 sqlite3_stmt *pInsert = pLaf->pInsert; in recoverLostAndFoundOnePage()
15319 int nVal = -1; in recoverLostAndFoundOnePage()
15328 while( p->errCode==SQLITE_OK && SQLITE_ROW==sqlite3_step(pPageData) ){ in recoverLostAndFoundOnePage()
15355 nVal = -1; in recoverLostAndFoundOnePage()
15361 assert( nVal==-1 ); in recoverLostAndFoundOnePage()
15365 }else if( iField<pLaf->nMaxField ){ in recoverLostAndFoundOnePage()
15368 assert( iField==nVal || (nVal==-1 && iField==0) ); in recoverLostAndFoundOnePage()
15388 ** RECOVER_STATE_LOSTANDFOUND3 state - during which the lost-and-found
15393 RecoverStateLAF *pLaf = &p->laf; in recoverLostAndFound3Step()
15394 if( p->errCode==SQLITE_OK ){ in recoverLostAndFound3Step()
15395 if( pLaf->pInsert==0 ){ in recoverLostAndFound3Step()
15398 if( p->errCode==SQLITE_OK ){ in recoverLostAndFound3Step()
15399 int res = sqlite3_step(pLaf->pAllPage); in recoverLostAndFound3Step()
15401 i64 iPage = sqlite3_column_int64(pLaf->pAllPage, 0); in recoverLostAndFound3Step()
15402 if( recoverBitmapQuery(pLaf->pUsed, iPage)==0 ){ in recoverLostAndFound3Step()
15406 recoverReset(p, pLaf->pAllPage); in recoverLostAndFound3Step()
15417 ** state - during which the lost-and-found table of the output database
15422 RecoverStateLAF *pLaf = &p->laf; in recoverLostAndFound3Init()
15424 if( pLaf->nMaxField>0 ){ in recoverLostAndFound3Init()
15427 zTab = recoverLostAndFoundCreate(p, pLaf->nMaxField); in recoverLostAndFound3Init()
15428 pLaf->pInsert = recoverLostAndFoundInsert(p, zTab, pLaf->nMaxField); in recoverLostAndFound3Init()
15431 pLaf->pAllPage = recoverPreparePrintf(p, p->dbOut, in recoverLostAndFound3Init()
15435 "SELECT ii FROM seq" , p->laf.nPg in recoverLostAndFound3Init()
15437 pLaf->pPageData = recoverPrepare(p, p->dbOut, in recoverLostAndFound3Init()
15441 "SELECT -1, -1, -1" in recoverLostAndFound3Init()
15444 pLaf->apVal = (sqlite3_value**)recoverMalloc(p, in recoverLostAndFound3Init()
15445 pLaf->nMaxField*sizeof(sqlite3_value*) in recoverLostAndFound3Init()
15451 ** Initialize resources required in RECOVER_STATE_WRITING state - during which
15456 RecoverStateW1 *p1 = &p->w1; in recoverWriteDataInit()
15461 assert( p1->nMax==0 ); in recoverWriteDataInit()
15462 for(pTbl=p->pTblList; pTbl; pTbl=pTbl->pNext){ in recoverWriteDataInit()
15463 if( pTbl->nCol>p1->nMax ) p1->nMax = pTbl->nCol; in recoverWriteDataInit()
15468 nByte = sizeof(sqlite3_value*) * (p1->nMax+1); in recoverWriteDataInit()
15469 p1->apVal = (sqlite3_value**)recoverMalloc(p, nByte); in recoverWriteDataInit()
15470 if( p1->apVal==0 ) return p->errCode; in recoverWriteDataInit()
15474 p1->pTbls = recoverPrepare(p, p->dbOut, in recoverWriteDataInit()
15479 p1->pSel = recoverPrepare(p, p->dbOut, in recoverWriteDataInit()
15492 return p->errCode; in recoverWriteDataInit()
15500 RecoverStateW1 *p1 = &p->w1; in recoverWriteDataCleanup()
15502 for(ii=0; ii<p1->nVal; ii++){ in recoverWriteDataCleanup()
15503 sqlite3_value_free(p1->apVal[ii]); in recoverWriteDataCleanup()
15505 sqlite3_free(p1->apVal); in recoverWriteDataCleanup()
15506 recoverFinalize(p, p1->pInsert); in recoverWriteDataCleanup()
15507 recoverFinalize(p, p1->pTbls); in recoverWriteDataCleanup()
15508 recoverFinalize(p, p1->pSel); in recoverWriteDataCleanup()
15515 ** RECOVER_STATE_WRITING state - during which tables recovered from the
15519 RecoverStateW1 *p1 = &p->w1; in recoverWriteDataStep()
15520 sqlite3_stmt *pSel = p1->pSel; in recoverWriteDataStep()
15521 sqlite3_value **apVal = p1->apVal; in recoverWriteDataStep()
15523 if( p->errCode==SQLITE_OK && p1->pTab==0 ){ in recoverWriteDataStep()
15524 if( sqlite3_step(p1->pTbls)==SQLITE_ROW ){ in recoverWriteDataStep()
15525 i64 iRoot = sqlite3_column_int64(p1->pTbls, 0); in recoverWriteDataStep()
15526 p1->pTab = recoverFindTable(p, iRoot); in recoverWriteDataStep()
15528 recoverFinalize(p, p1->pInsert); in recoverWriteDataStep()
15529 p1->pInsert = 0; in recoverWriteDataStep()
15533 if( p1->pTab==0 ) return p->errCode; in recoverWriteDataStep()
15537 ** keys before recovering its contents. The p1->pTbls SELECT statement in recoverWriteDataStep()
15540 if( sqlite3_stricmp("sqlite_sequence", p1->pTab->zTab)==0 ){ in recoverWriteDataStep()
15541 recoverExec(p, p->dbOut, "DELETE FROM sqlite_sequence"); in recoverWriteDataStep()
15546 ** SELECT statement p1->pSel. The SELECT statement will then iterate in recoverWriteDataStep()
15550 p1->nVal = 0; in recoverWriteDataStep()
15551 p1->bHaveRowid = 0; in recoverWriteDataStep()
15552 p1->iPrevPage = -1; in recoverWriteDataStep()
15553 p1->iPrevCell = -1; in recoverWriteDataStep()
15558 assert( p->errCode!=SQLITE_OK || p1->pTab ); in recoverWriteDataStep()
15560 if( p->errCode==SQLITE_OK && sqlite3_step(pSel)==SQLITE_ROW ){ in recoverWriteDataStep()
15561 RecoverTable *pTab = p1->pTab; in recoverWriteDataStep()
15567 int bNewCell = (p1->iPrevPage!=iPage || p1->iPrevCell!=iCell); in recoverWriteDataStep()
15569 assert( bNewCell==0 || (iField==-1 || iField==0) ); in recoverWriteDataStep()
15570 assert( bNewCell || iField==p1->nVal || p1->nVal==pTab->nCol ); in recoverWriteDataStep()
15574 if( p1->nVal>=0 ){ in recoverWriteDataStep()
15575 if( p1->pInsert==0 || p1->nVal!=p1->nInsert ){ in recoverWriteDataStep()
15576 recoverFinalize(p, p1->pInsert); in recoverWriteDataStep()
15577 p1->pInsert = recoverInsertStmt(p, pTab, p1->nVal); in recoverWriteDataStep()
15578 p1->nInsert = p1->nVal; in recoverWriteDataStep()
15580 if( p1->nVal>0 ){ in recoverWriteDataStep()
15581 sqlite3_stmt *pInsert = p1->pInsert; in recoverWriteDataStep()
15582 for(ii=0; ii<pTab->nCol; ii++){ in recoverWriteDataStep()
15583 RecoverColumn *pCol = &pTab->aCol[ii]; in recoverWriteDataStep()
15584 int iBind = pCol->iBind; in recoverWriteDataStep()
15586 if( pCol->bIPK ){ in recoverWriteDataStep()
15587 sqlite3_bind_int64(pInsert, iBind, p1->iRowid); in recoverWriteDataStep()
15588 }else if( pCol->iField<p1->nVal ){ in recoverWriteDataStep()
15589 recoverBindValue(p, pInsert, iBind, apVal[pCol->iField]); in recoverWriteDataStep()
15593 if( p->bRecoverRowid && pTab->iRowidBind>0 && p1->bHaveRowid ){ in recoverWriteDataStep()
15594 sqlite3_bind_int64(pInsert, pTab->iRowidBind, p1->iRowid); in recoverWriteDataStep()
15601 assert( p->errCode || pInsert ); in recoverWriteDataStep()
15606 for(ii=0; ii<p1->nVal; ii++){ in recoverWriteDataStep()
15610 p1->nVal = -1; in recoverWriteDataStep()
15611 p1->bHaveRowid = 0; in recoverWriteDataStep()
15616 p1->iRowid = sqlite3_column_int64(pSel, 3); in recoverWriteDataStep()
15617 assert( p1->nVal==-1 ); in recoverWriteDataStep()
15618 p1->nVal = 0; in recoverWriteDataStep()
15619 p1->bHaveRowid = 1; in recoverWriteDataStep()
15620 }else if( iField<pTab->nCol ){ in recoverWriteDataStep()
15626 p1->nVal = iField+1; in recoverWriteDataStep()
15628 p1->iPrevCell = iCell; in recoverWriteDataStep()
15629 p1->iPrevPage = iPage; in recoverWriteDataStep()
15633 p1->pTab = 0; in recoverWriteDataStep()
15636 return p->errCode; in recoverWriteDataStep()
15641 ** RECOVER_STATE_LOSTANDFOUND1 state - during which the set of pages not
15645 RecoverStateLAF *pLaf = &p->laf; in recoverLostAndFound1Init()
15648 assert( p->laf.pUsed==0 ); in recoverLostAndFound1Init()
15649 pLaf->nPg = recoverPageCount(p); in recoverLostAndFound1Init()
15650 pLaf->pUsed = recoverBitmapAlloc(p, pLaf->nPg); in recoverLostAndFound1Init()
15654 ** if !p->bFreelistCorrupt, add all pages that appear to be part of the in recoverLostAndFound1Init()
15657 p, p->dbOut, in recoverLostAndFound1Init()
15667 " SELECT data, min(16384, read_i32(data, 1)-1), pgno FROM trunkdata" in recoverLostAndFound1Init()
15669 " SELECT data, n-1, read_i32(data, 2+n) FROM freelist WHERE n>=0" in recoverLostAndFound1Init()
15686 if( pStmt ) sqlite3_bind_int(pStmt, 1, p->bFreelistCorrupt); in recoverLostAndFound1Init()
15687 pLaf->pUsedPages = pStmt; in recoverLostAndFound1Init()
15693 ** RECOVER_STATE_LOSTANDFOUND1 state - during which the set of pages not
15697 RecoverStateLAF *pLaf = &p->laf; in recoverLostAndFound1Step()
15698 int rc = p->errCode; in recoverLostAndFound1Step()
15700 rc = sqlite3_step(pLaf->pUsedPages); in recoverLostAndFound1Step()
15702 i64 iPg = sqlite3_column_int64(pLaf->pUsedPages, 0); in recoverLostAndFound1Step()
15703 recoverBitmapSet(pLaf->pUsed, iPg); in recoverLostAndFound1Step()
15706 recoverFinalize(p, pLaf->pUsedPages); in recoverLostAndFound1Step()
15707 pLaf->pUsedPages = 0; in recoverLostAndFound1Step()
15715 ** state - during which the pages identified in RECOVER_STATE_LOSTANDFOUND1
15719 RecoverStateLAF *pLaf = &p->laf; in recoverLostAndFound2Init()
15721 assert( p->laf.pAllAndParent==0 ); in recoverLostAndFound2Init()
15722 assert( p->laf.pMapInsert==0 ); in recoverLostAndFound2Init()
15723 assert( p->laf.pMaxField==0 ); in recoverLostAndFound2Init()
15724 assert( p->laf.nMaxField==0 ); in recoverLostAndFound2Init()
15726 pLaf->pMapInsert = recoverPrepare(p, p->dbOut, in recoverLostAndFound2Init()
15729 pLaf->pAllAndParent = recoverPreparePrintf(p, p->dbOut, in recoverLostAndFound2Init()
15735 "SELECT NULL, ii FROM seq", p->laf.nPg in recoverLostAndFound2Init()
15737 pLaf->pMaxField = recoverPreparePrintf(p, p->dbOut, in recoverLostAndFound2Init()
15745 ** RECOVER_STATE_LOSTANDFOUND2 state - during which the pages identified
15750 RecoverStateLAF *pLaf = &p->laf; in recoverLostAndFound2Step()
15751 if( p->errCode==SQLITE_OK ){ in recoverLostAndFound2Step()
15752 int res = sqlite3_step(pLaf->pAllAndParent); in recoverLostAndFound2Step()
15754 i64 iChild = sqlite3_column_int(pLaf->pAllAndParent, 1); in recoverLostAndFound2Step()
15755 if( recoverBitmapQuery(pLaf->pUsed, iChild)==0 ){ in recoverLostAndFound2Step()
15756 sqlite3_bind_int64(pLaf->pMapInsert, 1, iChild); in recoverLostAndFound2Step()
15757 sqlite3_bind_value(pLaf->pMapInsert, 2, in recoverLostAndFound2Step()
15758 sqlite3_column_value(pLaf->pAllAndParent, 0) in recoverLostAndFound2Step()
15760 sqlite3_step(pLaf->pMapInsert); in recoverLostAndFound2Step()
15761 recoverReset(p, pLaf->pMapInsert); in recoverLostAndFound2Step()
15762 sqlite3_bind_int64(pLaf->pMaxField, 1, iChild); in recoverLostAndFound2Step()
15763 if( SQLITE_ROW==sqlite3_step(pLaf->pMaxField) ){ in recoverLostAndFound2Step()
15764 int nMax = sqlite3_column_int(pLaf->pMaxField, 0); in recoverLostAndFound2Step()
15765 if( nMax>pLaf->nMaxField ) pLaf->nMaxField = nMax; in recoverLostAndFound2Step()
15767 recoverReset(p, pLaf->pMaxField); in recoverLostAndFound2Step()
15770 recoverFinalize(p, pLaf->pAllAndParent); in recoverLostAndFound2Step()
15771 pLaf->pAllAndParent =0; in recoverLostAndFound2Step()
15775 return p->errCode; in recoverLostAndFound2Step()
15783 recoverBitmapFree(p->laf.pUsed); in recoverLostAndFoundCleanup()
15784 p->laf.pUsed = 0; in recoverLostAndFoundCleanup()
15785 sqlite3_finalize(p->laf.pUsedPages); in recoverLostAndFoundCleanup()
15786 sqlite3_finalize(p->laf.pAllAndParent); in recoverLostAndFoundCleanup()
15787 sqlite3_finalize(p->laf.pMapInsert); in recoverLostAndFoundCleanup()
15788 sqlite3_finalize(p->laf.pMaxField); in recoverLostAndFoundCleanup()
15789 sqlite3_finalize(p->laf.pFindRoot); in recoverLostAndFoundCleanup()
15790 sqlite3_finalize(p->laf.pInsert); in recoverLostAndFoundCleanup()
15791 sqlite3_finalize(p->laf.pAllPage); in recoverLostAndFoundCleanup()
15792 sqlite3_finalize(p->laf.pPageData); in recoverLostAndFoundCleanup()
15793 p->laf.pUsedPages = 0; in recoverLostAndFoundCleanup()
15794 p->laf.pAllAndParent = 0; in recoverLostAndFoundCleanup()
15795 p->laf.pMapInsert = 0; in recoverLostAndFoundCleanup()
15796 p->laf.pMaxField = 0; in recoverLostAndFoundCleanup()
15797 p->laf.pFindRoot = 0; in recoverLostAndFoundCleanup()
15798 p->laf.pInsert = 0; in recoverLostAndFoundCleanup()
15799 p->laf.pAllPage = 0; in recoverLostAndFoundCleanup()
15800 p->laf.pPageData = 0; in recoverLostAndFoundCleanup()
15801 sqlite3_free(p->laf.apVal); in recoverLostAndFoundCleanup()
15802 p->laf.apVal = 0; in recoverLostAndFoundCleanup()
15815 for(pTab=p->pTblList; pTab; pTab=pNext){ in recoverFinalCleanup()
15816 pNext = pTab->pNext; in recoverFinalCleanup()
15819 p->pTblList = 0; in recoverFinalCleanup()
15820 sqlite3_finalize(p->pGetPage); in recoverFinalCleanup()
15821 p->pGetPage = 0; in recoverFinalCleanup()
15822 sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0); in recoverFinalCleanup()
15828 sqlite3_close(p->dbOut); in recoverFinalCleanup()
15831 p->dbOut = 0; in recoverFinalCleanup()
15835 ** Decode and return an unsigned 16-bit big-endian integer value from
15843 ** Decode and return an unsigned 32-bit big-endian integer value from
15868 ** or a prefix thereof appears to contain a well-formed SQLite b-tree page,
15869 ** return the page-size in bytes. Otherwise, if the buffer does not
15870 ** appear to contain a well-formed b-tree page, return 0.
15897 /* Follow the free-list. This is the same format for all b-tree pages. */ in recoverIsValidPage()
15902 if( iFree>(n-4) ) return 0; in recoverIsValidPage()
15933 int X = (eType==0x0D) ? n-35 : (((n-12)*64/255)-23); in recoverIsValidPage()
15934 int M = ((n-12)*32/255)-23; in recoverIsValidPage()
15935 int K = M+((nPayload-M)%(n-4)); in recoverIsValidPage()
16007 assert( pFd->pMethods!=&recover_methods ); in recoverVfsClose()
16008 return pFd->pMethods->xClose(pFd); in recoverVfsClose()
16012 ** Write value v to buffer a[] as a 16-bit big-endian unsigned integer.
16020 ** Write value v to buffer a[] as a 32-bit big-endian unsigned integer.
16030 ** Detect the page-size of the database opened by file-handle pFd by
16031 ** searching the first part of the file for a well-formed SQLite b-tree
16032 ** page. If parameter nReserve is non-zero, then as well as searching for
16033 ** a b-tree page with zero reserved bytes, this function searches for one
16036 ** If successful, set variable p->detected_pgsz to the detected page-size
16038 ** can be found, return SQLITE_OK but leave p->detected_pgsz set to 0. Or,
16040 ** is returned. The final value of p->detected_pgsz is undefined in this
16045 sqlite3_file *pFd, /* File-handle open on input database */ in recoverVfsDetectPagesize()
16063 nBlk = (nSz+nMax-1)/nMax; in recoverVfsDetectPagesize()
16070 rc = pFd->pMethods->xRead(pFd, aPg, nByte, iBlk*nMax); in recoverVfsDetectPagesize()
16076 if( recoverIsValidPage(aTmp, &aPg[iOff], pgsz2-nReserve) ){ in recoverVfsDetectPagesize()
16084 if( pgsz>(u32)p->detected_pgsz ){ in recoverVfsDetectPagesize()
16085 p->detected_pgsz = pgsz; in recoverVfsDetectPagesize()
16086 p->nReserve = nReserve; in recoverVfsDetectPagesize()
16092 p->detected_pgsz = pgsz; in recoverVfsDetectPagesize()
16103 if( pFd->pMethods==&recover_methods ){ in recoverVfsRead()
16104 pFd->pMethods = recover_g.pMethods; in recoverVfsRead()
16105 rc = pFd->pMethods->xRead(pFd, aBuf, nByte, iOff); in recoverVfsRead()
16113 ** + Database page size (16-bits at offset 16) in recoverVfsRead()
16114 ** + Size of db in pages (32-bits at offset 28) in recoverVfsRead()
16115 ** + Database encoding (32-bits at offset 56) in recoverVfsRead()
16119 ** + first freelist page (32-bits at offset 32) in recoverVfsRead()
16120 ** + size of freelist (32-bits at offset 36) in recoverVfsRead()
16121 ** + the wal-mode flags (16-bits at offset 18) in recoverVfsRead()
16123 ** We also try to preserve the auto-vacuum, incr-value, user-version in recoverVfsRead()
16124 ** and application-id fields - all 32 bit quantities at offsets in recoverVfsRead()
16127 ** Byte offset 105 should also contain the page-size as a 16-bit in recoverVfsRead()
16159 rc = pFd->pMethods->xFileSize(pFd, &dbFileSize); in recoverVfsRead()
16161 if( rc==SQLITE_OK && p->detected_pgsz==0 ){ in recoverVfsRead()
16164 if( p->detected_pgsz ){ in recoverVfsRead()
16165 pgsz = p->detected_pgsz; in recoverVfsRead()
16166 nReserve = p->nReserve; in recoverVfsRead()
16176 sqlite3_free(p->pPage1Cache); in recoverVfsRead()
16177 p->pPage1Cache = 0; in recoverVfsRead()
16178 p->pPage1Disk = 0; in recoverVfsRead()
16180 p->pgsz = nByte; in recoverVfsRead()
16181 p->pPage1Cache = (u8*)recoverMalloc(p, nByte*2); in recoverVfsRead()
16182 if( p->pPage1Cache ){ in recoverVfsRead()
16183 p->pPage1Disk = &p->pPage1Cache[nByte]; in recoverVfsRead()
16184 memcpy(p->pPage1Disk, aBuf, nByte); in recoverVfsRead()
16189 recoverPutU16(&aHdr[105], pgsz-nReserve); in recoverVfsRead()
16197 memset(&((u8*)aBuf)[sizeof(aHdr)], 0, nByte-sizeof(aHdr)); in recoverVfsRead()
16199 memcpy(p->pPage1Cache, aBuf, nByte); in recoverVfsRead()
16201 rc = p->errCode; in recoverVfsRead()
16205 pFd->pMethods = &recover_methods; in recoverVfsRead()
16207 rc = pFd->pMethods->xRead(pFd, aBuf, nByte, iOff); in recoverVfsRead()
16217 if( pFd->pMethods==&recover_methods ){ \
16218 pFd->pMethods = recover_g.pMethods; \
16220 pFd->pMethods = &recover_methods; \
16236 pFd->pMethods->xWrite(pFd, aBuf, nByte, iOff) in recoverVfsWrite()
16241 pFd->pMethods->xTruncate(pFd, size) in recoverVfsTruncate()
16246 pFd->pMethods->xSync(pFd, flags) in recoverVfsSync()
16251 pFd->pMethods->xFileSize(pFd, pSize) in recoverVfsFileSize()
16256 pFd->pMethods->xLock(pFd, eLock) in recoverVfsLock()
16261 pFd->pMethods->xUnlock(pFd, eLock) in recoverVfsUnlock()
16266 pFd->pMethods->xCheckReservedLock(pFd, pResOut) in recoverVfsCheckReservedLock()
16271 (pFd->pMethods ? pFd->pMethods->xFileControl(pFd, op, pArg) : SQLITE_NOTFOUND) in recoverVfsFileControl()
16276 pFd->pMethods->xSectorSize(pFd) in recoverVfsSectorSize()
16281 pFd->pMethods->xDeviceCharacteristics(pFd) in recoverVfsDeviceCharacteristics()
16288 pFd->pMethods->xShmMap(pFd, iPg, pgsz, bExtend, pp) in recoverVfsShmMap()
16293 pFd->pMethods->xShmLock(pFd, offset, n, flags) in recoverVfsShmLock()
16297 if( pFd->pMethods==&recover_methods ){ in recoverVfsShmBarrier()
16298 pFd->pMethods = recover_g.pMethods; in recoverVfsShmBarrier()
16299 pFd->pMethods->xShmBarrier(pFd); in recoverVfsShmBarrier()
16300 pFd->pMethods = &recover_methods; in recoverVfsShmBarrier()
16302 pFd->pMethods->xShmBarrier(pFd); in recoverVfsShmBarrier()
16307 pFd->pMethods->xShmUnmap(pFd, deleteFlag) in recoverVfsShmUnmap()
16331 ** Install the VFS wrapper around the file-descriptor open on the input
16339 sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_FILE_POINTER, (void*)&pFd); in recoverInstallWrapper()
16340 assert( pFd==0 || pFd->pMethods!=&recover_methods ); in recoverInstallWrapper()
16341 if( pFd && pFd->pMethods ){ in recoverInstallWrapper()
16342 int iVersion = 1 + (pFd->pMethods->iVersion>1 && pFd->pMethods->xShmMap!=0); in recoverInstallWrapper()
16343 recover_g.pMethods = pFd->pMethods; in recoverInstallWrapper()
16346 pFd->pMethods = &recover_methods; in recoverInstallWrapper()
16351 ** Uninstall the VFS wrapper that was installed around the file-descriptor open
16358 sqlite3_file_control(p->dbIn, p->zDb,SQLITE_FCNTL_FILE_POINTER,(void*)&pFd); in recoverUninstallWrapper()
16359 if( pFd && pFd->pMethods ){ in recoverUninstallWrapper()
16360 pFd->pMethods = recover_g.pMethods; in recoverUninstallWrapper()
16372 assert( p && p->errCode==SQLITE_OK ); in recoverStep()
16373 switch( p->eState ){ in recoverStep()
16388 sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0); in recoverStep()
16389 recoverExec(p, p->dbIn, "PRAGMA writable_schema = on"); in recoverStep()
16390 recoverExec(p, p->dbIn, "BEGIN"); in recoverStep()
16391 if( p->errCode==SQLITE_OK ) p->bCloseTransaction = 1; in recoverStep()
16392 recoverExec(p, p->dbIn, "SELECT 1 FROM sqlite_schema"); in recoverStep()
16400 recoverExec(p, p->dbOut, "BEGIN"); in recoverStep()
16403 p->eState = RECOVER_STATE_WRITING; in recoverStep()
16407 if( p->w1.pTbls==0 ){ in recoverStep()
16412 if( p->zLostAndFound ){ in recoverStep()
16413 p->eState = RECOVER_STATE_LOSTANDFOUND1; in recoverStep()
16415 p->eState = RECOVER_STATE_SCHEMA2; in recoverStep()
16422 if( p->laf.pUsed==0 ){ in recoverStep()
16426 p->eState = RECOVER_STATE_LOSTANDFOUND2; in recoverStep()
16431 if( p->laf.pAllAndParent==0 ){ in recoverStep()
16435 p->eState = RECOVER_STATE_LOSTANDFOUND3; in recoverStep()
16441 if( p->laf.pInsert==0 ){ in recoverStep()
16445 p->eState = RECOVER_STATE_SCHEMA2; in recoverStep()
16454 p->eState = RECOVER_STATE_DONE; in recoverStep()
16459 recoverExec(p, p->dbOut, "COMMIT"); in recoverStep()
16460 rc = sqlite3_exec(p->dbIn, "END", 0, 0, 0); in recoverStep()
16461 if( p->errCode==SQLITE_OK ) p->errCode = rc; in recoverStep()
16465 p->eState = RECOVER_STATE_DONE; in recoverStep()
16471 /* no-op */ in recoverStep()
16510 pRet->dbIn = db; in recoverInit()
16511 pRet->zDb = (char*)&pRet[1]; in recoverInit()
16512 pRet->zUri = &pRet->zDb[nDb+1]; in recoverInit()
16513 memcpy(pRet->zDb, zDb, nDb); in recoverInit()
16514 if( nUri>0 && zUri ) memcpy(pRet->zUri, zUri, nUri); in recoverInit()
16515 pRet->xSql = xSql; in recoverInit()
16516 pRet->pSqlCtx = pSqlCtx; in recoverInit()
16517 pRet->bRecoverRowid = RECOVER_ROWID_DEFAULT; in recoverInit()
16552 return (p && p->errCode!=SQLITE_NOMEM) ? p->zErrMsg : "out of memory"; in sqlite3_recover_errmsg()
16559 return p ? p->errCode : SQLITE_NOMEM; in sqlite3_recover_errcode()
16569 }else if( p->eState!=RECOVER_STATE_INIT ){ in sqlite3_recover_config()
16575 ** name of the auxiliary database that is ATTACH-ed to the database in sqlite3_recover_config()
16579 sqlite3_free(p->zStateDb); in sqlite3_recover_config()
16580 p->zStateDb = recoverMPrintf(p, "%s", (char*)pArg); in sqlite3_recover_config()
16585 sqlite3_free(p->zLostAndFound); in sqlite3_recover_config()
16587 p->zLostAndFound = recoverMPrintf(p, "%s", zArg); in sqlite3_recover_config()
16589 p->zLostAndFound = 0; in sqlite3_recover_config()
16595 p->bFreelistCorrupt = *(int*)pArg; in sqlite3_recover_config()
16599 p->bRecoverRowid = *(int*)pArg; in sqlite3_recover_config()
16603 p->bSlowIndexes = *(int*)pArg; in sqlite3_recover_config()
16623 if( p->errCode==SQLITE_OK ) recoverStep(p); in sqlite3_recover_step()
16624 if( p->eState==RECOVER_STATE_DONE && p->errCode==SQLITE_OK ){ in sqlite3_recover_step()
16627 return p->errCode; in sqlite3_recover_step()
16655 if( p->bCloseTransaction && sqlite3_get_autocommit(p->dbIn)==0 ){ in sqlite3_recover_finish()
16656 rc = sqlite3_exec(p->dbIn, "END", 0, 0, 0); in sqlite3_recover_finish()
16657 if( p->errCode==SQLITE_OK ) p->errCode = rc; in sqlite3_recover_finish()
16659 rc = p->errCode; in sqlite3_recover_finish()
16660 sqlite3_free(p->zErrMsg); in sqlite3_recover_finish()
16661 sqlite3_free(p->zStateDb); in sqlite3_recover_finish()
16662 sqlite3_free(p->zLostAndFound); in sqlite3_recover_finish()
16663 sqlite3_free(p->pPage1Cache); in sqlite3_recover_finish()
16736 u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
16740 u8 bSafeModePersist; /* The long-term value of bSafeMode */
16765 sqlite3_int64 szMax; /* --maxsize argument to .open */
16794 char *zNonce; /* Nonce for temporary safe-mode excapes */
16820 #define SHELL_OPEN_UNSPEC 0 /* No open-mode specified */
16824 #define SHELL_OPEN_READONLY 4 /* Open a normal database read-only */
16838 ** top-level SQL statement */
16839 #define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */
16844 #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
16846 #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
16848 #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
16850 #define SHFLG_Echo 0x00000040 /* .echo on/off, or --echo setting */
16859 #define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
16860 #define ShellSetFlag(P,X) ((P)->shellFlgs|=(X))
16861 #define ShellClearFlag(P,X) ((P)->shellFlgs&=(~(X)))
16873 #define MODE_Tcl 7 /* Generate ANSI-C or TCL quoted elements */
16877 #define MODE_Pretty 11 /* Pretty-print schemas */
16881 #define MODE_Table 15 /* MySQL-style table formatting */
16882 #define MODE_Box 16 /* Unicode box-drawing characters */
16932 if( p->pLog==0 ) return; in shellLog()
16933 utf8_printf(p->pLog, "(%d) %s\n", iErrCode, zMsg); in shellLog()
16934 fflush(p->pLog); in shellLog()
16950 utf8_printf(p->out, "%s\n", sqlite3_value_text(apVal[0])); in shellPutsFunc()
16963 if( p->bSafeMode ){ in failIfSafeMode()
16969 raw_printf(stderr, "line %d: ", p->lineno); in failIfSafeMode()
16989 ** Also throw an error if the EDITOR program returns a non-zero exit code.
17015 sqlite3_result_error(context, "no editor for edit()", -1); in editFunc()
17019 sqlite3_result_error(context, "NULL input to edit()", -1); in editFunc()
17039 sqlite3_result_error(context, "edit() cannot open temp file", -1); in editFunc()
17054 sqlite3_result_error(context, "edit() could not write the whole file", -1); in editFunc()
17065 sqlite3_result_error(context, "EDITOR returned non-zero", -1); in editFunc()
17071 "edit() cannot reopen temp file after edit", -1); in editFunc()
17086 sqlite3_result_error(context, "could not read back the whole file", -1); in editFunc()
17123 p->modePrior = p->mode; in outputModePush()
17124 p->priorShFlgs = p->shellFlgs; in outputModePush()
17125 memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator)); in outputModePush()
17126 memcpy(p->rowSepPrior, p->rowSeparator, sizeof(p->rowSeparator)); in outputModePush()
17129 p->mode = p->modePrior; in outputModePop()
17130 p->shellFlgs = p->priorShFlgs; in outputModePop()
17131 memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator)); in outputModePop()
17132 memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator)); in outputModePop()
17136 ** Output the given string as a hex-encoded blob (eg. X'1234' )
17219 ** get corrupted by end-of-line translation facilities in some operating
17322 while( n-- ){ in output_json_string()
17408 ** Output a single term of CSV. Actually, p->colSeparator is used for
17409 ** the separator, which may or may not be a comma. p->nullValue is
17414 FILE *out = p->out; in output_csv()
17416 utf8_printf(out,"%s",p->nullValue); in output_csv()
17425 if( i==0 || strstr(z, p->colSeparator)!=0 ){ in output_csv()
17435 utf8_printf(p->out, "%s", p->colSeparator); in output_csv()
17440 ** This routine runs when the user presses Ctrl-C
17450 ** This routine runs for console events (e.g. Ctrl-C) on Win32
17543 utf8_printf(p->out, "authorizer: %s", azAction[op]); in shellAuth()
17545 raw_printf(p->out, " "); in shellAuth()
17547 output_c_string(p->out, az[i]); in shellAuth()
17549 raw_printf(p->out, "NULL"); in shellAuth()
17552 raw_printf(p->out, "\n"); in shellAuth()
17553 if( p->bSafeMode ) (void)safeModeAuth(pClientData, op, zA1, zA2, zA3, zA4); in shellAuth()
17564 ** If the schema statement in z[] contains a start-of-comment and if
17572 if( zTail[0]==';' && (strstr(z, "/*")!=0 || strstr(z,"--")!=0) ){ in printSchemaLine()
17581 zNew[n-1] = 0; in printSchemaLine()
17612 if( z[i]=='-' && z[i+1]=='-' ) return 1; in wsToEol()
17626 if( p->autoEQPtest ){ in eqp_append()
17627 utf8_printf(p->out, "%d,%d,%s\n", iEqpId, p2, zText); in eqp_append()
17631 pNew->iEqpId = iEqpId; in eqp_append()
17632 pNew->iParentId = p2; in eqp_append()
17633 memcpy(pNew->zText, zText, nText+1); in eqp_append()
17634 pNew->pNext = 0; in eqp_append()
17635 if( p->sGraph.pLast ){ in eqp_append()
17636 p->sGraph.pLast->pNext = pNew; in eqp_append()
17638 p->sGraph.pRow = pNew; in eqp_append()
17640 p->sGraph.pLast = pNew; in eqp_append()
17645 ** in p->sGraph.
17649 for(pRow = p->sGraph.pRow; pRow; pRow = pNext){ in eqp_reset()
17650 pNext = pRow->pNext; in eqp_reset()
17653 memset(&p->sGraph, 0, sizeof(p->sGraph)); in eqp_reset()
17660 EQPGraphRow *pRow = pOld ? pOld->pNext : p->sGraph.pRow; in eqp_next_row()
17661 while( pRow && pRow->iParentId!=iEqpId ) pRow = pRow->pNext; in eqp_next_row()
17670 i64 n = strlen(p->sGraph.zPrefix); in eqp_render_level()
17674 z = pRow->zText; in eqp_render_level()
17675 utf8_printf(p->out, "%s%s%s\n", p->sGraph.zPrefix, in eqp_render_level()
17676 pNext ? "|--" : "`--", z); in eqp_render_level()
17677 if( n<(i64)sizeof(p->sGraph.zPrefix)-7 ){ in eqp_render_level()
17678 memcpy(&p->sGraph.zPrefix[n], pNext ? "| " : " ", 4); in eqp_render_level()
17679 eqp_render_level(p, pRow->iEqpId); in eqp_render_level()
17680 p->sGraph.zPrefix[n] = 0; in eqp_render_level()
17689 EQPGraphRow *pRow = p->sGraph.pRow; in eqp_render()
17691 if( pRow->zText[0]=='-' ){ in eqp_render()
17692 if( pRow->pNext==0 ){ in eqp_render()
17696 utf8_printf(p->out, "%s\n", pRow->zText+3); in eqp_render()
17697 p->sGraph.pRow = pRow->pNext; in eqp_render()
17700 utf8_printf(p->out, "QUERY PLAN (cycles=%lld [100%%])\n", nCycle); in eqp_render()
17702 utf8_printf(p->out, "QUERY PLAN\n"); in eqp_render()
17704 p->sGraph.zPrefix[0] = 0; in eqp_render()
17716 p->nProgress++; in progress_handler()
17717 if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){ in progress_handler()
17718 raw_printf(p->out, "Progress limit reached (%u)\n", p->nProgress); in progress_handler()
17719 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0; in progress_handler()
17720 if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0; in progress_handler()
17723 if( (p->flgProgress & SHELL_PROGRESS_QUIET)==0 ){ in progress_handler()
17724 raw_printf(p->out, "Progress %u\n", p->nProgress); in progress_handler()
17734 const char zDash[] = "--------------------------------------------------"; in print_dashes()
17735 const int nDash = sizeof(zDash) - 1; in print_dashes()
17738 N -= nDash; in print_dashes()
17744 ** Print a markdown or table-style row separator using ascii-art
17753 fputs(zSep, p->out); in print_row_separator()
17754 print_dashes(p->out, p->actualWidth[0]+2); in print_row_separator()
17756 fputs(zSep, p->out); in print_row_separator()
17757 print_dashes(p->out, p->actualWidth[i]+2); in print_row_separator()
17759 fputs(zSep, p->out); in print_row_separator()
17761 fputs("\n", p->out); in print_row_separator()
17779 switch( p->cMode ){ in shell_callback()
17791 if( p->cnt++>0 ) utf8_printf(p->out, "%s", p->rowSeparator); in shell_callback()
17793 utf8_printf(p->out,"%*s = %s%s", w, azCol[i], in shell_callback()
17794 azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator); in shell_callback()
17803 if( p->cnt++==0 ){ in shell_callback()
17806 utf8_width_print(p->out, w, azCol[i]); in shell_callback()
17807 fputs(i==nArg-1 ? "\n" : " ", p->out); in shell_callback()
17811 print_dashes(p->out, w); in shell_callback()
17812 fputs(i==nArg-1 ? "\n" : " ", p->out); in shell_callback()
17818 if( i==nArg-1 ) w = 0; in shell_callback()
17822 if( i==1 && p->aiIndent && p->pStmt ){ in shell_callback()
17823 if( p->iIndent<p->nIndent ){ in shell_callback()
17824 utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], ""); in shell_callback()
17826 p->iIndent++; in shell_callback()
17828 utf8_width_print(p->out, w, azArg[i] ? azArg[i] : p->nullValue); in shell_callback()
17829 fputs(i==nArg-1 ? "\n" : " ", p->out); in shell_callback()
17834 printSchemaLine(p->out, azArg[0], ";\n"); in shell_callback()
17837 case MODE_Pretty: { /* .schema and .fullschema with --indent */ in shell_callback()
17849 utf8_printf(p->out, "%s;\n", azArg[0]); in shell_callback()
17858 if( z[j-1]=='\r' ) z[j-1] = '\n'; in shell_callback()
17859 if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue; in shell_callback()
17860 }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){ in shell_callback()
17861 j--; in shell_callback()
17865 while( j>0 && IsSpace(z[j-1]) ){ j--; } in shell_callback()
17875 }else if( c=='-' && z[i+1]=='-' ){ in shell_callback()
17880 nParen--; in shell_callback()
17882 printSchemaLineN(p->out, z, j, "\n"); in shell_callback()
17890 if( c=='\n' ) j--; in shell_callback()
17891 printSchemaLineN(p->out, z, j, "\n "); in shell_callback()
17899 printSchemaLine(p->out, z, ";\n"); in shell_callback()
17904 if( p->cnt++==0 && p->showHeader ){ in shell_callback()
17906 utf8_printf(p->out,"%s%s",azCol[i], in shell_callback()
17907 i==nArg-1 ? p->rowSeparator : p->colSeparator); in shell_callback()
17913 if( z==0 ) z = p->nullValue; in shell_callback()
17914 utf8_printf(p->out, "%s", z); in shell_callback()
17915 if( i<nArg-1 ){ in shell_callback()
17916 utf8_printf(p->out, "%s", p->colSeparator); in shell_callback()
17918 utf8_printf(p->out, "%s", p->rowSeparator); in shell_callback()
17924 if( p->cnt++==0 && p->showHeader ){ in shell_callback()
17925 raw_printf(p->out,"<TR>"); in shell_callback()
17927 raw_printf(p->out,"<TH>"); in shell_callback()
17928 output_html_string(p->out, azCol[i]); in shell_callback()
17929 raw_printf(p->out,"</TH>\n"); in shell_callback()
17931 raw_printf(p->out,"</TR>\n"); in shell_callback()
17934 raw_printf(p->out,"<TR>"); in shell_callback()
17936 raw_printf(p->out,"<TD>"); in shell_callback()
17937 output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue); in shell_callback()
17938 raw_printf(p->out,"</TD>\n"); in shell_callback()
17940 raw_printf(p->out,"</TR>\n"); in shell_callback()
17944 if( p->cnt++==0 && p->showHeader ){ in shell_callback()
17946 output_c_string(p->out,azCol[i] ? azCol[i] : ""); in shell_callback()
17947 if(i<nArg-1) utf8_printf(p->out, "%s", p->colSeparator); in shell_callback()
17949 utf8_printf(p->out, "%s", p->rowSeparator); in shell_callback()
17953 output_c_string(p->out, azArg[i] ? azArg[i] : p->nullValue); in shell_callback()
17954 if(i<nArg-1) utf8_printf(p->out, "%s", p->colSeparator); in shell_callback()
17956 utf8_printf(p->out, "%s", p->rowSeparator); in shell_callback()
17960 setBinaryMode(p->out, 1); in shell_callback()
17961 if( p->cnt++==0 && p->showHeader ){ in shell_callback()
17963 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1); in shell_callback()
17965 utf8_printf(p->out, "%s", p->rowSeparator); in shell_callback()
17969 output_csv(p, azArg[i], i<nArg-1); in shell_callback()
17971 utf8_printf(p->out, "%s", p->rowSeparator); in shell_callback()
17973 setTextMode(p->out, 1); in shell_callback()
17978 utf8_printf(p->out,"INSERT INTO %s",p->zDestTable); in shell_callback()
17979 if( p->showHeader ){ in shell_callback()
17980 raw_printf(p->out,"("); in shell_callback()
17982 if( i>0 ) raw_printf(p->out, ","); in shell_callback()
17986 utf8_printf(p->out, "%s", z); in shell_callback()
17989 raw_printf(p->out, "%s", azCol[i]); in shell_callback()
17992 raw_printf(p->out,")"); in shell_callback()
17994 p->cnt++; in shell_callback()
17996 raw_printf(p->out, i>0 ? "," : " VALUES("); in shell_callback()
17998 utf8_printf(p->out,"NULL"); in shell_callback()
18001 output_quoted_string(p->out, azArg[i]); in shell_callback()
18003 output_quoted_escaped_string(p->out, azArg[i]); in shell_callback()
18006 utf8_printf(p->out,"%s", azArg[i]); in shell_callback()
18009 double r = sqlite3_column_double(p->pStmt, i); in shell_callback()
18013 raw_printf(p->out, "9.0e+999"); in shell_callback()
18015 raw_printf(p->out, "-9.0e+999"); in shell_callback()
18023 raw_printf(p->out, "%s", z); in shell_callback()
18025 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ in shell_callback()
18026 const void *pBlob = sqlite3_column_blob(p->pStmt, i); in shell_callback()
18027 int nBlob = sqlite3_column_bytes(p->pStmt, i); in shell_callback()
18028 output_hex_blob(p->out, pBlob, nBlob); in shell_callback()
18030 utf8_printf(p->out,"%s", azArg[i]); in shell_callback()
18032 output_quoted_string(p->out, azArg[i]); in shell_callback()
18034 output_quoted_escaped_string(p->out, azArg[i]); in shell_callback()
18037 raw_printf(p->out,");\n"); in shell_callback()
18042 if( p->cnt==0 ){ in shell_callback()
18043 fputs("[{", p->out); in shell_callback()
18045 fputs(",\n{", p->out); in shell_callback()
18047 p->cnt++; in shell_callback()
18049 output_json_string(p->out, azCol[i], -1); in shell_callback()
18050 putc(':', p->out); in shell_callback()
18052 fputs("null",p->out); in shell_callback()
18055 double r = sqlite3_column_double(p->pStmt, i); in shell_callback()
18059 raw_printf(p->out, "9.0e+999"); in shell_callback()
18061 raw_printf(p->out, "-9.0e+999"); in shell_callback()
18064 raw_printf(p->out, "%s", z); in shell_callback()
18066 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ in shell_callback()
18067 const void *pBlob = sqlite3_column_blob(p->pStmt, i); in shell_callback()
18068 int nBlob = sqlite3_column_bytes(p->pStmt, i); in shell_callback()
18069 output_json_string(p->out, pBlob, nBlob); in shell_callback()
18071 output_json_string(p->out, azArg[i], -1); in shell_callback()
18073 utf8_printf(p->out,"%s", azArg[i]); in shell_callback()
18075 if( i<nArg-1 ){ in shell_callback()
18076 putc(',', p->out); in shell_callback()
18079 putc('}', p->out); in shell_callback()
18084 if( p->cnt==0 && p->showHeader ){ in shell_callback()
18086 if( i>0 ) fputs(p->colSeparator, p->out); in shell_callback()
18087 output_quoted_string(p->out, azCol[i]); in shell_callback()
18089 fputs(p->rowSeparator, p->out); in shell_callback()
18091 p->cnt++; in shell_callback()
18093 if( i>0 ) fputs(p->colSeparator, p->out); in shell_callback()
18095 utf8_printf(p->out,"NULL"); in shell_callback()
18097 output_quoted_string(p->out, azArg[i]); in shell_callback()
18099 utf8_printf(p->out,"%s", azArg[i]); in shell_callback()
18102 double r = sqlite3_column_double(p->pStmt, i); in shell_callback()
18104 raw_printf(p->out, "%s", z); in shell_callback()
18105 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ in shell_callback()
18106 const void *pBlob = sqlite3_column_blob(p->pStmt, i); in shell_callback()
18107 int nBlob = sqlite3_column_bytes(p->pStmt, i); in shell_callback()
18108 output_hex_blob(p->out, pBlob, nBlob); in shell_callback()
18110 utf8_printf(p->out,"%s", azArg[i]); in shell_callback()
18112 output_quoted_string(p->out, azArg[i]); in shell_callback()
18115 fputs(p->rowSeparator, p->out); in shell_callback()
18119 if( p->cnt++==0 && p->showHeader ){ in shell_callback()
18121 if( i>0 ) utf8_printf(p->out, "%s", p->colSeparator); in shell_callback()
18122 utf8_printf(p->out,"%s",azCol[i] ? azCol[i] : ""); in shell_callback()
18124 utf8_printf(p->out, "%s", p->rowSeparator); in shell_callback()
18128 if( i>0 ) utf8_printf(p->out, "%s", p->colSeparator); in shell_callback()
18129 utf8_printf(p->out,"%s",azArg[i] ? azArg[i] : p->nullValue); in shell_callback()
18131 utf8_printf(p->out, "%s", p->rowSeparator); in shell_callback()
18160 if( p->n ) appendText(p, "|", 0); in captureOutputCallback()
18173 sqlite3_exec(p->db, in createSelftestTable()
18184 " 'memo','Tests generated by --init');\n" in createSelftestTable()
18213 sqlite3_exec(p->db, "RELEASE selftest_init",0,0,0); in createSelftestTable()
18227 if( p->zDestTable ){ in set_table_name()
18228 free(p->zDestTable); in set_table_name()
18229 p->zDestTable = 0; in set_table_name()
18235 z = p->zDestTable = malloc( n+1 ); in set_table_name()
18270 iOffset--; in shell_error_context()
18272 while( (zSql[0]&0xc0)==0x80 ){ zSql++; iOffset--; } in shell_error_context()
18277 while( len>0 && (zSql[len]&0xc0)==0x80 ) len--; in shell_error_context()
18283 zMsg = sqlite3_mprintf("\n %z\n %*s^--- error here", zCode,iOffset,""); in shell_error_context()
18285 zMsg = sqlite3_mprintf("\n %z\n %*serror here ---^", zCode,iOffset-14,""); in shell_error_context()
18293 ** the result columns, comma-separated, on a line and then add a
18296 ** If the number of columns is 1 and that column contains text "--"
18298 ** "--" comment occurs at the end of the statement, the comment
18310 rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0); in run_table_dump_query()
18312 char *zContext = shell_error_context(zSelect, p->db); in run_table_dump_query()
18313 utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n%s", rc, in run_table_dump_query()
18314 sqlite3_errmsg(p->db), zContext); in run_table_dump_query()
18316 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; in run_table_dump_query()
18323 utf8_printf(p->out, "%s", z); in run_table_dump_query()
18325 utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i)); in run_table_dump_query()
18328 while( z[0] && (z[0]!='-' || z[1]!='-') ) z++; in run_table_dump_query()
18330 raw_printf(p->out, "\n;\n"); in run_table_dump_query()
18332 raw_printf(p->out, ";\n"); in run_table_dump_query()
18338 utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, in run_table_dump_query()
18339 sqlite3_errmsg(p->db)); in run_table_dump_query()
18340 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; in run_table_dump_query()
18398 utf8_printf(out, "%-36s %s", aTrans[i].zDesc, &z[n]); in displayLinuxIoStats()
18408 ** Display a single line of status using 64-bit values.
18417 sqlite3_int64 iCur = -1; in displayStatLine()
18418 sqlite3_int64 iHiwtr = -1; in displayStatLine()
18430 raw_printf(p->out, "%-36s %s\n", zLabel, zLine); in displayStatLine()
18444 if( pArg==0 || pArg->out==0 ) return 0; in display_stats()
18445 out = pArg->out; in display_stats()
18447 if( pArg->pStmt && pArg->statsOn==2 ){ in display_stats()
18449 sqlite3_stmt *pStmt = pArg->pStmt; in display_stats()
18452 raw_printf(out, "%-36s %d\n", "Number of output columns:", nCol); in display_stats()
18455 utf8_printf(out, "%-36s %s\n", z, sqlite3_column_name(pStmt,i)); in display_stats()
18458 utf8_printf(out, "%-36s %s\n", z, sqlite3_column_decltype(pStmt, i)); in display_stats()
18462 utf8_printf(out, "%-36s %s\n", z, sqlite3_column_database_name(pStmt,i)); in display_stats()
18464 utf8_printf(out, "%-36s %s\n", z, sqlite3_column_table_name(pStmt,i)); in display_stats()
18466 utf8_printf(out, "%-36s %s\n", z, sqlite3_column_origin_name(pStmt,i)); in display_stats()
18471 if( pArg->statsOn==3 ){ in display_stats()
18472 if( pArg->pStmt ){ in display_stats()
18473 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP,bReset); in display_stats()
18474 raw_printf(pArg->out, "VM-steps: %d\n", iCur); in display_stats()
18483 if( pArg->shellFlgs & SHFLG_Pagecache ){ in display_stats()
18499 if( pArg->shellFlgs & SHFLG_Lookaside ){ in display_stats()
18500 iHiwtr = iCur = -1; in display_stats()
18503 raw_printf(pArg->out, in display_stats()
18508 raw_printf(pArg->out, "Successful lookaside attempts: %d\n", in display_stats()
18512 raw_printf(pArg->out, "Lookaside failures due to size: %d\n", in display_stats()
18516 raw_printf(pArg->out, "Lookaside failures due to OOM: %d\n", in display_stats()
18519 iHiwtr = iCur = -1; in display_stats()
18521 raw_printf(pArg->out, "Pager Heap Usage: %d bytes\n", in display_stats()
18523 iHiwtr = iCur = -1; in display_stats()
18525 raw_printf(pArg->out, "Page cache hits: %d\n", iCur); in display_stats()
18526 iHiwtr = iCur = -1; in display_stats()
18528 raw_printf(pArg->out, "Page cache misses: %d\n", iCur); in display_stats()
18529 iHiwtr = iCur = -1; in display_stats()
18531 raw_printf(pArg->out, "Page cache writes: %d\n", iCur); in display_stats()
18532 iHiwtr = iCur = -1; in display_stats()
18534 raw_printf(pArg->out, "Page cache spills: %d\n", iCur); in display_stats()
18535 iHiwtr = iCur = -1; in display_stats()
18537 raw_printf(pArg->out, "Schema Heap Usage: %d bytes\n", in display_stats()
18539 iHiwtr = iCur = -1; in display_stats()
18541 raw_printf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n", in display_stats()
18545 if( pArg->pStmt ){ in display_stats()
18547 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, in display_stats()
18549 raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur); in display_stats()
18550 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset); in display_stats()
18551 raw_printf(pArg->out, "Sort Operations: %d\n", iCur); in display_stats()
18552 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset); in display_stats()
18553 raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur); in display_stats()
18554 iHit = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_HIT, in display_stats()
18556 iMiss = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_MISS, in display_stats()
18559 raw_printf(pArg->out, "Bloom filter bypass taken: %d/%d\n", in display_stats()
18562 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset); in display_stats()
18563 raw_printf(pArg->out, "Virtual Machine Steps: %d\n", iCur); in display_stats()
18564 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_REPREPARE,bReset); in display_stats()
18565 raw_printf(pArg->out, "Reprepare operations: %d\n", iCur); in display_stats()
18566 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_RUN, bReset); in display_stats()
18567 raw_printf(pArg->out, "Number of times run: %d\n", iCur); in display_stats()
18568 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_MEMUSED, bReset); in display_stats()
18569 raw_printf(pArg->out, "Memory used by prepared stmt: %d\n", iCur); in display_stats()
18573 displayLinuxIoStats(pArg->out); in display_stats()
18576 /* Do not remove this machine readable comment: extra-stats-output-here */ in display_stats()
18622 sqlite3_stmt *p = pArg->pStmt; in display_scanstats()
18639 sqlite3_stmt_scanstatus_v2(p, -1, SQLITE_SCANSTAT_NCYCLE, f, (void*)&nTotal); in display_scanstats()
18677 if( zName && pArg->scanstatsOn>1 ){ in display_scanstats()
18683 "% *z (%z)", -1*(nWidth-scanStatsHeight(p, ii)*3), zText, z in display_scanstats()
18696 ** Parameter azArray points to a zero-terminated array of strings. zStr
18697 ** points to a single nul-terminated string. Return non-zero if zStr
18721 ** See tag-20220407a in wherecode.c and vdbe.c.
18734 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */ in explain_data_prepare()
18735 int iOp; /* Index of operation in p->aiIndent[] */ in explain_data_prepare()
18746 p->cMode = p->mode; in explain_data_prepare()
18753 p->cMode = p->mode; in explain_data_prepare()
18765 ** the current instruction is part of a sub-program generated by an in explain_data_prepare()
18768 int p2op = (p2 + (iOp-iAddr)); in explain_data_prepare()
18770 /* Grow the p->aiIndent array as required */ in explain_data_prepare()
18780 p->cMode = p->mode; in explain_data_prepare()
18787 p->aiIndent = (int*)sqlite3_realloc64(p->aiIndent, nAlloc*sizeof(int)); in explain_data_prepare()
18788 shell_check_oom(p->aiIndent); in explain_data_prepare()
18793 p->aiIndent[iOp] = 0; in explain_data_prepare()
18794 p->nIndent = iOp+1; in explain_data_prepare()
18797 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2; in explain_data_prepare()
18799 if( str_in_array(zOp, azGoto) && p2op<p->nIndent in explain_data_prepare()
18802 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2; in explain_data_prepare()
18806 p->iIndent = 0; in explain_data_prepare()
18815 sqlite3_free(p->aiIndent); in explain_data_delete()
18816 p->aiIndent = 0; in explain_data_delete()
18817 p->nIndent = 0; in explain_data_delete()
18818 p->iIndent = 0; in explain_data_delete()
18842 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode); in bind_table_init()
18843 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0); in bind_table_init()
18844 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema); in bind_table_init()
18845 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0); in bind_table_init()
18846 sqlite3_exec(p->db, in bind_table_init()
18852 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0); in bind_table_init()
18853 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0); in bind_table_init()
18876 if( sqlite3_table_column_metadata(pArg->db, "TEMP", "sqlite_parameters", in bind_prepared_stmt()
18881 rc = sqlite3_prepare_v2(pArg->db, in bind_prepared_stmt()
18883 " WHERE key=?1", -1, &pQ, 0); in bind_prepared_stmt()
18892 sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC); in bind_prepared_stmt()
18912 ** UTF8 box-drawing characters. Imagine box lines like this:
18916 ** 4 --+-- 2
18924 #define BOX_24 "\342\224\200" /* U+2500 --- */
18926 #define BOX_23 "\342\224\214" /* U+250c ,- */
18927 #define BOX_34 "\342\224\220" /* U+2510 -, */
18928 #define BOX_12 "\342\224\224" /* U+2514 '- */
18929 #define BOX_14 "\342\224\230" /* U+2518 -' */
18930 #define BOX_123 "\342\224\234" /* U+251c |- */
18931 #define BOX_134 "\342\224\244" /* U+2524 -| */
18932 #define BOX_234 "\342\224\254" /* U+252c -,- */
18933 #define BOX_124 "\342\224\264" /* U+2534 -'- */
18934 #define BOX_1234 "\342\224\274" /* U+253c -|- */
18943 const int nDash = sizeof(zDash) - 1; in print_box_line()
18947 N -= nDash; in print_box_line()
18964 utf8_printf(p->out, "%s", zSep1); in print_box_row_separator()
18965 print_box_line(p->out, p->actualWidth[0]+2); in print_box_row_separator()
18967 utf8_printf(p->out, "%s", zSep2); in print_box_row_separator()
18968 print_box_line(p->out, p->actualWidth[i]+2); in print_box_row_separator()
18970 utf8_printf(p->out, "%s", zSep3); in print_box_row_separator()
18972 fputs("\n", p->out); in print_box_row_separator()
18990 u8 bWordWrap /* If true, avoid breaking mid-word */ in translateForDisplayAndDup()
19002 if( mxWidth<0 ) mxWidth = -mxWidth; in translateForDisplayAndDup()
19023 for(k=i; k>i/2; k--){ in translateForDisplayAndDup()
19024 if( isspace(z[k-1]) ) break; in translateForDisplayAndDup()
19027 for(k=i; k>i/2; k--){ in translateForDisplayAndDup()
19028 if( isalnum(z[k-1])!=isalnum(z[k]) && (z[k]&0xc0)!=0x80 ) break; in translateForDisplayAndDup()
19072 /* Extract the value of the i-th current column for pStmt as an SQL literal
19106 ** table-oriented formats: MODE_Column, MODE_Markdown, MODE_Table,
19134 int bw = p->cmOpts.bWordWrap; in exec_prepared_stmt_columnar()
19136 const char *zShowNull = p->nullValue; in exec_prepared_stmt_columnar()
19148 if( p->cmOpts.bQuote ){ in exec_prepared_stmt_columnar()
19155 if( nColumn>p->nWidth ){ in exec_prepared_stmt_columnar()
19156 p->colWidth = realloc(p->colWidth, (nColumn+1)*2*sizeof(int)); in exec_prepared_stmt_columnar()
19157 shell_check_oom(p->colWidth); in exec_prepared_stmt_columnar()
19158 for(i=p->nWidth; i<nColumn; i++) p->colWidth[i] = 0; in exec_prepared_stmt_columnar()
19159 p->nWidth = nColumn; in exec_prepared_stmt_columnar()
19160 p->actualWidth = &p->colWidth[nColumn]; in exec_prepared_stmt_columnar()
19162 memset(p->actualWidth, 0, nColumn*sizeof(int)); in exec_prepared_stmt_columnar()
19164 w = p->colWidth[i]; in exec_prepared_stmt_columnar()
19165 if( w<0 ) w = -w; in exec_prepared_stmt_columnar()
19166 p->actualWidth[i] = w; in exec_prepared_stmt_columnar()
19170 int wx = p->colWidth[i]; in exec_prepared_stmt_columnar()
19172 wx = p->cmOpts.iWrap; in exec_prepared_stmt_columnar()
19174 if( wx<0 ) wx = -wx; in exec_prepared_stmt_columnar()
19192 int wx = p->colWidth[i]; in exec_prepared_stmt_columnar()
19194 wx = p->cmOpts.iWrap; in exec_prepared_stmt_columnar()
19196 if( wx<0 ) wx = -wx; in exec_prepared_stmt_columnar()
19200 }else if( p->cmOpts.bQuote ){ in exec_prepared_stmt_columnar()
19212 abRowDiv[nRow-1] = 0; in exec_prepared_stmt_columnar()
19223 if( n>p->actualWidth[j] ) p->actualWidth[j] = n; in exec_prepared_stmt_columnar()
19227 switch( p->cMode ){ in exec_prepared_stmt_columnar()
19231 if( p->showHeader ){ in exec_prepared_stmt_columnar()
19233 w = p->actualWidth[i]; in exec_prepared_stmt_columnar()
19234 if( p->colWidth[i]<0 ) w = -w; in exec_prepared_stmt_columnar()
19235 utf8_width_print(p->out, w, azData[i]); in exec_prepared_stmt_columnar()
19236 fputs(i==nColumn-1?"\n":" ", p->out); in exec_prepared_stmt_columnar()
19239 print_dashes(p->out, p->actualWidth[i]); in exec_prepared_stmt_columnar()
19240 fputs(i==nColumn-1?"\n":" ", p->out); in exec_prepared_stmt_columnar()
19249 fputs("| ", p->out); in exec_prepared_stmt_columnar()
19251 w = p->actualWidth[i]; in exec_prepared_stmt_columnar()
19253 utf8_printf(p->out, "%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, ""); in exec_prepared_stmt_columnar()
19254 fputs(i==nColumn-1?" |\n":" | ", p->out); in exec_prepared_stmt_columnar()
19262 fputs("| ", p->out); in exec_prepared_stmt_columnar()
19264 w = p->actualWidth[i]; in exec_prepared_stmt_columnar()
19266 utf8_printf(p->out, "%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, ""); in exec_prepared_stmt_columnar()
19267 fputs(i==nColumn-1?" |\n":" | ", p->out); in exec_prepared_stmt_columnar()
19276 utf8_printf(p->out, BOX_13 " "); in exec_prepared_stmt_columnar()
19278 w = p->actualWidth[i]; in exec_prepared_stmt_columnar()
19280 utf8_printf(p->out, "%*s%s%*s%s", in exec_prepared_stmt_columnar()
19281 (w-n)/2, "", azData[i], (w-n+1)/2, "", in exec_prepared_stmt_columnar()
19282 i==nColumn-1?" "BOX_13"\n":" "BOX_13" "); in exec_prepared_stmt_columnar()
19289 if( j==0 && p->cMode!=MODE_Column ){ in exec_prepared_stmt_columnar()
19290 utf8_printf(p->out, "%s", p->cMode==MODE_Box?BOX_13" ":"| "); in exec_prepared_stmt_columnar()
19293 if( z==0 ) z = p->nullValue; in exec_prepared_stmt_columnar()
19294 w = p->actualWidth[j]; in exec_prepared_stmt_columnar()
19295 if( p->colWidth[j]<0 ) w = -w; in exec_prepared_stmt_columnar()
19296 utf8_width_print(p->out, w, z); in exec_prepared_stmt_columnar()
19297 if( j==nColumn-1 ){ in exec_prepared_stmt_columnar()
19298 utf8_printf(p->out, "%s", rowSep); in exec_prepared_stmt_columnar()
19299 if( bMultiLineRowExists && abRowDiv[i/nColumn-1] && i+1<nTotal ){ in exec_prepared_stmt_columnar()
19300 if( p->cMode==MODE_Table ){ in exec_prepared_stmt_columnar()
19302 }else if( p->cMode==MODE_Box ){ in exec_prepared_stmt_columnar()
19304 }else if( p->cMode==MODE_Column ){ in exec_prepared_stmt_columnar()
19305 raw_printf(p->out, "\n"); in exec_prepared_stmt_columnar()
19308 j = -1; in exec_prepared_stmt_columnar()
19311 utf8_printf(p->out, "%s", colSep); in exec_prepared_stmt_columnar()
19314 if( p->cMode==MODE_Table ){ in exec_prepared_stmt_columnar()
19316 }else if( p->cMode==MODE_Box ){ in exec_prepared_stmt_columnar()
19321 utf8_printf(p->out, "Interrupt\n"); in exec_prepared_stmt_columnar()
19347 if( pArg->cMode==MODE_Column in exec_prepared_stmt()
19348 || pArg->cMode==MODE_Table in exec_prepared_stmt()
19349 || pArg->cMode==MODE_Box in exec_prepared_stmt()
19350 || pArg->cMode==MODE_Markdown in exec_prepared_stmt()
19384 && (pArg->cMode==MODE_Insert || pArg->cMode==MODE_Quote) in exec_prepared_stmt()
19407 if( pArg->cMode==MODE_Json ){ in exec_prepared_stmt()
19408 fputs("]\n", pArg->out); in exec_prepared_stmt()
19409 }else if( pArg->cMode==MODE_Count ){ in exec_prepared_stmt()
19435 assert( pState->expert.pExpert ); in expertHandleSQL()
19437 return sqlite3_expert_sql(pState->expert.pExpert, zSql, pzErr); in expertHandleSQL()
19456 sqlite3expert *p = pState->expert.pExpert; in expertFinish()
19460 FILE *out = pState->out; in expertFinish()
19461 int bVerbose = pState->expert.bVerbose; in expertFinish()
19470 raw_printf(out, "-- Candidates -----------------------------\n"); in expertFinish()
19479 raw_printf(out, "-- Query %d --------------------------------\n",i+1); in expertFinish()
19488 pState->expert.pExpert = 0; in expertFinish()
19505 assert( pState->expert.pExpert==0 ); in expertDotCommand()
19506 memset(&pState->expert, 0, sizeof(ExpertInfo)); in expertDotCommand()
19511 if( z[0]=='-' && z[1]=='-' ) z++; in expertDotCommand()
19513 if( n>=2 && 0==cli_strncmp(z, "-verbose", n) ){ in expertDotCommand()
19514 pState->expert.bVerbose = 1; in expertDotCommand()
19516 else if( n>=2 && 0==cli_strncmp(z, "-sample", n) ){ in expertDotCommand()
19517 if( i==(nArg-1) ){ in expertDotCommand()
19535 pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr); in expertDotCommand()
19536 if( pState->expert.pExpert==0 ){ in expertDotCommand()
19542 pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample in expertDotCommand()
19557 ** This is very similar to SQLite's built-in sqlite3_exec()
19570 sqlite3 *db = pArg->db; in shell_exec()
19577 if( pArg->expert.pExpert ){ in shell_exec()
19585 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover); in shell_exec()
19592 /* this happens for a comment or white-space */ in shell_exec()
19603 pArg->pStmt = pStmt; in shell_exec()
19604 pArg->cnt = 0; in shell_exec()
19608 if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){ in shell_exec()
19613 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP); in shell_exec()
19614 if( pArg->autoEQP>=AUTOEQP_trigger ){ in shell_exec()
19619 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0); in shell_exec()
19626 if( zEQPLine[0]=='-' ) eqp_render(pArg, 0); in shell_exec()
19633 if( pArg->autoEQP>=AUTOEQP_full ){ in shell_exec()
19637 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0); in shell_exec()
19639 pArg->cMode = MODE_Explain; in shell_exec()
19647 if( pArg->autoEQP>=AUTOEQP_trigger && triggerEQP==0 ){ in shell_exec()
19651 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); in shell_exec()
19652 if( pArg ) pArg->pStmt = pStmt; in shell_exec()
19658 pArg->cMode = pArg->mode; in shell_exec()
19659 if( pArg->autoExplain ){ in shell_exec()
19661 pArg->cMode = MODE_Explain; in shell_exec()
19664 pArg->cMode = MODE_EQP; in shell_exec()
19670 if( pArg->cMode==MODE_Explain ){ in shell_exec()
19681 if( pArg && pArg->statsOn ){ in shell_exec()
19685 /* print loop-counters if required */ in shell_exec()
19686 if( pArg && pArg->scanstatsOn ){ in shell_exec()
19704 pArg->pStmt = NULL; in shell_exec()
19750 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in tableColumnList()
19754 if( nCol>=nAlloc-2 ){ in tableColumnList()
19795 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in tableColumnList()
19819 rc = sqlite3_table_column_metadata(p->db,0,zTab,azRowid[j],0,0,0,0,0); in tableColumnList()
19835 sqlite3_prepare_v2(db, "PRAGMA reverse_unordered_selects", -1, &pStmt, 0); in toggleSelectOrder()
19867 dataOnly = (p->shellFlgs & SHFLG_DumpDataOnly)!=0; in dump_callback()
19868 noSys = (p->shellFlgs & SHFLG_DumpNoSys)!=0; in dump_callback()
19871 if( !dataOnly ) raw_printf(p->out, "DELETE FROM sqlite_sequence;\n"); in dump_callback()
19873 if( !dataOnly ) raw_printf(p->out, "ANALYZE sqlite_schema;\n"); in dump_callback()
19877 /* no-op */ in dump_callback()
19880 if( !p->writableSchema ){ in dump_callback()
19881 raw_printf(p->out, "PRAGMA writable_schema=ON;\n"); in dump_callback()
19882 p->writableSchema = 1; in dump_callback()
19889 utf8_printf(p->out, "%s\n", zIns); in dump_callback()
19893 printSchemaLine(p->out, zSql, ";\n"); in dump_callback()
19906 p->nErr++; in dump_callback()
19945 savedDestTable = p->zDestTable; in dump_callback()
19946 savedMode = p->mode; in dump_callback()
19947 p->zDestTable = sTable.z; in dump_callback()
19948 p->mode = p->cMode = MODE_Insert; in dump_callback()
19951 raw_printf(p->out, "/****** CORRUPTION ERROR *******/\n"); in dump_callback()
19952 toggleSelectOrder(p->db); in dump_callback()
19954 toggleSelectOrder(p->db); in dump_callback()
19956 p->zDestTable = savedDestTable; in dump_callback()
19957 p->mode = savedMode; in dump_callback()
19960 if( rc ) p->nErr++; in dump_callback()
19978 rc = sqlite3_exec(p->db, zQuery, dump_callback, p, &zErr); in run_schema_dump_query()
19982 raw_printf(p->out, "/****** CORRUPTION ERROR *******/\n"); in run_schema_dump_query()
19984 utf8_printf(p->out, "/****** %s ******/\n", zErr); in run_schema_dump_query()
19991 rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr); in run_schema_dump_query()
19993 utf8_printf(p->out, "/****** ERROR: %s ******/\n", zErr); in run_schema_dump_query()
20017 " -c, --create Create a new archive",
20018 " -u, --update Add or update files with changed mtime",
20019 " -i, --insert Like -u but always add even if unchanged",
20020 " -r, --remove Remove files from archive",
20021 " -t, --list List contents of archive",
20022 " -x, --extract Extract files from archive",
20024 " -v, --verbose Print each filename as it is processed",
20025 " -f FILE, --file FILE Use archive FILE (default is current db)",
20026 " -a FILE, --append FILE Open FILE using the apndvfs VFS",
20027 " -C DIR, --directory DIR Read/extract files from directory DIR",
20028 " -g, --glob Use glob matching for names in archive",
20029 " -n, --dryrun Show the SQL that would have occurred",
20031 " .ar -cf ARCHIVE foo bar # Create ARCHIVE from files foo and bar",
20032 " .ar -tf ARCHIVE # List members of ARCHIVE",
20033 " .ar -xvf ARCHIVE # Verbosely extract files from ARCHIVE",
20043 " --append Use the appendvfs",
20044 " --async Write to FILE without journal and fsync()",
20064 " --data-only Output only INSERT statements",
20065 " --newlines Allow unescaped newline characters in output",
20066 " --nosys Omit system tables (ex: \"sqlite_stat1\")",
20067 " --preserve-rowids Include ROWID values in the output",
20080 " --bom Put a UTF8 byte-order mark on intermediate file",
20083 ".exit ?CODE? Exit this program with return-code CODE",
20088 " --schema SCHEMA Use SCHEMA instead of \"main\"",
20089 " --help Show CMD details",
20090 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
20092 ".help ?-all? ?PATTERN? Show help text for PATTERN",
20096 " --ascii Use \\037 and \\036 as column and row separators",
20097 " --csv Use , and \\n as column and row separators",
20098 " --skip N Skip the first N rows of input",
20099 " --schema S Target table to be S.TABLE",
20100 " -v \"Verbose\" - increase auxiliary output",
20104 " * If neither --csv or --ascii are used, the input mode is derived",
20121 " fkey-indexes Find missing foreign key indexes",
20133 " box Tables using unicode box-drawing characters",
20134 " csv Comma-separated values",
20142 " qbox Shorthand for \"box --wrap 60 --quote\"",
20144 " table ASCII-art table",
20145 " tabs Tab-separated values",
20148 " --wrap N Wrap output lines to no longer than N characters",
20149 " --wordwrap B Wrap or not at word boundaries per B (on/off)",
20150 " --ww Shorthand for \"--wordwrap 1\"",
20151 " --quote Quote output text as SQL literals",
20152 " --noquote Do not quote output text",
20161 " --bom Put a UTF8 byte-order mark at the beginning",
20162 " -e Send output to the system text editor",
20163 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
20169 " --append Use appendvfs to append database to the end of FILE",
20172 " --deserialize Load into memory using sqlite3_deserialize()",
20173 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
20174 " --maxsize N Maximum size for --hexdb or --deserialized database",
20176 " --new Initialize FILE to an empty database",
20177 " --nofollow Do not follow symbolic links",
20178 " --readonly Open FILE readonly",
20179 " --zip FILE is a ZIP archive",
20184 " --bom Prefix output with a UTF8 byte-order mark",
20185 " -e Send output to the system text editor",
20186 " -x Send output as CSV to a spreadsheet",
20198 " --limit N Interrupt after N progress callbacks",
20199 " --once Do no more than one progress interrupt",
20200 " --quiet|-q No output except at interrupts",
20201 " --reset Reset the count for each input and interrupt",
20211 " --ignore-freelist Ignore pages that appear to be on db freelist",
20212 " --lost-and-found TABLE Alternative name for the lost-and-found table",
20213 " --no-rowids Do not attempt to recover rowid values",
20223 " --indent Try to pretty-print the schema",
20224 " --nosys Omit objects whose names start with \"sqlite_\"",
20227 " --init Create a new SELFTEST table",
20228 " -v Verbose output",
20247 " --schema Also hash the sqlite_schema table",
20248 " --sha3-224 Use the sha3-224 algorithm",
20249 " --sha3-256 Use the sha3-256 algorithm (default)",
20250 " --sha3-384 Use the sha3-384 algorithm",
20251 " --sha3-512 Use the sha3-512 algorithm",
20267 ",testcase NAME Begin redirecting output to 'testcase-out.txt'",
20279 " --expanded Expand query parameters",
20281 " --normalized Normal the SQL statements",
20283 " --plain Show SQL as it is input",
20284 " --stmt Trace statement execution (SQLITE_TRACE_STMT)",
20285 " --profile Profile statements (SQLITE_TRACE_PROFILE)",
20286 " --row Trace each row (SQLITE_TRACE_ROW)",
20287 " --close Trace connection close (SQLITE_TRACE_CLOSE)",
20291 " --allexcept Unregister everything except those named",
20294 ".vfsinfo ?AUX? Information about the top-level VFS",
20298 " Negative values right-justify",
20305 ** If zPattern is NULL, then show all commands, but only give a one-line
20317 || cli_strcmp(zPattern,"-a")==0 in showHelp()
20318 || cli_strcmp(zPattern,"-all")==0 in showHelp()
20319 || cli_strcmp(zPattern,"--all")==0 in showHelp()
20370 while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){ in showHelp()
20383 while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i; in showHelp()
20389 while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){ in showHelp()
20413 ** For convenience, a nul-terminator byte is always appended to the data read
20460 sqlite3session_delete(pSession->p); in session_close()
20461 sqlite3_free(pSession->zName); in session_close()
20462 for(i=0; i<pSession->nFilter; i++){ in session_close()
20463 sqlite3_free(pSession->azFilter[i]); in session_close()
20465 sqlite3_free(pSession->azFilter); in session_close()
20476 struct AuxDb *pAuxDb = i<0 ? p->pAuxDb : &p->aAuxDb[i]; in session_close_all()
20477 for(j=0; j<pAuxDb->nSession; j++){ in session_close_all()
20478 session_close(&pAuxDb->aSession[j]); in session_close_all()
20480 pAuxDb->nSession = 0; in session_close_all()
20494 for(i=0; i<pSession->nFilter; i++){ in session_filter()
20495 if( sqlite3_strglob(pSession->azFilter[i], zTab)==0 ) return 0; in session_filter()
20527 fseek(f, -25, SEEK_END); in deduceDatabaseType()
20529 if( n==1 && memcmp(zBuf, "Start-Of-SQLite3-", 17)==0 ){ in deduceDatabaseType()
20532 fseek(f, -22, SEEK_END); in deduceDatabaseType()
20547 ** Reconstruct an in-memory database using the output from the "dbtotxt"
20548 ** program. Read content from the file in p->aAuxDb[].zDbFilename.
20549 ** If p->aAuxDb[].zDbFilename is 0, then read from standard input.
20560 const char *zDbFilename = p->pAuxDb->zDbFilename; in readHexDb()
20571 in = p->in; in readHexDb()
20572 nLine = p->lineno; in readHexDb()
20581 if( pgsz<512 || pgsz>65536 || (pgsz&(pgsz-1))!=0 ) goto readHexDb_error; in readHexDb()
20582 n = (n+pgsz-1)&~(pgsz-1); /* Round n up to the next multiple of pgsz */ in readHexDb()
20586 if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){ in readHexDb()
20611 if( in!=p->in ){ in readHexDb()
20614 p->lineno = nLine; in readHexDb()
20619 if( in!=p->in ){ in readHexDb()
20622 while( fgets(zLine, sizeof(zLine), p->in)!=0 ){ in readHexDb()
20626 p->lineno = nLine; in readHexDb()
20629 utf8_printf(stderr,"Error on line %d of --hexdb input\n", nLine); in readHexDb()
20666 if( p->db==0 ){ in open_db()
20667 const char *zDbFilename = p->pAuxDb->zDbFilename; in open_db()
20668 if( p->openMode==SHELL_OPEN_UNSPEC ){ in open_db()
20670 p->openMode = SHELL_OPEN_NORMAL; in open_db()
20672 p->openMode = (u8)deduceDatabaseType(zDbFilename, in open_db()
20676 switch( p->openMode ){ in open_db()
20678 sqlite3_open_v2(zDbFilename, &p->db, in open_db()
20679 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs"); in open_db()
20684 sqlite3_open(0, &p->db); in open_db()
20688 sqlite3_open(":memory:", &p->db); in open_db()
20692 sqlite3_open_v2(zDbFilename, &p->db, in open_db()
20693 SQLITE_OPEN_READONLY|p->openFlags, 0); in open_db()
20698 sqlite3_open_v2(zDbFilename, &p->db, in open_db()
20699 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0); in open_db()
20703 globalDb = p->db; in open_db()
20704 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ in open_db()
20706 zDbFilename, sqlite3_errmsg(p->db)); in open_db()
20710 sqlite3_close(p->db); in open_db()
20711 sqlite3_open(":memory:", &p->db); in open_db()
20712 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ in open_db()
20714 "Also: unable to open substitute in-memory database.\n" in open_db()
20719 "Notice: using substitute in-memory database instead of \"%s\"\n", in open_db()
20723 sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0); in open_db()
20725 /* Reflect the use or absence of --unsafe-testing invocation. */ in open_db()
20728 sqlite3_db_config(p->db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, testmode_on,0); in open_db()
20729 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, !testmode_on,0); in open_db()
20733 sqlite3_enable_load_extension(p->db, 1); in open_db()
20735 sqlite3_shathree_init(p->db, 0, 0); in open_db()
20736 sqlite3_uint_init(p->db, 0, 0); in open_db()
20737 sqlite3_decimal_init(p->db, 0, 0); in open_db()
20738 sqlite3_base64_init(p->db, 0, 0); in open_db()
20739 sqlite3_base85_init(p->db, 0, 0); in open_db()
20740 sqlite3_regexp_init(p->db, 0, 0); in open_db()
20741 sqlite3_ieee_init(p->db, 0, 0); in open_db()
20742 sqlite3_series_init(p->db, 0, 0); in open_db()
20744 sqlite3_fileio_init(p->db, 0, 0); in open_db()
20745 sqlite3_completion_init(p->db, 0, 0); in open_db()
20748 if( !p->bSafeModePersist ){ in open_db()
20749 sqlite3_zipfile_init(p->db, 0, 0); in open_db()
20750 sqlite3_sqlar_init(p->db, 0, 0); in open_db()
20756 * This is a short-span macro. See further below for usage. in open_db()
20760 /* Let custom-included extensions get their ..._init() called. in open_db()
20766 int irc = SHELL_SUBMACRO(SQLITE_SHELL_EXTFUNCS, INIT)(p->db); in open_db()
20767 /* Let custom-included extensions expose their functionality. in open_db()
20774 SHELL_SUBMACRO(SQLITE_SHELL_EXTFUNCS, EXPOSE)(p->db, 0); in open_db()
20781 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0, in open_db()
20783 sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0, in open_db()
20785 sqlite3_create_function(p->db, "shell_putsnl", 1, SQLITE_UTF8, p, in open_db()
20787 sqlite3_create_function(p->db, "usleep",1,SQLITE_UTF8,0, in open_db()
20790 sqlite3_create_function(p->db, "edit", 1, SQLITE_UTF8, 0, in open_db()
20792 sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0, in open_db()
20796 if( p->openMode==SHELL_OPEN_ZIPFILE ){ in open_db()
20800 sqlite3_exec(p->db, zSql, 0, 0, 0); in open_db()
20805 if( p->openMode==SHELL_OPEN_DESERIALIZE || p->openMode==SHELL_OPEN_HEXDB ){ in open_db()
20809 if( p->openMode==SHELL_OPEN_DESERIALIZE ){ in open_db()
20817 rc = sqlite3_deserialize(p->db, "main", aData, nData, nData, in open_db()
20823 if( p->szMax>0 ){ in open_db()
20824 sqlite3_file_control(p->db, "main", SQLITE_FCNTL_SIZE_LIMIT, &p->szMax); in open_db()
20829 if( p->db!=0 ){ in open_db()
20830 if( p->bSafeModePersist ){ in open_db()
20831 sqlite3_set_authorizer(p->db, safeModeAuth, p); in open_db()
20834 p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, p->scanstatsOn, (int*)0 in open_db()
20863 sqlite3_prepare_v2(globalDb, zSql, -1, &pStmt, 0); in readline_completion_generator()
20894 if( nLine>(i64)sizeof(zBuf)-30 ) return; in linenoise_completion()
20896 for(i=nLine-1; i>=0 && (isalnum(zLine[i]) || zLine[i]=='_'); i--){} in linenoise_completion()
20897 if( i==nLine-1 ) return; in linenoise_completion()
20904 sqlite3_prepare_v2(globalDb, zSql, -1, &pStmt, 0); in linenoise_completion()
20910 if( iStart+nCompletion < (i64)sizeof(zBuf)-1 && zCompletion ){ in linenoise_completion()
20920 ** Do C-language style dequoting.
20922 ** \a -> alarm
20923 ** \b -> backspace
20924 ** \t -> tab
20925 ** \n -> newline
20926 ** \v -> vertical tab
20927 ** \f -> form feed
20928 ** \r -> carriage return
20929 ** \s -> space
20930 ** \" -> "
20931 ** \' -> '
20932 ** \\ -> backslash
20933 ** \NNN -> ascii character NNN in octal
20934 ** \xHH -> ascii character HH in hexadecimal
20973 c -= '0'; in resolve_backslashes()
20976 c = (c<<3) + z[i] - '0'; in resolve_backslashes()
20979 c = (c<<3) + z[i] - '0'; in resolve_backslashes()
21066 if( p->traceOut==0 ) return 0; in sql_trace_callback()
21068 utf8_printf(p->traceOut, "-- closing database connection\n"); in sql_trace_callback()
21071 if( mType!=SQLITE_TRACE_ROW && pX!=0 && ((const char*)pX)[0]=='-' ){ in sql_trace_callback()
21075 switch( p->eTraceType ){ in sql_trace_callback()
21095 while( nSql>0 && zSql[nSql-1]==';' ){ nSql--; } in sql_trace_callback()
21099 utf8_printf(p->traceOut, "%.*s;\n", (int)nSql, zSql); in sql_trace_callback()
21104 utf8_printf(p->traceOut, "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec); in sql_trace_callback()
21113 ** A no-op routine that runs with the ".breakpoint" doc-command. This is
21146 if( p->in!=0 && p->xCloser!=0 ){ in import_cleanup()
21147 p->xCloser(p->in); in import_cleanup()
21148 p->in = 0; in import_cleanup()
21150 sqlite3_free(p->z); in import_cleanup()
21151 p->z = 0; in import_cleanup()
21156 if( p->n+1>=p->nAlloc ){ in import_append_char()
21157 p->nAlloc += p->nAlloc + 100; in import_append_char()
21158 p->z = sqlite3_realloc64(p->z, p->nAlloc); in import_append_char()
21159 shell_check_oom(p->z); in import_append_char()
21161 p->z[p->n++] = (char)c; in import_append_char()
21167 ** + Input comes from p->in.
21168 ** + Store results in p->z of length p->n. Space to hold p->z comes
21170 ** + Use p->cSep as the column separator. The default is ",".
21171 ** + Use p->rSep as the row separator. The default is "\n".
21172 ** + Keep track of the line number in p->nLine.
21173 ** + Store the character that terminates the field in p->cTerm. Store
21174 ** EOF on end-of-file.
21179 int cSep = (u8)p->cColSep; in csv_read_one_field()
21180 int rSep = (u8)p->cRowSep; in csv_read_one_field()
21181 p->n = 0; in csv_read_one_field()
21182 c = fgetc(p->in); in csv_read_one_field()
21184 p->cTerm = EOF; in csv_read_one_field()
21189 int startLine = p->nLine; in csv_read_one_field()
21193 c = fgetc(p->in); in csv_read_one_field()
21194 if( c==rSep ) p->nLine++; in csv_read_one_field()
21206 do{ p->n--; }while( p->z[p->n]!=cQuote ); in csv_read_one_field()
21207 p->cTerm = c; in csv_read_one_field()
21212 p->zFile, p->nLine, cQuote); in csv_read_one_field()
21215 utf8_printf(stderr, "%s:%d: unterminated %c-quoted field\n", in csv_read_one_field()
21216 p->zFile, startLine, cQuote); in csv_read_one_field()
21217 p->cTerm = c; in csv_read_one_field()
21226 ** UTF-8 BOM (0xEF BB BF) then skip the BOM */ in csv_read_one_field()
21227 if( (c&0xff)==0xef && p->bNotFirst==0 ){ in csv_read_one_field()
21229 c = fgetc(p->in); in csv_read_one_field()
21232 c = fgetc(p->in); in csv_read_one_field()
21234 p->bNotFirst = 1; in csv_read_one_field()
21235 p->n = 0; in csv_read_one_field()
21242 c = fgetc(p->in); in csv_read_one_field()
21245 p->nLine++; in csv_read_one_field()
21246 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--; in csv_read_one_field()
21248 p->cTerm = c; in csv_read_one_field()
21250 if( p->z ) p->z[p->n] = 0; in csv_read_one_field()
21251 p->bNotFirst = 1; in csv_read_one_field()
21252 return p->z; in csv_read_one_field()
21257 ** + Input comes from p->in.
21258 ** + Store results in p->z of length p->n. Space to hold p->z comes
21260 ** + Use p->cSep as the column separator. The default is "\x1F".
21261 ** + Use p->rSep as the row separator. The default is "\x1E".
21262 ** + Keep track of the row number in p->nLine.
21263 ** + Store the character that terminates the field in p->cTerm. Store
21264 ** EOF on end-of-file.
21269 int cSep = (u8)p->cColSep; in ascii_read_one_field()
21270 int rSep = (u8)p->cRowSep; in ascii_read_one_field()
21271 p->n = 0; in ascii_read_one_field()
21272 c = fgetc(p->in); in ascii_read_one_field()
21274 p->cTerm = EOF; in ascii_read_one_field()
21279 c = fgetc(p->in); in ascii_read_one_field()
21282 p->nLine++; in ascii_read_one_field()
21284 p->cTerm = c; in ascii_read_one_field()
21285 if( p->z ) p->z[p->n] = 0; in ascii_read_one_field()
21286 return p->z; in ascii_read_one_field()
21312 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); in tryToCloneData()
21315 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), in tryToCloneData()
21330 rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0); in tryToCloneData()
21356 -1, SQLITE_STATIC); in tryToCloneData()
21375 printf("%c\b", "|/-\\"[(cnt/spinRate)%4]); in tryToCloneData()
21385 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); in tryToCloneData()
21422 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); in tryToCloneSchema()
21425 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), in tryToCloneSchema()
21453 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); in tryToCloneSchema()
21456 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), in tryToCloneSchema()
21500 sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0); in tryToClone()
21505 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); in tryToClone()
21513 ** If the p->doXdgOpen flag is set, that means the output was being
21514 ** redirected to a temporary file named by p->zTempFile. In that case,
21515 ** launch start/open/xdg-open on that temporary file.
21518 if( p->outfile[0]=='|' ){ in output_reset()
21520 pclose(p->out); in output_reset()
21523 output_file_close(p->out); in output_reset()
21525 if( p->doXdgOpen ){ in output_reset()
21532 "xdg-open"; in output_reset()
21535 zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile); in output_reset()
21539 /* Give the start/open/xdg-open command some time to get in output_reset()
21541 ** p->zTempFile data file out from under it */ in output_reset()
21546 p->doXdgOpen = 0; in output_reset()
21550 p->outfile[0] = 0; in output_reset()
21551 p->out = stdout; in output_reset()
21560 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); in db_int()
21570 ** Convert a 2-byte or 4-byte big-endian integer into a native integer
21618 if( p->db==0 ) return 1; in shell_dbinfo_command()
21619 rc = sqlite3_prepare_v2(p->db, in shell_dbinfo_command()
21621 -1, &pStmt, 0); in shell_dbinfo_command()
21623 utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db)); in shell_dbinfo_command()
21627 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC); in shell_dbinfo_command()
21642 utf8_printf(p->out, "%-20s %d\n", "database page size:", i); in shell_dbinfo_command()
21643 utf8_printf(p->out, "%-20s %d\n", "write format:", aHdr[18]); in shell_dbinfo_command()
21644 utf8_printf(p->out, "%-20s %d\n", "read format:", aHdr[19]); in shell_dbinfo_command()
21645 utf8_printf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]); in shell_dbinfo_command()
21649 utf8_printf(p->out, "%-20s %u", aField[i].zName, val); in shell_dbinfo_command()
21652 if( val==1 ) raw_printf(p->out, " (utf8)"); in shell_dbinfo_command()
21653 if( val==2 ) raw_printf(p->out, " (utf16le)"); in shell_dbinfo_command()
21654 if( val==3 ) raw_printf(p->out, " (utf16be)"); in shell_dbinfo_command()
21657 raw_printf(p->out, "\n"); in shell_dbinfo_command()
21668 int val = db_int(p->db, zSql); in shell_dbinfo_command()
21670 utf8_printf(p->out, "%-20s %d\n", aQuery[i].zName, val); in shell_dbinfo_command()
21673 sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_DATA_VERSION, &iDataVersion); in shell_dbinfo_command()
21674 utf8_printf(p->out, "%-20s %u\n", "data version", iDataVersion); in shell_dbinfo_command()
21704 ** optional + or - sign in front
21728 while( *z && testcase_glob(zGlob-1,z)==0 ){ in testcase_glob()
21759 if( c2=='-' && zGlob[0]!=']' && zGlob[0]!=0 && prior_c>0 ){ in testcase_glob()
21773 if( (z[0]=='-' || z[0]=='+') && IsDigit(z[1]) ) z++; in testcase_glob()
21787 ** Compare the string as a command-line option with either one or two
21788 ** initial "-" characters.
21791 if( zStr[0]!='-' ) return 0; in optionMatch()
21793 if( zStr[0]=='-' ) zStr++; in optionMatch()
21817 if( p->zTempFile==0 ) return; in clearTempFile()
21818 if( p->doXdgOpen ) return; in clearTempFile()
21819 if( shellDeleteFile(p->zTempFile) ) return; in clearTempFile()
21820 sqlite3_free(p->zTempFile); in clearTempFile()
21821 p->zTempFile = 0; in clearTempFile()
21829 sqlite3_free(p->zTempFile); in newTempFile()
21830 p->zTempFile = 0; in newTempFile()
21831 if( p->db ){ in newTempFile()
21832 sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile); in newTempFile()
21834 if( p->zTempFile==0 ){ in newTempFile()
21835 /* If p->db is an in-memory database then the TEMPFILENAME file-control in newTempFile()
21849 p->zTempFile = sqlite3_mprintf("%s/temp%llx.%s", zTemp, r, zSuffix); in newTempFile()
21851 p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix); in newTempFile()
21853 shell_check_oom(p->zTempFile); in newTempFile()
21859 ** by the ".lint fkey-indexes" command. This scalar function is always
21860 ** called with four arguments - the parent table name, the parent column name,
21863 ** fkey_collate_clause('parent-tab', 'parent-col', 'child-tab', 'child-col')
21869 ** function returns the string " COLLATE <parent-collation>", where
21870 ** <parent-collation> is the default collation sequence of the parent column.
21883 const char *zChildSeq = 0; /* Initialize to avoid false-positive warning */ in shellFkeyCollateClause()
21892 sqlite3_result_text(pCtx, "", -1, SQLITE_STATIC); in shellFkeyCollateClause()
21904 sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT); in shellFkeyCollateClause()
21911 ** The implementation of dot-command ".lint fkey-indexes".
21918 sqlite3 *db = pState->db; /* Database handle to query "main" db of */ in lintFkeyIndexes()
21919 FILE *out = pState->out; /* Stream to write non-error output to */ in lintFkeyIndexes()
21920 int bVerbose = 0; /* If -verbose is present */ in lintFkeyIndexes()
21921 int bGroupByParent = 0; /* If -groupbyparent is present */ in lintFkeyIndexes()
21985 "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) " in lintFkeyIndexes()
21993 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){ in lintFkeyIndexes()
21996 else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){ in lintFkeyIndexes()
22001 raw_printf(stderr, "Usage: %s %s ?-verbose? ?-groupbyparent?\n", in lintFkeyIndexes()
22015 rc = sqlite3_prepare_v2(db, zSql, -1, &pSql, 0); in lintFkeyIndexes()
22025 int res = -1; in lintFkeyIndexes()
22036 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0); in lintFkeyIndexes()
22054 raw_printf(out, "-- Parent table %s\n", zParent); in lintFkeyIndexes()
22060 raw_printf(out, "%s%s --> %s\n", zIndent, zCI, zTarget); in lintFkeyIndexes()
22062 raw_printf(out, "%s/* no extra indexes required for %s -> %s */\n", in lintFkeyIndexes()
22096 if( n<1 || sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ) goto usage; in lintDotCommand()
22100 raw_printf(stderr, "Usage %s sub-command ?switches...?\n", azArg[0]); in lintDotCommand()
22101 raw_printf(stderr, "Where sub-commands are:\n"); in lintDotCommand()
22102 raw_printf(stderr, " fkey-indexes\n"); in lintDotCommand()
22115 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0); in shellPrepare()
22126 ** Create a prepared statement using printf-style arguments for the SQL.
22129 ** depending on compile-time options. By omitting the "static", we avoid
22158 ** depending on compile-time options. By omitting the "static", we avoid
22180 ** depending on compile-time options. By omitting the "static", we avoid
22208 u8 bVerbose; /* True if --verbose */
22210 u8 bDryRun; /* True if --dry-run */
22211 u8 bAppend; /* True if --append */
22212 u8 bGlob; /* True if --glob */
22213 u8 fromCmdLine; /* Run from -A instead of .archive */
22216 const char *zFile; /* --file argument, or NULL */
22217 const char *zDir; /* --directory argument, or NULL */
22242 if( pAr->fromCmdLine ){ in arErrorMsg()
22243 utf8_printf(stderr, "Use \"-A\" for more help\n"); in arErrorMsg()
22245 utf8_printf(stderr, "Use \".archive --help\" for more help\n"); in arErrorMsg()
22263 ** Other (non-command) switches.
22281 if( pAr->eCmd ){ in arProcessSwitch()
22284 pAr->eCmd = eSwitch; in arProcessSwitch()
22288 pAr->bDryRun = 1; in arProcessSwitch()
22291 pAr->bGlob = 1; in arProcessSwitch()
22294 pAr->bVerbose = 1; in arProcessSwitch()
22297 pAr->bAppend = 1; in arProcessSwitch()
22300 pAr->zFile = zArg; in arProcessSwitch()
22303 pAr->zDir = zArg; in arProcessSwitch()
22349 if( z[0]!='-' ){ in arParseCommand()
22357 if( z[i]==pOpt->cShort ) break; in arParseCommand()
22362 if( pOpt->bArg ){ in arParseCommand()
22368 if( arProcessSwitch(pAr, pOpt->eSwitch, zArg) ) return SQLITE_ERROR; in arParseCommand()
22370 pAr->nArg = nArg-iArg; in arParseCommand()
22371 if( pAr->nArg>0 ){ in arParseCommand()
22372 pAr->azArg = &azArg[iArg]; in arParseCommand()
22375 /* Non-traditional invocation */ in arParseCommand()
22380 if( z[0]!='-' ){ in arParseCommand()
22382 pAr->azArg = &azArg[iArg]; in arParseCommand()
22383 pAr->nArg = nArg-iArg; in arParseCommand()
22388 if( z[1]!='-' ){ in arParseCommand()
22395 if( z[i]==pOpt->cShort ) break; in arParseCommand()
22400 if( pOpt->bArg ){ in arParseCommand()
22401 if( i<(n-1) ){ in arParseCommand()
22405 if( iArg>=(nArg-1) ){ in arParseCommand()
22412 if( arProcessSwitch(pAr, pOpt->eSwitch, zArg) ) return SQLITE_ERROR; in arParseCommand()
22415 /* A -- option, indicating that all remaining command line words in arParseCommand()
22417 pAr->azArg = &azArg[iArg+1]; in arParseCommand()
22418 pAr->nArg = nArg-iArg-1; in arParseCommand()
22426 const char *zLong = pOpt->zLong; in arParseCommand()
22427 if( (n-2)<=strlen30(zLong) && 0==memcmp(&z[2], zLong, n-2) ){ in arParseCommand()
22439 if( pMatch->bArg ){ in arParseCommand()
22440 if( iArg>=(nArg-1) ){ in arParseCommand()
22445 if( arProcessSwitch(pAr, pMatch->eSwitch, zArg) ) return SQLITE_ERROR; in arParseCommand()
22450 if( pAr->eCmd==0 ){ in arParseCommand()
22459 ** array refer to archive members, as for the --extract, --list or --remove
22464 ** exact equality when pAr->bGlob is false or a "name GLOB pattern" match
22465 ** when pAr->bGlob is true.
22473 if( pAr->nArg ){ in arCheckEntries()
22476 const char *zSel = (pAr->bGlob) in arCheckEntries()
22480 shellPreparePrintf(pAr->db, &rc, &pTest, zSel, pAr->zSrcTable); in arCheckEntries()
22482 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){ in arCheckEntries()
22483 char *z = pAr->azArg[i]; in arCheckEntries()
22486 while( n>0 && z[n-1]=='/' ) n--; in arCheckEntries()
22488 sqlite3_bind_text(pTest, j, z, -1, SQLITE_STATIC); in arCheckEntries()
22508 ** any non-NULL (*pzWhere) value. Here, "match" means strict equality
22509 ** when pAr->bGlob is false and GLOB match when pAr->bGlob is true.
22517 const char *zSameOp = (pAr->bGlob)? "GLOB" : "="; in arWhereClause()
22519 if( pAr->nArg==0 ){ in arWhereClause()
22524 for(i=0; i<pAr->nArg; i++){ in arWhereClause()
22525 const char *z = pAr->azArg[i]; in arWhereClause()
22558 shellPreparePrintf(pAr->db, &rc, &pSql, zSql, azCols[pAr->bVerbose], in arListCommand()
22559 pAr->zSrcTable, zWhere); in arListCommand()
22560 if( pAr->bDryRun ){ in arListCommand()
22561 utf8_printf(pAr->p->out, "%s\n", sqlite3_sql(pSql)); in arListCommand()
22564 if( pAr->bVerbose ){ in arListCommand()
22565 utf8_printf(pAr->p->out, "%s % 10d %s %s\n", in arListCommand()
22572 utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0)); in arListCommand()
22590 if( pAr->nArg ){ in arRemoveCommand()
22598 pAr->zSrcTable, zWhere); in arRemoveCommand()
22599 if( pAr->bDryRun ){ in arRemoveCommand()
22600 utf8_printf(pAr->p->out, "%s\n", zSql); in arRemoveCommand()
22603 rc = sqlite3_exec(pAr->db, "SAVEPOINT ar;", 0, 0, 0); in arRemoveCommand()
22605 rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr); in arRemoveCommand()
22607 sqlite3_exec(pAr->db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0); in arRemoveCommand()
22609 rc = sqlite3_exec(pAr->db, "RELEASE ar;", 0, 0, 0); in arRemoveCommand()
22652 if( pAr->zDir ){ in arExtractCommand()
22653 zDir = sqlite3_mprintf("%s/", pAr->zDir); in arExtractCommand()
22660 shellPreparePrintf(pAr->db, &rc, &pSql, zSql1, in arExtractCommand()
22661 azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere in arExtractCommand()
22666 sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC); in arExtractCommand()
22676 if( pAr->bDryRun ){ in arExtractCommand()
22677 utf8_printf(pAr->p->out, "%s\n", sqlite3_sql(pSql)); in arExtractCommand()
22680 if( i==0 && pAr->bVerbose ){ in arExtractCommand()
22681 utf8_printf(pAr->p->out, "%s\n", sqlite3_column_text(pSql, 0)); in arExtractCommand()
22696 ** Run the SQL statement in zSql. Or if doing a --dryrun, merely print it out.
22700 if( pAr->bDryRun ){ in arExecSql()
22701 utf8_printf(pAr->p->out, "%s\n", zSql); in arExecSql()
22705 rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr); in arExecSql()
22718 ** create -> Create a new SQL archive
22719 ** insert -> Insert or reinsert all files listed
22720 ** update -> Insert files that have changed or that were not
22725 ** are added recursively. If argument bVerbose is non-zero, a message is
22730 ** always overwrites every file named on the command-line, where as
22735 int bUpdate, /* true for a --create. */ in arCreateOrUpdateCommand()
22740 " name TEXT PRIMARY KEY, -- name of the file\n" in arCreateOrUpdateCommand()
22741 " mode INT, -- access permissions\n" in arCreateOrUpdateCommand()
22742 " mtime INT, -- last modification time\n" in arCreateOrUpdateCommand()
22743 " sz INT, -- original file size\n" in arCreateOrUpdateCommand()
22744 " data BLOB -- compressed content\n" in arCreateOrUpdateCommand()
22754 " WHEN '-' THEN length(data)\n" in arCreateOrUpdateCommand()
22756 " ELSE -1 END,\n" in arCreateOrUpdateCommand()
22781 if( pAr->bZip ){ in arCreateOrUpdateCommand()
22783 if( pAr->zFile ){ in arCreateOrUpdateCommand()
22790 zTab, pAr->zFile in arCreateOrUpdateCommand()
22817 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){ in arCreateOrUpdateCommand()
22818 char *zSql2 = sqlite3_mprintf(zInsertFmt[pAr->bZip], zTab, in arCreateOrUpdateCommand()
22819 pAr->bVerbose ? "shell_putsnl(name)" : "name", in arCreateOrUpdateCommand()
22820 pAr->azArg[i], pAr->zDir, zExists); in arCreateOrUpdateCommand()
22826 sqlite3_exec(pAr->db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0); in arCreateOrUpdateCommand()
22829 if( pAr->bZip && pAr->zFile ){ in arCreateOrUpdateCommand()
22844 int fromCmdLine, /* True if -A command-line option, not .ar cmd */ in arDotCommand()
22856 cmd.db = pState->db; in arDotCommand()
22860 eDbType = pState->openMode; in arDotCommand()
22882 utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile, in arDotCommand()
22924 arUsage(pState->out); in arDotCommand()
22942 if( cmd.db!=pState->db ){ in arDotCommand()
22961 utf8_printf(pState->out, "%s;\n", zSql); in recoverSqlCb()
22968 ** on stream pState->out.
22974 int bFreelist = 1; /* 0 if --ignore-freelist is specified */ in recoverDatabaseCmd()
22975 int bRowids = 1; /* 0 if --no-rowids */ in recoverDatabaseCmd()
22982 if( z[0]=='-' && z[1]=='-' ) z++; in recoverDatabaseCmd()
22984 if( n<=17 && memcmp("-ignore-freelist", z, n)==0 ){ in recoverDatabaseCmd()
22987 if( n<=12 && memcmp("-recovery-db", z, n)==0 && i<(nArg-1) ){ in recoverDatabaseCmd()
22988 /* This option determines the name of the ATTACH-ed database used in recoverDatabaseCmd()
22996 if( n<=15 && memcmp("-lost-and-found", z, n)==0 && i<(nArg-1) ){ in recoverDatabaseCmd()
23000 if( n<=10 && memcmp("-no-rowids", z, n)==0 ){ in recoverDatabaseCmd()
23005 showHelp(pState->out, azArg[0]); in recoverDatabaseCmd()
23011 pState->db, "main", recoverSqlCb, (void*)pState in recoverDatabaseCmd()
23040 * pointer is non-zero, its referent will be set to a summary of renames
23090 SELECT count(DISTINCT (substring(name,1,nlen-chop)||suff) COLLATE NOCASE)\ in zAutoColumn()
23098 nlen-length(rtrim(name, '"AUTOCOLUMN_SEP"0123456789')),\ in zAutoColumn()
23106 WHERE substring(t.name,1,t.nlen-t.chop)=substring(d.name,1,d.nlen-d.chop)\ in zAutoColumn()
23164 ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\ in zAutoColumn()
23167 SELECT cpos, printf('\"%w\"',printf('%!.*s%s', nlen-chop,name,suff)) AS cname \ in zAutoColumn()
23172 " printf('\"%w\" to \"%w\"',name,printf('%!.*s%s', nlen-chop, name, suff))," in zAutoColumn()
23192 rc = sqlite3_prepare_v2(*pDb, zTabFill, -1, &pStmt, 0); in zAutoColumn()
23194 rc = sqlite3_bind_text(pStmt, 1, zColNew, -1, 0); in zAutoColumn()
23214 rc = sqlite3_prepare_v2(*pDb, zRenameRank, -1, &pStmt, 0); in zAutoColumn()
23222 rc = sqlite3_prepare_v2(*pDb, zCollectVar, -1, &pStmt, 0); in zAutoColumn()
23234 if( SQLITE_OK==sqlite3_prepare_v2(*pDb, zRenamesDone, -1, &pStmt, 0) in zAutoColumn()
23262 if( p->expert.pExpert ){ in do_meta_command()
23269 while( zLine[h] && nArg<ArraySize(azArg)-1 ){ in do_meta_command()
23282 if( delim=='"' ) resolve_backslashes(azArg[nArg-1]); in do_meta_command()
23287 resolve_backslashes(azArg[nArg-1]); in do_meta_command()
23308 sqlite3_set_authorizer(p->db, shellAuth, p); in do_meta_command()
23309 }else if( p->bSafeModePersist ){ in do_meta_command()
23310 sqlite3_set_authorizer(p->db, safeModeAuth, p); in do_meta_command()
23312 sqlite3_set_authorizer(p->db, 0, 0); in do_meta_command()
23340 if( z[0]=='-' ){ in do_meta_command()
23341 if( z[1]=='-' ) z++; in do_meta_command()
23342 if( cli_strcmp(z, "-append")==0 ){ in do_meta_command()
23345 if( cli_strcmp(z, "-async")==0 ){ in do_meta_command()
23379 pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb); in do_meta_command()
23409 setBinaryMode(p->out, 1); in do_meta_command()
23411 setTextMode(p->out, 1); in do_meta_command()
23419 /* The undocumented ".breakpoint" command causes a call to the no-op in do_meta_command()
23459 ** Then read the content of the testcase-out.txt file and compare against in do_meta_command()
23466 raw_printf(stderr, "Usage: .check GLOB-PATTERN\n"); in do_meta_command()
23468 }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){ in do_meta_command()
23472 "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n", in do_meta_command()
23473 p->zTestcase, azArg[1], zRes); in do_meta_command()
23476 utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase); in do_meta_command()
23477 p->nCheck++; in do_meta_command()
23499 for(i=0; i<ArraySize(p->aAuxDb); i++){ in do_meta_command()
23500 const char *zFile = p->aAuxDb[i].zDbFilename; in do_meta_command()
23501 if( p->aAuxDb[i].db==0 && p->pAuxDb!=&p->aAuxDb[i] ){ in do_meta_command()
23506 zFile = "(temporary-file)"; in do_meta_command()
23508 if( p->pAuxDb == &p->aAuxDb[i] ){ in do_meta_command()
23510 }else if( p->aAuxDb[i].db!=0 ){ in do_meta_command()
23515 int i = azArg[1][0] - '0'; in do_meta_command()
23516 if( p->pAuxDb != &p->aAuxDb[i] && i>=0 && i<ArraySize(p->aAuxDb) ){ in do_meta_command()
23517 p->pAuxDb->db = p->db; in do_meta_command()
23518 p->pAuxDb = &p->aAuxDb[i]; in do_meta_command()
23519 globalDb = p->db = p->pAuxDb->db; in do_meta_command()
23520 p->pAuxDb->db = 0; in do_meta_command()
23524 int i = azArg[2][0] - '0'; in do_meta_command()
23525 if( i<0 || i>=ArraySize(p->aAuxDb) ){ in do_meta_command()
23526 /* No-op */ in do_meta_command()
23527 }else if( p->pAuxDb == &p->aAuxDb[i] ){ in do_meta_command()
23530 }else if( p->aAuxDb[i].db ){ in do_meta_command()
23532 close_db(p->aAuxDb[i].db); in do_meta_command()
23533 p->aAuxDb[i].db = 0; in do_meta_command()
23536 raw_printf(stderr, "Usage: .connection [close] [CONNECTION-NUMBER]\n"); in do_meta_command()
23547 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0); in do_meta_command()
23549 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); in do_meta_command()
23565 int eTxn = sqlite3_txn_state(p->db, azName[i*2]); in do_meta_command()
23566 int bRdonly = sqlite3_db_readonly(p->db, azName[i*2]); in do_meta_command()
23568 utf8_printf(p->out, "%s: %s %s%s\n", in do_meta_command()
23573 eTxn==SQLITE_TXN_READ ? " read-txn" : " write-txn"); in do_meta_command()
23609 sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0); in do_meta_command()
23611 sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v); in do_meta_command()
23612 utf8_printf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off"); in do_meta_command()
23636 int savedShowHeader = p->showHeader; in do_meta_command()
23637 int savedShellFlags = p->shellFlgs; in do_meta_command()
23642 if( azArg[i][0]=='-' ){ in do_meta_command()
23644 if( z[0]=='-' ) z++; in do_meta_command()
23645 if( cli_strcmp(z,"preserve-rowids")==0 ){ in do_meta_command()
23647 raw_printf(stderr, "The --preserve-rowids option is not compatible" in do_meta_command()
23659 if( cli_strcmp(z,"data-only")==0 ){ in do_meta_command()
23696 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ in do_meta_command()
23699 ** So disable foreign-key constraint enforcement to prevent problems. */ in do_meta_command()
23700 raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n"); in do_meta_command()
23701 raw_printf(p->out, "BEGIN TRANSACTION;\n"); in do_meta_command()
23703 p->writableSchema = 0; in do_meta_command()
23704 p->showHeader = 0; in do_meta_command()
23708 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0); in do_meta_command()
23709 p->nErr = 0; in do_meta_command()
23720 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ in do_meta_command()
23731 if( p->writableSchema ){ in do_meta_command()
23732 raw_printf(p->out, "PRAGMA writable_schema=OFF;\n"); in do_meta_command()
23733 p->writableSchema = 0; in do_meta_command()
23735 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); in do_meta_command()
23736 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0); in do_meta_command()
23737 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ in do_meta_command()
23738 raw_printf(p->out, p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n"); in do_meta_command()
23740 p->showHeader = savedShowHeader; in do_meta_command()
23741 p->shellFlgs = savedShellFlags; in do_meta_command()
23755 p->autoEQPtest = 0; in do_meta_command()
23756 if( p->autoEQPtrace ){ in do_meta_command()
23757 if( p->db ) sqlite3_exec(p->db, "PRAGMA vdbe_trace=OFF;", 0, 0, 0); in do_meta_command()
23758 p->autoEQPtrace = 0; in do_meta_command()
23761 p->autoEQP = AUTOEQP_full; in do_meta_command()
23763 p->autoEQP = AUTOEQP_trigger; in do_meta_command()
23766 p->autoEQP = AUTOEQP_on; in do_meta_command()
23767 p->autoEQPtest = 1; in do_meta_command()
23769 p->autoEQP = AUTOEQP_full; in do_meta_command()
23770 p->autoEQPtrace = 1; in do_meta_command()
23772 sqlite3_exec(p->db, "SELECT name FROM sqlite_schema LIMIT 1", 0, 0, 0); in do_meta_command()
23773 sqlite3_exec(p->db, "PRAGMA vdbe_trace=ON;", 0, 0, 0); in do_meta_command()
23776 p->autoEQP = (u8)booleanValue(azArg[1]); in do_meta_command()
23802 if( val==1 && p->mode!=MODE_Explain ){ in do_meta_command()
23803 p->normalMode = p->mode; in do_meta_command()
23804 p->mode = MODE_Explain; in do_meta_command()
23805 p->autoExplain = 0; in do_meta_command()
23807 if( p->mode==MODE_Explain ) p->mode = p->normalMode; in do_meta_command()
23808 p->autoExplain = 0; in do_meta_command()
23810 if( p->mode==MODE_Explain ) p->mode = p->normalMode; in do_meta_command()
23811 p->autoExplain = 1; in do_meta_command()
23817 if( p->bSafeMode ){ in do_meta_command()
23831 const char *zCtrlName; /* Name of a test-control option */ in do_meta_command()
23847 int filectrl = -1; in do_meta_command()
23848 int iCtrl = -1; in do_meta_command()
23850 int isOk = 0; /* 0: usage 1: %lld 2: no-result */ in do_meta_command()
23858 if( zCmd[0]=='-' in do_meta_command()
23859 && (cli_strcmp(zCmd,"--schema")==0 || cli_strcmp(zCmd,"-schema")==0) in do_meta_command()
23863 for(i=3; i<nArg; i++) azArg[i-2] = azArg[i]; in do_meta_command()
23864 nArg -= 2; in do_meta_command()
23868 /* The argument can optionally begin with "-" or "--" */ in do_meta_command()
23869 if( zCmd[0]=='-' && zCmd[1] ){ in do_meta_command()
23871 if( zCmd[0]=='-' && zCmd[1] ) zCmd++; in do_meta_command()
23874 /* --help lists all file-controls */ in do_meta_command()
23876 utf8_printf(p->out, "Available file-controls:\n"); in do_meta_command()
23878 utf8_printf(p->out, " .filectrl %s %s\n", in do_meta_command()
23894 utf8_printf(stderr, "Error: ambiguous file-control: \"%s\"\n" in do_meta_command()
23895 "Use \".filectrl --help\" for help\n", zCmd); in do_meta_command()
23902 utf8_printf(stderr,"Error: unknown file-control: %s\n" in do_meta_command()
23903 "Use \".filectrl --help\" for help\n", zCmd); in do_meta_command()
23908 iRes = nArg==3 ? integerValue(azArg[2]) : -1; in do_meta_command()
23909 sqlite3_file_control(p->db, zSchema, SQLITE_FCNTL_SIZE_LIMIT, &iRes); in do_meta_command()
23918 sqlite3_file_control(p->db, zSchema, filectrl, &x); in do_meta_command()
23926 x = nArg==3 ? booleanValue(azArg[2]) : -1; in do_meta_command()
23927 sqlite3_file_control(p->db, zSchema, filectrl, &x); in do_meta_command()
23936 sqlite3_file_control(p->db, zSchema, filectrl, &x); in do_meta_command()
23944 sqlite3_file_control(p->db, zSchema, filectrl, &z); in do_meta_command()
23946 utf8_printf(p->out, "%s\n", z); in do_meta_command()
23956 sqlite3_file_control(p->db, zSchema, filectrl, &x); in do_meta_command()
23958 x = -1; in do_meta_command()
23959 sqlite3_file_control(p->db, zSchema, filectrl, &x); in do_meta_command()
23960 utf8_printf(p->out,"%d\n", x); in do_meta_command()
23967 utf8_printf(p->out, "Usage: .filectrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage); in do_meta_command()
23972 raw_printf(p->out, "%s\n", zBuf); in do_meta_command()
23987 raw_printf(stderr, "Usage: .fullschema ?--indent?\n"); in do_meta_command()
23992 rc = sqlite3_exec(p->db, in do_meta_command()
24003 rc = sqlite3_prepare_v2(p->db, in do_meta_command()
24006 -1, &pStmt, 0); in do_meta_command()
24011 raw_printf(p->out, "/* No STAT tables available */\n"); in do_meta_command()
24013 raw_printf(p->out, "ANALYZE sqlite_schema;\n"); in do_meta_command()
24019 raw_printf(p->out, "ANALYZE sqlite_schema;\n"); in do_meta_command()
24025 p->showHeader = booleanValue(azArg[1]); in do_meta_command()
24026 p->shellFlgs |= SHFLG_HeaderSet; in do_meta_command()
24035 n = showHelp(p->out, azArg[1]); in do_meta_command()
24037 utf8_printf(p->out, "Nothing matches '%s'\n", azArg[1]); in do_meta_command()
24040 showHelp(p->out, 0); in do_meta_command()
24054 int nSep; /* Number of bytes in p->colSeparator[] */ in do_meta_command()
24066 if( p->mode==MODE_Ascii ){ in do_meta_command()
24074 if( z[0]=='-' && z[1]=='-' ) z++; in do_meta_command()
24075 if( z[0]!='-' ){ in do_meta_command()
24081 utf8_printf(p->out, "ERROR: extra argument: \"%s\". Usage:\n", z); in do_meta_command()
24082 showHelp(p->out, "import"); in do_meta_command()
24085 }else if( cli_strcmp(z,"-v")==0 ){ in do_meta_command()
24087 }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){ in do_meta_command()
24089 }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){ in do_meta_command()
24091 }else if( cli_strcmp(z,"-ascii")==0 ){ in do_meta_command()
24096 }else if( cli_strcmp(z,"-csv")==0 ){ in do_meta_command()
24102 utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", z); in do_meta_command()
24103 showHelp(p->out, "import"); in do_meta_command()
24108 utf8_printf(p->out, "ERROR: missing %s argument. Usage:\n", in do_meta_command()
24110 showHelp(p->out, "import"); in do_meta_command()
24116 /* If neither the --csv or --ascii options are specified, then set in do_meta_command()
24118 nSep = strlen30(p->colSeparator); in do_meta_command()
24121 "Error: non-null column separator required for import\n"); in do_meta_command()
24126 "Error: multi-character column separators not allowed" in do_meta_command()
24130 nSep = strlen30(p->rowSeparator); in do_meta_command()
24133 "Error: non-null row separator required for import\n"); in do_meta_command()
24136 if( nSep==2 && p->mode==MODE_Csv in do_meta_command()
24137 && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 in do_meta_command()
24143 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row); in do_meta_command()
24144 nSep = strlen30(p->rowSeparator); in do_meta_command()
24147 raw_printf(stderr, "Error: multi-character row separators not allowed" in do_meta_command()
24151 sCtx.cColSep = (u8)p->colSeparator[0]; in do_meta_command()
24152 sCtx.cRowSep = (u8)p->rowSeparator[0]; in do_meta_command()
24177 utf8_printf(p->out, "Column separator "); in do_meta_command()
24178 output_c_string(p->out, zSep); in do_meta_command()
24179 utf8_printf(p->out, ", row separator "); in do_meta_command()
24181 output_c_string(p->out, zSep); in do_meta_command()
24182 utf8_printf(p->out, "\n"); in do_meta_command()
24190 while( (nSkip--)>0 ){ in do_meta_command()
24204 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
24206 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){ in do_meta_command()
24217 utf8_printf((stdin_is_interactive && p->in==stdin)? p->out : stderr, in do_meta_command()
24235 utf8_printf(p->out, "%s\n", zCreate); in do_meta_command()
24237 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0); in do_meta_command()
24239 utf8_printf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db)); in do_meta_command()
24244 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
24248 utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db)); in do_meta_command()
24270 utf8_printf(p->out, "Insert using: %s\n", zSql); in do_meta_command()
24272 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
24274 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); in do_meta_command()
24280 needCommit = sqlite3_get_autocommit(p->db); in do_meta_command()
24281 if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0); in do_meta_command()
24287 ** Did we reach end-of-file before finding any columns? in do_meta_command()
24292 ** Did we reach end-of-file OR end-of-line before finding any in do_meta_command()
24296 if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break; in do_meta_command()
24297 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT); in do_meta_command()
24298 if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){ in do_meta_command()
24299 utf8_printf(stderr, "%s:%d: expected %d columns but found %d - " in do_meta_command()
24311 utf8_printf(stderr, "%s:%d: expected %d columns but found %d - " in do_meta_command()
24320 startLine, sqlite3_errmsg(p->db)); in do_meta_command()
24330 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0); in do_meta_command()
24332 utf8_printf(p->out, in do_meta_command()
24334 sCtx.nRow, sCtx.nErr, sCtx.nLine-1); in do_meta_command()
24349 utf8_printf(stderr, ".%s unavailable without --unsafe-testing\n", in do_meta_command()
24369 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1); in do_meta_command()
24381 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
24389 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
24397 if( sqlite3_column_int(pStmt,1)==-1 ){ in do_meta_command()
24425 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum); in do_meta_command()
24427 rc = sqlite3_exec(p->db, zSql, 0, 0, 0); in do_meta_command()
24428 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0); in do_meta_command()
24430 utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db)); in do_meta_command()
24453 }else if( cli_strcmp(azArg[1], "-")==0 ){ in do_meta_command()
24492 sqlite3_limit(p->db, aLimit[i].limitCode, -1)); in do_meta_command()
24495 raw_printf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n"); in do_meta_command()
24499 int iLimit = -1; in do_meta_command()
24520 sqlite3_limit(p->db, aLimit[iLimit].limitCode, in do_meta_command()
24524 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1)); in do_meta_command()
24539 /* Must have a non-empty FILE. (Will not load self.) */ in do_meta_command()
24547 rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg); in do_meta_command()
24562 if( p->bSafeMode in do_meta_command()
24570 output_file_close(p->pLog); in do_meta_command()
24572 p->pLog = output_file_open(zFile, 0); in do_meta_command()
24595 /* Apply defaults for qbox pseudo-mode. If that in do_meta_command()
24596 * overwrites already-set values, user was informed of this. in do_meta_command()
24605 }else if( z[0]=='-' ){ in do_meta_command()
24608 " --noquote\n" in do_meta_command()
24609 " --quote\n" in do_meta_command()
24610 " --wordwrap on/off\n" in do_meta_command()
24611 " --wrap N\n" in do_meta_command()
24612 " --ww\n"); in do_meta_command()
24622 if( p->mode==MODE_Column in do_meta_command()
24623 || (p->mode>=MODE_Markdown && p->mode<=MODE_Box) in do_meta_command()
24626 (p->out, in do_meta_command()
24627 "current output mode: %s --wrap %d --wordwrap %s --%squote\n", in do_meta_command()
24628 modeDescr[p->mode], p->cmOpts.iWrap, in do_meta_command()
24629 p->cmOpts.bWordWrap ? "on" : "off", in do_meta_command()
24630 p->cmOpts.bQuote ? "" : "no"); in do_meta_command()
24632 raw_printf(p->out, "current output mode: %s\n", modeDescr[p->mode]); in do_meta_command()
24634 zMode = modeDescr[p->mode]; in do_meta_command()
24638 p->mode = MODE_Line; in do_meta_command()
24639 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row); in do_meta_command()
24641 p->mode = MODE_Column; in do_meta_command()
24642 if( (p->shellFlgs & SHFLG_HeaderSet)==0 ){ in do_meta_command()
24643 p->showHeader = 1; in do_meta_command()
24645 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row); in do_meta_command()
24646 p->cmOpts = cmOpts; in do_meta_command()
24648 p->mode = MODE_List; in do_meta_command()
24649 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Column); in do_meta_command()
24650 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row); in do_meta_command()
24652 p->mode = MODE_Html; in do_meta_command()
24654 p->mode = MODE_Tcl; in do_meta_command()
24655 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space); in do_meta_command()
24656 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row); in do_meta_command()
24658 p->mode = MODE_Csv; in do_meta_command()
24659 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma); in do_meta_command()
24660 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf); in do_meta_command()
24662 p->mode = MODE_List; in do_meta_command()
24663 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Tab); in do_meta_command()
24665 p->mode = MODE_Insert; in do_meta_command()
24668 p->mode = MODE_Quote; in do_meta_command()
24669 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma); in do_meta_command()
24670 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row); in do_meta_command()
24672 p->mode = MODE_Ascii; in do_meta_command()
24673 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit); in do_meta_command()
24674 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record); in do_meta_command()
24676 p->mode = MODE_Markdown; in do_meta_command()
24677 p->cmOpts = cmOpts; in do_meta_command()
24679 p->mode = MODE_Table; in do_meta_command()
24680 p->cmOpts = cmOpts; in do_meta_command()
24682 p->mode = MODE_Box; in do_meta_command()
24683 p->cmOpts = cmOpts; in do_meta_command()
24685 p->mode = MODE_Count; in do_meta_command()
24687 p->mode = MODE_Off; in do_meta_command()
24689 p->mode = MODE_Json; in do_meta_command()
24696 p->cMode = p->mode; in do_meta_command()
24704 }else if( p->zNonce==0 || cli_strcmp(azArg[1],p->zNonce)!=0 ){ in do_meta_command()
24706 p->lineno, azArg[1]); in do_meta_command()
24709 p->bSafeMode = 0; in do_meta_command()
24718 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue, in do_meta_command()
24719 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]); in do_meta_command()
24733 /* Check for command-line arguments */ in do_meta_command()
24748 p->openFlags |= SQLITE_OPEN_NOFOLLOW; in do_meta_command()
24755 p->szMax = integerValue(azArg[++iName]); in do_meta_command()
24759 if( z[0]=='-' ){ in do_meta_command()
24773 session_close_all(p, -1); in do_meta_command()
24774 close_db(p->db); in do_meta_command()
24775 p->db = 0; in do_meta_command()
24776 p->pAuxDb->zDbFilename = 0; in do_meta_command()
24777 sqlite3_free(p->pAuxDb->zFreeOnClose); in do_meta_command()
24778 p->pAuxDb->zFreeOnClose = 0; in do_meta_command()
24779 p->openMode = openMode; in do_meta_command()
24780 p->openFlags = 0; in do_meta_command()
24781 p->szMax = 0; in do_meta_command()
24784 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){ in do_meta_command()
24785 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN); in do_meta_command()
24787 if( p->bSafeMode in do_meta_command()
24788 && p->openMode!=SHELL_OPEN_HEXDB in do_meta_command()
24792 failIfSafeMode(p, "cannot open disk-based database files in safe mode"); in do_meta_command()
24795 /* WASM mode has its own sandboxed pseudo-filesystem. */ in do_meta_command()
24803 p->pAuxDb->zDbFilename = zNewFilename; in do_meta_command()
24805 if( p->db==0 ){ in do_meta_command()
24809 p->pAuxDb->zFreeOnClose = zNewFilename; in do_meta_command()
24812 if( p->db==0 ){ in do_meta_command()
24813 /* As a fall-back open a TEMP database */ in do_meta_command()
24814 p->pAuxDb->zDbFilename = 0; in do_meta_command()
24830 unsigned char zBOM[4]; /* Byte-order mark to using if --bom is present */ in do_meta_command()
24842 if( z[0]=='-' ){ in do_meta_command()
24843 if( z[1]=='-' ) z++; in do_meta_command()
24844 if( cli_strcmp(z,"-bom")==0 ){ in do_meta_command()
24849 }else if( c!='e' && cli_strcmp(z,"-x")==0 ){ in do_meta_command()
24851 }else if( c!='e' && cli_strcmp(z,"-e")==0 ){ in do_meta_command()
24854 utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", in do_meta_command()
24856 showHelp(p->out, azArg[0]); in do_meta_command()
24867 utf8_printf(p->out,"ERROR: extra parameter: \"%s\". Usage:\n", in do_meta_command()
24869 showHelp(p->out, azArg[0]); in do_meta_command()
24879 p->outCount = 2; in do_meta_command()
24881 p->outCount = 0; in do_meta_command()
24886 p->doXdgOpen = 1; in do_meta_command()
24892 p->mode = MODE_Csv; in do_meta_command()
24893 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma); in do_meta_command()
24894 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf); in do_meta_command()
24901 zFile = sqlite3_mprintf("%s", p->zTempFile); in do_meta_command()
24909 p->out = stdout; in do_meta_command()
24911 p->out = popen(zFile + 1, "w"); in do_meta_command()
24912 if( p->out==0 ){ in do_meta_command()
24914 p->out = stdout; in do_meta_command()
24917 if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out); in do_meta_command()
24918 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); in do_meta_command()
24922 p->out = output_file_open(zFile, bTxtMode); in do_meta_command()
24923 if( p->out==0 ){ in do_meta_command()
24927 p->out = stdout; in do_meta_command()
24930 if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out); in do_meta_command()
24931 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); in do_meta_command()
24946 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.sqlite_parameters;", in do_meta_command()
24957 rx = sqlite3_prepare_v2(p->db, in do_meta_command()
24959 "FROM temp.sqlite_parameters;", -1, &pStmt, 0); in do_meta_command()
24967 rx = sqlite3_prepare_v2(p->db, in do_meta_command()
24969 "FROM temp.sqlite_parameters;", -1, &pStmt, 0); in do_meta_command()
24971 utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0), in do_meta_command()
25004 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
25013 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
25016 utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db)); in do_meta_command()
25034 sqlite3_exec(p->db, zSql, 0, 0, 0); in do_meta_command()
25039 showHelp(p->out, "parameter"); in do_meta_command()
25045 if( i>1 ) raw_printf(p->out, " "); in do_meta_command()
25046 utf8_printf(p->out, "%s", azArg[i]); in do_meta_command()
25048 raw_printf(p->out, "\n"); in do_meta_command()
25055 p->flgProgress = 0; in do_meta_command()
25056 p->mxProgress = 0; in do_meta_command()
25057 p->nProgress = 0; in do_meta_command()
25060 if( z[0]=='-' ){ in do_meta_command()
25062 if( z[0]=='-' ) z++; in do_meta_command()
25064 p->flgProgress |= SHELL_PROGRESS_QUIET; in do_meta_command()
25068 p->flgProgress |= SHELL_PROGRESS_RESET; in do_meta_command()
25072 p->flgProgress |= SHELL_PROGRESS_ONCE; in do_meta_command()
25077 utf8_printf(stderr, "Error: missing argument on --limit\n"); in do_meta_command()
25081 p->mxProgress = (int)integerValue(azArg[++i]); in do_meta_command()
25093 sqlite3_progress_handler(p->db, nn, progress_handler, p); in do_meta_command()
25099 shell_strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1); in do_meta_command()
25102 shell_strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1); in do_meta_command()
25114 FILE *inSaved = p->in; in do_meta_command()
25115 int savedLineno = p->lineno; in do_meta_command()
25126 p->out = stdout; in do_meta_command()
25128 p->in = popen(azArg[1]+1, "r"); in do_meta_command()
25129 if( p->in==0 ){ in do_meta_command()
25134 pclose(p->in); in do_meta_command()
25137 }else if( (p->in = openChrSource(azArg[1]))==0 ){ in do_meta_command()
25142 fclose(p->in); in do_meta_command()
25144 p->in = inSaved; in do_meta_command()
25145 p->lineno = savedLineno; in do_meta_command()
25176 pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main"); in do_meta_command()
25178 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); in do_meta_command()
25196 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); in do_meta_command()
25206 p->scanstatsOn = 2; in do_meta_command()
25208 p->scanstatsOn = (u8)booleanValue(azArg[1]); in do_meta_command()
25212 p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, p->scanstatsOn, (int*)0 in do_meta_command()
25246 }else if( azArg[ii][0]=='-' ){ in do_meta_command()
25254 "Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n"); in do_meta_command()
25284 rc = sqlite3_prepare_v2(p->db, "SELECT name FROM pragma_database_list", in do_meta_command()
25285 -1, &pStmt, 0); in do_meta_command()
25287 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); in do_meta_command()
25349 utf8_printf(p->out, "SQL: %s;\n", sSelect.z); in do_meta_command()
25351 rc = sqlite3_exec(p->db, sSelect.z, callback, &data, &zErrMsg); in do_meta_command()
25376 struct AuxDb *pAuxDb = p->pAuxDb; in do_meta_command()
25377 OpenSession *pSession = &pAuxDb->aSession[0]; in do_meta_command()
25380 int nCmd = nArg - 1; in do_meta_command()
25385 for(iSes=0; iSes<pAuxDb->nSession; iSes++){ in do_meta_command()
25386 if( cli_strcmp(pAuxDb->aSession[iSes].zName, azArg[1])==0 ) break; in do_meta_command()
25388 if( iSes<pAuxDb->nSession ){ in do_meta_command()
25389 pSession = &pAuxDb->aSession[iSes]; in do_meta_command()
25391 nCmd--; in do_meta_command()
25393 pSession = &pAuxDb->aSession[0]; in do_meta_command()
25404 if( pSession->p==0 ){ in do_meta_command()
25408 rc = sqlite3session_attach(pSession->p, azCmd[1]); in do_meta_command()
25426 if( pSession->p==0 ) goto session_not_open; in do_meta_command()
25435 rc = sqlite3session_changeset(pSession->p, &szChng, &pChng); in do_meta_command()
25437 rc = sqlite3session_patchset(pSession->p, &szChng, &pChng); in do_meta_command()
25445 raw_printf(stderr, "ERROR: Failed to write entire %d-byte output\n", in do_meta_command()
25458 if( pAuxDb->nSession ){ in do_meta_command()
25460 pAuxDb->aSession[iSes] = pAuxDb->aSession[--pAuxDb->nSession]; in do_meta_command()
25470 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]); in do_meta_command()
25471 if( pAuxDb->nSession ){ in do_meta_command()
25472 ii = sqlite3session_enable(pSession->p, ii); in do_meta_command()
25473 utf8_printf(p->out, "session %s enable flag = %d\n", in do_meta_command()
25474 pSession->zName, ii); in do_meta_command()
25484 if( pAuxDb->nSession ){ in do_meta_command()
25485 for(ii=0; ii<pSession->nFilter; ii++){ in do_meta_command()
25486 sqlite3_free(pSession->azFilter[ii]); in do_meta_command()
25488 sqlite3_free(pSession->azFilter); in do_meta_command()
25489 nByte = sizeof(pSession->azFilter[0])*(nCmd-1); in do_meta_command()
25490 pSession->azFilter = sqlite3_malloc( nByte ); in do_meta_command()
25491 if( pSession->azFilter==0 ){ in do_meta_command()
25496 char *x = pSession->azFilter[ii-1] = sqlite3_mprintf("%s", azCmd[ii]); in do_meta_command()
25499 pSession->nFilter = ii-1; in do_meta_command()
25509 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]); in do_meta_command()
25510 if( pAuxDb->nSession ){ in do_meta_command()
25511 ii = sqlite3session_indirect(pSession->p, ii); in do_meta_command()
25512 utf8_printf(p->out, "session %s indirect flag = %d\n", in do_meta_command()
25513 pSession->zName, ii); in do_meta_command()
25523 if( pAuxDb->nSession ){ in do_meta_command()
25524 ii = sqlite3session_isempty(pSession->p); in do_meta_command()
25525 utf8_printf(p->out, "session %s isempty flag = %d\n", in do_meta_command()
25526 pSession->zName, ii); in do_meta_command()
25534 for(i=0; i<pAuxDb->nSession; i++){ in do_meta_command()
25535 utf8_printf(p->out, "%d %s\n", i, pAuxDb->aSession[i].zName); in do_meta_command()
25548 for(i=0; i<pAuxDb->nSession; i++){ in do_meta_command()
25549 if( cli_strcmp(pAuxDb->aSession[i].zName,zName)==0 ){ in do_meta_command()
25554 if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){ in do_meta_command()
25556 "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession)); in do_meta_command()
25559 pSession = &pAuxDb->aSession[pAuxDb->nSession]; in do_meta_command()
25560 rc = sqlite3session_create(p->db, azCmd[1], &pSession->p); in do_meta_command()
25566 pSession->nFilter = 0; in do_meta_command()
25567 sqlite3session_table_filter(pSession->p, session_filter, pSession); in do_meta_command()
25568 pAuxDb->nSession++; in do_meta_command()
25569 pSession->zName = sqlite3_mprintf("%s", zName); in do_meta_command()
25570 shell_check_oom(pSession->zName); in do_meta_command()
25574 showHelp(p->out, "session"); in do_meta_command()
25581 if( c=='s' && n>=10 && cli_strncmp(azArg[0], "selftest-", 9)==0 ){ in do_meta_command()
25582 if( cli_strncmp(azArg[0]+9, "boolean", n-9)==0 ){ in do_meta_command()
25586 utf8_printf(p->out, "%s: %d 0x%x\n", azArg[i], v, v); in do_meta_command()
25589 if( cli_strncmp(azArg[0]+9, "integer", n-9)==0 ){ in do_meta_command()
25595 utf8_printf(p->out, "%s", zBuf); in do_meta_command()
25614 if( z[0]=='-' && z[1]=='-' ) z++; in do_meta_command()
25615 if( cli_strcmp(z,"-init")==0 ){ in do_meta_command()
25618 if( cli_strcmp(z,"-v")==0 ){ in do_meta_command()
25624 raw_printf(stderr, "Should be one of: --init -v\n"); in do_meta_command()
25629 if( sqlite3_table_column_metadata(p->db,"main","selftest",0,0,0,0,0,0) in do_meta_command()
25641 for(k=bSelftestExists; k>=0; k--){ in do_meta_command()
25643 rc = sqlite3_prepare_v2(p->db, in do_meta_command()
25645 -1, &pStmt, 0); in do_meta_command()
25647 rc = sqlite3_prepare_v2(p->db, in do_meta_command()
25648 "VALUES(0,'memo','Missing SELFTEST table - default checks only','')," in do_meta_command()
25650 -1, &pStmt, 0); in do_meta_command()
25672 utf8_printf(p->out, "%s\n", zSql); in do_meta_command()
25678 rc = sqlite3_exec(p->db, zSql, captureOutputCallback, &str, &zErrMsg); in do_meta_command()
25681 utf8_printf(p->out, "Result: %s\n", str.z); in do_meta_command()
25686 utf8_printf(p->out, "%d: error-code-%d: %s\n", tno, rc, zErrMsg); in do_meta_command()
25691 utf8_printf(p->out, "%d: Expected: [%s]\n", tno, zAns); in do_meta_command()
25692 utf8_printf(p->out, "%d: Got: [%s]\n", tno, str.z); in do_meta_command()
25705 utf8_printf(p->out, "%d errors out of %d tests\n", nErr, nTest); in do_meta_command()
25714 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, in do_meta_command()
25715 "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]); in do_meta_command()
25718 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, in do_meta_command()
25719 "%.*s", (int)ArraySize(p->rowSeparator)-1, azArg[2]); in do_meta_command()
25738 if( z[0]=='-' ){ in do_meta_command()
25740 if( z[0]=='-' ) z++; in do_meta_command()
25744 if( cli_strcmp(z,"sha3-224")==0 || cli_strcmp(z,"sha3-256")==0 in do_meta_command()
25745 || cli_strcmp(z,"sha3-384")==0 || cli_strcmp(z,"sha3-512")==0 in do_meta_command()
25755 showHelp(p->out, azArg[0]); in do_meta_command()
25760 raw_printf(stderr, "Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n"); in do_meta_command()
25780 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
25832 utf8_printf(p->out, "%s\n", zSql); in do_meta_command()
25839 char *zRevText = /* Query for reversible to-blob-to-text check */ in do_meta_command()
25846 /* lower-case query is first run, producing upper-case query. */ in do_meta_command()
25861 if( bDebug ) utf8_printf(p->out, "%s\n", zRevText); in do_meta_command()
25862 lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0); in do_meta_command()
25868 if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC); in do_meta_command()
25873 lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0); in do_meta_command()
25874 if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery); in do_meta_command()
25932 utf8_printf(p->out, "%12.12s: %s\n","echo", in do_meta_command()
25934 utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]); in do_meta_command()
25935 utf8_printf(p->out, "%12.12s: %s\n","explain", in do_meta_command()
25936 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off"); in do_meta_command()
25937 utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]); in do_meta_command()
25938 if( p->mode==MODE_Column in do_meta_command()
25939 || (p->mode>=MODE_Markdown && p->mode<=MODE_Box) in do_meta_command()
25942 (p->out, "%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode", in do_meta_command()
25943 modeDescr[p->mode], p->cmOpts.iWrap, in do_meta_command()
25944 p->cmOpts.bWordWrap ? "on" : "off", in do_meta_command()
25945 p->cmOpts.bQuote ? "" : "no"); in do_meta_command()
25947 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]); in do_meta_command()
25949 utf8_printf(p->out, "%12.12s: ", "nullvalue"); in do_meta_command()
25950 output_c_string(p->out, p->nullValue); in do_meta_command()
25951 raw_printf(p->out, "\n"); in do_meta_command()
25952 utf8_printf(p->out,"%12.12s: %s\n","output", in do_meta_command()
25953 strlen30(p->outfile) ? p->outfile : "stdout"); in do_meta_command()
25954 utf8_printf(p->out,"%12.12s: ", "colseparator"); in do_meta_command()
25955 output_c_string(p->out, p->colSeparator); in do_meta_command()
25956 raw_printf(p->out, "\n"); in do_meta_command()
25957 utf8_printf(p->out,"%12.12s: ", "rowseparator"); in do_meta_command()
25958 output_c_string(p->out, p->rowSeparator); in do_meta_command()
25959 raw_printf(p->out, "\n"); in do_meta_command()
25960 switch( p->statsOn ){ in do_meta_command()
25966 utf8_printf(p->out, "%12.12s: %s\n","stats", zOut); in do_meta_command()
25967 utf8_printf(p->out, "%12.12s: ", "width"); in do_meta_command()
25968 for (i=0;i<p->nWidth;i++) { in do_meta_command()
25969 raw_printf(p->out, "%d ", p->colWidth[i]); in do_meta_command()
25971 raw_printf(p->out, "\n"); in do_meta_command()
25972 utf8_printf(p->out, "%12.12s: %s\n", "filename", in do_meta_command()
25973 p->pAuxDb->zDbFilename ? p->pAuxDb->zDbFilename : ""); in do_meta_command()
25979 p->statsOn = 2; in do_meta_command()
25981 p->statsOn = 3; in do_meta_command()
25983 p->statsOn = (u8)booleanValue(azArg[1]); in do_meta_command()
25986 display_stats(p->db, p, 0); in do_meta_command()
26004 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0); in do_meta_command()
26007 return shellDatabaseError(p->db); in do_meta_command()
26014 raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n"); in do_meta_command()
26044 rc = sqlite3_prepare_v2(p->db, s.z, -1, &pStmt, 0); in do_meta_command()
26047 if( rc ) return shellDatabaseError(p->db); in do_meta_command()
26050 ** as an array of nul-terminated strings in azResult[]. */ in do_meta_command()
26054 sqlite3_bind_text(pStmt, 1, azArg[1], -1, SQLITE_TRANSIENT); in do_meta_command()
26056 sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC); in do_meta_command()
26072 rc = shellDatabaseError(p->db); in do_meta_command()
26075 /* Pretty-print the contents of array azResult[] to the output */ in do_meta_command()
26086 nPrintRow = (nRow + nPrintCol - 1)/nPrintCol; in do_meta_command()
26090 utf8_printf(p->out, "%s%-*s", zSp, maxlen, in do_meta_command()
26093 raw_printf(p->out, "\n"); in do_meta_command()
26102 /* Begin redirecting output to the file "testcase-out.txt" */ in do_meta_command()
26105 p->out = output_file_open("testcase-out.txt", 0); in do_meta_command()
26106 if( p->out==0 ){ in do_meta_command()
26107 raw_printf(stderr, "Error: cannot open 'testcase-out.txt'\n"); in do_meta_command()
26110 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]); in do_meta_command()
26112 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?"); in do_meta_command()
26120 const char *zCtrlName; /* Name of a test-control option */ in do_meta_command()
26122 int unSafe; /* Not valid for --safe mode */ in do_meta_command()
26136 {"optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS,0,"DISABLE-MASK" }, in do_meta_command()
26148 int testctrl = -1; in do_meta_command()
26149 int iCtrl = -1; in do_meta_command()
26150 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */ in do_meta_command()
26156 utf8_printf(stderr, ".%s unavailable without --unsafe-testing\n", in do_meta_command()
26164 /* The argument can optionally begin with "-" or "--" */ in do_meta_command()
26165 if( zCmd[0]=='-' && zCmd[1] ){ in do_meta_command()
26167 if( zCmd[0]=='-' && zCmd[1] ) zCmd++; in do_meta_command()
26170 /* --help lists all test-controls */ in do_meta_command()
26172 utf8_printf(p->out, "Available test-controls:\n"); in do_meta_command()
26174 utf8_printf(p->out, " .testctrl %s %s\n", in do_meta_command()
26190 utf8_printf(stderr, "Error: ambiguous test-control: \"%s\"\n" in do_meta_command()
26191 "Use \".testctrl --help\" for help\n", zCmd); in do_meta_command()
26198 utf8_printf(stderr,"Error: unknown test-control: %s\n" in do_meta_command()
26199 "Use \".testctrl --help\" for help\n", zCmd); in do_meta_command()
26200 }else if( aCtrl[iCtrl].unSafe && p->bSafeMode ){ in do_meta_command()
26203 p->lineno, aCtrl[iCtrl].zCtrlName); in do_meta_command()
26212 rc2 = sqlite3_test_control(testctrl, p->db, opt); in do_meta_command()
26243 printf("-- random seed: %d\n", ii); in do_meta_command()
26248 db = p->db; in do_meta_command()
26279 rc2 = sqlite3_test_control(testctrl, p->db); in do_meta_command()
26285 rc2 = sqlite3_test_control(testctrl, p->db, in do_meta_command()
26295 rc2 = sqlite3_test_control(testctrl, p->db, &x); in do_meta_command()
26296 utf8_printf(p->out, "%llu\n", x); in do_meta_command()
26304 sqlite3_test_control(testctrl, p->out); in do_meta_command()
26319 sqlite3_test_control(testctrl, -id, &rc2); in do_meta_command()
26325 rc2 = sqlite3_test_control(testctrl, -id, &val); in do_meta_command()
26327 if( id>1 ) utf8_printf(p->out, " "); in do_meta_command()
26328 utf8_printf(p->out, "%d: %d", id, val); in do_meta_command()
26331 if( id>1 ) utf8_printf(p->out, "\n"); in do_meta_command()
26340 rc2 = sqlite3_test_control(testctrl, p->db, opt); in do_meta_command()
26347 utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage); in do_meta_command()
26350 raw_printf(p->out, "%d\n", rc2); in do_meta_command()
26352 raw_printf(p->out, "0x%08x\n", rc2); in do_meta_command()
26359 sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0); in do_meta_command()
26382 if( z[0]=='-' ){ in do_meta_command()
26384 p->eTraceType = SHELL_TRACE_EXPANDED; in do_meta_command()
26388 p->eTraceType = SHELL_TRACE_NORMALIZED; in do_meta_command()
26392 p->eTraceType = SHELL_TRACE_PLAIN; in do_meta_command()
26412 output_file_close(p->traceOut); in do_meta_command()
26413 p->traceOut = output_file_open(z, 0); in do_meta_command()
26416 if( p->traceOut==0 ){ in do_meta_command()
26417 sqlite3_trace_v2(p->db, 0, 0, 0); in do_meta_command()
26420 sqlite3_trace_v2(p->db, mType, sql_trace_callback, p); in do_meta_command()
26431 raw_printf(stderr, "Usage: .unmodule [--allexcept] NAME ...\n"); in do_meta_command()
26437 if( zOpt[0]=='-' && zOpt[1]=='-' && zOpt[2]!=0 ) zOpt++; in do_meta_command()
26439 if( lenOpt>=3 && cli_strncmp(zOpt, "-allexcept",lenOpt)==0 ){ in do_meta_command()
26441 sqlite3_drop_modules(p->db, nArg>2 ? (const char**)(azArg+2) : 0); in do_meta_command()
26444 sqlite3_create_module(p->db, azArg[ii], 0, 0); in do_meta_command()
26464 rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3], in do_meta_command()
26476 rc = sqlite3_user_add(p->db, azArg[2], azArg[3], strlen30(azArg[3]), in do_meta_command()
26479 raw_printf(stderr, "User-Add failed: %d\n", rc); in do_meta_command()
26488 rc = sqlite3_user_change(p->db, azArg[2], azArg[3], strlen30(azArg[3]), in do_meta_command()
26491 raw_printf(stderr, "User-Edit failed: %d\n", rc); in do_meta_command()
26500 rc = sqlite3_user_delete(p->db, azArg[2]); in do_meta_command()
26502 raw_printf(stderr, "User-Delete failed: %d\n", rc); in do_meta_command()
26514 utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/, in do_meta_command()
26517 utf8_printf(p->out, "zlib version %s\n", zlibVersion()); in do_meta_command()
26522 utf8_printf(p->out, "clang-" CTIMEOPT_VAL(__clang_major__) "." in do_meta_command()
26526 utf8_printf(p->out, "msvc-" CTIMEOPT_VAL(_MSC_VER) "\n"); in do_meta_command()
26528 utf8_printf(p->out, "gcc-" __VERSION__ "\n"); in do_meta_command()
26535 if( p->db ){ in do_meta_command()
26536 sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs); in do_meta_command()
26538 utf8_printf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName); in do_meta_command()
26539 raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion); in do_meta_command()
26540 raw_printf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile); in do_meta_command()
26541 raw_printf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname); in do_meta_command()
26549 if( p->db ){ in do_meta_command()
26550 sqlite3_file_control(p->db, "main", SQLITE_FCNTL_VFS_POINTER, &pCurrent); in do_meta_command()
26552 for(pVfs=sqlite3_vfs_find(0); pVfs; pVfs=pVfs->pNext){ in do_meta_command()
26553 utf8_printf(p->out, "vfs.zName = \"%s\"%s\n", pVfs->zName, in do_meta_command()
26554 pVfs==pCurrent ? " <--- CURRENT" : ""); in do_meta_command()
26555 raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion); in do_meta_command()
26556 raw_printf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile); in do_meta_command()
26557 raw_printf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname); in do_meta_command()
26558 if( pVfs->pNext ){ in do_meta_command()
26559 raw_printf(p->out, "-----------------------------------\n"); in do_meta_command()
26567 if( p->db ){ in do_meta_command()
26568 sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName); in do_meta_command()
26570 utf8_printf(p->out, "%s\n", zVfsName); in do_meta_command()
26584 p->nWidth = nArg-1; in do_meta_command()
26585 p->colWidth = realloc(p->colWidth, (p->nWidth+1)*sizeof(int)*2); in do_meta_command()
26586 if( p->colWidth==0 && p->nWidth>0 ) shell_out_of_memory(); in do_meta_command()
26587 if( p->nWidth ) p->actualWidth = &p->colWidth[p->nWidth]; in do_meta_command()
26589 p->colWidth[j-1] = (int)integerValue(azArg[j]); in do_meta_command()
26600 if( p->outCount ){ in do_meta_command()
26601 p->outCount--; in do_meta_command()
26602 if( p->outCount==0 ) output_reset(p); in do_meta_command()
26604 p->bSafeMode = p->bSafeModePersist; in do_meta_command()
26615 QSS_CharMask = (1<<CHAR_BIT)-1, QSS_ScanMask = 3<<CHAR_BIT,
26640 case '-': in quickscan()
26641 if( *zLine!='-' ) in quickscan()
26671 CONTINUE_PAREN_INCR(pst, -1); in quickscan()
26693 /* Swallow doubled end-delimiter.*/ in quickscan()
26713 ** than a semi-colon. The SQL Server style "go" command is understood
26737 ** ends in the middle of a string literal or C-style comment.
26758 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0; in runOneSqlLine()
26768 zErrorTail = sqlite3_errmsg(p->db); in runOneSqlLine()
26793 sqlite3_changes64(p->db), sqlite3_total_changes64(p->db)); in runOneSqlLine()
26794 raw_printf(p->out, "%s\n", zLineBuf); in runOneSqlLine()
26800 if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo); in echo_group_input()
26824 if(nZ>0 && '\r'==zBegin[nZ-1]){ in one_input_line()
26825 --nZ; in one_input_line()
26838 ** is interactive - the user is typing it it. Otherwise, input
26856 if( p->inputNesting==MAX_INPUT_NESTING ){ in process_input()
26859 " Check recursion.\n", MAX_INPUT_NESTING, p->lineno); in process_input()
26862 ++p->inputNesting; in process_input()
26863 p->lineno = 0; in process_input()
26865 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){ in process_input()
26866 fflush(p->out); in process_input()
26867 zLine = one_input_line(p->in, zLine, nSql>0); in process_input()
26870 if( p->in==0 && stdin_is_interactive ) printf("\n"); in process_input()
26874 if( p->in!=0 ) break; in process_input()
26877 p->lineno++; in process_input()
26885 /* Just swallow single-line whitespace */ in process_input()
26904 /* No single-line dispositions remain; accumulate line(s). */ in process_input()
26907 /* Grow buffer by half-again increments when big. */ in process_input()
26916 memcpy(zSql, zLine+i, nLine+1-i); in process_input()
26917 startline = p->lineno; in process_input()
26918 nSql = nLine-i; in process_input()
26926 errCnt += runOneSqlLine(p, zSql, p->in, startline); in process_input()
26929 if( p->outCount ){ in process_input()
26931 p->outCount = 0; in process_input()
26935 p->bSafeMode = p->bSafeModePersist; in process_input()
26946 errCnt += runOneSqlLine(p, zSql, p->in, startline); in process_input()
26951 --p->inputNesting; in process_input()
26974 home_dir = pwent->pw_dir; in find_home_dir()
26980 /* Windows CE (arm-wince-mingw32ce-gcc) does not provide getenv() in find_home_dir()
27025 ** On non-Windows platforms, look for $XDG_CONFIG_HOME.
27071 FILE *inSaved = p->in; in process_sqliterc()
27072 int savedLineno = p->lineno; in process_sqliterc()
27080 raw_printf(stderr, "-- warning: cannot find home directory;" in process_sqliterc()
27088 p->in = fopen(sqliterc,"rb"); in process_sqliterc()
27089 if( p->in ){ in process_sqliterc()
27091 utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc); in process_sqliterc()
27094 fclose(p->in); in process_sqliterc()
27099 p->in = inSaved; in process_sqliterc()
27100 p->lineno = savedLineno; in process_sqliterc()
27108 " -- treat no subsequent arguments as options\n"
27110 " -A ARGS... run \".archive ARGS\" and exit\n"
27112 " -append append the database to the end of the file\n"
27113 " -ascii set output mode to 'ascii'\n"
27114 " -bail stop after hitting an error\n"
27115 " -batch force batch I/O\n"
27116 " -box set output mode to 'box'\n"
27117 " -column set output mode to 'column'\n"
27118 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
27119 " -csv set output mode to 'csv'\n"
27121 " -deserialize open the database using sqlite3_deserialize()\n"
27123 " -echo print inputs before execution\n"
27124 " -init FILENAME read/process named file\n"
27125 " -[no]header turn headers on or off\n"
27127 " -heap SIZE Size of heap for memsys3 or memsys5\n"
27129 " -help show this message\n"
27130 " -html set output mode to HTML\n"
27131 " -interactive force interactive I/O\n"
27132 " -json set output mode to 'json'\n"
27133 " -line set output mode to 'line'\n"
27134 " -list set output mode to 'list'\n"
27135 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
27136 " -markdown set output mode to 'markdown'\n"
27138 " -maxsize N maximum size for a --deserialize database\n"
27140 " -memtrace trace all memory allocations and deallocations\n"
27141 " -mmap N default mmap size set to N\n"
27143 " -multiplex enable the multiplexor VFS\n"
27145 " -newline SEP set output row separator. Default: '\\n'\n"
27146 " -nofollow refuse to open symbolic links to database files\n"
27147 " -nonce STRING set the safe-mode escape nonce\n"
27148 " -nullvalue TEXT set text string for NULL values. Default ''\n"
27149 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
27150 " -quote set output mode to 'quote'\n"
27151 " -readonly open the database read-only\n"
27152 " -safe enable safe-mode\n"
27153 " -separator SEP set output column separator. Default: '|'\n"
27155 " -sorterref SIZE sorter references threshold size\n"
27157 " -stats print memory stats before each finalize\n"
27158 " -table set output mode to 'table'\n"
27159 " -tabs set output mode to 'tabs'\n"
27160 " -unsafe-testing allow unsafe commands and modes for testing\n"
27162 " -utf8 setup interactive console code page for UTF-8\n"
27164 " -version show SQLite version\n"
27165 " -vfs NAME use NAME as the default VFS\n"
27167 " -vfstrace enable tracing of all VFS calls\n"
27170 " -zip open the file as a ZIP Archive\n"
27181 raw_printf(stderr, "Use the -help option for additional information\n"); in usage()
27191 if( sqlite3_config(-1)==SQLITE_MISUSE ){ in verify_uninitialized()
27202 data->normalMode = data->cMode = data->mode = MODE_List; in main_init()
27203 data->autoExplain = 1; in main_init()
27204 data->pAuxDb = &data->aAuxDb[0]; in main_init()
27205 memcpy(data->colSeparator,SEP_Column, 2); in main_init()
27206 memcpy(data->rowSeparator,SEP_Row, 2); in main_init()
27207 data->showHeader = 0; in main_init()
27208 data->shellFlgs = SHFLG_Lookaside; in main_init()
27244 ** Get the argument to an --option. Throw an error and die if no argument
27250 argv[0], argv[argc-1]); in cmdline_option_value()
27296 const char *zVfs = 0; /* Value of -vfs command-line option */
27356 /* On Windows, we must translate command-line arguments into UTF-8.
27388 ** of a C-function that will provide the name of the database file. Use
27389 ** this compile-time option to embed this shell program in larger
27392 SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
27397 /* Do an initial pass through the command-line argument to locate
27408 if( z[0]!='-' || i>nOptsEnd ){
27409 if( data.aAuxDb->zDbFilename==0 ){
27410 data.aAuxDb->zDbFilename = z;
27412 /* Excesss arguments are interpreted as SQL (or dot-commands) and
27418 azCmd[nCmd-1] = z;
27422 if( z[1]=='-' ) z++;
27423 if( cli_strcmp(z, "-")==0 ){
27426 }else if( cli_strcmp(z,"-separator")==0
27427 || cli_strcmp(z,"-nullvalue")==0
27428 || cli_strcmp(z,"-newline")==0
27429 || cli_strcmp(z,"-cmd")==0
27432 }else if( cli_strcmp(z,"-init")==0 ){
27434 }else if( cli_strcmp(z,"-batch")==0 ){
27440 }else if( cli_strcmp(z,"-heap")==0 ){
27453 }else if( cli_strcmp(z,"-pagecache")==0 ){
27466 }else if( cli_strcmp(z,"-lookaside")==0 ){
27475 }else if( cli_strcmp(z,"-threadsafe")==0 ){
27485 }else if( cli_strcmp(z,"-vfstrace")==0 ){
27496 }else if( cli_strcmp(z,"-multiplex")==0 ){
27500 }else if( cli_strcmp(z,"-mmap")==0 ){
27505 }else if( cli_strcmp(z,"-sorterref")==0 ){
27510 }else if( cli_strcmp(z,"-vfs")==0 ){
27513 }else if( cli_strcmp(z,"-zip")==0 ){
27516 }else if( cli_strcmp(z,"-append")==0 ){
27519 }else if( cli_strcmp(z,"-deserialize")==0 ){
27521 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
27524 }else if( cli_strcmp(z,"-readonly")==0 ){
27526 }else if( cli_strcmp(z,"-nofollow")==0 ){
27529 }else if( cli_strncmp(z, "-A",2)==0 ){
27530 /* All remaining command-line arguments are passed to the ".archive"
27534 }else if( cli_strcmp(z, "-memtrace")==0 ){
27536 }else if( cli_strcmp(z,"-bail")==0 ){
27538 }else if( cli_strcmp(z,"-nonce")==0 ){
27541 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
27543 }else if( cli_strcmp(z,"-safe")==0 ){
27544 /* no-op - catch this on the second pass */
27555 ** of a C-function that will perform initialization actions on SQLite that
27556 ** occur just before or after sqlite3_initialize(). Use this compile-time
27563 ** to call sqlite3_initialize() and process any command line -vfs option. */
27577 if( data.pAuxDb->zDbFilename==0 ){
27579 data.pAuxDb->zDbFilename = ":memory:";
27594 ** to the sqlite command-line tool.
27596 if( access(data.pAuxDb->zDbFilename, 0)==0 ){
27600 /* Process the initialization file if there is one. If no -init option
27606 /* Make a second pass through the command-line argument and set
27608 ** file is processed so that the command-line arguments will override
27613 if( z[0]!='-' || i>=nOptsEnd ) continue;
27614 if( z[1]=='-' ){ z++; }
27615 if( cli_strcmp(z,"-init")==0 ){
27617 }else if( cli_strcmp(z,"-html")==0 ){
27619 }else if( cli_strcmp(z,"-list")==0 ){
27621 }else if( cli_strcmp(z,"-quote")==0 ){
27625 }else if( cli_strcmp(z,"-line")==0 ){
27627 }else if( cli_strcmp(z,"-column")==0 ){
27629 }else if( cli_strcmp(z,"-json")==0 ){
27631 }else if( cli_strcmp(z,"-markdown")==0 ){
27633 }else if( cli_strcmp(z,"-table")==0 ){
27635 }else if( cli_strcmp(z,"-box")==0 ){
27637 }else if( cli_strcmp(z,"-csv")==0 ){
27641 }else if( cli_strcmp(z,"-zip")==0 ){
27644 }else if( cli_strcmp(z,"-append")==0 ){
27647 }else if( cli_strcmp(z,"-deserialize")==0 ){
27649 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
27652 }else if( cli_strcmp(z,"-readonly")==0 ){
27654 }else if( cli_strcmp(z,"-nofollow")==0 ){
27656 }else if( cli_strcmp(z,"-ascii")==0 ){
27660 }else if( cli_strcmp(z,"-tabs")==0 ){
27664 }else if( cli_strcmp(z,"-separator")==0 ){
27667 }else if( cli_strcmp(z,"-newline")==0 ){
27670 }else if( cli_strcmp(z,"-nullvalue")==0 ){
27673 }else if( cli_strcmp(z,"-header")==0 ){
27676 }else if( cli_strcmp(z,"-noheader")==0 ){
27679 }else if( cli_strcmp(z,"-echo")==0 ){
27681 }else if( cli_strcmp(z,"-eqp")==0 ){
27683 }else if( cli_strcmp(z,"-eqpfull")==0 ){
27685 }else if( cli_strcmp(z,"-stats")==0 ){
27687 }else if( cli_strcmp(z,"-scanstats")==0 ){
27689 }else if( cli_strcmp(z,"-backslash")==0 ){
27690 /* Undocumented command-line option: -backslash
27691 ** Causes C-style backslash escapes to be evaluated in SQL statements
27696 }else if( cli_strcmp(z,"-bail")==0 ){
27697 /* No-op. The bail_on_error flag should already be set. */
27698 }else if( cli_strcmp(z,"-version")==0 ){
27701 }else if( cli_strcmp(z,"-interactive")==0 ){
27703 }else if( cli_strcmp(z,"-batch")==0 ){
27705 }else if( cli_strcmp(z,"-utf8")==0 ){
27709 }else if( cli_strcmp(z,"-heap")==0 ){
27711 }else if( cli_strcmp(z,"-pagecache")==0 ){
27713 }else if( cli_strcmp(z,"-lookaside")==0 ){
27715 }else if( cli_strcmp(z,"-threadsafe")==0 ){
27717 }else if( cli_strcmp(z,"-nonce")==0 ){
27719 }else if( cli_strcmp(z,"-mmap")==0 ){
27721 }else if( cli_strcmp(z,"-memtrace")==0 ){
27724 }else if( cli_strcmp(z,"-sorterref")==0 ){
27727 }else if( cli_strcmp(z,"-vfs")==0 ){
27730 }else if( cli_strcmp(z,"-vfstrace")==0 ){
27734 }else if( cli_strcmp(z,"-multiplex")==0 ){
27737 }else if( cli_strcmp(z,"-help")==0 ){
27739 }else if( cli_strcmp(z,"-cmd")==0 ){
27740 /* Run commands that follow -cmd first and separately from commands
27741 ** that simply appear on the command-line. This seems goofy. It would
27744 if( i==argc-1 ) break;
27761 }else if( cli_strncmp(z, "-A", 2)==0 ){
27763 utf8_printf(stderr, "Error: cannot mix regular SQL or dot-commands"
27770 arDotCommand(&data, 1, argv+(i-1), argc-(i-1));
27772 arDotCommand(&data, 1, argv+i, argc-i);
27777 }else if( cli_strcmp(z,"-safe")==0 ){
27779 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
27783 raw_printf(stderr,"Use -help for a list of options.\n");
27798 /* Run all arguments that do not begin with '-' as if they were separate
27799 ** command-line inputs, except for the argToSkip argument which contains
27833 "SQLite version %s %.19s\n" /*extra-version-info*/
27839 printBold("transient in-memory database");
27876 session_close_all(&data, -1);
27902 (unsigned int)(sqlite3_memory_used()-mem_main_enter));
27964 ** Completely wipes out the contents of the currently-opened database
27979 ** on success, non-0 on error. This function returns 0 on success,
27980 ** SQLITE_NOTFOUND if no db is open, or propagates any other non-0
27981 ** code from the callback. Note that this is not thread-friendly: it
27996 rc = pFile->pMethods->xFileSize(pFile, &nSize);
28008 rc = pFile->pMethods->xRead(pFile, buf, nBuf, nPos);