Lines Matching +defs:a +defs:code

4 ** code from various constituent source files of SQLite into this single
7 ** Most of the code found below comes from the "src/shell.c.in" file in
12 ** The code from multiple files is combined into this single "shell.c"
15 ** To modify this program, get a copy of the canonical SQLite source tree,
22 ** The author disclaims copyright to this source code. In place of
23 ** a legal notice, here is a blessing:
30 ** This file contains code to implement the "sqlite" command line
41 ** Optionally #include a user-defined header, whereby compilation options
44 ** file. Note that this macro has a like effect on sqlite3.c compilation.
53 ** Determine if we are dealing with WinRT, which provides only a subset of
62 ** somewhat for use as a WASM module in a web browser. This flag
189 /* Quiet some compilers about some of our intentional code. */
219 /* Make sure isatty() has a prototype. */
234 * thus we always assume that we have a console. That can be
258 /* Use console I/O package as a direct INCLUDE. */
272 ** The author disclaims copyright to this source code. In place of
273 ** a legal notice, here is a blessing:
288 ** source or object code compiled from it need no explicit conditional
291 ** The symbols and functionality exposed here are not a public API.
292 ** This code may change in tandem with other project code as needed.
295 ** a source conglomeration (such as shell.c), the preprocessor symbol
322 ** they are connected to a console attached to the process.
325 ** or SAC_NoConsole if none of the streams reaches a console.
328 ** the given streams. As a side-effect, the given inputs are
349 ** such a process exits to guard against console mode changes.
364 ** before so that said process will have a console setup
388 ** It is error to close a stream so designated, then, without
451 ** translation may be done as set by set{Binary,Text}Mode(). As a
472 ** a new line and CR,LF chars from the console become a newline.
485 ** Macros for use of a line editor.
487 ** The following macros define operations involving use of a
489 ** A "T" argument is a text (char *) buffer or filename.
506 ** Retrieve a single line of input text from an input stream.
509 ** and azPrompt is not NULL, then a prompt is issued before the
513 ** If zBufPrior is not NULL then it is a buffer from a prior
520 ** This function may call upon services of a line-editing
533 ** console I/O is desirable because a line-editing library
535 ** in a way that interferes with the above functionality.
555 ** The author disclaims copyright to this source code. In place of
556 ** a legal notice, here is a blessing:
642 /* Quickly say whether a known output is going to the console. */
659 /* Say whether FILE* appears to be a console, collect associated info. */
807 /* Setting a possibly new output stream. */
899 ** In either case, ppst references a caller-owned PerStreamTags
901 ** streams is being held by consoleInfo. The ppf parameter is a
902 ** byref output when chix!=0 and a byref input when chix==0.
1086 }else if( (c & 0xC0) != 0xC0 ) return z; /* not a lead byte */
1173 # define SHELL_GULP 150 /* Count of WCHARS to be gulped at a time */
1178 /* There is room for at least 2 more characters and a 0-terminator. */
1184 /* Last WHAR read is first of a UTF-16 surrogate pair. Grab its mate. */
1274 * from the WASM build are issued for non-formatted output, (when a mere
1292 static int cli_strcmp(const char *a, const char *b){
1293 if( a==0 ) a = "";
1295 return strcmp(a,b);
1297 static int cli_strncmp(const char *a, const char *b, size_t n){
1298 if( a==0 ) a = "";
1300 return strncmp(a,b,n);
1393 ** does, save off a pointer to it and the current process handle.
1474 ** is true. Otherwise, assume stdin is connected to a file or pipe.
1479 ** On Windows systems we need to know if standard output is a console
1486 ** The following is the open SQLite database. We make a pointer
1487 ** to this database a static variable so that it can be accessed
1499 ** in a number of other places, mostly for error messages.
1569 /* Record that a lexeme is opened, or closed with args==0. */
1617 /* Check a pointer to see if it is NULL. If it is NULL, exit with an
1632 ** This routine works like printf in that its first argument is a
1681 ** Determines if a string is a number of not.
1708 ** Compute a string length that is limited to what can be stored in
1709 ** lower 30 bits of a 32-bit signed integer.
1718 ** Return the length of a string in characters. Multibyte UTF8 characters
1719 ** count as a single character.
1731 ** and is an ordinary file or a character stream source.
1739 ** is necessary because _stat() and sibs, when checking a named pipe,
1764 ** This routine reads a line of text from FILE in, stores
1765 ** the text in memory obtained from malloc() and returns a pointer
1769 ** If zLine is not NULL then it is a malloced buffer returned from
1770 ** a previous call to this routine that may be reused.
1802 ** Retrieve a single line of input text.
1805 ** If isContinuation is true, then a continuation prompt is appropriate.
1808 ** If zPrior is not NULL then it is a buffer from a prior call to this
1829 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
1836 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
1849 ** Return the value of a hexadecimal digit. Return -1 if the input
1850 ** is not a hex digit.
1854 if( c>='a' && c<='f' ) return c - 'a' + 10;
1916 ** Initialize and destroy a ShellText object
1926 /* zIn is either a pointer to a NULL-terminated string in memory obtained
1927 ** from malloc(), or a NULL pointer. The string pointed to by zAppend is
1931 ** If the third argument, quote, is not '\0', then it is used as a
1989 ** Construct a fake object name and column list to describe the structure
2039 ** Use the C-library strtod() function to convert string X into a double.
2057 ** Use the C-library printf() function to convert real value X into a string.
2079 ** Return a fake schema for the table-valued function or eponymous virtual
2173 ** The source code for several run-time loadable extensions is inserted
2175 ** code, we need to override some macros to make the included program code
2186 ** The author disclaims copyright to this source code. In place of
2187 ** a legal notice, here is a blessing:
2314 ** Provide a macro, for use by the implementation, to determine if a
2321 # define is_filtered(a) ((((a).attrib)&_A_HIDDEN) || (((a).attrib)&_A_SYSTEM))
2348 ** The author disclaims copyright to this source code. In place of
2349 ** a legal notice, here is a blessing:
2356 ** This file contains code to implement most of the opendir() family of
2544 ** The author disclaims copyright to this source code. In place of
2545 ** a legal notice, here is a blessing:
2554 ** mechanism to add a tracing layer on top of SQLite. If this extension
2655 ** The author disclaims copyright to this source code. In place of
2656 ** a legal notice, here is a blessing:
2665 ** mechanism to add a tracing layer on top of pluggable page cache of
2837 ** The author disclaims copyright to this source code. In place of
2838 ** a legal notice, here is a blessing:
2857 ** and returns a hash of their results.
2900 ** State structure for a SHA3 hash in progress
2914 ** A single step of the Keccak mixing function for a 1600-bit state
2960 # define ROL64(a,x) ((a<<x)|(a>>(64-x)))
3234 ** Initialize a new hash. iSize determines the size of the hash
3304 ** the final hash. The function returns a pointer to the binary
3330 ** Return a BLOB which is the SIZE-bit SHA3 hash of X. The default
3331 ** size is 256. If X is a BLOB, it is hashed as is.
3332 ** For all other non-NULL types of input, X is converted into a UTF-8 string
3334 ** of a NULL value is NULL.
3365 /* Compute a string using sqlite3_vsnprintf() with a maximum length
3387 ** argument. The results are hashed using a SIZE-bit SHA3. The default
3402 ** occurs before the start of each row. N means a NULL value.
3403 ** I mean an 8-byte little-endian integer <int>. F is a floating point
3468 /* Compute a hash over the result of the query */
3565 ** The author disclaims copyright to this source code. In place of
3566 ** a legal notice, here is a blessing:
3588 ** is *not* limited integers that can be expressed as a
3660 ** The author disclaims copyright to this source code. In place of
3661 ** a legal notice, here is a blessing:
3680 /* Mark a function parameter as unused, to suppress nuisance compiler
3692 char isNull; /* True if holds a NULL rather than a number */
3696 signed char *a; /* Array of digits. Most significant first. */
3700 ** Release memory held by a Decimal, but do not free the object itself.
3703 sqlite3_free(p->a);
3707 ** Destroy a Decimal object
3717 ** Allocate a new Decimal object initialized to the text in zIn[].
3733 p->a = sqlite3_malloc64( n+1 );
3734 if( p->a==0 ) goto new_from_text_failed;
3746 p->a[p->nDigit++] = c - '0';
3784 p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
3785 if( p->a==0 ) goto new_from_text_failed;
3786 memset(p->a+p->nDigit, 0, iExp);
3803 p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
3804 if( p->a==0 ) goto new_from_text_failed;
3805 memmove(p->a+iExp, p->a, p->nDigit);
3806 memset(p->a, 0, iExp);
3815 if( p->a ) sqlite3_free(p->a);
3825 ** Allocate a new Decimal object from an sqlite3_value. Return a pointer
3830 ** directly into a Decimal. For SQLITE_FLOAT or for SQLITE_BLOB of length
3832 ** If pIn is NULL or if it is a BLOB that is not exactly 8 bytes in length,
3909 if( p->nDigit==0 || (p->nDigit==1 && p->a[0]==0) ){
3921 while( n>1 && p->a[j]==0 ){
3926 z[i++] = p->a[j] + '0';
3933 z[i++] = p->a[j] + '0';
3954 signed char *a; /* Array of digits */
3964 for(nDigit=p->nDigit; nDigit>0 && p->a[nDigit-1]==0; nDigit--){}
3965 for(nZero=0; nZero<nDigit && p->a[nZero]==0; nZero++){}
3975 a = &zero;
3979 a = &p->a[nZero];
3986 z[1] = a[0]+'0';
3993 z[2+i] = a[i]+'0';
4030 rc = memcmp(pA->a, pB->a, n);
4066 ** Expand the Decimal so that it has a least nDigit digits and nFrac
4076 p->a = sqlite3_realloc64(p->a, nDigit+1);
4077 if( p->a==0 ){
4082 memmove(p->a+nAddSig, p->a, p->nDigit);
4083 memset(p->a, 0, nAddSig);
4087 memset(p->a+p->nDigit, 0, nAddFrac);
4113 if( nSig && pA->a[0]==0 ) nSig--;
4128 int x = pA->a[i] + pB->a[i] + carry;
4131 pA->a[i] = x - 10;
4134 pA->a[i] = x;
4140 rc = memcmp(pA->a, pB->a, nDigit);
4142 aA = pB->a;
4143 aB = pA->a;
4146 aA = pA->a;
4147 aB = pB->a;
4152 pA->a[i] = x+10;
4155 pA->a[i] = x;
4190 signed char f = pA->a[i];
4193 x = acc[k] + f*pB->a[j] + carry;
4201 sqlite3_free(pA->a);
4202 pA->a = acc;
4207 while( pA->nFrac>minFrac && pA->a[pA->nDigit-1]==0 ){
4217 ** Create a new Decimal object that contains an integer power of 2.
4252 ** Use an IEEE754 binary64 ("double") to generate a new Decimal object.
4255 sqlite3_int64 m, a;
4267 memcpy(&a,&r,sizeof(a));
4268 if( a==0 ){
4272 e = a>>52;
4273 m = a & ((((sqlite3_int64)1)<<52)-1);
4305 ** If X is originally a float, then a full decimal expansion of that floating
4307 ** as a float and similarly expanded.
4310 ** decimal(X) returns a complete decimal, without the e+NNN at the end.
4407 p->a = sqlite3_malloc(2);
4408 if( p->a==0 ){
4411 p->a[0] = 0;
4549 ** The author disclaims copyright to this source code. In place of
4550 ** a legal notice, here is a blessing:
4558 ** This is a SQLite extension for converting in either direction
4559 ** between a (binary) blob and base64 text. Base64 can transit a
4580 ** This SQLite3 extension creates a function, base64(x), which
4581 ** either: converts text x containing base64 to a returned blob;
4582 ** or converts a blob x to returned text containing base64. An
4585 ** This code relies on UTF-8 encoding only with respect to the
4604 /* Quiet some compilers about some of our intentional code. */
4638 /* a o */
4656 /* Encode a byte buffer into base64 text with linefeeds appended to limit
4702 /* Decode base64 text into a byte buffer. */
4762 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
4847 ** The author disclaims copyright to this source code. In place of
4848 ** a legal notice, here is a blessing:
4856 ** This is a utility for converting binary to base85 or vice-versa.
4857 ** It can be built as a standalone program or an SQLite3 extension.
4859 ** Much like base64 representations, base85 can be sent through a
4866 ** variant sources existed, in the 1984 timeframe on a VAX mainframe.
4867 ** Further, this is an independent implementation of a base85 system.
4872 ** in code order representing digit values 0 to 84 (base 10.)
4893 ** a non-base85 character; the conversion to binary will then
4897 ** a binary file or converts a binary file to base85 on stdout.
4900 ** The SQLite3 extension creates a function, base85(x), which will
4901 ** either convert text base85 to a blob or a blob to text base85
4903 ** Unless built with OMIT_BASE85_CHECKER defined, it also creates a
4948 " <binFile> names a binary file to be rendered or created.\n"
4967 /* Provide digitValue to b85Numeral offset as a function of above class. */
4971 /* Say whether c is a base85 numeral. */
4993 * Do not use the macro form with argument expression having a side-effect.*/
5009 /* Encode a byte buffer into base85 text. If pSep!=0, it's a C string
5053 /* Decode base85 text into a byte buffer. */
5300 ** The author disclaims copyright to this source code. In place of
5301 ** a legal notice, here is a blessing:
5315 ** In the first form, the value X should be a floating-point number.
5316 ** The function will return a string of the form 'ieee754(Y,Z)' where
5320 ** base-2 exponent of a new floating point number. The function returns
5321 ** a floating-point value equal to Y*pow(2,Z).
5342 ** then that blob is interpreted as a big-endian binary64 value.
5350 ** values. To begin, first compute a table of exponent values:
5364 ** Then, to compute the exact decimal representation of a floating
5372 ** Here is a query to show various boundry values for the binary64
5389 /* Mark a function parameter as unused, to suppress nuisance compiler
5404 sqlite3_int64 m, a;
5429 memcpy(&a,&r,sizeof(a));
5430 if( a==0 ){
5434 e = a>>52;
5435 m = a & ((((sqlite3_int64)1)<<52)-1);
5461 sqlite3_int64 m, e, a;
5502 a = m & ((((sqlite3_int64)1)<<52)-1);
5503 a |= e<<52;
5504 if( isNeg ) a |= ((sqlite3_uint64)1)<<63;
5505 memcpy(&r, &a, sizeof(r));
5544 unsigned char a[sizeof(r)];
5548 a[sizeof(r)-i] = v&0xff;
5551 sqlite3_result_blob(context, a, sizeof(r), SQLITE_TRANSIENT);
5561 ** Behind the scenes: this routine merely casts r into a 64-bit unsigned
5627 ** The author disclaims copyright to this source code. In place of
5628 ** a legal notice, here is a blessing:
5636 ** This file demonstrates how to create a table-valued-function using
5637 ** a virtual table. This demo implements the generate_series() function
5660 ** Integers from 0 through 100 with a step size of 1.
5676 ** The generate_series "function" is really a virtual table with the
5686 ** The virtual table also has a rowid, logically equivalent to n+1 where
5703 ** set to NULL. This means that it is not possible to do a CREATE VIRTUAL
5705 ** is a single generate_series virtual table that is always available without
5712 ** xBestIndex returns a small cost when both start and stop are available,
5713 ** and a very large cost if either start or stop are unavailable. This
5725 ** Return that member of a generate_series(...) sequence whose 0-based
5768 ** Prepare a SequenceSpec for use in generating an integer series
5824 ** Return whether there is a next value, or 0 at EOF.
5846 /* series_cursor is a subclass of sqlite3_vtab_cursor which will
5847 ** serve as the underlying representation of a cursor that scans
5857 ** The seriesConnect() method is invoked to create a new
5909 ** Constructor for a new series_cursor object.
5922 ** Destructor for a series_cursor.
5931 ** Advance a series_cursor to its next row of output.
6000 ** is a bitmask showing which constraints are available:
6062 /* If any of the constraints have a NULL value, then return no rows.
6080 ** SQLite will invoke this method one or more times while planning a query
6082 ** a query plan for each invocation and compute an estimated cost for that
6202 /* If either boundary is missing, we have to generate a huge span
6222 seriesOpen, /* xOpen - open a cursor */
6223 seriesClose, /* xClose - close a cursor */
6225 seriesNext, /* xNext - advance a cursor */
6271 ** The author disclaims copyright to this source code. In place of
6272 ** a legal notice, here is a blessing:
6280 ** The code in this file implements a compact but reasonably
6284 ** This file is an SQLite extension. It registers a single function
6308 ** [a-z] Any single character in the range a-z
6309 ** [^a-z] Any single character not in the range a-z
6345 ** set. Each opcode has a single integer argument.
6352 #define RE_OP_ACCEPT 6 /* Halt and indicate a successful match */
6353 #define RE_OP_CC_INC 7 /* Beginning of a [...] character class */
6354 #define RE_OP_CC_EXC 8 /* Beginning of a [^...] character class */
6355 #define RE_OP_CC_VALUE 9 /* Single value in a character class */
6356 #define RE_OP_CC_RANGE 10 /* Range of values in a character class */
6358 #define RE_OP_NOTWORD 12 /* Not a perl word character */
6360 #define RE_OP_NOTDIGIT 14 /* Not a digit */
6362 #define RE_OP_NOTSPACE 16 /* Not a digit */
6392 /* Each opcode is a "state" in the NFA */
6395 /* Because this is an NFA and not a DFA, multiple states can be active at
6405 /* An input string read one character at a time.
6430 /* Add a state to the given state set if it is not already there */
6440 ** optimized for the common case where the next character is a single byte.
6469 if( c>='A' && c<='Z' ) c += 'a' - 'A';
6473 /* Return true if c is a perl "word" character: [A-Za-z0-9_] */
6475 return (c>='0' && c<='9') || (c>='a' && c<='z')
6479 /* Return true if c is a "digit" character: [0-9] */
6484 /* Return true if c is a perl "space" character: [ \t\r\n\v\f] */
6489 /* Run a compiled regular expression on the zero-terminated input
6490 ** string zIn[]. Return true on a match and false if there is no match.
6655 /* Insert a new opcode and argument into an RE under construction. The
6671 /* Append a new opcode and argument to the end of the RE under construction.
6677 /* Make a copy of N opcodes starting at iStart onto the end of the RE
6687 /* Return true if c is a hexadecimal digit character: [0-9a-fA-F]
6688 ** If c is a hex digit, also set *pV = (*pV)*16 + valueof(c). If
6689 ** c is not a hex digit *pV is unchanged.
6694 }else if( c>='a' && c<='f' ){
6695 c -= 'a' - 10;
6710 static const char zTrans[] = "\a\f\n\r\t\v";
6753 /* Compile RE text into a sequence of opcodes. Continue up to the
6755 ** return a pointer to the error message string.
6776 ** an operand to the "|" operator). Return NULL on success or a pointer
6777 ** to the error message if there is a problem.
6922 /* Free and reclaim all the memory used by a previously compiled
6935 ** Compile a textual regular expression in zIn[] into a compiled regular
6936 ** expression suitable for us by re_match() and return a pointer to the
6977 /* The following is a performance optimization. If the regex begins with
7058 ** Compile a regular expression and then convert the compiled expression into
7134 /* The regexpi(PATTERN,STRING) function is a case-insensitive version
7156 ** The author disclaims copyright to this source code. In place of
7157 ** a legal notice, here is a blessing:
7175 ** be passed an integer value that corresponds to a POSIX mode
7184 ** For a directory, the DATA is ignored. For a symbolic link, it is
7185 ** interpreted as text and used as the target of the link. For a
7186 ** regular file, it is interpreted as a blob and written into the
7209 ** refers to does not exist, it is an error. If the path refers to a regular
7210 ** file or symbolic link, it returns a single row. Or, if the path refers
7211 ** to a directory, it returns one row for the directory, and one row for each
7219 ** data: For a regular file, a blob containing the file data. For a
7220 ** symlink, a text value containing the text of the link. For a
7223 ** If a non-NULL value is specified for the optional $dir parameter and
7224 ** $path is a relative path, then $path is interpreted relative to $dir.
7229 ** Unless linked statically with the SQLite library, a preprocessor
7230 ** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
7280 ** Set the result stored by context ctx to a blob containing the
7329 ** of the file named X is read and returned as a BLOB. NULL is returned
7360 ** This function is designed to convert a Win32 FILETIME structure into the
7387 # /* To allow a standalone DLL, use this next replacement function: */
7466 ** Argument zFile is the name of a file that will be created and/or written
7536 ** be an error though - if there is already a directory at the same
7617 ** Do not use utimes() on a symbolic link - it sees through the link and
7686 ** Given a numberic st_mode from stat(), convert it into a human-readable
7709 char *a = &z[1 + i*3];
7710 a[0] = (m & 0x4) ? 'r' : '-';
7711 a[1] = (m & 0x2) ? 'w' : '-';
7712 a[2] = (m & 0x1) ? 'x' : '-';
7721 ** Cursor type for recursively iterating through a directory structure.
7752 ** Construct a new fsdir virtual table object.
7787 ** Constructor for a new fsdir_cursor object.
7801 ** Reset a cursor back to the state it was in when first returned
7975 ** row a value 1 more than that of the previous.
8016 fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
8041 ** SQLite will invoke this method one or more times while planning a query
8043 ** a query plan for each invocation and compute an estimated cost for that
8097 /* The pIdxInfo->estimatedCost should have been initialized to a huge
8128 fsdirOpen, /* xOpen - open a cursor */
8129 fsdirClose, /* xClose - close a cursor */
8131 fsdirNext, /* xNext - advance a cursor */
8186 /* To allow a standalone DLL, make test_windirent.c use the same
8187 * redefined SQLite API calls as the above extension code does.
8188 * Just pull in this .c to accomplish this. As a beneficial side
8189 * effect, this extension becomes a single translation unit. */
8198 ** The author disclaims copyright to this source code. In place of
8199 ** a legal notice, here is a blessing:
8208 ** completions for a partial SQL input.
8226 ** is no attempt to make it fast. Even a slow implementation will be much
8238 /* completion_vtab is a subclass of sqlite3_vtab which will
8239 ** serve as the underlying representation of a completion virtual table
8247 /* completion_cursor is a subclass of sqlite3_vtab_cursor which will
8248 ** serve as the underlying representation of a cursor that scans
8282 ** The completionConnect() method is invoked to create a new
8342 ** Constructor for a new completion_cursor object.
8365 ** Destructor for a completion_cursor.
8374 ** Advance a completion_cursor to its next row of output.
8589 ** SQLite will invoke this method one or more times while planning a query
8591 ** a query plan for each invocation and compute an estimated cost for that
8650 completionOpen, /* xOpen - open a cursor */
8651 completionClose, /* xClose - close a cursor */
8653 completionNext, /* xNext - advance a cursor */
8703 ** The author disclaims copyright to this source code. In place of
8704 ** a legal notice, here is a blessing:
8712 ** This file implements a VFS shim that allows an SQLite database to be
8718 ** For best performance page 1 should be located at a disk page boundary,
8721 ** When opening a database using this VFS, the connection might treat
8722 ** the file as an ordinary SQLite database, or it might treat it as a
8735 ** set, then a new database is appended to the already existing file.
8742 ** might be lifted in future versions. For now, if you need a larger
8743 ** database, then keep it in a separate file.
8745 ** If the file being opened is a plain database (not an appended one), then
8746 ** this shim is a pass-through into the default underlying VFS. (rule 3)
8758 ** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
8787 /* Access to a lower-level VFS that (might) implement dynamic loading,
8822 ** of iPgOne stored as a big-ending 64-bit integer.
8956 unsigned char a[APND_MARK_SIZE];
8960 memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
8962 a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
8967 (pFile, a, APND_MARK_SIZE, iWriteEnd)) ){
9041 ** Check if another file-handle holds a RESERVED lock on an apnd-file.
9079 /* Create a shared memory file mapping */
9091 /* Perform locking on a shared-memory segment */
9103 /* Unmap a shared memory segment */
9109 /* Fetch a page of a memory-mapped file */
9124 /* Release a memory-mapped page */
9132 ** Try to read the append-mark off the end of a file. Return the
9138 ** start-of-database value must be a multiple of 512.
9144 unsigned char a[APND_MARK_SIZE];
9147 rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
9149 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
9150 iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs;
9153 iMark |= (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<msbs;
9271 ** For now, this code deletes the underlying file too.
9317 static int apndGetLastError(sqlite3_vfs *pVfs, int a, char *b){
9318 return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b);
9380 ** The author disclaims copyright to this source code. In place of
9381 ** a legal notice, here is a blessing:
9389 ** This file implements a virtual table for reading and writing ZIP archive
9434 #define MIN(a,b) ((a)<(b) ? (a) : (b))
9456 ** header files. But, the dependency is undesirable and (a) these
9505 ** First 4 bytes of a valid CDS record.
9508 ** First 4 bytes of a valid LFH record.
9511 ** First 4 bytes of a valid EOCD record.
9523 ** structures in a zip archive.
9713 ** Construct a new ZipfileTab virtual table object.
9783 ** Release resources that should be freed at the end of a write
9814 ** Constructor for a new ZipfileCsr object.
9832 ** Reset a cursor back to the state it was in when first returned
9891 ** aRead[]. Return SQLITE_OK if successful, or an SQLite error code
9935 ** Read and return a 16-bit little-endian unsigned integer from buffer aBuf.
9942 ** Read and return a 32-bit little-endian unsigned integer from buffer aBuf.
9953 ** Write a 16-bit little endiate integer into buffer aBuf.
9961 ** Write a 32-bit little endiate integer into buffer aBuf.
10088 ** fields of the CDS structure passed as the only argument to a 32-bit
10168 ** If aBlob is not NULL, then it is a pointer to a buffer (nBlob bytes in
10170 ** then pFile is a file-handle open on a zip file. In either case, this
10171 ** function creates a ZipfileEntry object based on the zip archive entry
10175 ** the new object. Otherwise, an SQLite error code is returned and the
10317 ** return value in context pCtx to the result (a blob).
10319 ** If an error occurs, an error code is left in pCtx instead.
10359 ** compresses it and sets (*ppOut) to point to a buffer containing the
10365 ** code is returned and an error message left in virtual-table handle
10473 /* Figure out if this is a directory or a zero-sized file. Consider
10474 ** it to be a directory either if the mode suggests so, or if
10508 ** If aBlob is not NULL, then it points to a buffer nBlob bytes in size
10510 ** is guaranteed to be a file-handle open on a zip file.
10514 ** returned if successful. Otherwise, an SQLite error code is returned and
10579 ** before pBefore (which is guaranteed to be a part of said list).
10740 u8 *a = aBuf;
10745 zipfileWrite32(a, ZIPFILE_SIGNATURE_LFH);
10746 zipfileWrite16(a, pCds->iVersionExtract);
10747 zipfileWrite16(a, pCds->flags);
10748 zipfileWrite16(a, pCds->iCompression);
10749 zipfileWrite16(a, pCds->mTime);
10750 zipfileWrite16(a, pCds->mDate);
10751 zipfileWrite32(a, pCds->crc32);
10752 zipfileWrite32(a, pCds->szCompressed);
10753 zipfileWrite32(a, pCds->szUncompressed);
10754 zipfileWrite16(a, (u16)pCds->nFile);
10755 zipfileWrite16(a, pCds->nExtra);
10756 assert( a==&aBuf[ZIPFILE_LFH_FIXED_SZ] );
10759 memcpy(a, pCds->zFile, (int)pCds->nFile);
10760 a += (int)pCds->nFile;
10763 zipfileWrite16(a, ZIPFILE_EXTRA_TIMESTAMP);
10764 zipfileWrite16(a, 5);
10765 *a++ = 0x01;
10766 zipfileWrite32(a, pEntry->mUnixTime);
10768 return a-aBuf;
10819 /* The "mode" attribute is a directory, but data has been specified.
10820 ** Or vice-versa - no data but "mode" is a file or symlink. */
10854 /* Open a write fd on the file. Also load the entire central directory
10878 ** Return the current time as a 32-bit timestamp in UNIX epoch format (like
10898 ** Return a 32-bit timestamp in UNIX epoch format.
10902 ** cast to a 32-bit unsigned integer.
10970 /* If this is a DELETE or UPDATE, find the archive entry to delete. */
11005 ** a regular file or a symlink. */
11046 /* For a directory, check that the last character in the path is a
11062 /* Check that we're not inserting a duplicate entry -OR- updating an
11063 ** entry with a path, thereby making it into a duplicate. */
11131 u8 *a = aBuf;
11132 zipfileWrite32(a, ZIPFILE_SIGNATURE_EOCD);
11133 zipfileWrite16(a, p->iDisk);
11134 zipfileWrite16(a, p->iFirstDisk);
11135 zipfileWrite16(a, p->nEntry);
11136 zipfileWrite16(a, p->nEntryTotal);
11137 zipfileWrite32(a, p->nSize);
11138 zipfileWrite32(a, p->iOffset);
11139 zipfileWrite16(a, 0); /* Size of trailing comment in bytes*/
11141 return a-aBuf;
11155 u8 *a = aBuf;
11162 zipfileWrite32(a, ZIPFILE_SIGNATURE_CDS);
11163 zipfileWrite16(a, pCDS->iVersionMadeBy);
11164 zipfileWrite16(a, pCDS->iVersionExtract);
11165 zipfileWrite16(a, pCDS->flags);
11166 zipfileWrite16(a, pCDS->iCompression);
11167 zipfileWrite16(a, pCDS->mTime);
11168 zipfileWrite16(a, pCDS->mDate);
11169 zipfileWrite32(a, pCDS->crc32);
11170 zipfileWrite32(a, pCDS->szCompressed);
11171 zipfileWrite32(a, pCDS->szUncompressed);
11172 assert( a==&aBuf[ZIPFILE_CDS_NFILE_OFF] );
11173 zipfileWrite16(a, pCDS->nFile);
11174 zipfileWrite16(a, pCDS->nExtra);
11175 zipfileWrite16(a, pCDS->nComment);
11176 zipfileWrite16(a, pCDS->iDiskStart);
11177 zipfileWrite16(a, pCDS->iInternalAttr);
11178 zipfileWrite32(a, pCDS->iExternalAttr);
11179 zipfileWrite32(a, pCDS->iOffset);
11181 memcpy(a, pCDS->zFile, pCDS->nFile);
11182 a += pCDS->nFile;
11186 memcpy(a, pEntry->aExtra, n);
11187 a += n;
11190 zipfileWrite16(a, ZIPFILE_EXTRA_TIMESTAMP);
11191 zipfileWrite16(a, 5);
11192 *a++ = 0x01;
11193 zipfileWrite32(a, pEntry->mUnixTime);
11196 return a-aBuf;
11310 u8 *a; /* Pointer to buffer */
11312 int nAlloc; /* Byte allocated at a[] */
11329 aNew = sqlite3_realloc64(pBuf->a, nNew);
11331 pBuf->a = aNew;
11415 /* Now inspect the data. If this is NULL, then the new entry must be a
11448 /* If this is a directory entry, ensure that there is exactly one '/'
11449 ** at the end of the path. Or, if this is not a directory and the path
11487 p->body.n += zipfileSerializeLFH(&e, &p->body.a[p->body.n]);
11492 memcpy(&p->body.a[p->body.n], aData, nData);
11499 p->cds.n += zipfileSerializeCDS(&e, &p->cds.a[p->cds.n]);
11540 memcpy(aZip, p->body.a, p->body.n);
11541 memcpy(&aZip[p->body.n], p->cds.a, p->cds.n);
11547 sqlite3_free(p->body.a);
11548 sqlite3_free(p->cds.a);
11563 zipfileOpen, /* xOpen - open a cursor */
11564 zipfileClose, /* xClose - close a cursor */
11566 zipfileNext, /* xNext - advance a cursor */
11619 ** The author disclaims copyright to this source code. In place of
11620 ** a legal notice, here is a blessing:
11641 ** zlib utility function compress() yields a smaller blob, return the
11642 ** compressed blob. Otherwise, return a copy of X.
11645 ** contains a two-byte identification header and a four-byte checksum at
11687 ** equal to zero, then this function returns a copy of X. Or, if
11688 ** SZ is equal to the size of X when interpreted as a blob, also
11689 ** return a copy of X. Otherwise, decompress blob X using zlib
11749 ** The author disclaims copyright to this source code. In place of
11750 ** a legal notice, here is a blessing:
11765 ** Create a new sqlite3expert object.
11767 ** If successful, a pointer to the new object is returned and (*pzErr) set
11784 ** be configured so that sqlite_stat1 data is instead generated based on a
11814 ** due to a error in the SQL - an SQLite error code is returned and (*pzErr)
11823 ** This function must be called before sqlite3_expert_analyze(). If a call
11829 sqlite3expert *p, /* From a successful sqlite3_expert_new() */
11842 ** an error occurs, an SQLite error code is returned and (*pzErr) set to
11843 ** point to a buffer containing an English language error message. In this
11850 ** the analysis. The sqlite3expert object must still be freed using a call
11863 ** Return a component of the report.
11866 ** results of the analysis. Each call to this function returns either a
11867 ** NULL pointer or a pointer to a buffer containing a nul-terminated string.
11872 ** information relating to a specific SQL statement. In these cases that
11883 ** Return a buffer containing the CREATE INDEX statements for all recommended
11888 ** Return a buffer containing the EXPLAIN QUERY PLAN output for SQL query
11892 ** Return a pointer to a buffer containing the CREATE INDEX statements
11920 ** The author disclaims copyright to this source code. In place of
11921 ** a legal notice, here is a blessing:
11974 ** any other type of single-ended range constraint on a column).
11991 ** A single scan of a single table.
12004 ** Information regarding a single database table. Extracted from
12021 ** seen. The objects are stored in a singly-linked list beginning at
12044 ** A hash table for storing strings. With space for a payload string
12081 int rc; /* Error code from whereinfo hook */
12180 ** If zKey/nKey is present in the hash table, return a pointer to the
12198 ** If the hash table contains an entry with a key equal to the string
12199 ** passed as the final two arguments to this function, return a pointer
12210 ** Allocate and return a new IdxConstraint object. Set the IdxConstraint.zColl
12211 ** variable to point to a copy of nul-terminated string zColl.
12255 ** Prepare an SQL statement using the results of a printf() formatting.
12475 ** Return non-zero if the cursor does not currently point to a valid
12558 expertConnect, /* xCreate - create a table */
12561 expertDisconnect, /* xDisconnect - Disconnect from a table */
12562 expertDisconnect, /* xDestroy - Drop a table */
12563 expertOpen, /* xOpen - open a cursor */
12564 expertClose, /* xClose - close a cursor */
12566 expertNext, /* xNext - advance a cursor */
12603 ** SQLite error code and set (*ppOut) to NULL. In this case *pzErrmsg may be
12698 ** This function is a no-op if *pRc is set to anything other than
12703 ** in a buffer allocated by sqlite3_malloc(). sqlite3_free() is called on
12747 && !(zId[i]>='a' && zId[i]<='z')
12761 int *pRc, /* IN/OUT: Error code */
12796 ** If an error occurs, set *pRc to an SQLite error code and return zero.
12799 int *pRc, /* OUT: Error code */
12903 /* Hash the list of columns to come up with a name for the index */
12932 /* This return means "Gave up trying to find a unique index name." */
12965 ** a constraint compatible with *p. Otherwise return false.
12996 /* If no range/ORDER BY passed by the caller, create a version of the
13743 ** Define and possibly pretend to use a useless collation sequence.
13755 /* And a callback to register above upon actual need */
13804 }else if( strcmp(type,"a")==0 ){
13825 ** Allocate a new sqlite3expert object.
13834 ** will contain a virtual table corresponding to each real table in
13835 ** the user database schema, and a copy of each view. It is used to
13987 *pzErr = sqlite3_mprintf("Cannot find a unique index name to propose.");
14027 ** Return a component of the report.
14077 ** The author disclaims copyright to this source code. In place of
14078 ** a legal notice, here is a blessing:
14091 ** This module contains code to check whether or not an SQLite database
14124 ** Usually, the sqlite3_intck object opens a read transaction within the
14127 ** called, the read transaction is ended and a new read transaction opened
14147 ** Open a new incremental integrity-check object. If successful, populate
14150 ** code (e.g. SQLITE_NOMEM).
14165 ** Close and release all resources associated with a handle opened by an
14175 ** integrity-check operation is finished, or an SQLite error code if
14180 ** Following a successful call to sqlite3_intck_step() (one that returns
14181 ** SQLITE_OK), sqlite3_intck_message() returns a non-NULL value if
14184 ** If an error occurs and a value other than SQLITE_OK or SQLITE_DONE is
14195 ** within the database, then this function returns a pointer to a buffer
14196 ** containing a nul-terminated string describing the corruption in
14206 ** open a new transaction. Return SQLITE_OK if successful, or an SQLite error
14207 ** code otherwise.
14220 ** SQLite error code. Additionally, if pzErr is not NULL, then (*pzErr)
14221 ** may be set to point to a nul-terminated string containing an English
14233 ** statement used to test object zObj, which may be a table or index.
14251 ** The author disclaims copyright to this source code. In place of
14252 ** a legal notice, here is a blessing:
14274 ** Error code returned by most recent sqlite3_intck_step() or
14299 int rc; /* Error code */
14307 ** and error code currently held by the database handle in p->rc and p->zErr.
14317 ** then this function is a no-op (returns NULL immediately). Otherwise, if an
14337 ** then this function is a no-op (returns NULL immediately). Otherwise, if an
14340 ** Otherwise, this function treats argument zFmt as a printf() style format
14384 ** code convention.
14395 ** code convention.
14415 ** required to restart the current pCheck query as a nul-terminated string
14439 /* Object is a table, not an index. This is the easy case,as there are
14440 ** no DESC columns or NULL values in a primary key. */
14515 ** set sqlite3_intck.zObj to point to a nul-terminated buffer containing
14547 /* If this is a new object, ensure the previous key value is cleared. */
14558 ** For the purposes of this call, a token is either:
14560 ** * a quoted SQL string,
14561 * * a contiguous series of ascii alphabet characters, or
14579 else if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){
14580 while( (z[iRet]>='A' && z[iRet]<='Z') || (z[iRet]>='a' && z[iRet]<='z') ){
14596 ** Argument z points to the text of a CREATE INDEX statement. This function
14606 ** clause, NULL is returned and (*pnByte) is set to 0. Otherwise, a pointer to
14635 /* Check if this is the end of the current column - either a "," or ")"
14667 ** CREATE INDEX statement. Try to find a WHERE clause to return. */
14745 ** Return a pointer to a nul-terminated buffer containing the SQL statement
14746 ** used to check database object zObj (a table or index) for corruption.
14747 ** If parameter zPrev is not NULL, then it must be a string containing the
14752 ** This function uses the sqlite3_intck error code convention.
14767 ** set to true if the table being examined is a WITHOUT ROWID table,
14781 ** idx_ispk: True if this index is the PK of a WITHOUT ROWID table.
14804 ** For a PK declared as "PRIMARY KEY(a, b) ... WITHOUT ROWID", where
14805 ** the intck_wrapper aliases of "a" and "b" are "c1" and "c2":
14808 ** i_pk: "i.'a', i.'b'"
14813 " WITH pkfields(f, a) AS ("
14817 " group_concat(a, ', '), "
14819 " group_concat('quote(o.'||a||')', ' || '','' || '), "
14821 " group_concat('o.'||a, ', '), "
14825 " group_concat('quote('||a||')', ', '), "
14851 " WITH f(a, b) AS ("
14856 " SELECT group_concat(format('%s AS %s', a, b), ',\n ') FROM f"
14859 /* If the object being checked is a table, append "NOT INDEXED".
14861 ** is a partial index " WHERE <condition>". */
14879 /* Table idxname contains a single row. The first column, "db", contains
14933 /* Table tabname contains a single row. The first column, "db", contains
14977 /* This table contains a single row consisting of a single value -
14980 ** the scan if it is suspended. e.g. for a rowid table, an expression
15025 ** Open a new integrity-check object.
15134 ** Return a message describing the corruption encountered by the most recent
15149 ** Return the error code and message.
15201 ** The author disclaims copyright to this source code. In place of
15202 ** a legal notice, here is a blessing:
15218 ** To use the API to recover data from a corrupted database, an
15233 ** 4) Retrieves any error code and English language error message using the
15257 ** An instance of the sqlite3_recover object represents a recovery
15280 ** These two APIs attempt to create and return a new sqlite3_recover object.
15283 ** database handle and the second the name of a database attached to that
15287 ** handle, then data is recovered into a new database, identified by
15293 ** be returned to the user as a series of SQL statements. Executing these
15297 ** invoked once. The first parameter is a passed a copy of the fourth argument
15298 ** to this function (pCtx) as its first parameter, and a pointer to a
15302 ** the recover handle error code (see below).
15305 ** a valid handle. In all other cases, it is the responsibility of the
15332 ** or an SQLite error code otherwise.
15338 ** The pArg argument points to a string buffer containing the name
15339 ** of a "lost-and-found" table in the output database, or NULL. If
15346 ** The pArg value must actually be a pointer to a value of type
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
15357 ** The pArg value must actually be a pointer to a value of type
15358 ** int containing value 0 or 1 cast as a (void*). If this option is set
15365 ** The pArg value must actually be a pointer to a value of type
15366 ** int containing value 0 or 1 cast as a (void*). If this option is clear
15371 ** final call to sqlite3_recover_step() for a recovery operation may
15372 ** be need to create a large number of indexes, which may be very slow.
15387 ** Perform a unit of work towards the recovery operation. This function
15393 ** error code (e.g. SQLITE_IOERR or SQLITE_NOMEM) is returned. It is not
15397 ** Once sqlite3_recover_step() has returned a value other than SQLITE_OK,
15405 ** or an SQLite error code otherwise. Calling this function is the same
15414 ** If an error has been encountered during a prior call to
15415 ** sqlite3_recover_step(), then this function attempts to return a
15416 ** pointer to a buffer containing an English language explanation of
15418 ** error occurs while attempting to allocate a buffer in which to format
15428 ** an error occurs, an SQLite error code is returned. Otherwise, SQLITE_OK.
15433 ** Clean up a recovery object created by a call to sqlite3_recover_init().
15434 ** The results of using a recovery object with any API after it has been
15454 ** The author disclaims copyright to this source code. In place of
15455 ** a legal notice, here is a blessing:
15468 ** sqlite_dbdata is used to extract data directly from a database b-tree
15485 ** a b-tree page, or if it is a b-tree page containing 0 entries, the
15493 ** CREATE TABLE t1(a, b); -- root page is page 2
15494 ** INSERT INTO t1(rowid, a, b) VALUES(5, 'v', 'five');
15495 ** INSERT INTO t1(rowid, a, b) VALUES(10, 'x', 'ten');
15521 ** It contains one entry for each b-tree pointer between a parent and
15670 ** Disconnect from or destroy a sqlite_dbdata or sqlite_dbptr virtual table.
15742 ** Open a new sqlite_dbdata or sqlite_dbptr cursor.
15760 ** Restore a cursor object to the state it was in when first allocated
15794 static u32 get_uint16(unsigned char *a){
15795 return (a[0]<<8)|a[1];
15797 static u32 get_uint32(unsigned char *a){
15798 return ((u32)a[0]<<24)
15799 | ((u32)a[1]<<16)
15800 | ((u32)a[2]<<8)
15801 | ((u32)a[3]);
15806 ** If successful, set (*ppPage) to point to a buffer containing the page
15812 ** return an SQLite error code.
15852 ** Read a varint. Put the value in *pVal and return the number of bytes.
15910 ** Load a value of type eType from buffer pData and use it to set the
15993 /* This macro is a copy of the MX_CELL() macro in the SQLite core. Given
15994 ** a page-size, it returns the maximum number of cells that may be present
15998 /* Maximum number of fields that may appear in a single record. This is
16070 /* This is not a b-tree page with records on it. Continue. */
16098 /* If this is a leaf intkey cell, load the rowid */
16127 /* Allocate space for payload. And a bit more to catch small buffer
16128 ** overruns caused by attempting to read a varint or similar from
16129 ** near the end of a corrupt record. */
16240 ** an SQLite error code.
16269 ** and return SQLITE_OK. Otherwise, return an SQLite error code.
16353 ** Return a column for the sqlite_dbdata or sqlite_dbptr table.
16432 dbdataOpen, /* xOpen - open a cursor */
16433 dbdataClose, /* xClose - close a cursor */
16435 dbdataNext, /* xNext - advance a cursor */
16476 ** The author disclaims copyright to this source code. In place of
16477 ** a legal notice, here is a blessing:
16497 ** sqlite_dbdata virtual tables with a database handle.
16533 ** used to construct the output database. If the table does has a rowid
16544 ** are then stored in a singly-linked list linked by this variable beginning
16605 ** Array large enough to contain a bit for each key. For key value
16685 /* Error code and error message */
16719 ** Populate the recovery.map table - used to figure out a "root" page
16793 ** This function is a no-op if the recover handle passed as the first
16796 ** Otherwise, an attempt is made to allocate, zero and return a buffer nByte
16797 ** bytes in size. If successful, a pointer to the new buffer is returned. Or,
16798 ** if an OOM error occurs, NULL is returned and the handle error code
16816 ** Set the error code and error message for the recover handle passed as
16817 ** the first argument. The error code is set to the value of parameter
16820 ** Parameter zFmt must be a printf() style formatting string. The handle
16848 ** This function is a no-op if p->errCode is initially other than SQLITE_OK.
16851 ** Otherwise, an attempt is made to allocate and return a bitmap object
16852 ** large enough to store a bit for all page numbers between 1 and nPg,
16867 ** Free a bitmap object allocated by recoverBitmapAlloc().
16899 ** Set the recover handle error to the error code and message returned by
16908 ** This function is a no-op if recover handle p already contains an error
16931 ** This function is a no-op if recover handle p already contains an error
16934 ** Otherwise, argument zFmt is used as a printf() style format string,
16939 ** error code and message are left in the recover handle.
16967 ** code and error message appropriately.
16969 ** This function returns a copy of the statement handle pointer passed
16984 ** code and error message appropriately.
16995 ** This function is a no-op if recover handle p already contains an error
17000 ** Or, if an error occurs, leave an error code and message in the recover
17001 ** handle and return a copy of the error code.
17031 ** This function is a no-op if recover handle p already contains an error
17034 ** Otherwise, an attempt is made to interpret zFmt as a printf() style
17036 ** parameter substitution with it written into a buffer obtained from
17037 ** sqlite3_malloc(). If successful, a pointer to the buffer is returned.
17041 ** Or, if an error occurs, an error code and message is left in the recover
17060 ** This function is a no-op if recover handle p already contains an error
17065 ** error code and error message in the sqlite3_recover handle and return
17084 ** this function must be a blob. The second a non-negative integer. This
17085 ** function reads and returns a 32-bit big-endian integer from byte
17105 const unsigned char *a = &pBlob[iInt*4];
17106 i64 iVal = ((i64)a[0]<<24)
17107 + ((i64)a[1]<<16)
17108 + ((i64)a[2]<< 8)
17109 + ((i64)a[3]<< 0);
17120 ** The only argument to this function is a page-number. It returns true
17138 ** The implementation of a user-defined SQL function invoked by the
17142 ** This function always takes a single integer argument. If the argument
17144 ** recovered. If the argument is greater than zero, it is a page number.
17149 ** SELECT getpage(4); -- return page 4 of db as a blob of data
17198 ** Find a string that is not found anywhere in z[]. Return a pointer
17207 char *zBuf /* Space to store a generated string */
17222 ** was a text value, then this function searches the input for "\n" and "\r"
17223 ** characters and adds a wrapper similar to the following:
17227 ** Or, if the first character of the input is not "'", then a copy of the input
17309 ** This function is a no-op if recover handle p already contains an error
17310 ** (if p->errCode!=SQLITE_OK). A copy of the error code is returned in
17316 ** If no error occurs, SQLITE_OK is returned. Otherwise, an error code
17317 ** and error message are left in the recover handle and a copy of the
17318 ** error code returned. It is not considered an error if part of all of
17343 ** this function is a no-op. Otherwise, issue a callback with SQL statement
17346 ** If the callback returns non-zero, set the recover handle error code to
17379 ** opening a new, empty, temp db, then using the backup API to clobber
17380 ** any existing output db with a copy of it. */
17405 recoverExec(p, db2, "CREATE TABLE t1(a); DROP TABLE t1;");
17423 ** This function is a no-op if recover handle p already contains an error
17424 ** (if p->errCode!=SQLITE_OK). A copy of the error code is returned in
17432 ** If no error occurs, SQLITE_OK is returned. Otherwise, an error code
17433 ** and error message are left in the recover handle and a copy of the
17434 ** error code returned.
17497 ** This function is a no-op if recover handle p already contains an error
17500 ** Otherwise, argument zName must be the name of a table that has just been
17502 ** for the schema of said table, and creates a RecoverTable object to
17722 ** This function is a no-op if recover handle p already contains an error
17727 ** prepares and returns an SQL statement to INSERT a new record into table
17728 ** pTab, assuming the first nField fields of a record extracted from disk
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);
17744 ** prepared is such that evaluating it returns a single row containing
17745 ** a single text value - itself an SQL statement similar to the above,
17748 ** SELECT 'INSERT INTO (a, c, d) VALUES ('
17828 ** return a pointer to it. Otherwise, return NULL.
17837 ** This function attempts to create a lost and found table within the
17838 ** output db. If successful, it returns a pointer to a buffer containing
17842 ** If an error occurs, NULL is returned and an error code and error
17949 ** an SQLite error code is returned and the final value of *piRoot
18140 ** that will be written to the output database in a single row. */
18146 ** to loop through cells that appear to belong to a single table (pSel). */
18315 ** already allocated to a recovered schema element is determined.
18325 /* Prepare a statement to iterate through all pages that are part of any tree
18367 ** already allocated to a recovered schema element is determined.
18509 ** buffer a[].
18511 static u32 recoverGetU16(const u8 *a){
18512 return (((u32)a[0])<<8) + ((u32)a[1]);
18517 ** buffer a[].
18519 static u32 recoverGetU32(const u8 *a){
18520 return (((u32)a[0])<<24) + (((u32)a[1])<<16) + (((u32)a[2])<<8) + ((u32)a[3]);
18524 ** Decode an SQLite varint from buffer a[]. Write the decoded value to (*pVal)
18527 static int recoverGetVarint(const u8 *a, i64 *pVal){
18531 u = (u<<7) + (a[i]&0x7f);
18532 if( (a[i]&0x80)==0 ){ *pVal = (sqlite3_int64)u; return i+1; }
18534 u = (u<<8) + (a[i]&0xff);
18540 ** The second argument points to a buffer n bytes in size. If this buffer
18541 ** or a prefix thereof appears to contain a well-formed SQLite b-tree page,
18543 ** appear to contain a well-formed b-tree page, return 0.
18545 static int recoverIsValidPage(u8 *aTmp, const u8 *a, int n){
18556 eType = (int)a[0];
18559 iFree = (int)recoverGetU16(&a[1]);
18560 nCell = (int)recoverGetU16(&a[3]);
18561 iContent = (int)recoverGetU16(&a[5]);
18563 nFrag = (int)a[7];
18576 iNext = recoverGetU16(&a[iFree]);
18577 nByte = recoverGetU16(&a[iFree+2]);
18595 int iOff = recoverGetU16(&a[iCellOff + 2*ii]);
18600 nByte += recoverGetVarint(&a[iOff+nByte], &nPayload);
18603 nByte += recoverGetVarint(&a[iOff+nByte], &dummy);
18685 ** Write value v to buffer a[] as a 16-bit big-endian unsigned integer.
18687 static void recoverPutU16(u8 *a, u32 v){
18688 a[0] = (v>>8) & 0x00FF;
18689 a[1] = (v>>0) & 0x00FF;
18693 ** Write value v to buffer a[] as a 32-bit big-endian unsigned integer.
18695 static void recoverPutU32(u8 *a, u32 v){
18696 a[0] = (v>>24) & 0x00FF;
18697 a[1] = (v>>16) & 0x00FF;
18698 a[2] = (v>>8) & 0x00FF;
18699 a[3] = (v>>0) & 0x00FF;
18704 ** searching the first part of the file for a well-formed SQLite b-tree
18706 ** a b-tree page with zero reserved bytes, this function searches for one
18712 ** if an error occurs (e.g. an IO or OOM error), then an SQLite error code
18783 /* Ensure that the database has a valid header file. The only fields
18800 ** Byte offset 105 should also contain the page-size as a 16-bit
18821 u8 *a = (u8*)aBuf;
18823 u32 pgsz = recoverGetU16(&a[16]);
18824 u32 nReserve = a[20];
18825 u32 enc = recoverGetU32(&a[56]);
18858 aHdr[18] = a[18];
18859 aHdr[19] = a[19];
18867 memcpy(&aHdr[aPreserve[ii]], &a[aPreserve[ii]], 4);
18888 #define RECOVER_VFS_WRAPPER(code) \
18892 rc = code; \
18895 rc = code; \
19040 ** This function does the work of a single sqlite3_recover_step() call. It
19152 ** This is a worker function that does the heavy lifting for both init
19197 ** Initialize a recovery handle that creates a new database containing
19209 ** Initialize a recovery handle that returns recovered data in the
19210 ** form of SQL statements via a callback.
19229 ** Return the handle error code.
19289 ** Do a unit of work towards the recovery job. Return SQLITE_OK if
19292 ** error code if an error has occurred.
19305 ** else an SQLite error code.
19315 ** argument. The results of using a handle with any sqlite3_recover_**
19353 ** State information for a single open session
19450 char nullValue[20]; /* The text to print when a NULL comes back from
19498 #define SHELL_OPEN_READONLY 4 /* Open a normal database read-only */
19542 #define MODE_List 2 /* One record per line with a separator */
19552 #define MODE_EQP 12 /* Converts EXPLAIN QUERY PLAN output into a graph */
19557 #define MODE_Count 17 /* Output only a count of the rows of output */
19598 ** It's not too expensive, so a generous allowance can be made.
19616 ** adding a newline at the end, and then return X.
19655 ** (1) Write VALUE into a temporary file.
19663 ** Also throw an error if the EDITOR program returns a non-zero exit code.
19810 ** Output the given string as a hex-encoded blob (eg. X'1234' )
19822 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
19834 ** Find a string that is not found anywhere in z[]. Return a pointer
19843 char *zBuf /* Space to store a generated string */
19855 ** Output the given string as a quoted string using SQL quoting conventions.
19898 ** Output the given string as a quoted string using SQL quoting conventions.
19989 ** Output the given string as a quoted according to C or TCL quoting rules.
20031 ** Output the given string as a quoted according to JSON quoting rules.
20115 ** If a field contains any character identified by a 1 in the following
20138 ** Output a single term of CSV. Actually, p->colSeparator is used for
20139 ** the separator, which may or may not be a comma. p->nullValue is
20220 /* In WASM builds the filesystem is a virtual sandbox, so
20288 ** Print a schema statement. Part of MODE_Semi and MODE_Pretty output.
20293 ** If the schema statement in z[] contains a start-of-comment and if
20348 ** Add a new entry to the EXPLAIN QUERY PLAN data
20394 /* Render a single level of the graph that has iEqpId as its parent. Called
20472 ** Print a markdown or table-style row separator using ascii-art
20494 ** invokes for each row of a query result.
20887 ** invokes for each row of a query result.
20890 /* since we don't have type info, call the shell_callback with a NULL value */
20896 ** output onto the end of a ShellText object.
20991 ** Maybe construct two lines of text that point out the position of a
20992 ** syntax error. Return a pointer to the text, in memory obtained from
20993 ** sqlite3_malloc(). Or, if the most recent error does not involve a
21035 ** Execute a query statement that will generate SQL output. Print
21036 ** the result columns, comma-separated, on a line and then add a
21040 ** then write the semicolon on a separate line. That way, if a
21093 int rc, /* Error code returned from API */
21150 ** Display a single line of status using 64-bit values.
21421 ** Parameter azArray points to a zero-terminated array of strings. zStr
21422 ** points to a single nul-terminated string. Return non-zero if zStr
21446 ** See tag-20220407a in wherecode.c and vdbe.c.
21469 ** an EXPLAIN, or it may be a query on the bytecode() virtual table. */
21485 ** different if the current instruction is part of a sub-program generated
21602 ** Bind parameters on a prepared statement.
21604 ** Parameter bindings are taken from a TEMP table of the form:
21698 ** Draw a horizontal separator for a MODE_Box table.
21721 ** z[] is a line of text that is to be displayed the .mode box or table or
21726 ** first \r, \n, or \f. Expand \t into spaces. Return a copy (obtained
21729 ** the last line, write a NULL into *pzTail. (*pzTail is not allocated.)
21767 /* Perhaps try to back up to a better place to break the line */
21836 const unsigned char *a = sqlite3_column_blob(pStmt,i);
21840 sqlite3_str_appendf(pStr, "%02x", a[j]);
21850 ** Run a prepared statement and output the result in one of the
22083 ** Run a prepared statement
22102 ** have a result set or not and how wide it is.
22105 /* if we have a result set... */
22171 ** code. In this case, (*pzErr) may be set to point to a buffer containing
22187 ** created by the ".expert" command (if bCancel==1), or to generate a
22191 ** code. In this case, (*pzErr) may be set to point to a buffer containing
22296 ** Execute a statement or set of statements. Print
22301 ** function except it takes a slightly different callback
22335 /* this happens for a comment or white-space */
22427 /* Finalize the statement just executed. If this fails, save a
22457 /* azCol[0] is a static string */
22462 ** Return a list of pointers to strings which are the names of all
22464 ** allocated and must be released by the caller using a subsequent call
22467 ** The azCol[0] entry is usually NULL. However, if zTab contains a rowid
22515 /* The decision of whether or not a rowid really needs to be preserved
22516 ** is tricky. We never need to preserve a rowid for a WITHOUT ROWID table
22517 ** or a table with an INTEGER PRIMARY KEY. We are unable to preserve
22522 /* If a single PRIMARY KEY column with type INTEGER was seen, then it
22523 ** might be an alias for the ROWID. But it might also be a WITHOUT ROWID
22524 ** table or a INTEGER PRIMARY KEY DESC column, neither of which are
22526 ** there is a "pk" entry in "PRAGMA index_list". There will be
22543 /* Only preserve the rowid if we can find a name to use for the
22553 ** ordinary column in the table. Verify that azRowid[j] is a valid
22583 ** This is a different callback routine used for dumping the database.
22584 ** Each row received by this callback consists of a table name,
22648 ** in case it is a keyword. Ex: INSERT INTO "table" ... */
22651 /* If preserving the rowid, add a column list after the table name.
22652 ** In other words: "INSERT INTO tab(rowid,a,b,c,...) VALUES(...)"
22706 ** If we get a SQLITE_CORRUPT error, rerun the query after appending
22743 ** The help text for each individual command begins with a line that starts
22754 " -c, --create Create a new archive",
22763 " -a FILE, --append FILE Open FILE using the apndvfs VFS",
22807 " OBJECTS is a LIKE pattern for tables, indexes, triggers or views to dump",
22819 " --bom Put a UTF8 byte-order mark on intermediate file",
22822 ".exit ?CODE? Exit this program with return-code CODE",
22845 " * If FILE begins with \"|\" then it is a command that generates the",
22876 " html HTML <table> code",
22878 " json Results in a JSON array",
22900 " If FILE begins with '|' then open as a pipe",
22901 " --bom Put a UTF8 byte-order mark at the beginning",
22903 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
22919 " --zip FILE is a ZIP archive",
22922 " If FILE begins with '|' then open it as a pipe.",
22924 " --bom Prefix output with a UTF8 byte-order mark",
22926 " -x Send output as CSV to a spreadsheet",
22932 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
22947 " If FILE begins with \"|\", it is a command that generates the input.",
22967 " --init Create a new SELFTEST table",
22974 " changeset FILE Write a changeset into FILE",
22981 " open DB NAME Open a new session on DB",
22982 " patchset FILE Write a patchset into FILE",
22985 ".sha3sum ... Compute a SHA3 hash of database content",
22992 " Any other argument is a LIKE pattern for tables to hash",
22994 ".shell CMD ARGS... Run CMD ARGS... in a system shell",
23003 ".system CMD ARGS... Run CMD ARGS... in a system shell",
23045 ** If zPattern is NULL, then show all commands, but only give a one-line
23057 || cli_strcmp(zPattern,"-a")==0
23108 /* when zPattern is a prefix of exactly one command, then include
23147 ** and return a pointer to the buffer. The caller is responsible for freeing
23153 ** For convenience, a nul-terminator byte is always appended to the data read
23195 ** Close a single OpenSession object and release all of its associated
23245 ** If the file does not exist or is empty but its name looks like a ZIP
23246 ** archive and the dfltZip flag is true, then assume it is a ZIP archive.
23292 unsigned char *a = 0;
23323 a = sqlite3_malloc( n ? n : 1 );
23324 shell_check_oom(a);
23325 memset(a, 0, n);
23346 for(ii=0; ii<16; ii++) a[k+ii] = x[ii]&0xff;
23356 return a;
23368 sqlite3_free(a);
23394 ** The OPEN_DB_ZIPFILE flag causes open_db() to prefer to open files as a
23491 /* Create a preprocessing mechanism for extensions to make
23493 * This is a short-span macro. See further below for usage.
23664 ** \a -> alarm
23685 if( c=='a' ){
23686 c = '\a';
23732 ** Interpret zArg as either an integer or a boolean value. Return 1 or 0
23749 eputf("ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n", zArg);
23754 ** Set or clear a shell flag according to a boolean value.
23800 void *pP, /* Usually a pointer to sqlite_stmt */
23855 ** a useful spot to set a debugger breakpoint.
23857 ** This routine does not do anything practical. The code are there simply
23866 ** An object used to read a CSV and other files for import.
23873 char *z; /* Accumulated text for a field */
23895 /* Append a single byte to z[] */
23905 /* Read a single field of CSV text. Compatible with rfc4180 and extended
23906 ** with the option of having a separator other than ",".
23995 /* Read a single field of ASCII delimited text.
24220 ** Open a new database file named "zNewDb". Try to recover as much information
24261 ** redirected to a temporary file named by p->zTempFile. In that case,
24322 ** Convert a 2-byte or 4-byte big-endian integer into a native integer
24324 static unsigned int get2byteInt(unsigned char *a){
24325 return (a[0]<<8) + a[1];
24327 static unsigned int get4byteInt(unsigned char *a){
24328 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
24539 ** Compare the string as a command-line option with either one or two
24550 ** Delete a file.
24577 ** Create a new temp file name with the given suffix.
24675 int rc; /* Return code */
24872 ** Create a prepared statement using printf-style arguments for the SQL.
24943 ** Structure representing a single ".ar" command.
24949 u8 bZip; /* True if the archive is a ZIP */
24964 ** Print a usage message for the .ar command to stderr and return SQLITE_ERROR.
25076 { "append", 'a', AR_SWITCH_APPEND, 1 },
25202 ** error code returned. Otherwise, if all specified arguments are present
25204 ** exact equality when pAr->bGlob is false or a "name GLOB pattern" match
25244 ** Format a WHERE clause that can be used against the "sqlar" table to
25328 ** And formulate a WHERE clause to match them. */
25382 ** the archive before proceeding. And formulate a WHERE clause to
25432 ** Run the SQL statement in zSql. Or if doing a --dryrun, merely print it out.
25454 ** create -> Create a new SQL archive
25461 ** are added recursively. If argument bVerbose is non-zero, a message is
25471 int bUpdate, /* true for a --create. */
25507 int rc; /* Return code */
25690 ** This function is used as a callback by the recover extension. Simply
25701 ** to construct a new database containing all recovered data is output
25724 ** means to use a temporary database that is automatically deleted
25805 * (a) The db was not initialized and zCol==0 (There are no columns.)
25808 * pointer is non-zero, its referent will be set to a summary of renames
25824 #ifdef SHELL_COLFIX_DB /* If this is set, the DB can be in a file. */
25929 '('||x'0a'\
25932 ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\
25941 " ','||x'0a')"
26045 int iId; /* ID that triggers a simulated fault. -1 means "any" */
26046 int iErr; /* The error code to return on a fault */
26131 if( c=='a' && cli_strncmp(azArg[0], "auth", n)==0 ){
26150 if( c=='a' && cli_strncmp(azArg[0], "archive", n)==0 ){
26252 /* The undocumented ".breakpoint" command causes a call to the no-op
26382 eputz("The \".crnl\" is a no-op on non-Windows machines.\n");
26463 eputz("Enter \".dbconfig\" with no arguments for a list\n");
26518 /* azArg[i] contains a LIKE pattern. This ".dump" request should
26520 ** the LIKE pattern, or the table appears to be a shadow table of
26521 ** a virtual table for which the name matches the LIKE pattern.
26544 /* When playing back a "dump", the content might appear in an order
26678 const char *zCtrlName; /* Name of a test-control option */
26679 int ctrlCode; /* Integer code for that option */
26732 ** of the option name, or a numerical value. */
27213 int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
27229 ** where TABLE is a WITHOUT ROWID table. In that case, the
27352 const char *zLimitName; /* Name of a limit */
27353 int limitCode; /* Integer code for that limit */
27395 "enter \".limits\" with no arguments for a list.\n",
27420 /* Must have a non-empty FILE. (Will not load self.) */
27662 /* If a filename is specified, try to open it first */
27692 /* As a fall-back open a TEMP database */
27861 ** Set or reset a bind parameter. NAME should be the full parameter
27864 ** understood to be a text string.
27911 /* If no command name matches, show a syntax error */
28279 ** Invoke the sqlite3session_attach() interface to attach a particular
28298 ** Write a changeset or patchset into a file. The file is overwritten.
28320 sputf(stdout, "Error: error code %d\n", rc);
28357 ** Set a list of GLOB patterns of table names to be excluded.
28413 ** Open a new session called NAME on the attached database DB.
28434 eputf("Cannot open session: error code=%d\n", rc);
28444 /* If no command name matches, show a syntax error */
28480 ShellText str; /* Answer for a query */
28557 oputf("%d: error-code-%d: %s\n", tno, rc, zErrMsg);
28652 appendText(&sSql, "WITH [sha3sum$query](a,b) AS(",0);
28687 " SELECT lower(hex(sha3_query(a,%d))) AS hash, b AS label"
28693 " SELECT lower(hex(sha3_query(group_concat(a,''),%d))) AS hash"
28989 const char *zCtrlName; /* Name of a test-control option */
28990 int ctrlCode; /* Integer code for that option */
29049 ** of the option name, or a numerical value. */
29294 " --errcode N When triggered, return N as error code\n"
29673 ** than a semi-colon. The SQL Server style "go" command is understood
29688 ** The CLI needs a working sqlite3_complete() to work properly. So error
29696 ** Return true if zSql is a complete SQL statement. Return false if it
29697 ** ends in the middle of a string literal or C-style comment.
29725 ** 7: Nothing left to do. This function becomes a no-op.
29792 ** Run a single line of SQL. Return the number of errors.
29851 ** function without moving lots of code around (creating a larger/messier diff).
29883 ** is coming from a file or device. A prompt is issued and history
29895 int rc; /* Error code */
29901 /* This will be more informative in a later version. */
30000 ** Return a pathname which is the user's home directory. A
30182 " -maxsize N maximum size for a --deserialize database\n"
30213 " -zip open the file as a ZIP Archive\n"
30229 ** Internal check: Verify that the SQLite is uninitialized. Print a
30262 ** Output text to the console in a font that attracts extra attention.
30378 /* Register a valid signal handler early, before much else is done. */
30428 ** of a C-function that will provide the name of the database file. Use
30478 ** we do the actual processing of arguments later in a second pass.
30604 ** of a C-function that will perform initialization actions on SQLite that
30642 ** files from being created if a user mistypes the database name argument
30650 ** is given on the command line, look for a file named ~/.sqliterc and
30655 /* Make a second pass through the command-line argument and set
30840 eputz("Use -help for a list of options.\n");
30890 sputz(stdout, "Connected to a ");
30892 sputz(stdout, ".\nUse \".open FILENAME\" to reopen on a"
30924 ** client code can "push" SQL into it after this call returns. */
30969 int fiddle_experiment(int a,int b){
30970 return a + b;
30974 ** Returns a pointer to the current DB handle.
30981 ** Returns a pointer to the given DB name's VFS. If zDbName is 0 then
31001 ** Intended to be called via a SharedWorker() while a separate
31044 ** contents out to the given callback. The callback gets a single
31048 ** code from the callback. Note that this is not thread-friendly: it