Lines Matching +full:0 +full:x3300
57 # define SQLITE_OS_WINRT 0
141 # define S_ISLNK(mode) (0)
391 static int simBinaryStdout = 0;
392 static int simBinaryOther = 0;
411 FILE *fp = 0; in sqlite3_fopen()
417 b1 = sqlite3_malloc( (sz1+1)*sizeof(b1[0]) ); in sqlite3_fopen()
418 b2 = sqlite3_malloc( (sz2+1)*sizeof(b1[0]) ); in sqlite3_fopen()
420 sz1 = MultiByteToWideChar(CP_UTF8, 0, zFilename, sz1, b1, sz1); in sqlite3_fopen()
421 b1[sz1] = 0; in sqlite3_fopen()
422 sz2 = MultiByteToWideChar(CP_UTF8, 0, zMode, sz2, b2, sz2); in sqlite3_fopen()
423 b2[sz2] = 0; in sqlite3_fopen()
428 simBinaryOther = 0; in sqlite3_fopen()
437 FILE *fp = 0; in sqlite3_popen()
443 b1 = sqlite3_malloc( (sz1+1)*sizeof(b1[0]) ); in sqlite3_popen()
444 b2 = sqlite3_malloc( (sz2+1)*sizeof(b1[0]) ); in sqlite3_popen()
446 sz1 = MultiByteToWideChar(CP_UTF8, 0, zCommand, sz1, b1, sz1); in sqlite3_popen()
447 b1[sz1] = 0; in sqlite3_popen()
448 sz2 = MultiByteToWideChar(CP_UTF8, 0, zMode, sz2, b2, sz2); in sqlite3_popen()
449 b2[sz2] = 0; in sqlite3_popen()
468 if( b1==0 ) return 0; in sqlite3_fgets()
470 DWORD nRead = 0; in sqlite3_fgets()
472 && ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), b1, sz-1, &nRead, 0) in sqlite3_fgets()
474 b1[nRead] = 0; in sqlite3_fgets()
479 if( fgetws(b1, sz/4, in)==0 ){ in sqlite3_fgets()
481 return 0; in sqlite3_fgets()
484 WideCharToMultiByte(CP_UTF8, 0, b1, -1, buf, sz, 0, 0); in sqlite3_fgets()
501 while( sz>0 ){ in piecemealOutput()
502 for(i=0; i<sz && b1[i]>=0x80; i++){} in piecemealOutput()
503 if( i>0 ){ in piecemealOutput()
505 b1[i] = 0; in piecemealOutput()
511 b1[0] = c; in piecemealOutput()
517 fwrite(&b1[0], 1, 1, out); in piecemealOutput()
518 for(i=1; i<sz && b1[i]<0x80; i++){ in piecemealOutput()
543 if( b1==0 ) return 0; in sqlite3_fputs()
544 sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz); in sqlite3_fputs()
545 b1[sz] = 0; in sqlite3_fputs()
548 DWORD nWr = 0; in sqlite3_fputs()
550 && WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE),b1,sz,&nWr,0) in sqlite3_fputs()
568 return 0; in sqlite3_fputs()
637 static int enableTimer = 0;
641 if( a==0 ) a = ""; in cli_strcmp()
642 if( b==0 ) b = ""; in cli_strcmp()
646 if( a==0 ) a = ""; in cli_strncmp()
647 if( b==0 ) b = ""; in cli_strncmp()
653 static sqlite3_vfs *clockVfs = 0; in timeOfDay()
655 if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0); in timeOfDay()
656 if( clockVfs==0 ) return 0; /* Never actually happens */ in timeOfDay()
657 if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){ in timeOfDay()
677 #define getrusage(A,B) memset(B,0,sizeof(*B))
758 return 0; in hasTimer()
802 #define HAS_TIMER 0
813 #define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
819 static int bail_on_error = 0;
839 static sqlite3 *globalDb = 0;
844 static volatile int seenInterrupt = 0;
869 for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i]; in shell_strncpy()
870 dest[i] = 0; in shell_strncpy()
879 while( (*(dest++) = *(src++))!=0 ){} in shell_strcpy()
895 # define CONTINUE_PROMPT_PSTATE 0
901 do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)
903 if(p && stdin_is_interactive) setLexemeOpen(p, s, 0)
905 if(p && stdin_is_interactive) setLexemeOpen(p, 0, c)
917 } dynPrompt = { {0}, {0}, 0, 0 };
919 /* Record parenthesis nesting level change, or force level to 0. */
922 if( ni==0 ) p->inParenLevel = 0; in trackParenLevel()
923 p->zScannerAwaits = 0; in trackParenLevel()
926 /* Record that a lexeme is opened, or closed with args==0. */
928 if( s!=0 || c==0 ){ in setLexemeOpen()
930 p->acAwait[0] = 0; in setLexemeOpen()
932 p->acAwait[0] = c; in setLexemeOpen()
939 if( continuePrompt[0]==0 in dynamicContinuePrompt()
940 || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){ in dynamicContinuePrompt()
954 }else if( dynPrompt.inParenLevel<0 ){ in dynamicContinuePrompt()
958 dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel); in dynamicContinuePrompt()
978 if( p==0 ) shell_out_of_memory(); in shell_check_oom()
985 static FILE *iotrace = 0;
998 if( iotrace==0 ) return; in iotracePrintf()
1014 /* {1, 0x00000}, */
1015 {0, 0x00300}, {1, 0x00370}, {0, 0x00483}, {1, 0x00487}, {0, 0x00488},
1016 {1, 0x0048a}, {0, 0x00591}, {1, 0x005be}, {0, 0x005bf}, {1, 0x005c0},
1017 {0, 0x005c1}, {1, 0x005c3}, {0, 0x005c4}, {1, 0x005c6}, {0, 0x005c7},
1018 {1, 0x005c8}, {0, 0x00600}, {1, 0x00604}, {0, 0x00610}, {1, 0x00616},
1019 {0, 0x0064b}, {1, 0x0065f}, {0, 0x00670}, {1, 0x00671}, {0, 0x006d6},
1020 {1, 0x006e5}, {0, 0x006e7}, {1, 0x006e9}, {0, 0x006ea}, {1, 0x006ee},
1021 {0, 0x0070f}, {1, 0x00710}, {0, 0x00711}, {1, 0x00712}, {0, 0x00730},
1022 {1, 0x0074b}, {0, 0x007a6}, {1, 0x007b1}, {0, 0x007eb}, {1, 0x007f4},
1023 {0, 0x00901}, {1, 0x00903}, {0, 0x0093c}, {1, 0x0093d}, {0, 0x00941},
1024 {1, 0x00949}, {0, 0x0094d}, {1, 0x0094e}, {0, 0x00951}, {1, 0x00955},
1025 {0, 0x00962}, {1, 0x00964}, {0, 0x00981}, {1, 0x00982}, {0, 0x009bc},
1026 {1, 0x009bd}, {0, 0x009c1}, {1, 0x009c5}, {0, 0x009cd}, {1, 0x009ce},
1027 {0, 0x009e2}, {1, 0x009e4}, {0, 0x00a01}, {1, 0x00a03}, {0, 0x00a3c},
1028 {1, 0x00a3d}, {0, 0x00a41}, {1, 0x00a43}, {0, 0x00a47}, {1, 0x00a49},
1029 {0, 0x00a4b}, {1, 0x00a4e}, {0, 0x00a70}, {1, 0x00a72}, {0, 0x00a81},
1030 {1, 0x00a83}, {0, 0x00abc}, {1, 0x00abd}, {0, 0x00ac1}, {1, 0x00ac6},
1031 {0, 0x00ac7}, {1, 0x00ac9}, {0, 0x00acd}, {1, 0x00ace}, {0, 0x00ae2},
1032 {1, 0x00ae4}, {0, 0x00b01}, {1, 0x00b02}, {0, 0x00b3c}, {1, 0x00b3d},
1033 {0, 0x00b3f}, {1, 0x00b40}, {0, 0x00b41}, {1, 0x00b44}, {0, 0x00b4d},
1034 {1, 0x00b4e}, {0, 0x00b56}, {1, 0x00b57}, {0, 0x00b82}, {1, 0x00b83},
1035 {0, 0x00bc0}, {1, 0x00bc1}, {0, 0x00bcd}, {1, 0x00bce}, {0, 0x00c3e},
1036 {1, 0x00c41}, {0, 0x00c46}, {1, 0x00c49}, {0, 0x00c4a}, {1, 0x00c4e},
1037 {0, 0x00c55}, {1, 0x00c57}, {0, 0x00cbc}, {1, 0x00cbd}, {0, 0x00cbf},
1038 {1, 0x00cc0}, {0, 0x00cc6}, {1, 0x00cc7}, {0, 0x00ccc}, {1, 0x00cce},
1039 {0, 0x00ce2}, {1, 0x00ce4}, {0, 0x00d41}, {1, 0x00d44}, {0, 0x00d4d},
1040 {1, 0x00d4e}, {0, 0x00dca}, {1, 0x00dcb}, {0, 0x00dd2}, {1, 0x00dd5},
1041 {0, 0x00dd6}, {1, 0x00dd7}, {0, 0x00e31}, {1, 0x00e32}, {0, 0x00e34},
1042 {1, 0x00e3b}, {0, 0x00e47}, {1, 0x00e4f}, {0, 0x00eb1}, {1, 0x00eb2},
1043 {0, 0x00eb4}, {1, 0x00eba}, {0, 0x00ebb}, {1, 0x00ebd}, {0, 0x00ec8},
1044 {1, 0x00ece}, {0, 0x00f18}, {1, 0x00f1a}, {0, 0x00f35}, {1, 0x00f36},
1045 {0, 0x00f37}, {1, 0x00f38}, {0, 0x00f39}, {1, 0x00f3a}, {0, 0x00f71},
1046 {1, 0x00f7f}, {0, 0x00f80}, {1, 0x00f85}, {0, 0x00f86}, {1, 0x00f88},
1047 {0, 0x00f90}, {1, 0x00f98}, {0, 0x00f99}, {1, 0x00fbd}, {0, 0x00fc6},
1048 {1, 0x00fc7}, {0, 0x0102d}, {1, 0x01031}, {0, 0x01032}, {1, 0x01033},
1049 {0, 0x01036}, {1, 0x01038}, {0, 0x01039}, {1, 0x0103a}, {0, 0x01058},
1050 {1, 0x0105a}, {2, 0x01100}, {0, 0x01160}, {1, 0x01200}, {0, 0x0135f},
1051 {1, 0x01360}, {0, 0x01712}, {1, 0x01715}, {0, 0x01732}, {1, 0x01735},
1052 {0, 0x01752}, {1, 0x01754}, {0, 0x01772}, {1, 0x01774}, {0, 0x017b4},
1053 {1, 0x017b6}, {0, 0x017b7}, {1, 0x017be}, {0, 0x017c6}, {1, 0x017c7},
1054 {0, 0x017c9}, {1, 0x017d4}, {0, 0x017dd}, {1, 0x017de}, {0, 0x0180b},
1055 {1, 0x0180e}, {0, 0x018a9}, {1, 0x018aa}, {0, 0x01920}, {1, 0x01923},
1056 {0, 0x01927}, {1, 0x01929}, {0, 0x01932}, {1, 0x01933}, {0, 0x01939},
1057 {1, 0x0193c}, {0, 0x01a17}, {1, 0x01a19}, {0, 0x01b00}, {1, 0x01b04},
1058 {0, 0x01b34}, {1, 0x01b35}, {0, 0x01b36}, {1, 0x01b3b}, {0, 0x01b3c},
1059 {1, 0x01b3d}, {0, 0x01b42}, {1, 0x01b43}, {0, 0x01b6b}, {1, 0x01b74},
1060 {0, 0x01dc0}, {1, 0x01dcb}, {0, 0x01dfe}, {1, 0x01e00}, {0, 0x0200b},
1061 {1, 0x02010}, {0, 0x0202a}, {1, 0x0202f}, {0, 0x02060}, {1, 0x02064},
1062 {0, 0x0206a}, {1, 0x02070}, {0, 0x020d0}, {1, 0x020f0}, {2, 0x02329},
1063 {1, 0x0232b}, {2, 0x02e80}, {0, 0x0302a}, {2, 0x03030}, {1, 0x0303f},
1064 {2, 0x03040}, {0, 0x03099}, {2, 0x0309b}, {1, 0x0a4d0}, {0, 0x0a806},
1065 {1, 0x0a807}, {0, 0x0a80b}, {1, 0x0a80c}, {0, 0x0a825}, {1, 0x0a827},
1066 {2, 0x0ac00}, {1, 0x0d7a4}, {2, 0x0f900}, {1, 0x0fb00}, {0, 0x0fb1e},
1067 {1, 0x0fb1f}, {0, 0x0fe00}, {2, 0x0fe10}, {1, 0x0fe1a}, {0, 0x0fe20},
1068 {1, 0x0fe24}, {2, 0x0fe30}, {1, 0x0fe70}, {0, 0x0feff}, {2, 0x0ff00},
1069 {1, 0x0ff61}, {2, 0x0ffe0}, {1, 0x0ffe7}, {0, 0x0fff9}, {1, 0x0fffc},
1070 {0, 0x10a01}, {1, 0x10a04}, {0, 0x10a05}, {1, 0x10a07}, {0, 0x10a0c},
1071 {1, 0x10a10}, {0, 0x10a38}, {1, 0x10a3b}, {0, 0x10a3f}, {1, 0x10a40},
1072 {0, 0x1d167}, {1, 0x1d16a}, {0, 0x1d173}, {1, 0x1d183}, {0, 0x1d185},
1073 {1, 0x1d18c}, {0, 0x1d1aa}, {1, 0x1d1ae}, {0, 0x1d242}, {1, 0x1d245},
1074 {2, 0x20000}, {1, 0x2fffe}, {2, 0x30000}, {1, 0x3fffe}, {0, 0xe0001},
1075 {1, 0xe0002}, {0, 0xe0020}, {1, 0xe0080}, {0, 0xe0100}, {1, 0xe01f0}
1081 ** estimate might be 0 or 2 for zero-width and double-width characters.
1092 if( c<=0x300 ) return 1; in cli_wcwidth()
1095 iFirst = 0; in cli_wcwidth()
1096 iLast = sizeof(aUWidth)/sizeof(aUWidth[0]) - 1; in cli_wcwidth()
1114 ** begins at z[0]. Return the length. Write the Unicode value into *pU.
1119 if( (z[0] & 0xe0)==0xc0 && (z[1] & 0xc0)==0x80 ){ in decodeUtf8()
1120 *pU = ((z[0] & 0x1f)<<6) | (z[1] & 0x3f); in decodeUtf8()
1123 if( (z[0] & 0xf0)==0xe0 && (z[1] & 0xc0)==0x80 && (z[2] & 0xc0)==0x80 ){ in decodeUtf8()
1124 *pU = ((z[0] & 0x0f)<<12) | ((z[1] & 0x3f)<<6) | (z[2] & 0x3f); in decodeUtf8()
1127 if( (z[0] & 0xf8)==0xf0 && (z[1] & 0xc0)==0x80 && (z[2] & 0xc0)==0x80 in decodeUtf8()
1128 && (z[3] & 0xc0)==0x80 in decodeUtf8()
1130 *pU = ((z[0] & 0x0f)<<18) | ((z[1] & 0x3f)<<12) | ((z[2] & 0x3f))<<6 in decodeUtf8()
1131 | (z[4] & 0x3f); in decodeUtf8()
1134 *pU = 0; in decodeUtf8()
1139 #if 0 /* NOT USED */
1148 int n = 0;
1149 int i = 0;
1151 while( (c = a[i])!=0 ){
1152 if( c>=0xc0 ){
1170 ** return the number of bytes in the escape sequence. Return 0 if
1173 ** This routine assumes that z[0] is \033 (ESC).
1177 if( z[1]!='[' ) return 0; in isVt100()
1179 while( z[i]>=0x30 && z[i]<=0x3f ){ i++; } in isVt100()
1180 while( z[i]>=0x20 && z[i]<=0x2f ){ i++; } in isVt100()
1181 if( z[i]<0x40 || z[i]>0x7e ) return 0; in isVt100()
1198 int i = 0; in utf8_width_print()
1199 int n = 0; in utf8_width_print()
1201 int aw = w<0 ? -w : w; in utf8_width_print()
1202 if( zUtf==0 ) zUtf = ""; in utf8_width_print()
1203 while( (c = a[i])!=0 ){ in utf8_width_print()
1204 if( (c&0xc0)==0xc0 ){ in utf8_width_print()
1213 }else if( c==0x1b && (k = isVt100(&a[i]))>0 ){ in utf8_width_print()
1224 }else if( w<0 ){ in utf8_width_print()
1238 return 0; in isNumber()
1241 if( realnum ) *realnum = 0; in isNumber()
1245 if( !IsDigit(*z) ) return 0; in isNumber()
1252 if( !IsDigit(*z) ) return 0; in isNumber()
1256 return *z==0; in isNumber()
1266 return 0x3fffffff & (int)(z2 - z); in strlen30()
1274 int n = 0; in strlenChar()
1276 if( (0xc0&*(z++))!=0x80 ) n++; in strlenChar()
1284 ** Otherwise return 0.
1288 struct __stat64 x = {0}; in openChrSource()
1289 # define STAT_CHR_SRC(mode) ((mode & (_S_IFCHR|_S_IFIFO|_S_IFREG))!=0) in openChrSource()
1294 if( rv==0 ) return 0; in openChrSource()
1295 if( _fstat64(_fileno(rv), &x) != 0 in openChrSource()
1298 rv = 0; in openChrSource()
1302 struct stat x = {0}; in openChrSource()
1305 if( rc!=0 ) return 0; in openChrSource()
1309 return 0; in openChrSource()
1325 int nLine = zLine==0 ? 0 : 100; in local_getline()
1326 int n = 0; in local_getline()
1334 if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){ in local_getline()
1335 if( n==0 ){ in local_getline()
1337 return 0; in local_getline()
1339 zLine[n] = 0; in local_getline()
1343 if( n>0 && zLine[n-1]=='\n' ){ in local_getline()
1345 if( n>0 && zLine[n-1]=='\r' ) n--; in local_getline()
1346 zLine[n] = 0; in local_getline()
1356 ** If in==0 then read from standard input and prompt before each line.
1371 if( in!=0 ){ in one_input_line()
1380 zPrior = 0; in one_input_line()
1382 if( zResult==0 ) sqlite3_sleep(50); in one_input_line()
1383 }while( zResult==0 && seenInterrupt>0 ); in one_input_line()
1387 while( zResult==0 ){ in one_input_line()
1390 if( seenInterrupt==0 ) break; in one_input_line()
1405 if( c>='0' && c<='9' ) return c - '0'; in hexDigitValue()
1415 sqlite3_int64 v = 0; in integerValue()
1428 int isNeg = 0; in integerValue()
1429 if( zArg[0]=='-' ){ in integerValue()
1432 }else if( zArg[0]=='+' ){ in integerValue()
1435 if( zArg[0]=='0' && zArg[1]=='x' ){ in integerValue()
1438 while( (x = hexDigitValue(zArg[0]))>=0 ){ in integerValue()
1443 while( IsDigit(zArg[0]) ){ in integerValue()
1444 v = v*10 + zArg[0] - '0'; in integerValue()
1448 for(i=0; i<ArraySize(aMult); i++){ in integerValue()
1449 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){ in integerValue()
1471 memset(p, 0, sizeof(*p)); in initText()
1483 ** If the third argument, quote, is not '\0', then it is used as a
1494 for(i=0; i<nAppend; i++){ in appendText()
1499 if( p->z==0 || p->n+len>=p->nAlloc ){ in appendText()
1508 for(i=0; i<nAppend; i++){ in appendText()
1514 *zCsr = '\0'; in appendText()
1518 p->z[p->n] = '\0'; in appendText()
1528 ** Return '"' if quoting is required. Return 0 if no quoting is required.
1532 if( zName==0 ) return '"'; in quoteChar()
1533 if( !IsAlpha(zName[0]) && zName[0]!='_' ) return '"'; in quoteChar()
1534 for(i=0; zName[i]; i++){ in quoteChar()
1537 return sqlite3_keyword_check(zName, i) ? '"' : 0; in quoteChar()
1549 sqlite3_stmt *pStmt = 0; in shellFakeSchema()
1554 int nRow = 0; in shellFakeSchema()
1559 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); in shellFakeSchema()
1564 if( cQuote && sqlite3_stricmp(zSchema,"temp")==0 ) cQuote = 0; in shellFakeSchema()
1566 appendText(&s, ".", 0); in shellFakeSchema()
1573 appendText(&s, zDiv, 0); in shellFakeSchema()
1575 if( zCol==0 ) zCol = ""; in shellFakeSchema()
1579 appendText(&s, ")", 0); in shellFakeSchema()
1581 if( nRow==0 ){ in shellFakeSchema()
1583 s.z = 0; in shellFakeSchema()
1600 char *z = (char*)sqlite3_value_text(apVal[0]); in shellStrtod()
1602 if( z==0 ) return; in shellStrtod()
1603 sqlite3_result_double(pCtx, strtod(z,0)); in shellStrtod()
1618 double r = sqlite3_value_double(apVal[0]); in shellDtostr()
1659 int i = 0; in shellAddSchemaName()
1660 const char *zIn = (const char*)sqlite3_value_text(apVal[0]); in shellAddSchemaName()
1665 if( zIn!=0 && cli_strncmp(zIn, "CREATE ", 7)==0 ){ in shellAddSchemaName()
1666 for(i=0; i<ArraySize(aPrefix); i++){ in shellAddSchemaName()
1668 if( cli_strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){ in shellAddSchemaName()
1669 char *z = 0; in shellAddSchemaName()
1670 char *zFake = 0; in shellAddSchemaName()
1673 if( cQuote && sqlite3_stricmp(zSchema,"temp")!=0 ){ in shellAddSchemaName()
1680 && aPrefix[i][0]=='V' in shellAddSchemaName()
1681 && (zFake = shellFakeSchema(db, zSchema, zName))!=0 in shellAddSchemaName()
1683 if( z==0 ){ in shellAddSchemaName()
1697 sqlite3_result_value(pCtx, apVal[0]); in shellAddSchemaName()
1770 #define S_ISLNK(mode) (0)
1809 # define NULL_INTPTR_T ((intptr_t)(0))
1901 memset(value, 0, sizeof(value)); in windirent_getenv()
1903 if( dwRet==0 || dwRet>dwSize ){ in windirent_getenv()
1908 return 0; in windirent_getenv()
1926 SIZE_T namesize = sizeof(data.name) / sizeof(data.name[0]); in opendir()
1931 memset(dirp, 0, sizeof(DIR)); in opendir()
1934 if( sqlite3_stricmp(dirname, "/")==0 ){ in opendir()
1938 memset(&data, 0, sizeof(data)); in opendir()
1940 b1 = sqlite3_malloc64( (sz+3)*sizeof(b1[0]) ); in opendir()
1941 if( b1==0 ){ in opendir()
1945 sz = MultiByteToWideChar(CP_UTF8, 0, dirname, sz, b1, sz); in opendir()
1948 b1[sz] = 0; in opendir()
1954 memcpy(data.name, b1, (sz+1)*sizeof(b1[0])); in opendir()
1967 memset(&data, 0, sizeof(data)); in opendir()
1978 WideCharToMultiByte(CP_UTF8, 0, data.name, -1, in opendir()
1979 dirp->d_first.d_name, DIRENT_NAME_MAX, 0, 0); in opendir()
1993 if( dirp->d_first.d_ino==0 ){ in readdir()
2002 memset(&data, 0, sizeof(data)); in readdir()
2010 WideCharToMultiByte(CP_UTF8, 0, data.name, -1, in readdir()
2011 dirp->d_next.d_name, DIRENT_NAME_MAX, 0, 0); in readdir()
2021 INT result = 0; in closedir()
2079 if( p==0 ) return; in memtraceFree()
2086 if( p==0 ) return memtraceMalloc(n); in memtraceRealloc()
2087 if( n==0 ){ in memtraceRealloc()
2089 return 0; in memtraceRealloc()
2119 0
2125 if( memtraceBase.xMalloc==0 ){ in sqlite3MemTraceActivate()
2138 if( memtraceBase.xMalloc!=0 ){ in sqlite3MemTraceDeactivate()
2141 memset(&memtraceBase, 0, sizeof(memtraceBase)); in sqlite3MemTraceDeactivate()
2144 memtraceOut = 0; in sqlite3MemTraceDeactivate()
2289 0,
2290 0,
2307 if( pcacheBase.xFetch==0 ){ in sqlite3PcacheTraceActivate()
2320 if( pcacheBase.xFetch!=0 ){ in sqlite3PcacheTraceDeactivate()
2323 memset(&pcacheBase, 0, sizeof(pcacheBase)); in sqlite3PcacheTraceDeactivate()
2326 pcachetraceOut = 0; in sqlite3PcacheTraceDeactivate()
2414 ** WITH a(x) AS (VALUES(0x123456))
2452 ** -DSHA3_BYTEORDER=0 is set, then byte-order is determined
2464 # define SHA3_BYTEORDER 0
2493 0x0000000000000001ULL, 0x0000000000008082ULL, in KeccakF1600Step()
2494 0x800000000000808aULL, 0x8000000080008000ULL, in KeccakF1600Step()
2495 0x000000000000808bULL, 0x0000000080000001ULL, in KeccakF1600Step()
2496 0x8000000080008081ULL, 0x8000000000008009ULL, in KeccakF1600Step()
2497 0x000000000000008aULL, 0x0000000000000088ULL, in KeccakF1600Step()
2498 0x0000000080008009ULL, 0x000000008000000aULL, in KeccakF1600Step()
2499 0x000000008000808bULL, 0x800000000000008bULL, in KeccakF1600Step()
2500 0x8000000000008089ULL, 0x8000000000008003ULL, in KeccakF1600Step()
2501 0x8000000000008002ULL, 0x8000000000000080ULL, in KeccakF1600Step()
2502 0x000000000000800aULL, 0x800000008000000aULL, in KeccakF1600Step()
2503 0x8000000080008081ULL, 0x8000000000008080ULL, in KeccakF1600Step()
2504 0x0000000080000001ULL, 0x8000000080008008ULL in KeccakF1600Step()
2506 # define a00 (p->u.s[0]) in KeccakF1600Step()
2533 for(i=0; i<24; i+=4){ in KeccakF1600Step()
2810 memset(p, 0, sizeof(*p)); in SHA3Init()
2826 p->ixMask = 0; in SHA3Init()
2844 unsigned int i = 0; in SHA3Update()
2845 if( aData==0 ) return; in SHA3Update()
2847 if( (p->nLoaded % 8)==0 && ((aData - (const unsigned char*)0)&7)==0 ){ in SHA3Update()
2853 p->nLoaded = 0; in SHA3Update()
2862 p->u.x[p->nLoaded^0x07] ^= aData[i]; in SHA3Update()
2869 p->nLoaded = 0; in SHA3Update()
2882 const unsigned char c1 = 0x86; in SHA3Final()
2885 const unsigned char c2 = 0x06; in SHA3Final()
2886 const unsigned char c3 = 0x80; in SHA3Final()
2891 for(i=0; i<p->nRate; i++){ in SHA3Final()
2905 ** and the string is hashed without the trailing 0x00 terminator. The hash
2914 int eType = sqlite3_value_type(argv[0]); in sha3Func()
2915 int nByte = sqlite3_value_bytes(argv[0]); in sha3Func()
2930 SHA3Update(&cx, sqlite3_value_blob(argv[0]), nByte); in sha3Func()
2932 SHA3Update(&cx, sqlite3_value_text(argv[0]), nByte); in sha3Func()
2971 x[j] = u & 0xff; in sha3UpdateFromValue()
2974 x[0] = 'I'; in sha3UpdateFromValue()
2985 x[j] = u & 0xff; in sha3UpdateFromValue()
2988 x[0] = 'F'; in sha3UpdateFromValue()
3047 const char *zSql = (const char*)sqlite3_value_text(argv[0]); in sha3QueryFunc()
3048 sqlite3_stmt *pStmt = 0; in sha3QueryFunc()
3067 if( zSql==0 ) return; in sha3QueryFunc()
3069 while( zSql[0] ){ in sha3QueryFunc()
3097 for(i=0; i<nCol; i++){ in sha3QueryFunc()
3116 if( p==0 ) return; in sha3AggStep()
3117 if( p->nRate==0 ){ in sha3AggStep()
3127 sha3UpdateFromValue(p, argv[0]); in sha3AggStep()
3137 if( p==0 ) return; in sha3AggFinal()
3158 0, sha3Func, 0, 0); in sqlite3_shathree_init()
3162 0, sha3Func, 0, 0); in sqlite3_shathree_init()
3167 0, 0, sha3AggStep, sha3AggFinal); in sqlite3_shathree_init()
3172 0, 0, sha3AggStep, sha3AggFinal); in sqlite3_shathree_init()
3177 0, sha3QueryFunc, 0, 0); in sqlite3_shathree_init()
3182 0, sha3QueryFunc, 0, 0); in sqlite3_shathree_init()
3234 #define blk0le(i) (block[i] = (ror(block[i],8)&0xFF00FF00) \
3235 |(rol(block[i],8)&0x00FF00FF))
3247 z+=((w&(x^y))^y)+blk0le(i)+0x5A827999+rol(v,5);w=ror(w,2);
3249 z+=((w&(x^y))^y)+blk0be(i)+0x5A827999+rol(v,5);w=ror(w,2);
3251 z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=ror(w,2);
3253 z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=ror(w,2);
3255 z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=ror(w,2);
3257 z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=ror(w,2);
3269 #define a qq[0] in SHA1Transform()
3277 a = state[0]; in SHA1Transform()
3286 Rl0(a,b,c,d,e, 0); Rl0(e,a,b,c,d, 1); Rl0(d,e,a,b,c, 2); Rl0(c,d,e,a,b, 3); in SHA1Transform()
3291 Rb0(a,b,c,d,e, 0); Rb0(e,a,b,c,d, 1); Rb0(d,e,a,b,c, 2); Rb0(c,d,e,a,b, 3); in SHA1Transform()
3314 state[0] += a; in SHA1Transform()
3331 p->state[0] = 0x67452301; in hash_init()
3332 p->state[1] = 0xEFCDAB89; in hash_init()
3333 p->state[2] = 0x98BADCFE; in hash_init()
3334 p->state[3] = 0x10325476; in hash_init()
3335 p->state[4] = 0xC3D2E1F0; in hash_init()
3336 p->count[0] = p->count[1] = 0; in hash_init()
3347 j = p->count[0]; in hash_step()
3348 if( (p->count[0] += len << 3) < j ){ in hash_step()
3358 j = 0; in hash_step()
3360 i = 0; in hash_step()
3388 int bAsBinary /* 1 for binary hash, 0 for hex hash */ in hash_finish()
3395 for (i = 0; i < 8; i++){ in hash_finish()
3396 finalcount[i] = (unsigned char)((p->count[(i >= 4 ? 0 : 1)] in hash_finish()
3400 while ((p->count[0] & 504) != 448){ in hash_finish()
3401 hash_step(p, (const unsigned char *)"\0", 1); in hash_finish()
3404 for (i = 0; i < 20; i++){ in hash_finish()
3410 for(i=0; i<20; i++){ in hash_finish()
3411 zOut[i*2] = zEncode[(digest[i]>>4)&0xf]; in hash_finish()
3412 zOut[i*2+1] = zEncode[digest[i] & 0xf]; in hash_finish()
3414 zOut[i*2]= 0; in hash_finish()
3426 ** is hash without the trailing 0x00 terminator. The hash of a NULL
3435 int eType = sqlite3_value_type(argv[0]); in sha1Func()
3436 int nByte = sqlite3_value_bytes(argv[0]); in sha1Func()
3443 hash_step(&cx, sqlite3_value_blob(argv[0]), nByte); in sha1Func()
3445 hash_step(&cx, sqlite3_value_text(argv[0]), nByte); in sha1Func()
3447 if( sqlite3_user_data(context)!=0 ){ in sha1Func()
3451 hash_finish(&cx, zOut, 0); in sha1Func()
3474 const char *zSql = (const char*)sqlite3_value_text(argv[0]); in sha1QueryFunc()
3475 sqlite3_stmt *pStmt = 0; in sha1QueryFunc()
3485 if( zSql==0 ) return; in sha1QueryFunc()
3487 while( zSql[0] ){ in sha1QueryFunc()
3513 for(i=0; i<nCol; i++){ in sha1QueryFunc()
3526 x[j] = u & 0xff; in sha1QueryFunc()
3529 x[0] = 'I'; in sha1QueryFunc()
3540 x[j] = u & 0xff; in sha1QueryFunc()
3543 x[0] = 'F'; in sha1QueryFunc()
3566 hash_finish(&cx, zOut, 0); in sha1QueryFunc()
3585 0, sha1Func, 0, 0); in sqlite3_sha_init()
3589 (void*)&one, sha1Func, 0, 0); in sqlite3_sha_init()
3593 SQLITE_UTF8|SQLITE_DIRECTONLY, 0, in sqlite3_sha_init()
3594 sha1QueryFunc, 0, 0); in sqlite3_sha_init()
3647 int i=0, j=0, x; in uintCollFunc()
3654 while( i<nKey1 && zA[i]=='0' ){ i++; } in uintCollFunc()
3655 while( j<nKey2 && zB[j]=='0' ){ j++; } in uintCollFunc()
3656 k = 0; in uintCollFunc()
3691 return sqlite3_create_collation(db, "uint", SQLITE_UTF8, 0, uintCollFunc); in sqlite3_uint_init()
3732 char sign; /* 0 for positive, 1 for negative */
3763 Decimal *p = 0; in decimalNewFromText()
3765 int iExp = 0; in decimalNewFromText()
3768 if( p==0 ) goto new_from_text_failed; in decimalNewFromText()
3769 p->sign = 0; in decimalNewFromText()
3770 p->oom = 0; in decimalNewFromText()
3772 p->isNull = 0; in decimalNewFromText()
3773 p->nDigit = 0; in decimalNewFromText()
3774 p->nFrac = 0; in decimalNewFromText()
3776 if( p->a==0 ) goto new_from_text_failed; in decimalNewFromText()
3777 for(i=0; IsSpace(zIn[i]); i++){} in decimalNewFromText()
3784 while( i<n && zIn[i]=='0' ) i++; in decimalNewFromText()
3787 if( c>='0' && c<='9' ){ in decimalNewFromText()
3788 p->a[p->nDigit++] = c - '0'; in decimalNewFromText()
3793 int neg = 0; in decimalNewFromText()
3802 if( zIn[j]>='0' && zIn[j]<='9' ){ in decimalNewFromText()
3803 iExp = iExp*10 + zIn[j] - '0'; in decimalNewFromText()
3815 if( iExp>0 ){ in decimalNewFromText()
3816 if( p->nFrac>0 ){ in decimalNewFromText()
3819 iExp = 0; in decimalNewFromText()
3822 p->nFrac = 0; in decimalNewFromText()
3825 if( iExp>0 ){ in decimalNewFromText()
3827 if( p->a==0 ) goto new_from_text_failed; in decimalNewFromText()
3828 memset(p->a+p->nDigit, 0, iExp); in decimalNewFromText()
3831 }else if( iExp<0 ){ in decimalNewFromText()
3838 iExp = 0; in decimalNewFromText()
3844 if( iExp>0 ){ in decimalNewFromText()
3846 if( p->a==0 ) goto new_from_text_failed; in decimalNewFromText()
3848 memset(p->a, 0, iExp); in decimalNewFromText()
3860 return 0; in decimalNewFromText()
3882 Decimal *p = 0; in decimal_new()
3893 if( p==0 ) goto new_failed; in decimal_new()
3905 sqlite3_uint64 v = 0; in decimal_new()
3910 for(i=0; i<sizeof(r); i++){ in decimal_new()
3927 return 0; in decimal_new()
3937 if( p==0 || p->oom ){ in decimal_result()
3946 if( z==0 ){ in decimal_result()
3950 i = 0; in decimal_result()
3951 if( p->nDigit==0 || (p->nDigit==1 && p->a[0]==0) ){ in decimal_result()
3952 p->sign = 0; in decimal_result()
3955 z[0] = '-'; in decimal_result()
3959 if( n<=0 ){ in decimal_result()
3960 z[i++] = '0'; in decimal_result()
3962 j = 0; in decimal_result()
3963 while( n>1 && p->a[j]==0 ){ in decimal_result()
3967 while( n>0 ){ in decimal_result()
3968 z[i++] = p->a[j] + '0'; in decimal_result()
3975 z[i++] = p->a[j] + '0'; in decimal_result()
3979 z[i] = 0; in decimal_result()
3998 if( p==0 || p->oom ){ in decimal_result_sci()
4006 for(nDigit=p->nDigit; nDigit>0 && p->a[nDigit-1]==0; nDigit--){} in decimal_result_sci()
4007 for(nZero=0; nZero<nDigit && p->a[nZero]==0; nZero++){} in decimal_result_sci()
4011 if( z==0 ){ in decimal_result_sci()
4015 if( nDigit==0 ){ in decimal_result_sci()
4016 zero = 0; in decimal_result_sci()
4019 nFrac = 0; in decimal_result_sci()
4023 if( p->sign && nDigit>0 ){ in decimal_result_sci()
4024 z[0] = '-'; in decimal_result_sci()
4026 z[0] = '+'; in decimal_result_sci()
4028 z[1] = a[0]+'0'; in decimal_result_sci()
4031 z[3] = '0'; in decimal_result_sci()
4035 z[2+i] = a[i]+'0'; in decimal_result_sci()
4045 ** Compare to Decimal objects. Return negative, 0, or positive if the
4050 ** pA!=0
4051 ** pA->isNull==0
4052 ** pB!=0
4053 ** pB->isNull==0
4073 if( rc==0 ){ in decimal_cmp()
4090 Decimal *pA = 0, *pB = 0; in decimalCmpFunc()
4094 pA = decimal_new(context, argv[0], 1); in decimalCmpFunc()
4095 if( pA==0 || pA->isNull ) goto cmp_done; in decimalCmpFunc()
4097 if( pB==0 || pB->isNull ) goto cmp_done; in decimalCmpFunc()
4099 if( rc<0 ) rc = -1; in decimalCmpFunc()
4100 else if( rc>0 ) rc = +1; in decimalCmpFunc()
4114 if( p==0 ) return; in decimal_expand()
4117 if( nAddFrac==0 && nAddSig==0 ) return; in decimal_expand()
4119 if( p->a==0 ){ in decimal_expand()
4125 memset(p->a, 0, nAddSig); in decimal_expand()
4129 memset(p->a+p->nDigit, 0, nAddFrac); in decimal_expand()
4143 if( pA==0 ){ in decimal_add()
4146 if( pA->oom || pB==0 || pB->oom ){ in decimal_add()
4155 if( nSig && pA->a[0]==0 ) nSig--; in decimal_add()
4168 int carry = 0; in decimal_add()
4169 for(i=nDigit-1; i>=0; i--){ in decimal_add()
4175 carry = 0; in decimal_add()
4181 int borrow = 0; in decimal_add()
4183 if( rc<0 ){ in decimal_add()
4191 for(i=nDigit-1; i>=0; i--){ in decimal_add()
4193 if( x<0 ){ in decimal_add()
4198 borrow = 0; in decimal_add()
4214 signed char *acc = 0; in decimalMul()
4218 if( pA==0 || pA->oom || pA->isNull in decimalMul()
4219 || pB==0 || pB->oom || pB->isNull in decimalMul()
4224 if( acc==0 ){ in decimalMul()
4228 memset(acc, 0, pA->nDigit + pB->nDigit + 2); in decimalMul()
4231 for(i=pA->nDigit-1; i>=0; i--){ in decimalMul()
4233 int carry = 0, x; in decimalMul()
4234 for(j=pB->nDigit-1, k=i+j+3; j>=0; j--, k--){ in decimalMul()
4245 acc = 0; in decimalMul()
4249 while( pA->nFrac>minFrac && pA->a[pA->nDigit-1]==0 ){ in decimalMul()
4262 Decimal *pA = 0; /* The result to be returned */ in decimalPow2()
4263 Decimal *pX = 0; /* Multiplier */ in decimalPow2()
4266 if( pA==0 || pA->oom ) goto pow2_fault; in decimalPow2()
4267 if( N==0 ) return pA; in decimalPow2()
4268 if( N>0 ){ in decimalPow2()
4274 if( pX==0 || pX->oom ) goto pow2_fault; in decimalPow2()
4281 if( N==0 ) break; in decimalPow2()
4290 return 0; in decimalPow2()
4307 isNeg = 0; in decimalFromDouble()
4310 if( a==0 ){ in decimalFromDouble()
4311 e = 0; in decimalFromDouble()
4312 m = 0; in decimalFromDouble()
4316 if( e==0 ){ in decimalFromDouble()
4321 while( e<1075 && m>0 && (m&1)==0 ){ in decimalFromDouble()
4328 return 0; /* A NaN or an Infinity */ in decimalFromDouble()
4359 Decimal *p = decimal_new(context, argv[0], 0); in decimalFunc()
4362 if( sqlite3_user_data(context)!=0 ){ in decimalFunc()
4385 if( pA==0 || pB==0 ){ in decimalCollFunc()
4386 rc = 0; in decimalCollFunc()
4407 Decimal *pA = decimal_new(context, argv[0], 1); in decimalAddFunc()
4420 Decimal *pA = decimal_new(context, argv[0], 1); in decimalSubFunc()
4446 if( p==0 ) return; in decimalSumStep()
4450 if( p->a==0 ){ in decimalSumStep()
4453 p->a[0] = 0; in decimalSumStep()
4456 p->nFrac = 0; in decimalSumStep()
4458 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; in decimalSumStep()
4459 pArg = decimal_new(context, argv[0], 1); in decimalSumStep()
4472 if( p==0 ) return; in decimalSumInverse()
4473 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; in decimalSumInverse()
4474 pArg = decimal_new(context, argv[0], 1); in decimalSumInverse()
4480 Decimal *p = sqlite3_aggregate_context(context, 0); in decimalSumValue()
4481 if( p==0 ) return; in decimalSumValue()
4485 Decimal *p = sqlite3_aggregate_context(context, 0); in decimalSumFinalize()
4486 if( p==0 ) return; in decimalSumFinalize()
4501 Decimal *pA = decimal_new(context, argv[0], 1); in decimalMulFunc()
4504 if( pA==0 || pA->oom || pA->isNull in decimalMulFunc()
4505 || pB==0 || pB->oom || pB->isNull in decimalMulFunc()
4531 if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){ in decimalPow2Func()
4532 Decimal *pA = decimalPow2(sqlite3_value_int(argv[0])); in decimalPow2Func()
4553 { "decimal", 1, 0, decimalFunc }, in sqlite3_decimal_init()
4555 { "decimal_cmp", 2, 0, decimalCmpFunc }, in sqlite3_decimal_init()
4556 { "decimal_add", 2, 0, decimalAddFunc }, in sqlite3_decimal_init()
4557 { "decimal_sub", 2, 0, decimalSubFunc }, in sqlite3_decimal_init()
4558 { "decimal_mul", 2, 0, decimalMulFunc }, in sqlite3_decimal_init()
4559 { "decimal_pow2", 1, 0, decimalPow2Func }, in sqlite3_decimal_init()
4566 for(i=0; i<(int)(sizeof(aFunc)/sizeof(aFunc[0])) && rc==SQLITE_OK; i++){ in sqlite3_decimal_init()
4569 aFunc[i].iArg ? db : 0, aFunc[i].xFunc, 0, 0); in sqlite3_decimal_init()
4573 SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC, 0, in sqlite3_decimal_init()
4575 decimalSumValue, decimalSumInverse, 0); in sqlite3_decimal_init()
4579 0, decimalCollFunc); in sqlite3_decimal_init()
4634 ** drawn from 0 to N-1 such that the height of the graph at J is
4650 ** the second argument is in the range of 0 to 1 instead of 0 to 100.
4678 ** the fraction parameter to percentile() goes from 0 to 100 whereas
4680 ** 0 to 1.
4737 { "median", 1, 1, 0 },
4738 { "percentile", 2, 100, 0 },
4739 { "percentile_cont", 2, 1, 0 },
4750 return ((u>>52)&0x7ff)==0x7ff; in percentIsInfinity()
4769 ** order. The smallest return value in this case will be 0, and
4773 int iFirst = 0; /* First element of search range */ in percentBinarySearch()
4806 zMsg2 = zMsg1 ? sqlite3_mprintf(zMsg1, pFunc->zName) : 0; in percentError()
4827 /* Requirement 3: P must be a number between 0 and 100 */ in percentStep()
4843 if( p==0 ) return; in percentStep()
4857 eType = sqlite3_value_type(argv[0]); in percentStep()
4868 y = sqlite3_value_double(argv[0]); in percentStep()
4878 if( a==0 ){ in percentStep()
4880 memset(p, 0, sizeof(*p)); in percentStep()
4887 if( p->nUsed==0 ){ in percentStep()
4894 i = percentBinarySearch(p, y, 0); in percentStep()
4896 memmove(&p->a[i+1], &p->a[i], (p->nUsed-i)*sizeof(p->a[0])); in percentStep()
4902 p->bSorted = 0; in percentStep()
4930 if( a[0]>a[n-1] ){ in percentSort()
4931 SWAP_DOUBLE(a[0],a[n-1]) in percentSort()
4936 if( a[0]>a[i] ){ in percentSort()
4937 SWAP_DOUBLE(a[0],a[i]) in percentSort()
4962 #if 0 in percentSort()
4963 for(i=0; i<n-1; i++){ in percentSort()
4983 assert( p!=0 ); in percentInverse()
4986 eType = sqlite3_value_type(argv[0]); in percentInverse()
4996 y = sqlite3_value_double(argv[0]); in percentInverse()
5000 if( p->bSorted==0 ){ in percentInverse()
5009 if( i>=0 ){ in percentInverse()
5012 memmove(&p->a[i], &p->a[i+1], (p->nUsed - i)*sizeof(p->a[0])); in percentInverse()
5027 p = (Percentile*)sqlite3_aggregate_context(pCtx, 0); in percentCompute()
5028 if( p==0 ) return; in percentCompute()
5029 if( p->a==0 ) return; in percentCompute()
5031 if( p->bSorted==0 ){ in percentCompute()
5050 memset(p, 0, sizeof(*p)); in percentCompute()
5059 percentCompute(pCtx, 0); in percentValue()
5078 for(i=0; i<sizeof(aPercentFunc)/sizeof(aPercentFunc[0]); i++){ in sqlite3_percentile_init()
5084 percentStep, percentFinal, percentValue, percentInverse, 0); in sqlite3_percentile_init()
5162 #define PC 0x80 /* pad character */
5163 #define WS 0x81 /* whitespace */
5164 #define ND 0x82 /* Not above or digit-value */
5180 /* 0 1 5 9 = */
5183 ND, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
5196 ((((u8)(c))<0x80)? (u8)(b64DigitValues[(u8)(c)]) : 0x80)
5197 #define IS_BX_DIGIT(bdp) (((u8)(bdp))<0x80)
5208 int nCol = 0; in toBase64()
5211 pOut[0] = BX_NUMERAL(pIn[0]>>2); in toBase64()
5212 pOut[1] = BX_NUMERAL(((pIn[0]<<4)|(pIn[1]>>4))&0x3f); in toBase64()
5213 pOut[2] = BX_NUMERAL(((pIn[1]&0xf)<<2)|(pIn[2]>>6)); in toBase64()
5214 pOut[3] = BX_NUMERAL(pIn[2]&0x3f); in toBase64()
5218 if( (nCol += 4)>=B64_DARK_MAX || nbIn<=0 ){ in toBase64()
5220 nCol = 0; in toBase64()
5223 if( nbIn > 0 ){ in toBase64()
5231 for( nbe=3; nbe>=0; --nbe ){ in toBase64()
5232 char ce = (nbe<nco)? BX_NUMERAL((u8)(qv & 0x3f)) : PAD_CHAR; in toBase64()
5239 *pOut = 0; in toBase64()
5246 while( nc-- > 0 && (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s; in skipNonB64()
5252 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn; in fromBase64()
5253 while( ncIn>0 && *pIn!=PAD_CHAR ){ in fromBase64()
5254 static signed char nboi[] = { 0, 0, 1, 2, 3 }; in fromBase64()
5256 unsigned long qv = 0L; in fromBase64()
5263 if( nbo==0 ) break; in fromBase64()
5264 for( nac=0; nac<4; ++nac ){ in fromBase64()
5265 char c = (nac<nti)? *pIn++ : b64Numerals[0]; in fromBase64()
5270 ncIn = 0; in fromBase64()
5277 bdp = 0; in fromBase64()
5287 pOut[2] = (qv) & 0xff; in fromBase64()
5290 pOut[1] = (qv>>8) & 0xff; in fromBase64()
5293 pOut[0] = (qv>>16) & 0xff; in fromBase64()
5303 int nb, nc, nv = sqlite3_value_bytes(av[0]); in base64()
5309 switch( sqlite3_value_type(av[0]) ){ in base64()
5313 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */ in base64()
5318 bBuf = (u8*)sqlite3_value_blob(av[0]); in base64()
5340 cBuf = (char *)sqlite3_value_text(av[0]); in base64()
5345 sqlite3_result_zeroblob(context, 0); in base64()
5379 0, base64, 0, 0); in sqlite3_base_init()
5387 #define BASE64_INIT(db) sqlite3_base64_init(db, 0, 0)
5423 ** in code order representing digit values 0 to 84 (base 10.)
5431 ** Groups of 0 bytes are represented with 0 digits and vice-versa.
5456 ** nothing other than base85 numerals and whitespace, or 0 otherwise.
5514 * Values of 1 and 3 are base85 numerals. Values of 0, 2, or 4 are not.
5519 static u8 b85_cOffset[] = { 0, '#', 0, '*'-4, 0 };
5525 #if 0 /* Not used, */
5528 if( dv>87 ) return 0xff;
5539 while( nc-- > 0 && (c = *s) && !IS_B85(c) ) ++s; in skipNonB85()
5543 /* Convert small integer, known to be in 0..84 inclusive, to base85 numeral.
5545 #if 0
5556 while( (c = *s++)!=0 ) *pc++ = c; in putcs()
5560 /* Encode a byte buffer into base85 text. If pSep!=0, it's a C string
5565 int nCol = 0; in toBase85()
5568 unsigned long qbv = (((unsigned long)pIn[0])<<24) | in toBase85()
5570 while( nco > 0 ){ in toBase85()
5581 nCol = 0; in toBase85()
5584 if( nbIn > 0 ){ in toBase85()
5592 while( nco > 0 ){ in toBase85()
5599 if( pSep && nCol>0 ) pOut = putcs(pOut, pSep); in toBase85()
5600 *pOut = 0; in toBase85()
5606 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn; in fromBase85()
5607 while( ncIn>0 ){ in fromBase85()
5608 static signed char nboi[] = { 0, 0, 1, 2, 3, 4 }; in fromBase85()
5610 unsigned long qv = 0L; in fromBase85()
5616 if( nbo==0 ) break; in fromBase85()
5617 while( nti>0 ){ in fromBase85()
5621 if( cdo==0 ) break; in fromBase85()
5628 *pOut++ = (qv >> 24)&0xff; in fromBase85()
5631 *pOut++ = (qv >> 16)&0xff; in fromBase85()
5634 *pOut++ = (qv >> 8)&0xff; in fromBase85()
5637 *pOut++ = qv&0xff; in fromBase85()
5639 case 0: in fromBase85()
5650 while( len-- > 0 && (c = *p++) != 0 ){ in allBase85()
5651 if( !IS_B85(c) && !isspace(c) ) return 0; in allBase85()
5663 switch( sqlite3_value_type(av[0]) ){ in is_base85()
5666 int rv = allBase85( (char *)sqlite3_value_text(av[0]), in is_base85()
5667 sqlite3_value_bytes(av[0]) ); in is_base85()
5683 int nb, nc, nv = sqlite3_value_bytes(av[0]); in base85()
5689 switch( sqlite3_value_type(av[0]) ){ in base85()
5698 bBuf = (u8*)sqlite3_value_blob(av[0]); in base85()
5720 cBuf = (char *)sqlite3_value_text(av[0]); in base85()
5725 sqlite3_result_zeroblob(context, 0); in base85()
5761 0, is_base85, 0, 0); in sqlite3_base_init()
5768 0, base85, 0, 0); in sqlite3_base_init()
5776 # define BASE85_INIT(db) sqlite3_base85_init(db, 0, 0)
5783 int rc = 0; in main()
5791 FILE *fb = 0, *foc = 0; in main()
5793 if( na < 3 || av[1][0]!='-' || (rw = av[1][1])==0 || (rw!='r' && rw!='w') ){ in main()
5795 return 0; in main()
5797 fmode[0] = rw; in main()
5798 if( av[2][0]=='-' && av[2][1]==0 ){ in main()
5819 while( (nio = fread( bBuf, 1, sizeof(bBuf), fb))>0 ){ in main()
5820 toBase85( bBuf, (int)nio, cBuf, 0 ); in main()
5825 while( 0 != fgets(cBuf, sizeof(cBuf), stdin) ){ in main()
5880 ** ieee754(2.0) -> 'ieee754(2,0)'
5882 ** ieee754(2, 0) -> 2.0
5909 ** VALUES(0,'1')
5965 if( sqlite3_value_type(argv[0])==SQLITE_BLOB in ieee754func()
5966 && sqlite3_value_bytes(argv[0])==sizeof(r) in ieee754func()
5968 const unsigned char *x = sqlite3_value_blob(argv[0]); in ieee754func()
5970 sqlite3_uint64 v = 0; in ieee754func()
5971 for(i=0; i<sizeof(r); i++){ in ieee754func()
5976 r = sqlite3_value_double(argv[0]); in ieee754func()
5982 isNeg = 0; in ieee754func()
5985 if( a==0 ){ in ieee754func()
5986 e = 0; in ieee754func()
5987 m = 0; in ieee754func()
5991 if( e==0 ){ in ieee754func()
5996 while( e<1075 && m>0 && (m&1)==0 ){ in ieee754func()
6003 case 0: in ieee754func()
6018 int isNeg = 0; in ieee754func()
6019 m = sqlite3_value_int64(argv[0]); in ieee754func()
6029 if( m<0 ){ in ieee754func()
6032 if( m<0 ) return; in ieee754func()
6033 }else if( m==0 && e>-1000 && e<1000 ){ in ieee754func()
6037 while( (m>>32)&0xffe00000 ){ in ieee754func()
6041 while( m!=0 && ((m>>32)&0xfff00000)==0 ){ in ieee754func()
6046 if( e<=0 ){ in ieee754func()
6049 m = 0; in ieee754func()
6053 e = 0; in ieee754func()
6054 }else if( e>0x7ff ){ in ieee754func()
6055 e = 0x7ff; in ieee754func()
6074 if( sqlite3_value_type(argv[0])==SQLITE_BLOB in ieee754func_from_blob()
6075 && sqlite3_value_bytes(argv[0])==sizeof(double) in ieee754func_from_blob()
6078 const unsigned char *x = sqlite3_value_blob(argv[0]); in ieee754func_from_blob()
6080 sqlite3_uint64 v = 0; in ieee754func_from_blob()
6081 for(i=0; i<sizeof(r); i++){ in ieee754func_from_blob()
6094 if( sqlite3_value_type(argv[0])==SQLITE_FLOAT in ieee754func_to_blob()
6095 || sqlite3_value_type(argv[0])==SQLITE_INTEGER in ieee754func_to_blob()
6097 double r = sqlite3_value_double(argv[0]); in ieee754func_to_blob()
6103 a[sizeof(r)-i] = v&0xff; in ieee754func_to_blob()
6133 r = sqlite3_value_double(argv[0]); in ieee754inc()
6156 { "ieee754", 1, 0, ieee754func }, in sqlite3_ieee_init()
6157 { "ieee754", 2, 0, ieee754func }, in sqlite3_ieee_init()
6160 { "ieee754_to_blob", 1, 0, ieee754func_to_blob }, in sqlite3_ieee_init()
6161 { "ieee754_from_blob", 1, 0, ieee754func_from_blob }, in sqlite3_ieee_init()
6162 { "ieee754_inc", 2, 0, ieee754inc }, in sqlite3_ieee_init()
6168 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){ in sqlite3_ieee_init()
6172 aFunc[i].xFunc, 0, 0); in sqlite3_ieee_init()
6197 ** value V[n] sequence is produced for integer n ascending from 0 where
6198 ** ( V[n] == start + n * step && sgn(V[n] - stop) * sgn(step) >= 0 )
6203 ** The stop parameter defaults to (1<<32)-1 (aka 4294967295 or 0xffffffff)
6204 ** The step parameter defaults to 1 and 0 is treated as 1.
6208 ** SELECT * FROM generate_series(0,100,5);
6210 ** The query above returns integers from 0 through 100 counting by steps
6213 ** SELECT * FROM generate_series(0,100);
6215 ** Integers from 0 through 100 with a step size of 1.
6221 ** SELECT * FROM generate_series(0,-100,-5);
6223 ** Integers 0 -5 -10 ... -100.
6225 ** SELECT * FROM generate_series(0,-1);
6247 ** SELECT * FROM generate_series(0,100,5);
6248 ** SELECT * FROM generate_series WHERE start=0 AND stop=100 AND step=5;
6250 ** SELECT * FROM generate_series(0,100);
6251 ** SELECT * FROM generate_series WHERE start=0 AND stop=100;
6265 ** are missing, it uses 0 for start, 4294967295 for stop, and 1 for step.
6300 ** Return that member of a generate_series(...) sequence whose 0-based
6301 ** index is ix. The 0th member is given by smBase. The sequence members
6310 ((sqlite3_uint64)0x7fffffff)<<32 | 0xffffffff; in genSeqMember()
6351 pss->uSeqIndexMax = 0; in setupSequence()
6352 pss->isNotEOF = 0; in setupSequence()
6353 bSameSigns = (pss->iBase < 0)==(pss->iTerm < 0); in setupSequence()
6355 sqlite3_uint64 nuspan = 0; in setupSequence()
6360 * In this clause, iBase>=0 and iTerm<0 . */ in setupSequence()
6365 if( pss->iStep<0 ){ in setupSequence()
6374 sqlite3_uint64 puspan = 0; in setupSequence()
6379 * In this clause, iTerm>=0 and iBase<0 . */ in setupSequence()
6384 if( pss->iStep>0 ){ in setupSequence()
6390 pss->uSeqIndexMax = 0; in setupSequence()
6392 pss->uSeqIndexNow = (pss->isReversing)? pss->uSeqIndexMax : 0; in setupSequence()
6401 ** Return whether there is a next value, or 0 at EOF.
6404 if( !pss->isNotEOF ) return 0; in progressSequence()
6406 if( pss->uSeqIndexNow > 0 ){ in progressSequence()
6410 pss->isNotEOF = 0; in progressSequence()
6417 pss->isNotEOF = 0; in progressSequence()
6458 #define SERIES_COLUMN_VALUE 0 in seriesConnect()
6471 if( pNew==0 ) return SQLITE_NOMEM; in seriesConnect()
6472 memset(pNew, 0, sizeof(*pNew)); in seriesConnect()
6493 if( pCur==0 ) return SQLITE_NOMEM; in seriesOpen()
6494 memset(pCur, 0, sizeof(*pCur)); in seriesOpen()
6527 sqlite3_int64 x = 0; in seriesColumn()
6539 #define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
6540 #define LARGEST_UINT64 (0xffffffff|(((sqlite3_uint64)0xffffffff)<<32))
6567 # define SQLITE_SERIES_CONSTRAINT_VERIFY 0
6580 ** 0x0001: start=VALUE
6581 ** 0x0002: stop=VALUE
6582 ** 0x0004: step=VALUE
6583 ** 0x0008: descending order
6584 ** 0x0010: ascending order
6585 ** 0x0020: LIMIT VALUE
6586 ** 0x0040: OFFSET VALUE
6587 ** 0x0080: value=VALUE
6588 ** 0x0100: value>=VALUE
6589 ** 0x0200: value>VALUE
6590 ** 0x1000: value<=VALUE
6591 ** 0x2000: value<VALUE
6603 int i = 0; in seriesFilter()
6604 int returnNoRows = 0; in seriesFilter()
6607 sqlite3_int64 iLimit = 0; in seriesFilter()
6608 sqlite3_int64 iOffset = 0; in seriesFilter()
6611 if( idxNum & 0x01 ){ in seriesFilter()
6614 pCur->ss.iBase = 0; in seriesFilter()
6616 if( idxNum & 0x02 ){ in seriesFilter()
6619 pCur->ss.iTerm = 0xffffffff; in seriesFilter()
6621 if( idxNum & 0x04 ){ in seriesFilter()
6623 if( pCur->ss.iStep==0 ){ in seriesFilter()
6625 }else if( pCur->ss.iStep<0 ){ in seriesFilter()
6626 if( (idxNum & 0x10)==0 ) idxNum |= 0x08; in seriesFilter()
6638 if( (idxNum & 0x05)==0 && (idxNum & 0x0380)!=0 ){ in seriesFilter()
6641 if( (idxNum & 0x06)==0 && (idxNum & 0x3080)!=0 ){ in seriesFilter()
6650 if( idxNum & 0x20 ){ in seriesFilter()
6652 if( idxNum & 0x40 ){ in seriesFilter()
6657 if( idxNum & 0x3380 ){ in seriesFilter()
6661 if( idxNum & 0x0080 ){ in seriesFilter()
6673 if( idxNum & 0x0300 ){ in seriesFilter()
6676 if( idxNum & 0x0200 && r==ceil(r) ){ in seriesFilter()
6683 if( idxNum & 0x0200 ){ in seriesFilter()
6692 if( idxNum & 0x3000 ){ in seriesFilter()
6695 if( (idxNum & 0x2000)!=0 && r==floor(r) ){ in seriesFilter()
6702 if( idxNum & 0x2000 ){ in seriesFilter()
6719 if( pCur->ss.iStep>0 ){ in seriesFilter()
6730 assert( szStep>0 ); in seriesFilter()
6742 if( idxNum & 0x20 ){ in seriesFilter()
6743 if( iOffset>0 ){ in seriesFilter()
6746 if( iLimit>=0 ){ in seriesFilter()
6749 if( pCur->ss.iStep<0 ){ in seriesFilter()
6758 for(i=0; i<argc; i++){ in seriesFilter()
6768 pCur->ss.iTerm = 0; in seriesFilter()
6771 if( idxNum & 0x08 ){ in seriesFilter()
6772 pCur->ss.isReversing = pCur->ss.iStep > 0; in seriesFilter()
6774 pCur->ss.isReversing = pCur->ss.iStep < 0; in seriesFilter()
6791 ** 0x0001 start = $num
6792 ** 0x0002 stop = $num
6793 ** 0x0004 step = $num
6794 ** 0x0008 output is in descending order
6795 ** 0x0010 output is in ascending order
6796 ** 0x0020 LIMIT $num
6797 ** 0x0040 OFFSET $num
6798 ** 0x0080 value = $num
6799 ** 0x0100 value >= $num
6800 ** 0x0200 value > $num
6801 ** 0x1000 value <= $num
6802 ** 0x2000 value < $num
6804 ** Only one of 0x0100 or 0x0200 will be returned. Similarly, only
6805 ** one of 0x1000 or 0x2000 will be returned. If the 0x0080 is set, then
6806 ** none of the 0xff00 bits will be set.
6810 ** * The argument to start= if bit 0x0001 is in the idxNum mask
6811 ** * The argument to stop= if bit 0x0002 is in the idxNum mask
6812 ** * The argument to step= if bit 0x0004 is in the idxNum mask
6813 ** * The argument to LIMIT if bit 0x0020 is in the idxNum mask
6814 ** * The argument to OFFSET if bit 0x0040 is in the idxNum mask
6816 ** bits 0x0380 are in the idxNum mask
6817 ** * The argument to value<= or value< if either of bits 0x3000
6826 int idxNum = 0; /* The query plan bitmask */ in seriesBestIndex()
6828 int bStartSeen = 0; /* EQ constraint seen on the START column */ in seriesBestIndex()
6830 int unusableMask = 0; /* Mask of unusable constraints */ in seriesBestIndex()
6831 int nArg = 0; /* Number of arguments that seriesFilter() expects */ in seriesBestIndex()
6842 aIdx[0] = aIdx[1] = aIdx[2] = aIdx[3] = aIdx[4] = aIdx[5] = aIdx[6] = -1; in seriesBestIndex()
6844 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){ in seriesBestIndex()
6845 int iCol; /* 0 for start, 1 for stop, 2 for step */ in seriesBestIndex()
6851 if( pConstraint->usable==0 ){ in seriesBestIndex()
6855 idxNum |= 0x20; in seriesBestIndex()
6859 idxNum |= 0x40; in seriesBestIndex()
6871 idxNum |= 0x0080; in seriesBestIndex()
6872 idxNum &= ~0x3300; in seriesBestIndex()
6881 if( idxNum & 0x0080 ) break; in seriesBestIndex()
6882 idxNum |= 0x0100; in seriesBestIndex()
6883 idxNum &= ~0x0200; in seriesBestIndex()
6891 if( idxNum & 0x0080 ) break; in seriesBestIndex()
6892 idxNum |= 0x0200; in seriesBestIndex()
6893 idxNum &= ~0x0100; in seriesBestIndex()
6901 if( idxNum & 0x0080 ) break; in seriesBestIndex()
6902 idxNum |= 0x1000; in seriesBestIndex()
6903 idxNum &= ~0x2000; in seriesBestIndex()
6908 if( idxNum & 0x0080 ) break; in seriesBestIndex()
6909 idxNum |= 0x2000; in seriesBestIndex()
6910 idxNum &= ~0x1000; in seriesBestIndex()
6919 assert( iCol>=0 && iCol<=2 ); in seriesBestIndex()
6922 if( iCol==0 && op==SQLITE_INDEX_CONSTRAINT_EQ ){ in seriesBestIndex()
6926 if( pConstraint->usable==0 ){ in seriesBestIndex()
6934 if( aIdx[3]==0 ){ in seriesBestIndex()
6936 idxNum &= ~0x60; in seriesBestIndex()
6937 aIdx[4] = 0; in seriesBestIndex()
6939 for(i=0; i<7; i++){ in seriesBestIndex()
6940 if( (j = aIdx[i])>=0 ){ in seriesBestIndex()
6947 ** argument (the START value). Legacy versions assumed START=0 if the in seriesBestIndex()
6958 if( (unusableMask & ~idxNum)!=0 ){ in seriesBestIndex()
6964 if( (idxNum & 0x03)==0x03 ){ in seriesBestIndex()
6967 pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0)); in seriesBestIndex()
6969 if( pIdxInfo->nOrderBy>=1 && pIdxInfo->aOrderBy[0].iColumn==0 ){ in seriesBestIndex()
6970 if( pIdxInfo->aOrderBy[0].desc ){ in seriesBestIndex()
6971 idxNum |= 0x08; in seriesBestIndex()
6973 idxNum |= 0x10; in seriesBestIndex()
6977 }else if( (idxNum & 0x21)==0x21 ){ in seriesBestIndex()
6998 0, /* iVersion */
6999 0, /* xCreate */
7003 0, /* xDestroy */
7011 0, /* xUpdate */
7012 0, /* xBegin */
7013 0, /* xSync */
7014 0, /* xCommit */
7015 0, /* xRollback */
7016 0, /* xFindMethod */
7017 0, /* xRename */
7018 0, /* xSavepoint */
7019 0, /* xRelease */
7020 0, /* xRollbackTo */
7021 0, /* xShadowName */
7022 0 /* xIntegrity */
7038 if( sqlite3_libversion_number()<3008012 && pzErrMsg!=0 ){ in sqlite3_series_init()
7043 rc = sqlite3_create_module(db, "generate_series", &seriesModule, 0); in sqlite3_series_init()
7123 #define RE_EOF 0 /* End of input */
7124 #define RE_START 0xfffffff /* Start of input - larger than an UTF-8 */
7141 #define RE_OP_DIGIT 13 /* digit: [0-9] */
7215 for(i=0; i<pSet->nState; i++) if( pSet->aState[i]==newState ) return; in re_add_state()
7226 if( p->i>=p->mx ) return 0; in re_next_char()
7228 if( c>=0x80 ){ in re_next_char()
7229 if( (c&0xe0)==0xc0 && p->i<p->mx && (p->z[p->i]&0xc0)==0x80 ){ in re_next_char()
7230 c = (c&0x1f)<<6 | (p->z[p->i++]&0x3f); in re_next_char()
7231 if( c<0x80 ) c = 0xfffd; in re_next_char()
7232 }else if( (c&0xf0)==0xe0 && p->i+1<p->mx && (p->z[p->i]&0xc0)==0x80 in re_next_char()
7233 && (p->z[p->i+1]&0xc0)==0x80 ){ in re_next_char()
7234 c = (c&0x0f)<<12 | ((p->z[p->i]&0x3f)<<6) | (p->z[p->i+1]&0x3f); in re_next_char()
7236 if( c<=0x7ff || (c>=0xd800 && c<=0xdfff) ) c = 0xfffd; in re_next_char()
7237 }else if( (c&0xf8)==0xf0 && p->i+2<p->mx && (p->z[p->i]&0xc0)==0x80 in re_next_char()
7238 && (p->z[p->i+1]&0xc0)==0x80 && (p->z[p->i+2]&0xc0)==0x80 ){ in re_next_char()
7239 c = (c&0x07)<<18 | ((p->z[p->i]&0x3f)<<12) | ((p->z[p->i+1]&0x3f)<<6) in re_next_char()
7240 | (p->z[p->i+2]&0x3f); in re_next_char()
7242 if( c<=0xffff || c>0x10ffff ) c = 0xfffd; in re_next_char()
7244 c = 0xfffd; in re_next_char()
7257 return (c>='0' && c<='9') || (c>='a' && c<='z') in re_word_char()
7261 /* Return true if c is a "digit" character: [0-9] */
7263 return (c>='0' && c<='9'); in re_digit_char()
7278 unsigned int i = 0; in re_match()
7279 unsigned int iSwap = 0; in re_match()
7281 int cPrev = 0; in re_match()
7282 int rc = 0; in re_match()
7286 in.i = 0; in re_match()
7287 in.mx = nIn>=0 ? nIn : (int)strlen((char const*)zIn); in re_match()
7291 unsigned char x = pRe->zInit[0]; in re_match()
7294 strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0) in re_match()
7298 if( in.i+pRe->nInit>in.mx ) return 0; in re_match()
7302 if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){ in re_match()
7303 pToFree = 0; in re_match()
7304 aStateSet[0].aState = aSpace; in re_match()
7307 if( pToFree==0 ) return -1; in re_match()
7308 aStateSet[0].aState = pToFree; in re_match()
7310 aStateSet[1].aState = &aStateSet[0].aState[pRe->nState]; in re_match()
7312 pNext->nState = 0; in re_match()
7313 re_add_state(pNext, 0); in re_match()
7314 while( c!=RE_EOF && pNext->nState>0 ){ in re_match()
7320 pNext->nState = 0; in re_match()
7321 for(i=0; i<pThis->nState; i++){ in re_match()
7333 if( c!=0 ) re_add_state(pNext, x+1); in re_match()
7341 if( !re_word_char(c) && c!=0 ) re_add_state(pNext, x+1); in re_match()
7349 if( !re_digit_char(c) && c!=0 ) re_add_state(pNext, x+1); in re_match()
7357 if( !re_space_char(c) && c!=0 ) re_add_state(pNext, x+1); in re_match()
7383 if( c==0 ) break; in re_match()
7389 int hit = 0; in re_match()
7390 for(j=1; j>0 && j<n; j++){ in re_match()
7412 for(i=0; i<pNext->nState; i++){ in re_match()
7427 aOp = sqlite3_realloc64(p->aOp, N*sizeof(p->aOp[0])); in re_resize()
7428 if( aOp==0 ) return 1; in re_resize()
7430 aArg = sqlite3_realloc64(p->aArg, N*sizeof(p->aArg[0])); in re_resize()
7431 if( aArg==0 ) return 1; in re_resize()
7434 return 0; in re_resize()
7442 if( p->nAlloc<=p->nState && re_resize(p, p->nAlloc*2) ) return 0; in re_insert()
7464 memcpy(&p->aOp[p->nState], &p->aOp[iStart], N*sizeof(p->aOp[0])); in re_copy()
7465 memcpy(&p->aArg[p->nState], &p->aArg[iStart], N*sizeof(p->aArg[0])); in re_copy()
7469 /* Return true if c is a hexadecimal digit character: [0-9a-fA-F]
7474 if( c>='0' && c<='9' ){ in re_hex()
7475 c -= '0'; in re_hex()
7481 return 0; in re_hex()
7483 *pV = (*pV)*16 + (c & 0xff); in re_hex()
7493 int i, v = 0; in re_esc_char()
7495 if( p->sIn.i>=p->sIn.mx ) return 0; in re_esc_char()
7517 for(i=0; zEsc[i] && zEsc[i]!=c; i++){} in re_esc_char()
7532 return p->sIn.i<p->sIn.mx ? p->sIn.z[p->sIn.i] : 0; in rePeek()
7548 iGoto = re_append(p, RE_OP_GOTO, 0); in re_subcompile_re()
7554 return 0; in re_subcompile_re()
7566 while( (c = p->xNextChar(&p->sIn))!=0 ){ in re_subcompile_string()
7572 return 0; in re_subcompile_string()
7583 re_append(p, RE_OP_ANYSTAR, 0); in re_subcompile_string()
7586 re_append(p, RE_OP_ANY, 0); in re_subcompile_string()
7591 if( iPrev<0 ) return "'*' without operand"; in re_subcompile_string()
7597 if( iPrev<0 ) return "'+' without operand"; in re_subcompile_string()
7602 if( iPrev<0 ) return "'?' without operand"; in re_subcompile_string()
7611 re_append(p, RE_OP_ATSTART, 0); in re_subcompile_string()
7615 int m = 0, n = 0; in re_subcompile_string()
7617 if( iPrev<0 ) return "'{m,n}' without operand"; in re_subcompile_string()
7618 while( (c=rePeek(p))>='0' && c<='9' ){ m = m*10 + c - '0'; p->sIn.i++; } in re_subcompile_string()
7622 n = 0; in re_subcompile_string()
7623 while( (c=rePeek(p))>='0' && c<='9' ){ n = n*10 + c-'0'; p->sIn.i++; } in re_subcompile_string()
7626 if( n>0 && n<m ) return "n less than m in '{m,n}'"; in re_subcompile_string()
7629 if( m==0 ){ in re_subcompile_string()
7630 if( n==0 ) return "both m and n are zero in '{m,n}'"; in re_subcompile_string()
7641 if( n==0 && m>0 ){ in re_subcompile_string()
7649 re_append(p, RE_OP_CC_EXC, 0); in re_subcompile_string()
7652 re_append(p, RE_OP_CC_INC, 0); in re_subcompile_string()
7654 while( (c = p->xNextChar(&p->sIn))!=0 ){ in re_subcompile_string()
7670 if( c==0 ) return "unclosed '['"; in re_subcompile_string()
7675 int specialOp = 0; in re_subcompile_string()
7687 re_append(p, specialOp, 0); in re_subcompile_string()
7701 return 0; in re_subcompile_string()
7728 *ppRe = 0; in re_compile()
7730 if( pRe==0 ){ in re_compile()
7733 memset(pRe, 0, sizeof(*pRe)); in re_compile()
7739 if( zIn[0]=='^' ){ in re_compile()
7742 re_append(pRe, RE_OP_ANYSTAR, 0); in re_compile()
7745 pRe->sIn.i = 0; in re_compile()
7753 re_append(pRe, RE_OP_ACCEPT, 0); in re_compile()
7766 ** unicode characters beyond plane 0 - those are very rare and this is in re_compile()
7768 if( pRe->aOp[0]==RE_OP_ANYSTAR && !noCase ){ in re_compile()
7769 for(j=0, i=1; j<(int)sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){ in re_compile()
7771 if( x<=0x7f ){ in re_compile()
7773 }else if( x<=0x7ff ){ in re_compile()
7774 pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6)); in re_compile()
7775 pRe->zInit[j++] = 0x80 | (x&0x3f); in re_compile()
7776 }else if( x<=0xffff ){ in re_compile()
7777 pRe->zInit[j++] = (unsigned char)(0xe0 | (x>>12)); in re_compile()
7778 pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f); in re_compile()
7779 pRe->zInit[j++] = 0x80 | (x&0x3f); in re_compile()
7784 if( j>0 && pRe->zInit[j-1]==0 ) j--; in re_compile()
7808 int setAux = 0; /* True to invoke sqlite3_set_auxdata() */ in re_sql_func()
7811 pRe = sqlite3_get_auxdata(context, 0); in re_sql_func()
7812 if( pRe==0 ){ in re_sql_func()
7813 zPattern = (const char*)sqlite3_value_text(argv[0]); in re_sql_func()
7814 if( zPattern==0 ) return; in re_sql_func()
7815 zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0); in re_sql_func()
7821 if( pRe==0 ){ in re_sql_func()
7828 if( zStr!=0 ){ in re_sql_func()
7832 sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free); in re_sql_func()
7858 zPattern = (const char*)sqlite3_value_text(argv[0]); in re_bytecode_func()
7859 if( zPattern==0 ) return; in re_bytecode_func()
7860 zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0); in re_bytecode_func()
7866 if( pRe==0 ){ in re_bytecode_func()
7870 pStr = sqlite3_str_new(0); in re_bytecode_func()
7871 if( pStr==0 ) goto re_bytecode_func_err; in re_bytecode_func()
7872 if( pRe->nInit>0 ){ in re_bytecode_func()
7874 for(i=0; i<pRe->nInit; i++){ in re_bytecode_func()
7879 for(i=0; (unsigned)i<pRe->nState; i++){ in re_bytecode_func()
7885 if( n==0 ){ in re_bytecode_func()
7915 0, re_sql_func, 0, 0); in sqlite3_regexp_init()
7921 (void*)db, re_sql_func, 0, 0); in sqlite3_regexp_init()
7926 0, re_bytecode_func, 0, 0); in sqlite3_regexp_init()
8055 /* 0 1 2 3 4 5 */
8057 #define FSDIR_COLUMN_NAME 0 /* Name of the file */
8070 wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) ); in fileio_chmod()
8072 if( b1==0 ) return -1; in fileio_chmod()
8073 sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz); in fileio_chmod()
8074 b1[sz] = 0; in fileio_chmod()
8087 wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) ); in fileio_mkdir()
8089 if( b1==0 ) return -1; in fileio_mkdir()
8090 sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz); in fileio_mkdir()
8091 b1[sz] = 0; in fileio_mkdir()
8118 if( in==0 ){ in readFileContents()
8122 fseek(in, 0, SEEK_END); in readFileContents()
8133 if( pBuf==0 ){ in readFileContents()
8159 zName = (const char*)sqlite3_value_text(argv[0]); in readfileFunc()
8160 if( zName==0 ) return; in readfileFunc()
8169 char *zMsg = 0; in ctxErrorMsg()
8191 memset(&epochSystemTime, 0, sizeof(SYSTEMTIME)); in fileTimeToUnixTime()
8212 int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0); in utf8_to_utf16()
8214 if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) ) in utf8_to_utf16()
8217 return 0; in utf8_to_utf16()
8236 memset(&fd, 0, sizeof(WIN32_FIND_DATAW)); in statTimesToUtc()
8260 wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) ); in fileStat()
8262 if( b1==0 ) return 1; in fileStat()
8263 sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz); in fileStat()
8264 b1[sz] = 0; in fileStat()
8266 if( rc==0 ) statTimesToUtc(zPath, pStatBuf); in fileStat()
8306 if( zCopy==0 ){ in makeDirectory()
8318 zCopy[i] = '\0'; in makeDirectory()
8321 if( rc2!=0 ){ in makeDirectory()
8347 if( zFile==0 ) return 1; in writeFile()
8351 if( zTo==0 ) return 1; in writeFile()
8353 if( symlink(zTo, zFile)<0 ) return 1; in writeFile()
8365 || 0!=fileStat(zFile, &sStat) in writeFile()
8367 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777)) in writeFile()
8373 sqlite3_int64 nWrite = 0; in writeFile()
8375 int rc = 0; in writeFile()
8377 if( out==0 ) return 1; in writeFile()
8387 if( rc==0 && mode && chmod(zFile, mode & 0777) ){ in writeFile()
8395 if( mtime>=0 ){ in writeFile()
8413 if( zUnicodeName==0 ){ in writeFile()
8417 zUnicodeName, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, in writeFile()
8429 #elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */ in writeFile()
8432 times[0].tv_nsec = times[1].tv_nsec = 0; in writeFile()
8433 times[0].tv_sec = time(0); in writeFile()
8444 if( 0==S_ISLNK(mode) ){ in writeFile()
8446 times[0].tv_usec = times[1].tv_usec = 0; in writeFile()
8447 times[0].tv_sec = time(0); in writeFile()
8456 return 0; in writeFile()
8469 mode_t mode = 0; in writefileFunc()
8480 zFile = (const char*)sqlite3_value_text(argv[0]); in writefileFunc()
8481 if( zFile==0 ) return; in writefileFunc()
8496 if( argc>2 && res!=0 ){ in writefileFunc()
8519 int iMode = sqlite3_value_int(argv[0]); in lsModeFunc()
8523 z[0] = 'l'; in lsModeFunc()
8525 z[0] = '-'; in lsModeFunc()
8527 z[0] = 'd'; in lsModeFunc()
8529 z[0] = '?'; in lsModeFunc()
8531 for(i=0; i<3; i++){ in lsModeFunc()
8534 a[0] = (m & 0x4) ? 'r' : '-'; in lsModeFunc()
8535 a[1] = (m & 0x2) ? 'w' : '-'; in lsModeFunc()
8536 a[2] = (m & 0x1) ? 'x' : '-'; in lsModeFunc()
8538 z[10] = '\0'; in lsModeFunc()
8585 fsdir_tab *pNew = 0; in fsdirConnect()
8594 if( pNew==0 ) return SQLITE_NOMEM; in fsdirConnect()
8595 memset(pNew, 0, sizeof(*pNew)); in fsdirConnect()
8617 if( pCur==0 ) return SQLITE_NOMEM; in fsdirOpen()
8618 memset(pCur, 0, sizeof(*pCur)); in fsdirOpen()
8630 for(i=0; i<=pCur->iLvl; i++){ in fsdirResetCursor()
8637 pCur->aLvl = 0; in fsdirResetCursor()
8638 pCur->zPath = 0; in fsdirResetCursor()
8639 pCur->zBase = 0; in fsdirResetCursor()
8640 pCur->nBase = 0; in fsdirResetCursor()
8641 pCur->nLvl = 0; in fsdirResetCursor()
8685 if( aNew==0 ) return SQLITE_NOMEM; in fsdirNext()
8686 memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl)); in fsdirNext()
8694 pCur->zPath = 0; in fsdirNext()
8696 if( pLvl->pDir==0 ){ in fsdirNext()
8702 while( pCur->iLvl>=0 ){ in fsdirNext()
8706 if( pEntry->d_name[0]=='.' ){ in fsdirNext()
8707 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue; in fsdirNext()
8708 if( pEntry->d_name[1]=='\0' ) continue; in fsdirNext()
8712 if( pCur->zPath==0 ) return SQLITE_NOMEM; in fsdirNext()
8721 pLvl->pDir = 0; in fsdirNext()
8722 pLvl->zDir = 0; in fsdirNext()
8728 pCur->zPath = 0; in fsdirNext()
8773 if( aBuf==0 ){ in fsdirColumn()
8813 return (pCur->zPath==0); in fsdirEof()
8827 const char *zDir = 0; in fsdirFilter()
8832 if( idxNum==0 ){ in fsdirFilter()
8838 zDir = (const char*)sqlite3_value_text(argv[0]); in fsdirFilter()
8839 if( zDir==0 ){ in fsdirFilter()
8853 if( pCur->zPath==0 ){ in fsdirFilter()
8875 ** (1) The path value is supplied by argv[0]
8876 ** (2) Path is in argv[0] and dir is in argv[1]
8885 int seenPath = 0; /* True if an unusable PATH= constraint is seen */ in fsdirBestIndex()
8886 int seenDir = 0; /* True if an unusable DIR= constraint is seen */ in fsdirBestIndex()
8891 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){ in fsdirBestIndex()
8897 seenPath = 0; in fsdirBestIndex()
8898 }else if( idxPath<0 ){ in fsdirBestIndex()
8906 seenDir = 0; in fsdirBestIndex()
8907 }else if( idxDir<0 ){ in fsdirBestIndex()
8919 if( idxPath<0 ){ in fsdirBestIndex()
8920 pIdxInfo->idxNum = 0; in fsdirBestIndex()
8923 pIdxInfo->estimatedRows = 0x7fffffff; in fsdirBestIndex()
8927 if( idxDir>=0 ){ in fsdirBestIndex()
8946 0, /* iVersion */ in fsdirRegister()
8947 0, /* xCreate */ in fsdirRegister()
8951 0, /* xDestroy */ in fsdirRegister()
8959 0, /* xUpdate */ in fsdirRegister()
8960 0, /* xBegin */ in fsdirRegister()
8961 0, /* xSync */ in fsdirRegister()
8962 0, /* xCommit */ in fsdirRegister()
8963 0, /* xRollback */ in fsdirRegister()
8964 0, /* xFindMethod */ in fsdirRegister()
8965 0, /* xRename */ in fsdirRegister()
8966 0, /* xSavepoint */ in fsdirRegister()
8967 0, /* xRelease */ in fsdirRegister()
8968 0, /* xRollbackTo */ in fsdirRegister()
8969 0, /* xShadowName */ in fsdirRegister()
8970 0 /* xIntegrity */ in fsdirRegister()
8973 int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0); in fsdirRegister()
8992 SQLITE_UTF8|SQLITE_DIRECTONLY, 0, in sqlite3_fileio_init()
8993 readfileFunc, 0, 0); in sqlite3_fileio_init()
8996 SQLITE_UTF8|SQLITE_DIRECTONLY, 0, in sqlite3_fileio_init()
8997 writefileFunc, 0, 0); in sqlite3_fileio_init()
9000 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0, in sqlite3_fileio_init()
9001 lsModeFunc, 0, 0); in sqlite3_fileio_init()
9139 #define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */ in completionConnect()
9155 if( pNew==0 ) return SQLITE_NOMEM; in completionConnect()
9156 memset(pNew, 0, sizeof(*pNew)); in completionConnect()
9176 if( pCur==0 ) return SQLITE_NOMEM; in completionOpen()
9177 memset(pCur, 0, sizeof(*pCur)); in completionOpen()
9187 sqlite3_free(pCur->zPrefix); pCur->zPrefix = 0; pCur->nPrefix = 0; in completionCursorReset()
9188 sqlite3_free(pCur->zLine); pCur->zLine = 0; pCur->nLine = 0; in completionCursorReset()
9189 sqlite3_finalize(pCur->pStmt); pCur->pStmt = 0; in completionCursorReset()
9190 pCur->j = 0; in completionCursorReset()
9218 int eNextPhase = 0; /* Next phase to try if current phase reaches end */ in completionNext()
9219 int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */ in completionNext()
9225 pCur->zCurrentRow = 0; in completionNext()
9234 if( pCur->pStmt==0 ){ in completionNext()
9236 &pCur->pStmt, 0); in completionNext()
9243 if( pCur->pStmt==0 ){ in completionNext()
9245 char *zSql = 0; in completionNext()
9247 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0); in completionNext()
9255 if( zSql==0 ) return SQLITE_NOMEM; in completionNext()
9259 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0); in completionNext()
9262 iCol = 0; in completionNext()
9267 if( pCur->pStmt==0 ){ in completionNext()
9269 char *zSql = 0; in completionNext()
9271 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0); in completionNext()
9281 if( zSql==0 ) return SQLITE_NOMEM; in completionNext()
9285 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0); in completionNext()
9288 iCol = 0; in completionNext()
9293 if( iCol<0 ){ in completionNext()
9295 if( pCur->zCurrentRow==0 ) continue; in completionNext()
9304 pCur->pStmt = 0; in completionNext()
9309 if( pCur->nPrefix==0 ) break; in completionNext()
9311 && sqlite3_strnicmp(pCur->zPrefix, pCur->zCurrentRow, pCur->nPrefix)==0 in completionNext()
9382 int iArg = 0; in completionFilter()
9388 if( pCur->nPrefix>0 ){ in completionFilter()
9390 if( pCur->zPrefix==0 ) return SQLITE_NOMEM; in completionFilter()
9396 if( pCur->nLine>0 ){ in completionFilter()
9398 if( pCur->zLine==0 ) return SQLITE_NOMEM; in completionFilter()
9401 if( pCur->zLine!=0 && pCur->zPrefix==0 ){ in completionFilter()
9403 while( i>0 && (IsAlnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){ in completionFilter()
9407 if( pCur->nPrefix>0 ){ in completionFilter()
9409 if( pCur->zPrefix==0 ) return SQLITE_NOMEM; in completionFilter()
9412 pCur->iRowid = 0; in completionFilter()
9424 ** function: "prefix" and "wholeline". Bit 0 of idxNum is set if "prefix"
9432 int idxNum = 0; /* The query plan bitmask */ in completionBestIndex()
9435 int nArg = 0; /* Number of arguments that completeFilter() expects */ in completionBestIndex()
9440 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){ in completionBestIndex()
9441 if( pConstraint->usable==0 ) continue; in completionBestIndex()
9454 if( prefixIdx>=0 ){ in completionBestIndex()
9458 if( wholelineIdx>=0 ){ in completionBestIndex()
9473 0, /* iVersion */
9474 0, /* xCreate */
9478 0, /* xDestroy */
9486 0, /* xUpdate */
9487 0, /* xBegin */
9488 0, /* xSync */
9489 0, /* xCommit */
9490 0, /* xRollback */
9491 0, /* xFindMethod */
9492 0, /* xRename */
9493 0, /* xSavepoint */
9494 0, /* xRelease */
9495 0, /* xRollbackTo */
9496 0, /* xShadowName */
9497 0 /* xIntegrity */
9505 rc = sqlite3_create_module(db, "completion", &completionModule, 0); in sqlite3CompletionVtabInit()
9597 ** must be less than 0x40000000 to avoid locking issues on Windows.
9599 #define APND_MAX_SIZE (0x40000000)
9707 0, /* szOsFile (set when registered) */
9709 0, /* pNext */
9711 0, /* pAppData (set when registered) */
9790 while( --i >= 0 ){ in apndWriteMark()
9791 a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff); in apndWriteMark()
9816 if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){ in apndWrite()
9845 ** If the append mark is not yet there, the file-size is 0.
9849 *pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0; in apndFileSize()
9946 if( p->iMark < 0 || iOfst+iAmt > p->iMark ){ in apndFetch()
9975 if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1; in apndReadMark()
9978 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1; in apndReadMark()
9979 iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs; in apndReadMark()
9985 if( iMark & 0x1ff ) return -1; in apndReadMark()
9998 if( iMark>=0 ){ in apndIsAppendvfsDatabase()
10005 && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0 in apndIsAppendvfsDatabase()
10006 && (sz & 0x1ff) == APND_MARK_SIZE in apndIsAppendvfsDatabase()
10012 return 0; in apndIsAppendvfsDatabase()
10022 || (sz & 0x1ff) != 0 in apndIsOrdinaryDatabaseFile()
10023 || SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0) in apndIsOrdinaryDatabaseFile()
10024 || memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))!=0 in apndIsOrdinaryDatabaseFile()
10026 return 0; in apndIsOrdinaryDatabaseFile()
10046 sqlite3_int64 sz = 0; in apndOpen()
10047 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){ in apndOpen()
10054 memset(pApndFile, 0, sizeof(ApndFile)); in apndOpen()
10066 pFile->pMethods = 0; in apndOpen()
10077 if( pApndFile->iPgOne>=0 ){ in apndOpen()
10081 if( (flags & SQLITE_OPEN_CREATE)==0 ){ in apndOpen()
10084 pFile->pMethods = 0; in apndOpen()
10187 pOrig = sqlite3_vfs_find(0); in sqlite3_appendvfs_init()
10188 if( pOrig==0 ) return SQLITE_ERROR; in sqlite3_appendvfs_init()
10192 rc = sqlite3_vfs_register(&apnd_vfs, 0); in sqlite3_appendvfs_init()
10280 # define NEVER(X) (0)
10282 # define ALWAYS(X) ((X)?1:(assert(0),0))
10283 # define NEVER(X) ((X)?(assert(0),1):0)
10312 "name PRIMARY KEY," /* 0: Name of file in zip archive */
10352 #define ZIPFILE_EXTRA_TIMESTAMP 0x5455
10355 #define ZIPFILE_NEWENTRY_FLAGS 0x800
10356 #define ZIPFILE_SIGNATURE_CDS 0x02014b50
10357 #define ZIPFILE_SIGNATURE_LFH 0x04034b50
10358 #define ZIPFILE_SIGNATURE_EOCD 0x06054b50
10371 *** end of central dir signature 4 bytes (0x06054b50)
10401 *** central file header signature 4 bytes (0x02014b50)
10443 *** local file header signature 4 bytes (0x04034b50)
10475 i64 iDataOff; /* Offset to data in file (if aData==0) */
10511 ZipfileEntry *pFirstEntry; /* Linked list of all files (if pWriteFd!=0) */
10523 char *zMsg = 0; in zipfileCtxErrorMsg()
10537 char q = zIn[0]; in zipfileDequote()
10540 int iOut = 0; in zipfileDequote()
10547 zIn[iOut] = '\0'; in zipfileDequote()
10554 ** argv[0] -> module name ("zipfile")
10567 int nFile = 0; in zipfileConnect()
10568 const char *zFile = 0; in zipfileConnect()
10569 ZipfileTab *pNew = 0; in zipfileConnect()
10582 assert( 0==sqlite3_stricmp(argv[0], "zipfile") ); in zipfileConnect()
10583 if( (0!=sqlite3_stricmp(argv[2], "zipfile") && argc<4) || argc>4 ){ in zipfileConnect()
10596 if( pNew==0 ) return SQLITE_NOMEM; in zipfileConnect()
10597 memset(pNew, 0, nByte+nFile); in zipfileConnect()
10631 pTab->pWriteFd = 0; in zipfileCleanupTransaction()
10637 pTab->pFirstEntry = 0; in zipfileCleanupTransaction()
10638 pTab->pLastEntry = 0; in zipfileCleanupTransaction()
10639 pTab->szCurrent = 0; in zipfileCleanupTransaction()
10640 pTab->szOrig = 0; in zipfileCleanupTransaction()
10660 if( pCsr==0 ){ in zipfileOpen()
10663 memset(pCsr, 0, sizeof(*pCsr)); in zipfileOpen()
10678 pCsr->bEof = 0; in zipfileResetCursor()
10681 pCsr->pFile = 0; in zipfileResetCursor()
10683 pCsr->pCurrent = 0; in zipfileResetCursor()
10760 if( nWrite>0 ){ in zipfileAppendData()
10777 return (aBuf[1] << 8) + aBuf[0]; in zipfileGetU16()
10784 if( aBuf==0 ) return 0; in zipfileGetU32()
10788 + ((u32)(aBuf[0]) << 0); in zipfileGetU32()
10795 aBuf[0] = val & 0xFF; in zipfilePutU16()
10796 aBuf[1] = (val>>8) & 0xFF; in zipfilePutU16()
10803 aBuf[0] = val & 0xFF; in zipfilePutU32()
10804 aBuf[1] = (val>>8) & 0xFF; in zipfilePutU32()
10805 aBuf[2] = (val>>16) & 0xFF; in zipfilePutU32()
10806 aBuf[3] = (val>>24) & 0xFF; in zipfilePutU32()
10901 int ret = 0; in zipfileScanExtra()
10911 u8 b = p[0]; in zipfileScanExtra()
10912 if( b & 0x01 ){ /* 0x01 -> modtime is present */ in zipfileScanExtra()
10946 Y = (1980 + ((pCDS->mDate >> 9) & 0x7F)); in zipfileMtime()
10947 M = ((pCDS->mDate >> 5) & 0x0F); in zipfileMtime()
10948 D = (pCDS->mDate & 0x1F); in zipfileMtime()
10949 sec = (pCDS->mTime & 0x1F)*2; in zipfileMtime()
10950 min = (pCDS->mTime >> 5) & 0x3F; in zipfileMtime()
10951 hr = (pCDS->mTime >> 11) & 0x1F; in zipfileMtime()
10996 pCds->mDate = pCds->mTime = 0; in zipfileMtimeToDos()
11021 FILE *pFile, /* If aBlob==0, read from this file */ in zipfileGetEntry()
11030 if( aBlob==0 ){ in zipfileGetEntry()
11051 if( pNew==0 ){ in zipfileGetEntry()
11054 memset(pNew, 0, sizeof(ZipfileEntry)); in zipfileGetEntry()
11058 }else if( aBlob==0 ){ in zipfileGetEntry()
11072 if( pNew->cds.zFile==0 ){ in zipfileGetEntry()
11074 }else if( 0==zipfileScanExtra(&aRead[nFile], pNew->cds.nExtra, pt) ){ in zipfileGetEntry()
11123 pCsr->pCurrent = 0; in zipfileNext()
11127 ZipfileEntry *p = 0; in zipfileNext()
11129 rc = zipfileGetEntry(pTab, 0, 0, pCsr->pFile, pCsr->iNextOff, &p); in zipfileNext()
11140 if( pCsr->pCurrent==0 ){ in zipfileNext()
11145 pCsr->bNoop = 0; in zipfileNext()
11167 if( aRes==0 ){ in zipfileInflate()
11172 memset(&str, 0, sizeof(str)); in zipfileInflate()
11188 aRes = 0; in zipfileInflate()
11218 memset(&str, 0, sizeof(str)); in zipfileDeflate()
11225 if( aOut==0 ){ in zipfileDeflate()
11260 case 0: /* name */ in zipfileColumn()
11273 if( sqlite3_vtab_nochange(ctx)==0 ){ in zipfileColumn()
11281 if( i==4 || pCDS->iCompression==0 || pCDS->iCompression==8 ){ in zipfileColumn()
11284 if( szFinal>0 ){ in zipfileColumn()
11286 u8 *aFree = 0; in zipfileColumn()
11291 if( aBuf==0 ){ in zipfileColumn()
11295 if( pFile==0 ){ in zipfileColumn()
11320 sqlite3_result_blob(ctx, "", 0, SQLITE_STATIC); in zipfileColumn()
11360 FILE *pFile, /* Read from this file if aBlob==0 */ in zipfileReadEOCD()
11367 memset(pEOCD, 0, sizeof(ZipfileEOCD)); in zipfileReadEOCD()
11368 if( aBlob==0 ){ in zipfileReadEOCD()
11371 fseek(pFile, 0, SEEK_END); in zipfileReadEOCD()
11373 if( szFile==0 ){ in zipfileReadEOCD()
11388 for(i=nRead-20; i>=0; i--){ in zipfileReadEOCD()
11389 if( aRead[i]==0x50 && aRead[i+1]==0x4b in zipfileReadEOCD()
11390 && aRead[i+2]==0x05 && aRead[i+3]==0x06 in zipfileReadEOCD()
11395 if( i<0 ){ in zipfileReadEOCD()
11425 assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) ); in zipfileAddEntry()
11426 assert( pNew->pNext==0 ); in zipfileAddEntry()
11427 if( pBefore==0 ){ in zipfileAddEntry()
11428 if( pTab->pFirstEntry==0 ){ in zipfileAddEntry()
11431 assert( pTab->pLastEntry->pNext==0 ); in zipfileAddEntry()
11451 for(i=0; rc==SQLITE_OK && i<eocd.nEntry; i++){ in zipfileLoadDirectory()
11452 ZipfileEntry *pNew = 0; in zipfileLoadDirectory()
11456 zipfileAddEntry(pTab, 0, pNew); in zipfileLoadDirectory()
11474 const char *zFile = 0; /* Zip file to scan */ in zipfileFilter()
11476 int bInMemory = 0; /* True for an in-memory zipfile */ in zipfileFilter()
11485 }else if( idxNum==0 ){ in zipfileFilter()
11488 }else if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){ in zipfileFilter()
11489 static const u8 aEmptyBlob = 0; in zipfileFilter()
11490 const u8 *aBlob = (const u8*)sqlite3_value_blob(argv[0]); in zipfileFilter()
11491 int nBlob = sqlite3_value_bytes(argv[0]); in zipfileFilter()
11492 assert( pTab->pFirstEntry==0 ); in zipfileFilter()
11493 if( aBlob==0 ){ in zipfileFilter()
11495 nBlob = 0; in zipfileFilter()
11499 pTab->pFirstEntry = pTab->pLastEntry = 0; in zipfileFilter()
11503 zFile = (const char*)sqlite3_value_text(argv[0]); in zipfileFilter()
11506 if( 0==pTab->pWriteFd && 0==bInMemory ){ in zipfileFilter()
11507 pCsr->pFile = zFile ? sqlite3_fopen(zFile, "rb") : 0; in zipfileFilter()
11508 if( pCsr->pFile==0 ){ in zipfileFilter()
11512 rc = zipfileReadEOCD(pTab, 0, 0, pCsr->pFile, &pCsr->eocd); in zipfileFilter()
11514 if( pCsr->eocd.nEntry==0 ){ in zipfileFilter()
11540 int unusable = 0; in zipfileBestIndex()
11543 for(i=0; i<pIdxInfo->nConstraint; i++){ in zipfileBestIndex()
11546 if( pCons->usable==0 ){ in zipfileBestIndex()
11553 if( idx>=0 ){ in zipfileBestIndex()
11567 memset(pNew, 0, sizeof(ZipfileEntry)); in zipfileNewEntry()
11569 if( pNew->cds.zFile==0 ){ in zipfileNewEntry()
11571 pNew = 0; in zipfileNewEntry()
11604 *a++ = 0x01; in zipfileSerializeLFH()
11637 u32 mode = 0; in zipfileGetMode()
11638 if( z==0 ){ in zipfileGetMode()
11640 }else if( z[0]>='0' && z[0]<='9' ){ in zipfileGetMode()
11646 switch( z[0] ){ in zipfileGetMode()
11657 if( ((mode & S_IFDIR)==0)==bIsDir ){ in zipfileGetMode()
11673 ** nB is the value of strlen(zB). This function returns 0 if the strings are
11677 if( nA>0 && zA[nA-1]=='/' ) nA--; in zipfileComparePath()
11678 if( nB>0 && zB[nB-1]=='/' ) nB--; in zipfileComparePath()
11679 if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0; in zipfileComparePath()
11687 assert( pTab->pWriteFd==0 ); in zipfileBegin()
11688 if( pTab->zFile==0 || pTab->zFile[0]==0 ){ in zipfileBegin()
11698 if( pTab->pWriteFd==0 ){ in zipfileBegin()
11704 fseek(pTab->pWriteFd, 0, SEEK_END); in zipfileBegin()
11706 rc = zipfileLoadDirectory(pTab, 0, 0); in zipfileBegin()
11721 sqlite3_vfs *pVfs = sqlite3_vfs_find(0); in zipfileTime()
11723 if( pVfs==0 ) return 0; in zipfileTime()
11744 if( pVal==0 || sqlite3_value_type(pVal)==SQLITE_NULL ){ in zipfileGetTime()
11758 if( pTab->pLastEntry==pOld ) pTab->pLastEntry = 0; in zipfileRemoveEntryFromList()
11784 ZipfileEntry *pNew = 0; /* New in-memory CDS entry */ in zipfileUpdate()
11786 u32 mode = 0; /* Mode for new entry */ in zipfileUpdate()
11787 u32 mTime = 0; /* Modification time for new entry */ in zipfileUpdate()
11788 i64 sz = 0; /* Uncompressed size */ in zipfileUpdate()
11789 const char *zPath = 0; /* Path for new entry */ in zipfileUpdate()
11790 int nPath = 0; /* strlen(zPath) */ in zipfileUpdate()
11791 const u8 *pData = 0; /* Pointer to buffer containing content */ in zipfileUpdate()
11792 int nData = 0; /* Size of pData buffer in bytes */ in zipfileUpdate()
11793 int iMethod = 0; /* Compression method for new entry */ in zipfileUpdate()
11794 u8 *pFree = 0; /* Free this */ in zipfileUpdate()
11795 char *zFree = 0; /* Also free this */ in zipfileUpdate()
11796 ZipfileEntry *pOld = 0; in zipfileUpdate()
11797 ZipfileEntry *pOld2 = 0; in zipfileUpdate()
11798 int bUpdate = 0; /* True for an update that modifies "name" */ in zipfileUpdate()
11799 int bIsDir = 0; in zipfileUpdate()
11800 u32 iCrc32 = 0; in zipfileUpdate()
11804 if( pTab->pWriteFd==0 ){ in zipfileUpdate()
11810 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ in zipfileUpdate()
11811 const char *zDelete = (const char*)sqlite3_value_text(apVal[0]); in zipfileUpdate()
11815 if( zUpdate && zipfileComparePath(zUpdate, zDelete, nDelete)!=0 ){ in zipfileUpdate()
11820 if( zipfileComparePath(pOld->cds.zFile, zDelete, nDelete)==0 ){ in zipfileUpdate()
11853 if( iMethod!=0 && iMethod!=8 ){ in zipfileUpdate()
11868 iCrc32 = crc32(0, aIn, nIn); in zipfileUpdate()
11879 if( zPath==0 ) zPath = ""; in zipfileUpdate()
11889 if( nPath<=0 || zPath[nPath-1]!='/' ){ in zipfileUpdate()
11892 if( zFree==0 ){ in zipfileUpdate()
11894 nPath = 0; in zipfileUpdate()
11903 if( (pOld==0 || bUpdate) && rc==SQLITE_OK ){ in zipfileUpdate()
11906 if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){ in zipfileUpdate()
11929 if( pNew==0 ){ in zipfileUpdate()
11978 zipfileWrite16(a, 0); /* Size of trailing comment in bytes*/ in zipfileSerializeEOCD()
11997 if( pEntry->aExtra==0 ){ in zipfileSerializeCDS()
12031 *a++ = 0x01; in zipfileSerializeCDS()
12045 int nEntry = 0; in zipfileCommit()
12055 eocd.iDisk = 0; in zipfileCommit()
12056 eocd.iFirstDisk = 0; in zipfileCommit()
12087 assert( argc>0 ); in zipfileFunctionCds()
12089 pCsr = zipfileFindCursor(pTab, sqlite3_value_int64(argv[0])); in zipfileFunctionCds()
12119 if( zRes==0 ){ in zipfileFunctionCds()
12139 if( sqlite3_stricmp("zipfile_cds", zName)==0 ){ in zipfileFindFunction()
12144 return 0; in zipfileFindFunction()
12169 if( aNew==0 ) return SQLITE_NOMEM; in zipfileBufferGrow()
12188 sqlite3_value *pName = 0; in zipfileStep()
12189 sqlite3_value *pMode = 0; in zipfileStep()
12190 sqlite3_value *pMtime = 0; in zipfileStep()
12191 sqlite3_value *pData = 0; in zipfileStep()
12192 sqlite3_value *pMethod = 0; in zipfileStep()
12194 int bIsDir = 0; in zipfileStep()
12197 char *zErr = 0; in zipfileStep()
12199 int iMethod = -1; /* Compression method to use (0 or 8) */ in zipfileStep()
12201 const u8 *aData = 0; /* Possibly compressed data for new entry */ in zipfileStep()
12202 int nData = 0; /* Size of aData[] in bytes */ in zipfileStep()
12203 int szUncompressed = 0; /* Size of data before compression */ in zipfileStep()
12204 u8 *aFree = 0; /* Free this before returning */ in zipfileStep()
12205 u32 iCrc32 = 0; /* crc32 of uncompressed data */ in zipfileStep()
12207 char *zName = 0; /* Path (name) of new entry */ in zipfileStep()
12208 int nName = 0; /* Size of zName in bytes */ in zipfileStep()
12209 char *zFree = 0; /* Free this before returning */ in zipfileStep()
12212 memset(&e, 0, sizeof(e)); in zipfileStep()
12214 if( p==0 ) return; in zipfileStep()
12222 pName = apVal[0]; in zipfileStep()
12237 if( zName==0 ){ in zipfileStep()
12243 /* Inspect the 'method' parameter. This must be either 0 (store), 8 (use in zipfileStep()
12247 if( iMethod!=0 && iMethod!=8 ){ in zipfileStep()
12259 iMethod = 0; in zipfileStep()
12263 iCrc32 = crc32(0, aData, nData); in zipfileStep()
12264 if( iMethod<0 || iMethod==8 ){ in zipfileStep()
12265 int nOut = 0; in zipfileStep()
12275 iMethod = 0; in zipfileStep()
12290 if( bIsDir==0 ){ in zipfileStep()
12291 if( nName>0 && zName[nName-1]=='/' ){ in zipfileStep()
12297 if( nName==0 || zName[nName-1]!='/' ){ in zipfileStep()
12299 if( zName==0 ){ in zipfileStep()
12329 if( nData>0 ){ in zipfileStep()
12366 if( p==0 ) return; in zipfileFinal()
12367 if( p->nEntry>0 ){ in zipfileFinal()
12368 memset(&eocd, 0, sizeof(eocd)); in zipfileFinal()
12376 if( aZip==0 ){ in zipfileFinal()
12408 0, /* xRowid - read data */ in zipfileRegister()
12411 0, /* xSync */ in zipfileRegister()
12415 0, /* xRename */ in zipfileRegister()
12416 0, /* xSavepoint */ in zipfileRegister()
12417 0, /* xRelease */ in zipfileRegister()
12418 0, /* xRollback */ in zipfileRegister()
12419 0, /* xShadowName */ in zipfileRegister()
12420 0 /* xIntegrity */ in zipfileRegister()
12423 int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0); in zipfileRegister()
12426 rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0, in zipfileRegister()
12497 if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){ in sqlarCompressFunc()
12498 const Bytef *pData = sqlite3_value_blob(argv[0]); in sqlarCompressFunc()
12499 uLong nData = sqlite3_value_bytes(argv[0]); in sqlarCompressFunc()
12504 if( pOut==0 ){ in sqlarCompressFunc()
12513 sqlite3_result_value(context, argv[0]); in sqlarCompressFunc()
12518 sqlite3_result_value(context, argv[0]); in sqlarCompressFunc()
12543 if( sz<=0 || sz==(nData = sqlite3_value_bytes(argv[0])) ){ in sqlarUncompressFunc()
12544 sqlite3_result_value(context, argv[0]); in sqlarUncompressFunc()
12547 const Bytef *pData= sqlite3_value_blob(argv[0]); in sqlarUncompressFunc()
12549 if( pOut==0 ){ in sqlarUncompressFunc()
12572 SQLITE_UTF8|SQLITE_INNOCUOUS, 0, in sqlite3_sqlar_init()
12573 sqlarCompressFunc, 0, 0); in sqlite3_sqlar_init()
12576 SQLITE_UTF8|SQLITE_INNOCUOUS, 0, in sqlite3_sqlar_init()
12577 sqlarUncompressFunc, 0, 0); in sqlite3_sqlar_init()
12631 ** value falls between 0 and 100, then it represents the percentage of user
12637 ** sqlite3_expert_config(pExpert, EXPERT_CONFIG_SAMPLE, 0);
12713 ** SQL statements are numbered from 0 in the order in which they are parsed.
12779 # define NEVER(X) (0)
12781 # define ALWAYS(X) ((X)?1:(assert(0),0))
12782 # define NEVER(X) ((X)?(assert(0),1):0)
12933 assert( nByte>0 ); in idxMalloc()
12936 memset(pRet, 0, nByte); in idxMalloc()
12947 memset(pHash, 0, sizeof(IdxHash)); in idxHashInit()
12955 for(i=0; i<IDX_HASH_SIZE; i++){ in idxHashClear()
12964 memset(pHash, 0, sizeof(IdxHash)); in idxHashClear()
12972 unsigned int ret = 0; in idxHashString()
12974 for(i=0; i<n; i++){ in idxHashString()
12993 int nVal = (zVal ? STRLEN(zVal) : 0); in idxHashAdd()
12995 assert( iHash>=0 ); in idxHashAdd()
12997 if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){ in idxHashAdd()
13015 return 0; in idxHashAdd()
13025 if( nKey<0 ) nKey = STRLEN(zKey); in idxHashFind()
13027 assert( iHash>=0 ); in idxHashFind()
13029 if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){ in idxHashFind()
13033 return 0; in idxHashFind()
13045 return 0; in idxHashSearch()
13085 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0); in idxPrepareStmt()
13087 *ppStmt = 0; in idxPrepareStmt()
13108 if( zSql==0 ){ in idxPrintfPrepareStmt()
13139 assert( zIn[0]=='\'' ); in expertDequote()
13143 int iOut = 0; in expertDequote()
13144 int iIn = 0; in expertDequote()
13152 zRet[iOut] = '\0'; in expertDequote()
13162 ** argv[0] -> module name
13175 ExpertVtab *p = 0; in expertConnect()
13191 assert( sqlite3_stricmp(p->pTab->zName, argv[2])==0 ); in expertConnect()
13212 int n = 0; in expertBestIndex()
13229 for(i=0; i<pIdxInfo->nConstraint; i++){ in expertBestIndex()
13232 && pCons->iColumn>=0 in expertBestIndex()
13233 && p->pTab->aCol[pCons->iColumn].iPk==0 in expertBestIndex()
13256 for(i=pIdxInfo->nOrderBy-1; i>=0; i--){ in expertBestIndex()
13258 if( iCol>=0 ){ in expertBestIndex()
13319 return pCsr->pData==0; in expertEof()
13333 pCsr->pData = 0; in expertNext()
13346 *pRowid = 0; in expertRowid()
13381 pCsr->pData = 0; in expertFilter()
13410 0, /* xBegin - begin transaction */ in idxRegisterVtab()
13411 0, /* xSync - sync transaction */ in idxRegisterVtab()
13412 0, /* xCommit - commit transaction */ in idxRegisterVtab()
13413 0, /* xRollback - rollback transaction */ in idxRegisterVtab()
13414 0, /* xFindFunction - function overloading */ in idxRegisterVtab()
13415 0, /* xRename - rename the table */ in idxRegisterVtab()
13416 0, /* xSavepoint */ in idxRegisterVtab()
13417 0, /* xRelease */ in idxRegisterVtab()
13418 0, /* xRollbackTo */ in idxRegisterVtab()
13419 0, /* xShadowName */ in idxRegisterVtab()
13420 0, /* xIntegrity */ in idxRegisterVtab()
13454 sqlite3_stmt *p1 = 0; in idxGetTableInfo()
13455 int nCol = 0; in idxGetTableInfo()
13458 IdxTable *pNew = 0; in idxGetTableInfo()
13460 char *pCsr = 0; in idxGetTableInfo()
13461 int nPk = 0; in idxGetTableInfo()
13463 *ppOut = 0; in idxGetTableInfo()
13464 if( zTab==0 ) return SQLITE_ERROR; in idxGetTableInfo()
13470 const char *zColSeq = 0; in idxGetTableInfo()
13471 if( zCol==0 ){ in idxGetTableInfo()
13477 db, "main", zTab, zCol, 0, &zColSeq, 0, 0, 0 in idxGetTableInfo()
13479 if( zColSeq==0 ) zColSeq = "binary"; in idxGetTableInfo()
13482 nPk += (sqlite3_column_int(p1, 5)>0); in idxGetTableInfo()
13497 nCol = 0; in idxGetTableInfo()
13500 const char *zColSeq = 0; in idxGetTableInfo()
13502 if( zCol==0 ) continue; in idxGetTableInfo()
13510 db, "main", zTab, zCol, 0, &zColSeq, 0, 0, 0 in idxGetTableInfo()
13513 if( zColSeq==0 ) zColSeq = "binary"; in idxGetTableInfo()
13526 pNew = 0; in idxGetTableInfo()
13527 }else if( ALWAYS(pNew!=0) ){ in idxGetTableInfo()
13529 if( ALWAYS(pNew->zName!=0) ) memcpy(pNew->zName, zTab, nTab+1); in idxGetTableInfo()
13547 char *zAppend = 0; in idxAppendText()
13548 char *zRet = 0; in idxAppendText()
13549 int nIn = zIn ? STRLEN(zIn) : 0; in idxAppendText()
13550 int nAppend = 0; in idxAppendText()
13563 zRet = 0; in idxAppendText()
13583 for(i=0; zId[i]; i++){ in idxIdentifierRequiresQuotes()
13585 && !(zId[i]>='0' && zId[i]<='9') in idxIdentifierRequiresQuotes()
13592 return 0; in idxIdentifierRequiresQuotes()
13645 sqlite3_stmt *pIdxList = 0; in idxFindCompatible()
13647 int nEq = 0; /* Number of elements in pEq */ in idxFindCompatible()
13653 rc = idxPrintfPrepareStmt(dbm, &pIdxList, 0, "PRAGMA index_list=%Q", zTbl); in idxFindCompatible()
13657 sqlite3_stmt *pInfo = 0; in idxFindCompatible()
13659 if( zIdx==0 ) continue; in idxFindCompatible()
13662 for(pIter=pEq; pIter; pIter=pIter->pLink) pIter->bFlag = 0; in idxFindCompatible()
13664 rc = idxPrintfPrepareStmt(dbm, &pInfo, 0, "PRAGMA index_xInfo=%Q", zIdx); in idxFindCompatible()
13666 int iIdx = sqlite3_column_int(pInfo, 0); in idxFindCompatible()
13678 if( pIter==0 ){ in idxFindCompatible()
13679 bMatch = 0; in idxFindCompatible()
13685 bMatch = 0; in idxFindCompatible()
13702 return 0; in idxFindCompatible()
13707 * if that leading column is not exactly '0'.
13712 if( nc>0 && (azResults[0][0]!='0' || azResults[0][1]!=0) ){ in countNonzeros()
13715 return 0; in countNonzeros()
13726 if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){ in idxCreateFromCons()
13728 char *zCols = 0; in idxCreateFromCons()
13729 char *zIdx = 0; in idxCreateFromCons()
13731 unsigned int h = 0; in idxCreateFromCons()
13745 char *zName = 0; /* Index name */ in idxCreateFromCons()
13746 int collisions = 0; in idxCreateFromCons()
13750 for(i=0; zCols[i]; i++){ in idxCreateFromCons()
13755 if( zName==0 ) break; in idxCreateFromCons()
13760 i = 0; in idxCreateFromCons()
13761 rc = sqlite3_exec(dbm, zFind, countNonzeros, &i, 0); in idxCreateFromCons()
13764 if( i==0 ){ in idxCreateFromCons()
13765 collisions = 0; in idxCreateFromCons()
13769 }while( collisions<50 && zName!=0 ); in idxCreateFromCons()
13773 }else if( zName==0 ){ in idxCreateFromCons()
13785 rc = sqlite3_exec(dbm, zIdx, 0, 0, p->pzErrmsg); in idxCreateFromCons()
13811 return 0; in idxFindConstraint()
13819 IdxConstraint *p1 = 0; in idxCreateFromWhere()
13837 if( pTail==0 ){ in idxCreateFromWhere()
13839 assert( pCon->pLink==0 ); in idxCreateFromWhere()
13858 rc = idxCreateFromWhere(p, pIter, 0); in idxCreateCandidates()
13955 sqlite3_stmt *pExplain = 0; in idxFindIndexes()
13961 /* int iId = sqlite3_column_int(pExplain, 0); */ in idxFindIndexes()
13971 for(i=0; i<nDetail; i++){ in idxFindIndexes()
13972 const char *zIdx = 0; in idxFindIndexes()
13973 if( i+13<nDetail && memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){ in idxFindIndexes()
13976 && memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0 in idxFindIndexes()
13982 int nIdx = 0; in idxFindIndexes()
13983 while( zIdx[nIdx]!='\0' && (zIdx[nIdx]!=' ' || zIdx[nIdx+1]!='(') ){ in idxFindIndexes()
13988 idxHashAdd(&rc, &hIdx, zSql, 0); in idxFindIndexes()
13995 if( zDetail[0]!='-' ){ in idxFindIndexes()
14024 if( sqlite3_stricmp(zDb, "main")==0 ){ in idxAuthCallback()
14028 if( 0==sqlite3_stricmp(z3, pTab->zName) ) break; in idxAuthCallback()
14035 if( pWrite==0 ){ in idxAuthCallback()
14063 sqlite3_stmt *pSelect = 0; in idxProcessOneTrigger()
14065 char *zWrite = 0; in idxProcessOneTrigger()
14070 const char *zCreate = (const char*)sqlite3_column_text(pSelect, 0); in idxProcessOneTrigger()
14071 if( zCreate==0 ) continue; in idxProcessOneTrigger()
14072 rc = sqlite3_exec(p->dbv, zCreate, 0, 0, pzErr); in idxProcessOneTrigger()
14079 if( z==0 ){ in idxProcessOneTrigger()
14082 rc = sqlite3_exec(p->dbv, z, 0, 0, pzErr); in idxProcessOneTrigger()
14091 for(i=0; i<pTab->nCol; i++){ in idxProcessOneTrigger()
14092 zWrite = idxAppendText(&rc, zWrite, "%s?", i==0 ? "" : ", "); in idxProcessOneTrigger()
14100 for(i=0; i<pTab->nCol; i++){ in idxProcessOneTrigger()
14101 zWrite = idxAppendText(&rc, zWrite, "%s%Q=?", i==0 ? "" : ", ", in idxProcessOneTrigger()
14111 if( zWrite==0 ) rc = SQLITE_NOMEM; in idxProcessOneTrigger()
14117 sqlite3_stmt *pX = 0; in idxProcessOneTrigger()
14118 rc = sqlite3_prepare_v2(p->dbv, zWrite, -1, &pX, 0); in idxProcessOneTrigger()
14127 rc = sqlite3_exec(p->dbv, zDrop, 0, 0, pzErr); in idxProcessOneTrigger()
14135 IdxWrite *pEnd = 0; in idxProcessTriggers()
14164 sqlite3_stmt *pSql = 0; in expertDbContainsObject()
14166 int ret = 0; in expertDbContainsObject()
14168 rc = sqlite3_prepare_v2(db, zSql, -1, &pSql, 0); in expertDbContainsObject()
14195 char *zErr = 0; in expertSchemaSql()
14197 rc = sqlite3_exec(db, zSql, 0, 0, &zErr); in expertSchemaSql()
14200 if( nErr>=15 && memcmp(zErr, "no such module:", 15)==0 ){ in expertSchemaSql()
14203 zErr = 0; in expertSchemaSql()
14213 sqlite3_stmt *pSchema = 0; in idxCreateVtabSchema()
14227 "SELECT type, name, sql, 2, 0 FROM sqlite_schema " in idxCreateVtabSchema()
14233 const char *zType = (const char*)sqlite3_column_text(pSchema, 0); in idxCreateVtabSchema()
14237 int bExists = 0; in idxCreateVtabSchema()
14239 if( zType==0 || zName==0 ) continue; in idxCreateVtabSchema()
14243 if( zType[0]=='v' || zType[1]=='r' || bVirtual ){ in idxCreateVtabSchema()
14249 if( rc==SQLITE_OK && ALWAYS(pTab!=0) ){ in idxCreateVtabSchema()
14251 char *zInner = 0; in idxCreateVtabSchema()
14252 char *zOuter = 0; in idxCreateVtabSchema()
14257 zInner = idxAppendText(&rc, 0, "CREATE TABLE x("); in idxCreateVtabSchema()
14258 for(i=0; i<pTab->nCol; i++){ in idxCreateVtabSchema()
14260 (i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl in idxCreateVtabSchema()
14266 zOuter = idxAppendText(&rc, 0, in idxCreateVtabSchema()
14270 rc = sqlite3_exec(p->dbv, zOuter, 0, 0, pzErrmsg); in idxCreateVtabSchema()
14297 assert( argc==0 ); in idxSampleFunc()
14302 if( bRet==0 ){ in idxSampleFunc()
14339 iSlot = sqlite3_value_int(argv[0]); in idxRemFunc()
14382 const void *pData = 0; in idxRemFunc()
14385 if( zNew==0 ){ in idxRemFunc()
14413 sqlite3_stmt *pMax = 0; in idxLargestIndex()
14415 *pnMax = 0; in idxLargestIndex()
14418 *pnMax = sqlite3_column_int(pMax, 0) + 1; in idxLargestIndex()
14433 char *zCols = 0; in idxPopulateOneStat1()
14434 char *zOrder = 0; in idxPopulateOneStat1()
14435 char *zQuery = 0; in idxPopulateOneStat1()
14436 int nCol = 0; in idxPopulateOneStat1()
14438 sqlite3_stmt *pQuery = 0; in idxPopulateOneStat1()
14439 int *aStat = 0; in idxPopulateOneStat1()
14442 assert( p->iSample>0 ); in idxPopulateOneStat1()
14447 const char *zComma = zCols==0 ? "" : ", "; in idxPopulateOneStat1()
14448 const char *zName = (const char*)sqlite3_column_text(pIndexXInfo, 0); in idxPopulateOneStat1()
14450 if( zName==0 ){ in idxPopulateOneStat1()
14489 char *zStat = 0; in idxPopulateOneStat1()
14490 for(i=0; i<=nCol; i++) aStat[i] = 1; in idxPopulateOneStat1()
14492 aStat[0]++; in idxPopulateOneStat1()
14493 for(i=0; i<nCol; i++){ in idxPopulateOneStat1()
14494 if( sqlite3_column_int(pQuery, i)==0 ) break; in idxPopulateOneStat1()
14502 int s0 = aStat[0]; in idxPopulateOneStat1()
14504 if( zStat==0 ) rc = SQLITE_NOMEM; in idxPopulateOneStat1()
14520 assert( pEntry->zVal2==0 ); in idxPopulateOneStat1()
14536 rc = sqlite3_exec(p->dbv,"DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0); in idxBuildSampleTable()
14542 if( zSql==0 ) return SQLITE_NOMEM; in idxBuildSampleTable()
14543 rc = sqlite3_exec(p->dbv, zSql, 0, 0, 0); in idxBuildSampleTable()
14558 int nMax =0; in idxPopulateStat1()
14559 struct IdxRemCtx *pCtx = 0; in idxPopulateStat1()
14563 sqlite3_stmt *pAllIndex = 0; in idxPopulateStat1()
14564 sqlite3_stmt *pIndexXInfo = 0; in idxPopulateStat1()
14565 sqlite3_stmt *pWrite = 0; in idxPopulateStat1()
14576 /* If iSample==0, no sqlite_stat1 data is required. */ in idxPopulateStat1()
14577 if( p->iSample==0 ) return SQLITE_OK; in idxPopulateStat1()
14580 if( nMax<=0 || rc!=SQLITE_OK ) return rc; in idxPopulateStat1()
14582 rc = sqlite3_exec(p->dbm, "ANALYZE; PRAGMA writable_schema=1", 0, 0, 0); in idxPopulateStat1()
14592 2, SQLITE_UTF8, (void*)pCtx, idxRemFunc, 0, 0 in idxPopulateStat1()
14597 0, SQLITE_UTF8, (void*)&samplectx, idxSampleFunc, 0, 0 in idxPopulateStat1()
14613 i64 iRowid = sqlite3_column_int64(pAllIndex, 0); in idxPopulateStat1()
14616 if( zTab==0 || zIdx==0 ) continue; in idxPopulateStat1()
14630 "DROP TABLE IF EXISTS temp." UNIQUE_TABLE_NAME, 0,0,0 in idxPopulateStat1()
14639 for(i=0; i<pCtx->nSlot; i++){ in idxPopulateStat1()
14646 rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_schema", 0, 0, 0); in idxPopulateStat1()
14649 sqlite3_create_function(p->db, "sqlite_expert_rem", 2, SQLITE_UTF8, 0,0,0,0); in idxPopulateStat1()
14650 sqlite3_create_function(p->db, "sqlite_expert_sample", 0,SQLITE_UTF8,0,0,0,0); in idxPopulateStat1()
14652 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0); in idxPopulateStat1()
14666 assert(0); /* VDBE should never be run. */ in dummyCompare()
14667 return 0; in dummyCompare()
14672 sqlite3_create_collation_v2(db, zName, etr, 0, dummyCompare, 0); in useDummyCS()
14684 assert(0); /* VDBE should never be run. */ in dummyUDF()
14688 assert(0); /* VDBE should never be run. */ in dummyUDFvalue()
14699 "WHERE builtin==0", -1, &pStmt, 0); in registerUDFs()
14704 const char *name = (char*)sqlite3_column_text(pStmt,0); in registerUDFs()
14707 if( name==0 || type==0 || enc==0 ){ in registerUDFs()
14712 if( strcmp(enc,"utf16le")==0 ) ienc = SQLITE_UTF16LE; in registerUDFs()
14713 else if( strcmp(enc,"utf16be")==0 ) ienc = SQLITE_UTF16BE; in registerUDFs()
14715 if( strcmp(type,"w")==0 ){ in registerUDFs()
14716 rcf = sqlite3_create_window_function(dbDst,name,nargs,ienc,0, in registerUDFs()
14717 dummyUDF,dummyUDFvalue,0,0,0); in registerUDFs()
14718 }else if( strcmp(type,"a")==0 ){ in registerUDFs()
14719 rcf = sqlite3_create_function(dbDst,name,nargs,ienc,0, in registerUDFs()
14720 0,dummyUDF,dummyUDFvalue); in registerUDFs()
14721 }else if( strcmp(type,"s")==0 ){ in registerUDFs()
14722 rcf = sqlite3_create_function(dbDst,name,nargs,ienc,0, in registerUDFs()
14723 dummyUDF,0,0); in registerUDFs()
14761 sqlite3_db_config(pNew->dbm, SQLITE_DBCONFIG_TRIGGER_EQP, 1, (int*)0); in sqlite3_expert_new()
14766 if( rc==SQLITE_OK ) rc = sqlite3_collation_needed(pNew->dbm,0,useDummyCS); in sqlite3_expert_new()
14767 if( rc==SQLITE_OK ) rc = sqlite3_collation_needed(pNew->dbv,0,useDummyCS); in sqlite3_expert_new()
14782 sqlite3_stmt *pSql = 0; in sqlite3_expert_new()
14789 const char *zSql = (const char*)sqlite3_column_text(pSql, 0); in sqlite3_expert_new()
14791 int bExists = 0; in sqlite3_expert_new()
14793 if( rc==SQLITE_OK && zSql && bExists==0 ){ in sqlite3_expert_new()
14814 pNew = 0; in sqlite3_expert_new()
14829 if( iVal<0 ) iVal = 0; in sqlite3_expert_config()
14858 while( rc==SQLITE_OK && zStmt && zStmt[0] ){ in sqlite3_expert_sql()
14859 sqlite3_stmt *pStmt = 0; in sqlite3_expert_sql()
14941 int nRet = 0; in sqlite3_expert_count()
14950 const char *zRet = 0; in sqlite3_expert_report()
14953 if( p->bRun==0 ) return 0; in sqlite3_expert_report()
14979 idxScanFree(p->pScan, 0); in sqlite3_expert_destroy()
14980 idxStatementFree(p->pStatement, 0); in sqlite3_expert_destroy()
15030 ** sqlite3_intck *p = 0;
15243 sqlite3_stmt *pRet = 0; in intckPrepare()
15245 p->rc = sqlite3_prepare_v2(p->db, zSql, -1, &pRet, 0); in intckPrepare()
15248 assert( pRet==0 ); in intckPrepare()
15265 sqlite3_stmt *pRet = 0; in intckPrepareFmt()
15267 char *zSql = 0; in intckPrepareFmt()
15270 if( p->rc==SQLITE_OK && zSql==0 ){ in intckPrepareFmt()
15306 sqlite3_stmt *pStmt = 0; in intckExec()
15318 char *zRet = 0; in intckMprintf()
15322 if( zRet==0 ){ in intckMprintf()
15327 zRet = 0; in intckMprintf()
15339 char *zSql = 0; in intckSaveKey()
15340 sqlite3_stmt *pStmt = 0; in intckSaveKey()
15341 sqlite3_stmt *pXinfo = 0; in intckSaveKey()
15342 const char *zDir = 0; in intckSaveKey()
15345 assert( p->zKey==0 ); in intckSaveKey()
15354 zDir = (const char*)sqlite3_column_text(pXinfo, 0); in intckSaveKey()
15357 if( zDir==0 ){ in intckSaveKey()
15361 for(ii=0; ii<p->nKeyVal; ii++){ in intckSaveKey()
15370 for(ii=p->nKeyVal; ii>0; ii--){ in intckSaveKey()
15374 char *zLhs = 0; in intckSaveKey()
15375 char *zRhs = 0; in intckSaveKey()
15376 char *zWhere = 0; in intckSaveKey()
15390 for(jj=0; jj<ii-1; jj++){ in intckSaveKey()
15406 (zSql==0 ? "VALUES" : ",\n "), in intckSaveKey()
15419 for(ii=0; ii<p->nKeyVal; ii++){ in intckSaveKey()
15423 p->zKey = intckMprintf(p,"%s",(const char*)sqlite3_column_text(pStmt, 0)); in intckSaveKey()
15438 sqlite3_stmt *pStmt = 0; in intckFindObject()
15440 p->zObj = 0; in intckFindObject()
15443 assert( p->pCheck==0 ); in intckFindObject()
15461 p->zObj = intckMprintf(p,"%s",(const char*)sqlite3_column_text(pStmt, 0)); in intckFindObject()
15469 p->zKey = 0; in intckFindObject()
15484 char c = z[0]; in intckGetToken()
15517 ** clause (if iCol<0) or the iCol'th column of the index.
15519 ** If (iCol<0), the identified fragment does not include the "WHERE" keyword,
15520 ** only the expression that follows it. If (iCol>=0) then the identified
15525 ** clause, NULL is returned and (*pnByte) is set to 0. Otherwise, a pointer to
15530 int iOff = 0; in intckParseCreateIndex()
15531 int iThisCol = 0; in intckParseCreateIndex()
15532 int iStart = 0; in intckParseCreateIndex()
15533 int nOpen = 0; in intckParseCreateIndex()
15535 const char *zRet = 0; in intckParseCreateIndex()
15536 int nRet = 0; in intckParseCreateIndex()
15538 int iEndOfCol = 0; in intckParseCreateIndex()
15543 if( z[iOff]=='\0' ) return 0; in intckParseCreateIndex()
15552 int nToken = 0; in intckParseCreateIndex()
15574 if( (nToken==3 && 0==sqlite3_strnicmp(zToken, "ASC", nToken)) in intckParseCreateIndex()
15575 || (nToken==4 && 0==sqlite3_strnicmp(zToken, "DESC", nToken)) in intckParseCreateIndex()
15578 }else if( 0==intckIsSpace(zToken[0]) ){ in intckParseCreateIndex()
15579 iEndOfCol = 0; in intckParseCreateIndex()
15587 while( zRet==0 && z[iOff] ){ in intckParseCreateIndex()
15589 if( n==5 && 0==sqlite3_strnicmp(&z[iOff], "where", 5) ){ in intckParseCreateIndex()
15598 while( intckIsSpace(zRet[0]) ){ in intckParseCreateIndex()
15602 while( nRet>0 && intckIsSpace(zRet[nRet-1]) ) nRet--; in intckParseCreateIndex()
15619 const char *zSql = (const char*)sqlite3_value_text(apVal[0]); in intckParseCreateIndexFunc()
15621 const char *zRes = 0; in intckParseCreateIndexFunc()
15622 int nRes = 0; in intckParseCreateIndexFunc()
15636 int bRet = 0; in intckGetAutoIndex()
15637 sqlite3_stmt *pStmt = 0; in intckGetAutoIndex()
15640 bRet = sqlite3_column_int(pStmt, 0); in intckGetAutoIndex()
15650 int bRet = 0; in intckIsIndex()
15651 sqlite3_stmt *pStmt = 0; in intckIsIndex()
15679 char *zRet = 0; in intckCheckObjectSql()
15680 sqlite3_stmt *pStmt = 0; in intckCheckObjectSql()
15681 int bAutoIndex = 0; in intckCheckObjectSql()
15682 int bIsIndex = 0; in intckCheckObjectSql()
15718 " SELECT '', 1, '_rowid_', '_rowid_', 'r1' FROM without_rowid WHERE b=0" in intckCheckObjectSql()
15764 " WHERE i.idx_ispk==0 " in intckCheckObjectSql()
15793 if( bAutoIndex ) intckExec(p, "PRAGMA automatic_index = 0"); in intckCheckObjectSql()
15875 " SELECT 0, 'n.ii=0', 'NULL'" in intckCheckObjectSql()
15932 zRet = intckMprintf(p, "%s", (const char*)sqlite3_column_text(pStmt, 0)); in intckCheckObjectSql()
15951 sqlite3_intck *pNew = 0; in sqlite3_intck_open()
15957 if( pNew==0 ){ in sqlite3_intck_open()
15960 memset(pNew, 0, sizeof(*pNew)); in sqlite3_intck_open()
15965 2, SQLITE_UTF8, 0, intckParseCreateIndexFunc, 0, 0 in sqlite3_intck_open()
15969 pNew = 0; in sqlite3_intck_open()
15984 p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0 in sqlite3_intck_close()
16003 p->zMessage = 0; in sqlite3_intck_step()
16009 if( p->pCheck==0 ){ in sqlite3_intck_step()
16013 char *zSql = 0; in sqlite3_intck_step()
16018 p->zKey = 0; in sqlite3_intck_step()
16037 p->pCheck = 0; in sqlite3_intck_step()
16038 p->nKeyVal = 0; in sqlite3_intck_step()
16057 assert( p->pCheck==0 || p->zMessage==0 ); in sqlite3_intck_message()
16062 return (const char*)sqlite3_column_text(p->pCheck, 0); in sqlite3_intck_message()
16064 return 0; in sqlite3_intck_message()
16081 assert( p->zKey==0 && p->nKeyVal>0 ); in sqlite3_intck_unlock()
16084 p->pCheck = 0; in sqlite3_intck_unlock()
16096 p->zTestSql = intckCheckObjectSql(p, zObj, 0, 0); in sqlite3_intck_test_sql()
16099 p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey, 0); in sqlite3_intck_test_sql()
16102 p->zTestSql = 0; in sqlite3_intck_test_sql()
16162 if( p==0 ){ in stmtrandFunc()
16165 if( p==0 ){ in stmtrandFunc()
16170 seed = (unsigned int)sqlite3_value_int(argv[0]); in stmtrandFunc()
16172 seed = 0; in stmtrandFunc()
16178 if( p==0 ){ in stmtrandFunc()
16183 p->x = (p->x>>1) ^ ((1+~(p->x&1)) & 0xd0000001); in stmtrandFunc()
16185 sqlite3_result_int(context, (int)((p->x ^ p->y)&0x7fffffff)); in stmtrandFunc()
16199 rc = sqlite3_create_function(db, "stmtrand", 1, SQLITE_UTF8, 0, in sqlite3_stmtrand_init()
16200 stmtrandFunc, 0, 0); in sqlite3_stmtrand_init()
16202 rc = sqlite3_create_function(db, "stmtrand", 0, SQLITE_UTF8, 0, in sqlite3_stmtrand_init()
16203 stmtrandFunc, 0, 0); in sqlite3_stmtrand_init()
16287 ** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE \
16294 ** use threads so we added -DSQLITE_THREADSAFE=0 just to make the code
16310 ** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_VFSTRACE \
16372 #define VTR_CLOSE 0x00000001
16373 #define VTR_READ 0x00000002
16374 #define VTR_WRITE 0x00000004
16375 #define VTR_TRUNC 0x00000008
16376 #define VTR_SYNC 0x00000010
16377 #define VTR_FSIZE 0x00000020
16378 #define VTR_LOCK 0x00000040
16379 #define VTR_UNLOCK 0x00000080
16380 #define VTR_CRL 0x00000100
16381 #define VTR_FCTRL 0x00000200
16382 #define VTR_SECSZ 0x00000400
16383 #define VTR_DEVCHAR 0x00000800
16384 #define VTR_SHMLOCK 0x00001000
16385 #define VTR_SHMMAP 0x00002000
16386 #define VTR_SHMBAR 0x00004000
16387 #define VTR_SHMUNMAP 0x00008000
16388 #define VTR_OPEN 0x00010000
16389 #define VTR_DELETE 0x00020000
16390 #define VTR_ACCESS 0x00040000
16391 #define VTR_FULLPATH 0x00080000
16392 #define VTR_DLOPEN 0x00100000
16393 #define VTR_DLERR 0x00200000
16394 #define VTR_DLSYM 0x00400000
16395 #define VTR_DLCLOSE 0x00800000
16396 #define VTR_RAND 0x01000000
16397 #define VTR_SLEEP 0x02000000
16398 #define VTR_CURTIME 0x04000000
16399 #define VTR_LASTERR 0x08000000
16400 #define VTR_FETCH 0x10000000 /* Also coverse xUnfetch */
16450 if( z==0 ) return 0; in fileTail()
16452 while( i>0 && z[i-1]!='/' ){ i--; } in fileTail()
16479 const char *zVal = 0; in vfstrace_errcode_name()
16549 if( zVal==0 ){ in vfstrace_print_errcode()
16550 zVal = vfstrace_errcode_name(rc&0xff); in vfstrace_print_errcode()
16552 sqlite3_snprintf(sizeof(zBuf), zBuf, "%s | 0x%x", zVal, rc&0xffff00); in vfstrace_print_errcode()
16554 sqlite3_snprintf(sizeof(zBuf), zBuf, "%d (0x%x)", rc, rc); in vfstrace_print_errcode()
16566 while( zAppend[0] ){ z[i++] = *(zAppend++); } in strappend()
16567 z[i] = 0; in strappend()
16575 pInfo->bOn = (pInfo->mTrace & mMask)!=0; in vfstraceOnOff()
16591 p->base.pMethods = 0; in vfstraceClose()
16660 memcpy(zBuf, "|0", 3); in vfstraceSync()
16661 i = 0; in vfstraceSync()
16666 sqlite3_snprintf(sizeof(zBuf)-i, &zBuf[i], "|0x%x", flags); in vfstraceSync()
16698 if( eLock<0 || eLock>=(int)(sizeof(azLockNames)/sizeof(azLockNames[0])) ){ in lockName()
16761 char *zRVal = 0; in vfstraceFileControl()
16791 if( a[1] && strcmp(a[1],"vfstrace")==0 && a[2] ){ in vfstraceFileControl()
16793 if( zArg[0]>='0' && zArg[0]<='9' ){ in vfstraceFileControl()
16794 pInfo->mTrace = (sqlite3_uint64)strtoll(a[2], 0, 0); in vfstraceFileControl()
16800 { "all", 0xffffffff }, in vfstraceFileControl()
16833 while( zArg[0] ){ in vfstraceFileControl()
16835 while( zArg[0]!=0 && zArg[0]!='-' && zArg[0]!='+' in vfstraceFileControl()
16836 && !isalpha(zArg[0]) ) zArg++; in vfstraceFileControl()
16837 if( zArg[0]==0 ) break; in vfstraceFileControl()
16838 if( zArg[0]=='-' ){ in vfstraceFileControl()
16839 onOff = 0; in vfstraceFileControl()
16841 }else if( zArg[0]=='+' ){ in vfstraceFileControl()
16845 while( !isalpha(zArg[0]) ){ in vfstraceFileControl()
16846 if( zArg[0]==0 ) break; in vfstraceFileControl()
16849 if( zArg[0]=='x' && isalpha(zArg[1]) ) zArg++; in vfstraceFileControl()
16850 for(n=0; isalpha(zArg[n]); n++){} in vfstraceFileControl()
16851 for(jj=0; jj<(int)(sizeof(aKw)/sizeof(aKw[0])); jj++){ in vfstraceFileControl()
16852 if( sqlite3_strnicmp(aKw[jj].z,(const char*)zArg,n)==0 ){ in vfstraceFileControl()
16908 case 0xca093fa0: zOp = "DB_UNCHANGED"; break; in vfstraceFileControl()
16978 vfstrace_printf(pInfo, " -> 0x%08x\n", rc); in vfstraceDeviceCharacteristics()
17000 int i = 0; in vfstraceShmLock()
17002 memcpy(zLck, "|0", 3); in vfstraceShmLock()
17007 if( flags & ~(0xf) ){ in vfstraceShmLock()
17008 sqlite3_snprintf(sizeof(zLck)-i, &zLck[i], "|0x%x", flags); in vfstraceShmLock()
17010 if( ofst>=0 && ofst<(int)(sizeof(azLockName)/sizeof(azLockName[0])) ){ in vfstraceShmLock()
17101 vfstrace_printf(pInfo, "%s.xOpen(%s,flags=0x%x)", in vfstraceOpen()
17106 memset(pNew, 0, sizeof(*pNew)); in vfstraceOpen()
17121 pNew->xShmMap = pSub->xShmMap ? vfstraceShmMap : 0; in vfstraceOpen()
17122 pNew->xShmLock = pSub->xShmLock ? vfstraceShmLock : 0; in vfstraceOpen()
17123 pNew->xShmBarrier = pSub->xShmBarrier ? vfstraceShmBarrier : 0; in vfstraceOpen()
17124 pNew->xShmUnmap = pSub->xShmUnmap ? vfstraceShmUnmap : 0; in vfstraceOpen()
17127 pNew->xFetch = pSub->xFetch ? vfstraceFetch : 0; in vfstraceOpen()
17128 pNew->xUnfetch = pSub->xUnfetch ? vfstraceUnfetch : 0; in vfstraceOpen()
17134 vfstrace_printf(pInfo, ", outFlags=0x%x\n", *pOutFlags); in vfstraceOpen()
17306 if( nErr ) zErr[0] = 0; in vfstraceGetLastError()
17361 if( pRoot==0 ) return SQLITE_NOTFOUND; in vfstrace_register()
17365 if( pNew==0 ) return SQLITE_NOMEM; in vfstrace_register()
17366 memset(pNew, 0, nByte); in vfstrace_register()
17378 pNew->xDlOpen = pRoot->xDlOpen==0 ? 0 : vfstraceDlOpen; in vfstrace_register()
17379 pNew->xDlError = pRoot->xDlError==0 ? 0 : vfstraceDlError; in vfstrace_register()
17380 pNew->xDlSym = pRoot->xDlSym==0 ? 0 : vfstraceDlSym; in vfstrace_register()
17381 pNew->xDlClose = pRoot->xDlClose==0 ? 0 : vfstraceDlClose; in vfstrace_register()
17385 pNew->xGetLastError = pRoot->xGetLastError==0 ? 0 : vfstraceGetLastError; in vfstrace_register()
17387 pNew->xCurrentTimeInt64 = pRoot->xCurrentTimeInt64==0 ? 0 : in vfstrace_register()
17390 pNew->xSetSystemCall = pRoot->xSetSystemCall==0 ? 0 : in vfstrace_register()
17392 pNew->xGetSystemCall = pRoot->xGetSystemCall==0 ? 0 : in vfstrace_register()
17394 pNew->xNextSystemCall = pRoot->xNextSystemCall==0 ? 0 : in vfstrace_register()
17403 pInfo->mTrace = 0xffffffff; in vfstrace_register()
17416 if( pVfs==0 ) return; in vfstrace_unregister()
17427 #define SQLITE_SHELL_HAVE_RECOVER 0
17580 ** int containing value 0 or 1 cast as a (void*). If this option is set
17587 ** value is 0 (clear).
17591 ** int containing value 0 or 1 cast as a (void*). If this option is set
17599 ** int containing value 0 or 1 cast as a (void*). If this option is clear
17600 ** (argument is 0), then when creating an output database, the recover
17612 ** The default option value is 0.
17718 ** a b-tree page, or if it is a b-tree page containing 0 entries, the
17734 ** (2, 0, -1, 5 ),
17735 ** (2, 0, 0, 'v' ),
17736 ** (2, 0, 1, 'five'),
17738 ** (2, 1, 0, 'x' ),
17819 #define DBDATA_COLUMN_PGNO 0
17834 #define DBPTR_COLUMN_PGNO 0
17854 if( aNew==0 ) return SQLITE_NOMEM; in dbdataBufferSize()
17866 memset(pBuf, 0, sizeof(*pBuf)); in dbdataBufferFree()
17870 ** Connect to an sqlite_dbdata (pAux==0) or sqlite_dbptr (pAux!=0) virtual
17880 DbdataTable *pTab = 0; in dbdataConnect()
17889 if( pTab==0 ){ in dbdataConnect()
17892 memset(pTab, 0, sizeof(DbdataTable)); in dbdataConnect()
17894 pTab->bPtr = (pAux!=0); in dbdataConnect()
17920 ** If neither are present, idxNum is set to 0. If schema=? is present,
17921 ** the 0x01 bit in idxNum is set. If pgno=? is present, the 0x02 bit
17924 ** If both parameters are present, schema is in position 0 and pgno in
17934 for(i=0; i<pIdx->nConstraint; i++){ in dbdataBestIndex()
17938 if( p->usable==0 ) return SQLITE_CONSTRAINT; in dbdataBestIndex()
17947 if( iSchema>=0 ){ in dbdataBestIndex()
17951 if( iPgno>=0 ){ in dbdataBestIndex()
17952 pIdx->aConstraintUsage[iPgno].argvIndex = 1 + (iSchema>=0); in dbdataBestIndex()
17957 if( pTab->bPtr==0 && pIdx->nOrderBy && pIdx->aOrderBy[0].desc==0 ){ in dbdataBestIndex()
17958 int iCol = pIdx->aOrderBy[0].iColumn; in dbdataBestIndex()
17960 pIdx->orderByConsumed = (iCol==0 || iCol==1); in dbdataBestIndex()
17961 }else if( pIdx->nOrderBy==2 && pIdx->aOrderBy[1].desc==0 && iCol==0 ){ in dbdataBestIndex()
17970 pIdx->idxNum = (iSchema>=0 ? 0x01 : 0x00) | (iPgno>=0 ? 0x02 : 0x00); in dbdataBestIndex()
17981 if( pCsr==0 ){ in dbdataOpen()
17984 memset(pCsr, 0, sizeof(DbdataCursor)); in dbdataOpen()
17998 if( pTab->pStmt==0 ){ in dbdataResetCursor()
18003 pCsr->pStmt = 0; in dbdataResetCursor()
18005 pCsr->iCell = 0; in dbdataResetCursor()
18006 pCsr->iField = 0; in dbdataResetCursor()
18007 pCsr->bOnePage = 0; in dbdataResetCursor()
18010 pCsr->aPage = 0; in dbdataResetCursor()
18011 pCsr->nRec = 0; in dbdataResetCursor()
18028 return (a[0]<<8)|a[1]; in get_uint16()
18031 return ((u32)a[0]<<24) in get_uint32()
18044 ** Or, if an error occurs, set both (*ppPage) and (*pnPage) to 0 and
18057 *ppPage = 0; in dbdataLoadPage()
18058 *pnPage = 0; in dbdataLoadPage()
18059 if( pgno>0 ){ in dbdataLoadPage()
18062 int nCopy = sqlite3_column_bytes(pStmt, 0); in dbdataLoadPage()
18063 if( nCopy>0 ){ in dbdataLoadPage()
18066 if( pPage==0 ){ in dbdataLoadPage()
18069 const u8 *pCopy = sqlite3_column_blob(pStmt, 0); in dbdataLoadPage()
18071 memset(&pPage[nCopy], 0, DBDATA_PADDING_BYTES); in dbdataLoadPage()
18088 sqlite3_uint64 u = 0; in dbdataGetVarint()
18090 for(i=0; i<8; i++){ in dbdataGetVarint()
18091 u = (u<<7) + (z[i]&0x7f); in dbdataGetVarint()
18092 if( (z[i]&0x80)==0 ){ *pVal = (sqlite3_int64)u; return i+1; } in dbdataGetVarint()
18094 u = (u<<8) + (z[i]&0xff); in dbdataGetVarint()
18100 ** Like dbdataGetVarint(), but set the output to 0 if it is less than 0
18101 ** or greater than 0xFFFFFFFF. This can be used for all varints in an
18107 if( val<0 || val>0xFFFFFFFF ) val = 0; in dbdataGetVarintU32()
18118 case 0: case 8: case 9: in dbdataValueBytes()
18120 return 0; in dbdataValueBytes()
18135 if( eType>0 ){ in dbdataValueBytes()
18138 return 0; in dbdataValueBytes()
18153 if( eType>=0 ){ in dbdataValue()
18156 case 0: in dbdataValue()
18163 sqlite3_result_int(pCtx, 0); in dbdataValue()
18170 sqlite3_uint64 v = (signed char)pData[0]; in dbdataValue()
18174 case 6: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2; in dbdataValue()
18175 case 5: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2; in dbdataValue()
18176 case 4: v = (v<<8) + pData[0]; pData++; in dbdataValue()
18177 case 3: v = (v<<8) + pData[0]; pData++; in dbdataValue()
18178 case 2: v = (v<<8) + pData[0]; pData++; in dbdataValue()
18216 sqlite3_result_int(pCtx, 0); in dbdataValue()
18218 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC); in dbdataValue()
18220 sqlite3_result_blob(pCtx, "", 0, SQLITE_STATIC); in dbdataValue()
18245 int iOff = (pCsr->iPgno==1 ? 100 : 0); in dbdataNext()
18246 int bNextPage = 0; in dbdataNext()
18248 if( pCsr->aPage==0 ){ in dbdataNext()
18250 if( pCsr->bOnePage==0 && pCsr->iPgno>pCsr->szDb ) return SQLITE_OK; in dbdataNext()
18255 pCsr->aPage = 0; in dbdataNext()
18261 pCsr->iCell = pTab->bPtr ? -2 : 0; in dbdataNext()
18269 if( pCsr->aPage[iOff]!=0x02 && pCsr->aPage[iOff]!=0x05 ){ in dbdataNext()
18275 pCsr->aPage = 0; in dbdataNext()
18283 assert( pCsr->rec.aBuf!=0 || pCsr->nRec==0 ); in dbdataNext()
18284 if( pCsr->nRec==0 ){ in dbdataNext()
18285 int bHasRowid = 0; in dbdataNext()
18286 int nPointer = 0; in dbdataNext()
18287 sqlite3_int64 nPayload = 0; in dbdataNext()
18288 sqlite3_int64 nHdr = 0; in dbdataNext()
18294 case 0x02: in dbdataNext()
18297 case 0x0a: in dbdataNext()
18299 case 0x0d: in dbdataNext()
18327 if( nPayload>0x7fffff00 ) nPayload &= 0x3fff; in dbdataNext()
18328 if( nPayload==0 ) nPayload = 1; in dbdataNext()
18365 assert( pCsr->rec.aBuf!=0 ); in dbdataNext()
18366 assert( nPayload!=0 ); in dbdataNext()
18376 while( nRem>0 ){ in dbdataNext()
18377 u8 *aOvfl = 0; in dbdataNext()
18378 int nOvfl = 0; in dbdataNext()
18381 assert( rc!=SQLITE_OK || aOvfl==0 || nOvfl==pCsr->nPage ); in dbdataNext()
18383 if( aOvfl==0 ) break; in dbdataNext()
18395 memset(&pCsr->rec.aBuf[nPayload], 0, DBDATA_PADDING_BYTES); in dbdataNext()
18399 if( nHdr>nPayload ) nHdr = 0; in dbdataNext()
18403 pCsr->iField = (bHasRowid ? -1 : 0); in dbdataNext()
18408 if( pCsr->iField>0 ){ in dbdataNext()
18415 int szField = 0; in dbdataNext()
18429 pCsr->aPage = 0; in dbdataNext()
18430 pCsr->nRec = 0; in dbdataNext()
18434 if( pCsr->iField<0 || pCsr->pHdrPtr<&pCsr->rec.aBuf[pCsr->nHdr] ){ in dbdataNext()
18440 pCsr->nRec = 0; in dbdataNext()
18455 return pCsr->aPage==0; in dbdataEof()
18467 return 0; in dbdataIsFunction()
18478 char *zSql = 0; in dbdataDbsize()
18480 int nFunc = 0; in dbdataDbsize()
18481 sqlite3_stmt *pStmt = 0; in dbdataDbsize()
18483 if( (nFunc = dbdataIsFunction(zSchema))>0 ){ in dbdataDbsize()
18484 zSql = sqlite3_mprintf("SELECT %.*s(0)", nFunc, zSchema); in dbdataDbsize()
18488 if( zSql==0 ) return SQLITE_NOMEM; in dbdataDbsize()
18490 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0); in dbdataDbsize()
18493 pCsr->szDb = sqlite3_column_int(pStmt, 0); in dbdataDbsize()
18507 int nPg1 = 0; in dbdataGetEncoding()
18508 u8 *aPg1 = 0; in dbdataGetEncoding()
18535 if( idxNum & 0x01 ){ in dbdataFilter()
18536 zSchema = (const char*)sqlite3_value_text(argv[0]); in dbdataFilter()
18537 if( zSchema==0 ) zSchema = ""; in dbdataFilter()
18539 if( idxNum & 0x02 ){ in dbdataFilter()
18540 pCsr->iPgno = sqlite3_value_int(argv[(idxNum & 0x01)]); in dbdataFilter()
18547 int nFunc = 0; in dbdataFilter()
18550 pTab->pStmt = 0; in dbdataFilter()
18551 }else if( (nFunc = dbdataIsFunction(zSchema))>0 ){ in dbdataFilter()
18553 if( zSql==0 ){ in dbdataFilter()
18556 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0); in dbdataFilter()
18562 &pCsr->pStmt, 0 in dbdataFilter()
18602 int iOff = pCsr->iPgno==1 ? 100 : 0; in dbdataColumn()
18603 if( pCsr->iCell<0 ){ in dbdataColumn()
18628 if( pCsr->iField<0 ){ in dbdataColumn()
18660 0, /* iVersion */ in sqlite3DbdataRegister()
18661 0, /* xCreate */ in sqlite3DbdataRegister()
18665 0, /* xDestroy */ in sqlite3DbdataRegister()
18673 0, /* xUpdate */ in sqlite3DbdataRegister()
18674 0, /* xBegin */ in sqlite3DbdataRegister()
18675 0, /* xSync */ in sqlite3DbdataRegister()
18676 0, /* xCommit */ in sqlite3DbdataRegister()
18677 0, /* xRollback */ in sqlite3DbdataRegister()
18678 0, /* xFindMethod */ in sqlite3DbdataRegister()
18679 0, /* xRename */ in sqlite3DbdataRegister()
18680 0, /* xSavepoint */ in sqlite3DbdataRegister()
18681 0, /* xRelease */ in sqlite3DbdataRegister()
18682 0, /* xRollbackTo */ in sqlite3DbdataRegister()
18683 0, /* xShadowName */ in sqlite3DbdataRegister()
18684 0 /* xIntegrity */ in sqlite3DbdataRegister()
18687 int rc = sqlite3_create_module(db, "sqlite_dbdata", &dbdata_module, 0); in sqlite3DbdataRegister()
18800 int iRowidBind; /* If >0, bind rowid to INSERT here */
18814 ** to. Or 0 if there is no such index (iff (iField<0)).
18833 #define RECOVER_EHIDDEN_NONE 0 /* Normal database column */
18857 ** (aElem[iKey/32] & (1 << (iKey%32))) ? 1 : 0
18976 #define RECOVER_STATE_INIT 0
19014 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE==0
19025 #if SQLITE_THREADSAFE+0>=1 && defined(SQLITE_DEBUG)
19038 if( zStr==0 ) return 0; in recoverStrlen()
19039 return (int)(strlen(zStr)&0x7fffffff); in recoverStrlen()
19052 void *pRet = 0; in recoverMalloc()
19053 assert( nByte>0 ); in recoverMalloc()
19057 memset(pRet, 0, nByte); in recoverMalloc()
19083 char *z = 0; in recoverError()
19136 ** iPg. Return 1 if it is set, or 0 otherwise.
19140 if( iPg<=pMap->nPg && iPg>0 ){ in recoverBitmapQuery()
19143 ret = (pMap->aElem[iElem] & (((u32)1) << iBit)) ? 1 : 0; in recoverBitmapQuery()
19171 sqlite3_stmt *pStmt = 0; in recoverPrepare()
19173 if( sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) ){ in recoverPrepare()
19196 sqlite3_stmt *pStmt = 0; in recoverPreparePrintf()
19203 if( z==0 ){ in recoverPreparePrintf()
19255 int rc = sqlite3_exec(db, zSql, 0, 0, 0); in recoverExec()
19276 if( rc ) recoverError(p, rc, 0); in recoverBindValue()
19301 if( z==0 ) p->errCode = SQLITE_NOMEM; in recoverMPrintf()
19304 z = 0; in recoverMPrintf()
19319 i64 nPg = 0; in recoverPageCount()
19321 sqlite3_stmt *pStmt = 0; in recoverPageCount()
19325 nPg = sqlite3_column_int64(pStmt, 0); in recoverPageCount()
19350 nBlob = sqlite3_value_bytes(argv[0]); in recoverReadI32()
19351 pBlob = (const unsigned char*)sqlite3_value_blob(argv[0]); in recoverReadI32()
19352 iInt = sqlite3_value_int(argv[1]) & 0xFFFF; in recoverReadI32()
19356 i64 iVal = ((i64)a[0]<<24) in recoverReadI32()
19359 + ((i64)a[3]<< 0); in recoverReadI32()
19382 i64 pgno = sqlite3_value_int64(apArg[0]); in recoverPageIsUsed()
19398 ** SELECT getpage(0); -- return number of pages in db
19407 i64 pgno = sqlite3_value_int64(apArg[0]); in recoverGetPage()
19408 sqlite3_stmt *pStmt = 0; in recoverGetPage()
19411 if( pgno==0 ){ in recoverGetPage()
19416 if( p->pGetPage==0 ){ in recoverGetPage()
19430 aPg = sqlite3_column_blob(pStmt, 0); in recoverGetPage()
19431 nPg = sqlite3_column_bytes(pStmt, 0); in recoverGetPage()
19432 if( pgno==1 && nPg==p->pgsz && 0==memcmp(p->pPage1Cache, aPg, nPg) ){ in recoverGetPage()
19459 unsigned i = 0; in recoverUnusedString()
19460 if( strstr(z, zA)==0 ) return zA; in recoverUnusedString()
19461 if( strstr(z, zB)==0 ) return zB; in recoverUnusedString()
19464 }while( strstr(z,zBuf)!=0 ); in recoverUnusedString()
19485 const char *zText = (const char*)sqlite3_value_text(argv[0]); in recoverEscapeCrlf()
19487 if( zText && zText[0]=='\'' ){ in recoverEscapeCrlf()
19488 int nText = sqlite3_value_bytes(argv[0]); in recoverEscapeCrlf()
19492 const char *zNL = 0; in recoverEscapeCrlf()
19493 const char *zCR = 0; in recoverEscapeCrlf()
19494 int nCR = 0; in recoverEscapeCrlf()
19495 int nNL = 0; in recoverEscapeCrlf()
19497 for(i=0; zText[i]; i++){ in recoverEscapeCrlf()
19498 if( zNL==0 && zText[i]=='\n' ){ in recoverEscapeCrlf()
19502 if( zCR==0 && zText[i]=='\r' ){ in recoverEscapeCrlf()
19509 int iOut = 0; in recoverEscapeCrlf()
19513 if( zOut==0 ){ in recoverEscapeCrlf()
19525 for(i=0; zText[i]; i++){ in recoverEscapeCrlf()
19555 sqlite3_result_value(context, argv[0]); in recoverEscapeCrlf()
19579 " max(CASE WHEN field=0 THEN value ELSE NULL END)," in recoverCacheSchema()
19628 /* Truncate the output database to 0 pages in size. This is done by in recoverTransferSettings()
19632 sqlite3 *db2 = 0; in recoverTransferSettings()
19639 for(ii=0; ii<(int)(sizeof(aPragma)/sizeof(aPragma[0])); ii++){ in recoverTransferSettings()
19641 sqlite3_stmt *p1 = 0; in recoverTransferSettings()
19644 const char *zArg = (const char*)sqlite3_column_text(p1, 0); in recoverTransferSettings()
19649 if( zArg==0 ){ in recoverTransferSettings()
19650 recoverError(p, SQLITE_NOMEM, 0); in recoverTransferSettings()
19699 sqlite3 *db = 0; /* New database handle */ in recoverOpenOutput()
19702 assert( p->dbOut==0 ); in recoverOpenOutput()
19704 if( sqlite3_open_v2(p->zUri, &db, flags, 0) ){ in recoverOpenOutput()
19713 p->errCode = sqlite3_dbdata_init(db, 0, 0); in recoverOpenOutput()
19717 for(ii=0; in recoverOpenOutput()
19718 p->errCode==SQLITE_OK && ii<(int)(sizeof(aFunc)/sizeof(aFunc[0])); in recoverOpenOutput()
19721 aFunc[ii].nArg, SQLITE_UTF8, (void*)p, aFunc[ii].xFunc, 0, 0 in recoverOpenOutput()
19771 RecoverTable *pNew = 0; in recoverAddTable()
19772 int nCol = 0; in recoverAddTable()
19774 int nByte = 0; in recoverAddTable()
19784 int i = 0; in recoverAddTable()
19785 int iField = 0; in recoverAddTable()
19786 char *csr = 0; in recoverAddTable()
19794 for(i=0; sqlite3_step(pStmt)==SQLITE_ROW; i++){ in recoverAddTable()
19828 int iField = sqlite3_column_int(pStmt, 0); in recoverAddTable()
19834 pNew->bIntkey = 0; in recoverAddTable()
19840 if( iPk>=0 ){ in recoverAddTable()
19869 sqlite3_stmt *pSelect = 0; in recoverWriteSchema1()
19870 sqlite3_stmt *pTblname = 0; in recoverWriteSchema1()
19894 i64 iRoot = sqlite3_column_int64(pSelect, 0); in recoverWriteSchema1()
19899 char *zFree = 0; in recoverWriteSchema1()
19904 "INSERT INTO sqlite_schema VALUES('table', %Q, %Q, 0, %Q)", in recoverWriteSchema1()
19908 rc = sqlite3_exec(p->dbOut, zSql, 0, 0, 0); in recoverWriteSchema1()
19913 const char *zTbl = (const char*)sqlite3_column_text(pTblname, 0); in recoverWriteSchema1()
19944 sqlite3_stmt *pSelect = 0; in recoverWriteSchema2()
19958 int rc = sqlite3_exec(p->dbOut, zSql, 0, 0, 0); in recoverWriteSchema2()
20011 sqlite3_stmt *pRet = 0; in recoverInsertStmt()
20014 char *zSql = 0; in recoverInsertStmt()
20015 char *zFinal = 0; in recoverInsertStmt()
20016 char *zBind = 0; in recoverInsertStmt()
20018 int bSql = p->xSql ? 1 : 0; in recoverInsertStmt()
20020 if( nField<=0 ) return 0; in recoverInsertStmt()
20038 for(ii=0; ii<nField; ii++){ in recoverInsertStmt()
20043 assert( pTab->aCol[ii].iField>=0 && pTab->aCol[ii].iBind>=1 ); in recoverInsertStmt()
20081 RecoverTable *pRet = 0; in recoverFindTable()
20099 char *zTbl = 0; in recoverLostAndFoundCreate()
20100 sqlite3_stmt *pProbe = 0; in recoverLostAndFoundCreate()
20101 int ii = 0; in recoverLostAndFoundCreate()
20106 for(ii=-1; zTbl==0 && p->errCode==SQLITE_OK && ii<1000; ii++){ in recoverLostAndFoundCreate()
20107 int bFail = 0; in recoverLostAndFoundCreate()
20108 if( ii<0 ){ in recoverLostAndFoundCreate()
20125 zTbl = 0; in recoverLostAndFoundCreate()
20131 const char *zSep = 0; in recoverLostAndFoundCreate()
20132 char *zField = 0; in recoverLostAndFoundCreate()
20133 char *zSql = 0; in recoverLostAndFoundCreate()
20136 for(ii=0; p->errCode==SQLITE_OK && ii<nField; ii++){ in recoverLostAndFoundCreate()
20168 char *zBind = 0; in recoverLostAndFoundInsert()
20169 sqlite3_stmt *pRet = 0; in recoverLostAndFoundInsert()
20171 if( p->xSql==0 ){ in recoverLostAndFoundInsert()
20172 for(ii=0; ii<nTotal; ii++){ in recoverLostAndFoundInsert()
20180 for(ii=0; ii<nTotal; ii++){ in recoverLostAndFoundInsert()
20209 if( pLaf->pFindRoot==0 ){ in recoverLostAndFoundFindRoot()
20223 *piRoot = sqlite3_column_int64(pLaf->pFindRoot, 0); in recoverLostAndFoundFindRoot()
20243 int iPrevCell = 0; in recoverLostAndFoundOnePage()
20244 i64 iRoot = 0; in recoverLostAndFoundOnePage()
20245 int bHaveRowid = 0; in recoverLostAndFoundOnePage()
20246 i64 iRowid = 0; in recoverLostAndFoundOnePage()
20247 int ii = 0; in recoverLostAndFoundOnePage()
20252 int iCell = sqlite3_column_int64(pPageData, 0); in recoverLostAndFoundOnePage()
20255 if( iPrevCell!=iCell && nVal>=0 ){ in recoverLostAndFoundOnePage()
20263 for(ii=0; ii<nVal; ii++){ in recoverLostAndFoundOnePage()
20267 recoverSqlCallback(p, (const char*)sqlite3_column_text(pInsert, 0)); in recoverLostAndFoundOnePage()
20272 for(ii=0; ii<nVal; ii++){ in recoverLostAndFoundOnePage()
20274 apVal[ii] = 0; in recoverLostAndFoundOnePage()
20277 bHaveRowid = 0; in recoverLostAndFoundOnePage()
20281 if( iCell<0 ) break; in recoverLostAndFoundOnePage()
20283 if( iField<0 ){ in recoverLostAndFoundOnePage()
20287 nVal = 0; in recoverLostAndFoundOnePage()
20291 assert( iField==nVal || (nVal==-1 && iField==0) ); in recoverLostAndFoundOnePage()
20293 if( apVal[iField]==0 ){ in recoverLostAndFoundOnePage()
20294 recoverError(p, SQLITE_NOMEM, 0); in recoverLostAndFoundOnePage()
20302 for(ii=0; ii<nVal; ii++){ in recoverLostAndFoundOnePage()
20304 apVal[ii] = 0; in recoverLostAndFoundOnePage()
20318 if( pLaf->pInsert==0 ){ in recoverLostAndFound3Step()
20324 i64 iPage = sqlite3_column_int64(pLaf->pAllPage, 0); in recoverLostAndFound3Step()
20325 if( recoverBitmapQuery(pLaf->pUsed, iPage)==0 ){ in recoverLostAndFound3Step()
20347 if( pLaf->nMaxField>0 ){ in recoverLostAndFound3Init()
20348 char *zTab = 0; /* Name of lost_and_found table */ in recoverLostAndFound3Init()
20380 RecoverTable *pTbl = 0; in recoverWriteDataInit()
20381 int nByte = 0; in recoverWriteDataInit()
20384 assert( p1->nMax==0 ); in recoverWriteDataInit()
20393 if( p1->apVal==0 ) return p->errCode; in recoverWriteDataInit()
20412 "SELECT 0, 0, 0, 0" in recoverWriteDataInit()
20425 for(ii=0; ii<p1->nVal; ii++){ in recoverWriteDataCleanup()
20432 memset(p1, 0, sizeof(*p1)); in recoverWriteDataCleanup()
20446 if( p->errCode==SQLITE_OK && p1->pTab==0 ){ in recoverWriteDataStep()
20448 i64 iRoot = sqlite3_column_int64(p1->pTbls, 0); in recoverWriteDataStep()
20452 p1->pInsert = 0; in recoverWriteDataStep()
20456 if( p1->pTab==0 ) return p->errCode; in recoverWriteDataStep()
20463 if( sqlite3_stricmp("sqlite_sequence", p1->pTab->zTab)==0 ){ in recoverWriteDataStep()
20473 p1->nVal = 0; in recoverWriteDataStep()
20474 p1->bHaveRowid = 0; in recoverWriteDataStep()
20486 i64 iPage = sqlite3_column_int64(pSel, 0); in recoverWriteDataStep()
20492 assert( bNewCell==0 || (iField==-1 || iField==0) ); in recoverWriteDataStep()
20496 int ii = 0; in recoverWriteDataStep()
20497 if( p1->nVal>=0 ){ in recoverWriteDataStep()
20498 if( p1->pInsert==0 || p1->nVal!=p1->nInsert ){ in recoverWriteDataStep()
20503 if( p1->nVal>0 ){ in recoverWriteDataStep()
20505 for(ii=0; ii<pTab->nCol; ii++){ in recoverWriteDataStep()
20508 if( iBind>0 ){ in recoverWriteDataStep()
20516 if( p->bRecoverRowid && pTab->iRowidBind>0 && p1->bHaveRowid ){ in recoverWriteDataStep()
20520 const char *z = (const char*)sqlite3_column_text(pInsert, 0); in recoverWriteDataStep()
20529 for(ii=0; ii<p1->nVal; ii++){ in recoverWriteDataStep()
20531 apVal[ii] = 0; in recoverWriteDataStep()
20534 p1->bHaveRowid = 0; in recoverWriteDataStep()
20537 if( iPage!=0 ){ in recoverWriteDataStep()
20538 if( iField<0 ){ in recoverWriteDataStep()
20541 p1->nVal = 0; in recoverWriteDataStep()
20544 assert( apVal[iField]==0 ); in recoverWriteDataStep()
20546 if( apVal[iField]==0 ){ in recoverWriteDataStep()
20547 recoverError(p, SQLITE_NOMEM, 0); in recoverWriteDataStep()
20550 }else if( pTab->nCol==0 ){ in recoverWriteDataStep()
20558 p1->pTab = 0; in recoverWriteDataStep()
20571 sqlite3_stmt *pStmt = 0; in recoverLostAndFound1Init()
20573 assert( p->laf.pUsed==0 ); in recoverLostAndFound1Init()
20584 " SELECT read_i32(getpage(1), 8) AS x WHERE x>0" in recoverLostAndFound1Init()
20586 " SELECT read_i32(getpage(trunk.pgno), 0) AS x FROM trunk WHERE x>0" in recoverLostAndFound1Init()
20594 " SELECT data, n-1, read_i32(data, 2+n) FROM freelist WHERE n>=0" in recoverLostAndFound1Init()
20599 " SELECT rootpage FROM recovery.schema WHERE rootpage>0" in recoverLostAndFound1Init()
20627 i64 iPg = sqlite3_column_int64(pLaf->pUsedPages, 0); in recoverLostAndFound1Step()
20632 pLaf->pUsedPages = 0; in recoverLostAndFound1Step()
20646 assert( p->laf.pAllAndParent==0 ); in recoverLostAndFound2Init()
20647 assert( p->laf.pMapInsert==0 ); in recoverLostAndFound2Init()
20648 assert( p->laf.pMaxField==0 ); in recoverLostAndFound2Init()
20649 assert( p->laf.nMaxField==0 ); in recoverLostAndFound2Init()
20680 if( recoverBitmapQuery(pLaf->pUsed, iChild)==0 ){ in recoverLostAndFound2Step()
20683 sqlite3_column_value(pLaf->pAllAndParent, 0) in recoverLostAndFound2Step()
20689 int nMax = sqlite3_column_int(pLaf->pMaxField, 0); in recoverLostAndFound2Step()
20696 pLaf->pAllAndParent =0; in recoverLostAndFound2Step()
20709 p->laf.pUsed = 0; in recoverLostAndFoundCleanup()
20718 p->laf.pUsedPages = 0; in recoverLostAndFoundCleanup()
20719 p->laf.pAllAndParent = 0; in recoverLostAndFoundCleanup()
20720 p->laf.pMapInsert = 0; in recoverLostAndFoundCleanup()
20721 p->laf.pMaxField = 0; in recoverLostAndFoundCleanup()
20722 p->laf.pFindRoot = 0; in recoverLostAndFoundCleanup()
20723 p->laf.pInsert = 0; in recoverLostAndFoundCleanup()
20724 p->laf.pAllPage = 0; in recoverLostAndFoundCleanup()
20725 p->laf.pPageData = 0; in recoverLostAndFoundCleanup()
20727 p->laf.apVal = 0; in recoverLostAndFoundCleanup()
20734 RecoverTable *pTab = 0; in recoverFinalCleanup()
20735 RecoverTable *pNext = 0; in recoverFinalCleanup()
20744 p->pTblList = 0; in recoverFinalCleanup()
20746 p->pGetPage = 0; in recoverFinalCleanup()
20747 sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0); in recoverFinalCleanup()
20756 p->dbOut = 0; in recoverFinalCleanup()
20764 return (((u32)a[0])<<8) + ((u32)a[1]); in recoverGetU16()
20772 return (((u32)a[0])<<24) + (((u32)a[1])<<16) + (((u32)a[2])<<8) + ((u32)a[3]); in recoverGetU32()
20780 sqlite3_uint64 u = 0; in recoverGetVarint()
20782 for(i=0; i<8; i++){ in recoverGetVarint()
20783 u = (u<<7) + (a[i]&0x7f); in recoverGetVarint()
20784 if( (a[i]&0x80)==0 ){ *pVal = (sqlite3_int64)u; return i+1; } in recoverGetVarint()
20786 u = (u<<8) + (a[i]&0xff); in recoverGetVarint()
20795 ** appear to contain a well-formed b-tree page, return 0.
20799 int nFrag = 0; in recoverIsValidPage()
20800 int nActual = 0; in recoverIsValidPage()
20801 int iFree = 0; in recoverIsValidPage()
20802 int nCell = 0; /* Number of cells on page */ in recoverIsValidPage()
20803 int iCellOff = 0; /* Offset of cell array in page */ in recoverIsValidPage()
20804 int iContent = 0; in recoverIsValidPage()
20805 int eType = 0; in recoverIsValidPage()
20806 int ii = 0; in recoverIsValidPage()
20808 eType = (int)a[0]; in recoverIsValidPage()
20809 if( eType!=0x02 && eType!=0x05 && eType!=0x0A && eType!=0x0D ) return 0; in recoverIsValidPage()
20814 if( iContent==0 ) iContent = 65536; in recoverIsValidPage()
20817 if( iContent>n ) return 0; in recoverIsValidPage()
20819 memset(aUsed, 0, n); in recoverIsValidPage()
20820 memset(aUsed, 0xFF, iContent); in recoverIsValidPage()
20823 if( iFree && iFree<=iContent ) return 0; in recoverIsValidPage()
20825 int iNext = 0; in recoverIsValidPage()
20826 int nByte = 0; in recoverIsValidPage()
20827 if( iFree>(n-4) ) return 0; in recoverIsValidPage()
20830 if( iFree+nByte>n || nByte<4 ) return 0; in recoverIsValidPage()
20831 if( iNext && iNext<iFree+nByte ) return 0; in recoverIsValidPage()
20832 memset(&aUsed[iFree], 0xFF, nByte); in recoverIsValidPage()
20837 if( eType==0x02 || eType==0x05 ){ in recoverIsValidPage()
20842 if( (iCellOff + 2*nCell)>iContent ) return 0; in recoverIsValidPage()
20843 for(ii=0; ii<nCell; ii++){ in recoverIsValidPage()
20845 i64 nPayload = 0; in recoverIsValidPage()
20846 int nByte = 0; in recoverIsValidPage()
20849 return 0; in recoverIsValidPage()
20851 if( eType==0x05 || eType==0x02 ) nByte += 4; in recoverIsValidPage()
20853 if( eType==0x0D ){ in recoverIsValidPage()
20854 i64 dummy = 0; in recoverIsValidPage()
20857 if( eType!=0x05 ){ in recoverIsValidPage()
20858 int X = (eType==0x0D) ? n-35 : (((n-12)*64/255)-23); in recoverIsValidPage()
20872 return 0; in recoverIsValidPage()
20875 if( aUsed[iByte]!=0 ){ in recoverIsValidPage()
20876 return 0; in recoverIsValidPage()
20878 aUsed[iByte] = 0xFF; in recoverIsValidPage()
20882 nActual = 0; in recoverIsValidPage()
20883 for(ii=0; ii<n; ii++){ in recoverIsValidPage()
20884 if( aUsed[ii]==0 ) nActual++; in recoverIsValidPage()
20940 a[0] = (v>>8) & 0x00FF; in recoverPutU16()
20941 a[1] = (v>>0) & 0x00FF; in recoverPutU16()
20948 a[0] = (v>>24) & 0x00FF; in recoverPutU32()
20949 a[1] = (v>>16) & 0x00FF; in recoverPutU32()
20950 a[2] = (v>>8) & 0x00FF; in recoverPutU32()
20951 a[3] = (v>>0) & 0x00FF; in recoverPutU32()
20963 ** can be found, return SQLITE_OK but leave p->detected_pgsz set to 0. Or,
20978 u32 pgsz = 0; in recoverVfsDetectPagesize()
20979 int iBlk = 0; in recoverVfsDetectPagesize()
20980 u8 *aPg = 0; in recoverVfsDetectPagesize()
20981 u8 *aTmp = 0; in recoverVfsDetectPagesize()
20982 int nBlk = 0; in recoverVfsDetectPagesize()
20985 if( aPg==0 ) return SQLITE_NOMEM; in recoverVfsDetectPagesize()
20992 for(iBlk=0; rc==SQLITE_OK && iBlk<nBlk; iBlk++){ in recoverVfsDetectPagesize()
20994 memset(aPg, 0, nMax); in recoverVfsDetectPagesize()
21000 for(iOff=0; iOff<nMax; iOff+=pgsz2){ in recoverVfsDetectPagesize()
21013 if( nReserve==0 ) break; in recoverVfsDetectPagesize()
21014 nReserve = 0; in recoverVfsDetectPagesize()
21034 if( rc==SQLITE_OK && iOff==0 && nByte>=108 ){ in recoverVfsRead()
21057 0x53, 0x51, 0x4c, 0x69, 0x74, 0x65, 0x20, 0x66, in recoverVfsRead()
21058 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x20, 0x33, 0x00, in recoverVfsRead()
21059 0xFF, 0xFF, 0x01, 0x01, 0x00, 0x40, 0x20, 0x20, in recoverVfsRead()
21060 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, in recoverVfsRead()
21061 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, in recoverVfsRead()
21062 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, in recoverVfsRead()
21063 0x00, 0x00, 0x10, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, in recoverVfsRead()
21064 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, in recoverVfsRead()
21065 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, in recoverVfsRead()
21066 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, in recoverVfsRead()
21067 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, in recoverVfsRead()
21068 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, in recoverVfsRead()
21069 0x00, 0x2e, 0x5b, 0x30, in recoverVfsRead()
21071 0x0D, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00 in recoverVfsRead()
21078 u32 dbsz = 0; in recoverVfsRead()
21079 i64 dbFileSize = 0; in recoverVfsRead()
21083 if( pgsz==0x01 ) pgsz = 65536; in recoverVfsRead()
21086 if( rc==SQLITE_OK && p->detected_pgsz==0 ){ in recoverVfsRead()
21102 p->pPage1Cache = 0; in recoverVfsRead()
21103 p->pPage1Disk = 0; in recoverVfsRead()
21118 for(ii=0; ii<(int)(sizeof(aPreserve)/sizeof(aPreserve[0])); ii++){ in recoverVfsRead()
21122 memset(&((u8*)aBuf)[sizeof(aHdr)], 0, nByte-sizeof(aHdr)); in recoverVfsRead()
21245 *pp = 0; in recoverVfsFetch()
21261 sqlite3_file *pFd = 0; in recoverInstallWrapper()
21262 assert( recover_g.pMethods==0 ); in recoverInstallWrapper()
21265 assert( pFd==0 || pFd->pMethods!=&recover_methods ); in recoverInstallWrapper()
21267 int iVersion = 1 + (pFd->pMethods->iVersion>1 && pFd->pMethods->xShmMap!=0); in recoverInstallWrapper()
21281 sqlite3_file *pFd = 0; in recoverUninstallWrapper()
21286 recover_g.pMethods = 0; in recoverUninstallWrapper()
21287 recover_g.p = 0; in recoverUninstallWrapper()
21324 sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0); in recoverStep()
21336 && SQLITE_OK==sqlite3_exec(p->dbIn, "ROLLBACK", 0, 0, 0) in recoverStep()
21348 if( p->w1.pTbls==0 ){ in recoverStep()
21363 if( p->laf.pUsed==0 ){ in recoverStep()
21372 if( p->laf.pAllAndParent==0 ){ in recoverStep()
21382 if( p->laf.pInsert==0 ){ in recoverStep()
21401 rc = sqlite3_exec(p->dbIn, "END", 0, 0, 0); in recoverStep()
21437 sqlite3_recover *pRet = 0; in recoverInit()
21438 int nDb = 0; in recoverInit()
21439 int nUri = 0; in recoverInit()
21440 int nByte = 0; in recoverInit()
21442 if( zDb==0 ){ zDb = "main"; } in recoverInit()
21450 memset(pRet, 0, nByte); in recoverInit()
21455 if( nUri>0 && zUri ) memcpy(pRet->zUri, zUri, nUri); in recoverInit()
21473 return recoverInit(db, zDb, zUri, 0, 0); in sqlite3_recover_init()
21486 return recoverInit(db, zDb, 0, xSql, pSqlCtx); in sqlite3_recover_init_sql()
21508 if( p==0 ){ in sqlite3_recover_config()
21530 p->zLostAndFound = 0; in sqlite3_recover_config()
21563 if( p==0 ) return SQLITE_NOMEM; in sqlite3_recover_step()
21592 if( p==0 ){ in sqlite3_recover_finish()
21596 if( p->bCloseTransaction && sqlite3_get_autocommit(p->dbIn)==0 ){ in sqlite3_recover_finish()
21597 rc = sqlite3_exec(p->dbIn, "END", 0, 0, 0); in sqlite3_recover_finish()
21661 #define ColModeOpts_default { 60, 0, 0 }
21662 #define ColModeOpts_default_qbox { 60, 1, 0 }
21731 OpenSession aSession[4]; /* Array of sessions. [0] is in focus. */
21757 #define AUTOEQP_off 0 /* Automatic EXPLAIN QUERY PLAN is off */
21764 #define SHELL_OPEN_UNSPEC 0 /* No open-mode specified */
21774 #define SHELL_TRACE_PLAIN 0 /* Show input SQL text */
21779 #define SHELL_PROGRESS_QUIET 0x01 /* Omit announcing every progress callback */
21780 #define SHELL_PROGRESS_RESET 0x02 /* Reset the count when the progress
21783 #define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */
21786 ** be 0, so to change the default, reorder the names.
21788 #define SHELL_ESC_ASCII 0 /* Substitute ^Y for X where Y=X+0x40 */
21797 #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
21798 #define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
21799 #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
21800 #define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
21801 #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
21802 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
21803 #define SHFLG_Echo 0x00000040 /* .echo on/off, or --echo setting */
21804 #define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
21805 #define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
21806 #define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
21807 #define SHFLG_TestingMode 0x00000400 /* allow unsafe testing features */
21812 #define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
21819 #define MODE_Line 0 /* One column per line. Blank line between records */
21829 #define MODE_Ascii 10 /* Use ASCII unit and record separators (0x1F/0x1E) */
21889 if( p->pLog==0 ) return; in shellLog()
21907 sqlite3_fprintf(p->out, "%s\n", sqlite3_value_text(apVal[0])); in shellPutsFunc()
21908 sqlite3_result_value(pCtx, apVal[0]); in shellPutsFunc()
21954 char *zTempFile = 0; in editFunc()
21956 char *zCmd = 0; in editFunc()
21959 int hasCRLF = 0; in editFunc()
21960 FILE *f = 0; in editFunc()
21963 unsigned char *p = 0; in editFunc()
21970 if( zEditor==0 ){ in editFunc()
21974 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){ in editFunc()
21979 zTempFile = 0; in editFunc()
21980 sqlite3_file_control(db, 0, SQLITE_FCNTL_TEMPFILENAME, &zTempFile); in editFunc()
21981 if( zTempFile==0 ){ in editFunc()
21982 sqlite3_uint64 r = 0; in editFunc()
21985 if( zTempFile==0 ){ in editFunc()
21990 bBin = sqlite3_value_type(argv[0])==SQLITE_BLOB; in editFunc()
21994 if( f==0 ){ in editFunc()
21998 sz = sqlite3_value_bytes(argv[0]); in editFunc()
22000 x = fwrite(sqlite3_value_blob(argv[0]), 1, (size_t)sz, f); in editFunc()
22002 const char *z = (const char*)sqlite3_value_text(argv[0]); in editFunc()
22004 if( z && strstr(z,"\r\n")!=0 ) hasCRLF = 1; in editFunc()
22005 x = fwrite(sqlite3_value_text(argv[0]), 1, (size_t)sz, f); in editFunc()
22008 f = 0; in editFunc()
22014 if( zCmd==0 ){ in editFunc()
22025 if( f==0 ){ in editFunc()
22030 fseek(f, 0, SEEK_END); in editFunc()
22034 if( p==0 ){ in editFunc()
22040 f = 0; in editFunc()
22054 p[sz] = 0; in editFunc()
22055 for(i=j=0; i<sz; i++){ in editFunc()
22060 p[sz] = 0; in editFunc()
22065 p = 0; in editFunc()
22116 for(i=0; i<nBlob; i++){ in output_hex_blob()
22118 '0', '1', '2', '3', '4', '5', '6', '7', in output_hex_blob()
22122 zStr[i*2+1] = aHex[ (aBlob[i] & 0x0F) ]; in output_hex_blob()
22124 zStr[i*2] = '\0'; in output_hex_blob()
22146 int needUnistr = 0; in output_quoted_string()
22147 int needDblQuote = 0; in output_quoted_string()
22152 if( z==0 ) return; in output_quoted_string()
22153 for(i=0; (c = z[i])!=0; i++){ in output_quoted_string()
22155 if( c>0x1f ) continue; in output_quoted_string()
22161 if( (needDblQuote==0 && needUnistr==0) in output_quoted_string()
22162 || (needDblQuote==0 && p->eEscMode==SHELL_ESC_OFF) in output_quoted_string()
22176 for(i=0; (c = z[i])!=0; i++){ in output_quoted_string()
22178 if( c>0x1f ) continue; in output_quoted_string()
22187 if( c==0 ) break; in output_quoted_string()
22228 ** With ns == ~0, is like strpbrk(s,zAny) and s must be 0-terminated.
22231 const char *pcFirst = 0; in anyOfInStr()
22232 if( ns == ~(size_t)0 ) ns = strlen(s); in anyOfInStr()
22234 const char *pc = (const char*)memchr(s, *zAny&0xff, ns); in anyOfInStr()
22246 ** no char cn such that ((1<<cn) & ccm)!=0. On return, the
22248 ** Limit: nAccept>=0 => char count, nAccept<0 => character
22251 int ng = (nAccept<0)? -nAccept : 0; in zSkipValidUtf8()
22252 const char *pcLimit = (nAccept>=0)? z+nAccept : 0; in zSkipValidUtf8()
22253 assert(z!=0); in zSkipValidUtf8()
22254 while( (pcLimit)? (z<pcLimit) : (ng-- != 0) ){ in zSkipValidUtf8()
22256 if( c<0x7f ){ in zSkipValidUtf8()
22257 if( ccm != 0L && c < 0x20 && ((1L<<c) & ccm) != 0 ) return z; in zSkipValidUtf8()
22259 }else if( (c & 0xC0) != 0xC0 ) return z; /* not a lead byte */ in zSkipValidUtf8()
22266 if( ct==0 || (zt-z)>4 || (ct & 0xC0)!=0x80 ){ in zSkipValidUtf8()
22271 } while( ((c <<= 1) & 0x40) == 0x40 ); /* Eat lead byte's count. */ in zSkipValidUtf8()
22285 static long ctrlMask = ~0L; in output_c_string()
22290 while( *z!=0 ){ in output_c_string()
22291 const char *pcDQBSRO = anyOfInStr(z, zDQBSRO, ~(size_t)0); in output_c_string()
22297 if( (c = *pcEnd)==0 ) break; in output_c_string()
22307 default: cbsSay = 0; break; in output_c_string()
22312 }else if( !isprint(c&0xff) ){ in output_c_string()
22313 sqlite3_fprintf(out, "\\%03o", c&0xff); in output_c_string()
22329 static long ctrlMask = ~0L; in output_json_string()
22335 if( z==0 ) z = ""; in output_json_string()
22336 pcLimit = z + ((n<0)? strlen(z) : (size_t)n); in output_json_string()
22357 default: cbsSay = 0; break; in output_json_string()
22362 }else if( c<=0x1f || c>=0x7f ){ in output_json_string()
22394 i64 nCtrl = 0; in escapeOutput()
22402 *ppFree = 0; in escapeOutput()
22408 for(i=0; (c = zIn[i])!=0; i++){ in escapeOutput()
22409 if( c<=0x1f in escapeOutput()
22417 if( nCtrl==0 ){ in escapeOutput()
22418 *ppFree = 0; in escapeOutput()
22424 for(i=j=0; (c = zIn[i])!=0; i++){ in escapeOutput()
22425 if( c>0x1f in escapeOutput()
22432 if( i>0 ){ in escapeOutput()
22440 zOut[j++] = 0xe2; in escapeOutput()
22441 zOut[j++] = 0x90; in escapeOutput()
22442 zOut[j++] = 0x80+c; in escapeOutput()
22446 zOut[j++] = 0x40+c; in escapeOutput()
22450 if( i>0 ){ in escapeOutput()
22454 zOut[j] = 0; in escapeOutput()
22465 if( z==0 ) z = ""; in output_html_string()
22467 for(i=0; z[i] in output_html_string()
22474 if( i>0 ){ in output_html_string()
22501 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
22502 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22503 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22504 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22505 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22506 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
22524 if( z==0 ){ in output_csv()
22528 for(i=0; z[i]; i++){ in output_csv()
22530 i = 0; in output_csv()
22534 if( i==0 || strstr(z, p->colSeparator)!=0 ){ in output_csv()
22565 interrupt_handler(0); in ConsoleCtrlHandler()
22608 for(i=0; i<ArraySize(azProhibitedFunctions); i++){ in safeModeAuth()
22609 if( sqlite3_stricmp(zA2, azProhibitedFunctions[i])==0 ){ in safeModeAuth()
22633 static const char *azAction[] = { 0, in shellAuth()
22648 az[0] = zA1; in shellAuth()
22653 for(i=0; i<4; i++){ in shellAuth()
22678 char *zToFree = 0; in printSchemaLine()
22679 if( z==0 ) return; in printSchemaLine()
22680 if( zTail==0 ) return; in printSchemaLine()
22681 if( zTail[0]==';' && (strstr(z, "/*")!=0 || strstr(z,"--")!=0) ){ in printSchemaLine()
22685 for(i=0; i<ArraySize(azTerm); i++){ in printSchemaLine()
22690 zNew[n-1] = 0; in printSchemaLine()
22698 if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){ in printSchemaLine()
22707 z[n] = 0; in printSchemaLineN()
22718 for(i=0; z[i]; i++){ in wsToEol()
22722 return 0; in wsToEol()
22733 if( zText==0 ) return; in eqp_append()
22743 pNew->pNext = 0; in eqp_append()
22762 memset(&p->sGraph, 0, sizeof(p->sGraph)); in eqp_reset()
22781 for(pRow = eqp_next_row(p, iEqpId, 0); pRow; pRow = pNext){ in eqp_render_level()
22789 p->sGraph.zPrefix[n] = 0; in eqp_render_level()
22800 if( pRow->zText[0]=='-' ){ in eqp_render()
22801 if( pRow->pNext==0 ){ in eqp_render()
22808 }else if( nCycle>0 ){ in eqp_render()
22813 p->sGraph.zPrefix[0] = 0; in eqp_render()
22814 eqp_render_level(p, 0); in eqp_render()
22826 if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){ in progress_handler()
22828 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0; in progress_handler()
22829 if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0; in progress_handler()
22832 if( (p->flgProgress & SHELL_PROGRESS_QUIET)==0 ){ in progress_handler()
22835 return 0; in progress_handler()
22861 if( nArg>0 ){ in print_row_separator()
22863 print_dashes(p->out, p->actualWidth[0]+2); in print_row_separator()
22887 if( azArg==0 ) return 0; in shell_callback()
22895 if( azArg==0 ) break; in shell_callback()
22896 for(i=0; i<nArg; i++){ in shell_callback()
22900 if( p->cnt++>0 ) sqlite3_fputs(p->rowSeparator, p->out); in shell_callback()
22901 for(i=0; i<nArg; i++){ in shell_callback()
22902 char *pFree = 0; in shell_callback()
22914 static const int aExplainMap[] = {0, 1, 2, 3, 4, 5, 6, 7 }; in shell_callback()
22916 static const int aScanExpMap[] = {0, 9, 8, 1, 2, 3, 4, 5, 6, 7 }; in shell_callback()
22932 if( p->cnt++==0 ){ in shell_callback()
22933 for(i=0; i<nArg; i++){ in shell_callback()
22937 for(i=0; i<nArg; i++){ in shell_callback()
22944 if( azArg==0 ) break; in shell_callback()
22946 for(i=0; i<nArg; i++){ in shell_callback()
22950 if( i==nArg-1 ) w = 0; in shell_callback()
22967 printSchemaLine(p->out, azArg[0], ";\n"); in shell_callback()
22973 int nParen = 0; in shell_callback()
22974 char cEnd = 0; in shell_callback()
22976 int nLine = 0; in shell_callback()
22978 int isWhere = 0; in shell_callback()
22980 if( azArg[0]==0 ) break; in shell_callback()
22981 if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0 in shell_callback()
22982 || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0 in shell_callback()
22984 sqlite3_fprintf(p->out, "%s;\n", azArg[0]); in shell_callback()
22987 isIndex = sqlite3_strlike("CREATE INDEX%", azArg[0], 0)==0 in shell_callback()
22988 || sqlite3_strlike("CREATE UNIQUE INDEX%", azArg[0], 0)==0; in shell_callback()
22989 z = sqlite3_mprintf("%s", azArg[0]); in shell_callback()
22991 j = 0; in shell_callback()
22992 for(i=0; IsSpace(z[i]); i++){} in shell_callback()
22993 for(; (c = z[i])!=0; i++){ in shell_callback()
22997 }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){ in shell_callback()
23002 while( j>0 && IsSpace(z[j-1]) ){ j--; } in shell_callback()
23003 z[j] = 0; in shell_callback()
23005 for(i=j=0; (c = z[i])!=0; i++){ /* Copy from z[i] back to z[j] */ in shell_callback()
23007 cEnd = 0; in shell_callback()
23018 if( nLine>0 && nParen==0 && j>0 && !isWhere ){ in shell_callback()
23020 j = 0; in shell_callback()
23023 && nParen==0 && isIndex in shell_callback()
23024 && sqlite3_strnicmp("WHERE",&z[i],5)==0 in shell_callback()
23028 && nParen==0 in shell_callback()
23029 && sqlite3_strnicmp("AND",&z[i],3)==0 in shell_callback()
23032 j = 0; in shell_callback()
23035 if( nParen==1 && cEnd==0 in shell_callback()
23041 j = 0; in shell_callback()
23046 z[j] = 0; in shell_callback()
23053 if( p->cnt++==0 && p->showHeader ){ in shell_callback()
23054 for(i=0; i<nArg; i++){ in shell_callback()
23063 if( azArg==0 ) break; in shell_callback()
23064 for(i=0; i<nArg; i++){ in shell_callback()
23068 if( z==0 ) z = p->nullValue; in shell_callback()
23078 if( p->cnt==0 && p->cMode==MODE_Www ){ in shell_callback()
23081 "<TABLE border='1' cellspacing='0' cellpadding='2'>\n" in shell_callback()
23085 if( p->cnt==0 && (p->showHeader || p->cMode==MODE_Www) ){ in shell_callback()
23087 for(i=0; i<nArg; i++){ in shell_callback()
23095 if( azArg==0 ) break; in shell_callback()
23097 for(i=0; i<nArg; i++){ in shell_callback()
23106 if( p->cnt++==0 && p->showHeader ){ in shell_callback()
23107 for(i=0; i<nArg; i++){ in shell_callback()
23113 if( azArg==0 ) break; in shell_callback()
23114 for(i=0; i<nArg; i++){ in shell_callback()
23123 if( p->cnt++==0 && p->showHeader ){ in shell_callback()
23124 for(i=0; i<nArg; i++){ in shell_callback()
23129 if( nArg>0 ){ in shell_callback()
23130 for(i=0; i<nArg; i++){ in shell_callback()
23139 if( azArg==0 ) break; in shell_callback()
23143 for(i=0; i<nArg; i++){ in shell_callback()
23144 if( i>0 ) sqlite3_fputs(",", p->out); in shell_callback()
23157 for(i=0; i<nArg; i++){ in shell_callback()
23158 sqlite3_fputs(i>0 ? "," : " VALUES(", p->out); in shell_callback()
23159 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ in shell_callback()
23174 if( ur==0x7ff0000000000000LL ){ in shell_callback()
23176 }else if( ur==0xfff0000000000000LL ){ in shell_callback()
23181 sqlite3_snprintf(50,z,"%lld.0", ir); in shell_callback()
23191 }else if( isNumber(azArg[i], 0) ){ in shell_callback()
23203 if( azArg==0 ) break; in shell_callback()
23204 if( p->cnt==0 ){ in shell_callback()
23210 for(i=0; i<nArg; i++){ in shell_callback()
23213 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ in shell_callback()
23220 if( ur==0x7ff0000000000000LL ){ in shell_callback()
23222 }else if( ur==0xfff0000000000000LL ){ in shell_callback()
23245 if( azArg==0 ) break; in shell_callback()
23246 if( p->cnt==0 && p->showHeader ){ in shell_callback()
23247 for(i=0; i<nArg; i++){ in shell_callback()
23248 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); in shell_callback()
23254 for(i=0; i<nArg; i++){ in shell_callback()
23255 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); in shell_callback()
23256 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ in shell_callback()
23271 }else if( isNumber(azArg[i], 0) ){ in shell_callback()
23281 if( p->cnt++==0 && p->showHeader ){ in shell_callback()
23282 for(i=0; i<nArg; i++){ in shell_callback()
23283 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); in shell_callback()
23288 if( azArg==0 ) break; in shell_callback()
23289 for(i=0; i<nArg; i++){ in shell_callback()
23290 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); in shell_callback()
23297 eqp_append(p, atoi(azArg[0]), atoi(azArg[1]), azArg[3]); in shell_callback()
23301 return 0; in shell_callback()
23321 if( azArg==0 ) return 0; in captureOutputCallback()
23322 if( p->n ) appendText(p, "|", 0); in captureOutputCallback()
23323 for(i=0; i<nArg; i++){ in captureOutputCallback()
23324 if( i ) appendText(p, ",", 0); in captureOutputCallback()
23325 if( azArg[i] ) appendText(p, azArg[i], 0); in captureOutputCallback()
23327 return 0; in captureOutputCallback()
23334 char *zErrMsg = 0; in createSelftestTable()
23362 " AND coalesce(rootpage,0)>0\n" in createSelftestTable()
23370 ,0,0,&zErrMsg); in createSelftestTable()
23375 sqlite3_exec(p->db, "RELEASE selftest_init",0,0,0); in createSelftestTable()
23391 p->zDestTable = 0; in set_table_name()
23393 if( zName==0 ) return; in set_table_name()
23399 n = 0; in set_table_name()
23401 for(i=0; zName[i]; i++){ in set_table_name()
23406 z[n] = 0; in set_table_name()
23424 if( db==0 in shell_error_context()
23425 || zSql==0 in shell_error_context()
23426 || (iOffset = sqlite3_error_offset(db))<0 in shell_error_context()
23434 while( (zSql[0]&0xc0)==0x80 ){ zSql++; iOffset--; } in shell_error_context()
23439 while( len>0 && (zSql[len]&0xc0)==0x80 ) len--; in shell_error_context()
23443 for(i=0; zCode[i]; i++){ if( IsSpace(zSql[i]) ) zCode[i] = ' '; } in shell_error_context()
23472 rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0); in run_table_dump_query()
23478 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; in run_table_dump_query()
23484 z = (const char*)sqlite3_column_text(pSelect, 0); in run_table_dump_query()
23489 if( z==0 ) z = ""; in run_table_dump_query()
23490 while( z[0] && (z[0]!='-' || z[1]!='-') ) z++; in run_table_dump_query()
23491 if( z[0] ){ in run_table_dump_query()
23502 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; in run_table_dump_query()
23518 sqlite3_str *pStr = sqlite3_str_new(0); in save_err_msg()
23542 if( in==0 ) return; in displayLinuxIoStats()
23543 while( sqlite3_fgets(z, sizeof(z), in)!=0 ){ in displayLinuxIoStats()
23557 for(i=0; i<ArraySize(aTrans); i++){ in displayLinuxIoStats()
23559 if( cli_strncmp(aTrans[i].zPattern, z, n)==0 ){ in displayLinuxIoStats()
23584 for(i=0, nPercent=0; zFormat[i]; i++){ in displayStatLine()
23606 if( pArg==0 || pArg->out==0 ) return 0; in display_stats()
23615 for(i=0; i<nCol; i++){ in display_stats()
23639 return 0; in display_stats()
23751 return 0; in display_stats()
23757 int iPid = 0; in scanStatsHeight()
23762 while( iPid!=0 ){ in scanStatsHeight()
23764 for(ii=0; 1; ii++){ in scanStatsHeight()
23790 int ii = 0; in display_explain_scanstats()
23791 i64 nTotal = 0; in display_explain_scanstats()
23792 int nWidth = 0; in display_explain_scanstats()
23795 for(ii=0; 1; ii++){ in display_explain_scanstats()
23796 const char *z = 0; in display_explain_scanstats()
23797 int n = 0; in display_explain_scanstats()
23807 for(ii=0; 1; ii++){ in display_explain_scanstats()
23808 i64 nLoop = 0; in display_explain_scanstats()
23809 i64 nRow = 0; in display_explain_scanstats()
23810 i64 nCycle = 0; in display_explain_scanstats()
23811 int iId = 0; in display_explain_scanstats()
23812 int iPid = 0; in display_explain_scanstats()
23813 const char *zo = 0; in display_explain_scanstats()
23814 const char *zName = 0; in display_explain_scanstats()
23815 char *zText = 0; in display_explain_scanstats()
23830 if( nCycle>=0 || nLoop>=0 || nRow>=0 ){ in display_explain_scanstats()
23831 char *z = 0; in display_explain_scanstats()
23832 if( nCycle>=0 && nTotal>0 ){ in display_explain_scanstats()
23837 if( nLoop>=0 ){ in display_explain_scanstats()
23840 if( nRow>=0 ){ in display_explain_scanstats()
23871 for(i=0; azArray[i]; i++){ in str_in_array()
23872 if( 0==cli_strcmp(zStr, azArray[i]) ) return 1; in str_in_array()
23874 return 0; in str_in_array()
23899 int *abYield = 0; /* True if op is an OP_Yield */ in explain_data_prepare()
23900 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */ in explain_data_prepare()
23904 "Return", 0 }; in explain_data_prepare()
23906 "Rewind", 0 }; in explain_data_prepare()
23907 const char *azGoto[] = { "Goto", 0 }; in explain_data_prepare()
23914 assert( 0==sqlite3_stricmp( sqlite3_column_name(pSql, 0), "addr" ) ); in explain_data_prepare()
23915 assert( 0==sqlite3_stricmp( sqlite3_column_name(pSql, 1), "opcode" ) ); in explain_data_prepare()
23916 assert( 0==sqlite3_stricmp( sqlite3_column_name(pSql, 2), "p1" ) ); in explain_data_prepare()
23917 assert( 0==sqlite3_stricmp( sqlite3_column_name(pSql, 3), "p2" ) ); in explain_data_prepare()
23919 for(iOp=0; SQLITE_ROW==sqlite3_step(pSql); iOp++){ in explain_data_prepare()
23921 int iAddr = sqlite3_column_int(pSql, 0); in explain_data_prepare()
23942 p->aiIndent[iOp] = 0; in explain_data_prepare()
23944 if( str_in_array(zOp, azNext) && p2op>0 ){ in explain_data_prepare()
23952 p->iIndent = 0; in explain_data_prepare()
23962 p->aiIndent = 0; in explain_data_delete()
23963 p->nIndent = 0; in explain_data_delete()
23964 p->iIndent = 0; in explain_data_delete()
23993 sqlite3_stmt *pStmt = 0; in display_scanstats()
23994 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); in display_scanstats()
23998 sqlite3_bind_pointer(pStmt, 1, pSave, "stmt-pointer", 0); in display_scanstats()
24000 pArg->cnt = 0; in display_scanstats()
24021 unsigned int zero = 0; in disable_debug_trace_modes()
24022 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 0, &savedSelectTrace); in disable_debug_trace_modes()
24034 int wrSchema = 0; in bind_table_init()
24035 int defensiveMode = 0; in bind_table_init()
24037 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0); in bind_table_init()
24039 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0); in bind_table_init()
24045 0, 0, 0); in bind_table_init()
24046 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0); in bind_table_init()
24047 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0); in bind_table_init()
24066 sqlite3_stmt *pQ = 0; in bind_prepared_stmt()
24069 if( nVar==0 ) return; /* Nothing to do */ in bind_prepared_stmt()
24071 "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){ in bind_prepared_stmt()
24073 pQ = 0; in bind_prepared_stmt()
24077 " WHERE key=?1", -1, &pQ, 0); in bind_prepared_stmt()
24082 if( zVar==0 ){ in bind_prepared_stmt()
24088 sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0)); in bind_prepared_stmt()
24090 }else if( sqlite3_strlike("_NAN", zVar, 0)==0 ){ in bind_prepared_stmt()
24094 }else if( sqlite3_strlike("_INF", zVar, 0)==0 ){ in bind_prepared_stmt()
24097 }else if( strncmp(zVar, "$int_", 5)==0 ){ in bind_prepared_stmt()
24099 }else if( strncmp(zVar, "$text_", 6)==0 ){ in bind_prepared_stmt()
24166 if( nArg>0 ){ in print_box_row_separator()
24168 print_box_line(p->out, p->actualWidth[0]+2); in print_box_row_separator()
24193 int mxWidth, /* Max width. 0 means no limit */ in translateForDisplayAndDup()
24202 if( z==0 ){ in translateForDisplayAndDup()
24203 *pzTail = 0; in translateForDisplayAndDup()
24204 return 0; in translateForDisplayAndDup()
24206 if( mxWidth<0 ) mxWidth = -mxWidth; in translateForDisplayAndDup()
24207 if( mxWidth==0 ) mxWidth = 1000000; in translateForDisplayAndDup()
24208 i = j = n = 0; in translateForDisplayAndDup()
24211 if( c>=0xc0 ){ in translateForDisplayAndDup()
24225 if( c==0 || c=='\n' || (c=='\r' && z[i+1]=='\n') ) break; in translateForDisplayAndDup()
24230 }while( (n&7)!=0 && n<mxWidth ); in translateForDisplayAndDup()
24234 if( c==0x1b && p->eEscMode==SHELL_ESC_OFF && (k = isVt100(&z[i]))>0 ){ in translateForDisplayAndDup()
24250 if( IsAlnum(z[k-1])!=IsAlnum(z[k]) && (z[k]&0xc0)!=0x80 ) break; in translateForDisplayAndDup()
24265 *pzTail = z[i+2] ? &z[i+2] : 0; in translateForDisplayAndDup()
24266 }else if( z[i]==0 || z[i+1]==0 ){ in translateForDisplayAndDup()
24267 *pzTail = 0; in translateForDisplayAndDup()
24273 i = j = n = 0; in translateForDisplayAndDup()
24276 if( c>=0xc0 ){ in translateForDisplayAndDup()
24279 do{ zOut[j++] = z[i++]; }while( (--len)>0 ); in translateForDisplayAndDup()
24288 if( c==0 ) break; in translateForDisplayAndDup()
24293 }while( (n&7)!=0 && n<mxWidth ); in translateForDisplayAndDup()
24299 zOut[j++] = 0xe2; in translateForDisplayAndDup()
24300 zOut[j++] = 0x90; in translateForDisplayAndDup()
24301 zOut[j++] = 0x80 + c; in translateForDisplayAndDup()
24305 zOut[j++] = 0x40 + c; in translateForDisplayAndDup()
24309 if( c==0x1b && (nn = isVt100(&z[i]))>0 ){ in translateForDisplayAndDup()
24321 zOut[j] = 0; in translateForDisplayAndDup()
24330 if( z==0 ) return 0; in needUnistr()
24331 while( (c = *z)>0x1f || c=='\t' || c=='\n' || (c=='\r' && z[1]=='\n') ){ z++; } in needUnistr()
24332 return c!=0; in needUnistr()
24354 sqlite3_str *pStr = sqlite3_str_new(0); in quoted_column()
24358 for(j=0; j<n; j++){ in quoted_column()
24365 return 0; /* Not reached */ in quoted_column()
24382 sqlite3_int64 nRow = 0; in exec_prepared_stmt_columnar()
24383 int nColumn = 0; in exec_prepared_stmt_columnar()
24384 char **azData = 0; in exec_prepared_stmt_columnar()
24385 sqlite3_int64 nAlloc = 0; in exec_prepared_stmt_columnar()
24386 char *abRowDiv = 0; in exec_prepared_stmt_columnar()
24389 char **azQuoted = 0; in exec_prepared_stmt_columnar()
24393 const char *colSep = 0; in exec_prepared_stmt_columnar()
24394 const char *rowSep = 0; in exec_prepared_stmt_columnar()
24395 const unsigned char **azNextLine = 0; in exec_prepared_stmt_columnar()
24396 int bNextLine = 0; in exec_prepared_stmt_columnar()
24397 int bMultiLineRowExists = 0; in exec_prepared_stmt_columnar()
24405 if( nColumn==0 ) goto columnar_end; in exec_prepared_stmt_columnar()
24407 if( nAlloc<=0 ) nAlloc = 1; in exec_prepared_stmt_columnar()
24412 memset((void*)azNextLine, 0, nColumn*sizeof(char*) ); in exec_prepared_stmt_columnar()
24416 memset(azQuoted, 0, nColumn*sizeof(char*) ); in exec_prepared_stmt_columnar()
24423 for(i=p->nWidth; i<nColumn; i++) p->colWidth[i] = 0; in exec_prepared_stmt_columnar()
24427 memset(p->actualWidth, 0, nColumn*sizeof(int)); in exec_prepared_stmt_columnar()
24428 for(i=0; i<nColumn; i++){ in exec_prepared_stmt_columnar()
24430 if( w<0 ) w = -w; in exec_prepared_stmt_columnar()
24433 for(i=0; i<nColumn; i++){ in exec_prepared_stmt_columnar()
24436 if( wx==0 ){ in exec_prepared_stmt_columnar()
24439 if( wx<0 ) wx = -wx; in exec_prepared_stmt_columnar()
24441 if( uz==0 ) uz = (u8*)""; in exec_prepared_stmt_columnar()
24446 bNextLine = 0; in exec_prepared_stmt_columnar()
24456 for(i=0; i<nColumn; i++){ in exec_prepared_stmt_columnar()
24458 if( wx==0 ){ in exec_prepared_stmt_columnar()
24461 if( wx<0 ) wx = -wx; in exec_prepared_stmt_columnar()
24464 if( uz==0 ) uz = (u8*)zEmpty; in exec_prepared_stmt_columnar()
24466 assert( azQuoted!=0 ); in exec_prepared_stmt_columnar()
24472 if( uz==0 ) uz = (u8*)zShowNull; in exec_prepared_stmt_columnar()
24478 abRowDiv[nRow-1] = 0; in exec_prepared_stmt_columnar()
24484 for(i=0; i<nTotal; i++){ in exec_prepared_stmt_columnar()
24486 if( z==0 ) z = (char*)zEmpty; in exec_prepared_stmt_columnar()
24497 for(i=0; i<nColumn; i++){ in exec_prepared_stmt_columnar()
24499 if( p->colWidth[i]<0 ) w = -w; in exec_prepared_stmt_columnar()
24503 for(i=0; i<nColumn; i++){ in exec_prepared_stmt_columnar()
24515 for(i=0; i<nColumn; i++){ in exec_prepared_stmt_columnar()
24529 for(i=0; i<nColumn; i++){ in exec_prepared_stmt_columnar()
24544 for(i=0; i<nColumn; i++){ in exec_prepared_stmt_columnar()
24555 for(i=nColumn, j=0; i<nTotal; i++, j++){ in exec_prepared_stmt_columnar()
24556 if( j==0 && p->cMode!=MODE_Column ){ in exec_prepared_stmt_columnar()
24560 if( z==0 ) z = p->nullValue; in exec_prepared_stmt_columnar()
24562 if( p->colWidth[j]<0 ) w = -w; in exec_prepared_stmt_columnar()
24591 for(i=0; i<nData; i++){ in exec_prepared_stmt_columnar()
24599 for(i=0; i<nColumn; i++) sqlite3_free(azQuoted[i]); in exec_prepared_stmt_columnar()
24612 sqlite3_uint64 nRow = 0; in exec_prepared_stmt()
24641 for(i=0; i<nCol; i++){ in exec_prepared_stmt()
24647 for(i=0; i<nCol; i++){ in exec_prepared_stmt()
24705 assert( pzErr==0 || *pzErr==0 ); in expertHandleSQL()
24712 ** report from it and then clean it up (if bCancel==0).
24728 assert( bCancel || pzErr==0 || *pzErr==0 ); in expertFinish()
24729 if( bCancel==0 ){ in expertFinish()
24738 const char *zCand = sqlite3_expert_report(p,0,EXPERT_REPORT_CANDIDATES); in expertFinish()
24742 for(i=0; i<nQuery; i++){ in expertFinish()
24746 if( zIdx==0 ) zIdx = "(no new indexes)\n"; in expertFinish()
24758 pState->expert.pExpert = 0; in expertFinish()
24771 char *zErr = 0; in expertDotCommand()
24773 int iSample = 0; in expertDotCommand()
24775 assert( pState->expert.pExpert==0 ); in expertDotCommand()
24776 memset(&pState->expert, 0, sizeof(ExpertInfo)); in expertDotCommand()
24781 if( z[0]=='-' && z[1]=='-' ) z++; in expertDotCommand()
24783 if( n>=2 && 0==cli_strncmp(z, "-verbose", n) ){ in expertDotCommand()
24786 else if( n>=2 && 0==cli_strncmp(z, "-sample", n) ){ in expertDotCommand()
24792 if( iSample<0 || iSample>100 ){ in expertDotCommand()
24806 if( pState->expert.pExpert==0 ){ in expertDotCommand()
24853 while( zSql[0] && (SQLITE_OK == rc) ){ in shell_exec()
24864 while( IsSpace(zSql[0]) ) zSql++; in shell_exec()
24868 if( zStmtSql==0 ) zStmtSql = ""; in shell_exec()
24869 while( IsSpace(zStmtSql[0]) ) zStmtSql++; in shell_exec()
24874 pArg->cnt = 0; in shell_exec()
24878 if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){ in shell_exec()
24880 int triggerEQP = 0; in shell_exec()
24884 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0); in shell_exec()
24893 int iEqpId = sqlite3_column_int(pExplain, 0); in shell_exec()
24895 if( zEQPLine==0 ) zEQPLine = ""; in shell_exec()
24896 if( zEQPLine[0]=='-' ) eqp_render(pArg, 0); in shell_exec()
24899 eqp_render(pArg, 0); in shell_exec()
24914 if( pArg->autoEQP>=AUTOEQP_trigger && triggerEQP==0 ){ in shell_exec()
24915 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 0, 0); in shell_exec()
24918 sqlite3_stmt_explain(pStmt, 0); in shell_exec()
24944 eqp_render(pArg, 0); in shell_exec()
24948 display_stats(db, pArg, 0); in shell_exec()
24963 while( IsSpace(zSql[0]) ) zSql++; in shell_exec()
24965 *pzErrMsg = save_err_msg(db, "stepping", rc, 0); in shell_exec()
24986 /* azCol[0] is a static string */ in freeColumnList()
24996 ** The azCol[0] entry is usually NULL. However, if zTab contains a rowid
24997 ** value that needs to be preserved, then azCol[0] is filled in with the
25001 ** by an entry with azCol[i]==0.
25004 char **azCol = 0; in tableColumnList()
25007 int nCol = 0; in tableColumnList()
25008 int nAlloc = 0; in tableColumnList()
25009 int nPK = 0; /* Number of PRIMARY KEY columns seen */ in tableColumnList()
25010 int isIPK = 0; /* True if one PRIMARY KEY column of type INTEGER */ in tableColumnList()
25016 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in tableColumnList()
25018 if( rc ) return 0; in tableColumnList()
25022 azCol = sqlite3_realloc(azCol, nAlloc*sizeof(azCol[0])); in tableColumnList()
25031 "INTEGER")==0 in tableColumnList()
25035 isIPK = 0; in tableColumnList()
25040 if( azCol==0 ) return 0; in tableColumnList()
25041 azCol[0] = 0; in tableColumnList()
25042 azCol[nCol+1] = 0; in tableColumnList()
25061 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in tableColumnList()
25065 return 0; in tableColumnList()
25076 for(j=0; j<3; j++){ in tableColumnList()
25078 if( sqlite3_stricmp(azRowid[j],azCol[i])==0 ) break; in tableColumnList()
25083 ** name for the rowid before adding it to azCol[0]. WITHOUT ROWID in tableColumnList()
25085 rc = sqlite3_table_column_metadata(p->db,0,zTab,azRowid[j],0,0,0,0,0); in tableColumnList()
25086 if( rc==SQLITE_OK ) azCol[0] = azRowid[j]; in tableColumnList()
25098 sqlite3_stmt *pStmt = 0; in toggleSelectOrder()
25099 int iSetting = 0; in toggleSelectOrder()
25101 sqlite3_prepare_v2(db, "PRAGMA reverse_unordered_selects", -1, &pStmt, 0); in toggleSelectOrder()
25103 iSetting = sqlite3_column_int(pStmt, 0); in toggleSelectOrder()
25108 sqlite3_exec(db, zStmt, 0, 0, 0); in toggleSelectOrder()
25127 if( nArg!=3 || azArg==0 ) return 0; in dump_callback()
25128 zTable = azArg[0]; in dump_callback()
25131 if( zTable==0 ) return 0; in dump_callback()
25132 if( zType==0 ) return 0; in dump_callback()
25133 dataOnly = (p->shellFlgs & SHFLG_DumpDataOnly)!=0; in dump_callback()
25134 noSys = (p->shellFlgs & SHFLG_DumpNoSys)!=0; in dump_callback()
25136 if( cli_strcmp(zTable, "sqlite_sequence")==0 && !noSys ){ in dump_callback()
25138 }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 && !noSys ){ in dump_callback()
25140 }else if( cli_strncmp(zTable, "sqlite_", 7)==0 ){ in dump_callback()
25141 return 0; in dump_callback()
25144 }else if( cli_strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){ in dump_callback()
25152 "VALUES('table','%q','%q',0,'%q');", in dump_callback()
25157 return 0; in dump_callback()
25162 if( cli_strcmp(zType, "table")==0 ){ in dump_callback()
25171 if( azCol==0 ){ in dump_callback()
25173 return 0; in dump_callback()
25184 if( azCol[0] ){ in dump_callback()
25185 appendText(&sTable, "(", 0); in dump_callback()
25186 appendText(&sTable, azCol[0], 0); in dump_callback()
25188 appendText(&sTable, ",", 0); in dump_callback()
25191 appendText(&sTable, ")", 0); in dump_callback()
25196 appendText(&sSelect, "SELECT ", 0); in dump_callback()
25197 if( azCol[0] ){ in dump_callback()
25198 appendText(&sSelect, azCol[0], 0); in dump_callback()
25199 appendText(&sSelect, ",", 0); in dump_callback()
25204 appendText(&sSelect, ",", 0); in dump_callback()
25208 appendText(&sSelect, " FROM ", 0); in dump_callback()
25215 rc = shell_exec(p, sSelect.z, 0); in dump_callback()
25216 if( (rc&0xff)==SQLITE_CORRUPT ){ in dump_callback()
25219 shell_exec(p, sSelect.z, 0); in dump_callback()
25228 return 0; in dump_callback()
25243 char *zErr = 0; in run_schema_dump_query()
25252 zErr = 0; in run_schema_dump_query()
25255 if( zQ2==0 ) return rc; in run_schema_dump_query()
25400 " ascii Columns/rows delimited by 0x1F and 0x1E",
25588 ** * If zPattern is "0" then show all help for undocumented commands.
25604 int i = 0; in showHelp()
25605 int j = 0; in showHelp()
25606 int n = 0; in showHelp()
25608 if( zPattern==0 ){ in showHelp()
25611 }else if( cli_strcmp(zPattern,"-a")==0 in showHelp()
25612 || cli_strcmp(zPattern,"-all")==0 in showHelp()
25613 || cli_strcmp(zPattern,"--all")==0 in showHelp()
25617 }else if( cli_strcmp(zPattern,"0")==0 ){ in showHelp()
25619 int show = 0; in showHelp()
25620 for(i=0; i<ArraySize(azHelp); i++){ in showHelp()
25621 if( azHelp[i][0]=='.' ){ in showHelp()
25622 show = 0; in showHelp()
25623 }else if( azHelp[i][0]==',' ){ in showHelp()
25637 for(i=0; i<ArraySize(azHelp); i++){ in showHelp()
25638 if( sqlite3_strglob(zPat, azHelp[i])==0 ){ in showHelp()
25649 while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){ in showHelp()
25661 for(i=0; i<ArraySize(azHelp); i++){ in showHelp()
25662 if( azHelp[i][0]==',' ){ in showHelp()
25663 while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i; in showHelp()
25666 if( azHelp[i][0]=='.' ) j = i; in showHelp()
25667 if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){ in showHelp()
25669 while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){ in showHelp()
25705 if( in==0 ) return 0; in readFile()
25706 rc = fseek(in, 0, SEEK_END); in readFile()
25707 if( rc!=0 ){ in readFile()
25710 return 0; in readFile()
25715 if( pBuf==0 ){ in readFile()
25718 return 0; in readFile()
25725 return 0; in readFile()
25727 pBuf[nIn] = 0; in readFile()
25741 for(i=0; i<pSession->nFilter; i++){ in session_close()
25745 memset(pSession, 0, sizeof(OpenSession)); in session_close()
25755 struct AuxDb *pAuxDb = i<0 ? p->pAuxDb : &p->aAuxDb[i]; in session_close_all()
25756 for(j=0; j<pAuxDb->nSession; j++){ in session_close_all()
25759 pAuxDb->nSession = 0; in session_close_all()
25773 for(i=0; i<pSession->nFilter; i++){ in session_filter()
25774 if( sqlite3_strglob(pSession->azFilter[i], zTab)==0 ) return 0; in session_filter()
25794 if( f==0 ){ in deduceDatabaseType()
25795 if( dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){ in deduceDatabaseType()
25802 if( n==1 && memcmp(zBuf, "SQLite format 3", 16)==0 ){ in deduceDatabaseType()
25808 if( n==1 && memcmp(zBuf, "Start-Of-SQLite3-", 17)==0 ){ in deduceDatabaseType()
25813 if( n==1 && zBuf[0]==0x50 && zBuf[1]==0x4b && zBuf[2]==0x05 in deduceDatabaseType()
25814 && zBuf[3]==0x06 ){ in deduceDatabaseType()
25816 }else if( n==0 && dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){ in deduceDatabaseType()
25828 ** If p->aAuxDb[].zDbFilename is 0, then read from standard input.
25831 unsigned char *a = 0; in readHexDb()
25833 int n = 0; in readHexDb()
25834 int pgsz = 0; in readHexDb()
25835 int iOffset = 0; in readHexDb()
25844 if( in==0 ){ in readHexDb()
25846 return 0; in readHexDb()
25848 nLine = 0; in readHexDb()
25852 if( in==0 ) in = stdin; in readHexDb()
25854 *pnData = 0; in readHexDb()
25856 if( sqlite3_fgets(zLine, sizeof(zLine), in)==0 ) goto readHexDb_error; in readHexDb()
25859 if( n<0 ) goto readHexDb_error; in readHexDb()
25860 if( pgsz<512 || pgsz>65536 || (pgsz&(pgsz-1))!=0 ) goto readHexDb_error; in readHexDb()
25864 memset(a, 0, n); in readHexDb()
25865 if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){ in readHexDb()
25869 for(nLine++; sqlite3_fgets(zLine, sizeof(zLine), in)!=0; nLine++){ in readHexDb()
25875 if( cli_strncmp(zLine, "| end ", 6)==0 ){ in readHexDb()
25879 &j, &x[0], &x[1], &x[2], &x[3], &x[4], &x[5], &x[6], &x[7], in readHexDb()
25883 if( k+16<=n && k>=0 ){ in readHexDb()
25885 for(ii=0; ii<16; ii++) a[k+ii] = x[ii]&0xff; in readHexDb()
25901 while( sqlite3_fgets(zLine, sizeof(zLine), p->in)!=0 ){ in readHexDb()
25903 if(cli_strncmp(zLine, "| end ", 6)==0 ) break; in readHexDb()
25909 return 0; in readHexDb()
25921 int sleep = sqlite3_value_int(argv[0]); in shellUSleepFunc()
25943 zName = (const char*)sqlite3_value_text(apVal[0]); in shellModuleSchema()
25949 p->pLog = 0; in shellModuleSchema()
25950 zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0; in shellModuleSchema()
25970 #define OPEN_DB_KEEPALIVE 0x001 /* Return after error if true */
25971 #define OPEN_DB_ZIPFILE 0x002 /* Open as ZIP if name matches *.zip */
25978 if( p->db==0 ){ in open_db()
25981 if( zDbFilename==0 || zDbFilename[0]==0 ){ in open_db()
25985 (openFlags & OPEN_DB_ZIPFILE)!=0); in open_db()
25996 sqlite3_open(0, &p->db); in open_db()
26005 SQLITE_OPEN_READONLY|p->openFlags, 0); in open_db()
26011 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, 0); in open_db()
26015 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ in open_db()
26018 if( (openFlags & OPEN_DB_KEEPALIVE)==0 ){ in open_db()
26023 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ in open_db()
26034 sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0); in open_db()
26039 sqlite3_db_config(p->db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, testmode_on,0); in open_db()
26040 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, !testmode_on,0); in open_db()
26046 sqlite3_sha_init(p->db, 0, 0); in open_db()
26047 sqlite3_shathree_init(p->db, 0, 0); in open_db()
26048 sqlite3_uint_init(p->db, 0, 0); in open_db()
26049 sqlite3_stmtrand_init(p->db, 0, 0); in open_db()
26050 sqlite3_decimal_init(p->db, 0, 0); in open_db()
26051 sqlite3_percentile_init(p->db, 0, 0); in open_db()
26052 sqlite3_base64_init(p->db, 0, 0); in open_db()
26053 sqlite3_base85_init(p->db, 0, 0); in open_db()
26054 sqlite3_regexp_init(p->db, 0, 0); in open_db()
26055 sqlite3_ieee_init(p->db, 0, 0); in open_db()
26056 sqlite3_series_init(p->db, 0, 0); in open_db()
26058 sqlite3_fileio_init(p->db, 0, 0); in open_db()
26059 sqlite3_completion_init(p->db, 0, 0); in open_db()
26063 sqlite3_zipfile_init(p->db, 0, 0); in open_db()
26064 sqlite3_sqlar_init(p->db, 0, 0); in open_db()
26088 SHELL_SUBMACRO(SQLITE_SHELL_EXTFUNCS, EXPOSE)(p->db, 0); in open_db()
26095 sqlite3_create_function(p->db, "strtod", 1, SQLITE_UTF8, 0, in open_db()
26096 shellStrtod, 0, 0); in open_db()
26097 sqlite3_create_function(p->db, "dtostr", 1, SQLITE_UTF8, 0, in open_db()
26098 shellDtostr, 0, 0); in open_db()
26099 sqlite3_create_function(p->db, "dtostr", 2, SQLITE_UTF8, 0, in open_db()
26100 shellDtostr, 0, 0); in open_db()
26101 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0, in open_db()
26102 shellAddSchemaName, 0, 0); in open_db()
26104 shellModuleSchema, 0, 0); in open_db()
26106 shellPutsFunc, 0, 0); in open_db()
26107 sqlite3_create_function(p->db, "usleep",1,SQLITE_UTF8,0, in open_db()
26108 shellUSleepFunc, 0, 0); in open_db()
26110 sqlite3_create_function(p->db, "edit", 1, SQLITE_UTF8, 0, in open_db()
26111 editFunc, 0, 0); in open_db()
26112 sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0, in open_db()
26113 editFunc, 0, 0); in open_db()
26120 sqlite3_exec(p->db, zSql, 0, 0, 0); in open_db()
26127 int nData = 0; in open_db()
26134 if( aData==0 ){ in open_db()
26143 if( p->szMax>0 ){ in open_db()
26149 if( p->db!=0 ){ in open_db()
26154 p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, p->scanstatsOn, (int*)0 in open_db()
26176 static sqlite3_stmt *pStmt = 0; in readline_completion_generator()
26178 if( state==0 ){ in readline_completion_generator()
26184 sqlite3_prepare_v2(globalDb, zSql, -1, &pStmt, 0); in readline_completion_generator()
26188 const char *z = (const char*)sqlite3_column_text(pStmt,0); in readline_completion_generator()
26189 zRet = z ? strdup(z) : 0; in readline_completion_generator()
26192 pStmt = 0; in readline_completion_generator()
26193 zRet = 0; in readline_completion_generator()
26218 sqlite3_stmt *pStmt = 0; in linenoise_completion()
26226 if( zLine[0]=='.' || zLine[0]=='#') return; in linenoise_completion()
26227 for(i=nLine-1; i>=0 && (IsAlnum(zLine[i]) || zLine[i]=='_'); i--){} in linenoise_completion()
26235 sqlite3_prepare_v2(globalDb, zSql, -1, &pStmt, 0); in linenoise_completion()
26237 sqlite3_exec(globalDb, "PRAGMA page_count", 0, 0, 0); /* Load the schema */ in linenoise_completion()
26239 const char *zCompletion = (const char*)sqlite3_column_text(pStmt, 0); in linenoise_completion()
26240 int nCompletion = sqlite3_column_bytes(pStmt, 0); in linenoise_completion()
26271 for(i=j=0; (c = z[i])!=0; i++, j++){ in resolve_backslashes()
26272 if( c=='\\' && z[i+1]!=0 ){ in resolve_backslashes()
26295 int nhd = 0, hdv; in resolve_backslashes()
26296 u8 hv = 0; in resolve_backslashes()
26297 while( nhd<2 && (c=z[i+1+nhd])!=0 && (hdv=hexDigitValue(c))>=0 ){ in resolve_backslashes()
26303 }else if( c>='0' && c<='7' ){ in resolve_backslashes()
26304 c -= '0'; in resolve_backslashes()
26305 if( z[i+1]>='0' && z[i+1]<='7' ){ in resolve_backslashes()
26307 c = (c<<3) + z[i] - '0'; in resolve_backslashes()
26308 if( z[i+1]>='0' && z[i+1]<='7' ){ in resolve_backslashes()
26310 c = (c<<3) + z[i] - '0'; in resolve_backslashes()
26317 if( j<i ) z[j] = 0; in resolve_backslashes()
26321 ** Interpret zArg as either an integer or a boolean value. Return 1 or 0
26326 if( zArg[0]=='0' && zArg[1]=='x' ){ in booleanValue()
26327 for(i=2; hexDigitValue(zArg[i])>=0; i++){} in booleanValue()
26329 for(i=0; zArg[i]>='0' && zArg[i]<='9'; i++){} in booleanValue()
26331 if( i>0 && zArg[i]==0 ) return (int)(integerValue(zArg) & 0xffffffff); in booleanValue()
26332 if( sqlite3_stricmp(zArg, "on")==0 || sqlite3_stricmp(zArg,"yes")==0 ){ in booleanValue()
26335 if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){ in booleanValue()
26336 return 0; in booleanValue()
26340 return 0; in booleanValue()
26368 if( cli_strcmp(zFile,"stdout")==0 ){ in output_file_open()
26370 }else if( cli_strcmp(zFile, "stderr")==0 ){ in output_file_open()
26372 }else if( cli_strcmp(zFile, "off")==0 ){ in output_file_open()
26373 f = 0; in output_file_open()
26376 if( f==0 ){ in output_file_open()
26397 if( p->traceOut==0 ) return 0; in sql_trace_callback()
26400 return 0; in sql_trace_callback()
26402 if( mType!=SQLITE_TRACE_ROW && pX!=0 && ((const char*)pX)[0]=='-' ){ in sql_trace_callback()
26423 if( zSql==0 ) return 0; in sql_trace_callback()
26426 while( nSql>0 && zSql[nSql-1]==';' ){ nSql--; } in sql_trace_callback()
26434 sqlite3_int64 nNanosec = pX ? *(sqlite3_int64*)pX : 0; in sql_trace_callback()
26440 return 0; in sql_trace_callback()
26452 static unsigned int nCall = 0; in test_breakpoint()
26453 if( (nCall++)==0xffffffff ) printf("Many .breakpoints have run\n"); in test_breakpoint()
26478 if( p->in!=0 && p->xCloser!=0 ){ in import_cleanup()
26480 p->in = 0; in import_cleanup()
26483 p->z = 0; in import_cleanup()
26513 p->n = 0; in csv_read_one_field()
26517 return 0; in csv_read_one_field()
26523 pc = ppc = 0; in csv_read_one_field()
26529 pc = 0; in csv_read_one_field()
26558 ** UTF-8 BOM (0xEF BB BF) then skip the BOM */ in csv_read_one_field()
26559 if( (c&0xff)==0xef && p->bNotFirst==0 ){ in csv_read_one_field()
26562 if( (c&0xff)==0xbb ){ in csv_read_one_field()
26565 if( (c&0xff)==0xbf ){ in csv_read_one_field()
26567 p->n = 0; in csv_read_one_field()
26578 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--; in csv_read_one_field()
26582 if( p->z ) p->z[p->n] = 0; in csv_read_one_field()
26603 p->n = 0; in ascii_read_one_field()
26607 return 0; in ascii_read_one_field()
26617 if( p->z ) p->z[p->n] = 0; in ascii_read_one_field()
26631 sqlite3_stmt *pQuery = 0; in tryToCloneData()
26632 sqlite3_stmt *pInsert = 0; in tryToCloneData()
26633 char *zQuery = 0; in tryToCloneData()
26634 char *zInsert = 0; in tryToCloneData()
26638 int k = 0; in tryToCloneData()
26639 int cnt = 0; in tryToCloneData()
26644 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); in tryToCloneData()
26661 rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0); in tryToCloneData()
26667 for(k=0; k<2; k++){ in tryToCloneData()
26669 for(i=0; i<n; i++){ in tryToCloneData()
26704 if( (cnt%spinRate)==0 ){ in tryToCloneData()
26715 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); in tryToCloneData()
26720 } /* End for(k=0...) */ in tryToCloneData()
26742 sqlite3_stmt *pQuery = 0; in tryToCloneSchema()
26743 char *zQuery = 0; in tryToCloneSchema()
26747 char *zErrMsg = 0; in tryToCloneSchema()
26752 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); in tryToCloneSchema()
26760 zName = sqlite3_column_text(pQuery, 0); in tryToCloneSchema()
26762 if( zName==0 || zSql==0 ) continue; in tryToCloneSchema()
26763 if( sqlite3_stricmp((char*)zName, "sqlite_sequence")!=0 ){ in tryToCloneSchema()
26765 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg); in tryToCloneSchema()
26769 zErrMsg = 0; in tryToCloneSchema()
26783 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); in tryToCloneSchema()
26790 zName = sqlite3_column_text(pQuery, 0); in tryToCloneSchema()
26792 if( zName==0 || zSql==0 ) continue; in tryToCloneSchema()
26793 if( sqlite3_stricmp((char*)zName, "sqlite_sequence")==0 ) continue; in tryToCloneSchema()
26795 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg); in tryToCloneSchema()
26799 zErrMsg = 0; in tryToCloneSchema()
26819 sqlite3 *newDb = 0; in tryToClone()
26820 if( access(zNewDb,0)==0 ){ in tryToClone()
26829 sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0); in tryToClone()
26830 sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0); in tryToClone()
26832 tryToCloneSchema(p, newDb, "type!='table'", 0); in tryToClone()
26833 sqlite3_exec(newDb, "COMMIT;", 0, 0, 0); in tryToClone()
26834 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); in tryToClone()
26867 if( p->outfile[0]=='|' ){ in output_reset()
26898 p->doXdgOpen = 0; in output_reset()
26902 p->outfile[0] = 0; in output_reset()
26916 int res = 0; in db_int()
26922 sqlite3_prepare_v2(db, z, -1, &pStmt, 0); in db_int()
26924 res = sqlite3_column_int(pStmt,0); in db_int()
26936 return (a[0]<<8) + a[1]; in get2byteInt()
26939 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3]; in get4byteInt()
26945 ** Return 1 on error, 2 to exit, and 0 otherwise.
26978 sqlite3_stmt *pStmt = 0; in shell_dbinfo_command()
26980 open_db(p, 0); in shell_dbinfo_command()
26981 if( p->db==0 ) return 1; in shell_dbinfo_command()
26984 -1, &pStmt, 0); in shell_dbinfo_command()
26992 && sqlite3_column_bytes(pStmt,0)>100 in shell_dbinfo_command()
26994 const u8 *pb = sqlite3_column_blob(pStmt,0); in shell_dbinfo_command()
27009 for(i=0; i<ArraySize(aField); i++){ in shell_dbinfo_command()
27022 if( zDb==0 ){ in shell_dbinfo_command()
27024 }else if( cli_strcmp(zDb,"temp")==0 ){ in shell_dbinfo_command()
27029 for(i=0; i<ArraySize(aQuery); i++){ in shell_dbinfo_command()
27036 return 0; in shell_dbinfo_command()
27043 ** Return 1 on error, 2 to exit, and 0 otherwise.
27046 sqlite3_stmt *pStmt = 0; in shell_dbtotxt_command()
27047 sqlite3_int64 nPage = 0; in shell_dbtotxt_command()
27048 int pgSz = 0; in shell_dbtotxt_command()
27050 char *zName = 0; in shell_dbtotxt_command()
27060 rc = sqlite3_prepare_v2(p->db, "PRAGMA page_size", -1, &pStmt, 0); in shell_dbtotxt_command()
27062 rc = 0; in shell_dbtotxt_command()
27064 pgSz = sqlite3_column_int(pStmt, 0); in shell_dbtotxt_command()
27066 pStmt = 0; in shell_dbtotxt_command()
27067 if( pgSz<512 || pgSz>65536 || (pgSz&(pgSz-1))!=0 ) goto dbtotxt_error; in shell_dbtotxt_command()
27068 rc = sqlite3_prepare_v2(p->db, "PRAGMA page_count", -1, &pStmt, 0); in shell_dbtotxt_command()
27070 rc = 0; in shell_dbtotxt_command()
27072 nPage = sqlite3_column_int64(pStmt, 0); in shell_dbtotxt_command()
27074 pStmt = 0; in shell_dbtotxt_command()
27076 rc = sqlite3_prepare_v2(p->db, "PRAGMA databases", -1, &pStmt, 0); in shell_dbtotxt_command()
27082 if( zFilename==0 || zFilename[0]==0 ) zFilename = "unk.db"; in shell_dbtotxt_command()
27085 if( zTail==0 ) zTail = strrchr(zFilename, '\\'); in shell_dbtotxt_command()
27093 pStmt = 0; in shell_dbtotxt_command()
27095 "SELECT pgno, data FROM sqlite_dbpage ORDER BY pgno", -1, &pStmt, 0); in shell_dbtotxt_command()
27098 sqlite3_int64 pgno = sqlite3_column_int64(pStmt, 0); in shell_dbtotxt_command()
27100 int seenPageLabel = 0; in shell_dbtotxt_command()
27101 for(i=0; i<pgSz; i+=16){ in shell_dbtotxt_command()
27103 for(j=0; j<16 && aLine[j]==0; j++){} in shell_dbtotxt_command()
27110 for(j=0; j<16; j++) sqlite3_fprintf(p->out, " %02x", aLine[j]); in shell_dbtotxt_command()
27112 for(j=0; j<16; j++){ in shell_dbtotxt_command()
27122 return 0; in shell_dbtotxt_command()
27149 ** if they match and FALSE (0) if they do not match.
27175 while( (c = (*(zGlob++)))!=0 ){ in testcase_glob()
27177 if( !IsSpace(*z) ) return 0; in testcase_glob()
27182 if( c=='?' && (*(z++))==0 ) return 0; in testcase_glob()
27184 if( c==0 ){ in testcase_glob()
27187 while( *z && testcase_glob(zGlob-1,z)==0 ){ in testcase_glob()
27190 return (*z)!=0; in testcase_glob()
27192 while( (c2 = (*(z++)))!=0 ){ in testcase_glob()
27195 if( c2==0 ) return 0; in testcase_glob()
27199 return 0; in testcase_glob()
27201 if( (*(z++))==0 ) return 0; in testcase_glob()
27203 int prior_c = 0; in testcase_glob()
27204 seen = 0; in testcase_glob()
27205 invert = 0; in testcase_glob()
27207 if( c==0 ) return 0; in testcase_glob()
27218 if( c2=='-' && zGlob[0]!=']' && zGlob[0]!=0 && prior_c>0 ){ in testcase_glob()
27221 prior_c = 0; in testcase_glob()
27230 if( c2==0 || (seen ^ invert)==0 ) return 0; in testcase_glob()
27232 if( (z[0]=='-' || z[0]=='+') && IsDigit(z[1]) ) z++; in testcase_glob()
27233 if( !IsDigit(z[0]) ) return 0; in testcase_glob()
27235 while( IsDigit(z[0]) ){ z++; } in testcase_glob()
27237 if( c!=(*(z++)) ) return 0; in testcase_glob()
27241 return *z==0; in testcase_glob()
27250 if( zStr[0]!='-' ) return 0; in optionMatch()
27252 if( zStr[0]=='-' ) zStr++; in optionMatch()
27253 return cli_strcmp(zStr, zOpt)==0; in optionMatch()
27276 if( p->zTempFile==0 ) return; in clearTempFile()
27280 p->zTempFile = 0; in clearTempFile()
27289 p->zTempFile = 0; in newTempFile()
27291 sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile); in newTempFile()
27293 if( p->zTempFile==0 ){ in newTempFile()
27300 if( zTemp==0 ) zTemp = getenv("TMP"); in newTempFile()
27301 if( zTemp==0 ){ in newTempFile()
27342 const char *zChildSeq = 0; /* Initialize to avoid false-positive warning */ in shellFkeyCollateClause()
27346 zParent = (const char*)sqlite3_value_text(apVal[0]); in shellFkeyCollateClause()
27353 db, "main", zParent, zParentCol, 0, &zParentSeq, 0, 0, 0 in shellFkeyCollateClause()
27357 db, "main", zChild, zChildCol, 0, &zChildSeq, 0, 0, 0 in shellFkeyCollateClause()
27378 int bVerbose = 0; /* If -verbose is present */ in lintFkeyIndexes()
27379 int bGroupByParent = 0; /* If -groupbyparent is present */ in lintFkeyIndexes()
27383 sqlite3_stmt *pSql = 0; /* Compiled version of SQL statement below */ in lintFkeyIndexes()
27390 ** 0. The text of an SQL statement similar to: in lintFkeyIndexes()
27452 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){ in lintFkeyIndexes()
27455 else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){ in lintFkeyIndexes()
27461 "Usage: %s %s ?-verbose? ?-groupbyparent?\n", azArg[0], azArg[1]); in lintFkeyIndexes()
27468 0, shellFkeyCollateClause, 0, 0 in lintFkeyIndexes()
27473 rc = sqlite3_prepare_v2(db, zSql, -1, &pSql, 0); in lintFkeyIndexes()
27481 char *zPrev = 0; in lintFkeyIndexes()
27484 sqlite3_stmt *pExplain = 0; in lintFkeyIndexes()
27485 const char *zEQP = (const char*)sqlite3_column_text(pSql, 0); in lintFkeyIndexes()
27492 if( zEQP==0 ) continue; in lintFkeyIndexes()
27493 if( zGlob==0 ) continue; in lintFkeyIndexes()
27494 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0); in lintFkeyIndexes()
27498 res = zPlan!=0 && ( 0==sqlite3_strglob(zGlob, zPlan) in lintFkeyIndexes()
27499 || 0==sqlite3_strglob(zGlobIPK, zPlan)); in lintFkeyIndexes()
27504 if( res<0 ){ in lintFkeyIndexes()
27509 && (bVerbose || res==0) in lintFkeyIndexes()
27510 && (zPrev==0 || sqlite3_stricmp(zParent, zPrev)) in lintFkeyIndexes()
27517 if( res==0 ){ in lintFkeyIndexes()
27554 n = (nArg>=2 ? strlen30(azArg[1]) : 0); in lintDotCommand()
27559 sqlite3_fprintf(stderr,"Usage %s sub-command ?switches...?\n", azArg[0]); in lintDotCommand()
27571 *ppStmt = 0; in shellPrepare()
27573 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0); in shellPrepare()
27592 *ppStmt = 0; in shellPreparePrintf()
27599 if( z==0 ){ in shellPreparePrintf()
27779 { "create", 'c', AR_CMD_CREATE, 0 }, in arParseCommand()
27780 { "extract", 'x', AR_CMD_EXTRACT, 0 }, in arParseCommand()
27781 { "insert", 'i', AR_CMD_INSERT, 0 }, in arParseCommand()
27782 { "list", 't', AR_CMD_LIST, 0 }, in arParseCommand()
27783 { "remove", 'r', AR_CMD_REMOVE, 0 }, in arParseCommand()
27784 { "update", 'u', AR_CMD_UPDATE, 0 }, in arParseCommand()
27785 { "help", 'h', AR_CMD_HELP, 0 }, in arParseCommand()
27786 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 }, in arParseCommand()
27790 { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 }, in arParseCommand()
27791 { "glob", 'g', AR_SWITCH_GLOB, 0 }, in arParseCommand()
27801 if( z[0]!='-' ){ in arParseCommand()
27805 for(i=0; z[i]; i++){ in arParseCommand()
27806 const char *zArg = 0; in arParseCommand()
27808 for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){ in arParseCommand()
27823 if( pAr->nArg>0 ){ in arParseCommand()
27832 if( z[0]!='-' ){ in arParseCommand()
27844 const char *zArg = 0; in arParseCommand()
27846 for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){ in arParseCommand()
27866 }else if( z[2]=='\0' ){ in arParseCommand()
27874 const char *zArg = 0; /* Argument for option, if any */ in arParseCommand()
27875 struct ArSwitch *pMatch = 0; /* Matching option */ in arParseCommand()
27877 for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){ in arParseCommand()
27879 if( (n-2)<=strlen30(zLong) && 0==memcmp(&z[2], zLong, n-2) ){ in arParseCommand()
27888 if( pMatch==0 ){ in arParseCommand()
27902 if( pAr->eCmd==0 ){ in arParseCommand()
27927 sqlite3_stmt *pTest = 0; in arCheckEntries()
27934 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){ in arCheckEntries()
27937 int bOk = 0; in arCheckEntries()
27938 while( n>0 && z[n-1]=='/' ) n--; in arCheckEntries()
27939 z[n] = '\0'; in arCheckEntries()
27945 if( rc==SQLITE_OK && bOk==0 ){ in arCheckEntries()
27968 char *zWhere = 0; in arWhereClause()
27971 if( pAr->nArg==0 ){ in arWhereClause()
27976 for(i=0; i<pAr->nArg; i++){ in arWhereClause()
27982 if( zWhere==0 ){ in arWhereClause()
28003 char *zWhere = 0; in arListCommand()
28004 sqlite3_stmt *pSql = 0; in arListCommand()
28018 sqlite3_column_text(pSql, 0), sqlite3_column_int(pSql, 1), in arListCommand()
28021 sqlite3_fprintf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0)); in arListCommand()
28034 int rc = 0; in arRemoveCommand()
28035 char *zSql = 0; in arRemoveCommand()
28036 char *zWhere = 0; in arRemoveCommand()
28050 char *zErr = 0; in arRemoveCommand()
28051 rc = sqlite3_exec(pAr->db, "SAVEPOINT ar;", 0, 0, 0); in arRemoveCommand()
28053 rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr); in arRemoveCommand()
28055 sqlite3_exec(pAr->db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0); in arRemoveCommand()
28057 rc = sqlite3_exec(pAr->db, "RELEASE ar;", 0, 0, 0); in arRemoveCommand()
28079 "FROM %s WHERE (%s) AND (data IS NULL OR $dirOnly = 0)" in arExtractCommand()
28087 sqlite3_stmt *pSql = 0; in arExtractCommand()
28089 char *zDir = 0; in arExtractCommand()
28090 char *zWhere = 0; in arExtractCommand()
28105 if( zDir==0 ) rc = SQLITE_NOMEM; in arExtractCommand()
28121 for(i=0; i<2; i++){ in arExtractCommand()
28128 if( i==0 && pAr->bVerbose ){ in arExtractCommand()
28129 sqlite3_fprintf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0)); in arExtractCommand()
28152 char *zErr = 0; in arExecSql()
28153 rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr); in arExecSql()
28203 " WHEN 'd' THEN 0\n" in arCreateOrUpdateCommand()
28220 const char *zTab = 0; /* SQL table into which to insert */ in arCreateOrUpdateCommand()
28223 char *zExists = 0; in arCreateOrUpdateCommand()
28228 zTemp[0] = 0; in arCreateOrUpdateCommand()
28248 if( bUpdate==0 ){ in arCreateOrUpdateCommand()
28264 if( zExists==0 ) rc = SQLITE_NOMEM; in arCreateOrUpdateCommand()
28265 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){ in arCreateOrUpdateCommand()
28274 sqlite3_exec(pAr->db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0); in arCreateOrUpdateCommand()
28298 memset(&cmd, 0, sizeof(cmd)); in arDotCommand()
28313 if( cmd.zFile==0 ){ in arDotCommand()
28329 cmd.db = 0; in arDotCommand()
28335 eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0); in arDotCommand()
28341 sqlite3_fileio_init(cmd.db, 0, 0); in arDotCommand()
28342 sqlite3_sqlar_init(cmd.db, 0, 0); in arDotCommand()
28344 shellPutsFunc, 0, 0); in arDotCommand()
28347 if( cmd.zSrcTable==0 && cmd.bZip==0 && cmd.eCmd!=AR_CMD_HELP ){ in arDotCommand()
28349 && sqlite3_table_column_metadata(cmd.db,0,"sqlar","name",0,0,0,0,0) in arDotCommand()
28360 rc = arCreateOrUpdateCommand(&cmd, 0, 0); in arDotCommand()
28376 rc = arCreateOrUpdateCommand(&cmd, 1, 0); in arDotCommand()
28422 int bFreelist = 1; /* 0 if --ignore-freelist is specified */ in recoverDatabaseCmd()
28423 int bRowids = 1; /* 0 if --no-rowids */ in recoverDatabaseCmd()
28424 sqlite3_recover *p = 0; in recoverDatabaseCmd()
28425 int i = 0; in recoverDatabaseCmd()
28430 if( z[0]=='-' && z[1]=='-' ) z++; in recoverDatabaseCmd()
28432 if( n<=17 && memcmp("-ignore-freelist", z, n)==0 ){ in recoverDatabaseCmd()
28433 bFreelist = 0; in recoverDatabaseCmd()
28435 if( n<=12 && memcmp("-recovery-db", z, n)==0 && i<(nArg-1) ){ in recoverDatabaseCmd()
28444 if( n<=15 && memcmp("-lost-and-found", z, n)==0 && i<(nArg-1) ){ in recoverDatabaseCmd()
28448 if( n<=10 && memcmp("-no-rowids", z, n)==0 ){ in recoverDatabaseCmd()
28449 bRowids = 0; in recoverDatabaseCmd()
28453 showHelp(pState->out, azArg[0]); in recoverDatabaseCmd()
28483 sqlite3_intck *p = 0; in intckDatabaseCmd()
28488 i64 nStep = 0; in intckDatabaseCmd()
28489 i64 nError = 0; in intckDatabaseCmd()
28490 const char *zErr = 0; in intckDatabaseCmd()
28498 if( nStepPerUnlock && (nStep % nStepPerUnlock)==0 ){ in intckDatabaseCmd()
28516 * zAutoColumn(0, &db, ?) => (db!=0) Form columns spec for CREATE TABLE,
28517 * close db and set it to 0, and return the columns spec, to later
28519 * The return is 0 when either:
28520 * (a) The db was not initialized and zCol==0 (There are no columns.)
28521 * (b) zCol!=0 (Column was added, db initialized as needed.)
28524 * done if renaming was necessary, or set to 0 if none was done. The out
28529 if( rc==SQLITE_NOMEM ) shell_check_oom(0); \
28531 sqlite3_fprintf(stderr,"E:%d\n",rc), assert(0)
28534 if( rc==SQLITE_NOMEM ) shell_check_oom(0); in rc_err_oom_die()
28570 VALUES(iif(length(?1)>0,?1,'?'),max(length(?1),1),0,0,'')\ in zAutoColumn()
28579 (substring(name,nlen,1) BETWEEN '0' AND '9')\ in zAutoColumn()
28582 0\ in zAutoColumn()
28608 "iif(reps>1, printf('%c%0*d', '"AUTOCOLUMN_SEP"', $1, cpos), '')" in zAutoColumn()
28610 "WITH Lzn(nlz) AS (" /* Find minimum extraneous leading 0's for uniqueness */ in zAutoColumn()
28611 " SELECT 0 AS nlz" in zAutoColumn()
28620 " t.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,t.cpos),2))," in zAutoColumn()
28626 " o.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,o.cpos),2))," in zAutoColumn()
28634 " chop = 0," /* No chopping, never touch incoming names. */ in zAutoColumn()
28637 " printf('%.*c%0.*d',(SELECT max(nlz) FROM Lzn)+1,'0',1,t.cpos),2))," in zAutoColumn()
28644 '('||x'0a'\ in zAutoColumn()
28647 ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\ in zAutoColumn()
28656 " ','||x'0a')" in zAutoColumn()
28657 "FROM ColNames WHERE suff<>'' OR chop!=0" in zAutoColumn()
28660 sqlite3_stmt *pStmt = 0; in zAutoColumn()
28661 assert(pDb!=0); in zAutoColumn()
28664 if( *pDb==0 ){ in zAutoColumn()
28665 if( SQLITE_OK!=sqlite3_open(zCOL_DB, pDb) ) return 0; in zAutoColumn()
28669 "drop view if exists RepeatedNames;",0,0,0); in zAutoColumn()
28672 rc = sqlite3_exec(*pDb, zTabMake, 0, 0, 0); in zAutoColumn()
28675 assert(*pDb!=0); in zAutoColumn()
28676 rc = sqlite3_prepare_v2(*pDb, zTabFill, -1, &pStmt, 0); in zAutoColumn()
28678 rc = sqlite3_bind_text(pStmt, 1, zColNew, -1, 0); in zAutoColumn()
28683 return 0; in zAutoColumn()
28684 }else if( *pDb==0 ){ in zAutoColumn()
28685 return 0; in zAutoColumn()
28688 char *zColsSpec = 0; in zAutoColumn()
28690 int nDigits = (hasDupes)? db_int(*pDb, "%s", zColDigits) : 0; in zAutoColumn()
28693 rc = sqlite3_exec(*pDb, zDedoctor, 0, 0, 0); in zAutoColumn()
28696 rc = sqlite3_exec(*pDb, zSetReps, 0, 0, 0); in zAutoColumn()
28698 rc = sqlite3_prepare_v2(*pDb, zRenameRank, -1, &pStmt, 0); in zAutoColumn()
28705 assert(db_int(*pDb, "%s", zHasDupes)==0); /* Consider: remove this */ in zAutoColumn()
28706 rc = sqlite3_prepare_v2(*pDb, zCollectVar, -1, &pStmt, 0); in zAutoColumn()
28710 zColsSpec = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0)); in zAutoColumn()
28712 zColsSpec = 0; in zAutoColumn()
28714 if( pzRenamed!=0 ){ in zAutoColumn()
28715 if( !hasDupes ) *pzRenamed = 0; in zAutoColumn()
28718 if( SQLITE_OK==sqlite3_prepare_v2(*pDb, zRenamesDone, -1, &pStmt, 0) in zAutoColumn()
28720 *pzRenamed = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0)); in zAutoColumn()
28722 *pzRenamed = 0; in zAutoColumn()
28727 *pDb = 0; in zAutoColumn()
28742 sqlite3_stmt *pStmt = 0; in outputDumpWarning()
28767 int nRepeat; /* Turn off after this many hits. 0 for never */
28769 } faultsim_state = {-1, 0, 0, 0, 0, 0, 0, 0};
28775 if( faultsim_state.iId>0 && faultsim_state.iId!=iArg ){ in faultsim_callback()
28779 if( faultsim_state.iCnt>0 ) faultsim_state.iCnt--; in faultsim_callback()
28792 if( faultsim_state.nRepeat>0 && faultsim_state.nRepeat<=faultsim_state.nHit ){ in faultsim_callback()
28802 ** Return 1 on error, 2 to exit, and 0 otherwise.
28806 int nArg = 0; in do_meta_command()
28808 int rc = 0; in do_meta_command()
28813 expertFinish(p, 1, 0); in do_meta_command()
28821 if( zLine[h]==0 ) break; in do_meta_command()
28826 if( zLine[h]=='\\' && delim=='"' && zLine[h+1]!=0 ) h++; in do_meta_command()
28830 zLine[h++] = 0; in do_meta_command()
28836 if( zLine[h] ) zLine[h++] = 0; in do_meta_command()
28839 azArg[nArg] = 0; in do_meta_command()
28843 if( nArg==0 ) return 0; /* no tokens, no error */ in do_meta_command()
28844 n = strlen30(azArg[0]); in do_meta_command()
28845 c = azArg[0][0]; in do_meta_command()
28849 if( c=='a' && cli_strncmp(azArg[0], "auth", n)==0 ){ in do_meta_command()
28855 open_db(p, 0); in do_meta_command()
28861 sqlite3_set_authorizer(p->db, 0, 0); in do_meta_command()
28868 if( c=='a' && cli_strncmp(azArg[0], "archive", n)==0 ){ in do_meta_command()
28869 open_db(p, 0); in do_meta_command()
28871 rc = arDotCommand(p, 0, azArg, nArg); in do_meta_command()
28876 if( (c=='b' && n>=3 && cli_strncmp(azArg[0], "backup", n)==0) in do_meta_command()
28877 || (c=='s' && n>=3 && cli_strncmp(azArg[0], "save", n)==0) in do_meta_command()
28879 const char *zDestFile = 0; in do_meta_command()
28880 const char *zDb = 0; in do_meta_command()
28884 int bAsync = 0; in do_meta_command()
28885 const char *zVfs = 0; in do_meta_command()
28886 failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]); in do_meta_command()
28889 if( z[0]=='-' ){ in do_meta_command()
28891 if( cli_strcmp(z, "-append")==0 ){ in do_meta_command()
28894 if( cli_strcmp(z, "-async")==0 ){ in do_meta_command()
28901 }else if( zDestFile==0 ){ in do_meta_command()
28903 }else if( zDb==0 ){ in do_meta_command()
28911 if( zDestFile==0 ){ in do_meta_command()
28915 if( zDb==0 ) zDb = "main"; in do_meta_command()
28925 0, 0, 0); in do_meta_command()
28927 open_db(p, 0); in do_meta_command()
28929 if( pBackup==0 ){ in do_meta_command()
28937 rc = 0; in do_meta_command()
28946 if( c=='b' && n>=3 && cli_strncmp(azArg[0], "bail", n)==0 ){ in do_meta_command()
28956 if( c=='b' && n>=3 && cli_strncmp(azArg[0], "binary", n)==0 ){ in do_meta_command()
28964 if( c=='b' && n>=3 && cli_strncmp(azArg[0], "breakpoint", n)==0 ){ in do_meta_command()
28969 if( c=='c' && cli_strcmp(azArg[0],"cd")==0 ){ in do_meta_command()
28990 if( c=='c' && n>=3 && cli_strncmp(azArg[0], "changes", n)==0 ){ in do_meta_command()
29004 if( c=='c' && n>=3 && cli_strncmp(azArg[0], "check", n)==0 ){ in do_meta_command()
29005 char *zRes = 0; in do_meta_command()
29010 }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){ in do_meta_command()
29012 }else if( testcase_glob(azArg[1],zRes)==0 ){ in do_meta_command()
29026 if( c=='c' && cli_strncmp(azArg[0], "clone", n)==0 ){ in do_meta_command()
29037 if( c=='c' && cli_strncmp(azArg[0], "connection", n)==0 ){ in do_meta_command()
29041 for(i=0; i<ArraySize(p->aAuxDb); i++){ in do_meta_command()
29043 if( p->aAuxDb[i].db==0 && p->pAuxDb!=&p->aAuxDb[i] ){ in do_meta_command()
29045 }else if( zFile==0 ){ in do_meta_command()
29047 }else if( zFile[0]==0 ){ in do_meta_command()
29052 }else if( p->aAuxDb[i].db!=0 ){ in do_meta_command()
29056 }else if( nArg==2 && IsDigit(azArg[1][0]) && azArg[1][1]==0 ){ in do_meta_command()
29057 int i = azArg[1][0] - '0'; in do_meta_command()
29058 if( p->pAuxDb != &p->aAuxDb[i] && i>=0 && i<ArraySize(p->aAuxDb) ){ in do_meta_command()
29062 p->pAuxDb->db = 0; in do_meta_command()
29064 }else if( nArg==3 && cli_strcmp(azArg[1], "close")==0 in do_meta_command()
29065 && IsDigit(azArg[2][0]) && azArg[2][1]==0 ){ in do_meta_command()
29066 int i = azArg[2][0] - '0'; in do_meta_command()
29067 if( i<0 || i>=ArraySize(p->aAuxDb) ){ in do_meta_command()
29075 p->aAuxDb[i].db = 0; in do_meta_command()
29084 && (cli_strncmp(azArg[0], "crlf", n)==0 in do_meta_command()
29085 || cli_strncmp(azArg[0], "crnl",n)==0) in do_meta_command()
29091 p->crlfMode = 0; in do_meta_command()
29097 if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){ in do_meta_command()
29098 char **azName = 0; in do_meta_command()
29099 int nName = 0; in do_meta_command()
29102 open_db(p, 0); in do_meta_command()
29103 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0); in do_meta_command()
29111 if( zSchema==0 || zFile==0 ) continue; in do_meta_command()
29120 for(i=0; i<nName; i++){ in do_meta_command()
29125 azName[i*2], z && z[0] ? z : "\"\"", bRdonly ? "r/o" : "r/w", in do_meta_command()
29134 if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbconfig", n)==0 ){ in do_meta_command()
29162 open_db(p, 0); in do_meta_command()
29163 for(ii=0; ii<ArraySize(aDbConfig); ii++){ in do_meta_command()
29164 if( nArg>1 && cli_strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue; in do_meta_command()
29166 sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0); in do_meta_command()
29180 if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbinfo", n)==0 ){ in do_meta_command()
29184 if( c=='r' && cli_strncmp(azArg[0], "recover", n)==0 ){ in do_meta_command()
29185 open_db(p, 0); in do_meta_command()
29190 if( c=='d' && cli_strncmp(azArg[0], "dump", n)==0 ){ in do_meta_command()
29191 char *zLike = 0; in do_meta_command()
29200 if( azArg[i][0]=='-' ){ in do_meta_command()
29202 if( z[0]=='-' ) z++; in do_meta_command()
29203 if( cli_strcmp(z,"preserve-rowids")==0 ){ in do_meta_command()
29214 if( cli_strcmp(z,"newlines")==0 ){ in do_meta_command()
29217 if( cli_strcmp(z,"data-only")==0 ){ in do_meta_command()
29220 if( cli_strcmp(z,"nosys")==0 ){ in do_meta_command()
29253 open_db(p, 0); in do_meta_command()
29256 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ in do_meta_command()
29263 p->writableSchema = 0; in do_meta_command()
29264 p->showHeader = 0; in do_meta_command()
29268 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0); in do_meta_command()
29269 p->nErr = 0; in do_meta_command()
29270 if( zLike==0 ) zLike = sqlite3_mprintf("true"); in do_meta_command()
29280 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ in do_meta_command()
29294 p->writableSchema = 0; in do_meta_command()
29296 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); in do_meta_command()
29297 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0); in do_meta_command()
29298 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ in do_meta_command()
29305 if( c=='e' && cli_strncmp(azArg[0], "echo", n)==0 ){ in do_meta_command()
29314 if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbtotxt", n)==0 ){ in do_meta_command()
29318 if( c=='e' && cli_strncmp(azArg[0], "eqp", n)==0 ){ in do_meta_command()
29320 p->autoEQPtest = 0; in do_meta_command()
29322 if( p->db ) sqlite3_exec(p->db, "PRAGMA vdbe_trace=OFF;", 0, 0, 0); in do_meta_command()
29323 p->autoEQPtrace = 0; in do_meta_command()
29325 if( cli_strcmp(azArg[1],"full")==0 ){ in do_meta_command()
29327 }else if( cli_strcmp(azArg[1],"trigger")==0 ){ in do_meta_command()
29330 }else if( cli_strcmp(azArg[1],"test")==0 ){ in do_meta_command()
29333 }else if( cli_strcmp(azArg[1],"trace")==0 ){ in do_meta_command()
29336 open_db(p, 0); in do_meta_command()
29337 sqlite3_exec(p->db, "SELECT name FROM sqlite_schema LIMIT 1", 0, 0, 0); in do_meta_command()
29338 sqlite3_exec(p->db, "PRAGMA vdbe_trace=ON;", 0, 0, 0); in do_meta_command()
29350 if( c=='e' && cli_strncmp(azArg[0], "exit", n)==0 ){ in do_meta_command()
29351 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc); in do_meta_command()
29358 if( c=='e' && cli_strncmp(azArg[0], "explain", n)==0 ){ in do_meta_command()
29361 if( cli_strcmp(azArg[1],"auto")==0 ){ in do_meta_command()
29370 p->autoExplain = 0; in do_meta_command()
29371 }else if( val==0 ){ in do_meta_command()
29373 p->autoExplain = 0; in do_meta_command()
29381 if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){ in do_meta_command()
29385 azArg[0]); in do_meta_command()
29388 open_db(p, 0); in do_meta_command()
29394 if( c=='f' && cli_strncmp(azArg[0], "filectrl", n)==0 ){ in do_meta_command()
29414 sqlite3_int64 iRes = 0; /* Integer result to display if rc2==1 */ in do_meta_command()
29415 int isOk = 0; /* 0: usage 1: %lld 2: no-result */ in do_meta_command()
29417 const char *zCmd = 0; in do_meta_command()
29418 const char *zSchema = 0; in do_meta_command()
29420 open_db(p, 0); in do_meta_command()
29423 if( zCmd[0]=='-' in do_meta_command()
29424 && (cli_strcmp(zCmd,"--schema")==0 || cli_strcmp(zCmd,"-schema")==0) in do_meta_command()
29434 if( zCmd[0]=='-' && zCmd[1] ){ in do_meta_command()
29436 if( zCmd[0]=='-' && zCmd[1] ) zCmd++; in do_meta_command()
29440 if( cli_strcmp(zCmd,"help")==0 ){ in do_meta_command()
29442 for(i=0; i<ArraySize(aCtrl); i++){ in do_meta_command()
29453 for(i=0; i<ArraySize(aCtrl); i++){ in do_meta_command()
29454 if( cli_strncmp(zCmd, aCtrl[i].zCtrlName, n2)==0 ){ in do_meta_command()
29455 if( filectrl<0 ){ in do_meta_command()
29466 if( filectrl<0 ){ in do_meta_command()
29507 char *z = 0; in do_meta_command()
29531 if( isOk==0 && iCtrl>=0 ){ in do_meta_command()
29542 if( c=='f' && cli_strncmp(azArg[0], "fullschema", n)==0 ){ in do_meta_command()
29544 int doStats = 0; in do_meta_command()
29546 data.showHeader = 0; in do_meta_command()
29557 open_db(p, 0); in do_meta_command()
29565 callback, &data, 0 in do_meta_command()
29572 -1, &pStmt, 0); in do_meta_command()
29578 if( doStats==0 ){ in do_meta_command()
29584 shell_exec(&data, "SELECT * FROM sqlite_stat1", 0); in do_meta_command()
29586 shell_exec(&data, "SELECT * FROM sqlite_stat4", 0); in do_meta_command()
29591 if( c=='h' && cli_strncmp(azArg[0], "headers", n)==0 ){ in do_meta_command()
29601 if( c=='h' && cli_strncmp(azArg[0], "help", n)==0 ){ in do_meta_command()
29604 if( n==0 ){ in do_meta_command()
29608 showHelp(p->out, 0); in do_meta_command()
29613 if( c=='i' && cli_strncmp(azArg[0], "import", n)==0 ){ in do_meta_command()
29614 char *zTable = 0; /* Insert data into this table */ in do_meta_command()
29615 char *zSchema = 0; /* Schema of zTable */ in do_meta_command()
29616 char *zFile = 0; /* Name of file to extra content from */ in do_meta_command()
29623 char *zSql = 0; /* An SQL statement */ in do_meta_command()
29626 int eVerbose = 0; /* Larger for more console output */ in do_meta_command()
29627 int nSkip = 0; /* Initial lines to skip */ in do_meta_command()
29629 char *zCreate = 0; /* CREATE TABLE statement text */ in do_meta_command()
29632 memset(&sCtx, 0, sizeof(sCtx)); in do_meta_command()
29641 if( z[0]=='-' && z[1]=='-' ) z++; in do_meta_command()
29642 if( z[0]!='-' ){ in do_meta_command()
29643 if( zFile==0 ){ in do_meta_command()
29645 }else if( zTable==0 ){ in do_meta_command()
29652 }else if( cli_strcmp(z,"-v")==0 ){ in do_meta_command()
29654 }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){ in do_meta_command()
29656 }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){ in do_meta_command()
29658 }else if( cli_strcmp(z,"-ascii")==0 ){ in do_meta_command()
29659 sCtx.cColSep = SEP_Unit[0]; in do_meta_command()
29660 sCtx.cRowSep = SEP_Record[0]; in do_meta_command()
29662 useOutputMode = 0; in do_meta_command()
29663 }else if( cli_strcmp(z,"-csv")==0 ){ in do_meta_command()
29667 useOutputMode = 0; in do_meta_command()
29674 if( zTable==0 ){ in do_meta_command()
29676 zFile==0 ? "FILE" : "TABLE"); in do_meta_command()
29680 seenInterrupt = 0; in do_meta_command()
29681 open_db(p, 0); in do_meta_command()
29686 if( nSep==0 ){ in do_meta_command()
29696 if( nSep==0 ){ in do_meta_command()
29701 && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 in do_meta_command()
29715 sCtx.cColSep = (u8)p->colSeparator[0]; in do_meta_command()
29716 sCtx.cRowSep = (u8)p->rowSeparator[0]; in do_meta_command()
29720 if( sCtx.zFile[0]=='|' ){ in do_meta_command()
29733 if( sCtx.in==0 ){ in do_meta_command()
29739 zSep[1] = 0; in do_meta_command()
29740 zSep[0] = sCtx.cColSep; in do_meta_command()
29744 zSep[0] = sCtx.cRowSep; in do_meta_command()
29749 if( sCtx.z==0 ){ in do_meta_command()
29754 while( (nSkip--)>0 ){ in do_meta_command()
29757 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */ in do_meta_command()
29758 if( sqlite3_table_column_metadata(p->db, zSchema, zTable,0,0,0,0,0,0) in do_meta_command()
29759 && 0==db_int(p->db, "SELECT count(*) FROM \"%w\".sqlite_schema" in do_meta_command()
29764 sqlite3 *dbCols = 0; in do_meta_command()
29765 char *zRenames = 0; in do_meta_command()
29770 zAutoColumn(sCtx.z, &dbCols, 0); in do_meta_command()
29773 zColDefs = zAutoColumn(0, &dbCols, &zRenames); in do_meta_command()
29774 if( zRenames!=0 ){ in do_meta_command()
29780 assert(dbCols==0); in do_meta_command()
29781 if( zColDefs==0 ){ in do_meta_command()
29789 if( zCreate==0 ){ in do_meta_command()
29796 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0); in do_meta_command()
29802 zCreate = 0; in do_meta_command()
29811 if( zSql==0 ){ in do_meta_command()
29815 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
29817 zSql = 0; in do_meta_command()
29826 nCol = sqlite3_column_int(pStmt, 0); in do_meta_command()
29828 nCol = 0; in do_meta_command()
29831 pStmt = 0; in do_meta_command()
29832 if( nCol==0 ) return 0; /* no columns, no error */ in do_meta_command()
29834 nByte = 64 /* space for "INSERT INTO", "VALUES(", ")\0" */ in do_meta_command()
29835 + (zSchema ? strlen(zSchema)*2 + 2: 0) /* Quoted schema name */ in do_meta_command()
29839 if( zSql==0 ){ in do_meta_command()
29855 zSql[j] = 0; in do_meta_command()
29860 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
29862 zSql = 0; in do_meta_command()
29871 if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0); in do_meta_command()
29874 for(i=0; i<nCol; i++){ in do_meta_command()
29880 if( z==0 && i==0 ) break; in do_meta_command()
29886 if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break; in do_meta_command()
29892 if( z==0 && (xRead==csv_read_one_field) && i==nCol-1 && i>0 ){ in do_meta_command()
29928 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0); in do_meta_command()
29929 if( eVerbose>0 ){ in do_meta_command()
29938 if( c=='i' && cli_strncmp(azArg[0], "imposter", n)==0 ){ in do_meta_command()
29940 char *zCollist = 0; in do_meta_command()
29942 int tnum = 0; in do_meta_command()
29943 int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */ in do_meta_command()
29944 int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */ in do_meta_command()
29952 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){ in do_meta_command()
29965 open_db(p, 0); in do_meta_command()
29967 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1); in do_meta_command()
29971 "SELECT rootpage, 0 FROM sqlite_schema" in do_meta_command()
29979 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
29982 tnum = sqlite3_column_int(pStmt, 0); in do_meta_command()
29987 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
29989 i = 0; in do_meta_command()
29994 if( zCol==0 ){ in do_meta_command()
30002 if( isWO && lenPK==0 && sqlite3_column_int(pStmt,5)==0 && zCollist ){ in do_meta_command()
30005 if( zCollist==0 ){ in do_meta_command()
30012 if( i==0 || tnum==0 ){ in do_meta_command()
30018 if( lenPK==0 ) lenPK = 100000; in do_meta_command()
30025 rc = sqlite3_exec(p->db, zSql, 0, 0, 0); in do_meta_command()
30026 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0); in do_meta_command()
30044 if( c=='i' && cli_strncmp(azArg[0], "intck", n)==0 ){ in do_meta_command()
30045 i64 iArg = 0; in do_meta_command()
30048 if( iArg==0 ) iArg = -1; in do_meta_command()
30050 if( (nArg!=1 && nArg!=2) || iArg<0 ){ in do_meta_command()
30055 open_db(p, 0); in do_meta_command()
30060 if( c=='i' && cli_strncmp(azArg[0], "iotrace", n)==0 ){ in do_meta_command()
30063 iotrace = 0; in do_meta_command()
30065 sqlite3IoTrace = 0; in do_meta_command()
30066 }else if( cli_strcmp(azArg[1], "-")==0 ){ in do_meta_command()
30071 if( iotrace==0 ){ in do_meta_command()
30073 sqlite3IoTrace = 0; in do_meta_command()
30082 if( c=='l' && n>=5 && cli_strncmp(azArg[0], "limits", n)==0 ){ in do_meta_command()
30101 open_db(p, 0); in do_meta_command()
30103 for(i=0; i<ArraySize(aLimit); i++){ in do_meta_command()
30114 for(i=0; i<ArraySize(aLimit); i++){ in do_meta_command()
30115 if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){ in do_meta_command()
30116 if( iLimit<0 ){ in do_meta_command()
30125 if( iLimit<0 ){ in do_meta_command()
30141 if( c=='l' && n>2 && cli_strncmp(azArg[0], "lint", n)==0 ){ in do_meta_command()
30142 open_db(p, 0); in do_meta_command()
30147 if( c=='l' && cli_strncmp(azArg[0], "load", n)==0 ){ in do_meta_command()
30149 char *zErrMsg = 0; in do_meta_command()
30151 if( nArg<2 || azArg[1][0]==0 ){ in do_meta_command()
30158 zProc = nArg>=3 ? azArg[2] : 0; in do_meta_command()
30159 open_db(p, 0); in do_meta_command()
30169 if( c=='l' && cli_strncmp(azArg[0], "log", n)==0 ){ in do_meta_command()
30176 && cli_strcmp(zFile,"on")!=0 in do_meta_command()
30177 && cli_strcmp(zFile,"off")!=0 in do_meta_command()
30184 if( cli_strcmp(zFile,"on")==0 ) zFile = "stdout"; in do_meta_command()
30189 if( c=='m' && cli_strncmp(azArg[0], "mode", n)==0 ){ in do_meta_command()
30190 const char *zMode = 0; in do_meta_command()
30191 const char *zTabname = 0; in do_meta_command()
30193 int chng = 0; /* 0x01: change to cmopts. 0x02: Any other change */ in do_meta_command()
30210 cmOpts.bQuote = 0; in do_meta_command()
30216 for(k=0; k<ArraySize(shell_EscModeNames); k++){ in do_meta_command()
30217 if( sqlite3_stricmp(zEsc,shell_EscModeNames[k])==0 ){ in do_meta_command()
30226 for(k=0; k<ArraySize(shell_EscModeNames); k++){ in do_meta_command()
30233 }else if( zMode==0 ){ in do_meta_command()
30239 if( cli_strcmp(z, "qbox")==0 ){ in do_meta_command()
30244 }else if( zTabname==0 ){ in do_meta_command()
30246 }else if( z[0]=='-' ){ in do_meta_command()
30283 if( zMode==0 ){ in do_meta_command()
30285 if( (chng&1)==0 ) cmOpts = p->cmOpts; in do_meta_command()
30288 if( cli_strncmp(zMode,"lines",n2)==0 ){ in do_meta_command()
30291 }else if( cli_strncmp(zMode,"columns",n2)==0 ){ in do_meta_command()
30293 if( (p->shellFlgs & SHFLG_HeaderSet)==0 ){ in do_meta_command()
30298 }else if( cli_strncmp(zMode,"list",n2)==0 ){ in do_meta_command()
30302 }else if( cli_strncmp(zMode,"html",n2)==0 ){ in do_meta_command()
30304 }else if( cli_strncmp(zMode,"tcl",n2)==0 ){ in do_meta_command()
30308 }else if( cli_strncmp(zMode,"csv",n2)==0 ){ in do_meta_command()
30312 }else if( cli_strncmp(zMode,"tabs",n2)==0 ){ in do_meta_command()
30315 }else if( cli_strncmp(zMode,"insert",n2)==0 ){ in do_meta_command()
30323 }else if( cli_strncmp(zMode,"quote",n2)==0 ){ in do_meta_command()
30327 }else if( cli_strncmp(zMode,"ascii",n2)==0 ){ in do_meta_command()
30331 }else if( cli_strncmp(zMode,"markdown",n2)==0 ){ in do_meta_command()
30334 }else if( cli_strncmp(zMode,"table",n2)==0 ){ in do_meta_command()
30337 }else if( cli_strncmp(zMode,"box",n2)==0 ){ in do_meta_command()
30340 }else if( cli_strncmp(zMode,"count",n2)==0 ){ in do_meta_command()
30342 }else if( cli_strncmp(zMode,"off",n2)==0 ){ in do_meta_command()
30344 }else if( cli_strncmp(zMode,"json",n2)==0 ){ in do_meta_command()
30356 if( c=='n' && cli_strcmp(azArg[0], "nonce")==0 ){ in do_meta_command()
30360 }else if( p->zNonce==0 || cli_strcmp(azArg[1],p->zNonce)!=0 ){ in do_meta_command()
30365 p->bSafeMode = 0; in do_meta_command()
30366 return 0; /* Return immediately to bypass the safe mode reset in do_meta_command()
30372 if( c=='n' && cli_strncmp(azArg[0], "nullvalue", n)==0 ){ in do_meta_command()
30382 if( c=='o' && cli_strncmp(azArg[0], "open", n)==0 && n>=2 ){ in do_meta_command()
30383 const char *zFN = 0; /* Pointer to constant filename */ in do_meta_command()
30384 char *zNewFilename = 0; /* Name of the database file to open */ in do_meta_command()
30386 int newFlag = 0; /* True to delete file before opening */ in do_meta_command()
30415 if( z[0]=='-' ){ in do_meta_command()
30431 p->db = 0; in do_meta_command()
30432 p->pAuxDb->zDbFilename = 0; in do_meta_command()
30434 p->pAuxDb->zFreeOnClose = 0; in do_meta_command()
30436 p->openFlags = 0; in do_meta_command()
30437 p->szMax = 0; in do_meta_command()
30446 && cli_strcmp(zFN,":memory:")!=0 in do_meta_command()
30457 zNewFilename = 0; in do_meta_command()
30461 if( p->db==0 ){ in do_meta_command()
30468 if( p->db==0 ){ in do_meta_command()
30470 p->pAuxDb->zDbFilename = 0; in do_meta_command()
30471 open_db(p, 0); in do_meta_command()
30477 && (cli_strncmp(azArg[0], "output", n)==0 in do_meta_command()
30478 || cli_strncmp(azArg[0], "once", n)==0)) in do_meta_command()
30479 || (c=='e' && n==5 && cli_strcmp(azArg[0],"excel")==0) in do_meta_command()
30480 || (c=='w' && n==3 && cli_strcmp(azArg[0],"www")==0) in do_meta_command()
30482 char *zFile = 0; in do_meta_command()
30484 int eMode = 0; /* 0: .outout/.once, 'x'=.excel, 'w'=.www */ in do_meta_command()
30485 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */ in do_meta_command()
30486 int bPlain = 0; /* --plain option */ in do_meta_command()
30488 const char *zBom = 0; in do_meta_command()
30490 failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]); in do_meta_command()
30497 }else if( cli_strncmp(azArg[0],"once",n)==0 ){ in do_meta_command()
30502 if( z[0]=='-' ){ in do_meta_command()
30504 if( cli_strcmp(z,"-bom")==0 ){ in do_meta_command()
30506 }else if( cli_strcmp(z,"-plain")==0 ){ in do_meta_command()
30508 }else if( c=='o' && cli_strcmp(z,"-x")==0 ){ in do_meta_command()
30510 }else if( c=='o' && cli_strcmp(z,"-e")==0 ){ in do_meta_command()
30512 }else if( c=='o' && cli_strcmp(z,"-w")==0 ){ in do_meta_command()
30517 showHelp(p->out, azArg[0]); in do_meta_command()
30521 }else if( zFile==0 && eMode==0 ){ in do_meta_command()
30522 if( cli_strcmp(z, "off")==0 ){ in do_meta_command()
30531 if( zFile && zFile[0]=='|' ){ in do_meta_command()
30538 showHelp(p->out, azArg[0]); in do_meta_command()
30544 if( zFile==0 ){ in do_meta_command()
30551 p->outCount = 0; in do_meta_command()
30582 if( zFile[0]=='|' ){ in do_meta_command()
30589 if( pfPipe==0 ){ in do_meta_command()
30601 if( pfFile==0 ){ in do_meta_command()
30602 if( cli_strcmp(zFile,"off")!=0 ){ in do_meta_command()
30623 if( c=='p' && n>=3 && cli_strncmp(azArg[0], "parameter", n)==0 ){ in do_meta_command()
30624 open_db(p,0); in do_meta_command()
30630 if( nArg==2 && cli_strcmp(azArg[1],"clear")==0 ){ in do_meta_command()
30632 0, 0, 0); in do_meta_command()
30638 if( nArg==2 && cli_strcmp(azArg[1],"list")==0 ){ in do_meta_command()
30639 sqlite3_stmt *pStmt = 0; in do_meta_command()
30641 int len = 0; in do_meta_command()
30644 "FROM temp.sqlite_parameters;", -1, &pStmt, 0); in do_meta_command()
30646 len = sqlite3_column_int(pStmt, 0); in do_meta_command()
30650 pStmt = 0; in do_meta_command()
30654 "FROM temp.sqlite_parameters;", -1, &pStmt, 0); in do_meta_command()
30657 "%-*s %s\n", len, sqlite3_column_text(pStmt,0), in do_meta_command()
30668 if( nArg==2 && cli_strcmp(azArg[1],"init")==0 ){ in do_meta_command()
30678 if( nArg==4 && cli_strcmp(azArg[1],"set")==0 ){ in do_meta_command()
30689 pStmt = 0; in do_meta_command()
30690 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
30694 pStmt = 0; in do_meta_command()
30699 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
30704 pStmt = 0; in do_meta_command()
30717 if( nArg==3 && cli_strcmp(azArg[1],"unset")==0 ){ in do_meta_command()
30721 sqlite3_exec(p->db, zSql, 0, 0, 0); in do_meta_command()
30729 if( c=='p' && n>=3 && cli_strncmp(azArg[0], "print", n)==0 ){ in do_meta_command()
30739 if( c=='p' && n>=3 && cli_strncmp(azArg[0], "progress", n)==0 ){ in do_meta_command()
30741 int nn = 0; in do_meta_command()
30742 p->flgProgress = 0; in do_meta_command()
30743 p->mxProgress = 0; in do_meta_command()
30744 p->nProgress = 0; in do_meta_command()
30747 if( z[0]=='-' ){ in do_meta_command()
30749 if( z[0]=='-' ) z++; in do_meta_command()
30750 if( cli_strcmp(z,"quiet")==0 || cli_strcmp(z,"q")==0 ){ in do_meta_command()
30754 if( cli_strcmp(z,"reset")==0 ){ in do_meta_command()
30758 if( cli_strcmp(z,"once")==0 ){ in do_meta_command()
30762 if( cli_strcmp(z,"limit")==0 ){ in do_meta_command()
30779 open_db(p, 0); in do_meta_command()
30784 if( c=='p' && cli_strncmp(azArg[0], "prompt", n)==0 ){ in do_meta_command()
30794 if( c=='q' && cli_strncmp(azArg[0], "quit", n)==0 ){ in do_meta_command()
30800 if( c=='r' && n>=3 && cli_strncmp(azArg[0], "read", n)==0 ){ in do_meta_command()
30809 if( azArg[1][0]=='|' ){ in do_meta_command()
30815 if( p->in==0 ){ in do_meta_command()
30823 }else if( (p->in = openChrSource(azArg[1]))==0 ){ in do_meta_command()
30836 if( c=='r' && n>=3 && cli_strncmp(azArg[0], "restore", n)==0 ){ in do_meta_command()
30841 int nTimeout = 0; in do_meta_command()
30861 open_db(p, 0); in do_meta_command()
30863 if( pBackup==0 ){ in do_meta_command()
30877 rc = 0; in do_meta_command()
30890 (cli_strncmp(azArg[0], "scanstats", n)==0 || in do_meta_command()
30891 cli_strncmp(azArg[0], "scanstatus", n)==0) in do_meta_command()
30894 if( cli_strcmp(azArg[1], "vm")==0 ){ in do_meta_command()
30897 if( cli_strcmp(azArg[1], "est")==0 ){ in do_meta_command()
30902 open_db(p, 0); in do_meta_command()
30904 p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, p->scanstatsOn, (int*)0 in do_meta_command()
30919 if( c=='s' && cli_strncmp(azArg[0], "schema", n)==0 ){ in do_meta_command()
30922 char *zErrMsg = 0; in do_meta_command()
30924 const char *zName = 0; in do_meta_command()
30925 int iSchema = 0; in do_meta_command()
30926 int bDebug = 0; in do_meta_command()
30927 int bNoSystemTabs = 0; in do_meta_command()
30930 open_db(p, 0); in do_meta_command()
30932 data.showHeader = 0; in do_meta_command()
30942 }else if( azArg[ii][0]=='-' ){ in do_meta_command()
30946 }else if( zName==0 ){ in do_meta_command()
30954 if( zName!=0 ){ in do_meta_command()
30955 int isSchema = sqlite3_strlike(zName, "sqlite_master", '\\')==0 in do_meta_command()
30956 || sqlite3_strlike(zName, "sqlite_schema", '\\')==0 in do_meta_command()
30957 || sqlite3_strlike(zName,"sqlite_temp_master", '\\')==0 in do_meta_command()
30958 || sqlite3_strlike(zName,"sqlite_temp_schema", '\\')==0; in do_meta_command()
30961 new_argv[0] = sqlite3_mprintf( in do_meta_command()
30969 shell_check_oom(new_argv[0]); in do_meta_command()
30970 new_argv[1] = 0; in do_meta_command()
30971 new_colv[0] = "sql"; in do_meta_command()
30972 new_colv[1] = 0; in do_meta_command()
30974 sqlite3_free(new_argv[0]); in do_meta_command()
30978 sqlite3_stmt *pStmt = 0; in do_meta_command()
30980 -1, &pStmt, 0); in do_meta_command()
30987 appendText(&sSelect, "SELECT sql FROM", 0); in do_meta_command()
30988 iSchema = 0; in do_meta_command()
30990 const char *zDb = (const char*)sqlite3_column_text(pStmt, 0); in do_meta_command()
30993 appendText(&sSelect, zDiv, 0); in do_meta_command()
30995 appendText(&sSelect, "SELECT shell_add_schema(sql,", 0); in do_meta_command()
30996 if( sqlite3_stricmp(zDb, "main")!=0 ){ in do_meta_command()
30999 appendText(&sSelect, "NULL", 0); in do_meta_command()
31001 appendText(&sSelect, ",name) AS sql, type, tbl_name, name, rowid,", 0); in do_meta_command()
31002 appendText(&sSelect, zScNum, 0); in do_meta_command()
31003 appendText(&sSelect, " AS snum, ", 0); in do_meta_command()
31005 appendText(&sSelect, " AS sname FROM ", 0); in do_meta_command()
31007 appendText(&sSelect, ".sqlite_schema", 0); in do_meta_command()
31015 0); in do_meta_command()
31018 appendText(&sSelect, ") WHERE ", 0); in do_meta_command()
31023 bGlob = strchr(zName, '*') != 0 || strchr(zName, '?') != 0 || in do_meta_command()
31024 strchr(zName, '[') != 0; in do_meta_command()
31026 appendText(&sSelect, "lower(printf('%s.%s',sname,tbl_name))", 0); in do_meta_command()
31028 appendText(&sSelect, "lower(tbl_name)", 0); in do_meta_command()
31030 appendText(&sSelect, bGlob ? " GLOB " : " LIKE ", 0); in do_meta_command()
31031 appendText(&sSelect, zQarg, 0); in do_meta_command()
31033 appendText(&sSelect, " ESCAPE '\\' ", 0); in do_meta_command()
31035 appendText(&sSelect, " AND ", 0); in do_meta_command()
31039 appendText(&sSelect, "name NOT LIKE 'sqlite_%%' AND ", 0); in do_meta_command()
31042 " ORDER BY snum, rowid", 0); in do_meta_command()
31058 rc = 0; in do_meta_command()
31062 if( (c=='s' && n==11 && cli_strncmp(azArg[0], "selecttrace", n)==0) in do_meta_command()
31063 || (c=='t' && n==9 && cli_strncmp(azArg[0], "treetrace", n)==0) in do_meta_command()
31065 unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff; in do_meta_command()
31070 if( c=='s' && cli_strncmp(azArg[0],"session",n)==0 && n>=3 ){ in do_meta_command()
31072 OpenSession *pSession = &pAuxDb->aSession[0]; in do_meta_command()
31074 int iSes = 0; in do_meta_command()
31078 open_db(p, 0); in do_meta_command()
31080 for(iSes=0; iSes<pAuxDb->nSession; iSes++){ in do_meta_command()
31081 if( cli_strcmp(pAuxDb->aSession[iSes].zName, azArg[1])==0 ) break; in do_meta_command()
31088 pSession = &pAuxDb->aSession[0]; in do_meta_command()
31089 iSes = 0; in do_meta_command()
31097 if( cli_strcmp(azCmd[0],"attach")==0 ){ in do_meta_command()
31099 if( pSession->p==0 ){ in do_meta_command()
31107 rc = 0; in do_meta_command()
31116 if( cli_strcmp(azCmd[0],"changeset")==0 in do_meta_command()
31117 || cli_strcmp(azCmd[0],"patchset")==0 in do_meta_command()
31119 FILE *out = 0; in do_meta_command()
31120 failIfSafeMode(p, "cannot run \".session %s\" in safe mode", azCmd[0]); in do_meta_command()
31122 if( pSession->p==0 ) goto session_not_open; in do_meta_command()
31124 if( out==0 ){ in do_meta_command()
31130 if( azCmd[0][0]=='c' ){ in do_meta_command()
31137 rc = 0; in do_meta_command()
31152 if( cli_strcmp(azCmd[0], "close")==0 ){ in do_meta_command()
31163 if( cli_strcmp(azCmd[0], "enable")==0 ){ in do_meta_command()
31177 if( cli_strcmp(azCmd[0], "filter")==0 ){ in do_meta_command()
31181 for(ii=0; ii<pSession->nFilter; ii++){ in do_meta_command()
31185 nByte = sizeof(pSession->azFilter[0])*(nCmd-1); in do_meta_command()
31199 if( cli_strcmp(azCmd[0], "indirect")==0 ){ in do_meta_command()
31213 if( cli_strcmp(azCmd[0], "isempty")==0 ){ in do_meta_command()
31226 if( cli_strcmp(azCmd[0],"list")==0 ){ in do_meta_command()
31227 for(i=0; i<pAuxDb->nSession; i++){ in do_meta_command()
31236 if( cli_strcmp(azCmd[0],"open")==0 ){ in do_meta_command()
31240 if( zName[0]==0 ) goto session_syntax_error; in do_meta_command()
31241 for(i=0; i<pAuxDb->nSession; i++){ in do_meta_command()
31242 if( cli_strcmp(pAuxDb->aSession[i].zName,zName)==0 ){ in do_meta_command()
31256 rc = 0; in do_meta_command()
31259 pSession->nFilter = 0; in do_meta_command()
31274 if( c=='s' && n>=10 && cli_strncmp(azArg[0], "selftest-", 9)==0 ){ in do_meta_command()
31275 if( cli_strncmp(azArg[0]+9, "boolean", n-9)==0 ){ in do_meta_command()
31279 sqlite3_fprintf(p->out, "%s: %d 0x%x\n", azArg[i], v, v); in do_meta_command()
31282 if( cli_strncmp(azArg[0]+9, "integer", n-9)==0 ){ in do_meta_command()
31287 sqlite3_snprintf(sizeof(zBuf),zBuf,"%s: %lld 0x%llx\n", azArg[i],v,v); in do_meta_command()
31294 if( c=='s' && n>=4 && cli_strncmp(azArg[0],"selftest",n)==0 ){ in do_meta_command()
31295 int bIsInit = 0; /* True to initialize the SELFTEST table */ in do_meta_command()
31296 int bVerbose = 0; /* Verbose output */ in do_meta_command()
31299 int nTest = 0; /* Number of tests runs */ in do_meta_command()
31300 int nErr = 0; /* Number of errors seen */ in do_meta_command()
31302 sqlite3_stmt *pStmt = 0; /* Query against the SELFTEST table */ in do_meta_command()
31304 open_db(p,0); in do_meta_command()
31307 if( z[0]=='-' && z[1]=='-' ) z++; in do_meta_command()
31308 if( cli_strcmp(z,"-init")==0 ){ in do_meta_command()
31311 if( cli_strcmp(z,"-v")==0 ){ in do_meta_command()
31316 "Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); in do_meta_command()
31322 if( sqlite3_table_column_metadata(p->db,"main","selftest",0,0,0,0,0,0) in do_meta_command()
31324 bSelftestExists = 0; in do_meta_command()
31333 appendText(&str, "x", 0); in do_meta_command()
31334 for(k=bSelftestExists; k>=0; k--){ in do_meta_command()
31338 -1, &pStmt, 0); in do_meta_command()
31341 "VALUES(0,'memo','Missing SELFTEST table - default checks only','')," in do_meta_command()
31343 -1, &pStmt, 0); in do_meta_command()
31352 int tno = sqlite3_column_int(pStmt, 0); in do_meta_command()
31357 if( zOp==0 ) continue; in do_meta_command()
31358 if( zSql==0 ) continue; in do_meta_command()
31359 if( zAns==0 ) continue; in do_meta_command()
31360 k = 0; in do_meta_command()
31361 if( bVerbose>0 ){ in do_meta_command()
31364 if( cli_strcmp(zOp,"memo")==0 ){ in do_meta_command()
31367 if( cli_strcmp(zOp,"run")==0 ){ in do_meta_command()
31368 char *zErrMsg = 0; in do_meta_command()
31369 str.n = 0; in do_meta_command()
31370 str.z[0] = 0; in do_meta_command()
31381 }else if( cli_strcmp(zAns,str.z)!=0 ){ in do_meta_command()
31401 if( c=='s' && cli_strncmp(azArg[0], "separator", n)==0 ){ in do_meta_command()
31416 if( c=='s' && n>=4 && cli_strncmp(azArg[0],"sha3sum",n)==0 ){ in do_meta_command()
31417 const char *zLike = 0; /* Which table to checksum. 0 means everything */ in do_meta_command()
31419 int bSchema = 0; /* Also hash the schema */ in do_meta_command()
31420 int bSeparate = 0; /* Hash each table separately */ in do_meta_command()
31422 int bDebug = 0; /* Only show the query that would have run */ in do_meta_command()
31428 open_db(p, 0); in do_meta_command()
31431 if( z[0]=='-' ){ in do_meta_command()
31433 if( z[0]=='-' ) z++; in do_meta_command()
31434 if( cli_strcmp(z,"schema")==0 ){ in do_meta_command()
31437 if( cli_strcmp(z,"sha3-224")==0 || cli_strcmp(z,"sha3-256")==0 in do_meta_command()
31438 || cli_strcmp(z,"sha3-384")==0 || cli_strcmp(z,"sha3-512")==0 in do_meta_command()
31442 if( cli_strcmp(z,"debug")==0 ){ in do_meta_command()
31447 "Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); in do_meta_command()
31448 showHelp(p->out, azArg[0]); in do_meta_command()
31459 if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1; in do_meta_command()
31464 " WHERE type='table' AND coalesce(rootpage,0)>1" in do_meta_command()
31469 " WHERE type='table' AND coalesce(rootpage,0)>1" in do_meta_command()
31473 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); in do_meta_command()
31476 appendText(&sSql, "WITH [sha3sum$query](a,b) AS(",0); in do_meta_command()
31479 const char *zTab = (const char*)sqlite3_column_text(pStmt,0); in do_meta_command()
31480 if( zTab==0 ) continue; in do_meta_command()
31481 if( zLike && sqlite3_strlike(zLike, zTab, 0)!=0 ) continue; in do_meta_command()
31482 if( cli_strncmp(zTab, "sqlite_",7)!=0 ){ in do_meta_command()
31483 appendText(&sQuery,"SELECT * FROM ", 0); in do_meta_command()
31485 appendText(&sQuery," NOT INDEXED;", 0); in do_meta_command()
31486 }else if( cli_strcmp(zTab, "sqlite_schema")==0 ){ in do_meta_command()
31488 " ORDER BY name;", 0); in do_meta_command()
31489 }else if( cli_strcmp(zTab, "sqlite_sequence")==0 ){ in do_meta_command()
31491 " ORDER BY name;", 0); in do_meta_command()
31492 }else if( cli_strcmp(zTab, "sqlite_stat1")==0 ){ in do_meta_command()
31494 " ORDER BY tbl,idx;", 0); in do_meta_command()
31495 }else if( cli_strcmp(zTab, "sqlite_stat4")==0 ){ in do_meta_command()
31496 appendText(&sQuery, "SELECT * FROM ", 0); in do_meta_command()
31497 appendText(&sQuery, zTab, 0); in do_meta_command()
31498 appendText(&sQuery, " ORDER BY tbl, idx, rowid;\n", 0); in do_meta_command()
31500 appendText(&sSql, zSep, 0); in do_meta_command()
31502 sQuery.n = 0; in do_meta_command()
31503 appendText(&sSql, ",", 0); in do_meta_command()
31527 shell_exec(p, zSql, 0); in do_meta_command()
31534 "WHERE type='table' AND coalesce(rootpage,0)>1\n" in do_meta_command()
31556 lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0); in do_meta_command()
31559 ** user does cruel and unnatural things like ".limit expr_depth 0". */ in do_meta_command()
31565 const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0); in do_meta_command()
31567 lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0); in do_meta_command()
31573 double countIrreversible = sqlite3_column_double(pCheckStmt, 0); in do_meta_command()
31574 if( countIrreversible>0 ){ in do_meta_command()
31595 && (cli_strncmp(azArg[0], "shell", n)==0 in do_meta_command()
31596 || cli_strncmp(azArg[0],"system",n)==0) in do_meta_command()
31600 failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]); in do_meta_command()
31606 zCmd = sqlite3_mprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]); in do_meta_command()
31607 for(i=2; i<nArg && zCmd!=0; i++){ in do_meta_command()
31608 zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"", in do_meta_command()
31612 x = zCmd!=0 ? system(zCmd) : 1; in do_meta_command()
31619 if( c=='s' && cli_strncmp(azArg[0], "show", n)==0 ){ in do_meta_command()
31634 azBool[p->showHeader!=0]); in do_meta_command()
31658 case 0: zOut = "off"; break; in do_meta_command()
31665 for (i=0;i<p->nWidth;i++) { in do_meta_command()
31673 if( c=='s' && cli_strncmp(azArg[0], "stats", n)==0 ){ in do_meta_command()
31675 if( cli_strcmp(azArg[1],"stmt")==0 ){ in do_meta_command()
31677 }else if( cli_strcmp(azArg[1],"vmstep")==0 ){ in do_meta_command()
31683 display_stats(p->db, p, 0); in do_meta_command()
31690 if( (c=='t' && n>1 && cli_strncmp(azArg[0], "tables", n)==0) in do_meta_command()
31691 || (c=='i' && (cli_strncmp(azArg[0], "indices", n)==0 in do_meta_command()
31692 || cli_strncmp(azArg[0], "indexes", n)==0) ) in do_meta_command()
31700 open_db(p, 0); in do_meta_command()
31701 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0); in do_meta_command()
31716 for(ii=0; sqlite3_step(pStmt)==SQLITE_ROW; ii++){ in do_meta_command()
31718 if( zDbName==0 ) continue; in do_meta_command()
31719 if( s.z && s.z[0] ) appendText(&s, " UNION ALL ", 0); in do_meta_command()
31720 if( sqlite3_stricmp(zDbName, "main")==0 ){ in do_meta_command()
31721 appendText(&s, "SELECT name FROM ", 0); in do_meta_command()
31723 appendText(&s, "SELECT ", 0); in do_meta_command()
31725 appendText(&s, "||'.'||name FROM ", 0); in do_meta_command()
31728 appendText(&s, ".sqlite_schema ", 0); in do_meta_command()
31732 " AND name LIKE ?1", 0); in do_meta_command()
31735 " AND tbl_name LIKE ?1", 0); in do_meta_command()
31740 appendText(&s, " ORDER BY 1", 0); in do_meta_command()
31741 rc = sqlite3_prepare_v2(p->db, s.z, -1, &pStmt, 0); in do_meta_command()
31748 nRow = nAlloc = 0; in do_meta_command()
31749 azResult = 0; in do_meta_command()
31759 azNew = sqlite3_realloc64(azResult, sizeof(azResult[0])*n2); in do_meta_command()
31764 azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0)); in do_meta_command()
31773 if( rc==0 && nRow>0 ){ in do_meta_command()
31774 int len, maxlen = 0; in do_meta_command()
31777 for(i=0; i<nRow; i++){ in do_meta_command()
31784 for(i=0; i<nPrintRow; i++){ in do_meta_command()
31794 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]); in do_meta_command()
31800 if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){ in do_meta_command()
31803 if( p->out==0 ){ in do_meta_command()
31815 if( c=='t' && n>=8 && cli_strncmp(azArg[0], "testctrl", n)==0 ){ in do_meta_command()
31826 {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" }, in do_meta_command()
31827 {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" }, in do_meta_command()
31829 {"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" }, in do_meta_command()
31831 {"internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" }, in do_meta_command()
31832 {"json_selfcheck", SQLITE_TESTCTRL_JSON_SELFCHECK ,0,"BOOLEAN" }, in do_meta_command()
31833 {"localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,0,"BOOLEAN" }, in do_meta_command()
31835 {"optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS,0,"DISABLE-MASK ..."}, in do_meta_command()
31837 {"parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE,0,"" }, in do_meta_command()
31840 {"prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE,0, "" }, in do_meta_command()
31841 {"prng_save", SQLITE_TESTCTRL_PRNG_SAVE, 0, "" }, in do_meta_command()
31842 {"prng_seed", SQLITE_TESTCTRL_PRNG_SEED, 0, "SEED ?db?" }, in do_meta_command()
31843 {"seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" }, in do_meta_command()
31844 {"sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" }, in do_meta_command()
31849 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */ in do_meta_command()
31850 int isOk = 0; in do_meta_command()
31852 const char *zCmd = 0; in do_meta_command()
31854 open_db(p, 0); in do_meta_command()
31858 if( zCmd[0]=='-' && zCmd[1] ){ in do_meta_command()
31860 if( zCmd[0]=='-' && zCmd[1] ) zCmd++; in do_meta_command()
31864 if( cli_strcmp(zCmd,"help")==0 ){ in do_meta_command()
31866 for(i=0; i<ArraySize(aCtrl); i++){ in do_meta_command()
31878 for(i=0; i<ArraySize(aCtrl); i++){ in do_meta_command()
31880 if( cli_strncmp(zCmd, aCtrl[i].zCtrlName, n2)==0 ){ in do_meta_command()
31881 if( testctrl<0 ){ in do_meta_command()
31892 if( testctrl<0 ){ in do_meta_command()
31913 { 0x00000001, 1, "QueryFlattener" }, in do_meta_command()
31914 { 0x00000001, 0, "Flatten" }, in do_meta_command()
31915 { 0x00000002, 1, "WindowFunc" }, in do_meta_command()
31916 { 0x00000004, 1, "GroupByOrder" }, in do_meta_command()
31917 { 0x00000008, 1, "FactorOutConst" }, in do_meta_command()
31918 { 0x00000010, 1, "DistinctOpt" }, in do_meta_command()
31919 { 0x00000020, 1, "CoverIdxScan" }, in do_meta_command()
31920 { 0x00000040, 1, "OrderByIdxJoin" }, in do_meta_command()
31921 { 0x00000080, 1, "Transitive" }, in do_meta_command()
31922 { 0x00000100, 1, "OmitNoopJoin" }, in do_meta_command()
31923 { 0x00000200, 1, "CountOfView" }, in do_meta_command()
31924 { 0x00000400, 1, "CurosrHints" }, in do_meta_command()
31925 { 0x00000800, 1, "Stat4" }, in do_meta_command()
31926 { 0x00001000, 1, "PushDown" }, in do_meta_command()
31927 { 0x00002000, 1, "SimplifyJoin" }, in do_meta_command()
31928 { 0x00004000, 1, "SkipScan" }, in do_meta_command()
31929 { 0x00008000, 1, "PropagateConst" }, in do_meta_command()
31930 { 0x00010000, 1, "MinMaxOpt" }, in do_meta_command()
31931 { 0x00020000, 1, "SeekScan" }, in do_meta_command()
31932 { 0x00040000, 1, "OmitOrderBy" }, in do_meta_command()
31933 { 0x00080000, 1, "BloomFilter" }, in do_meta_command()
31934 { 0x00100000, 1, "BloomPulldown" }, in do_meta_command()
31935 { 0x00200000, 1, "BalancedMerge" }, in do_meta_command()
31936 { 0x00400000, 1, "ReleaseReg" }, in do_meta_command()
31937 { 0x00800000, 1, "FlttnUnionAll" }, in do_meta_command()
31938 { 0x01000000, 1, "IndexedEXpr" }, in do_meta_command()
31939 { 0x02000000, 1, "Coroutines" }, in do_meta_command()
31940 { 0x04000000, 1, "NullUnusedCols" }, in do_meta_command()
31941 { 0x08000000, 1, "OnePass" }, in do_meta_command()
31942 { 0x10000000, 1, "OrderBySubq" }, in do_meta_command()
31943 { 0x20000000, 1, "StarQuery" }, in do_meta_command()
31944 { 0xffffffff, 0, "All" }, in do_meta_command()
31955 int useLabel = 0; in do_meta_command()
31956 const char *zLabel = 0; in do_meta_command()
31957 if( (z[0]=='+'|| z[0]=='-') && !IsDigit(z[1]) ){ in do_meta_command()
31958 useLabel = z[0]; in do_meta_command()
31960 }else if( !IsDigit(z[0]) && z[0]!=0 && !IsDigit(z[1]) ){ in do_meta_command()
31964 newOpt = (unsigned int)strtol(z,0,0); in do_meta_command()
31968 for(jj=0; jj<ArraySize(aLabel); jj++){ in do_meta_command()
31969 if( sqlite3_stricmp(zLabel, aLabel[jj].zLabel)==0 ) break; in do_meta_command()
31975 for(jj=0; jj<ArraySize(aLabel); jj++){ in do_meta_command()
31992 for(ii=nOff=0, m=1; ii<32; ii++, m <<= 1){ in do_meta_command()
31997 for(ii=0; ii<ArraySize(aLabel); ii++){ in do_meta_command()
31999 if( (newOpt & aLabel[ii].mask)!=0 ){ in do_meta_command()
32005 for(ii=0; ii<ArraySize(aLabel); ii++){ in do_meta_command()
32007 if( (newOpt & aLabel[ii].mask)==0 ){ in do_meta_command()
32020 unsigned int opt = (unsigned int)strtol(azArg[2], 0, 0); in do_meta_command()
32050 if( ii==0 && cli_strcmp(azArg[2],"random")==0 ){ in do_meta_command()
32055 db = 0; in do_meta_command()
32059 sqlite3_table_column_metadata(db, 0, "x", 0, 0, 0, 0, 0, 0); in do_meta_command()
32103 u64 x = 0; in do_meta_command()
32133 int val = 0; in do_meta_command()
32169 if( z[0]=='-' && z[1]=='-' ) z++; in do_meta_command()
32170 if( cli_strcmp(z,"off")==0 ){ in do_meta_command()
32171 sqlite3_test_control(testctrl, 0); in do_meta_command()
32172 }else if( cli_strcmp(z,"on")==0 ){ in do_meta_command()
32174 if( faultsim_state.iErr==0 ) faultsim_state.iErr = 1; in do_meta_command()
32175 faultsim_state.nHit = 0; in do_meta_command()
32177 }else if( cli_strcmp(z,"reset")==0 ){ in do_meta_command()
32179 faultsim_state.nHit = 0; in do_meta_command()
32181 }else if( cli_strcmp(z,"status")==0 ){ in do_meta_command()
32198 }else if( cli_strcmp(z,"-v")==0 ){ in do_meta_command()
32200 }else if( cli_strcmp(z,"-q")==0 ){ in do_meta_command()
32201 if( faultsim_state.eVerbose>0 ) faultsim_state.eVerbose--; in do_meta_command()
32202 }else if( cli_strcmp(z,"-id")==0 && kk+1<nArg ){ in do_meta_command()
32204 }else if( cli_strcmp(z,"-errcode")==0 && kk+1<nArg ){ in do_meta_command()
32206 }else if( cli_strcmp(z,"-interval")==0 && kk+1<nArg ){ in do_meta_command()
32208 }else if( cli_strcmp(z,"-repeat")==0 && kk+1<nArg ){ in do_meta_command()
32210 }else if( cli_strcmp(z,"-skip")==0 && kk+1<nArg ){ in do_meta_command()
32212 }else if( cli_strcmp(z,"-?")==0 || sqlite3_strglob("*help*",z)==0){ in do_meta_command()
32236 " --repeat N Turn off after N hits. 0 means never\n" in do_meta_command()
32245 if( isOk==0 && iCtrl>=0 ){ in do_meta_command()
32252 sqlite3_fprintf(p->out, "0x%08x\n", rc2); in do_meta_command()
32257 if( c=='t' && n>4 && cli_strncmp(azArg[0], "timeout", n)==0 ){ in do_meta_command()
32258 open_db(p, 0); in do_meta_command()
32259 sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0); in do_meta_command()
32262 if( c=='t' && n>=5 && cli_strncmp(azArg[0], "timer", n)==0 ){ in do_meta_command()
32267 enableTimer = 0; in do_meta_command()
32276 if( c=='t' && cli_strncmp(azArg[0], "trace", n)==0 ){ in do_meta_command()
32277 int mType = 0; in do_meta_command()
32279 open_db(p, 0); in do_meta_command()
32282 if( z[0]=='-' ){ in do_meta_command()
32316 if( p->traceOut==0 ){ in do_meta_command()
32317 sqlite3_trace_v2(p->db, 0, 0, 0); in do_meta_command()
32319 if( mType==0 ) mType = SQLITE_TRACE_STMT; in do_meta_command()
32326 if( c=='u' && cli_strncmp(azArg[0], "unmodule", n)==0 ){ in do_meta_command()
32335 open_db(p, 0); in do_meta_command()
32337 if( zOpt[0]=='-' && zOpt[1]=='-' && zOpt[2]!=0 ) zOpt++; in do_meta_command()
32339 if( lenOpt>=3 && cli_strncmp(zOpt, "-allexcept",lenOpt)==0 ){ in do_meta_command()
32340 assert( azArg[nArg]==0 ); in do_meta_command()
32341 sqlite3_drop_modules(p->db, nArg>2 ? (const char**)(azArg+2) : 0); in do_meta_command()
32344 sqlite3_create_module(p->db, azArg[ii], 0, 0); in do_meta_command()
32350 if( c=='v' && cli_strncmp(azArg[0], "version", n)==0 ){ in do_meta_command()
32370 if( c=='v' && cli_strncmp(azArg[0], "vfsinfo", n)==0 ){ in do_meta_command()
32372 sqlite3_vfs *pVfs = 0; in do_meta_command()
32384 if( c=='v' && cli_strncmp(azArg[0], "vfslist", n)==0 ){ in do_meta_command()
32386 sqlite3_vfs *pCurrent = 0; in do_meta_command()
32390 for(pVfs=sqlite3_vfs_find(0); pVfs; pVfs=pVfs->pNext){ in do_meta_command()
32402 if( c=='v' && cli_strncmp(azArg[0], "vfsname", n)==0 ){ in do_meta_command()
32404 char *zVfsName = 0; in do_meta_command()
32414 if( c=='w' && cli_strncmp(azArg[0], "wheretrace", n)==0 ){ in do_meta_command()
32415 unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff; in do_meta_command()
32419 if( c=='w' && cli_strncmp(azArg[0], "width", n)==0 ){ in do_meta_command()
32424 if( p->colWidth==0 && p->nWidth>0 ) shell_out_of_memory(); in do_meta_command()
32433 " \"%s\". Enter \".help\" for help\n", azArg[0]); in do_meta_command()
32440 if( p->outCount==0 ) output_reset(p); in do_meta_command()
32454 QSS_Start = 0
32471 if( cWait==0 ){ in quickscan()
32473 while( (cin = *zLine++)!=0 ){ in quickscan()
32480 while((cin = *++zLine)!=0 ) in quickscan()
32517 while( (cin = *zLine++)!=0 ){ in quickscan()
32524 CONTINUE_PROMPT_AWAITC(pst, 0); in quickscan()
32525 qss = QSS_SETV(qss, 0); in quickscan()
32535 CONTINUE_PROMPT_AWAITC(pst, 0); in quickscan()
32536 qss = QSS_SETV(qss, 0); in quickscan()
32538 default: assert(0); in quickscan()
32552 while( IsSpace(zLine[0]) ){ zLine++; }; in line_is_command_terminator()
32553 if( zLine[0]=='/' ) in line_is_command_terminator()
32555 else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' ) in line_is_command_terminator()
32558 return 0; in line_is_command_terminator()
32559 return quickscan(zLine, QSS_Start, 0)==QSS_Start; in line_is_command_terminator()
32576 if( zSql==0 ) return 1; in line_is_complete()
32578 zSql[nSql+1] = 0; in line_is_complete()
32580 zSql[nSql] = 0; in line_is_complete()
32596 ** 0: Have not seen any SQL.
32607 case 0: { in doAutoDetectRestore()
32610 if( p->bSafeMode==0 in doAutoDetectRestore()
32612 && memcmp(zSql, zExpect, 25)==0 in doAutoDetectRestore()
32622 int bIsDump = 0; in doAutoDetectRestore()
32625 if( memcmp(zSql, zExpect, 19)==0 ){ in doAutoDetectRestore()
32628 sqlite3_stmt *pStmt = 0; in doAutoDetectRestore()
32633 bIsDump = 0; in doAutoDetectRestore()
32638 int bDefense = 0; in doAutoDetectRestore()
32639 int bDqsDdl = 0; in doAutoDetectRestore()
32642 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0); in doAutoDetectRestore()
32643 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, 1, 0); in doAutoDetectRestore()
32644 p->eRestoreState = (bDefense ? 2 : 0) + (bDqsDdl ? 4 : 0); in doAutoDetectRestore()
32654 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 1, 0); in doAutoDetectRestore()
32657 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, 0, 0); in doAutoDetectRestore()
32674 char *zErrMsg = 0; in runOneSqlLine()
32676 open_db(p, 0); in runOneSqlLine()
32678 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0; in runOneSqlLine()
32686 if( zErrMsg==0 ){ in runOneSqlLine()
32689 }else if( cli_strncmp(zErrMsg, "in prepare, ",12)==0 ){ in runOneSqlLine()
32692 }else if( cli_strncmp(zErrMsg, "stepping, ", 10)==0 ){ in runOneSqlLine()
32699 if( in!=0 || !stdin_is_interactive ){ in runOneSqlLine()
32707 zErrMsg = 0; in runOneSqlLine()
32718 return 0; in runOneSqlLine()
32738 char *zLine = 0; in one_input_line()
32739 i64 nZ = 0; in one_input_line()
32744 return 0; in one_input_line()
32749 if(nZ>0 && '\r'==zBegin[nZ-1]){ in one_input_line()
32756 zLine[nZ] = 0; in one_input_line()
32762 ** Read input from *in and process it. If *in==0 then input
32771 char *zLine = 0; /* A single input line */ in process_input()
32772 char *zSql = 0; /* Accumulated SQL text */ in process_input()
32774 i64 nSql = 0; /* Bytes of zSql[] used */ in process_input()
32775 i64 nAlloc = 0; /* Allocated zSql[] space */ in process_input()
32777 int errCnt = 0; /* Number of errors seen */ in process_input()
32778 i64 startline = 0; /* Line number for start of current input */ in process_input()
32788 p->lineno = 0; in process_input()
32790 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){ in process_input()
32792 zLine = one_input_line(p->in, zLine, nSql>0); in process_input()
32793 if( zLine==0 ){ in process_input()
32795 if( p->in==0 && stdin_is_interactive ) sqlite3_fputs("\n", p->out); in process_input()
32799 if( p->in!=0 ) break; in process_input()
32800 seenInterrupt = 0; in process_input()
32809 if( QSS_PLAINWHITE(qss) && nSql==0 ){ in process_input()
32815 if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){ in process_input()
32818 if( zLine[0]=='.' ){ in process_input()
32837 if( nSql==0 ){ in process_input()
32839 for(i=0; zLine[i] && IsSpace(zLine[i]); i++){} in process_input()
32840 assert( nAlloc>0 && zSql!=0 ); in process_input()
32853 nSql = 0; in process_input()
32856 p->outCount = 0; in process_input()
32864 nSql = 0; in process_input()
32877 return errCnt>0; in process_input()
32882 ** 0 return indicates an error of some kind.
32888 home_dir = 0; in find_home_dir()
32889 return 0; in find_home_dir()
32929 if( home_dir==0 ) return 0; in find_home_dir()
32954 ** return that. If none of these are found, return 0.
32962 return 0; in find_xdg_config()
32964 char *zConfig = 0; in find_xdg_config()
32968 if( zXdgHome==0 ){ in find_xdg_config()
32970 if( zHome==0 ) return 0; in find_xdg_config()
32976 if( access(zConfig,0)!=0 ){ in find_xdg_config()
32978 zConfig = 0; in find_xdg_config()
32997 char *zBuf = 0; in process_sqliterc()
33005 home_dir = find_home_dir(0); in process_sqliterc()
33006 if( home_dir==0 ){ in process_sqliterc()
33022 }else if( sqliterc_override!=0 ){ in process_sqliterc()
33107 exit(0); in usage()
33125 memset(data, 0, sizeof(*data)); in main_init()
33131 data->pAuxDb = &data->aAuxDb[0]; in main_init()
33134 data->showHeader = 0; in main_init()
33166 sqlite3_fprintf(stdout, "\033[1m%s\033[0m", zText); in printBold()
33177 "%s: Error: missing argument to %s\n", argv[0], argv[argc-1]); in cmdline_option_value()
33199 # define SQLITE_SHELL_IS_UTF8 (0)
33216 sqlite3_int64 mem_main_enter = 0;
33218 char *zErrMsg = 0;
33224 const char *zInitFile = 0;
33226 int rc = 0;
33227 int warnInmemoryDb = 0;
33229 int nCmd = 0;
33231 int bEnableVfstrace = 0;
33232 char **azCmd = 0;
33233 const char *zVfs = 0; /* Value of -vfs command-line option */
33235 char **argvToFree = 0;
33236 int argcToFree = 0;
33238 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
33241 stdin_is_interactive = 0;
33245 stdin_is_interactive = isatty(0);
33254 if( isatty(0) && isatty(2) ){
33259 if( sqlite3_fgets(zLine, sizeof(zLine), stdin)!=0
33260 && cli_strcmp(zLine,"stop")==0
33286 #if USE_SYSTEM_SQLITE+0!=1
33287 if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
33304 argvToFree = malloc(sizeof(argv[0])*argc*2);
33308 for(i=0; i<argc; i++){
33322 assert( argc>=1 && argv && argv[0] );
33323 Argv0 = argv[0];
33333 warnInmemoryDb = 0;
33348 if( z[0]!='-' || i>nOptsEnd ){
33349 if( data.aAuxDb->zDbFilename==0 ){
33354 readStdin = 0;
33356 azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
33363 if( cli_strcmp(z, "-")==0 ){
33366 }else if( cli_strcmp(z,"-separator")==0
33367 || cli_strcmp(z,"-nullvalue")==0
33368 || cli_strcmp(z,"-newline")==0
33369 || cli_strcmp(z,"-cmd")==0
33372 }else if( cli_strcmp(z,"-init")==0 ){
33374 }else if( cli_strcmp(z,"-interactive")==0 ){
33375 }else if( cli_strcmp(z,"-batch")==0 ){
33380 stdin_is_interactive = 0;
33381 }else if( cli_strcmp(z,"-utf8")==0 ){
33382 }else if( cli_strcmp(z,"-no-utf8")==0 ){
33383 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
33384 int val = 0;
33386 assert( val==0 );
33387 }else if( cli_strcmp(z,"-heap")==0 ){
33394 if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
33400 }else if( cli_strcmp(z,"-pagecache")==0 ){
33404 if( sz<0 ) sz = 0;
33406 if( sz>0 && n>0 && 0xffffffffffffLL/sz<n ){
33407 n = 0xffffffffffffLL/sz;
33411 (n>0 && sz>0) ? malloc(n*sz) : 0, sz, n);
33413 }else if( cli_strcmp(z,"-lookaside")==0 ){
33416 if( sz<0 ) sz = 0;
33418 if( n<0 ) n = 0;
33421 if( sz*n==0 ) data.shellFlgs &= ~SHFLG_Lookaside;
33422 }else if( cli_strcmp(z,"-threadsafe")==0 ){
33427 case 0: sqlite3_config(SQLITE_CONFIG_SINGLETHREAD); break;
33431 }else if( cli_strcmp(z,"-vfstrace")==0 ){
33434 }else if( cli_strcmp(z,"-multiplex")==0 ){
33436 sqlite3_multiplex_initialize(0, 1);
33438 }else if( cli_strcmp(z,"-mmap")==0 ){
33443 }else if( cli_strcmp(z,"-sorterref")==0 ){
33448 }else if( cli_strcmp(z,"-vfs")==0 ){
33451 }else if( cli_strcmp(z,"-zip")==0 ){
33454 }else if( cli_strcmp(z,"-append")==0 ){
33457 }else if( cli_strcmp(z,"-deserialize")==0 ){
33459 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
33462 }else if( cli_strcmp(z,"-readonly")==0 ){
33464 }else if( cli_strcmp(z,"-nofollow")==0 ){
33467 }else if( cli_strncmp(z, "-A",2)==0 ){
33472 }else if( cli_strcmp(z, "-memtrace")==0 ){
33474 }else if( cli_strcmp(z, "-pcachetrace")==0 ){
33476 }else if( cli_strcmp(z,"-bail")==0 ){
33478 }else if( cli_strcmp(z,"-nonce")==0 ){
33481 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
33483 }else if( cli_strcmp(z,"-safe")==0 ){
33485 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
33520 if( data.pAuxDb->zDbFilename==0 ){
33532 vfstrace_register("trace",0,vfstraceOut, &data, 1);
33535 sqlite3_appendvfs_init(0,0,0);
33543 if( access(data.pAuxDb->zDbFilename, 0)==0 ){
33544 open_db(&data, 0);
33560 if( z[0]!='-' || i>=nOptsEnd ) continue;
33562 if( cli_strcmp(z,"-init")==0 ){
33564 }else if( cli_strcmp(z,"-html")==0 ){
33566 }else if( cli_strcmp(z,"-list")==0 ){
33568 }else if( cli_strcmp(z,"-quote")==0 ){
33572 }else if( cli_strcmp(z,"-line")==0 ){
33574 }else if( cli_strcmp(z,"-column")==0 ){
33576 }else if( cli_strcmp(z,"-json")==0 ){
33578 }else if( cli_strcmp(z,"-markdown")==0 ){
33580 }else if( cli_strcmp(z,"-table")==0 ){
33582 }else if( cli_strcmp(z,"-box")==0 ){
33584 }else if( cli_strcmp(z,"-csv")==0 ){
33587 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
33591 for(k=0; k<ArraySize(shell_EscModeNames); k++){
33592 if( sqlite3_stricmp(zEsc,shell_EscModeNames[k])==0 ){
33600 for(k=0; k<ArraySize(shell_EscModeNames); k++){
33607 }else if( cli_strcmp(z,"-zip")==0 ){
33610 }else if( cli_strcmp(z,"-append")==0 ){
33613 }else if( cli_strcmp(z,"-deserialize")==0 ){
33615 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
33618 }else if( cli_strcmp(z,"-readonly")==0 ){
33620 }else if( cli_strcmp(z,"-nofollow")==0 ){
33622 }else if( cli_strcmp(z,"-ascii")==0 ){
33626 }else if( cli_strcmp(z,"-tabs")==0 ){
33630 }else if( cli_strcmp(z,"-separator")==0 ){
33633 }else if( cli_strcmp(z,"-newline")==0 ){
33636 }else if( cli_strcmp(z,"-nullvalue")==0 ){
33639 }else if( cli_strcmp(z,"-header")==0 ){
33642 }else if( cli_strcmp(z,"-noheader")==0 ){
33643 data.showHeader = 0;
33645 }else if( cli_strcmp(z,"-echo")==0 ){
33647 }else if( cli_strcmp(z,"-eqp")==0 ){
33649 }else if( cli_strcmp(z,"-eqpfull")==0 ){
33651 }else if( cli_strcmp(z,"-stats")==0 ){
33653 }else if( cli_strcmp(z,"-scanstats")==0 ){
33655 }else if( cli_strcmp(z,"-backslash")==0 ){
33662 }else if( cli_strcmp(z,"-bail")==0 ){
33664 }else if( cli_strcmp(z,"-version")==0 ){
33667 return 0;
33668 }else if( cli_strcmp(z,"-interactive")==0 ){
33673 }else if( cli_strcmp(z,"-batch")==0 ){
33675 }else if( cli_strcmp(z,"-utf8")==0 ){
33677 }else if( cli_strcmp(z,"-no-utf8")==0 ){
33679 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
33681 }else if( cli_strcmp(z,"-heap")==0 ){
33683 }else if( cli_strcmp(z,"-pagecache")==0 ){
33685 }else if( cli_strcmp(z,"-lookaside")==0 ){
33687 }else if( cli_strcmp(z,"-threadsafe")==0 ){
33689 }else if( cli_strcmp(z,"-nonce")==0 ){
33691 }else if( cli_strcmp(z,"-mmap")==0 ){
33693 }else if( cli_strcmp(z,"-memtrace")==0 ){
33695 }else if( cli_strcmp(z,"-pcachetrace")==0 ){
33698 }else if( cli_strcmp(z,"-sorterref")==0 ){
33701 }else if( cli_strcmp(z,"-vfs")==0 ){
33703 }else if( cli_strcmp(z,"-vfstrace")==0 ){
33706 }else if( cli_strcmp(z,"-multiplex")==0 ){
33709 }else if( cli_strcmp(z,"-help")==0 ){
33711 }else if( cli_strcmp(z,"-cmd")==0 ){
33718 if( z[0]=='.' ){
33720 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
33722 open_db(&data, 0);
33724 if( zErrMsg!=0 ){
33726 if( bail_on_error ) return rc!=0 ? rc : 1;
33727 }else if( rc!=0 ){
33733 }else if( cli_strncmp(z, "-A", 2)==0 ){
33734 if( nCmd>0 ){
33746 readStdin = 0;
33749 }else if( cli_strcmp(z,"-safe")==0 ){
33751 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
33766 for(i=0; i<nCmd; i++){
33768 if( azCmd[i][0]=='.' ){
33771 if( rc==2 ) rc = 0;
33775 open_db(&data, 0);
33778 if( zErrMsg!=0 ){
33785 if( rc==0 ) rc = 1;
33810 }else if( (zHome = find_home_dir(0))!=0 ){
33812 if( (zHistory = malloc(nHistory))!=0 ){
33824 data.in = 0;
33841 expertFinish(&data, 1, 0);
33846 set_table_name(&data, 0);
33851 for(i=0; i<ArraySize(data.aAuxDb); i++){
33860 data.doXdgOpen = 0;
33863 for(i=0; i<argcToFree; i++) free(argvToFree[i]);
33870 memset(&data, 0, sizeof(data));
33901 ** Returns a pointer to the given DB name's VFS. If zDbName is 0 then
33902 ** "main" is assumed. Returns 0 if no db with the given name is
33906 sqlite3_vfs * pVfs = 0;
33948 while( sqlite3_txn_state(globalDb,0)>0 ){
33951 ** https://sqlite.org/forum/forumpost/0b41a25d65
33954 sqlite3_exec(globalDb,"ROLLBACK", 0, 0, 0);
33956 rc = sqlite3_db_config(globalDb, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
33957 if( 0==rc ) sqlite3_exec(globalDb, "VACUUM", 0, 0, 0);
33958 sqlite3_db_config(globalDb, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
33965 ** chunk of size n (its 2nd argument) on each call and must return 0
33966 ** on success, non-0 on error. This function returns 0 on success,
33967 ** SQLITE_NOTFOUND if no db is open, or propagates any other non-0
33973 sqlite3_int64 nSize = 0;
33974 sqlite3_int64 nPos = 0;
33975 sqlite3_file * pFile = 0;
33989 if(0 == nSize % 4096) nBuf = 4096;
33990 else if(0 == nSize % 2048) nBuf = 2048;
33991 else if(0 == nSize % 1024) nBuf = 1024;
33994 for( ; 0==rc && nPos<nSize; nPos += nBuf ){
33997 rc = (nPos + nBuf) < nSize ? rc : 0/*assume EOF*/;
33999 if( 0==rc ) rc = xCallback(buf, nBuf);
34016 shellState.wasm.zInput = shellState.wasm.zPos = 0;