Lines Matching +full:1 +full:qbv

94 # define SQLITE_OMIT_LOAD_EXTENSION 1
101 # define _LARGE_FILE 1
105 # define _LARGEFILE_SOURCE 1
185 # define SHELL_USE_LOCAL_GETLINE 1
199 # define SQLITE_OMIT_POPEN 1
228 # define SQLITE_OMIT_POPEN 1
237 #define isatty(x) 1
270 ** 2023 November 1
296 ** CIO_WIN_WC_XLATE is defined as 0 or 1, reflecting whether console I/O
299 #define HAVE_CONSOLE_IO_H 1
316 SAC_InConsole = 1, SAC_OutConsole = 2, SAC_ErrConsole = 4,
511 ** Array azPrompt[{0,1}] holds the {main,continuation} prompt.
541 ** no char cn such that ((1<<cn) & ccm)!=0. On return, the
596 # define CIO_WIN_WC_XLATE 1 /* Use WCHAR Windows APIs for console I/O */
793 &consoleInfo.pstDesignated[1], &consoleInfo.pstDesignated[2],
794 &consoleInfo.pstSetup[1], &consoleInfo.pstSetup[2], 0
818 return designateEmitStream(pf, 1);
898 ** chix equals 1 or 2, or for an arbitrary stream when chix == 0.
916 pfEmit = (chix > 1)? stderr : stdout;
936 PerStreamTags *ppst = getEmitStreamInfo(1, &pst, &pfOut);
938 getEmitStreamInfo(1, &pst, &pfOut);
993 maybeSetupAsConsole(ppst, 1);
1017 maybeSetupAsConsole(ppst, 1);
1052 PerStreamTags *ppst = getEmitStreamInfo(1, &pst, &pfOut);
1054 getEmitStreamInfo(1, &pst, &pfOut);
1072 ** no char cn such that ((1<<cn) & ccm)!=0. On return, the
1084 if( ccm != 0L && c < 0x20 && ((1L<<c) & ccm) != 0 ) return z;
1088 const char *zt = z+1; /* Got lead byte, look at trail bytes.*/
1098 } while( ((c <<= 1) & 0x40) == 0x40 ); /* Eat lead byte's count. */
1116 maybeSetupAsConsole(ppst, 1);
1122 return (int)fwrite(cBuf, 1, nAccept, pfO);
1134 PerStreamTags *ppst = getEmitStreamInfo(1, &pst, &pfOut);
1136 getEmitStreamInfo(1, &pst, &pfOut);
1143 return (int)fwrite(cBuf, 1, nAccept, pfOut);
1160 return (int)fwrite(cBuf, 1, nAccept, pfErr);
1172 # if CIO_WIN_WC_XLATE==1
1174 WCHAR wcBuf[SHELL_GULP+1];
1177 while( noc < ncMax-8-1 && !lend ){
1179 int na = (ncMax > SHELL_GULP*4+1 + noc)? SHELL_GULP : (ncMax-1 - noc)/4;
1183 if( bRC && nbr>0 && (wcBuf[nbr-1]&0xF800)==0xD800 ){
1186 bRC &= ReadConsoleW(consoleInfo.pstSetup[0].hx, wcBuf+nbr, 1, &nbrx, 0);
1201 if( cBuf[noc-1]=='\n' ){
1202 lend = 1;
1203 if( noc > 1 && cBuf[noc-2]=='\r' ) cBuf[--noc-1] = '\n';
1210 lend = 1; /* Counts as end of line too. */
1253 * oputb(b, n) => emit char buffer b[0..n-1] to default stream
1285 # define oputb(buf,na) fwrite(buf,1,na,stdout)
1369 #define HAS_TIMER 1
1383 ** Check to see if we have timer support. Return 1 if necessary
1388 return 1;
1402 return 1;
1476 static int stdin_is_interactive = 1;
1483 static int stdout_is_console = 1;
1515 ** if there is no zero-terminator in the first n-1 characters of the source
1520 for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i];
1614 exit(1);
1695 if( realnum ) *realnum = 1;
1702 if( realnum ) *realnum = 1;
1776 while( 1 ){
1791 if( n>0 && zLine[n-1]=='\n' ){
1793 if( n>0 && zLine[n-1]=='\r' ) n--;
1849 ** Return the value of a hexadecimal digit. Return -1 if the input
1856 return -1;
1878 isNeg = 1;
1883 if( zArg[0]=='0' && zArg[1]=='x' ){
1939 len = nAppend+p->n+1;
2007 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
2019 const char *zCol = (const char*)sqlite3_column_text(pStmt, 1);
2067 int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26;
2069 if( n<1 ) n = 1;
2072 sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
2094 -1, sqlite3_free);
2133 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
2163 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
2284 # define BAD_INTPTR_T ((intptr_t)(-1))
2298 char d_name[NAME_MAX + 1]; /* Name within the directory. */
2423 if( _findnext(dirp->d_handle, &data)==-1 ){
2459 if( _findnext(dirp->d_handle, &data)==-1 ) return NULL;
2500 if( _findnext(dirp->d_handle, &data)==-1 ){
2508 entry->d_ino = (ino_t)-1; /* not available */
2936 # define a01 (p->u.s[1])
2968 d0 = c4^ROL64(c1, 1);
2969 d1 = c0^ROL64(c2, 1);
2970 d2 = c1^ROL64(c3, 1);
2971 d3 = c2^ROL64(c4, 1);
2972 d4 = c3^ROL64(c0, 1);
2998 b0 = ROL64((a01^d1), 1);
3035 d0 = c4^ROL64(c1, 1);
3036 d1 = c0^ROL64(c2, 1);
3037 d2 = c1^ROL64(c3, 1);
3038 d3 = c2^ROL64(c4, 1);
3039 d4 = c3^ROL64(c0, 1);
3047 a00 ^= RC[i+1];
3065 b0 = ROL64((a11^d1), 1);
3102 d0 = c4^ROL64(c1, 1);
3103 d1 = c0^ROL64(c2, 1);
3104 d2 = c1^ROL64(c3, 1);
3105 d3 = c2^ROL64(c4, 1);
3106 d4 = c3^ROL64(c0, 1);
3132 b0 = ROL64((a31^d1), 1);
3169 d0 = c4^ROL64(c1, 1);
3170 d1 = c0^ROL64(c2, 1);
3171 d2 = c1^ROL64(c3, 1);
3172 d3 = c2^ROL64(c4, 1);
3173 d4 = c3^ROL64(c0, 1);
3199 b0 = ROL64((a21^d1), 1);
3251 static unsigned int one = 1;
3252 if( 1==*(unsigned char*)&one ){
3309 if( p->nLoaded==p->nRate-1 ){
3311 SHA3Update(p, &c1, 1);
3315 SHA3Update(p, &c2, 1);
3316 p->nLoaded = p->nRate - 1;
3317 SHA3Update(p, &c3, 1);
3345 if( argc==1 ){
3348 iSize = sqlite3_value_int(argv[1]);
3351 "384 512", -1);
3431 if( argc==1 ){
3434 iSize = sqlite3_value_int(argv[1]);
3437 "384 512", -1);
3444 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zSql);
3449 sqlite3_result_error(context, zMsg, -1);
3456 sqlite3_result_error(context, zMsg, -1);
3470 SHA3Update(&cx,(const unsigned char*)"R",1);
3474 SHA3Update(&cx, (const unsigned char*)"N",1);
3483 for(j=8; j>=1; j--){
3497 for(j=8; j>=1; j--){
3539 rc = sqlite3_create_function(db, "sha3", 1,
3548 rc = sqlite3_create_function(db, "sha3_query", 1,
3623 return +1;
3625 return -1;
3690 char sign; /* 0 for positive, 1 for negative */
3729 p->isInit = 1;
3733 p->a = sqlite3_malloc64( n+1 );
3737 p->sign = 1;
3748 p->nFrac = p->nDigit + 1;
3750 int j = i+1;
3754 neg = 1;
3771 p->nFrac = p->nDigit - (p->nFrac - 1);
3784 p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
3792 nExtra = p->nDigit - p->nFrac - 1;
3799 p->nFrac = p->nDigit - 1;
3803 p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
3909 if( p->nDigit==0 || (p->nDigit==1 && p->a[0]==0) ){
3914 i = 1;
3921 while( n>1 && p->a[j]==0 ){
3964 for(nDigit=p->nDigit; nDigit>0 && p->a[nDigit-1]==0; nDigit--){}
3976 nDigit = 1;
3986 z[1] = a[0]+'0';
3988 if( nDigit==1 ){
3992 for(i=1; i<nDigit; i++){
3997 exp = nDigit - nFrac - 1;
3999 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
4016 return pA->sign ? -1 : +1;
4052 pA = decimal_new(context, argv[0], 1);
4054 pB = decimal_new(context, argv[1], 1);
4057 if( rc<0 ) rc = -1;
4058 else if( rc>0 ) rc = +1;
4076 p->a = sqlite3_realloc64(p->a, nDigit+1);
4078 p->oom = 1;
4105 pA->oom = 1;
4109 pA->isNull = 1;
4119 nDigit = nSig + nFrac + 1;
4123 pA->oom = 1;
4127 for(i=nDigit-1; i>=0; i--){
4130 carry = 1;
4149 for(i=nDigit-1; i>=0; i--){
4153 borrow = 1;
4183 pA->oom = 1;
4189 for(i=pA->nDigit-1; i>=0; i--){
4192 for(j=pB->nDigit-1, k=i+j+3; j>=0; j--, k--){
4199 acc[k-1] += x/10;
4207 while( pA->nFrac>minFrac && pA->a[pA->nDigit-1]==0 ){
4233 while( 1 /* Exit by break */ ){
4234 if( N & 1 ){
4238 N >>= 1;
4262 isNeg = 1;
4273 m = a & ((((sqlite3_int64)1)<<52)-1);
4275 m <<= 1;
4277 m |= ((sqlite3_int64)1)<<52;
4279 while( e<1075 && m>0 && (m&1)==0 ){
4280 m >>= 1;
4365 Decimal *pA = decimal_new(context, argv[0], 1);
4366 Decimal *pB = decimal_new(context, argv[1], 1);
4378 Decimal *pA = decimal_new(context, argv[0], 1);
4379 Decimal *pB = decimal_new(context, argv[1], 1);
4406 p->isInit = 1;
4409 p->oom = 1;
4413 p->nDigit = 1;
4417 pArg = decimal_new(context, argv[0], 1);
4432 pArg = decimal_new(context, argv[0], 1);
4459 Decimal *pA = decimal_new(context, argv[0], 1);
4460 Decimal *pB = decimal_new(context, argv[1], 1);
4511 { "decimal", 1, 0, decimalFunc },
4512 { "decimal_exp", 1, 1, decimalFunc },
4517 { "decimal_pow2", 1, 0, decimalPow2Func },
4530 rc = sqlite3_create_window_function(db, "decimal_sum", 1,
4632 /* 0 1 5 9 = */
4635 ND, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
4644 static const char b64Numerals[64+1]
4664 pOut[1] = BX_NUMERAL(((pIn[0]<<4)|(pIn[1]>>4))&0x3f);
4665 pOut[2] = BX_NUMERAL(((pIn[1]&0xf)<<2)|(pIn[2]>>6));
4676 signed char nco = nbIn+1;
4679 for( nbe=1; nbe<3; ++nbe ){
4704 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
4706 static signed char nboi[] = { 0, 0, 1, 2, 3 };
4741 pOut[1] = (qv>>8) & 0xff;
4742 case 1:
4754 SQLITE_LIMIT_LENGTH, -1);
4757 assert(na==1);
4762 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
4764 sqlite3_result_error(context, "blob expanded to base64 too big", -1);
4772 sqlite3_result_text(context,"",-1,SQLITE_STATIC);
4784 sqlite3_result_error(context, "blob from base64 may be too big", -1);
4786 }else if( nb<1 ){
4787 nb = 1;
4803 sqlite3_result_error(context, "base64 accepts only blob or text", -1);
4808 sqlite3_result_error(context, "base64 OOM", -1);
4826 (db, "base64", 1,
4876 ** order. Groups of 1-3 bytes are represented with 2-4 digits,
4882 ** (aka "group") length maps 1-to-1 to the decoded binary length.
4904 ** function, is_base85(t), which returns 1 iff the text t contains
4963 * Values of 1 and 3 are base85 numerals. Values of 0, 2, or 4 are not.
4972 #define IS_B85( c ) (B85_CLASS(c) & 1)
5017 unsigned long qbv = (((unsigned long)pIn[0])<<24) |
5018 (pIn[1]<<16) | (pIn[2]<<8) | pIn[3];
5020 unsigned nqv = (unsigned)(qbv/85UL);
5021 unsigned char dv = qbv - 85UL*nqv;
5022 qbv = nqv;
5034 int nco = nbIn + 1;
5036 int nbe = 1;
5046 pOut += (nbIn+1);
5055 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
5057 static signed char nboi[] = { 0, 0, 1, 2, 3, 4 };
5082 case 1:
5098 return 1;
5107 assert(na==1);
5120 sqlite3_result_error(context, "is_base85 accepts only text or NULL", -1);
5130 SQLITE_LIMIT_LENGTH, -1);
5133 assert(na==1);
5138 nc = 5*(nv/4) + nv%4 + nv/64+1 + 2;
5140 sqlite3_result_error(context, "blob expanded to base85 too big", -1);
5148 sqlite3_result_text(context,"",-1,SQLITE_STATIC);
5160 sqlite3_result_error(context, "blob from base85 may be too big", -1);
5162 }else if( nb<1 ){
5163 nb = 1;
5179 sqlite3_result_error(context, "base85 accepts only blob or text.", -1);
5184 sqlite3_result_error(context, "base85 OOM", -1);
5204 (db, "is_base85", 1,
5211 (db, "base85", 1,
5233 int b85Clean = 1;
5238 if( na < 3 || av[1][0]!='-' || (rw = av[1][1])==0 || (rw!='r' && rw!='w') ){
5243 if( av[2][0]=='-' && av[2][1]==0 ){
5260 rc = 1;
5264 while( (nio = fread( bBuf, 1, sizeof(bBuf), fb))>0 ){
5273 if( 1 != fwrite(bBuf, nbo, 1, fb) ) rc = 1;
5281 rc = 1;
5354 ** VALUES(0,'1')
5356 ** SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971
5359 ** VALUES(-1,'0.5')
5361 ** SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075
5403 if( argc==1 ){
5424 isNeg = 1;
5435 m = a & ((((sqlite3_int64)1)<<52)-1);
5437 m <<= 1;
5439 m |= ((sqlite3_int64)1)<<52;
5441 while( e<1075 && m>0 && (m&1)==0 ){
5442 m >>= 1;
5451 sqlite3_result_text(context, zResult, -1, SQLITE_TRANSIENT);
5453 case 1:
5465 e = sqlite3_value_int64(argv[1]);
5475 isNeg = 1;
5483 m >>= 1;
5487 m <<= 1;
5493 if( 1-e >= 64 ){
5496 m >>= 1-e;
5502 a = m & ((((sqlite3_int64)1)<<52)-1);
5504 if( isNeg ) a |= ((sqlite3_uint64)1)<<63;
5547 for(i=1; i<=sizeof(r); i++){
5566 ** SELECT ieee754_inc(0.0,+1);
5579 N = sqlite3_value_int64(argv[1]);
5601 { "ieee754", 1, 0, ieee754func },
5603 { "ieee754_mantissa", 1, 1, ieee754func },
5604 { "ieee754_exponent", 1, 2, ieee754func },
5605 { "ieee754_to_blob", 1, 0, ieee754func_to_blob },
5606 { "ieee754_from_blob", 1, 0, ieee754func_from_blob },
5648 ** The stop parameter defaults to (1<<32)-1 (aka 4294967295 or 0xffffffff)
5649 ** The step parameter defaults to 1 and 0 is treated as 1.
5660 ** Integers from 0 through 100 with a step size of 1.
5670 ** SELECT * FROM generate_series(0,-1);
5686 ** The virtual table also has a rowid, logically equivalent to n+1 where
5711 ** are missing, it uses 0 for start, 4294967295 for stop, and 1 for step.
5739 /* With 2's complement ALU, this next can be 1 step, but is split into
5740 * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */
5744 /* Under UBSAN (or on 1's complement machines), must do this last term
5782 /* Under UBSAN (or on 1's complement machines), must do this in steps.
5784 nuspan = 1;
5786 nuspan += -(pss->iTerm+1);
5789 pss->isNotEOF = 1;
5791 pss->uSeqIndexMax = ( pss->iStep>LLONG_MIN )? nuspan/-pss->iStep : 1;
5801 /* Under UBSAN (or on 1's complement machines), must do this in steps.
5803 puspan = 1;
5805 puspan += -(pss->iBase+1);
5808 pss->isNotEOF = 1;
5812 pss->isNotEOF = 1;
5864 ** (1) Allocate the series_vtab object and initialize all fields.
5881 #define SERIES_COLUMN_START 1
5965 ** Return the rowid for the current row, logically equivalent to n+1 where
5971 *pRowid = (sqlite3_int64)((n<LARGEST_UINT64)? n+1 : 0);
6035 pCur->ss.iStep = 1;
6040 pCur->ss.iStep = 1;
6052 iTerm = pCur->ss.iBase + (iLimit - 1)*pCur->ss.iStep;
6064 pCur->ss.iBase = 1;
6066 pCur->ss.iStep = 1;
6114 assert( SERIES_COLUMN_STOP == SERIES_COLUMN_START+1 );
6117 aIdx[0] = aIdx[1] = aIdx[2] = aIdx[3] = aIdx[4] = -1;
6120 int iCol; /* 0 for start, 1 for stop, 2 for step */
6141 iMask = 1 << iCol;
6144 bStartSeen = 1;
6190 if( pIdxInfo->nOrderBy>=1 && pIdxInfo->aOrderBy[0].iColumn==0 ){
6196 pIdxInfo->orderByConsumed = 1;
6347 #define RE_OP_MATCH 1 /* Match the one character in the argument */
6450 }else if( (c&0xf0)==0xe0 && p->i+1<p->mx && (p->z[p->i]&0xc0)==0x80
6451 && (p->z[p->i+1]&0xc0)==0x80 ){
6452 c = (c&0x0f)<<12 | ((p->z[p->i]&0x3f)<<6) | (p->z[p->i+1]&0x3f);
6456 && (p->z[p->i+1]&0xc0)==0x80 && (p->z[p->i+2]&0xc0)==0x80 ){
6457 c = (c&0x07)<<18 | ((p->z[p->i]&0x3f)<<12) | ((p->z[p->i+1]&0x3f)<<6)
6517 c = RE_START-1;
6525 if( pToFree==0 ) return -1;
6528 aStateSet[1].aState = &aStateSet[0].aState[pRe->nState];
6529 pNext = &aStateSet[1];
6537 iSwap = 1 - iSwap;
6543 if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
6547 if( cPrev==RE_START ) re_add_state(pThis, x+1);
6551 if( c!=0 ) re_add_state(pNext, x+1);
6555 if( re_word_char(c) ) re_add_state(pNext, x+1);
6559 if( !re_word_char(c) && c!=0 ) re_add_state(pNext, x+1);
6563 if( re_digit_char(c) ) re_add_state(pNext, x+1);
6567 if( !re_digit_char(c) && c!=0 ) re_add_state(pNext, x+1);
6571 if( re_space_char(c) ) re_add_state(pNext, x+1);
6575 if( !re_space_char(c) && c!=0 ) re_add_state(pNext, x+1);
6579 if( re_word_char(c)!=re_word_char(cPrev) ) re_add_state(pThis, x+1);
6584 re_add_state(pThis, x+1);
6589 re_add_state(pThis, x+1);
6597 rc = 1;
6605 int j = 1;
6608 for(j=1; j>0 && j<n; j++){
6611 hit = 1;
6612 j = -1;
6615 if( pRe->aArg[x+j]<=c && pRe->aArg[x+j+1]>=c ){
6616 hit = 1;
6617 j = -1;
6633 if( pRe->aOp[x]==RE_OP_ACCEPT ){ rc = 1; break; }
6646 if( aOp==0 ) return 1;
6649 if( aArg==0 ) return 1;
6662 p->aOp[i] = p->aOp[i-1];
6663 p->aArg[i] = p->aArg[i-1];
6702 return 1;
6717 if( re_hex(zIn[1],&v)
6728 if( re_hex(zIn[1],&v)
6780 int iPrev = -1;
6810 re_insert(p, iPrev, RE_OP_GOTO, p->nState - iPrev + 1);
6811 re_append(p, RE_OP_FORK, iPrev - p->nState + 1);
6821 re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
6849 re_insert(p, iPrev, RE_OP_FORK, sz+1);
6853 for(j=1; j<m; j++) re_copy(p, iPrev, sz);
6856 re_append(p, RE_OP_FORK, sz+1);
6986 for(j=0, i=1; j<(int)sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){
7001 if( j>0 && pRe->zInit[j-1]==0 ) j--;
7035 sqlite3_result_error(context, zErr, -1);
7042 setAux = 1;
7044 zStr = (const unsigned char*)sqlite3_value_text(argv[1]);
7046 sqlite3_result_int(context, re_match(pRe, zStr, -1));
7080 sqlite3_result_error(context, zErr, -1);
7105 sqlite3_result_text(context, z, n-1, sqlite3_free);
7141 rc = sqlite3_create_function(db, "regexp_bytecode", 1,
7269 /* 0 1 2 3 4 5 */
7272 #define FSDIR_COLUMN_MODE 1 /* Access mode */
7306 mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
7312 pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
7318 if( nIn==(sqlite3_int64)fread(pBuf, 1, (size_t)nIn, in) ){
7353 sqlite3_result_error(ctx, zMsg, -1);
7373 epochSystemTime.wMonth = 1;
7374 epochSystemTime.wDay = 1;
7392 int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0);
7394 if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) )
7486 int i = 1;
7521 sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */
7523 if( zFile==0 ) return 1;
7527 if( zTo==0 ) return 1;
7529 if( symlink(zTo, zFile)<0 ) return 1;
7545 return 1;
7553 if( out==0 ) return 1;
7556 sqlite3_int64 n = fwrite(z, 1, sqlite3_value_bytes(pData), out);
7559 rc = 1;
7564 rc = 1;
7590 return 1;
7602 return 1;
7608 times[0].tv_nsec = times[1].tv_nsec = 0;
7610 times[1].tv_sec = mtime;
7612 return 1;
7622 times[0].tv_usec = times[1].tv_usec = 0;
7624 times[1].tv_sec = mtime;
7626 return 1;
7647 sqlite3_int64 mtime = -1;
7651 "wrong number of arguments to function writefile()", -1
7665 res = writeFile(context, zFile, argv[1], mode, mtime);
7666 if( res==1 && errno==ENOENT ){
7668 res = writeFile(context, zFile, argv[1], mode, mtime);
7709 char *a = &z[1 + i*3];
7711 a[1] = (m & 0x2) ? 'w' : '-';
7715 sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
7795 pCur->iLvl = -1;
7818 pCur->iLvl = -1;
7819 pCur->iRowid = 1;
7855 int iNew = pCur->iLvl + 1;
7858 int nNew = iNew+1;
7883 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue;
7884 if( pEntry->d_name[1]=='\0' ) continue;
7920 sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
7943 while( 1 ){
7974 ** first row returned is assigned rowid value 1, and each subsequent
7975 ** row a value 1 more than that of the previous.
7995 ** idxNum==1 PATH parameter only
8013 assert( argc==idxNum && (argc==1 || argc==2) );
8020 pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
8023 pCur->nBase = (int)strlen(pCur->zBase)+1;
8051 ** (1) The path value is supplied by argv[0]
8052 ** (2) Path is in argv[0] and dir is in argv[1]
8059 int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
8060 int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
8075 seenPath = 1;
8084 seenDir = 1;
8101 pIdxInfo->aConstraintUsage[idxPath].omit = 1;
8102 pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
8104 pIdxInfo->aConstraintUsage[idxDir].omit = 1;
8109 pIdxInfo->idxNum = 1;
8167 rc = sqlite3_create_function(db, "readfile", 1,
8171 rc = sqlite3_create_function(db, "writefile", -1,
8176 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
8214 ** ORDER BY 1;
8268 #define COMPLETION_FIRST_PHASE 1
8269 #define COMPLETION_KEYWORDS 1
8289 ** (1) Allocate the completion_vtab object and initialize all fields.
8311 #define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
8390 int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */
8401 iCol = -1;
8406 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1,
8409 iCol = 1;
8418 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
8420 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
8430 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
8442 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
8444 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
8456 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
8507 sqlite3_result_text(ctx, pCur->zPrefix, -1, SQLITE_TRANSIENT);
8511 sqlite3_result_text(ctx, pCur->zLine, -1, SQLITE_TRANSIENT);
8557 if( idxNum & 1 ){
8563 iArg = 1;
8574 while( i>0 && (isalnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){
8596 ** is available and bit 1 is set if "wholeline" is available.
8604 int prefixIdx = -1; /* Index of the start= constraint, or -1 if none */
8605 int wholelineIdx = -1; /* Index of the stop= constraint, or -1 if none */
8617 idxNum |= 1;
8627 pIdxInfo->aConstraintUsage[prefixIdx].omit = 1;
8631 pIdxInfo->aConstraintUsage[wholelineIdx].omit = 1;
8718 ** For best performance page 1 should be located at a disk page boundary,
8726 ** (1) An empty file is an ordinary database.
8740 ** the file containing the database is limited to 1GiB. (1073741824 bytes)
8741 ** This VFS will not read or write past the 1GiB mark. This restriction
8759 ** the offset to page 1, and also the length of the prefix content.
8778 #define APND_ALIGN_MASK ((sqlite3_int64)(APND_ROUNDUP-1))
8791 #define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
8825 ** Or, iMark is -1 to indicate that it has not yet been written.
8830 sqlite3_int64 iMark; /* Offset of the append mark. -1 if unwritten */
9134 ** If there is no valid append-mark, return -1;
9143 int msbs = 8 * (APND_MARK_FOS_SZ-1);
9146 if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1;
9148 if( rc ) return -1;
9149 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
9151 for(i=1; i<8; i++){
9155 if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1;
9156 if( iMark & 0x1ff ) return -1;
9180 return 1; /* It's an appendvfs database */
9199 return 1;
9227 pApndFile->iMark = -1; /* Append mark not yet written */
9437 # define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1
9440 # define ALWAYS(X) (1)
9443 # define ALWAYS(X) ((X)?1:(assert(0),0))
9444 # define NEVER(X) ((X)?(assert(0),1):0)
9474 "mode," /* 1: POSIX mode for file */
9688 sqlite3_result_error(ctx, zMsg, -1);
9700 int iIn = 1;
9716 ** argv[1] -> database name
9751 nFile = (int)strlen(zFile)+1;
9760 pNew->aBuffer = (u8*)&pNew[1];
9908 n = fread(aRead, 1, nRead, pFile);
9924 n = fwrite(aWrite, 1, nWrite, pTab->pWriteFd);
9938 return (aBuf[1] << 8) + aBuf[0];
9948 + ((u32)(aBuf[1]) << 8)
9957 aBuf[1] = (val>>8) & 0xFF;
9965 aBuf[1] = (val>>8) & 0xFF;
10074 *pmTime = zipfileGetU32(&p[1]);
10075 ret = 1;
10099 ** Bits 05-08: month (1-12)
10118 X2 = 306001*(M+1)/10000;
10131 /* Convert unix timestamp to JD (2440588 is noon on 1/1/1970) */
10139 A = (int)(JD + 1 + A - (A/4));
10146 mon = (E<14 ? E-1 : E-13);
10162 || ((mUnixTime % 2) && mUnixTime-1==zipfileMtime(pCds))
10231 pNew->aExtra = (u8*)&pNew[1];
10286 pCsr->bEof = 1;
10302 pCsr->bEof = 1;
10422 sqlite3_result_text(ctx, pCDS->zFile, -1, SQLITE_TRANSIENT);
10424 case 1: /* mode */
10478 && pCDS->nFile>=1
10479 && pCDS->zFile[pCDS->nFile-1]!='/'
10550 if( aRead[i]==0x50 && aRead[i+1]==0x4b
10662 bInMemory = 1;
10676 pCsr->bEof = 1;
10684 pCsr->bNoop = 1;
10700 int idx = -1;
10708 unusable = 1;
10715 pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
10716 pIdxInfo->aConstraintUsage[idx].omit = 1;
10717 pIdxInfo->idxNum = 1;
10813 for(i=1; i<10; i++){
10814 if( z[i]==zTemplate[i] ) mode |= 1 << (9-i);
10838 if( nA>0 && zA[nA-1]=='/' ) nA--;
10839 if( nB>0 && zB[nB-1]=='/' ) nB--;
10841 return 1;
10974 if( nVal>1 ){
10975 const char *zUpdate = (const char*)sqlite3_value_text(apVal[1]);
10977 bUpdate = 1;
10980 for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){
10988 if( nVal>1 ){
11002 bIsDir = 1;
11050 if( nPath<=0 || zPath[nPath-1]!='/' ){
11116 pCsr->bNoop = 1;
11283 sqlite3_result_text(context, zRes, -1, SQLITE_TRANSIENT);
11303 return 1;
11360 int iMethod = -1; /* Compression method to use (0 or 8) */
11385 pData = apVal[1];
11387 pMode = apVal[1];
11419 bIsDir = 1;
11452 if( nName>0 && zName[nName-1]=='/' ){
11458 if( nName==0 || zName[nName-1]!='/' ){
11466 while( nName>1 && zName[nName-2]=='/' ) nName--;
11509 sqlite3_result_error(pCtx, zErr, -1);
11557 1, /* iVersion */
11585 if( rc==SQLITE_OK ) rc = sqlite3_overload_function(db, "zipfile_cds", -1);
11587 rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0,
11594 assert( sizeof(u8)==1 );
11657 assert( argc==1 );
11670 sqlite3_result_error(context, "error in compress()", -1);
11702 sz = sqlite3_value_int(argv[1]);
11713 sqlite3_result_error(context, "error in uncompress()", -1);
11732 rc = sqlite3_create_function(db, "sqlar_compress", 1,
11759 #define SQLITEEXPERT_H 1
11805 #define EXPERT_CONFIG_SAMPLE 1 /* int */
11901 #define EXPERT_REPORT_SQL 1
11936 # define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1
11939 # define ALWAYS(X) (1)
11942 # define ALWAYS(X) ((X)?1:(assert(0),0))
11943 # define NEVER(X) ((X)?(assert(0),1):0)
12159 return 1;
12162 pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + nKey+1 + nVal+1);
12164 pEntry->zKey = (char*)&pEntry[1];
12167 pEntry->zVal = &pEntry->zKey[nKey+1];
12218 pNew = (IdxConstraint*)idxMalloc(pRc, sizeof(IdxConstraint) * nColl + 1);
12220 pNew->zColl = (char*)&pNew[1];
12221 memcpy(pNew->zColl, zColl, nColl+1);
12246 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
12301 assert( zIn[n-1]=='\'' );
12306 for(iIn=1; iIn<(n-1); iIn++){
12308 assert( zIn[iIn+1]=='\'' );
12324 ** argv[1] -> database name
12406 pNew->bRange = 1;
12417 for(i=pIdxInfo->nOrderBy-1; i>=0; i--){
12433 pIdxInfo->estimatedCost = 1000000.0 / (n+1);
12627 nByte = sizeof(IdxTable) + nTab + 1;
12630 const char *zCol = (const char*)sqlite3_column_text(p1, 1);
12636 nByte += 1 + STRLEN(zCol);
12641 nByte += 1 + STRLEN(zColSeq);
12653 pNew->aCol = (IdxColumn*)&pNew[1];
12660 const char *zCol = (const char*)sqlite3_column_text(p1, 1);
12664 nCopy = STRLEN(zCol) + 1;
12666 pNew->aCol[nCol].iPk = (sqlite3_column_int(p1, 5)==1 && nPk==1);
12675 nCopy = STRLEN(zColSeq) + 1;
12690 if( ALWAYS(pNew->zName!=0) ) memcpy(pNew->zName, zTab, nTab+1);
12717 zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
12721 memcpy(&zRet[nIn], zAppend, nAppend+1);
12742 if( sqlite3_keyword_check(zId, nId) ) return 1;
12750 return 1;
12816 int bMatch = 1;
12819 const char *zIdx = (const char*)sqlite3_column_text(pIdxList, 1);
12828 int iCol = sqlite3_column_int(pInfo, 1);
12836 pIter->bFlag = 1;
12857 return 1;
12873 if( nc>0 && (azResults[0][0]!='0' || azResults[0][1]!=0) ){
12874 *((int *)pCount) += 1;
12970 if( p->iCol==pCmp->iCol ) return 1;
13123 /* int iParent = sqlite3_column_int(pExplain, 1); */
13144 while( zIdx[nIdx]!='\0' && (zIdx[nIdx]!=' ' || zIdx[nIdx+1]!='(') ){
13279 rc = sqlite3_prepare_v2(p->dbv, zWrite, -1, &pX, 0);
13318 ** 1) Add an entry to the p->pTable list, and
13322 "SELECT type, name, sql, 1 FROM sqlite_schema "
13328 "ORDER BY 4, 1"
13332 const char *zName = (const char*)sqlite3_column_text(pSchema, 1);
13336 if( zType[0]=='v' || zType[1]=='r' ){
13391 bRet = 1;
13415 } aSlot[1];
13457 pSlot->eType = sqlite3_value_type(argv[1]);
13464 pSlot->iVal = sqlite3_value_int64(argv[1]);
13468 pSlot->rVal = sqlite3_value_double(argv[1]);
13473 int nByte = sqlite3_value_bytes(argv[1]);
13486 pData = sqlite3_value_blob(argv[1]);
13489 pData = sqlite3_value_text(argv[1]);
13510 *pnMax = sqlite3_column_int(pMax, 0) + 1;
13537 sqlite3_bind_text(pIndexXInfo, 1, zIdx, -1, SQLITE_STATIC);
13541 const char *zColl = (const char*)sqlite3_column_text(pIndexXInfo, 1);
13571 aStat = (int*)idxMalloc(&rc, sizeof(int)*(nCol+1));
13576 for(i=0; i<=nCol; i++) aStat[i] = 1;
13583 aStat[i+1]++;
13591 for(i=1; rc==SQLITE_OK && i<=nCol; i++){
13597 sqlite3_bind_text(pWriteStat, 1, zTab, -1, SQLITE_STATIC);
13598 sqlite3_bind_text(pWriteStat, 2, zIdx, -1, SQLITE_STATIC);
13599 sqlite3_bind_text(pWriteStat, 3, zStat, -1, SQLITE_STATIC);
13668 rc = sqlite3_exec(p->dbm, "ANALYZE; PRAGMA writable_schema=1", 0, 0, 0);
13688 pCtx->nSlot = nMax+1;
13700 const char *zTab = (const char*)sqlite3_column_text(pAllIndex, 1);
13785 "WHERE builtin==0", -1, &pStmt, 0);
13791 const char *type = (char*)sqlite3_column_text(pStmt,1);
13847 sqlite3_db_config(pNew->dbm, SQLITE_DBCONFIG_TRIGGER_EQP, 1, (int*)0);
13944 rc = sqlite3_prepare_v2(p->dbv, zStmt, -1, &pStmt, &zStmt);
13950 pNew = (IdxStatement*)idxMalloc(&rc, sizeof(IdxStatement) + n+1);
13952 pNew->zSql = (char*)&pNew[1];
13953 memcpy(pNew->zSql, z, n+1);
13955 if( p->pStatement ) pNew->iId = p->pStatement->iId+1;
14011 p->bRun = 1;
14022 if( p->pStatement ) nRet = p->pStatement->iId+1;
14326 p->rc = sqlite3_prepare_v2(p->db, zSql, -1, &pRet, 0);
14450 assert( p->nKeyVal>1 );
14452 int bLastIsDesc = zDir[ii-1]=='1';
14467 if( ii>1 ){
14471 for(jj=0; jj<ii-1; jj++){
14472 const char *zAlias = (const char*)sqlite3_column_name(p->pCheck,jj+1);
14474 zRhs = intckMprintf(p, "%z%squote(?%d)", zRhs, zRhsSep, jj+1);
14501 sqlite3_bind_value(pStmt, ii+1, sqlite3_column_value(p->pCheck, ii+1));
14534 "WHERE ?1 IS NULL OR table_name%s?1 "
14535 "ORDER BY 1"
14540 sqlite3_bind_text(pStmt, 1, zPrev, -1, SQLITE_TRANSIENT);
14566 int iRet = 1;
14568 while( 1 ){
14628 nOpen = 1;
14636 ** when nOpen==1. */
14637 if( nOpen==1 ){
14645 iStart = iOff+1;
14666 /* iStart is now the byte offset of 1 byte passed the final ')' in the
14683 while( nRet>0 && intckIsSpace(zRet[nRet-1]) ) nRet--;
14701 int idx = sqlite3_value_int(apVal[1]);
14734 "SELECT 1 FROM %Q.sqlite_schema WHERE name=%Q AND type='index'",
14738 bRet = 1;
14771 " SELECT 1 FROM tabname, pragma_index_list(tab, db) AS l"
14773 " AND NOT EXISTS (SELECT 1 FROM sqlite_schema WHERE name=l.name)"
14777 /* Table idx_cols contains 1 row for each column in each index on the
14799 " SELECT '', 1, '_rowid_', '_rowid_', 'r1' FROM without_rowid WHERE b=0"
14837 " (SELECT sql FROM sqlite_schema WHERE name=idx_name), -1"
14892 " 'CASE WHEN (' || group_concat(col_alias, ', ') || ', 1) IS (\n' "
14893 " || ' SELECT ' || group_concat(col_expr, ', ') || ', 1 FROM '"
14945 " (SELECT 1 FROM %%Q.%%Q AS i INDEXED BY %%Q WHERE %%s%%s)\n"
14986 " SELECT o_pk || ', ii', n_pk+1 FROM tabpk"
15015 *pnKeyVal = sqlite3_column_int(pStmt, 1);
15020 if( bAutoIndex ) intckExec(p, "PRAGMA automatic_index = 1");
15037 pNew = (sqlite3_intck*)sqlite3_malloc(sizeof(*pNew) + nDb + 1);
15043 pNew->zDb = (const char*)&pNew[1];
15044 memcpy(&pNew[1], zDb, nDb+1);
15065 p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0
15108 p->bCorruptSchema = 1;
15192 #define SQLITE_SHELL_HAVE_RECOVER 1
15221 ** 1) Creates an sqlite3_recover handle by calling either
15347 ** int containing value 0 or 1 cast as a (void*). If this option is set
15348 ** (argument is 1) and a lost-and-found table has been configured using
15358 ** int containing value 0 or 1 cast as a (void*). If this option is set
15359 ** (argument is 1), then an attempt is made to recover rowid values
15362 ** default value is 1 (set).
15366 ** int containing value 0 or 1 cast as a (void*). If this option is clear
15374 ** Or, if this option is set (argument is 1), then non-UNIQUE indexes
15381 #define SQLITE_RECOVER_LOST_AND_FOUND 1
15489 ** field -1.
15498 ** page 1, content equivalent to:
15501 ** (2, 0, -1, 5 ),
15503 ** (2, 0, 1, 'five'),
15504 ** (2, 1, -1, 10 ),
15505 ** (2, 1, 0, 'x' ),
15506 ** (2, 1, 1, 'ten' );
15587 #define DBDATA_COLUMN_CELL 1
15602 #define DBPTR_COLUMN_CHILD 1
15692 ** position 1.
15697 int iSchema = -1;
15698 int iPgno = -1;
15715 pIdx->aConstraintUsage[iSchema].argvIndex = 1;
15716 pIdx->aConstraintUsage[iSchema].omit = 1;
15719 pIdx->aConstraintUsage[iPgno].argvIndex = 1 + (iSchema>=0);
15720 pIdx->aConstraintUsage[iPgno].omit = 1;
15726 if( pIdx->nOrderBy==1 ){
15727 pIdx->orderByConsumed = (iCol==0 || iCol==1);
15728 }else if( pIdx->nOrderBy==2 && pIdx->aOrderBy[1].desc==0 && iCol==0 ){
15729 pIdx->orderByConsumed = (pIdx->aOrderBy[1].iColumn==1);
15771 pCsr->iPgno = 1;
15795 return (a[0]<<8)|a[1];
15799 | ((u32)a[1]<<16)
15859 if( (z[i]&0x80)==0 ){ *pVal = (sqlite3_int64)u; return i+1; }
15888 case 1:
15889 return 1;
15933 sqlite3_result_int(pCtx, 1);
15936 case 1: case 2: case 3: case 4: case 5: case 6: case 7: {
15941 case 6: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2;
15942 case 5: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2;
16010 while( 1 ){
16012 int iOff = (pCsr->iPgno==1 ? 100 : 0);
16016 while( 1 ){
16067 bHasRowid = 1;
16076 bNextPage = 1;
16081 bNextPage = 1;
16091 bNextPage = 1;
16095 if( nPayload==0 ) nPayload = 1;
16124 bNextPage = 1;
16169 pCsr->iField = (bHasRowid ? -1 : 0);
16179 bNextPage = 1;
16230 if( n>2 && zSchema[n-2]=='(' && zSchema[n-1]==')' ){
16256 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0);
16267 ** Attempt to figure out the encoding of the database by retrieving page 1
16275 rc = dbdataLoadPage(pCsr, 1, &aPg1, &nPg1);
16300 assert( pCsr->iPgno==1 );
16307 pCsr->bOnePage = 1;
16322 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
16327 "SELECT data FROM sqlite_dbpage(?) WHERE pgno=?", -1,
16333 rc = sqlite3_bind_text(pCsr->pStmt, 1, zSchema, -1, SQLITE_TRANSIENT);
16337 ** field on page 1. */
16368 int iOff = pCsr->iPgno==1 ? 100 : 0;
16455 rc = sqlite3_create_module(db, "sqlite_dbptr", &dbdata_module, (void*)1);
16536 ** Otherwise, it contains -1. If the table does contain an INTEGER PRIMARY
16562 ** The index of the associated field within database records. Or -1 if
16587 #define RECOVER_EHIDDEN_HIDDEN 1 /* Column is __HIDDEN__ */
16602 ** of valid keys is 1 to nPg, inclusive.
16610 ** (aElem[iKey/32] & (1 << (iKey%32))) ? 1 : 0
16615 u32 aElem[1]; /* Array of 32-bit bitmasks */
16727 #define RECOVER_STATE_WRITING 1
16755 #define RECOVER_ROWID_DEFAULT 1
16775 #if SQLITE_THREADSAFE+0>=1 && defined(SQLITE_DEBUG)
16852 ** large enough to store a bit for all page numbers between 1 and nPg,
16856 int nElem = (nPg+1+31) / 32;
16880 pMap->aElem[iElem] |= (((u32)1) << iBit);
16886 ** iPg. Return 1 if it is set, or 0 otherwise.
16889 int ret = 1;
16893 ret = (pMap->aElem[iElem] & (((u32)1) << iBit)) ? 1 : 0;
16923 if( sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) ){
17102 iInt = sqlite3_value_int(argv[1]) & 0xFFFF;
17104 if( (iInt+1)*4<=nBlob ){
17107 + ((i64)a[1]<<16)
17133 assert( nArg==1 );
17160 assert( nArg==1 );
17175 sqlite3_bind_int64(pStmt, 1, pgno);
17182 if( pgno==1 && nPg==p->pgsz && 0==memcmp(p->pPage1Cache, aPg, nPg) ){
17192 if( p->zErrMsg ) sqlite3_result_error(pCtx, p->zErrMsg, -1);
17324 " SELECT 1"
17330 " max(CASE WHEN field=1 THEN value ELSE NULL END),"
17411 sqlite3_backup_step(pBackup, -1);
17442 { "getpage", 1, recoverGetPage },
17443 { "page_is_used", 1, recoverPageIsUsed },
17445 { "escape_crnl", 1, recoverEscapeCrnl },
17488 "PRAGMA writable_schema = 1;"
17519 int iPk = -1;
17520 int iBind = 1;
17527 nByte += (sqlite3_column_bytes(pStmt, 1)+1);
17529 nByte += sizeof(RecoverTable) + nCol*sizeof(RecoverColumn) + nName+1;
17537 pNew->aCol = (RecoverColumn*)&pNew[1];
17542 csr += nName+1;
17546 int n = sqlite3_column_bytes(pStmt, 1);
17547 const char *z = (const char*)sqlite3_column_text(pStmt, 1);
17551 if( iPk==-1 && iPKF==1 && !sqlite3_stricmp("integer", zType) ) iPk = i;
17552 if( iPKF>1 ) iPk = -2;
17556 pNew->aCol[i].iField = -1;
17566 csr += (n+1);
17571 pNew->bIntkey = 1;
17579 int iCol = sqlite3_column_int(pStmt, 1);
17591 pNew->aCol[iPk].bIPK = 1;
17627 " (type='index' AND (sql LIKE '%unique%' OR ?1))"
17638 "WHERE type='table' ORDER BY rowid DESC LIMIT 1"
17642 sqlite3_bind_int(pSelect, 1, p->bSlowIndexes);
17645 int bTable = sqlite3_column_int(pSelect, 1);
17707 const char *zSql = (const char*)sqlite3_column_text(pSelect, 1);
17733 ** CREATE TABLE name(a, b GENERATED ALWAYS AS (a+1) STORED, c, d, e);
17737 ** INSERT INTO (a, c, d) VALUES (?1, ?2, ?3);
17749 ** || quote(?1) || ', '
17768 int bSql = p->xSql ? 1 : 0;
17793 assert( pTab->aCol[ii].iField>=0 && pTab->aCol[ii].iBind>=1 );
17854 "SELECT 1 FROM sqlite_schema WHERE name=?"
17856 for(ii=-1; zTbl==0 && p->errCode==SQLITE_OK && ii<1000; ii++){
17865 sqlite3_bind_text(pProbe, 1, zTbl, -1, SQLITE_STATIC);
17867 bFail = 1;
17971 sqlite3_bind_int64(pLaf->pFindRoot, 1, iPg);
17992 int nVal = -1;
18000 sqlite3_bind_int64(pPageData, 1, iPage);
18003 int iField = sqlite3_column_int64(pPageData, 1);
18007 sqlite3_bind_int64(pInsert, 1, iRoot); /* rootpgno */
18028 nVal = -1;
18034 assert( nVal==-1 );
18036 bHaveRowid = 1;
18041 assert( iField==nVal || (nVal==-1 && iField==0) );
18042 nVal = iField+1;
18106 " SELECT 1 UNION ALL SELECT ii+1 FROM seq WHERE ii<%lld"
18114 "SELECT -1, -1, -1"
18141 nByte = sizeof(sqlite3_value*) * (p1->nMax+1);
18154 " SELECT ?1"
18221 sqlite3_bind_int64(pSel, 1, iRoot);
18225 p1->iPrevPage = -1;
18226 p1->iPrevCell = -1;
18237 int iCell = sqlite3_column_int(pSel, 1);
18242 assert( bNewCell==0 || (iField==-1 || iField==0) );
18283 p1->nVal = -1;
18290 assert( p1->nVal==-1 );
18292 p1->bHaveRowid = 1;
18299 p1->nVal = iField+1;
18332 " SELECT read_i32(getpage(1), 8) AS x WHERE x>0"
18340 " SELECT data, min(16384, read_i32(data, 1)-1), pgno FROM trunkdata"
18342 " SELECT data, n-1, read_i32(data, 2+n) FROM freelist WHERE n>=0"
18346 " SELECT 1 UNION ALL"
18359 if( pStmt ) sqlite3_bind_int(pStmt, 1, p->bFreelistCorrupt);
18404 " SELECT 1 UNION ALL SELECT ii+1 FROM seq WHERE ii<%lld"
18411 "SELECT max(field)+1 FROM sqlite_dbdata('getpage') WHERE pgno = ?"
18427 i64 iChild = sqlite3_column_int(pLaf->pAllAndParent, 1);
18429 sqlite3_bind_int64(pLaf->pMapInsert, 1, iChild);
18435 sqlite3_bind_int64(pLaf->pMaxField, 1, iChild);
18512 return (((u32)a[0])<<8) + ((u32)a[1]);
18520 return (((u32)a[0])<<24) + (((u32)a[1])<<16) + (((u32)a[2])<<8) + ((u32)a[3]);
18532 if( (a[i]&0x80)==0 ){ *pVal = (sqlite3_int64)u; return i+1; }
18559 iFree = (int)recoverGetU16(&a[1]);
18689 a[1] = (v>>0) & 0x00FF;
18697 a[1] = (v>>16) & 0x00FF;
18736 nBlk = (nSz+nMax-1)/nMax;
18741 int nByte = (nSz>=((iBlk+1)*nMax)) ? nMax : (nSz % nMax);
18763 }while( 1 );
18772 ** to read page 1 of the input database.
18863 if( pgsz==65536 ) pgsz = 1;
19015 int iVersion = 1 + (pFd->pMethods->iVersion>1 && pFd->pMethods->xShmMap!=0);
19064 if( p->errCode==SQLITE_OK ) p->bCloseTransaction = 1;
19065 recoverExec(p, p->dbIn, "SELECT 1 FROM sqlite_schema");
19179 nByte = sizeof(sqlite3_recover) + nDb+1 + nUri+1;
19184 pRet->zDb = (char*)&pRet[1];
19185 pRet->zUri = &pRet->zDb[nDb+1];
19376 char zText[1]; /* Text to display for this row */
19394 #define ColModeOpts_default_qbox { 60, 1, 0 }
19488 #define AUTOEQP_on 1 /* Automatic EQP is on */
19495 #define SHELL_OPEN_NORMAL 1 /* Normal database file */
19505 #define SHELL_TRACE_EXPANDED 1 /* Show expanded SQL text */
19541 #define MODE_Column 1 /* One record per line in neat columns */
19645 exit(1);
19655 ** (1) Write VALUE into a temporary file.
19684 zEditor = (const char*)sqlite3_value_text(argv[1]);
19689 sqlite3_result_error(context, "no editor for edit()", -1);
19693 sqlite3_result_error(context, "NULL input to edit()", -1);
19713 sqlite3_result_error(context, "edit() cannot open temp file", -1);
19718 x = fwrite(sqlite3_value_blob(argv[0]), 1, (size_t)sz, f);
19722 if( z && strstr(z,"\r\n")!=0 ) hasCRNL = 1;
19723 x = fwrite(sqlite3_value_text(argv[0]), 1, (size_t)sz, f);
19728 sqlite3_result_error(context, "edit() could not write the whole file", -1);
19739 sqlite3_result_error(context, "EDITOR returned non-zero", -1);
19745 "edit() cannot reopen temp file after edit", -1);
19751 p = sqlite3_malloc64( sz+1 );
19756 x = fread(p, 1, (size_t)sz, f);
19760 sqlite3_result_error(context, "could not read back the whole file", -1);
19774 if( p[i]=='\r' && p[i+1]=='\n' ) i++;
19816 char *zStr = sqlite3_malloc(nBlob*2 + 1);
19821 '0', '1', '2', '3', '4', '5', '6', '7',
19825 zStr[i*2+1] = aHex[ (aBlob[i] & 0x0F) ];
19864 setBinaryMode(pfO, 1);
19891 setTextMode(pfO, 1);
19893 setTextMode(stdout, 1);
19911 setBinaryMode(pfO, 1);
19965 setTextMode(pfO, 1);
19967 setTextMode(stdout, 1);
20017 ace[1] = cbsSay;
20022 ace[1] = (char)c;
20023 oputz(ace+1);
20067 ace[1] = cbsSay;
20072 ace[1] = (char)c;
20073 oputz(ace+1);
20110 z += i + 1;
20115 ** If a field contains any character identified by a 1 in the following
20119 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20120 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20121 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
20126 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
20127 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20128 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20129 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20130 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20131 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20132 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20133 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20134 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20173 if( ++seenInterrupt>1 ) exit(1);
20269 az[1] = zA2;
20310 zNew[n-1] = 0;
20339 if( z[i]=='\n' ) return 1;
20341 if( z[i]=='-' && z[i+1]=='-' ) return 1;
20344 return 1;
20362 memcpy(pNew->zText, zText, nText+1);
20449 return 1;
20463 const int nDash = sizeof(zDash) - 1;
20483 for(i=1; i<nArg; i++){
20529 static const int aExplainMap[] = {0, 1, 2, 3, 4, 5, 6, 7 };
20531 static const int aScanExpMap[] = {0, 9, 8, 1, 2, 3, 4, 5, 6, 7 };
20536 int iIndent = 1;
20550 oputz(i==nArg-1 ? "\n" : " ");
20554 oputz(i==nArg-1 ? "\n" : " ");
20565 if( i==nArg-1 ) w = 0;
20577 oputz(i==nArg-1 ? "\n" : zSep);
20592 assert( nArg==1 );
20606 if( z[j-1]=='\r' ) z[j-1] = '\n';
20607 if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
20608 }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
20613 while( j>0 && IsSpace(z[j-1]) ){ j--; }
20623 }else if( c=='-' && z[i+1]=='-' ){
20635 if( nParen==1 && cEnd==0
20636 && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1)))
20642 while( IsSpace(z[i+1]) ){ i++; }
20654 oputf("%s%s",azCol[i], i==nArg-1 ? p->rowSeparator : p->colSeparator);
20662 oputz((i<nArg-1)? p->colSeparator : p->rowSeparator);
20690 if(i<nArg-1) oputz(p->colSeparator);
20697 if(i<nArg-1) oputz(p->colSeparator);
20703 setBinaryMode(p->out, 1);
20706 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
20712 output_csv(p, azArg[i], i<nArg-1);
20716 setTextMode(p->out, 1);
20792 output_json_string(azCol[i], -1);
20814 output_json_string(azArg[i], -1);
20818 if( i<nArg-1 ){
20878 eqp_append(p, atoi(azArg[0]), atoi(azArg[1]), azArg[3]);
20978 z = p->zDestTable = malloc( n+1 );
21039 ** If the number of columns is 1 and that column contains text "--"
21053 rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
21067 for(i=1; i<nResult; i++){
21071 while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
21100 if( rc>1 ){
21158 sqlite3_int64 iCur = -1;
21159 sqlite3_int64 iHiwtr = -1;
21166 if( nPercent>1 ){
21239 iHiwtr = iCur = -1;
21253 iHiwtr = iCur = -1;
21256 iHiwtr = iCur = -1;
21257 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
21259 iHiwtr = iCur = -1;
21260 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
21262 iHiwtr = iCur = -1;
21263 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
21265 iHiwtr = iCur = -1;
21266 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_SPILL, &iCur, &iHiwtr, 1);
21268 iHiwtr = iCur = -1;
21271 iHiwtr = iCur = -1;
21315 int ret = 1;
21321 for(ii=0; 1; ii++){
21352 for(ii=0; 1; ii++){
21363 sqlite3_stmt_scanstatus_v2(p, -1, SQLITE_SCANSTAT_NCYCLE, f, (void*)&nTotal);
21364 for(ii=0; 1; ii++){
21401 if( zName && pArg->scanstatsOn>1 ){
21403 z = sqlite3_mprintf("%z rpl=%.1f est=%.1f", z, rpl, rEst);
21407 "% *z (%z)", -1*(nWidth-scanStatsHeight(p, ii)*3), zText, z
21429 if( 0==cli_strcmp(zStr, azArray[i]) ) return 1;
21472 assert( 0==sqlite3_stricmp( sqlite3_column_name(pSql, 1), "opcode" ) );
21479 const char *zOp = (const char*)sqlite3_column_text(pSql, 1);
21500 p->nIndent = iOp+1;
21545 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
21549 sqlite3_bind_pointer(pStmt, 1, pSave, "stmt-pointer", 0);
21574 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 1, &zero);
21579 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 1, &savedSelectTrace);
21587 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
21589 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
21590 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
21628 " WHERE key=?1", -1, &pQ, 0);
21630 for(i=1; i<=nVar; i++){
21637 sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
21659 ** 1
21688 const int nDash = sizeof(zDash) - 1;
21711 for(i=1; i<nArg; i++){
21769 if( isspace(z[k-1]) ) break;
21773 if( isalnum(z[k-1])!=isalnum(z[k]) && (z[k]&0xc0)!=0x80 ) break;
21787 }else if( z[i]=='\r' && z[i+1]=='\n' ){
21789 }else if( z[i]==0 || z[i+1]==0 ){
21792 *pzTail = &z[i+1];
21794 zOut = malloc( j+1 );
21842 sqlite3_str_append(pStr, "'", 1);
21888 if( nAlloc<=0 ) nAlloc = 1;
21902 p->colWidth = realloc(p->colWidth, (nColumn+1)*2*sizeof(int));
21935 abRowDiv[nRow] = 1;
21957 bNextLine = 1;
21958 abRowDiv[nRow-1] = 0;
21959 bMultiLineRowExists = 1;
21963 nTotal = nColumn*(nRow+1);
21981 fputs(i==nColumn-1?"\n":" ", p->out);
21985 fputs(i==nColumn-1?"\n":" ", p->out);
21998 oputf("%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, "");
21999 oputz(i==nColumn-1?" |\n":" | ");
22011 oputf("%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, "");
22012 oputz(i==nColumn-1?" |\n":" | ");
22026 (w-n)/2, "", azData[i], (w-n+1)/2, "",
22027 i==nColumn-1?" "BOX_13"\n":" "BOX_13" ");
22042 if( j==nColumn-1 ){
22044 if( bMultiLineRowExists && abRowDiv[i/nColumn-1] && i+1<nTotal ){
22053 j = -1;
22068 nData = (nRow+1)*nColumn;
22109 void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
22157 nRow, nRow!=1 ? "s" : "");
22187 ** created by the ".expert" command (if bCancel==1), or to generate a
22223 oputf("-- Query %d --------------------------------\n",i+1);
22252 for(i=1; rc==SQLITE_OK && i<nArg; i++){
22255 if( z[0]=='-' && z[1]=='-' ) z++;
22258 pState->expert.bVerbose = 1;
22261 if( i==(nArg-1) ){
22328 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
22355 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
22357 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
22366 int iParentId = sqlite3_column_int(pExplain, 1);
22376 rc = sqlite3_stmt_explain(pExplain, 1);
22379 assert( sqlite3_stmt_isexplain(pExplain)==1 );
22394 int bIsExplain = (sqlite3_stmt_isexplain(pStmt)==1);
22454 for(i=1; azCol[i]; i++){
22471 ** The first regular column in the table is azCol[1]. The list is terminated
22487 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
22496 azCol[++nCol] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1));
22500 if( nPK==1
22504 isIPK = 1;
22513 azCol[nCol+1] = 0;
22529 zSql = sqlite3_mprintf("SELECT 1 FROM pragma_index_list(%Q)"
22532 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
22548 for(i=1; i<=nCol; i++){
22572 sqlite3_prepare_v2(db, "PRAGMA reverse_unordered_selects", -1, &pStmt, 0);
22600 zType = azArg[1];
22619 p->writableSchema = 1;
22658 for(i=1; azCol[i]; i++){
22672 for(i=1; azCol[i]; i++){
22674 if( azCol[i+1] ){
22890 " --ww Shorthand for \"--wordwrap 1\"",
23061 enum HelpWanted { HW_NoCull = 0, HW_SummaryOnly = 1, HW_Undoc = 2 };
23062 enum HelpHave { HH_Undoc = 2, HH_Summary = 1, HH_More = 0 };
23087 sputf(out, ".%s\n", azHelp[i]+1);
23101 j = i+1;
23107 if( n==1 ){
23110 while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){
23123 while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i;
23129 while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){
23175 pBuf = sqlite3_malloc64( nIn+1 );
23181 nRead = fread(pBuf, nIn, 1, in);
23183 if( nRead!=1 ){
23237 return 1;
23262 n = fread(zBuf, 16, 1, f);
23263 if( n==1 && memcmp(zBuf, "SQLite format 3", 16)==0 ){
23268 n = fread(zBuf, 25, 1, f);
23269 if( n==1 && memcmp(zBuf, "Start-Of-SQLite3-", 17)==0 ){
23273 n = fread(zBuf, 22, 1, f);
23274 if( n==1 && zBuf[0]==0x50 && zBuf[1]==0x4b && zBuf[2]==0x05
23321 if( pgsz<512 || pgsz>65536 || (pgsz&(pgsz-1))!=0 ) goto readHexDb_error;
23322 n = (n+pgsz-1)&~(pgsz-1); /* Round n up to the next multiple of pgsz */
23323 a = sqlite3_malloc( n ? n : 1 );
23326 if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){
23340 &j, &x[0], &x[1], &x[2], &x[3], &x[4], &x[5], &x[6], &x[7],
23390 ** The default behavior of open_db() is to exit(1) if the database fails to
23447 exit(1);
23453 exit(1);
23470 sqlite3_enable_load_extension(p->db, 1);
23518 sqlite3_create_function(p->db, "strtod", 1, SQLITE_UTF8, 0,
23520 sqlite3_create_function(p->db, "dtostr", 1, SQLITE_UTF8, 0,
23526 sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
23528 sqlite3_create_function(p->db, "shell_putsnl", 1, SQLITE_UTF8, p,
23530 sqlite3_create_function(p->db, "usleep",1,SQLITE_UTF8,0,
23533 sqlite3_create_function(p->db, "edit", 1, SQLITE_UTF8, 0,
23603 " FROM completion(%Q) ORDER BY 1", text);
23605 sqlite3_prepare_v2(globalDb, zSql, -1, &pStmt, 0);
23621 rl_attempted_completion_over = 1;
23638 for(i=nLine-1; i>=0 && (isalnum(zLine[i]) || zLine[i]=='_'); i--){}
23639 if( i==nLine-1 ) return;
23640 iStart = i+1;
23643 " FROM completion(%Q,%Q) ORDER BY 1",
23646 sqlite3_prepare_v2(globalDb, zSql, -1, &pStmt, 0);
23652 if( iStart+nCompletion < (i64)sizeof(zBuf)-1 && zCompletion ){
23653 memcpy(zBuf+iStart, zCompletion, nCompletion+1);
23683 if( c=='\\' && z[i+1]!=0 ){
23708 while( nhd<2 && (c=z[i+1+nhd])!=0 && (hdv=hexDigitValue(c))>=0 ){
23716 if( z[i+1]>='0' && z[i+1]<='7' ){
23719 if( z[i+1]>='0' && z[i+1]<='7' ){
23732 ** Interpret zArg as either an integer or a boolean value. Return 1 or 0
23737 if( zArg[0]=='0' && zArg[1]=='x' ){
23744 return 1;
23836 while( nSql>0 && zSql[nSql-1]==';' ){ nSql--; }
23897 if( p->n+1>=p->nAlloc ){
23933 while( 1 ){
23974 p->bNotFirst = 1;
23986 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
23991 p->bNotFirst = 1;
24052 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
24064 for(j=1; j<n; j++){
24069 rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0);
24080 sqlite3_bind_null(pInsert, i+1);
24084 sqlite3_bind_int64(pInsert, i+1, sqlite3_column_int64(pQuery,i));
24088 sqlite3_bind_double(pInsert, i+1, sqlite3_column_double(pQuery,i));
24092 sqlite3_bind_text(pInsert, i+1,
24094 -1, SQLITE_STATIC);
24098 sqlite3_bind_blob(pInsert, i+1, sqlite3_column_blob(pQuery,i),
24123 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
24160 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
24168 zSql = sqlite3_column_text(pQuery, 1);
24190 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
24198 zSql = sqlite3_column_text(pQuery, 1);
24312 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
24325 return (a[0]<<8) + a[1];
24328 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
24334 ** Return 1 on error, 2 to exit, and 0 otherwise.
24366 char *zDb = nArg>=2 ? azArg[1] : "main";
24370 if( p->db==0 ) return 1;
24372 "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
24373 -1, &pStmt, 0);
24377 return 1;
24379 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
24390 return 1;
24393 if( i==1 ) i = 65536;
24404 if( val==1 ) oputz(" (utf8)");
24432 ** Print the current sqlite3_errmsg() value to stderr and return 1.
24437 return 1;
24478 return 1;
24480 while( *z && testcase_glob(zGlob-1,z)==0 ){
24490 if( testcase_glob(zGlob,z) ) return 1;
24503 invert = 1;
24507 if( c==']' ) seen = 1;
24513 if( c>=prior_c && c<=c2 ) seen = 1;
24517 seen = 1;
24525 if( (z[0]=='-' || z[0]=='+') && IsDigit(z[1]) ) z++;
24640 zParentCol = (const char*)sqlite3_value_text(apVal[1]);
24644 sqlite3_result_text(pCtx, "", -1, SQLITE_STATIC);
24656 sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
24684 ** "EXPLAIN QUERY PLAN SELECT 1 FROM child_table WHERE child_key=?"
24692 ** 1. A GLOB pattern suitable for sqlite3_strglob(). If the plan output by
24715 " 'EXPLAIN QUERY PLAN SELECT 1 FROM ' || quote(s.name) || ' WHERE '"
24736 "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
24744 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
24745 bVerbose = 1;
24747 else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){
24748 bGroupByParent = 1;
24752 eputf("Usage: %s %s ?-verbose? ?-groupbyparent?\n", azArg[0], azArg[1]);
24764 rc = sqlite3_prepare_v2(db, zSql, -1, &pSql, 0);
24767 sqlite3_bind_int(pSql, 1, bGroupByParent);
24774 int res = -1;
24777 const char *zGlob = (const char*)sqlite3_column_text(pSql, 1);
24785 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
24844 n = (nArg>=2 ? strlen30(azArg[1]) : 0);
24845 if( n<1 || sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ) goto usage;
24863 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
24994 #define AR_CMD_CREATE 1
25028 pAr->bDryRun = 1;
25031 pAr->bGlob = 1;
25034 pAr->bVerbose = 1;
25037 pAr->bAppend = 1;
25075 { "file", 'f', AR_SWITCH_FILE, 1 },
25076 { "append", 'a', AR_SWITCH_APPEND, 1 },
25077 { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
25084 if( nArg<=1 ){
25088 char *z = azArg[1];
25117 for(iArg=1; iArg<nArg; iArg++){
25128 if( z[1]!='-' ){
25131 for(i=1; i<n; i++){
25141 if( i<(n-1) ){
25142 zArg = &z[i+1];
25145 if( iArg>=(nArg-1) ){
25157 pAr->azArg = &azArg[iArg+1];
25158 pAr->nArg = nArg-iArg-1;
25180 if( iArg>=(nArg-1) ){
25226 while( n>0 && z[n-1]=='/' ) n--;
25228 sqlite3_bind_text(pTest, j, z, -1, SQLITE_STATIC);
25230 bOk = 1;
25260 zWhere = sqlite3_mprintf("1");
25267 "%z%s name %s '%q' OR substr(name,1,%d) %s '%q/'",
25268 zWhere, zSep, zSameOp, z, strlen30(z)+1, zSameOp, z
25306 sqlite3_column_text(pSql, 0), sqlite3_column_int(pSql, 1),
25402 sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC);
25489 " CASE substr(lsmode(mode),1,1)\n"
25492 " ELSE -1 END,\n"
25545 "SELECT 1 FROM %s AS mem"
25594 eDbType = deduceDatabaseType(cmd.zFile, 1);
25606 cmd.bZip = 1;
25629 sqlite3_create_function(cmd.db, "shell_putsnl", 1, SQLITE_UTF8, cmd.p,
25662 rc = arCreateOrUpdateCommand(&cmd, 1, 0);
25671 rc = arCreateOrUpdateCommand(&cmd, 1, 1);
25708 int bFreelist = 1; /* 0 if --ignore-freelist is specified */
25709 int bRowids = 1; /* 0 if --no-rowids */
25713 for(i=1; i<nArg; i++){
25716 if( z[0]=='-' && z[1]=='-' ) z++;
25721 if( n<=12 && memcmp("-recovery-db", z, n)==0 && i<(nArg-1) ){
25730 if( n<=15 && memcmp("-lost-and-found", z, n)==0 && i<(nArg-1) ){
25740 return 1;
25855 VALUES(iif(length(?1)>0,?1,'?'),max(length(?1),1),0,0,'')\
25858 SELECT count(DISTINCT (substring(name,1,nlen-chop)||suff) COLLATE NOCASE)\
25864 (substring(name,nlen,1) BETWEEN '0' AND '9')\
25874 WHERE substring(t.name,1,t.nlen-t.chop)=substring(d.name,1,d.nlen-d.chop)\
25885 SELECT CASE WHEN (nc < 10) THEN 1 WHEN (nc < 100) THEN 2 \
25893 "iif(reps>1, printf('%c%0*d', '"AUTOCOLUMN_SEP"', $1, cpos), '')"
25898 " SELECT nlz+1 AS nlz FROM Lzn"
25900 " SELECT 1"
25905 " t.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,t.cpos),2)),"
25911 " o.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,o.cpos),2)),"
25922 " printf('%.*c%0.*d',(SELECT max(nlz) FROM Lzn)+1,'0',1,t.cpos),2)),"
25932 ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\
25961 rc = sqlite3_prepare_v2(*pDb, zTabFill, -1, &pStmt, 0);
25963 rc = sqlite3_bind_text(pStmt, 1, zColNew, -1, 0);
25983 rc = sqlite3_prepare_v2(*pDb, zRenameRank, -1, &pStmt, 0);
25985 sqlite3_bind_int(pStmt, 1, nDigits);
25991 rc = sqlite3_prepare_v2(*pDb, zCollectVar, -1, &pStmt, 0);
26003 if( SQLITE_OK==sqlite3_prepare_v2(*pDb, zRenamesDone, -1, &pStmt, 0)
26029 "SELECT 1 FROM sqlite_schema o WHERE "
26045 int iId; /* ID that triggers a simulated fault. -1 means "any" */
26053 } faultsim_state = {-1, 0, 0, 0, 0, 0, 0, 0};
26069 if( faultsim_state.eVerbose>=1 ){
26075 faultsim_state.iCnt = -1;
26084 ** Return 1 on error, 2 to exit, and 0 otherwise.
26087 int h = 1;
26095 expertFinish(p, 1, 0);
26101 while( zLine[h] && nArg<ArraySize(azArg)-1 ){
26108 if( zLine[h]=='\\' && delim=='"' && zLine[h+1]!=0 ) h++;
26114 if( delim=='"' ) resolve_backslashes(azArg[nArg-1]);
26134 rc = 1;
26138 if( booleanValue(azArg[1]) ){
26169 for(j=1; j<nArg; j++){
26172 if( z[1]=='-' ) z++;
26177 bAsync = 1;
26181 return 1;
26190 return 1;
26195 return 1;
26203 return 1;
26214 return 1;
26222 rc = 1;
26230 bail_on_error = booleanValue(azArg[1]);
26233 rc = 1;
26240 if( booleanValue(azArg[1]) ){
26241 setBinaryMode(p->out, 1);
26243 setTextMode(p->out, 1);
26248 rc = 1;
26264 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
26268 rc = chdir(azArg[1]);
26271 eputf("Cannot change to directory \"%s\"\n", azArg[1]);
26272 rc = 1;
26276 rc = 1;
26283 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
26286 rc = 1;
26293 ** azArg[1]. If there are differences, report an error and exit.
26303 }else if( testcase_glob(azArg[1],zRes)==0 ){
26305 p->zTestcase, azArg[1], zRes);
26306 rc = 1;
26319 tryToClone(p, azArg[1]);
26322 rc = 1;
26328 if( nArg==1 ){
26346 }else if( nArg==2 && IsDigit(azArg[1][0]) && azArg[1][1]==0 ){
26347 int i = azArg[1][0] - '0';
26354 }else if( nArg==3 && cli_strcmp(azArg[1], "close")==0
26355 && IsDigit(azArg[2][0]) && azArg[2][1]==0 ){
26361 rc = 1;
26369 rc = 1;
26375 if( booleanValue(azArg[1]) ){
26376 setTextMode(p->out, 1);
26378 setBinaryMode(p->out, 1);
26385 rc = 1;
26389 if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){
26395 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
26398 rc = 1;
26401 const char *zSchema = (const char *)sqlite3_column_text(pStmt,1);
26404 azName = sqlite3_realloc(azName, (nName+1)*2*sizeof(char*));
26407 azName[nName*2+1] = strdup(zFile);
26415 const char *z = azName[i*2+1];
26421 free(azName[i*2+1]);
26453 if( nArg>1 && cli_strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
26457 sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
26459 if( nArg>1 ) break;
26461 if( nArg>1 && ii==ArraySize(aDbConfig) ){
26462 eputf("Error: unknown dbconfig \"%s\"\n", azArg[1]);
26487 for(i=1; i<nArg; i++){
26489 const char *z = azArg[i]+1;
26495 rc = 1;
26513 rc = 1;
26525 " SELECT 1 FROM sqlite_schema WHERE "
26528 " substr(o.name, 1, length(name)+1) == (name||'_')"
26594 setOrClearFlag(p, SHFLG_Echo, azArg[1]);
26597 rc = 1;
26608 if( cli_strcmp(azArg[1],"full")==0 ){
26610 }else if( cli_strcmp(azArg[1],"trigger")==0 ){
26613 }else if( cli_strcmp(azArg[1],"test")==0 ){
26615 p->autoEQPtest = 1;
26616 }else if( cli_strcmp(azArg[1],"trace")==0 ){
26618 p->autoEQPtrace = 1;
26620 sqlite3_exec(p->db, "SELECT name FROM sqlite_schema LIMIT 1", 0, 0, 0);
26624 p->autoEQP = (u8)booleanValue(azArg[1]);
26628 rc = 1;
26634 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
26642 int val = 1;
26644 if( cli_strcmp(azArg[1],"auto")==0 ){
26647 val = booleanValue(azArg[1]);
26650 if( val==1 && p->mode!=MODE_Explain ){
26659 p->autoExplain = 1;
26668 rc = 1;
26694 int filectrl = -1;
26695 int iCtrl = -1;
26696 sqlite3_int64 iRes = 0; /* Integer result to display if rc2==1 */
26697 int isOk = 0; /* 0: usage 1: %lld 2: no-result */
26703 zCmd = nArg>=2 ? azArg[1] : "help";
26712 zCmd = azArg[1];
26716 if( zCmd[0]=='-' && zCmd[1] ){
26718 if( zCmd[0]=='-' && zCmd[1] ) zCmd++;
26727 rc = 1;
26742 rc = 1;
26754 iRes = nArg==3 ? integerValue(azArg[2]) : -1;
26756 isOk = 1;
26772 x = nArg==3 ? booleanValue(azArg[2]) : -1;
26775 isOk = 1;
26784 isOk = 1;
26804 x = -1;
26814 rc = 1;
26815 }else if( isOk==1 ){
26828 if( nArg==2 && optionMatch(azArg[1], "indent") ){
26830 nArg = 1;
26832 if( nArg!=1 ){
26834 rc = 1;
26852 -1, &pStmt, 0);
26873 p->showHeader = booleanValue(azArg[1]);
26877 rc = 1;
26883 n = showHelp(p->out, azArg[1]);
26885 oputf("Nothing matches '%s'\n", azArg[1]);
26908 int useOutputMode = 1; /* Use output mode to determine separators */
26918 rc = 1;
26919 for(i=1; i<nArg; i++){
26921 if( z[0]=='-' && z[1]=='-' ) z++;
26934 }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
26936 }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
26970 if( nSep>1 ){
26990 if( nSep>1 ){
26999 sCtx.nLine = 1;
27005 sCtx.in = popen(sCtx.zFile+1, "r");
27017 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
27019 zSep[1] = 0;
27060 rc = 1;
27068 if( eVerbose>=1 ){
27077 rc = 1;
27087 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27094 rc = 1;
27122 for(i=1; i<nCol; i++){
27132 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27139 rc = 1;
27164 if( z==0 && (xRead==csv_read_one_field) && i==nCol-1 && i>0 ){
27167 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
27168 if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
27171 sCtx.zFile, startLine, nCol, i+1);
27202 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
27219 rc = 1;
27222 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
27232 rc = 1;
27237 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
27244 "SELECT rootpage, 1 FROM sqlite_schema"
27247 azArg[1], azArg[1]
27249 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27253 isWO = sqlite3_column_int(pStmt, 1);
27256 zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
27257 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27265 if( sqlite3_column_int(pStmt,1)==-1 ){
27283 eputf("no such index: \"%s\"\n", azArg[1]);
27284 rc = 1;
27293 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
27302 " the \"%s\" %s!\n", azArg[1], isWO ? "table" : "index");
27306 rc = 1;
27315 iArg = integerValue(azArg[1]);
27316 if( iArg==0 ) iArg = -1;
27318 if( (nArg!=1 && nArg!=2) || iArg<0 ){
27320 rc = 1;
27334 }else if( cli_strcmp(azArg[1], "-")==0 ){
27338 iotrace = fopen(azArg[1], "w");
27340 eputf("Error: cannot open \"%s\"\n", azArg[1]);
27342 rc = 1;
27370 if( nArg==1 ){
27373 sqlite3_limit(p->db, aLimit[i].limitCode, -1));
27377 rc = 1;
27380 int iLimit = -1;
27381 n2 = strlen30(azArg[1]);
27383 if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){
27387 eputf("ambiguous limit: \"%s\"\n", azArg[1]);
27388 rc = 1;
27396 azArg[1]);
27397 rc = 1;
27405 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
27419 if( nArg<2 || azArg[1][0]==0 ){
27422 rc = 1;
27425 zFile = azArg[1];
27432 rc = 1;
27440 rc = 1;
27442 const char *zFile = azArg[1];
27462 for(i=1; i<nArg; i++){
27464 if( optionMatch(z,"wrap") && i+1<nArg ){
27467 cmOpts.bWordWrap = 1;
27468 }else if( optionMatch(z,"wordwrap") && i+1<nArg ){
27471 cmOpts.bQuote = 1;
27494 rc = 1;
27498 rc = 1;
27522 p->showHeader = 1;
27573 rc = 1;
27582 rc = 1;
27583 }else if( p->zNonce==0 || cli_strcmp(azArg[1],p->zNonce)!=0 ){
27585 p->lineno, azArg[1]);
27586 exit(1);
27598 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
27601 rc = 1;
27608 int iName = 1; /* Index in azArg[] of the filename */
27613 for(iName=1; iName<nArg; iName++){
27617 newFlag = 1;
27633 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
27640 rc = 1;
27644 rc = 1;
27652 session_close_all(p, -1);
27708 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel */
27717 bOnce = 1;
27719 for(i=1; i<nArg; i++){
27722 if( z[1]=='-' ) z++;
27732 rc = 1;
27738 while( i+1<nArg ) zFile = sqlite3_mprintf("%z %s", zFile, azArg[++i]);
27744 rc = 1;
27760 p->doXdgOpen = 1;
27772 bTxtMode = 1;
27782 rc = 1;
27785 FILE *pfPipe = popen(zFile + 1, "w");
27787 eputf("Error: cannot open pipe \"%s\"\n", zFile + 1);
27788 rc = 1;
27801 rc = 1;
27814 if( nArg<=1 ) goto parameter_syntax_error;
27819 if( nArg==2 && cli_strcmp(azArg[1],"clear")==0 ){
27827 if( nArg==2 && cli_strcmp(azArg[1],"list")==0 ){
27833 "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
27843 "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
27846 sqlite3_column_text(pStmt,1));
27856 if( nArg==2 && cli_strcmp(azArg[1],"init")==0 ){
27866 if( nArg==4 && cli_strcmp(azArg[1],"set")==0 ){
27878 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27887 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
27893 rc = 1;
27904 if( nArg==3 && cli_strcmp(azArg[1],"unset")==0 ){
27918 for(i=1; i<nArg; i++){
27919 if( i>1 ) oputz(" ");
27932 for(i=1; i<nArg; i++){
27950 if( i+1>=nArg ){
27952 rc = 1;
27960 rc = 1;
27973 shell_strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
27976 shell_strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
27993 rc = 1;
27996 if( azArg[1][0]=='|' ){
27999 rc = 1;
28002 p->in = popen(azArg[1]+1, "r");
28004 eputf("Error: cannot open \"%s\"\n", azArg[1]);
28005 rc = 1;
28011 }else if( (p->in = openChrSource(azArg[1]))==0 ){
28012 eputf("Error: cannot open \"%s\"\n", azArg[1]);
28013 rc = 1;
28033 zSrcFile = azArg[1];
28037 zDb = azArg[1];
28040 rc = 1;
28047 return 1;
28054 return 1;
28068 rc = 1;
28071 rc = 1;
28079 if( cli_strcmp(azArg[1], "vm")==0 ){
28082 if( cli_strcmp(azArg[1], "est")==0 ){
28085 p->scanstatsOn = (u8)booleanValue(azArg[1]);
28100 rc = 1;
28120 for(ii=1; ii<nArg; ii++){
28124 bDebug = 1;
28126 bNoSystemTabs = 1;
28129 rc = 1;
28135 rc = 1;
28155 new_argv[1] = 0;
28157 new_colv[1] = 0;
28158 callback(&data, 1, new_argv, new_colv);
28165 -1, &pStmt, 0);
28169 rc = 1;
28238 rc = 1;
28241 rc = 1;
28250 unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
28251 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 1, &x);
28258 char **azCmd = &azArg[1];
28260 int nCmd = nArg - 1;
28262 if( nArg<=1 ) goto session_syntax_error;
28266 if( cli_strcmp(pAuxDb->aSession[iSes].zName, azArg[1])==0 ) break;
28288 rc = sqlite3session_attach(pSession->p, azCmd[1]);
28307 out = fopen(azCmd[1], "wb");
28310 azCmd[1]);
28324 && fwrite(pChng, szChng, 1, out)!=1 ){
28336 if( nCmd!=1 ) goto session_syntax_error;
28349 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
28367 nByte = sizeof(pSession->azFilter[0])*(nCmd-1);
28370 for(ii=1; ii<nCmd; ii++){
28371 char *x = pSession->azFilter[ii-1] = sqlite3_mprintf("%s", azCmd[ii]);
28374 pSession->nFilter = ii-1;
28384 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
28396 if( nCmd!=1 ) goto session_syntax_error;
28432 rc = sqlite3session_create(p->db, azCmd[1], &pSession->p);
28456 for(i=1; i<nArg; i++){
28463 for(i=1; i<nArg; i++){
28484 for(i=1; i<nArg; i++){
28486 if( z[0]=='-' && z[1]=='-' ) z++;
28488 bIsInit = 1;
28496 rc = 1;
28504 bSelftestExists = 1;
28508 bSelftestExists = 1;
28513 if( k==1 ){
28516 -1, &pStmt, 0);
28520 " (1,'run','PRAGMA integrity_check','ok')",
28521 -1, &pStmt, 0);
28525 rc = 1;
28529 for(i=1; sqlite3_step(pStmt)==SQLITE_ROW; i++){
28531 const char *zOp = (const char*)sqlite3_column_text(pStmt, 1);
28556 rc = 1;
28561 rc = 1;
28568 rc = 1;
28581 rc = 1;
28585 "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]);
28589 "%.*s", (int)ArraySize(p->rowSeparator)-1, azArg[2]);
28606 for(i=1; i<nArg; i++){
28612 bSchema = 1;
28620 bDebug = 1;
28625 rc = 1;
28630 rc = 1;
28634 bSeparate = 1;
28635 if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1;
28640 " WHERE type='table' AND coalesce(rootpage,0)>1"
28642 " ORDER BY 1 collate nocase";
28645 " WHERE type='table' AND coalesce(rootpage,0)>1"
28647 " ORDER BY 1 collate nocase";
28649 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
28710 "WHERE type='table' AND coalesce(rootpage,0)>1\n"
28712 "ORDER BY 1 collate nocase";
28732 lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
28736 rc = 1;
28738 if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
28743 lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
28746 rc = 1;
28753 sz, (sz>1)? "s": "");
28778 rc = 1;
28781 zCmd = sqlite3_mprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]);
28787 x = zCmd!=0 ? system(zCmd) : 1;
28798 if( nArg!=1 ){
28800 rc = 1;
28848 if( cli_strcmp(azArg[1],"stmt")==0 ){
28850 }else if( cli_strcmp(azArg[1],"vmstep")==0 ){
28853 p->statsOn = (u8)booleanValue(azArg[1]);
28855 }else if( nArg==1 ){
28859 rc = 1;
28863 if( (c=='t' && n>1 && cli_strncmp(azArg[0], "tables", n)==0)
28874 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
28885 rc = 1;
28890 const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
28905 " AND name LIKE ?1", 0);
28908 " AND tbl_name LIKE ?1", 0);
28913 appendText(&s, " ORDER BY 1", 0);
28914 rc = sqlite3_prepare_v2(p->db, s.z, -1, &pStmt, 0);
28923 if( nArg>1 ){
28924 sqlite3_bind_text(pStmt, 1, azArg[1], -1, SQLITE_TRANSIENT);
28926 sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC);
28955 if( nPrintCol<1 ) nPrintCol = 1;
28956 nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
28979 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
28994 {"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
28995 {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
28996 /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
28997 /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
29000 {"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
29002 {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
29006 {"never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT,1, "BOOLEAN" },
29017 {"tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" },
29020 int testctrl = -1;
29021 int iCtrl = -1;
29022 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
29028 zCmd = nArg>=2 ? azArg[1] : "help";
29031 if( zCmd[0]=='-' && zCmd[1] ){
29033 if( zCmd[0]=='-' && zCmd[1] ) zCmd++;
29044 rc = 1;
29060 rc = 1;
29087 isOk = testctrl==SQLITE_TESTCTRL_BYTEORDER ? 1 : 3;
29127 isOk = 1;
29143 int opt = -1;
29152 isOk = 1;
29199 isOk = 1;
29201 int id = 1;
29202 while(1){
29206 if( id>1 ) oputz(" ");
29210 if( id>1 ) oputz("\n");
29225 rc2 = -1;
29226 isOk = 1;
29239 if( z[0]=='-' && z[1]=='-' ) z++;
29244 if( faultsim_state.iErr==0 ) faultsim_state.iErr = 1;
29264 }else if( cli_strcmp(z,"-id")==0 && kk+1<nArg ){
29266 }else if( cli_strcmp(z,"-errcode")==0 && kk+1<nArg ){
29268 }else if( cli_strcmp(z,"-interval")==0 && kk+1<nArg ){
29270 }else if( cli_strcmp(z,"-repeat")==0 && kk+1<nArg ){
29272 }else if( cli_strcmp(z,"-skip")==0 && kk+1<nArg ){
29275 bShowHelp = 1;
29279 rc = 1;
29280 bShowHelp = 1;
29307 rc = 1;
29308 }else if( isOk==1 ){
29318 sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0);
29323 enableTimer = booleanValue(azArg[1]);
29330 rc = 1;
29339 for(jj=1; jj<nArg; jj++){
29367 rc = 1;
29391 rc = 1;
29395 zOpt = azArg[1];
29396 if( zOpt[0]=='-' && zOpt[1]=='-' && zOpt[2]!=0 ) zOpt++;
29402 for(ii=1; ii<nArg; ii++){
29413 rc = 1;
29417 if( cli_strcmp(azArg[1],"login")==0 ){
29420 rc = 1;
29427 rc = 1;
29429 }else if( cli_strcmp(azArg[1],"add")==0 ){
29432 rc = 1;
29439 rc = 1;
29441 }else if( cli_strcmp(azArg[1],"edit")==0 ){
29444 rc = 1;
29451 rc = 1;
29453 }else if( cli_strcmp(azArg[1],"delete")==0 ){
29456 rc = 1;
29462 rc = 1;
29466 rc = 1;
29493 const char *zDbName = nArg==2 ? azArg[1] : "main";
29525 const char *zDbName = nArg==2 ? azArg[1] : "main";
29537 unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
29544 p->nWidth = nArg-1;
29545 p->colWidth = realloc(p->colWidth, (p->nWidth+1)*sizeof(int)*2);
29548 for(j=1; j<nArg; j++){
29549 p->colWidth[j-1] = (int)integerValue(azArg[j]);
29556 rc = 1;
29574 QSS_HasDark = 1<<CHAR_BIT, QSS_EndingSemi = 2<<CHAR_BIT,
29575 QSS_CharMask = (1<<CHAR_BIT)-1, QSS_ScanMask = 3<<CHAR_BIT,
29628 CONTINUE_PAREN_INCR(pst, 1);
29631 CONTINUE_PAREN_INCR(pst, -1);
29679 zLine += 1; /* Oracle */
29680 else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
29701 if( zSql==0 ) return 1;
29703 zSql[nSql+1] = 0;
29714 ** 1. The first line of input is "PRAGMA foreign_keys=OFF;",
29722 ** 1: Have seen "PRAGMA foreign_keys=OFF;".
29736 p->eRestoreState = 1;
29743 case 1: {
29749 const char *zQuery = "SELECT 1 FROM sqlite_schema LIMIT 1";
29752 bIsDump = 1;
29762 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &bDefense);
29763 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, -1, &bDqsDdl);
29765 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, 1, 0);
29776 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 1, 0);
29830 return 1;
29839 if( doAutoDetectRestore(p, zSql) ) return 1;
29868 if(nZ>0 && '\r'==zBegin[nZ-1]){
29872 zLine = realloc(zPrior, nZ+1);
29904 return 1;
29952 nAlloc = nSql+(nSql>>1)+nLine+100;
29960 memcpy(zSql, zLine+i, nLine+1-i);
29965 memcpy(zSql+nSql, zLine, nLine+1);
30046 n = strlen30(zDrive) + strlen30(zPath) + 1;
30059 i64 n = strlen(home_dir) + 1;
30086 alreadyTried = 1;
30137 if( process_input(p) && bail_on_error ) exit(1);
30141 if( bail_on_error ) exit(1);
30233 if( sqlite3_config(-1)==SQLITE_MISUSE ){
30245 data->autoExplain = 1;
30255 sqlite3_config(SQLITE_CONFIG_URI, 1);
30281 sputf(stdout, "\033[1m%s\033[0m", zText);
30291 eputf("%s: Error: missing argument to %s\n", argv[0], argv[argc-1]);
30292 exit(1);
30306 # define SQLITE_SHELL_IS_UTF8 (1)
30334 int readStdin = 1;
30347 stdout_is_console = 1;
30387 #if USE_SYSTEM_SQLITE+0!=1
30391 exit(1);
30413 argv[i] = malloc( n+1 );
30415 memcpy(argv[i], z, n+1);
30422 assert( argc>=1 && argv && argv[0] );
30445 for(i=1; i<argc; i++){
30458 azCmd[nCmd-1] = z;
30462 if( z[1]=='-' ) z++;
30540 vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1);
30545 sqlite3_multiplex_initialize(0, 1);
30568 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
30586 bail_on_error = 1;
30619 sqlite3_vfs_register(pVfs, 1);
30622 exit(1);
30629 warnInmemoryDb = argc==1;
30632 return 1;
30660 for(i=1; i<argc; i++){
30663 if( z[1]=='-' ){ z++; }
30698 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
30723 data.showHeader = 1;
30735 data.statsOn = 1;
30737 data.scanstatsOn = 1;
30755 stdin_is_interactive = 1;
30795 usage(1);
30801 if( i==argc-1 ) break;
30811 if( bail_on_error ) return rc!=0 ? rc : 1;
30822 return 1;
30827 arDotCommand(&data, 1, argv+(i-1), argc-(i-1));
30829 arDotCommand(&data, 1, argv+i, argc-i);
30835 data.bSafeMode = data.bSafeModePersist = 1;
30841 return 1;
30870 return rc!=0 ? rc : 1;
30927 expertFinish(&data, 1, 0);
30933 session_close_all(&data, -1);
30943 find_home_dir(1);
31036 rc = sqlite3_db_config(globalDb, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);