Sqlite3 3.50.2
Light weight SQL DB
Loading...
Searching...
No Matches
shell.c File Reference
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include "sqlite3.h"
#include <ctype.h>
#include <stdarg.h>
#include <signal.h>
#include <pwd.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <memory.h>
#include <limits.h>
#include <fcntl.h>
#include <utime.h>
#include <time.h>
#include <errno.h>
Include dependency graph for shell.c:

Go to the source code of this file.

Data Structures

struct  DynaPrompt
struct  ShellText
struct  SHA3Context
struct  SHA1Context
struct  Decimal
struct  Percentile
struct  PercentileFunc
struct  SequenceSpec
struct  series_cursor
struct  ReStateSet
struct  ReInput
struct  ReCompiled
struct  FsdirLevel
struct  fsdir_cursor
struct  fsdir_tab
struct  completion_vtab
struct  completion_cursor
struct  ApndFile
struct  IdxConstraint
struct  IdxScan
struct  IdxColumn
struct  IdxTable
struct  IdxWrite
struct  IdxStatement
struct  IdxHashEntry
struct  IdxHash
struct  sqlite3expert
struct  ExpertVtab
struct  ExpertCsr
struct  IdxSampleCtx
struct  IdxRemCtx
struct  IdxRemCtx::IdxRemSlot
struct  sqlite3_intck
struct  Stmtrand
struct  vfstrace_info
struct  vfstrace_file
struct  ExpertInfo
struct  EQPGraphRow
struct  EQPGraph
struct  ColModeOpts
struct  ShellState
struct  ShellState::AuxDb
struct  ImportCtx
union  SHA3Context.u

Macros

#define SHELL_STRINGIFY_(f)
#define SHELL_STRINGIFY(f)
#define SQLITE_OS_WINRT   0
#define _LARGE_FILE   1
#define _FILE_OFFSET_BITS   64
#define _LARGEFILE_SOURCE   1
#define GETPID   getpid
#define shell_read_history(X)
#define shell_write_history(X)
#define shell_stifle_history(X)
#define SHELL_USE_LOCAL_GETLINE   1
#define deliberate_fall_through
#define IsSpace(X)
#define IsDigit(X)
#define ToLower(X)
#define IsAlnum(X)
#define IsAlpha(X)
#define _SQLITE3_STDIO_H_   1
#define sqlite3_fopen   fopen
#define sqlite3_popen   popen
#define sqlite3_fgets   fgets
#define sqlite3_fputs   fputs
#define sqlite3_fprintf   fprintf
#define sqlite3_fsetmode(F, X)
#define SQLITE_INTERNAL_LINKAGE   static
#define eputz(z)
#define sputz(fp, z)
#define BEGIN_TIMER   beginTimer()
#define END_TIMER(X)
#define HAS_TIMER   1
#define UNUSED_PARAMETER(x)
#define ArraySize(X)
#define PROMPT_LEN_MAX   128
#define CONTINUATION_PROMPT   dynamicContinuePrompt()
#define CONTINUE_PROMPT_RESET    do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)
#define CONTINUE_PROMPT_AWAITS(p, s)
#define CONTINUE_PROMPT_AWAITC(p, c)
#define CONTINUE_PAREN_INCR(p, n)
#define CONTINUE_PROMPT_PSTATE   (&dynPrompt)
#define SCAN_TRACKER_REFTYPE   t_DynaPromptRef
#define STAT_CHR_SRC(mode)
#define SQLITE_EXTENSION_INIT1
#define SQLITE_EXTENSION_INIT2(X)
#define SHA3_BYTEORDER   0
#define a00   (p->u.s[0])
#define a01   (p->u.s[1])
#define a02   (p->u.s[2])
#define a03   (p->u.s[3])
#define a04   (p->u.s[4])
#define a10   (p->u.s[5])
#define a11   (p->u.s[6])
#define a12   (p->u.s[7])
#define a13   (p->u.s[8])
#define a14   (p->u.s[9])
#define a20   (p->u.s[10])
#define a21   (p->u.s[11])
#define a22   (p->u.s[12])
#define a23   (p->u.s[13])
#define a24   (p->u.s[14])
#define a30   (p->u.s[15])
#define a31   (p->u.s[16])
#define a32   (p->u.s[17])
#define a33   (p->u.s[18])
#define a34   (p->u.s[19])
#define a40   (p->u.s[20])
#define a41   (p->u.s[21])
#define a42   (p->u.s[22])
#define a43   (p->u.s[23])
#define a44   (p->u.s[24])
#define ROL64(a, x)
#define SHA_ROT(x, l, r)
#define rol(x, k)
#define ror(x, k)
#define blk0le(i)
#define blk0be(i)
#define blk(i)
#define Rl0(v, w, x, y, z, i)
#define Rb0(v, w, x, y, z, i)
#define R1(v, w, x, y, z, i)
#define R2(v, w, x, y, z, i)
#define R3(v, w, x, y, z, i)
#define R4(v, w, x, y, z, i)
#define a   qq[0]
#define b   qq[1]
#define c   qq[2]
#define d   qq[3]
#define e   qq[4]
#define SWAP_DOUBLE(X, Y)
#define sqlite3_base_init   sqlite3_base64_init
#define PC   0x80 /* pad character */
#define WS   0x81 /* whitespace */
#define ND   0x82 /* Not above or digit-value */
#define PAD_CHAR   '='
#define U8_TYPEDEF
#define BX_DV_PROTO(c)
#define IS_BX_DIGIT(bdp)
#define IS_BX_WS(bdp)
#define IS_BX_PAD(bdp)
#define BX_NUMERAL(dv)
#define B64_DARK_MAX   72
#define BASE64_INIT(db)
#define BASE64_EXPOSE(db, pzErr)
#define sqlite3_base_init   sqlite3_base85_init
#define OMIT_BASE85_CHECKER
#define B85_CLASS(c)
#define B85_DNOS(c)
#define IS_B85(c)
#define B85_DARK_MAX   80
#define base85Numeral(dn)
#define BASE85_INIT(db)
#define BASE85_EXPOSE(db, pzErr)
#define SERIES_COLUMN_ROWID   (-1)
#define SERIES_COLUMN_VALUE   0
#define SERIES_COLUMN_START   1
#define SERIES_COLUMN_STOP   2
#define SERIES_COLUMN_STEP   3
#define LARGEST_INT64   (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
#define LARGEST_UINT64   (0xffffffff|(((sqlite3_uint64)0xffffffff)<<32))
#define SMALLEST_INT64   (((sqlite3_int64)-1) - LARGEST_INT64)
#define SQLITE_SERIES_CONSTRAINT_VERIFY   0
#define re_match   sqlite3re_match
#define re_compile   sqlite3re_compile
#define re_free   sqlite3re_free
#define RE_EOF   0 /* End of input */
#define RE_START   0xfffffff /* Start of input - larger than an UTF-8 */
#define RE_OP_MATCH   1 /* Match the one character in the argument */
#define RE_OP_ANY   2 /* Match any one character. (Implements ".") */
#define RE_OP_ANYSTAR   3 /* Special optimized version of .* */
#define RE_OP_FORK   4 /* Continue to both next and opcode at iArg */
#define RE_OP_GOTO   5 /* Jump to opcode at iArg */
#define RE_OP_ACCEPT   6 /* Halt and indicate a successful match */
#define RE_OP_CC_INC   7 /* Beginning of a [...] character class */
#define RE_OP_CC_EXC   8 /* Beginning of a [^...] character class */
#define RE_OP_CC_VALUE   9 /* Single value in a character class */
#define RE_OP_CC_RANGE   10 /* Range of values in a character class */
#define RE_OP_WORD   11 /* Perl word character [A-Za-z0-9_] */
#define RE_OP_NOTWORD   12 /* Not a perl word character */
#define RE_OP_DIGIT   13 /* digit: [0-9] */
#define RE_OP_NOTDIGIT   14 /* Not a digit */
#define RE_OP_SPACE   15 /* space: [ \t\n\r\v\f] */
#define RE_OP_NOTSPACE   16 /* Not a digit */
#define RE_OP_BOUNDARY   17 /* Boundary between word and non-word */
#define RE_OP_ATSTART   18 /* Currently at the start of the string */
#define STRUCT_STAT   struct stat
#define FSDIR_SCHEMA   "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
#define FSDIR_COLUMN_NAME   0 /* Name of the file */
#define FSDIR_COLUMN_MODE   1 /* Access mode */
#define FSDIR_COLUMN_MTIME   2 /* Last modification time */
#define FSDIR_COLUMN_DATA   3 /* File content */
#define FSDIR_COLUMN_PATH   4 /* Path to top of search */
#define FSDIR_COLUMN_DIR   5 /* Path is relative to this directory */
#define COMPLETION_FIRST_PHASE   1
#define COMPLETION_KEYWORDS   1
#define COMPLETION_PRAGMAS   2
#define COMPLETION_FUNCTIONS   3
#define COMPLETION_COLLATIONS   4
#define COMPLETION_INDEXES   5
#define COMPLETION_TRIGGERS   6
#define COMPLETION_DATABASES   7
#define COMPLETION_TABLES   8 /* Also VIEWs and TRIGGERs */
#define COMPLETION_COLUMNS   9
#define COMPLETION_MODULES   10
#define COMPLETION_EOF   11
#define COMPLETION_COLUMN_CANDIDATE   0 /* Suggested completion of the input */
#define COMPLETION_COLUMN_PREFIX   1 /* Prefix of the word to be completed */
#define COMPLETION_COLUMN_WHOLELINE   2 /* Entire line seen so far */
#define COMPLETION_COLUMN_PHASE   3 /* ePhase - used for debugging only */
#define APND_MARK_PREFIX   "Start-Of-SQLite3-"
#define APND_MARK_PREFIX_SZ   17
#define APND_MARK_FOS_SZ   8
#define APND_MARK_SIZE   (APND_MARK_PREFIX_SZ+APND_MARK_FOS_SZ)
#define APND_MAX_SIZE   (0x40000000)
#define APND_ROUNDUP   4096
#define APND_ALIGN_MASK   ((sqlite3_int64)(APND_ROUNDUP-1))
#define APND_START_ROUNDUP(fsz)
#define ORIGVFS(p)
#define ORIGFILE(p)
#define SQLITEEXPERT_H   1
#define EXPERT_CONFIG_SAMPLE   1 /* int */
#define EXPERT_REPORT_SQL   1
#define EXPERT_REPORT_INDEXES   2
#define EXPERT_REPORT_PLAN   3
#define EXPERT_REPORT_CANDIDATES   4
#define ALWAYS(X)
#define NEVER(X)
#define STRLEN   (int)strlen
#define UNIQUE_TABLE_NAME   "t592690916721053953805701627921227776"
#define IDX_HASH_SIZE   1023
#define _SQLITE_INTCK_H
#define STMTRAND_KEY   (-4418371)
#define VTR_CLOSE   0x00000001
#define VTR_READ   0x00000002
#define VTR_WRITE   0x00000004
#define VTR_TRUNC   0x00000008
#define VTR_SYNC   0x00000010
#define VTR_FSIZE   0x00000020
#define VTR_LOCK   0x00000040
#define VTR_UNLOCK   0x00000080
#define VTR_CRL   0x00000100
#define VTR_FCTRL   0x00000200
#define VTR_SECSZ   0x00000400
#define VTR_DEVCHAR   0x00000800
#define VTR_SHMLOCK   0x00001000
#define VTR_SHMMAP   0x00002000
#define VTR_SHMBAR   0x00004000
#define VTR_SHMUNMAP   0x00008000
#define VTR_OPEN   0x00010000
#define VTR_DELETE   0x00020000
#define VTR_ACCESS   0x00040000
#define VTR_FULLPATH   0x00080000
#define VTR_DLOPEN   0x00100000
#define VTR_DLERR   0x00200000
#define VTR_DLSYM   0x00400000
#define VTR_DLCLOSE   0x00800000
#define VTR_RAND   0x01000000
#define VTR_SLEEP   0x02000000
#define VTR_CURTIME   0x04000000
#define VTR_LASTERR   0x08000000
#define VTR_FETCH   0x10000000 /* Also coverse xUnfetch */
#define SQLITE_SHELL_HAVE_RECOVER   0
#define ColModeOpts_default   { 60, 0, 0 }
#define ColModeOpts_default_qbox   { 60, 1, 0 }
#define AUTOEQP_off   0 /* Automatic EXPLAIN QUERY PLAN is off */
#define AUTOEQP_on   1 /* Automatic EQP is on */
#define AUTOEQP_trigger   2 /* On and also show plans for triggers */
#define AUTOEQP_full   3 /* Show full EXPLAIN */
#define SHELL_OPEN_UNSPEC   0 /* No open-mode specified */
#define SHELL_OPEN_NORMAL   1 /* Normal database file */
#define SHELL_OPEN_APPENDVFS   2 /* Use appendvfs */
#define SHELL_OPEN_ZIPFILE   3 /* Use the zipfile virtual table */
#define SHELL_OPEN_READONLY   4 /* Open a normal database read-only */
#define SHELL_OPEN_DESERIALIZE   5 /* Open using sqlite3_deserialize() */
#define SHELL_OPEN_HEXDB   6 /* Use "dbtotxt" output as data source */
#define SHELL_TRACE_PLAIN   0 /* Show input SQL text */
#define SHELL_TRACE_EXPANDED   1 /* Show expanded SQL text */
#define SHELL_TRACE_NORMALIZED   2 /* Show normalized SQL text */
#define SHELL_PROGRESS_QUIET   0x01 /* Omit announcing every progress callback */
#define SHELL_PROGRESS_RESET
#define SHELL_PROGRESS_ONCE   0x04 /* Cancel the --limit after firing once */
#define SHELL_ESC_ASCII   0 /* Substitute ^Y for X where Y=X+0x40 */
#define SHELL_ESC_SYMBOL   1 /* Substitute U+2400 graphics */
#define SHELL_ESC_OFF   2 /* Send characters verbatim */
#define SHFLG_Pagecache   0x00000001 /* The --pagecache option is used */
#define SHFLG_Lookaside   0x00000002 /* Lookaside memory is used */
#define SHFLG_Backslash   0x00000004 /* The --backslash option is used */
#define SHFLG_PreserveRowid   0x00000008 /* .dump preserves rowid values */
#define SHFLG_Newlines   0x00000010 /* .dump --newline flag */
#define SHFLG_CountChanges   0x00000020 /* .changes setting */
#define SHFLG_Echo   0x00000040 /* .echo on/off, or --echo setting */
#define SHFLG_HeaderSet   0x00000080 /* showHeader has been specified */
#define SHFLG_DumpDataOnly   0x00000100 /* .dump show data only */
#define SHFLG_DumpNoSys   0x00000200 /* .dump omits system tables */
#define SHFLG_TestingMode   0x00000400 /* allow unsafe testing features */
#define ShellHasFlag(P, X)
#define ShellSetFlag(P, X)
#define ShellClearFlag(P, X)
#define MODE_Line   0 /* One column per line. Blank line between records */
#define MODE_Column   1 /* One record per line in neat columns */
#define MODE_List   2 /* One record per line with a separator */
#define MODE_Semi   3 /* Same as MODE_List but append ";" to each line */
#define MODE_Html   4 /* Generate an XHTML table */
#define MODE_Insert   5 /* Generate SQL "insert" statements */
#define MODE_Quote   6 /* Quote values as for SQL */
#define MODE_Tcl   7 /* Generate ANSI-C or TCL quoted elements */
#define MODE_Csv   8 /* Quote strings, numbers are plain */
#define MODE_Explain   9 /* Like MODE_Column, but do not truncate data */
#define MODE_Ascii   10 /* Use ASCII unit and record separators (0x1F/0x1E) */
#define MODE_Pretty   11 /* Pretty-print schemas */
#define MODE_EQP   12 /* Converts EXPLAIN QUERY PLAN output into a graph */
#define MODE_Json   13 /* Output JSON */
#define MODE_Markdown   14 /* Markdown formatting */
#define MODE_Table   15 /* MySQL-style table formatting */
#define MODE_Box   16 /* Unicode box-drawing characters */
#define MODE_Count   17 /* Output only a count of the rows of output */
#define MODE_Off   18 /* No query output shown */
#define MODE_ScanExp   19 /* Like MODE_Explain, but for ".scanstats vm" */
#define MODE_Www   20 /* Full web-page output */
#define SEP_Column   "|"
#define SEP_Row   "\n"
#define SEP_Tab   "\t"
#define SEP_Space   " "
#define SEP_Comma   ","
#define SEP_CrLf   "\r\n"
#define SEP_Unit   "\x1F"
#define SEP_Record   "\x1E"
#define MAX_INPUT_NESTING   25
#define BOX_24   "\342\224\200" /* U+2500 --- */
#define BOX_13   "\342\224\202" /* U+2502 | */
#define BOX_23   "\342\224\214" /* U+250c ,- */
#define BOX_34   "\342\224\220" /* U+2510 -, */
#define BOX_12   "\342\224\224" /* U+2514 '- */
#define BOX_14   "\342\224\230" /* U+2518 -' */
#define BOX_123   "\342\224\234" /* U+251c |- */
#define BOX_134   "\342\224\244" /* U+2524 -| */
#define BOX_234   "\342\224\254" /* U+252c -,- */
#define BOX_124   "\342\224\264" /* U+2534 -'- */
#define BOX_1234   "\342\224\274" /* U+253c -|- */
#define session_close_all(X, Y)
#define OPEN_DB_KEEPALIVE   0x001 /* Return after error if true */
#define OPEN_DB_ZIPFILE   0x002 /* Open as ZIP if name matches *.zip */
#define AUTOCOLUMN_SEP   "_"
#define CTIMEOPT_VAL_(opt)
#define CTIMEOPT_VAL(opt)
#define CHAR_BIT   8
#define QSS_SETV(qss, newst)
#define QSS_INPLAIN(qss)
#define QSS_PLAINWHITE(qss)
#define QSS_PLAINDARK(qss)
#define QSS_SEMITERM(qss)
#define SQLITE_SHELL_IS_UTF8   (1)

Typedefs

typedef unsigned int u32
typedef unsigned short int u16
typedef sqlite3_int64 i64
typedef sqlite3_uint64 u64
typedef unsigned char u8
typedef struct DynaPromptt_DynaPromptRef
typedef struct ShellText ShellText
typedef struct SHA3Context SHA3Context
typedef struct SHA1Context SHA1Context
typedef struct Decimal Decimal
typedef struct Percentile Percentile
typedef struct PercentileFunc PercentileFunc
typedef struct SequenceSpec SequenceSpec
typedef struct series_cursor series_cursor
typedef unsigned short ReStateNumber
typedef struct ReStateSet ReStateSet
typedef struct ReInput ReInput
typedef struct ReCompiled ReCompiled
typedef struct fsdir_cursor fsdir_cursor
typedef struct FsdirLevel FsdirLevel
typedef struct fsdir_tab fsdir_tab
typedef struct completion_vtab completion_vtab
typedef struct completion_cursor completion_cursor
typedef struct sqlite3_vfs ApndVfs
typedef struct ApndFile ApndFile
typedef struct sqlite3expert sqlite3expert
typedef struct IdxColumn IdxColumn
typedef struct IdxConstraint IdxConstraint
typedef struct IdxScan IdxScan
typedef struct IdxStatement IdxStatement
typedef struct IdxTable IdxTable
typedef struct IdxWrite IdxWrite
typedef struct IdxHashEntry IdxHashEntry
typedef struct IdxHash IdxHash
typedef struct ExpertVtab ExpertVtab
typedef struct ExpertCsr ExpertCsr
typedef struct sqlite3_intck sqlite3_intck
typedef struct Stmtrand Stmtrand
typedef struct vfstrace_info vfstrace_info
typedef struct vfstrace_file vfstrace_file
typedef struct ExpertInfo ExpertInfo
typedef struct EQPGraphRow EQPGraphRow
typedef struct EQPGraph EQPGraph
typedef struct ColModeOpts ColModeOpts
typedef struct ShellState ShellState
typedef struct ImportCtx ImportCtx

Enumerations

enum  QuickScanState { QSS_HasDark = 1<< 8 , QSS_EndingSemi = 2<< 8 , QSS_CharMask = (1<< 8 )-1 , QSS_ScanMask = 3<< 8 , QSS_Start = 0 }

Functions

int isatty (int)
FILE * popen (const char *, const char *)
int pclose (FILE *)
static int cli_strcmp (const char *a, const char *b)
static int cli_strncmp (const char *a, const char *b, size_t n)
static sqlite3_int64 timeOfDay (void)
static void beginTimer (void)
static double timeDiff (struct timeval *pStart, struct timeval *pEnd)
static void endTimer (FILE *out)
static char * shell_strncpy (char *dest, const char *src, size_t n)
static void shell_strcpy (char *dest, const char *src)
static void trackParenLevel (struct DynaPrompt *p, int ni)
static void setLexemeOpen (struct DynaPrompt *p, char *s, char c)
static char * dynamicContinuePrompt (void)
static void shell_out_of_memory (void)
static void shell_check_oom (const void *p)
int cli_wcwidth (int c)
static int decodeUtf8 (const unsigned char *z, int *pU)
static int isVt100 (const unsigned char *z)
static void utf8_width_print (FILE *out, int w, const char *zUtf)
static int isNumber (const char *z, int *realnum)
static int strlen30 (const char *z)
static int strlenChar (const char *z)
static FILE * openChrSource (const char *zFile)
static char * local_getline (char *zLine, FILE *in)
static char * one_input_line (FILE *in, char *zPrior, int isContinuation)
static int hexDigitValue (char c)
static sqlite3_int64 integerValue (const char *zArg)
static void initText (ShellText *p)
static void freeText (ShellText *p)
static void appendText (ShellText *p, const char *zAppend, char quote)
static char quoteChar (const char *zName)
static char * shellFakeSchema (sqlite3 *db, const char *zSchema, const char *zName)
static void shellStrtod (sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
static void shellDtostr (sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
static void shellAddSchemaName (sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
static void * memtraceMalloc (int n)
static void memtraceFree (void *p)
static void * memtraceRealloc (void *p, int n)
static int memtraceSize (void *p)
static int memtraceRoundup (int n)
static int memtraceInit (void *p)
static void memtraceShutdown (void *p)
int sqlite3MemTraceActivate (FILE *out)
int sqlite3MemTraceDeactivate (void)
static int pcachetraceInit (void *pArg)
static void pcachetraceShutdown (void *pArg)
static sqlite3_pcachepcachetraceCreate (int szPage, int szExtra, int bPurge)
static void pcachetraceCachesize (sqlite3_pcache *p, int nCachesize)
static int pcachetracePagecount (sqlite3_pcache *p)
static sqlite3_pcache_pagepcachetraceFetch (sqlite3_pcache *p, unsigned key, int crFg)
static void pcachetraceUnpin (sqlite3_pcache *p, sqlite3_pcache_page *pPg, int bDiscard)
static void pcachetraceRekey (sqlite3_pcache *p, sqlite3_pcache_page *pPg, unsigned oldKey, unsigned newKey)
static void pcachetraceTruncate (sqlite3_pcache *p, unsigned n)
static void pcachetraceDestroy (sqlite3_pcache *p)
static void pcachetraceShrink (sqlite3_pcache *p)
int sqlite3PcacheTraceActivate (FILE *out)
int sqlite3PcacheTraceDeactivate (void)
static void KeccakF1600Step (SHA3Context *p)
static void SHA3Init (SHA3Context *p, int iSize)
static void SHA3Update (SHA3Context *p, const unsigned char *aData, unsigned int nData)
static unsigned char * SHA3Final (SHA3Context *p)
static void sha3Func (sqlite3_context *context, int argc, sqlite3_value **argv)
static void sha3_step_vformat (SHA3Context *p, const char *zFormat,...)
static void sha3UpdateFromValue (SHA3Context *p, sqlite3_value *pVal)
static void sha3QueryFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static void sha3AggStep (sqlite3_context *context, int argc, sqlite3_value **argv)
static void sha3AggFinal (sqlite3_context *context)
int sqlite3_shathree_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static void SHA1Transform (unsigned int state[5], const unsigned char buffer[64])
static void hash_init (SHA1Context *p)
static void hash_step (SHA1Context *p, const unsigned char *data, unsigned int len)
static void hash_step_vformat (SHA1Context *p, const char *zFormat,...)
static void hash_finish (SHA1Context *p, char *zOut, int bAsBinary)
static void sha1Func (sqlite3_context *context, int argc, sqlite3_value **argv)
static void sha1QueryFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
int sqlite3_sha_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static int uintCollFunc (void *notUsed, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
int sqlite3_uint_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static void decimal_clear (Decimal *p)
static void decimal_free (Decimal *p)
static DecimaldecimalNewFromText (const char *zIn, int n)
static DecimaldecimalFromDouble (double)
static Decimaldecimal_new (sqlite3_context *pCtx, sqlite3_value *pIn, int bTextOnly)
static void decimal_result (sqlite3_context *pCtx, Decimal *p)
static void decimal_result_sci (sqlite3_context *pCtx, Decimal *p)
static int decimal_cmp (const Decimal *pA, const Decimal *pB)
static void decimalCmpFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static void decimal_expand (Decimal *p, int nDigit, int nFrac)
static void decimal_add (Decimal *pA, Decimal *pB)
static void decimalMul (Decimal *pA, Decimal *pB)
static DecimaldecimalPow2 (int N)
static void decimalFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static int decimalCollFunc (void *notUsed, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
static void decimalAddFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static void decimalSubFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static void decimalSumStep (sqlite3_context *context, int argc, sqlite3_value **argv)
static void decimalSumInverse (sqlite3_context *context, int argc, sqlite3_value **argv)
static void decimalSumValue (sqlite3_context *context)
static void decimalSumFinalize (sqlite3_context *context)
static void decimalMulFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static void decimalPow2Func (sqlite3_context *context, int argc, sqlite3_value **argv)
int sqlite3_decimal_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static int percentIsInfinity (double r)
static int percentSameValue (double a, double b)
static int percentBinarySearch (Percentile *p, double y, int bExact)
static void percentError (sqlite3_context *pCtx, const char *zFormat,...)
static void percentStep (sqlite3_context *pCtx, int argc, sqlite3_value **argv)
static void percentSort (double *a, unsigned int n)
static void percentInverse (sqlite3_context *pCtx, int argc, sqlite3_value **argv)
static void percentCompute (sqlite3_context *pCtx, int bIsFinal)
static void percentFinal (sqlite3_context *pCtx)
static void percentValue (sqlite3_context *pCtx)
int sqlite3_percentile_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static char * toBase64 (u8 *pIn, int nbIn, char *pOut)
static char * skipNonB64 (char *s, int nc)
static u8fromBase64 (char *pIn, int ncIn, u8 *pOut)
static void base64 (sqlite3_context *context, int na, sqlite3_value *av[])
int sqlite3_base64_init (sqlite3 *db, char **pzErr, const sqlite3_api_routines *pApi)
static char * skipNonB85 (char *s, int nc)
static char * putcs (char *pc, char *s)
static char * toBase85 (u8 *pIn, int nbIn, char *pOut, char *pSep)
static u8fromBase85 (char *pIn, int ncIn, u8 *pOut)
static void base85 (sqlite3_context *context, int na, sqlite3_value *av[])
int sqlite3_base85_init (sqlite3 *db, char **pzErr, const sqlite3_api_routines *pApi)
static void ieee754func (sqlite3_context *context, int argc, sqlite3_value **argv)
static void ieee754func_from_blob (sqlite3_context *context, int argc, sqlite3_value **argv)
static void ieee754func_to_blob (sqlite3_context *context, int argc, sqlite3_value **argv)
static void ieee754inc (sqlite3_context *context, int argc, sqlite3_value **argv)
int sqlite3_ieee_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static sqlite3_int64 genSeqMember (sqlite3_int64 smBase, sqlite3_int64 smStep, sqlite3_uint64 ix)
static void setupSequence (SequenceSpec *pss)
static int progressSequence (SequenceSpec *pss)
static int seriesConnect (sqlite3 *db, void *pUnused, int argcUnused, const char *const *argvUnused, sqlite3_vtab **ppVtab, char **pzErrUnused)
static int seriesDisconnect (sqlite3_vtab *pVtab)
static int seriesOpen (sqlite3_vtab *pUnused, sqlite3_vtab_cursor **ppCursor)
static int seriesClose (sqlite3_vtab_cursor *cur)
static int seriesNext (sqlite3_vtab_cursor *cur)
static int seriesColumn (sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
static int seriesRowid (sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid)
static int seriesEof (sqlite3_vtab_cursor *cur)
static int seriesFilter (sqlite3_vtab_cursor *pVtabCursor, int idxNum, const char *idxStrUnused, int argc, sqlite3_value **argv)
static int seriesBestIndex (sqlite3_vtab *pVTab, sqlite3_index_info *pIdxInfo)
int sqlite3_series_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static void re_add_state (ReStateSet *pSet, int newState)
static unsigned re_next_char (ReInput *p)
static unsigned re_next_char_nocase (ReInput *p)
static int re_word_char (int c)
static int re_digit_char (int c)
static int re_space_char (int c)
static int sqlite3re_match (ReCompiled *pRe, const unsigned char *zIn, int nIn)
static int re_resize (ReCompiled *p, int N)
static int re_insert (ReCompiled *p, int iBefore, int op, int arg)
static int re_append (ReCompiled *p, int op, int arg)
static void re_copy (ReCompiled *p, int iStart, int N)
static int re_hex (int c, int *pV)
static unsigned re_esc_char (ReCompiled *p)
static const char * re_subcompile_string (ReCompiled *)
static unsigned char rePeek (ReCompiled *p)
static const char * re_subcompile_re (ReCompiled *p)
static void sqlite3re_free (void *p)
static const char * sqlite3re_compile (ReCompiled **ppRe, const char *zIn, int noCase)
static void re_sql_func (sqlite3_context *context, int argc, sqlite3_value **argv)
int sqlite3_regexp_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static void readFileContents (sqlite3_context *ctx, const char *zName)
static void readfileFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static void ctxErrorMsg (sqlite3_context *ctx, const char *zFmt,...)
static int fileStat (const char *zPath, struct stat *pStatBuf)
static int fileLinkStat (const char *zPath, struct stat *pStatBuf)
static int makeDirectory (const char *zFile)
static int writeFile (sqlite3_context *pCtx, const char *zFile, sqlite3_value *pData, mode_t mode, sqlite3_int64 mtime)
static void writefileFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static void lsModeFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static int fsdirConnect (sqlite3 *db, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVtab, char **pzErr)
static int fsdirDisconnect (sqlite3_vtab *pVtab)
static int fsdirOpen (sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor)
static void fsdirResetCursor (fsdir_cursor *pCur)
static int fsdirClose (sqlite3_vtab_cursor *cur)
static void fsdirSetErrmsg (fsdir_cursor *pCur, const char *zFmt,...)
static int fsdirNext (sqlite3_vtab_cursor *cur)
static int fsdirColumn (sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
static int fsdirRowid (sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid)
static int fsdirEof (sqlite3_vtab_cursor *cur)
static int fsdirFilter (sqlite3_vtab_cursor *cur, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
static int fsdirBestIndex (sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo)
static int fsdirRegister (sqlite3 *db)
int sqlite3_fileio_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static int completionConnect (sqlite3 *db, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVtab, char **pzErr)
static int completionDisconnect (sqlite3_vtab *pVtab)
static int completionOpen (sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor)
static void completionCursorReset (completion_cursor *pCur)
static int completionClose (sqlite3_vtab_cursor *cur)
static int completionNext (sqlite3_vtab_cursor *cur)
static int completionColumn (sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
static int completionRowid (sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid)
static int completionEof (sqlite3_vtab_cursor *cur)
static int completionFilter (sqlite3_vtab_cursor *pVtabCursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
static int completionBestIndex (sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo)
int sqlite3CompletionVtabInit (sqlite3 *db)
int sqlite3_completion_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static int apndClose (sqlite3_file *)
static int apndRead (sqlite3_file *, void *, int iAmt, sqlite3_int64 iOfst)
static int apndWrite (sqlite3_file *, const void *, int iAmt, sqlite3_int64 iOfst)
static int apndTruncate (sqlite3_file *, sqlite3_int64 size)
static int apndSync (sqlite3_file *, int flags)
static int apndFileSize (sqlite3_file *, sqlite3_int64 *pSize)
static int apndLock (sqlite3_file *, int)
static int apndUnlock (sqlite3_file *, int)
static int apndCheckReservedLock (sqlite3_file *, int *pResOut)
static int apndFileControl (sqlite3_file *, int op, void *pArg)
static int apndSectorSize (sqlite3_file *)
static int apndDeviceCharacteristics (sqlite3_file *)
static int apndShmMap (sqlite3_file *, int iPg, int pgsz, int, void volatile **)
static int apndShmLock (sqlite3_file *, int offset, int n, int flags)
static void apndShmBarrier (sqlite3_file *)
static int apndShmUnmap (sqlite3_file *, int deleteFlag)
static int apndFetch (sqlite3_file *, sqlite3_int64 iOfst, int iAmt, void **pp)
static int apndUnfetch (sqlite3_file *, sqlite3_int64 iOfst, void *p)
static int apndOpen (sqlite3_vfs *, const char *, sqlite3_file *, int, int *)
static int apndDelete (sqlite3_vfs *, const char *zName, int syncDir)
static int apndAccess (sqlite3_vfs *, const char *zName, int flags, int *)
static int apndFullPathname (sqlite3_vfs *, const char *zName, int, char *zOut)
static void * apndDlOpen (sqlite3_vfs *, const char *zFilename)
static void apndDlError (sqlite3_vfs *, int nByte, char *zErrMsg)
static void apndDlClose (sqlite3_vfs *, void *)
static int apndRandomness (sqlite3_vfs *, int nByte, char *zOut)
static int apndSleep (sqlite3_vfs *, int microseconds)
static int apndCurrentTime (sqlite3_vfs *, double *)
static int apndGetLastError (sqlite3_vfs *, int, char *)
static int apndCurrentTimeInt64 (sqlite3_vfs *, sqlite3_int64 *)
static int apndSetSystemCall (sqlite3_vfs *, const char *, sqlite3_syscall_ptr)
static sqlite3_syscall_ptr apndGetSystemCall (sqlite3_vfs *, const char *z)
static const char * apndNextSystemCall (sqlite3_vfs *, const char *zName)
static int apndWriteMark (ApndFile *paf, sqlite3_file *pFile, sqlite_int64 iWriteEnd)
static sqlite3_int64 apndReadMark (sqlite3_int64 sz, sqlite3_file *pFile)
static int apndIsAppendvfsDatabase (sqlite3_int64 sz, sqlite3_file *pFile)
static int apndIsOrdinaryDatabaseFile (sqlite3_int64 sz, sqlite3_file *pFile)
int sqlite3_appendvfs_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
sqlite3expertsqlite3_expert_new (sqlite3 *db, char **pzErr)
int sqlite3_expert_config (sqlite3expert *p, int op,...)
int sqlite3_expert_sql (sqlite3expert *p, const char *zSql, char **pzErr)
int sqlite3_expert_analyze (sqlite3expert *p, char **pzErr)
int sqlite3_expert_count (sqlite3expert *)
const char * sqlite3_expert_report (sqlite3expert *, int iStmt, int eReport)
void sqlite3_expert_destroy (sqlite3expert *)
static void * idxMalloc (int *pRc, int nByte)
static void idxHashInit (IdxHash *pHash)
static void idxHashClear (IdxHash *pHash)
static int idxHashString (const char *z, int n)
static int idxHashAdd (int *pRc, IdxHash *pHash, const char *zKey, const char *zVal)
static IdxHashEntryidxHashFind (IdxHash *pHash, const char *zKey, int nKey)
static const char * idxHashSearch (IdxHash *pHash, const char *zKey, int nKey)
static IdxConstraintidxNewConstraint (int *pRc, const char *zColl)
static void idxDatabaseError (sqlite3 *db, char **pzErrmsg)
static int idxPrepareStmt (sqlite3 *db, sqlite3_stmt **ppStmt, char **pzErrmsg, const char *zSql)
static int idxPrintfPrepareStmt (sqlite3 *db, sqlite3_stmt **ppStmt, char **pzErrmsg, const char *zFmt,...)
static char * expertDequote (const char *zIn)
static int expertConnect (sqlite3 *db, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVtab, char **pzErr)
static int expertDisconnect (sqlite3_vtab *pVtab)
static int expertBestIndex (sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo)
static int expertUpdate (sqlite3_vtab *pVtab, int nData, sqlite3_value **azData, sqlite_int64 *pRowid)
static int expertOpen (sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor)
static int expertClose (sqlite3_vtab_cursor *cur)
static int expertEof (sqlite3_vtab_cursor *cur)
static int expertNext (sqlite3_vtab_cursor *cur)
static int expertRowid (sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid)
static int expertColumn (sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
static int expertFilter (sqlite3_vtab_cursor *cur, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
static int idxRegisterVtab (sqlite3expert *p)
static void idxFinalize (int *pRc, sqlite3_stmt *pStmt)
static int idxGetTableInfo (sqlite3 *db, const char *zTab, IdxTable **ppOut, char **pzErrmsg)
static char * idxAppendText (int *pRc, char *zIn, const char *zFmt,...)
static int idxIdentifierRequiresQuotes (const char *zId)
static char * idxAppendColDefn (int *pRc, char *zIn, IdxTable *pTab, IdxConstraint *pCons)
static int idxFindCompatible (int *pRc, sqlite3 *dbm, IdxScan *pScan, IdxConstraint *pEq, IdxConstraint *pTail)
static int countNonzeros (void *pCount, int nc, char *azResults[], char *azColumns[])
static int idxCreateFromCons (sqlite3expert *p, IdxScan *pScan, IdxConstraint *pEq, IdxConstraint *pTail)
static int idxFindConstraint (IdxConstraint *pList, IdxConstraint *p)
static int idxCreateFromWhere (sqlite3expert *p, IdxScan *pScan, IdxConstraint *pTail)
static int idxCreateCandidates (sqlite3expert *p)
static void idxConstraintFree (IdxConstraint *pConstraint)
static void idxScanFree (IdxScan *pScan, IdxScan *pLast)
static void idxStatementFree (IdxStatement *pStatement, IdxStatement *pLast)
static void idxTableFree (IdxTable *pTab)
static void idxWriteFree (IdxWrite *pTab)
static int idxFindIndexes (sqlite3expert *p, char **pzErr)
static int idxAuthCallback (void *pCtx, int eOp, const char *z3, const char *z4, const char *zDb, const char *zTrigger)
static int idxProcessOneTrigger (sqlite3expert *p, IdxWrite *pWrite, char **pzErr)
static int idxProcessTriggers (sqlite3expert *p, char **pzErr)
static int expertDbContainsObject (sqlite3 *db, const char *zTab, int *pbContains)
static int expertSchemaSql (sqlite3 *db, const char *zSql, char **pzErr)
static int idxCreateVtabSchema (sqlite3expert *p, char **pzErrmsg)
static void idxSampleFunc (sqlite3_context *pCtx, int argc, sqlite3_value **argv)
static void idxRemFunc (sqlite3_context *pCtx, int argc, sqlite3_value **argv)
static int idxLargestIndex (sqlite3 *db, int *pnMax, char **pzErr)
static int idxPopulateOneStat1 (sqlite3expert *p, sqlite3_stmt *pIndexXInfo, sqlite3_stmt *pWriteStat, const char *zTab, const char *zIdx, char **pzErr)
static int idxBuildSampleTable (sqlite3expert *p, const char *zTab)
static int idxPopulateStat1 (sqlite3expert *p, char **pzErr)
int dummyCompare (void *up1, int up2, const void *up3, int up4, const void *up5)
void useDummyCS (void *up1, sqlite3 *db, int etr, const char *zName)
void dummyUDF (sqlite3_context *up1, int up2, sqlite3_value **up3)
void dummyUDFvalue (sqlite3_context *up1)
int registerUDFs (sqlite3 *dbSrc, sqlite3 *dbDst)
int sqlite3_intck_open (sqlite3 *db, const char *zDb, sqlite3_intck **ppOut)
void sqlite3_intck_close (sqlite3_intck *pCk)
int sqlite3_intck_step (sqlite3_intck *pCk)
const char * sqlite3_intck_message (sqlite3_intck *pCk)
int sqlite3_intck_unlock (sqlite3_intck *pCk)
int sqlite3_intck_error (sqlite3_intck *pCk, const char **pzErr)
const char * sqlite3_intck_test_sql (sqlite3_intck *pCk, const char *zObj)
static void intckSaveErrmsg (sqlite3_intck *p)
static sqlite3_stmtintckPrepare (sqlite3_intck *p, const char *zSql)
static sqlite3_stmtintckPrepareFmt (sqlite3_intck *p, const char *zFmt,...)
static void intckFinalize (sqlite3_intck *p, sqlite3_stmt *pStmt)
static int intckStep (sqlite3_intck *p, sqlite3_stmt *pStmt)
static void intckExec (sqlite3_intck *p, const char *zSql)
static char * intckMprintf (sqlite3_intck *p, const char *zFmt,...)
static void intckSaveKey (sqlite3_intck *p)
static void intckFindObject (sqlite3_intck *p)
static int intckGetToken (const char *z)
static int intckIsSpace (char c)
static const char * intckParseCreateIndex (const char *z, int iCol, int *pnByte)
static void intckParseCreateIndexFunc (sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
static int intckGetAutoIndex (sqlite3_intck *p)
static int intckIsIndex (sqlite3_intck *p, const char *zObj)
static char * intckCheckObjectSql (sqlite3_intck *p, const char *zObj, const char *zPrev, int *pnKeyVal)
static void stmtrandFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
int sqlite3_stmtrand_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
static int vfstraceClose (sqlite3_file *)
static int vfstraceRead (sqlite3_file *, void *, int iAmt, sqlite3_int64 iOfst)
static int vfstraceWrite (sqlite3_file *, const void *, int iAmt, sqlite3_int64)
static int vfstraceTruncate (sqlite3_file *, sqlite3_int64 size)
static int vfstraceSync (sqlite3_file *, int flags)
static int vfstraceFileSize (sqlite3_file *, sqlite3_int64 *pSize)
static int vfstraceLock (sqlite3_file *, int)
static int vfstraceUnlock (sqlite3_file *, int)
static int vfstraceCheckReservedLock (sqlite3_file *, int *)
static int vfstraceFileControl (sqlite3_file *, int op, void *pArg)
static int vfstraceSectorSize (sqlite3_file *)
static int vfstraceDeviceCharacteristics (sqlite3_file *)
static int vfstraceShmLock (sqlite3_file *, int, int, int)
static int vfstraceShmMap (sqlite3_file *, int, int, int, void volatile **)
static void vfstraceShmBarrier (sqlite3_file *)
static int vfstraceShmUnmap (sqlite3_file *, int)
static int vfstraceOpen (sqlite3_vfs *, const char *, sqlite3_file *, int, int *)
static int vfstraceDelete (sqlite3_vfs *, const char *zName, int syncDir)
static int vfstraceAccess (sqlite3_vfs *, const char *zName, int flags, int *)
static int vfstraceFullPathname (sqlite3_vfs *, const char *zName, int, char *)
static void * vfstraceDlOpen (sqlite3_vfs *, const char *zFilename)
static void vfstraceDlError (sqlite3_vfs *, int nByte, char *zErrMsg)
static void vfstraceDlClose (sqlite3_vfs *, void *)
static int vfstraceRandomness (sqlite3_vfs *, int nByte, char *zOut)
static int vfstraceSleep (sqlite3_vfs *, int microseconds)
static int vfstraceCurrentTime (sqlite3_vfs *, double *)
static int vfstraceGetLastError (sqlite3_vfs *, int, char *)
static int vfstraceCurrentTimeInt64 (sqlite3_vfs *, sqlite3_int64 *)
static int vfstraceSetSystemCall (sqlite3_vfs *, const char *, sqlite3_syscall_ptr)
static sqlite3_syscall_ptr vfstraceGetSystemCall (sqlite3_vfs *, const char *)
static const char * vfstraceNextSystemCall (sqlite3_vfs *, const char *zName)
static const char * fileTail (const char *z)
static void vfstrace_printf (vfstrace_info *pInfo, const char *zFormat,...)
static const char * vfstrace_errcode_name (int rc)
static void vfstrace_print_errcode (vfstrace_info *pInfo, const char *zFormat, int rc)
static void strappend (char *z, int *pI, const char *zAppend)
static void vfstraceOnOff (vfstrace_info *pInfo, unsigned int mMask)
static const char * lockName (int eLock)
static int vfstraceFetch (sqlite3_file *pFile, i64 iOff, int nAmt, void **pptr)
static int vfstraceUnfetch (sqlite3_file *pFile, i64 iOff, void *ptr)
int vfstrace_register (const char *zTraceName, const char *zOldVfsName, int(*xOut)(const char *, void *), void *pOutArg, int makeDefault)
void vfstrace_unregister (const char *zTraceName)
static void shellLog (void *pArg, int iErrCode, const char *zMsg)
static void shellPutsFunc (sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
static void failIfSafeMode (ShellState *p, const char *zErrMsg,...)
static void editFunc (sqlite3_context *context, int argc, sqlite3_value **argv)
static void outputModePush (ShellState *p)
static void outputModePop (ShellState *p)
static void setCrlfMode (ShellState *p)
static void output_hex_blob (FILE *out, const void *pBlob, int nBlob)
static void output_quoted_string (ShellState *p, const char *zInX)
static void output_quoted_escaped_string (ShellState *p, const char *z)
static const char * anyOfInStr (const char *s, const char *zAny, size_t ns)
const char * zSkipValidUtf8 (const char *z, int nAccept, long ccm)
static void output_c_string (FILE *out, const char *z)
static void output_json_string (FILE *out, const char *z, i64 n)
static const char * escapeOutput (ShellState *p, const char *zInX, char **ppFree)
static void output_html_string (FILE *out, const char *z)
static void output_csv (ShellState *p, const char *z, int bSep)
static void interrupt_handler (int NotUsed)
static int safeModeAuth (void *pClientData, int op, const char *zA1, const char *zA2, const char *zA3, const char *zA4)
static int shellAuth (void *pClientData, int op, const char *zA1, const char *zA2, const char *zA3, const char *zA4)
static void printSchemaLine (FILE *out, const char *z, const char *zTail)
static void printSchemaLineN (FILE *out, char *z, int n, const char *zTail)
static int wsToEol (const char *z)
static void eqp_append (ShellState *p, int iEqpId, int p2, const char *zText)
static void eqp_reset (ShellState *p)
static EQPGraphRoweqp_next_row (ShellState *p, int iEqpId, EQPGraphRow *pOld)
static void eqp_render_level (ShellState *p, int iEqpId)
static void eqp_render (ShellState *p, i64 nCycle)
static int progress_handler (void *pClientData)
static void print_dashes (FILE *out, int N)
static void print_row_separator (ShellState *p, int nArg, const char *zSep)
static int shell_callback (void *pArg, int nArg, char **azArg, char **azCol, int *aiType)
static int callback (void *pArg, int nArg, char **azArg, char **azCol)
static int captureOutputCallback (void *pArg, int nArg, char **azArg, char **az)
static void createSelftestTable (ShellState *p)
static void set_table_name (ShellState *p, const char *zName)
static char * shell_error_context (const char *zSql, sqlite3 *db)
static int run_table_dump_query (ShellState *p, const char *zSelect)
static char * save_err_msg (sqlite3 *db, const char *zPhase, int rc, const char *zSql)
static void displayStatLine (FILE *out, char *zLabel, char *zFormat, int iStatusCtrl, int bReset)
static int display_stats (sqlite3 *db, ShellState *pArg, int bReset)
static int str_in_array (const char *zStr, const char **azArray)
static void explain_data_prepare (ShellState *p, sqlite3_stmt *pSql)
static void explain_data_delete (ShellState *p)
static void exec_prepared_stmt (ShellState *, sqlite3_stmt *)
static void display_scanstats (sqlite3 *db, ShellState *pArg)
static void disable_debug_trace_modes (void)
static void restore_debug_trace_modes (void)
static void bind_table_init (ShellState *p)
static void bind_prepared_stmt (ShellState *pArg, sqlite3_stmt *pStmt)
static void print_box_line (FILE *out, int N)
static void print_box_row_separator (ShellState *p, int nArg, const char *zSep1, const char *zSep2, const char *zSep3)
static char * translateForDisplayAndDup (ShellState *p, const unsigned char *z, const unsigned char **pzTail, int mxWidth, u8 bWordWrap)
static int needUnistr (const unsigned char *z)
static char * quoted_column (sqlite3_stmt *pStmt, int i)
static void exec_prepared_stmt_columnar (ShellState *p, sqlite3_stmt *pStmt)
static int expertHandleSQL (ShellState *pState, const char *zSql, char **pzErr)
static int expertFinish (ShellState *pState, int bCancel, char **pzErr)
static int expertDotCommand (ShellState *pState, char **azArg, int nArg)
static int shell_exec (ShellState *pArg, const char *zSql, char **pzErrMsg)
static void freeColumnList (char **azCol)
static char ** tableColumnList (ShellState *p, const char *zTab)
static void toggleSelectOrder (sqlite3 *db)
static int dump_callback (void *pArg, int nArg, char **azArg, char **azNotUsed)
static int run_schema_dump_query (ShellState *p, const char *zQuery)
static int showHelp (FILE *out, const char *zPattern)
static int process_input (ShellState *p)
static char * readFile (const char *zName, int *pnByte)
int deduceDatabaseType (const char *zName, int dfltZip)
static unsigned char * readHexDb (ShellState *p, int *pnData)
static void shellUSleepFunc (sqlite3_context *context, int argcUnused, sqlite3_value **argv)
static void shellModuleSchema (sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
static void open_db (ShellState *p, int openFlags)
void close_db (sqlite3 *db)
static void resolve_backslashes (char *z)
static int booleanValue (const char *zArg)
static void setOrClearFlag (ShellState *p, unsigned mFlag, const char *zArg)
static void output_file_close (FILE *f)
static FILE * output_file_open (const char *zFile)
static int sql_trace_callback (unsigned mType, void *pArg, void *pP, void *pX)
static void test_breakpoint (void)
static void import_cleanup (ImportCtx *p)
static void import_append_char (ImportCtx *p, int c)
static char * csv_read_one_field (ImportCtx *p)
static char * ascii_read_one_field (ImportCtx *p)
static void tryToCloneData (ShellState *p, sqlite3 *newDb, const char *zTable)
static void tryToCloneSchema (ShellState *p, sqlite3 *newDb, const char *zWhere, void(*xForEach)(ShellState *, sqlite3 *, const char *))
static void tryToClone (ShellState *p, const char *zNewDb)
static void output_redir (ShellState *p, FILE *pfNew)
static void output_reset (ShellState *p)
static int db_int (sqlite3 *db, const char *zSql,...)
static int shell_dbtotxt_command (ShellState *p, int nArg, char **azArg)
static void shellEmitError (const char *zErr)
static int shellDatabaseError (sqlite3 *db)
static int testcase_glob (const char *zGlob, const char *z)
static int optionMatch (const char *zStr, const char *zOpt)
int shellDeleteFile (const char *zFilename)
static void clearTempFile (ShellState *p)
static void newTempFile (ShellState *p, const char *zSuffix)
static void shellFkeyCollateClause (sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
static int lintFkeyIndexes (ShellState *pState, char **azArg, int nArg)
static int lintDotCommand (ShellState *pState, char **azArg, int nArg)
static void shellPrepare (sqlite3 *db, int *pRc, const char *zSql, sqlite3_stmt **ppStmt)
static void shellPreparePrintf (sqlite3 *db, int *pRc, sqlite3_stmt **ppStmt, const char *zFmt,...)
static void shellFinalize (int *pRc, sqlite3_stmt *pStmt)
void shellReset (int *pRc, sqlite3_stmt *pStmt)
static int intckDatabaseCmd (ShellState *pState, i64 nStepPerUnlock)
static void rc_err_oom_die (int rc)
static char * zAutoColumn (const char *zColNew, sqlite3 **pDb, char **pzRenamed)
static int outputDumpWarning (ShellState *p, const char *zLike)
static int faultsim_callback (int iArg)
static int do_meta_command (char *zLine, ShellState *p)
static QuickScanState quickscan (char *zLine, QuickScanState qss, t_DynaPromptRef pst)
static int line_is_command_terminator (char *zLine)
static int line_is_complete (char *zSql, int nSql)
static int doAutoDetectRestore (ShellState *p, const char *zSql)
static int runOneSqlLine (ShellState *p, char *zSql, FILE *in, int startline)
static void echo_group_input (ShellState *p, const char *zDo)
static char * find_home_dir (int clearFlag)
static char * find_xdg_config (void)
static void process_sqliterc (ShellState *p, const char *sqliterc_override)
static void usage (int showDetail)
static void verify_uninitialized (void)
static void main_init (ShellState *data)
static void printBold (const char *zText)
static char * cmdline_option_value (int argc, char **argv, int i)
static void sayAbnormalExit (void)
static int vfstraceOut (const char *z, void *pArg)
int main (int argc, char **argv)

Variables

static int enableTimer = 0
static struct rusage sBegin
static sqlite3_int64 iBegin
static int bail_on_error = 0
static int stdin_is_interactive = 1
static int stdout_is_console = 1
static sqlite3globalDb = 0
static volatile int seenInterrupt = 0
static char * Argv0
static char mainPrompt [128]
static char continuePrompt [128]
static struct DynaPrompt dynPrompt = { {0}, {0}, 0, 0 }
struct { 
unsigned char w
int iFirst
aUWidth []
static sqlite3_mem_methods memtraceBase
static FILE * memtraceOut
static sqlite3_mem_methods ersaztMethods
static sqlite3_pcache_methods2 pcacheBase
static FILE * pcachetraceOut
static sqlite3_pcache_methods2 ersaztPcacheMethods
static const PercentileFunc aPercentFunc []
static const u8 b64DigitValues [128]
static const char b64Numerals [64+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
static u8 b85_cOffset [] = { 0, '#', 0, '*'-4, 0 }
static sqlite3_module seriesModule
static sqlite3_module completionModule
static void(*)(void) apndDlSym (sqlite3_vfs *pVfs, void *p, const char *zSym)
static sqlite3_vfs apnd_vfs
static const sqlite3_io_methods apnd_io_methods
static const char apvfsSqliteHdr [] = "SQLite format 3"
static void(*)(void) vfstraceDlSym (sqlite3_vfs *, void *, const char *zSymbol)
static const char * shell_EscModeNames [] = { "ascii", "symbol", "off" }
static const char * modeDescr []
static const char needCsvQuote []
static unsigned int savedSelectTrace
static unsigned int savedWhereTrace
static const char * azHelp []
static const char * zCOL_DB = ":memory:"
struct { 
int iId
int iErr
int iCnt
int iInterval
int eVerbose
int nHit
int nRepeat
int nSkip
faultsim_state = {-1, 0, 0, 0, 0, 0, 0, 0}
static const char zOptions []

Data Structure Documentation

◆ DynaPrompt

struct DynaPrompt
Data Fields
char acAwait[2]
char dynamicPrompt[128]
int inParenLevel
char * zScannerAwaits

◆ ShellText

struct ShellText
Data Fields
int n
int nAlloc
char * z

◆ SHA3Context

struct SHA3Context
Data Fields
unsigned iSize
unsigned ixMask
unsigned nLoaded
unsigned nRate
union SHA3Context.u u

◆ SHA1Context

struct SHA1Context
Data Fields
unsigned char buffer[64]
unsigned int count[2]
unsigned int state[5]

◆ Decimal

struct Decimal
Data Fields
signed char * a
char isInit
char isNull
int nDigit
int nFrac
char oom
char sign

◆ Percentile

struct Percentile
Data Fields
double * a
char bKeepSorted
char bPctValid
char bSorted
unsigned nAlloc
unsigned nUsed
double rPct

◆ PercentileFunc

struct PercentileFunc
Data Fields
char bDiscrete
char mxFrac
char nArg
const char * zName

◆ SequenceSpec

struct SequenceSpec
Data Fields
sqlite3_int64 iBase
sqlite3_int64 iOBase
sqlite3_int64 iOTerm
u8 isNotEOF
u8 isReversing
sqlite3_int64 iStep
sqlite3_int64 iTerm
sqlite3_int64 iValueNow
sqlite3_uint64 uSeqIndexMax
sqlite3_uint64 uSeqIndexNow

◆ series_cursor

struct series_cursor
Collaboration diagram for series_cursor:
Data Fields
sqlite3_vtab_cursor base
SequenceSpec ss

◆ ReStateSet

struct ReStateSet
Data Fields
ReStateNumber * aState
unsigned nState

◆ ReInput

struct ReInput
Data Fields
int i
int mx
const unsigned char * z

◆ ReCompiled

struct ReCompiled
Collaboration diagram for ReCompiled:
Data Fields
int * aArg
char * aOp
unsigned nAlloc
int nInit
unsigned nState
ReInput sIn
unsigned(*)(ReInput *) xNextChar
const char * zErr
unsigned char zInit[12]

◆ FsdirLevel

struct FsdirLevel
Data Fields
DIR * pDir
char * zDir

◆ fsdir_cursor

struct fsdir_cursor
Collaboration diagram for fsdir_cursor:
Data Fields
FsdirLevel * aLvl
sqlite3_vtab_cursor base
int iLvl
sqlite3_int64 iRowid
int nBase
int nLvl
struct stat sStat
const char * zBase
char * zPath

◆ fsdir_tab

struct fsdir_tab
Collaboration diagram for fsdir_tab:
Data Fields
sqlite3_vtab base

◆ completion_vtab

struct completion_vtab
Collaboration diagram for completion_vtab:
Data Fields
sqlite3_vtab base
sqlite3 * db

◆ completion_cursor

struct completion_cursor
Collaboration diagram for completion_cursor:
Data Fields
sqlite3_vtab_cursor base
sqlite3 * db
int ePhase
sqlite3_int64 iRowid
int j
int nLine
int nPrefix
sqlite3_stmt * pStmt
int szRow
const char * zCurrentRow
char * zLine
char * zPrefix

◆ ApndFile

struct ApndFile
Collaboration diagram for ApndFile:
Data Fields
sqlite3_file base
sqlite3_int64 iMark
sqlite3_int64 iPgOne

◆ IdxConstraint

struct IdxConstraint
Collaboration diagram for IdxConstraint:
Data Fields
int bDesc
int bFlag
int bRange
int iCol
IdxConstraint * pLink
IdxConstraint * pNext
char * zColl

◆ IdxScan

struct IdxScan
Collaboration diagram for IdxScan:
Data Fields
i64 covering
int iDb
IdxConstraint * pEq
IdxScan * pNextScan
IdxConstraint * pOrder
IdxConstraint * pRange
IdxTable * pTab

◆ IdxColumn

struct IdxColumn
Data Fields
int iPk
char * zColl
char * zName

◆ IdxTable

struct IdxTable
Collaboration diagram for IdxTable:
Data Fields
IdxColumn * aCol
int nCol
IdxTable * pNext
char * zName

◆ IdxWrite

struct IdxWrite
Collaboration diagram for IdxWrite:
Data Fields
int eOp
IdxWrite * pNext
IdxTable * pTab

◆ IdxStatement

struct IdxStatement
Collaboration diagram for IdxStatement:
Data Fields
int iId
IdxStatement * pNext
char * zEQP
char * zIdx
char * zSql

◆ IdxHashEntry

struct IdxHashEntry
Collaboration diagram for IdxHashEntry:
Data Fields
IdxHashEntry * pHashNext
IdxHashEntry * pNext
char * zKey
char * zVal
char * zVal2

◆ IdxHash

struct IdxHash
Collaboration diagram for IdxHash:
Data Fields
IdxHashEntry * aHash[1023]
IdxHashEntry * pFirst

◆ sqlite3expert

struct sqlite3expert
Collaboration diagram for sqlite3expert:
Data Fields
int bRun
sqlite3 * db
sqlite3 * dbm
sqlite3 * dbv
IdxHash hIdx
int iSample
IdxScan * pScan
IdxStatement * pStatement
IdxTable * pTable
IdxWrite * pWrite
char ** pzErrmsg
int rc
char * zCandidates

◆ ExpertVtab

struct ExpertVtab
Collaboration diagram for ExpertVtab:
Data Fields
sqlite3_vtab base
sqlite3expert * pExpert
IdxTable * pTab

◆ ExpertCsr

struct ExpertCsr
Collaboration diagram for ExpertCsr:
Data Fields
sqlite3_vtab_cursor base
sqlite3_stmt * pData

◆ IdxSampleCtx

struct IdxSampleCtx
Data Fields
int iTarget
double nRet
double nRow
double target

◆ IdxRemCtx

struct IdxRemCtx
Collaboration diagram for IdxRemCtx:
Data Fields
struct IdxRemSlot aSlot[1]
int nSlot

◆ IdxRemCtx::IdxRemSlot

struct IdxRemCtx::IdxRemSlot
Data Fields
int eType
i64 iVal
int n
int nByte
double rVal
char * z

◆ sqlite3_intck

struct sqlite3_intck
Collaboration diagram for sqlite3_intck:
Data Fields
int bCorruptSchema
sqlite3 * db
int nKeyVal
sqlite3_stmt * pCheck
int rc
const char * zDb
char * zErr
char * zKey
char * zMessage
char * zObj
char * zTestSql

◆ Stmtrand

struct Stmtrand
Data Fields
unsigned int x
unsigned int y

◆ vfstrace_info

struct vfstrace_info
Collaboration diagram for vfstrace_info:
Data Fields
u8 bOn
unsigned int mTrace
void * pOutArg
sqlite3_vfs * pRootVfs
sqlite3_vfs * pTraceVfs
int(*)(const char *, void *) xOut
const char * zVfsName

◆ vfstrace_file

struct vfstrace_file
Collaboration diagram for vfstrace_file:
Data Fields
sqlite3_file base
vfstrace_info * pInfo
sqlite3_file * pReal
const char * zFName

◆ ExpertInfo

struct ExpertInfo
Collaboration diagram for ExpertInfo:
Data Fields
int bVerbose
sqlite3expert * pExpert

◆ EQPGraphRow

struct EQPGraphRow
Collaboration diagram for EQPGraphRow:
Data Fields
int iEqpId
int iParentId
EQPGraphRow * pNext
char zText[1]

◆ EQPGraph

struct EQPGraph
Collaboration diagram for EQPGraph:
Data Fields
EQPGraphRow * pLast
EQPGraphRow * pRow
char zPrefix[100]

◆ ColModeOpts

struct ColModeOpts
Data Fields
u8 bQuote
u8 bWordWrap
int iWrap

◆ ShellState

struct ShellState
Collaboration diagram for ShellState:
Data Fields
struct AuxDb aAuxDb[5]
int * actualWidth
int * aiIndent
u8 autoEQP
u8 autoEQPtest
u8 autoEQPtrace
u8 autoExplain
u8 bSafeMode
u8 bSafeModePersist
int cMode
ColModeOpts cmOpts
int cnt
char colSeparator[20]
char colSepPrior[20]
int * colWidth
u8 crlfMode
sqlite3 * db
u8 doXdgOpen
u8 eEscMode
u8 eRestoreState
u8 eTraceType
ExpertInfo expert
unsigned flgProgress
int iIndent
FILE * in
int inputNesting
int lineno
unsigned mEqpLines
int mode
int modePrior
unsigned mxProgress
int nCheck
u8 nEqpLevel
int nErr
int nIndent
int normalMode
unsigned nProgress
char nullValue[20]
int nWidth
int openFlags
u8 openMode
FILE * out
int outCount
char outfile[FILENAME_MAX]
struct AuxDb * pAuxDb[5]
FILE * pLog
unsigned priorShFlgs
sqlite3_stmt * pStmt
char rowSeparator[20]
char rowSepPrior[20]
u8 scanstatsOn
EQPGraph sGraph
unsigned shellFlgs
int showHeader
unsigned statsOn
sqlite3_int64 szMax
FILE * traceOut
int writableSchema
char * zDestTable
char * zNonce
char * zTempFile
char zTestcase[30]

◆ ShellState::AuxDb

struct ShellState::AuxDb
Collaboration diagram for ShellState::AuxDb:
Data Fields
sqlite3 * db
const char * zDbFilename
char * zFreeOnClose

◆ ImportCtx

struct ImportCtx
Data Fields
int bNotFirst
int cColSep
int cRowSep
int cTerm
FILE * in
int n
int nAlloc
int nErr
int nLine
int nRow
int(*)(FILE *) xCloser
char * z
const char * zFile

◆ SHA3Context.u

union SHA3Context.u
Data Fields
u64 s[25]
unsigned char x[1600]

Macro Definition Documentation

◆ _FILE_OFFSET_BITS

#define _FILE_OFFSET_BITS   64

◆ _LARGE_FILE

#define _LARGE_FILE   1

◆ _LARGEFILE_SOURCE

#define _LARGEFILE_SOURCE   1

◆ _SQLITE3_STDIO_H_

#define _SQLITE3_STDIO_H_   1

◆ _SQLITE_INTCK_H

#define _SQLITE_INTCK_H

◆ a

◆ a00

#define a00   (p->u.s[0])

Referenced by KeccakF1600Step().

◆ a01

#define a01   (p->u.s[1])

Referenced by KeccakF1600Step().

◆ a02

#define a02   (p->u.s[2])

Referenced by KeccakF1600Step().

◆ a03

#define a03   (p->u.s[3])

Referenced by KeccakF1600Step().

◆ a04

#define a04   (p->u.s[4])

Referenced by KeccakF1600Step().

◆ a10

#define a10   (p->u.s[5])

Referenced by KeccakF1600Step().

◆ a11

#define a11   (p->u.s[6])

Referenced by KeccakF1600Step().

◆ a12

#define a12   (p->u.s[7])

Referenced by KeccakF1600Step().

◆ a13

#define a13   (p->u.s[8])

Referenced by KeccakF1600Step().

◆ a14

#define a14   (p->u.s[9])

Referenced by KeccakF1600Step().

◆ a20

#define a20   (p->u.s[10])

Referenced by KeccakF1600Step().

◆ a21

#define a21   (p->u.s[11])

Referenced by KeccakF1600Step().

◆ a22

#define a22   (p->u.s[12])

Referenced by KeccakF1600Step().

◆ a23

#define a23   (p->u.s[13])

Referenced by KeccakF1600Step().

◆ a24

#define a24   (p->u.s[14])

Referenced by KeccakF1600Step().

◆ a30

#define a30   (p->u.s[15])

Referenced by KeccakF1600Step().

◆ a31

#define a31   (p->u.s[16])

Referenced by KeccakF1600Step().

◆ a32

#define a32   (p->u.s[17])

Referenced by KeccakF1600Step().

◆ a33

#define a33   (p->u.s[18])

Referenced by KeccakF1600Step().

◆ a34

#define a34   (p->u.s[19])

Referenced by KeccakF1600Step().

◆ a40

#define a40   (p->u.s[20])

Referenced by KeccakF1600Step().

◆ a41

#define a41   (p->u.s[21])

Referenced by KeccakF1600Step().

◆ a42

#define a42   (p->u.s[22])

Referenced by KeccakF1600Step().

◆ a43

#define a43   (p->u.s[23])

Referenced by KeccakF1600Step().

◆ a44

#define a44   (p->u.s[24])

Referenced by KeccakF1600Step().

◆ ALWAYS

◆ APND_ALIGN_MASK

#define APND_ALIGN_MASK   ((sqlite3_int64)(APND_ROUNDUP-1))

◆ APND_MARK_FOS_SZ

#define APND_MARK_FOS_SZ   8

Referenced by apndReadMark(), and apndWriteMark().

◆ APND_MARK_PREFIX

#define APND_MARK_PREFIX   "Start-Of-SQLite3-"

Referenced by apndReadMark(), and apndWriteMark().

◆ APND_MARK_PREFIX_SZ

#define APND_MARK_PREFIX_SZ   17

Referenced by apndReadMark(), and apndWriteMark().

◆ APND_MARK_SIZE

◆ APND_MAX_SIZE

#define APND_MAX_SIZE   (0x40000000)

Referenced by apndWrite().

◆ APND_ROUNDUP

#define APND_ROUNDUP   4096

◆ APND_START_ROUNDUP

#define APND_START_ROUNDUP ( fsz)
Value:
#define APND_ALIGN_MASK
Definition shell.c:9607

Referenced by apndOpen().

◆ ArraySize

◆ AUTOCOLUMN_SEP

#define AUTOCOLUMN_SEP   "_"

Referenced by zAutoColumn().

◆ AUTOEQP_full

#define AUTOEQP_full   3 /* Show full EXPLAIN */

Referenced by do_meta_command(), main(), and shell_exec().

◆ AUTOEQP_off

#define AUTOEQP_off   0 /* Automatic EXPLAIN QUERY PLAN is off */

◆ AUTOEQP_on

#define AUTOEQP_on   1 /* Automatic EQP is on */

Referenced by do_meta_command(), and main().

◆ AUTOEQP_trigger

#define AUTOEQP_trigger   2 /* On and also show plans for triggers */

Referenced by do_meta_command(), and shell_exec().

◆ b

◆ B64_DARK_MAX

#define B64_DARK_MAX   72

Referenced by base64(), and toBase64().

◆ B85_CLASS

#define B85_CLASS ( c)
Value:
(((c)>='#')+((c)>'&')+((c)>='*')+((c)>'z'))
#define c

◆ B85_DARK_MAX

#define B85_DARK_MAX   80

Referenced by toBase85().

◆ B85_DNOS

#define B85_DNOS ( c)
Value:
#define B85_CLASS(c)
Definition shell.c:5516
static u8 b85_cOffset[]
Definition shell.c:5519

Referenced by fromBase85().

◆ BASE64_EXPOSE

#define BASE64_EXPOSE ( db,
pzErr )
Value:
/* Not needed, ..._init() does this. */

◆ BASE64_INIT

#define BASE64_INIT ( db)
Value:
int sqlite3_base64_init(sqlite3 *db, char **pzErr, const sqlite3_api_routines *pApi)
Definition shell.c:5373

◆ BASE85_EXPOSE

#define BASE85_EXPOSE ( db,
pzErr )
Value:
/* Not needed, ..._init() does this. */

◆ BASE85_INIT

#define BASE85_INIT ( db)
Value:
int sqlite3_base85_init(sqlite3 *db, char **pzErr, const sqlite3_api_routines *pApi)
Definition shell.c:5753

◆ base85Numeral

#define base85Numeral ( dn)
Value:
((char)(((dn) < 4)? (char)((dn) + '#') : (char)((dn) - 4 + '*')))
5550# define base85Numeral( dn )\
5551 ((char)(((dn) < 4)? (char)((dn) + '#') : (char)((dn) - 4 + '*')))

Referenced by toBase85().

◆ BEGIN_TIMER

#define BEGIN_TIMER   beginTimer()

Referenced by runOneSqlLine().

◆ blk

#define blk ( i)
Value:
(block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15] \
^block[(i+2)&15]^block[i&15],1))
#define rol(x, k)
Definition shell.c:3231
3237#define blk(i) (block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15] \
3238 ^block[(i+2)&15]^block[i&15],1))

◆ blk0be

#define blk0be ( i)
Value:
block[i]

◆ blk0le

#define blk0le ( i)
Value:
(block[i] = (ror(block[i],8)&0xFF00FF00) \
|(rol(block[i],8)&0x00FF00FF))
#define ror(x, k)
Definition shell.c:3232
3234#define blk0le(i) (block[i] = (ror(block[i],8)&0xFF00FF00) \
3235 |(rol(block[i],8)&0x00FF00FF))

◆ BOX_12

#define BOX_12   "\342\224\224" /* U+2514 '- */

◆ BOX_123

#define BOX_123   "\342\224\234" /* U+251c |- */

◆ BOX_1234

#define BOX_1234   "\342\224\274" /* U+253c -|- */

◆ BOX_124

#define BOX_124   "\342\224\264" /* U+2534 -'- */

◆ BOX_13

#define BOX_13   "\342\224\202" /* U+2502 | */

◆ BOX_134

#define BOX_134   "\342\224\244" /* U+2524 -| */

◆ BOX_14

#define BOX_14   "\342\224\230" /* U+2518 -' */

◆ BOX_23

#define BOX_23   "\342\224\214" /* U+250c ,- */

◆ BOX_234

#define BOX_234   "\342\224\254" /* U+252c -,- */

◆ BOX_24

#define BOX_24   "\342\224\200" /* U+2500 --- */

Referenced by print_box_line().

◆ BOX_34

#define BOX_34   "\342\224\220" /* U+2510 -, */

◆ BX_DV_PROTO

#define BX_DV_PROTO ( c)
Value:
((((u8)(c))<0x80)? (u8)(b64DigitValues[(u8)(c)]) : 0x80)
static const u8 b64DigitValues[128]
Definition shell.c:5173
unsigned char u8
Definition shell.c:124
5195#define BX_DV_PROTO(c) \
5196 ((((u8)(c))<0x80)? (u8)(b64DigitValues[(u8)(c)]) : 0x80)

Referenced by fromBase64(), and skipNonB64().

◆ BX_NUMERAL

#define BX_NUMERAL ( dv)
Value:
(b64Numerals[(u8)(dv)])
static const char b64Numerals[64+1]
Definition shell.c:5193

Referenced by toBase64().

◆ c

#define c   qq[2]

◆ CHAR_BIT

#define CHAR_BIT   8

◆ ColModeOpts_default

#define ColModeOpts_default   { 60, 0, 0 }

Referenced by do_meta_command().

◆ ColModeOpts_default_qbox

#define ColModeOpts_default_qbox   { 60, 1, 0 }

Referenced by do_meta_command().

◆ COMPLETION_COLLATIONS

#define COMPLETION_COLLATIONS   4

◆ COMPLETION_COLUMN_CANDIDATE

#define COMPLETION_COLUMN_CANDIDATE   0 /* Suggested completion of the input */

Referenced by completionColumn().

◆ COMPLETION_COLUMN_PHASE

#define COMPLETION_COLUMN_PHASE   3 /* ePhase - used for debugging only */

Referenced by completionColumn().

◆ COMPLETION_COLUMN_PREFIX

#define COMPLETION_COLUMN_PREFIX   1 /* Prefix of the word to be completed */

◆ COMPLETION_COLUMN_WHOLELINE

#define COMPLETION_COLUMN_WHOLELINE   2 /* Entire line seen so far */

◆ COMPLETION_COLUMNS

#define COMPLETION_COLUMNS   9

Referenced by completionNext().

◆ COMPLETION_DATABASES

#define COMPLETION_DATABASES   7

Referenced by completionNext().

◆ COMPLETION_EOF

#define COMPLETION_EOF   11

Referenced by completionEof(), and completionNext().

◆ COMPLETION_FIRST_PHASE

#define COMPLETION_FIRST_PHASE   1

Referenced by completionFilter().

◆ COMPLETION_FUNCTIONS

#define COMPLETION_FUNCTIONS   3

◆ COMPLETION_INDEXES

#define COMPLETION_INDEXES   5

◆ COMPLETION_KEYWORDS

#define COMPLETION_KEYWORDS   1

Referenced by completionNext().

◆ COMPLETION_MODULES

#define COMPLETION_MODULES   10

◆ COMPLETION_PRAGMAS

#define COMPLETION_PRAGMAS   2

◆ COMPLETION_TABLES

#define COMPLETION_TABLES   8 /* Also VIEWs and TRIGGERs */

Referenced by completionNext().

◆ COMPLETION_TRIGGERS

#define COMPLETION_TRIGGERS   6

◆ CONTINUATION_PROMPT

#define CONTINUATION_PROMPT   dynamicContinuePrompt()

Referenced by one_input_line().

◆ CONTINUE_PAREN_INCR

#define CONTINUE_PAREN_INCR ( p,
n )
Value:
static int stdin_is_interactive
Definition shell.c:825
static void trackParenLevel(struct DynaPrompt *p, int ni)
Definition shell.c:920
906# define CONTINUE_PAREN_INCR(p,n) \
907 if(p && stdin_is_interactive) (trackParenLevel(p,n))

Referenced by quickscan().

◆ CONTINUE_PROMPT_AWAITC

#define CONTINUE_PROMPT_AWAITC ( p,
c )
Value:
static void setLexemeOpen(struct DynaPrompt *p, char *s, char c)
Definition shell.c:927
904# define CONTINUE_PROMPT_AWAITC(p,c) \
905 if(p && stdin_is_interactive) setLexemeOpen(p, 0, c)

Referenced by quickscan().

◆ CONTINUE_PROMPT_AWAITS

#define CONTINUE_PROMPT_AWAITS ( p,
s )
Value:
902# define CONTINUE_PROMPT_AWAITS(p,s) \
903 if(p && stdin_is_interactive) setLexemeOpen(p, s, 0)

Referenced by quickscan().

◆ CONTINUE_PROMPT_PSTATE

#define CONTINUE_PROMPT_PSTATE   (&dynPrompt)

Referenced by process_input().

◆ CONTINUE_PROMPT_RESET

#define CONTINUE_PROMPT_RESET    do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)
900# define CONTINUE_PROMPT_RESET \
901 do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)

Referenced by process_input().

◆ CTIMEOPT_VAL

#define CTIMEOPT_VAL ( opt)
Value:
#define CTIMEOPT_VAL_(opt)

Referenced by do_meta_command().

◆ CTIMEOPT_VAL_

#define CTIMEOPT_VAL_ ( opt)
Value:
#opt

◆ d

◆ deliberate_fall_through

◆ e

◆ END_TIMER

#define END_TIMER ( X)
Value:
static void endTimer(FILE *out)
Definition shell.c:704

Referenced by runOneSqlLine().

◆ eputz

#define eputz ( z)
Value:
sqlite3_fputs(z,stderr)
#define sqlite3_fputs
Definition shell.c:305

Referenced by do_meta_command(), main(), process_sqliterc(), shell_out_of_memory(), and usage().

◆ EXPERT_CONFIG_SAMPLE

#define EXPERT_CONFIG_SAMPLE   1 /* int */

◆ EXPERT_REPORT_CANDIDATES

#define EXPERT_REPORT_CANDIDATES   4

◆ EXPERT_REPORT_INDEXES

#define EXPERT_REPORT_INDEXES   2

◆ EXPERT_REPORT_PLAN

#define EXPERT_REPORT_PLAN   3

◆ EXPERT_REPORT_SQL

#define EXPERT_REPORT_SQL   1

◆ FSDIR_COLUMN_DATA

#define FSDIR_COLUMN_DATA   3 /* File content */

Referenced by fsdirColumn().

◆ FSDIR_COLUMN_DIR

#define FSDIR_COLUMN_DIR   5 /* Path is relative to this directory */

Referenced by fsdirBestIndex().

◆ FSDIR_COLUMN_MODE

#define FSDIR_COLUMN_MODE   1 /* Access mode */

Referenced by fsdirColumn().

◆ FSDIR_COLUMN_MTIME

#define FSDIR_COLUMN_MTIME   2 /* Last modification time */

Referenced by fsdirColumn().

◆ FSDIR_COLUMN_NAME

#define FSDIR_COLUMN_NAME   0 /* Name of the file */

Referenced by fsdirColumn().

◆ FSDIR_COLUMN_PATH

#define FSDIR_COLUMN_PATH   4 /* Path to top of search */

Referenced by fsdirBestIndex(), and fsdirColumn().

◆ FSDIR_SCHEMA

#define FSDIR_SCHEMA   "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"

Referenced by fsdirConnect().

◆ GETPID

#define GETPID   getpid

Referenced by main().

◆ HAS_TIMER

#define HAS_TIMER   1

Referenced by do_meta_command().

◆ IDX_HASH_SIZE

#define IDX_HASH_SIZE   1023

Referenced by idxHashClear(), and idxHashString().

◆ IS_B85

#define IS_B85 ( c)
Value:
(B85_CLASS(c) & 1)

Referenced by skipNonB85().

◆ IS_BX_DIGIT

#define IS_BX_DIGIT ( bdp)
Value:
(((u8)(bdp))<0x80)

Referenced by skipNonB64().

◆ IS_BX_PAD

#define IS_BX_PAD ( bdp)
Value:
((bdp)==PC)
#define PC
Definition shell.c:5162

◆ IS_BX_WS

#define IS_BX_WS ( bdp)
Value:
((bdp)==WS)
#define WS
Definition shell.c:5163

◆ IsAlnum

#define IsAlnum ( X)
Value:
isalnum((unsigned char)X)

Referenced by completionFilter(), quoteChar(), shell_callback(), and translateForDisplayAndDup().

◆ IsAlpha

#define IsAlpha ( X)
Value:
isalpha((unsigned char)X)

Referenced by quoteChar().

◆ IsDigit

#define IsDigit ( X)
Value:
isdigit((unsigned char)X)

Referenced by do_meta_command(), integerValue(), isNumber(), and testcase_glob().

◆ IsSpace

◆ LARGEST_INT64

#define LARGEST_INT64   (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))

◆ LARGEST_UINT64

#define LARGEST_UINT64   (0xffffffff|(((sqlite3_uint64)0xffffffff)<<32))

Referenced by sqlite3AtoF().

◆ MAX_INPUT_NESTING

#define MAX_INPUT_NESTING   25

Referenced by process_input().

◆ MODE_Ascii

#define MODE_Ascii   10 /* Use ASCII unit and record separators (0x1F/0x1E) */

◆ MODE_Box

#define MODE_Box   16 /* Unicode box-drawing characters */

◆ MODE_Column

#define MODE_Column   1 /* One record per line in neat columns */

◆ MODE_Count

#define MODE_Count   17 /* Output only a count of the rows of output */

◆ MODE_Csv

#define MODE_Csv   8 /* Quote strings, numbers are plain */

◆ MODE_EQP

#define MODE_EQP   12 /* Converts EXPLAIN QUERY PLAN output into a graph */

Referenced by shell_callback(), and shell_exec().

◆ MODE_Explain

#define MODE_Explain   9 /* Like MODE_Column, but do not truncate data */

◆ MODE_Html

#define MODE_Html   4 /* Generate an XHTML table */

◆ MODE_Insert

#define MODE_Insert   5 /* Generate SQL "insert" statements */

◆ MODE_Json

#define MODE_Json   13 /* Output JSON */

◆ MODE_Line

#define MODE_Line   0 /* One column per line. Blank line between records */

◆ MODE_List

#define MODE_List   2 /* One record per line with a separator */

◆ MODE_Markdown

#define MODE_Markdown   14 /* Markdown formatting */

◆ MODE_Off

#define MODE_Off   18 /* No query output shown */

Referenced by do_meta_command(), and shell_callback().

◆ MODE_Pretty

#define MODE_Pretty   11 /* Pretty-print schemas */

Referenced by do_meta_command(), and shell_callback().

◆ MODE_Quote

#define MODE_Quote   6 /* Quote values as for SQL */

◆ MODE_ScanExp

#define MODE_ScanExp   19 /* Like MODE_Explain, but for ".scanstats vm" */

◆ MODE_Semi

#define MODE_Semi   3 /* Same as MODE_List but append ";" to each line */

Referenced by do_meta_command(), and shell_callback().

◆ MODE_Table

#define MODE_Table   15 /* MySQL-style table formatting */

◆ MODE_Tcl

#define MODE_Tcl   7 /* Generate ANSI-C or TCL quoted elements */

Referenced by do_meta_command(), and shell_callback().

◆ MODE_Www

#define MODE_Www   20 /* Full web-page output */

◆ ND

#define ND   0x82 /* Not above or digit-value */

Referenced by fromBase64().

◆ NEVER

◆ OMIT_BASE85_CHECKER

#define OMIT_BASE85_CHECKER

◆ OPEN_DB_KEEPALIVE

#define OPEN_DB_KEEPALIVE   0x001 /* Return after error if true */

Referenced by do_meta_command(), and open_db().

◆ OPEN_DB_ZIPFILE

#define OPEN_DB_ZIPFILE   0x002 /* Open as ZIP if name matches *.zip */

Referenced by main(), and open_db().

◆ ORIGFILE

◆ ORIGVFS

◆ PAD_CHAR

#define PAD_CHAR   '='

Referenced by fromBase64(), and toBase64().

◆ PC

#define PC   0x80 /* pad character */

Referenced by fromBase64().

◆ PROMPT_LEN_MAX

#define PROMPT_LEN_MAX   128

Referenced by dynamicContinuePrompt().

◆ QSS_INPLAIN

#define QSS_INPLAIN ( qss)
Value:
@ QSS_Start
Definition shell.c:32452
@ QSS_CharMask
Definition shell.c:32451

Referenced by process_input().

◆ QSS_PLAINDARK

#define QSS_PLAINDARK ( qss)
Value:
@ QSS_HasDark
Definition shell.c:32450
@ QSS_EndingSemi
Definition shell.c:32450

◆ QSS_PLAINWHITE

#define QSS_PLAINWHITE ( qss)
Value:

Referenced by process_input().

◆ QSS_SEMITERM

#define QSS_SEMITERM ( qss)
Value:

Referenced by process_input().

◆ QSS_SETV

#define QSS_SETV ( qss,
newst )
Value:
((newst) | ((qss) & QSS_ScanMask))
@ QSS_ScanMask
Definition shell.c:32451

Referenced by quickscan().

◆ R1

#define R1 ( v,
w,
x,
y,
z,
i )
Value:
z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=ror(w,2);
#define blk(i)
Definition shell.c:3237
3250#define R1(v,w,x,y,z,i) \
3251 z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=ror(w,2);

Referenced by SHA1Transform().

◆ R2

#define R2 ( v,
w,
x,
y,
z,
i )
Value:
z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=ror(w,2);
3252#define R2(v,w,x,y,z,i) \
3253 z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=ror(w,2);

Referenced by SHA1Transform().

◆ R3

#define R3 ( v,
w,
x,
y,
z,
i )
Value:
z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=ror(w,2);
3254#define R3(v,w,x,y,z,i) \
3255 z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=ror(w,2);

Referenced by SHA1Transform().

◆ R4

#define R4 ( v,
w,
x,
y,
z,
i )
Value:
z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=ror(w,2);
3256#define R4(v,w,x,y,z,i) \
3257 z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=ror(w,2);

Referenced by SHA1Transform().

◆ Rb0

#define Rb0 ( v,
w,
x,
y,
z,
i )
Value:
z+=((w&(x^y))^y)+blk0be(i)+0x5A827999+rol(v,5);w=ror(w,2);
#define blk0be(i)
Definition shell.c:3236
3248#define Rb0(v,w,x,y,z,i) \
3249 z+=((w&(x^y))^y)+blk0be(i)+0x5A827999+rol(v,5);w=ror(w,2);

Referenced by SHA1Transform().

◆ re_compile

#define re_compile   sqlite3re_compile

Referenced by re_sql_func().

◆ RE_EOF

#define RE_EOF   0 /* End of input */

◆ re_free

#define re_free   sqlite3re_free

Referenced by re_sql_func(), and sqlite3re_compile().

◆ re_match

#define re_match   sqlite3re_match

Referenced by re_sql_func().

◆ RE_OP_ACCEPT

#define RE_OP_ACCEPT   6 /* Halt and indicate a successful match */

◆ RE_OP_ANY

#define RE_OP_ANY   2 /* Match any one character. (Implements ".") */

◆ RE_OP_ANYSTAR

#define RE_OP_ANYSTAR   3 /* Special optimized version of .* */

◆ RE_OP_ATSTART

#define RE_OP_ATSTART   18 /* Currently at the start of the string */

◆ RE_OP_BOUNDARY

#define RE_OP_BOUNDARY   17 /* Boundary between word and non-word */

◆ RE_OP_CC_EXC

#define RE_OP_CC_EXC   8 /* Beginning of a [^...] character class */

◆ RE_OP_CC_INC

#define RE_OP_CC_INC   7 /* Beginning of a [...] character class */

◆ RE_OP_CC_RANGE

#define RE_OP_CC_RANGE   10 /* Range of values in a character class */

Referenced by re_subcompile_string().

◆ RE_OP_CC_VALUE

#define RE_OP_CC_VALUE   9 /* Single value in a character class */

◆ RE_OP_DIGIT

#define RE_OP_DIGIT   13 /* digit: [0-9] */

◆ RE_OP_FORK

#define RE_OP_FORK   4 /* Continue to both next and opcode at iArg */

◆ RE_OP_GOTO

#define RE_OP_GOTO   5 /* Jump to opcode at iArg */

◆ RE_OP_MATCH

#define RE_OP_MATCH   1 /* Match the one character in the argument */

◆ RE_OP_NOTDIGIT

#define RE_OP_NOTDIGIT   14 /* Not a digit */

◆ RE_OP_NOTSPACE

#define RE_OP_NOTSPACE   16 /* Not a digit */

◆ RE_OP_NOTWORD

#define RE_OP_NOTWORD   12 /* Not a perl word character */

◆ RE_OP_SPACE

#define RE_OP_SPACE   15 /* space: [ \t\n\r\v\f] */

◆ RE_OP_WORD

#define RE_OP_WORD   11 /* Perl word character [A-Za-z0-9_] */

◆ RE_START

#define RE_START   0xfffffff /* Start of input - larger than an UTF-8 */

Referenced by sqlite3re_match().

◆ Rl0

#define Rl0 ( v,
w,
x,
y,
z,
i )
Value:
z+=((w&(x^y))^y)+blk0le(i)+0x5A827999+rol(v,5);w=ror(w,2);
#define blk0le(i)
Definition shell.c:3234
3246#define Rl0(v,w,x,y,z,i) \
3247 z+=((w&(x^y))^y)+blk0le(i)+0x5A827999+rol(v,5);w=ror(w,2);

Referenced by SHA1Transform().

◆ rol

#define rol ( x,
k )
Value:
SHA_ROT(x,k,32-(k))
#define SHA_ROT(x, l, r)
Definition shell.c:3230

◆ ROL64

#define ROL64 ( a,
x )
Value:
((a<<x)|(a>>(64-x)))
#define a

Referenced by KeccakF1600Step().

◆ ror

#define ror ( x,
k )
Value:
SHA_ROT(x,32-(k),k)

◆ SCAN_TRACKER_REFTYPE

#define SCAN_TRACKER_REFTYPE   t_DynaPromptRef

Referenced by quickscan().

◆ SEP_Column

#define SEP_Column   "|"

Referenced by do_meta_command(), and main_init().

◆ SEP_Comma

#define SEP_Comma   ","

Referenced by do_meta_command(), and main().

◆ SEP_CrLf

#define SEP_CrLf   "\r\n"

Referenced by do_meta_command().

◆ SEP_Record

#define SEP_Record   "\x1E"

Referenced by do_meta_command(), and main().

◆ SEP_Row

#define SEP_Row   "\n"

Referenced by do_meta_command(), main(), and main_init().

◆ SEP_Space

#define SEP_Space   " "

Referenced by do_meta_command().

◆ SEP_Tab

#define SEP_Tab   "\t"

Referenced by do_meta_command(), and main().

◆ SEP_Unit

#define SEP_Unit   "\x1F"

Referenced by do_meta_command(), and main().

◆ SERIES_COLUMN_ROWID

#define SERIES_COLUMN_ROWID   (-1)

Referenced by seriesBestIndex().

◆ SERIES_COLUMN_START

#define SERIES_COLUMN_START   1

Referenced by seriesBestIndex(), and seriesColumn().

◆ SERIES_COLUMN_STEP

#define SERIES_COLUMN_STEP   3

Referenced by seriesBestIndex(), and seriesColumn().

◆ SERIES_COLUMN_STOP

#define SERIES_COLUMN_STOP   2

Referenced by seriesBestIndex(), and seriesColumn().

◆ SERIES_COLUMN_VALUE

#define SERIES_COLUMN_VALUE   0

Referenced by seriesBestIndex().

◆ session_close_all

#define session_close_all ( X,
Y )

Referenced by do_meta_command(), and main().

◆ SHA3_BYTEORDER

#define SHA3_BYTEORDER   0

◆ SHA_ROT

#define SHA_ROT ( x,
l,
r )
Value:
((x) << (l) | (x) >> (r))

◆ SHELL_ESC_ASCII

#define SHELL_ESC_ASCII   0 /* Substitute ^Y for X where Y=X+0x40 */

◆ SHELL_ESC_OFF

#define SHELL_ESC_OFF   2 /* Send characters verbatim */

◆ SHELL_ESC_SYMBOL

#define SHELL_ESC_SYMBOL   1 /* Substitute U+2400 graphics */

◆ SHELL_OPEN_APPENDVFS

#define SHELL_OPEN_APPENDVFS   2 /* Use appendvfs */

◆ SHELL_OPEN_DESERIALIZE

#define SHELL_OPEN_DESERIALIZE   5 /* Open using sqlite3_deserialize() */

Referenced by do_meta_command(), main(), and open_db().

◆ SHELL_OPEN_HEXDB

#define SHELL_OPEN_HEXDB   6 /* Use "dbtotxt" output as data source */

Referenced by do_meta_command(), and open_db().

◆ SHELL_OPEN_NORMAL

#define SHELL_OPEN_NORMAL   1 /* Normal database file */

Referenced by deduceDatabaseType(), and open_db().

◆ SHELL_OPEN_READONLY

#define SHELL_OPEN_READONLY   4 /* Open a normal database read-only */

Referenced by do_meta_command(), main(), and open_db().

◆ SHELL_OPEN_UNSPEC

#define SHELL_OPEN_UNSPEC   0 /* No open-mode specified */

◆ SHELL_OPEN_ZIPFILE

#define SHELL_OPEN_ZIPFILE   3 /* Use the zipfile virtual table */

◆ SHELL_PROGRESS_ONCE

#define SHELL_PROGRESS_ONCE   0x04 /* Cancel the --limit after firing once */

◆ SHELL_PROGRESS_QUIET

#define SHELL_PROGRESS_QUIET   0x01 /* Omit announcing every progress callback */

◆ SHELL_PROGRESS_RESET

#define SHELL_PROGRESS_RESET
Value:
0x02 /* Reset the count when the progress
** callback limit is reached, and for each
** top-level SQL statement */

Referenced by do_meta_command(), progress_handler(), and runOneSqlLine().

◆ shell_read_history

#define shell_read_history ( X)

Referenced by main().

◆ shell_stifle_history

#define shell_stifle_history ( X)

Referenced by main().

◆ SHELL_STRINGIFY

#define SHELL_STRINGIFY ( f)
Value:
#define SHELL_STRINGIFY_(f)
Definition shell.c:46

◆ SHELL_STRINGIFY_

#define SHELL_STRINGIFY_ ( f)
Value:
#f

◆ SHELL_TRACE_EXPANDED

#define SHELL_TRACE_EXPANDED   1 /* Show expanded SQL text */

◆ SHELL_TRACE_NORMALIZED

#define SHELL_TRACE_NORMALIZED   2 /* Show normalized SQL text */

◆ SHELL_TRACE_PLAIN

#define SHELL_TRACE_PLAIN   0 /* Show input SQL text */

Referenced by do_meta_command().

◆ SHELL_USE_LOCAL_GETLINE

#define SHELL_USE_LOCAL_GETLINE   1

◆ shell_write_history

#define shell_write_history ( X)

Referenced by main().

◆ ShellClearFlag

#define ShellClearFlag ( P,
X )
Value:
((P)->shellFlgs&=(~(X)))

Referenced by do_meta_command(), and setOrClearFlag().

◆ ShellHasFlag

#define ShellHasFlag ( P,
X )
Value:
(((P)->shellFlgs & (X))!=0)

Referenced by do_meta_command(), open_db(), runOneSqlLine(), shell_callback(), and tableColumnList().

◆ ShellSetFlag

#define ShellSetFlag ( P,
X )
Value:
((P)->shellFlgs|=(X))

Referenced by do_meta_command(), main(), and setOrClearFlag().

◆ SHFLG_Backslash

#define SHFLG_Backslash   0x00000004 /* The --backslash option is used */

Referenced by main(), and runOneSqlLine().

◆ SHFLG_CountChanges

#define SHFLG_CountChanges   0x00000020 /* .changes setting */

Referenced by do_meta_command(), and runOneSqlLine().

◆ SHFLG_DumpDataOnly

#define SHFLG_DumpDataOnly   0x00000100 /* .dump show data only */

Referenced by do_meta_command(), and dump_callback().

◆ SHFLG_DumpNoSys

#define SHFLG_DumpNoSys   0x00000200 /* .dump omits system tables */

Referenced by do_meta_command(), and dump_callback().

◆ SHFLG_Echo

#define SHFLG_Echo   0x00000040 /* .echo on/off, or --echo setting */

Referenced by do_meta_command(), and main().

◆ SHFLG_HeaderSet

#define SHFLG_HeaderSet   0x00000080 /* showHeader has been specified */

Referenced by do_meta_command(), and main().

◆ SHFLG_Lookaside

#define SHFLG_Lookaside   0x00000002 /* Lookaside memory is used */

Referenced by display_stats(), main(), and main_init().

◆ SHFLG_Newlines

#define SHFLG_Newlines   0x00000010 /* .dump --newline flag */

Referenced by do_meta_command(), and shell_callback().

◆ SHFLG_Pagecache

#define SHFLG_Pagecache   0x00000001 /* The --pagecache option is used */

Referenced by display_stats(), and main().

◆ SHFLG_PreserveRowid

#define SHFLG_PreserveRowid   0x00000008 /* .dump preserves rowid values */

Referenced by do_meta_command(), and tableColumnList().

◆ SHFLG_TestingMode

#define SHFLG_TestingMode   0x00000400 /* allow unsafe testing features */

Referenced by do_meta_command(), main(), and open_db().

◆ SMALLEST_INT64

◆ sputz

◆ sqlite3_base_init [1/2]

#define sqlite3_base_init   sqlite3_base64_init

◆ sqlite3_base_init [2/2]

#define sqlite3_base_init   sqlite3_base85_init

◆ sqlite3_fgets

#define sqlite3_fgets   fgets

Referenced by local_getline(), main(), and readHexDb().

◆ sqlite3_fopen

◆ sqlite3_fprintf

◆ sqlite3_fputs

◆ sqlite3_fsetmode

#define sqlite3_fsetmode ( F,
X )

◆ sqlite3_popen

#define sqlite3_popen   popen

Referenced by do_meta_command().

◆ SQLITE_EXTENSION_INIT1

#define SQLITE_EXTENSION_INIT1

◆ SQLITE_EXTENSION_INIT2

◆ SQLITE_INTERNAL_LINKAGE

#define SQLITE_INTERNAL_LINKAGE   static

◆ SQLITE_OS_WINRT

#define SQLITE_OS_WINRT   0

◆ SQLITE_SERIES_CONSTRAINT_VERIFY

#define SQLITE_SERIES_CONSTRAINT_VERIFY   0

Referenced by seriesBestIndex().

◆ SQLITE_SHELL_HAVE_RECOVER

#define SQLITE_SHELL_HAVE_RECOVER   0

◆ SQLITE_SHELL_IS_UTF8

#define SQLITE_SHELL_IS_UTF8   (1)

◆ SQLITEEXPERT_H

#define SQLITEEXPERT_H   1

◆ STAT_CHR_SRC

#define STAT_CHR_SRC ( mode)
Value:
(S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode))

Referenced by openChrSource().

◆ STMTRAND_KEY

#define STMTRAND_KEY   (-4418371)

Referenced by stmtrandFunc().

◆ STRLEN

◆ STRUCT_STAT

#define STRUCT_STAT   struct stat

◆ SWAP_DOUBLE

#define SWAP_DOUBLE ( X,
Y )
Value:
{double ttt=(X);(X)=(Y);(Y)=ttt;}

Referenced by percentSort().

◆ ToLower

#define ToLower ( X)
Value:
(char)tolower((unsigned char)X)

Referenced by line_is_command_terminator().

◆ U8_TYPEDEF

#define U8_TYPEDEF

◆ UNIQUE_TABLE_NAME

#define UNIQUE_TABLE_NAME   "t592690916721053953805701627921227776"

◆ UNUSED_PARAMETER

◆ VTR_ACCESS

#define VTR_ACCESS   0x00040000

◆ VTR_CLOSE

#define VTR_CLOSE   0x00000001

◆ VTR_CRL

#define VTR_CRL   0x00000100

◆ VTR_CURTIME

#define VTR_CURTIME   0x04000000

◆ VTR_DELETE

#define VTR_DELETE   0x00020000

◆ VTR_DEVCHAR

#define VTR_DEVCHAR   0x00000800

◆ VTR_DLCLOSE

#define VTR_DLCLOSE   0x00800000

◆ VTR_DLERR

#define VTR_DLERR   0x00200000

◆ VTR_DLOPEN

#define VTR_DLOPEN   0x00100000

◆ VTR_DLSYM

#define VTR_DLSYM   0x00400000

Referenced by vfstraceFileControl().

◆ VTR_FCTRL

#define VTR_FCTRL   0x00000200

Referenced by vfstraceFileControl().

◆ VTR_FETCH

#define VTR_FETCH   0x10000000 /* Also coverse xUnfetch */

◆ VTR_FSIZE

#define VTR_FSIZE   0x00000020

◆ VTR_FULLPATH

#define VTR_FULLPATH   0x00080000

◆ VTR_LASTERR

#define VTR_LASTERR   0x08000000

◆ VTR_LOCK

#define VTR_LOCK   0x00000040

◆ VTR_OPEN

#define VTR_OPEN   0x00010000

◆ VTR_RAND

#define VTR_RAND   0x01000000

◆ VTR_READ

#define VTR_READ   0x00000002

◆ VTR_SECSZ

#define VTR_SECSZ   0x00000400

◆ VTR_SHMBAR

#define VTR_SHMBAR   0x00004000

◆ VTR_SHMLOCK

#define VTR_SHMLOCK   0x00001000

◆ VTR_SHMMAP

#define VTR_SHMMAP   0x00002000

◆ VTR_SHMUNMAP

#define VTR_SHMUNMAP   0x00008000

◆ VTR_SLEEP

#define VTR_SLEEP   0x02000000

◆ VTR_SYNC

#define VTR_SYNC   0x00000010

◆ VTR_TRUNC

#define VTR_TRUNC   0x00000008

◆ VTR_UNLOCK

#define VTR_UNLOCK   0x00000080

◆ VTR_WRITE

#define VTR_WRITE   0x00000004

◆ WS

#define WS   0x81 /* whitespace */

Referenced by fromBase64().

Typedef Documentation

◆ ApndFile

typedef struct ApndFile ApndFile

◆ ApndVfs

typedef struct sqlite3_vfs ApndVfs

◆ ColModeOpts

typedef struct ColModeOpts ColModeOpts

◆ completion_cursor

typedef struct completion_cursor completion_cursor

◆ completion_vtab

typedef struct completion_vtab completion_vtab

◆ Decimal

typedef struct Decimal Decimal

◆ EQPGraph

typedef struct EQPGraph EQPGraph

◆ EQPGraphRow

typedef struct EQPGraphRow EQPGraphRow

◆ ExpertCsr

typedef struct ExpertCsr ExpertCsr

◆ ExpertInfo

typedef struct ExpertInfo ExpertInfo

◆ ExpertVtab

typedef struct ExpertVtab ExpertVtab

◆ fsdir_cursor

typedef struct fsdir_cursor fsdir_cursor

◆ fsdir_tab

typedef struct fsdir_tab fsdir_tab

◆ FsdirLevel

typedef struct FsdirLevel FsdirLevel

◆ i64

typedef sqlite3_int64 i64

◆ IdxColumn

typedef struct IdxColumn IdxColumn

◆ IdxConstraint

typedef struct IdxConstraint IdxConstraint

◆ IdxHash

typedef struct IdxHash IdxHash

◆ IdxHashEntry

typedef struct IdxHashEntry IdxHashEntry

◆ IdxScan

typedef struct IdxScan IdxScan

◆ IdxStatement

typedef struct IdxStatement IdxStatement

◆ IdxTable

typedef struct IdxTable IdxTable

◆ IdxWrite

typedef struct IdxWrite IdxWrite

◆ ImportCtx

typedef struct ImportCtx ImportCtx

◆ Percentile

typedef struct Percentile Percentile

◆ PercentileFunc

typedef struct PercentileFunc PercentileFunc

◆ ReCompiled

typedef struct ReCompiled ReCompiled

◆ ReInput

typedef struct ReInput ReInput

◆ ReStateNumber

typedef unsigned short ReStateNumber

◆ ReStateSet

typedef struct ReStateSet ReStateSet

◆ SequenceSpec

typedef struct SequenceSpec SequenceSpec

◆ series_cursor

typedef struct series_cursor series_cursor

◆ SHA1Context

typedef struct SHA1Context SHA1Context

◆ SHA3Context

typedef struct SHA3Context SHA3Context

◆ ShellState

typedef struct ShellState ShellState

◆ ShellText

typedef struct ShellText ShellText

◆ sqlite3_intck

typedef struct sqlite3_intck sqlite3_intck

◆ sqlite3expert

typedef struct sqlite3expert sqlite3expert

◆ Stmtrand

typedef struct Stmtrand Stmtrand

◆ t_DynaPromptRef

typedef struct DynaPrompt* t_DynaPromptRef

◆ u16

typedef unsigned short int u16

◆ u32

typedef unsigned int u32

◆ u64

◆ u8

typedef unsigned char u8

◆ vfstrace_file

typedef struct vfstrace_file vfstrace_file

◆ vfstrace_info

typedef struct vfstrace_info vfstrace_info

Enumeration Type Documentation

◆ QuickScanState

Enumerator
QSS_HasDark 1<< 8 
QSS_EndingSemi 2<< 8 
QSS_CharMask (1<< 8 )-1 
QSS_ScanMask 3<< 8 
QSS_Start 
32451 {
#define CHAR_BIT
Definition shell.c:32447

Function Documentation

◆ anyOfInStr()

const char * anyOfInStr ( const char * s,
const char * zAny,
size_t ns )
static
22230 {
22231 const char *pcFirst = 0;
22232 if( ns == ~(size_t)0 ) ns = strlen(s);
22233 while(*zAny){
22234 const char *pc = (const char*)memchr(s, *zAny&0xff, ns);
22235 if( pc ){
22236 pcFirst = pc;
22237 ns = pcFirst - s;
22238 }
22239 ++zAny;
22240 }

Referenced by output_c_string(), and output_json_string().

Here is the caller graph for this function:

◆ apndAccess()

int apndAccess ( sqlite3_vfs * pVfs,
const char * zName,
int flags,
int * pResOut )
static
10114 {
10115 return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
10116}
#define ORIGVFS(p)
Definition shell.c:9619

References ORIGVFS.

◆ apndCheckReservedLock()

int apndCheckReservedLock ( sqlite3_file * pFile,
int * pResOut )
static
9872 {
9873 pFile = ORIGFILE(pFile);
9874 return pFile->pMethods->xCheckReservedLock(pFile, pResOut);
9875}
#define ORIGFILE(p)
Definition shell.c:9620
int(* xCheckReservedLock)(sqlite3_file *, int *pResOut)
Definition sqlite3.c:1175
const struct sqlite3_io_methods * pMethods
Definition sqlite3.c:1059

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xCheckReservedLock.

◆ apndClose()

int apndClose ( sqlite3_file * pFile)
static
9755 {
9756 pFile = ORIGFILE(pFile);
9757 return pFile->pMethods->xClose(pFile);
9758}
int(* xClose)(sqlite3_file *)
Definition sqlite3.c:1167

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xClose.

◆ apndCurrentTime()

int apndCurrentTime ( sqlite3_vfs * pVfs,
double * pTimeOut )
static
10143 {
10144 return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut);
10145}

References ORIGVFS.

◆ apndCurrentTimeInt64()

int apndCurrentTimeInt64 ( sqlite3_vfs * pVfs,
sqlite3_int64 * p )
static
10149 {
10150 return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p);
10151}

References ORIGVFS.

◆ apndDelete()

int apndDelete ( sqlite3_vfs * pVfs,
const char * zName,
int syncDir )
static
10102 {
10103 return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
10104}

References ORIGVFS.

◆ apndDeviceCharacteristics()

int apndDeviceCharacteristics ( sqlite3_file * pFile)
static
9903 {
9904 pFile = ORIGFILE(pFile);
9905 return pFile->pMethods->xDeviceCharacteristics(pFile);
9906}
int(* xDeviceCharacteristics)(sqlite3_file *)
Definition sqlite3.c:1178

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xDeviceCharacteristics.

◆ apndDlClose()

void apndDlClose ( sqlite3_vfs * pVfs,
void * pHandle )
static
10134 {
10135 ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle);
10136}

References ORIGVFS.

◆ apndDlError()

void apndDlError ( sqlite3_vfs * pVfs,
int nByte,
char * zErrMsg )
static
10128 {
10129 ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg);
10130}

References ORIGVFS.

◆ apndDlOpen()

void * apndDlOpen ( sqlite3_vfs * pVfs,
const char * zFilename )
static
10125 {
10126 return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath);
10127}

References ORIGVFS.

◆ apndFetch()

int apndFetch ( sqlite3_file * pFile,
sqlite3_int64 iOfst,
int iAmt,
void ** pp )
static
9944 {
9945 ApndFile *p = (ApndFile *)pFile;
9946 if( p->iMark < 0 || iOfst+iAmt > p->iMark ){
9947 return SQLITE_IOERR; /* Cannot read what is not yet there. */
9948 }
9949 pFile = ORIGFILE(pFile);
9950 return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
9951}
sqlite3_int64 iMark
Definition shell.c:9659
sqlite3_int64 iPgOne
Definition shell.c:9658
#define SQLITE_IOERR
Definition sqlite3.c:776
int(* xFetch)(sqlite3_file *, sqlite3_int64 iOfst, int iAmt, void **pp)
Definition sqlite3.c:1185

References ApndFile::iMark, ApndFile::iPgOne, ORIGFILE, sqlite3_file::pMethods, SQLITE_IOERR, and sqlite3_io_methods::xFetch.

◆ apndFileControl()

int apndFileControl ( sqlite3_file * pFile,
int op,
void * pArg )
static
9880 {
9881 ApndFile *paf = (ApndFile *)pFile;
9882 int rc;
9883 pFile = ORIGFILE(pFile);
9884 if( op==SQLITE_FCNTL_SIZE_HINT ) *(sqlite3_int64*)pArg += paf->iPgOne;
9885 rc = pFile->pMethods->xFileControl(pFile, op, pArg);
9886 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
9887 *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", paf->iPgOne,*(char**)pArg);
9888 }
9889 return rc;
9890}
sqlite_int64 sqlite3_int64
Definition sqlite3.c:623
#define SQLITE_FCNTL_SIZE_HINT
Definition sqlite3.c:1549
#define SQLITE_OK
Definition sqlite3.c:765
#define SQLITE_FCNTL_VFSNAME
Definition sqlite3.c:1556
int(* xFileControl)(sqlite3_file *, int op, void *pArg)
Definition sqlite3.c:1176
#define sqlite3_mprintf
Definition sqlite3ext.h:471

References ApndFile::iPgOne, ORIGFILE, sqlite3_file::pMethods, sqlite3_mprintf, SQLITE_FCNTL_SIZE_HINT, SQLITE_FCNTL_VFSNAME, SQLITE_OK, and sqlite3_io_methods::xFileControl.

◆ apndFileSize()

int apndFileSize ( sqlite3_file * pFile,
sqlite3_int64 * pSize )
static
9847 {
9848 ApndFile *paf = (ApndFile *)pFile;
9849 *pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0;
9850 return SQLITE_OK;
9851}

References ApndFile::iMark, ApndFile::iPgOne, and SQLITE_OK.

◆ apndFullPathname()

int apndFullPathname ( sqlite3_vfs * pVfs,
const char * zName,
int nOut,
char * zOut )
static
10122 {
10123 return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
10124}

References ORIGVFS.

◆ apndGetLastError()

int apndGetLastError ( sqlite3_vfs * pVfs,
int a,
char * b )
static
10146 {
10147 return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b);
10148}
#define b

References a, b, and ORIGVFS.

◆ apndGetSystemCall()

sqlite3_syscall_ptr apndGetSystemCall ( sqlite3_vfs * pVfs,
const char * z )
static
10162 {
10163 return ORIGVFS(pVfs)->xGetSystemCall(ORIGVFS(pVfs),zName);
10164}

References ORIGVFS.

◆ apndIsAppendvfsDatabase()

int apndIsAppendvfsDatabase ( sqlite3_int64 sz,
sqlite3_file * pFile )
static
9994 {
9995 int rc;
9996 char zHdr[16];
9997 sqlite3_int64 iMark = apndReadMark(sz, pFile);
9998 if( iMark>=0 ){
9999 /* If file has the correct end-marker, the expected odd size, and the
10000 ** SQLite DB type marker where the end-marker puts it, then it
10001 ** is an appendvfs database.
10002 */
10003 rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
10004 if( SQLITE_OK==rc
10005 && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
10006 && (sz & 0x1ff) == APND_MARK_SIZE
10007 && sz>=512+APND_MARK_SIZE
10008 ){
10009 return 1; /* It's an appendvfs database */
10010 }
10011 }
10012 return 0;
10013}
static const char apvfsSqliteHdr[]
Definition shell.c:9989
static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile)
Definition shell.c:9969
#define APND_MARK_SIZE
Definition shell.c:9593
int(* xRead)(sqlite3_file *, void *, int iAmt, sqlite3_int64 iOfst)
Definition sqlite3.c:1168

References APND_MARK_SIZE, apndReadMark(), apvfsSqliteHdr, sqlite3_file::pMethods, SQLITE_OK, and sqlite3_io_methods::xRead.

Referenced by apndIsOrdinaryDatabaseFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ apndIsOrdinaryDatabaseFile()

int apndIsOrdinaryDatabaseFile ( sqlite3_int64 sz,
sqlite3_file * pFile )
static
10019 {
10020 char zHdr[16];
10021 if( apndIsAppendvfsDatabase(sz, pFile) /* rule 2 */
10022 || (sz & 0x1ff) != 0
10023 || SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0)
10024 || memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))!=0
10025 ){
10026 return 0;
10027 }else{
10028 return 1;
10029 }
10030}
static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile)
Definition shell.c:9994

References apndIsAppendvfsDatabase(), apvfsSqliteHdr, sqlite3_file::pMethods, SQLITE_OK, and sqlite3_io_methods::xRead.

Referenced by apndOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ apndLock()

int apndLock ( sqlite3_file * pFile,
int eLock )
static
9856 {
9857 pFile = ORIGFILE(pFile);
9858 return pFile->pMethods->xLock(pFile, eLock);
9859}
int(* xLock)(sqlite3_file *, int)
Definition sqlite3.c:1173

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xLock.

◆ apndNextSystemCall()

const char * apndNextSystemCall ( sqlite3_vfs * pVfs,
const char * zName )
static
10165 {
10166 return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
10167}

References ORIGVFS.

◆ apndOpen()

int apndOpen ( sqlite3_vfs * pApndVfs,
const char * zName,
sqlite3_file * pFile,
int flags,
int * pOutFlags )
static
10041 {
10042 ApndFile *pApndFile = (ApndFile*)pFile;
10043 sqlite3_file *pBaseFile = ORIGFILE(pFile);
10044 sqlite3_vfs *pBaseVfs = ORIGVFS(pApndVfs);
10045 int rc;
10046 sqlite3_int64 sz = 0;
10047 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
10048 /* The appendvfs is not to be used for transient or temporary databases.
10049 ** Just use the base VFS open to initialize the given file object and
10050 ** open the underlying file. (Appendvfs is then unused for this file.)
10051 */
10052 return pBaseVfs->xOpen(pBaseVfs, zName, pFile, flags, pOutFlags);
10053 }
10054 memset(pApndFile, 0, sizeof(ApndFile));
10055 pFile->pMethods = &apnd_io_methods;
10056 pApndFile->iMark = -1; /* Append mark not yet written */
10057
10058 rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
10059 if( rc==SQLITE_OK ){
10060 rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
10061 if( rc ){
10062 pBaseFile->pMethods->xClose(pBaseFile);
10063 }
10064 }
10065 if( rc ){
10066 pFile->pMethods = 0;
10067 return rc;
10068 }
10069 if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
10070 /* The file being opened appears to be just an ordinary DB. Copy
10071 ** the base dispatch-table so this instance mimics the base VFS.
10072 */
10073 memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
10074 return SQLITE_OK;
10075 }
10076 pApndFile->iPgOne = apndReadMark(sz, pFile);
10077 if( pApndFile->iPgOne>=0 ){
10078 pApndFile->iMark = sz - APND_MARK_SIZE; /* Append mark found */
10079 return SQLITE_OK;
10080 }
10081 if( (flags & SQLITE_OPEN_CREATE)==0 ){
10082 pBaseFile->pMethods->xClose(pBaseFile);
10083 rc = SQLITE_CANTOPEN;
10084 pFile->pMethods = 0;
10085 }else{
10086 /* Round newly added appendvfs location to #define'd page boundary.
10087 ** Note that nothing has yet been written to the underlying file.
10088 ** The append mark will be written along with first content write.
10089 ** Until then, paf->iMark value indicates it is not yet written.
10090 */
10091 pApndFile->iPgOne = APND_START_ROUNDUP(sz);
10092 }
10093 return rc;
10094}
#define APND_START_ROUNDUP(fsz)
Definition shell.c:9608
static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile)
Definition shell.c:10019
static const sqlite3_io_methods apnd_io_methods
Definition shell.c:9730
#define SQLITE_OPEN_CREATE
Definition sqlite3.c:916
#define SQLITE_OPEN_MAIN_DB
Definition sqlite3.c:922
#define SQLITE_CANTOPEN
Definition sqlite3.c:780
int(* xOpen)(sqlite3_vfs *, sqlite3_filename zName, sqlite3_file *, int flags, int *pOutFlags)
Definition sqlite3.c:1815
int szOsFile
Definition sqlite3.c:1810
int(* xFileSize)(sqlite3_file *, sqlite3_int64 *pSize)
Definition sqlite3.c:1172

References apnd_io_methods, APND_MARK_SIZE, APND_START_ROUNDUP, apndIsOrdinaryDatabaseFile(), apndReadMark(), ApndFile::iMark, ApndFile::iPgOne, ORIGFILE, ORIGVFS, sqlite3_file::pMethods, SQLITE_CANTOPEN, SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_MAIN_DB, sqlite3_vfs::szOsFile, sqlite3_io_methods::xClose, sqlite3_io_methods::xFileSize, and sqlite3_vfs::xOpen.

Here is the call graph for this function:

◆ apndRandomness()

int apndRandomness ( sqlite3_vfs * pVfs,
int nByte,
char * zOut )
static
10137 {
10138 return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut);
10139}

References ORIGVFS.

◆ apndRead()

int apndRead ( sqlite3_file * pFile,
void * zBuf,
int iAmt,
sqlite3_int64 iOfst )
static
9768 {
9769 ApndFile *paf = (ApndFile *)pFile;
9770 pFile = ORIGFILE(pFile);
9771 return pFile->pMethods->xRead(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
9772}

References ApndFile::iPgOne, ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xRead.

◆ apndReadMark()

sqlite3_int64 apndReadMark ( sqlite3_int64 sz,
sqlite3_file * pFile )
static
9969 {
9970 int rc, i;
9971 sqlite3_int64 iMark;
9972 int msbs = 8 * (APND_MARK_FOS_SZ-1);
9973 unsigned char a[APND_MARK_SIZE];
9974
9975 if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1;
9976 rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
9977 if( rc ) return -1;
9978 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
9979 iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs;
9980 for(i=1; i<8; i++){
9981 msbs -= 8;
9982 iMark |= (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<msbs;
9983 }
9984 if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1;
9985 if( iMark & 0x1ff ) return -1;
9986 return iMark;
9987}
#define APND_MARK_FOS_SZ
Definition shell.c:9592
#define APND_MARK_PREFIX_SZ
Definition shell.c:9591
#define APND_MARK_PREFIX
Definition shell.c:9590

References a, APND_MARK_FOS_SZ, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ, APND_MARK_SIZE, sqlite3_file::pMethods, and sqlite3_io_methods::xRead.

Referenced by apndIsAppendvfsDatabase(), and apndOpen().

Here is the caller graph for this function:

◆ apndSectorSize()

int apndSectorSize ( sqlite3_file * pFile)
static
9895 {
9896 pFile = ORIGFILE(pFile);
9897 return pFile->pMethods->xSectorSize(pFile);
9898}
int(* xSectorSize)(sqlite3_file *)
Definition sqlite3.c:1177

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xSectorSize.

◆ apndSetSystemCall()

int apndSetSystemCall ( sqlite3_vfs * pVfs,
const char * zName,
sqlite3_syscall_ptr pCall )
static
10156 {
10157 return ORIGVFS(pVfs)->xSetSystemCall(ORIGVFS(pVfs),zName,pCall);
10158}

References ORIGVFS.

◆ apndShmBarrier()

void apndShmBarrier ( sqlite3_file * pFile)
static
9927 {
9928 pFile = ORIGFILE(pFile);
9929 pFile->pMethods->xShmBarrier(pFile);
9930}
void(* xShmBarrier)(sqlite3_file *)
Definition sqlite3.c:1182

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xShmBarrier.

◆ apndShmLock()

int apndShmLock ( sqlite3_file * pFile,
int offset,
int n,
int flags )
static
9921 {
9922 pFile = ORIGFILE(pFile);
9923 return pFile->pMethods->xShmLock(pFile,offset,n,flags);
9924}
int(* xShmLock)(sqlite3_file *, int offset, int n, int flags)
Definition sqlite3.c:1181

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xShmLock.

◆ apndShmMap()

int apndShmMap ( sqlite3_file * pFile,
int iPg,
int pgsz,
int bExtend,
void volatile ** pp )
static
9915 {
9916 pFile = ORIGFILE(pFile);
9917 return pFile->pMethods->xShmMap(pFile,iPg,pgsz,bExtend,pp);
9918}
int(* xShmMap)(sqlite3_file *, int iPg, int pgsz, int, void volatile **)
Definition sqlite3.c:1180

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xShmMap.

◆ apndShmUnmap()

int apndShmUnmap ( sqlite3_file * pFile,
int deleteFlag )
static
9933 {
9934 pFile = ORIGFILE(pFile);
9935 return pFile->pMethods->xShmUnmap(pFile,deleteFlag);
9936}
int(* xShmUnmap)(sqlite3_file *, int deleteFlag)
Definition sqlite3.c:1183

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xShmUnmap.

◆ apndSleep()

int apndSleep ( sqlite3_vfs * pVfs,
int microseconds )
static
10140 {
10141 return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro);
10142}

References ORIGVFS.

◆ apndSync()

int apndSync ( sqlite3_file * pFile,
int flags )
static
9838 {
9839 pFile = ORIGFILE(pFile);
9840 return pFile->pMethods->xSync(pFile, flags);
9841}
int(* xSync)(sqlite3_file *, int flags)
Definition sqlite3.c:1171

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xSync.

◆ apndTruncate()

int apndTruncate ( sqlite3_file * pFile,
sqlite3_int64 size )
static
9826 {
9827 ApndFile *paf = (ApndFile *)pFile;
9828 pFile = ORIGFILE(pFile);
9829 /* The append mark goes out first so truncate failure does not lose it. */
9830 if( SQLITE_OK!=apndWriteMark(paf, pFile, size) ) return SQLITE_IOERR;
9831 /* Truncate underlying file just past append mark */
9832 return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
9833}
static int apndWriteMark(ApndFile *paf, sqlite3_file *pFile, sqlite_int64 iWriteEnd)
Definition shell.c:9779
int(* xTruncate)(sqlite3_file *, sqlite3_int64 size)
Definition sqlite3.c:1170

References APND_MARK_SIZE, apndWriteMark(), ApndFile::iMark, ORIGFILE, sqlite3_file::pMethods, SQLITE_IOERR, SQLITE_OK, and sqlite3_io_methods::xTruncate.

Here is the call graph for this function:

◆ apndUnfetch()

int apndUnfetch ( sqlite3_file * pFile,
sqlite3_int64 iOfst,
void * p )
static
9954 {
9955 ApndFile *p = (ApndFile *)pFile;
9956 pFile = ORIGFILE(pFile);
9957 return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
9958}
int(* xUnfetch)(sqlite3_file *, sqlite3_int64 iOfst, void *p)
Definition sqlite3.c:1186

References ApndFile::iPgOne, ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xUnfetch.

◆ apndUnlock()

int apndUnlock ( sqlite3_file * pFile,
int eLock )
static
9864 {
9865 pFile = ORIGFILE(pFile);
9866 return pFile->pMethods->xUnlock(pFile, eLock);
9867}
int(* xUnlock)(sqlite3_file *, int)
Definition sqlite3.c:1174

References ORIGFILE, sqlite3_file::pMethods, and sqlite3_io_methods::xUnlock.

◆ apndWrite()

int apndWrite ( sqlite3_file * pFile,
const void * zBuf,
int iAmt,
sqlite3_int64 iOfst )
static
9810 {
9811 ApndFile *paf = (ApndFile *)pFile;
9812 sqlite_int64 iWriteEnd = iOfst + iAmt;
9813 if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
9814 pFile = ORIGFILE(pFile);
9815 /* If append-mark is absent or will be overwritten, write it. */
9816 if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
9817 int rc = apndWriteMark(paf, pFile, iWriteEnd);
9818 if( SQLITE_OK!=rc ) return rc;
9819 }
9820 return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
9821}
#define APND_MAX_SIZE
Definition shell.c:9599
#define SQLITE_FULL
Definition sqlite3.c:779
long long int sqlite_int64
Definition sqlite3.c:620
int(* xWrite)(sqlite3_file *, const void *, int iAmt, sqlite3_int64 iOfst)
Definition sqlite3.c:1169

References APND_MAX_SIZE, apndWriteMark(), ApndFile::iMark, ApndFile::iPgOne, ORIGFILE, sqlite3_file::pMethods, SQLITE_FULL, SQLITE_OK, and sqlite3_io_methods::xWrite.

Here is the call graph for this function:

◆ apndWriteMark()

int apndWriteMark ( ApndFile * paf,
sqlite3_file * pFile,
sqlite_int64 iWriteEnd )
static
9783 {
9784 sqlite_int64 iPgOne = paf->iPgOne;
9785 unsigned char a[APND_MARK_SIZE];
9786 int i = APND_MARK_FOS_SZ;
9787 int rc;
9788 assert(pFile == ORIGFILE(paf));
9790 while( --i >= 0 ){
9791 a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
9792 iPgOne >>= 8;
9793 }
9794 iWriteEnd += paf->iPgOne;
9795 if( SQLITE_OK==(rc = pFile->pMethods->xWrite
9796 (pFile, a, APND_MARK_SIZE, iWriteEnd)) ){
9797 paf->iMark = iWriteEnd;
9798 }
9799 return rc;
9800}

References a, APND_MARK_FOS_SZ, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ, APND_MARK_SIZE, ApndFile::iMark, ApndFile::iPgOne, ORIGFILE, sqlite3_file::pMethods, SQLITE_OK, and sqlite3_io_methods::xWrite.

Referenced by apndTruncate(), and apndWrite().

Here is the caller graph for this function:

◆ appendText()

void appendText ( ShellText * p,
const char * zAppend,
char quote )
static
1486 {
1487 i64 len;
1488 i64 i;
1489 i64 nAppend = strlen30(zAppend);
1490
1491 len = nAppend+p->n+1;
1492 if( quote ){
1493 len += 2;
1494 for(i=0; i<nAppend; i++){
1495 if( zAppend[i]==quote ) len++;
1496 }
1497 }
1498
1499 if( p->z==0 || p->n+len>=p->nAlloc ){
1500 p->nAlloc = p->nAlloc*2 + len + 20;
1501 p->z = realloc(p->z, p->nAlloc);
1502 shell_check_oom(p->z);
1503 }
1504
1505 if( quote ){
1506 char *zCsr = p->z+p->n;
1507 *zCsr++ = quote;
1508 for(i=0; i<nAppend; i++){
1509 *zCsr++ = zAppend[i];
1510 if( zAppend[i]==quote ) *zCsr++ = quote;
1511 }
1512 *zCsr++ = quote;
1513 p->n = (int)(zCsr - p->z);
1514 *zCsr = '\0';
1515 }else{
1516 memcpy(p->z+p->n, zAppend, nAppend);
1517 p->n += nAppend;
1518 p->z[p->n] = '\0';
1519 }
1520}
static int strlen30(const char *z)
Definition shell.c:1263
int nAlloc
Definition shell.c:1464
int n
Definition shell.c:1463
static void shell_check_oom(const void *p)
Definition shell.c:977
sqlite3_int64 i64
Definition shell.c:122
char * z
Definition shell.c:1462

References ShellText::n, ShellText::nAlloc, shell_check_oom(), strlen30(), and ShellText::z.

Referenced by captureOutputCallback(), do_meta_command(), dump_callback(), and shellFakeSchema().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_read_one_field()

char * ascii_read_one_field ( ImportCtx * p)
static
26599 {
26600 int c;
26601 int cSep = (u8)p->cColSep;
26602 int rSep = (u8)p->cRowSep;
26603 p->n = 0;
26604 c = fgetc(p->in);
26605 if( c==EOF || seenInterrupt ){
26606 p->cTerm = EOF;
26607 return 0;
26608 }
26609 while( c!=EOF && c!=cSep && c!=rSep ){
26611 c = fgetc(p->in);
26612 }
26613 if( c==rSep ){
26614 p->nLine++;
26615 }
26616 p->cTerm = c;
26617 if( p->z ) p->z[p->n] = 0;
int cTerm
Definition shell.c:26469
int cColSep
Definition shell.c:26470
FILE * in
Definition shell.c:26460
int nLine
Definition shell.c:26465
static void import_append_char(ImportCtx *p, int c)
Definition shell.c:26485
int n
Definition shell.c:26463
int cRowSep
Definition shell.c:26471
static volatile int seenInterrupt
Definition shell.c:844
char * z
Definition shell.c:26462

References c, ImportCtx::cColSep, ImportCtx::cRowSep, ImportCtx::cTerm, import_append_char(), ImportCtx::in, ImportCtx::n, ImportCtx::nLine, seenInterrupt, SQLITE_CDECL, and ImportCtx::z.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ base64()

void base64 ( sqlite3_context * context,
int na,
sqlite3_value * av[] )
static
5302 {
5303 int nb, nc, nv = sqlite3_value_bytes(av[0]);
5304 int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
5306 char *cBuf;
5307 u8 *bBuf;
5308 assert(na==1);
5309 switch( sqlite3_value_type(av[0]) ){
5310 case SQLITE_BLOB:
5311 nb = nv;
5312 nc = 4*(nv+2/3); /* quads needed */
5313 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
5314 if( nvMax < nc ){
5315 sqlite3_result_error(context, "blob expanded to base64 too big", -1);
5316 return;
5317 }
5318 bBuf = (u8*)sqlite3_value_blob(av[0]);
5319 if( !bBuf ){
5321 goto memFail;
5322 }
5323 sqlite3_result_text(context,"",-1,SQLITE_STATIC);
5324 break;
5325 }
5326 cBuf = sqlite3_malloc(nc);
5327 if( !cBuf ) goto memFail;
5328 nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf);
5329 sqlite3_result_text(context, cBuf, nc, sqlite3_free);
5330 break;
5331 case SQLITE_TEXT:
5332 nc = nv;
5333 nb = 3*((nv+3)/4); /* may overestimate due to LF and padding */
5334 if( nvMax < nb ){
5335 sqlite3_result_error(context, "blob from base64 may be too big", -1);
5336 return;
5337 }else if( nb<1 ){
5338 nb = 1;
5339 }
5340 cBuf = (char *)sqlite3_value_text(av[0]);
5341 if( !cBuf ){
5343 goto memFail;
5344 }
5345 sqlite3_result_zeroblob(context, 0);
5346 break;
5347 }
5348 bBuf = sqlite3_malloc(nb);
5349 if( !bBuf ) goto memFail;
5350 nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf);
5351 sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
5352 break;
5353 default:
5354 sqlite3_result_error(context, "base64 accepts only blob or text", -1);
5355 return;
5356 }
5357 return;
5358 memFail:
5359 sqlite3_result_error(context, "base64 OOM", -1);
5360}
#define B64_DARK_MAX
Definition shell.c:5202
static char * toBase64(u8 *pIn, int nbIn, char *pOut)
Definition shell.c:5207
static u8 * fromBase64(char *pIn, int ncIn, u8 *pOut)
Definition shell.c:5251
#define SQLITE_BLOB
Definition sqlite3.c:5564
#define SQLITE_STATIC
Definition sqlite3.c:6586
#define SQLITE_NOMEM
Definition sqlite3.c:773
#define SQLITE_TEXT
Definition sqlite3.c:5569
#define SQLITE_LIMIT_LENGTH
Definition sqlite3.c:4641
#define sqlite3_result_error
Definition sqlite3ext.h:484
#define sqlite3_free
Definition sqlite3ext.h:458
#define sqlite3_result_text
Definition sqlite3ext.h:489
#define sqlite3_value_blob
Definition sqlite3ext.h:508
#define sqlite3_malloc
Definition sqlite3ext.h:470
#define sqlite3_errcode
Definition sqlite3ext.h:450
#define sqlite3_result_zeroblob
Definition sqlite3ext.h:551
#define sqlite3_value_text
Definition sqlite3ext.h:515
#define sqlite3_result_blob
Definition sqlite3ext.h:482
#define sqlite3_value_bytes
Definition sqlite3ext.h:509
#define sqlite3_value_type
Definition sqlite3ext.h:519
#define sqlite3_limit
Definition sqlite3ext.h:557
#define sqlite3_context_db_handle
Definition sqlite3ext.h:555

References B64_DARK_MAX, fromBase64(), sqlite3_context_db_handle, sqlite3_errcode, sqlite3_free, sqlite3_limit, sqlite3_malloc, sqlite3_result_blob, sqlite3_result_error, sqlite3_result_text, sqlite3_result_zeroblob, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_text, sqlite3_value_type, SQLITE_BLOB, SQLITE_LIMIT_LENGTH, SQLITE_NOMEM, SQLITE_STATIC, SQLITE_TEXT, and toBase64().

Referenced by sqlite3_base64_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ base85()

void base85 ( sqlite3_context * context,
int na,
sqlite3_value * av[] )
static
5682 {
5683 int nb, nc, nv = sqlite3_value_bytes(av[0]);
5684 int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
5686 char *cBuf;
5687 u8 *bBuf;
5688 assert(na==1);
5689 switch( sqlite3_value_type(av[0]) ){
5690 case SQLITE_BLOB:
5691 nb = nv;
5692 /* ulongs tail newlines tailenc+nul*/
5693 nc = 5*(nv/4) + nv%4 + nv/64+1 + 2;
5694 if( nvMax < nc ){
5695 sqlite3_result_error(context, "blob expanded to base85 too big", -1);
5696 return;
5697 }
5698 bBuf = (u8*)sqlite3_value_blob(av[0]);
5699 if( !bBuf ){
5701 goto memFail;
5702 }
5703 sqlite3_result_text(context,"",-1,SQLITE_STATIC);
5704 break;
5705 }
5706 cBuf = sqlite3_malloc(nc);
5707 if( !cBuf ) goto memFail;
5708 nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf);
5709 sqlite3_result_text(context, cBuf, nc, sqlite3_free);
5710 break;
5711 case SQLITE_TEXT:
5712 nc = nv;
5713 nb = 4*(nv/5) + nv%5; /* may overestimate */
5714 if( nvMax < nb ){
5715 sqlite3_result_error(context, "blob from base85 may be too big", -1);
5716 return;
5717 }else if( nb<1 ){
5718 nb = 1;
5719 }
5720 cBuf = (char *)sqlite3_value_text(av[0]);
5721 if( !cBuf ){
5723 goto memFail;
5724 }
5725 sqlite3_result_zeroblob(context, 0);
5726 break;
5727 }
5728 bBuf = sqlite3_malloc(nb);
5729 if( !bBuf ) goto memFail;
5730 nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf);
5731 sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
5732 break;
5733 default:
5734 sqlite3_result_error(context, "base85 accepts only blob or text.", -1);
5735 return;
5736 }
5737 return;
5738 memFail:
5739 sqlite3_result_error(context, "base85 OOM", -1);
5740}
static char * toBase85(u8 *pIn, int nbIn, char *pOut, char *pSep)
Definition shell.c:5564
static u8 * fromBase85(char *pIn, int ncIn, u8 *pOut)
Definition shell.c:5605

References fromBase85(), sqlite3_context_db_handle, sqlite3_errcode, sqlite3_free, sqlite3_limit, sqlite3_malloc, sqlite3_result_blob, sqlite3_result_error, sqlite3_result_text, sqlite3_result_zeroblob, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_text, sqlite3_value_type, SQLITE_BLOB, SQLITE_LIMIT_LENGTH, SQLITE_NOMEM, SQLITE_STATIC, SQLITE_TEXT, and toBase85().

Referenced by sqlite3_base85_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginTimer()

void beginTimer ( void )
static
688 {
689 if( enableTimer ){
690 getrusage(RUSAGE_SELF, &sBegin);
691 iBegin = timeOfDay();
692 }
693}
static struct rusage sBegin
Definition shell.c:682
static sqlite3_int64 iBegin
Definition shell.c:683
static int enableTimer
Definition shell.c:637
static sqlite3_int64 timeOfDay(void)
Definition shell.c:652

References enableTimer, iBegin, sBegin, and timeOfDay().

Here is the call graph for this function:

◆ bind_prepared_stmt()

void bind_prepared_stmt ( ShellState * pArg,
sqlite3_stmt * pStmt )
static
24062 {
24063 int nVar;
24064 int i;
24065 int rc;
24066 sqlite3_stmt *pQ = 0;
24067
24068 nVar = sqlite3_bind_parameter_count(pStmt);
24069 if( nVar==0 ) return; /* Nothing to do */
24070 if( sqlite3_table_column_metadata(pArg->db, "TEMP", "sqlite_parameters",
24071 "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
24072 rc = SQLITE_NOTFOUND;
24073 pQ = 0;
24074 }else{
24075 rc = sqlite3_prepare_v2(pArg->db,
24076 "SELECT value FROM temp.sqlite_parameters"
24077 " WHERE key=?1", -1, &pQ, 0);
24078 }
24079 for(i=1; i<=nVar; i++){
24080 char zNum[30];
24081 const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
24082 if( zVar==0 ){
24083 sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
24084 zVar = zNum;
24085 }
24086 sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
24087 if( rc==SQLITE_OK && pQ && sqlite3_step(pQ)==SQLITE_ROW ){
24088 sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
24089#ifdef NAN
24090 }else if( sqlite3_strlike("_NAN", zVar, 0)==0 ){
24091 sqlite3_bind_double(pStmt, i, NAN);
24092#endif
24093#ifdef INFINITY
24094 }else if( sqlite3_strlike("_INF", zVar, 0)==0 ){
24095 sqlite3_bind_double(pStmt, i, INFINITY);
24096#endif
24097 }else if( strncmp(zVar, "$int_", 5)==0 ){
24098 sqlite3_bind_int(pStmt, i, atoi(&zVar[5]));
24099 }else if( strncmp(zVar, "$text_", 6)==0 ){
24100 size_t szVar = strlen(zVar);
24101 char *zBuf = sqlite3_malloc64( szVar-5 );
24102 if( zBuf ){
24103 memcpy(zBuf, &zVar[6], szVar-5);
24104 sqlite3_bind_text64(pStmt, i, zBuf, szVar-6, sqlite3_free, SQLITE_UTF8);
24105 }
24106 }else{
24107 sqlite3_bind_null(pStmt, i);
24108 }
24109 sqlite3_reset(pQ);
24110 }
sqlite3 * db
Definition shell.c:21670
#define SQLITE_NOTFOUND
Definition sqlite3.c:778
#define SQLITE_ROW
Definition sqlite3.c:795
#define SQLITE_UTF8
Definition sqlite3.c:6038
struct sqlite3_stmt sqlite3_stmt
Definition sqlite3.c:4541
#define sqlite3_reset
Definition sqlite3ext.h:481
#define sqlite3_malloc64
Definition sqlite3ext.h:605
#define sqlite3_step
Definition sqlite3ext.h:498
#define sqlite3_snprintf
Definition sqlite3ext.h:497
#define sqlite3_table_column_metadata
Definition sqlite3ext.h:499
#define sqlite3_bind_double
Definition sqlite3ext.h:400
#define sqlite3_bind_int
Definition sqlite3ext.h:401
#define sqlite3_bind_value
Definition sqlite3ext.h:409
#define sqlite3_strlike
Definition sqlite3ext.h:622
#define sqlite3_column_value
Definition sqlite3ext.h:436
#define sqlite3_bind_text64
Definition sqlite3ext.h:602
#define sqlite3_bind_null
Definition sqlite3ext.h:403
#define sqlite3_prepare_v2
Definition sqlite3ext.h:476
#define sqlite3_bind_parameter_count
Definition sqlite3ext.h:404
#define sqlite3_bind_text
Definition sqlite3ext.h:407
#define sqlite3_bind_parameter_name
Definition sqlite3ext.h:406

References ShellState::db, sqlite3_bind_double, sqlite3_bind_int, sqlite3_bind_null, sqlite3_bind_parameter_count, sqlite3_bind_parameter_name, sqlite3_bind_text, sqlite3_bind_text64, sqlite3_bind_value, sqlite3_column_value, sqlite3_finalize, sqlite3_free, sqlite3_malloc64, sqlite3_prepare_v2, sqlite3_reset, sqlite3_snprintf, sqlite3_step, sqlite3_strlike, sqlite3_table_column_metadata, SQLITE_NOTFOUND, SQLITE_OK, SQLITE_ROW, SQLITE_STATIC, and SQLITE_UTF8.

Referenced by do_meta_command(), and shell_exec().

Here is the caller graph for this function:

◆ bind_table_init()

void bind_table_init ( ShellState * p)
static
24033 {
24034 int wrSchema = 0;
24035 int defensiveMode = 0;
24036 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
24040 sqlite3_exec(p->db,
24041 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
24042 " key TEXT PRIMARY KEY,\n"
24043 " value\n"
24044 ") WITHOUT ROWID;",
24045 0, 0, 0);
#define SQLITE_DBCONFIG_DEFENSIVE
Definition sqlite3.c:2977
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA
Definition sqlite3.c:2978
#define sqlite3_db_config
Definition sqlite3ext.h:569
#define sqlite3_exec
Definition sqlite3ext.h:453

References ShellState::db, sqlite3_db_config, sqlite3_exec, SQLITE_DBCONFIG_DEFENSIVE, and SQLITE_DBCONFIG_WRITABLE_SCHEMA.

Referenced by do_meta_command().

Here is the caller graph for this function:

◆ booleanValue()

int booleanValue ( const char * zArg)
static
26324 {
26325 int i;
26326 if( zArg[0]=='0' && zArg[1]=='x' ){
26327 for(i=2; hexDigitValue(zArg[i])>=0; i++){}
26328 }else{
26329 for(i=0; zArg[i]>='0' && zArg[i]<='9'; i++){}
26330 }
26331 if( i>0 && zArg[i]==0 ) return (int)(integerValue(zArg) & 0xffffffff);
26332 if( sqlite3_stricmp(zArg, "on")==0 || sqlite3_stricmp(zArg,"yes")==0 ){
26333 return 1;
26334 }
26335 if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){
26336 return 0;
26337 }
26338 sqlite3_fprintf(stderr,
26339 "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n", zArg);
#define sqlite3_fprintf
Definition shell.c:306
static sqlite3_int64 integerValue(const char *zArg)
Definition shell.c:1414
static int hexDigitValue(char c)
Definition shell.c:1404
#define sqlite3_stricmp
Definition sqlite3ext.h:593

References hexDigitValue(), integerValue(), sqlite3_fprintf, and sqlite3_stricmp.

Referenced by do_meta_command(), and setOrClearFlag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback()

int callback ( void * pArg,
int nArg,
char ** azArg,
char ** azCol )
static
23308 {
23309 /* since we don't have type info, call the shell_callback with a NULL value */

References shell_callback().

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ captureOutputCallback()

int captureOutputCallback ( void * pArg,
int nArg,
char ** azArg,
char ** az )
static
23317 {
23318 ShellText *p = (ShellText*)pArg;
23319 int i;
23320 UNUSED_PARAMETER(az);
23321 if( azArg==0 ) return 0;
23322 if( p->n ) appendText(p, "|", 0);
23323 for(i=0; i<nArg; i++){
23324 if( i ) appendText(p, ",", 0);
23325 if( azArg[i] ) appendText(p, azArg[i], 0);
23326 }
#define UNUSED_PARAMETER(x)
Definition shell.c:808
static void appendText(ShellText *p, const char *zAppend, char quote)
Definition shell.c:1486
Definition shell.c:1461

References appendText(), ShellText::n, and UNUSED_PARAMETER.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearTempFile()

void clearTempFile ( ShellState * p)
static
27275 {
27276 if( p->zTempFile==0 ) return;
27277 if( p->doXdgOpen ) return;
27278 if( shellDeleteFile(p->zTempFile) ) return;
u8 doXdgOpen
Definition shell.c:21677
char * zTempFile
Definition shell.c:21711
int shellDeleteFile(const char *zFilename)
Definition shell.c:27257

References ShellState::doXdgOpen, shellDeleteFile(), sqlite3_free, and ShellState::zTempFile.

Referenced by do_meta_command(), main(), newTempFile(), and process_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cli_strcmp()

int cli_strcmp ( const char * a,
const char * b )
static
640 {
641 if( a==0 ) a = "";
642 if( b==0 ) b = "";
643 return strcmp(a,b);
644}

References a, and b.

Referenced by do_meta_command(), dump_callback(), main(), optionMatch(), output_file_open(), showHelp(), and str_in_array().

Here is the caller graph for this function:

◆ cli_strncmp()

int cli_strncmp ( const char * a,
const char * b,
size_t n )
static
645 {
646 if( a==0 ) a = "";
647 if( b==0 ) b = "";
648 return strncmp(a,b,n);
649}

References a, and b.

Referenced by do_meta_command(), dump_callback(), expertDotCommand(), main(), readHexDb(), runOneSqlLine(), and shellAddSchemaName().

Here is the caller graph for this function:

◆ cli_wcwidth()

int cli_wcwidth ( int c)
1088 {
1089 int iFirst, iLast;
1090
1091 /* Fast path for common characters */
1092 if( c<=0x300 ) return 1;
1093
1094 /* The general case */
1095 iFirst = 0;
1096 iLast = sizeof(aUWidth)/sizeof(aUWidth[0]) - 1;
1097 while( iFirst<iLast-1 ){
1098 int iMid = (iFirst+iLast)/2;
1099 int cMid = aUWidth[iMid].iFirst;
1100 if( cMid < c ){
1101 iFirst = iMid;
1102 }else if( cMid > c ){
1103 iLast = iMid - 1;
1104 }else{
1105 return aUWidth[iMid].w;
1106 }
1107 }
1108 if( aUWidth[iLast].iFirst > c ) return aUWidth[iFirst].w;
1109 return aUWidth[iLast].w;
1110}
static const struct @244007321120050323347230266016106212070356246363 aUWidth[]

References aUWidth, and c.

Referenced by translateForDisplayAndDup(), and utf8_width_print().

Here is the caller graph for this function:

◆ close_db()

void close_db ( sqlite3 * db)
26162 {
26163 int rc = sqlite3_close(db);
26164 if( rc ){
26165 sqlite3_fprintf(stderr,
26166 "Error: sqlite3_close() returns %d: %s\n", rc, sqlite3_errmsg(db));
#define sqlite3_errmsg
Definition sqlite3ext.h:451
#define sqlite3_close
Definition sqlite3ext.h:413

References sqlite3_close, sqlite3_errmsg, and sqlite3_fprintf.

Referenced by do_meta_command(), main(), and tryToClone().

Here is the caller graph for this function:

◆ cmdline_option_value()

char * cmdline_option_value ( int argc,
char ** argv,
int i )
static
33174 {
33175 if( i==argc ){
33176 sqlite3_fprintf(stderr,
33177 "%s: Error: missing argument to %s\n", argv[0], argv[argc-1]);
33178 exit(1);
33179 }

References sqlite3_fprintf.

Referenced by main().

Here is the caller graph for this function:

◆ completionBestIndex()

int completionBestIndex ( sqlite3_vtab * tab,
sqlite3_index_info * pIdxInfo )
static
9430 {
9431 int i; /* Loop over constraints */
9432 int idxNum = 0; /* The query plan bitmask */
9433 int prefixIdx = -1; /* Index of the start= constraint, or -1 if none */
9434 int wholelineIdx = -1; /* Index of the stop= constraint, or -1 if none */
9435 int nArg = 0; /* Number of arguments that completeFilter() expects */
9436 const struct sqlite3_index_constraint *pConstraint;
9437
9438 (void)(tab); /* Unused parameter */
9439 pConstraint = pIdxInfo->aConstraint;
9440 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
9441 if( pConstraint->usable==0 ) continue;
9442 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
9443 switch( pConstraint->iColumn ){
9445 prefixIdx = i;
9446 idxNum |= 1;
9447 break;
9449 wholelineIdx = i;
9450 idxNum |= 2;
9451 break;
9452 }
9453 }
9454 if( prefixIdx>=0 ){
9455 pIdxInfo->aConstraintUsage[prefixIdx].argvIndex = ++nArg;
9456 pIdxInfo->aConstraintUsage[prefixIdx].omit = 1;
9457 }
9458 if( wholelineIdx>=0 ){
9459 pIdxInfo->aConstraintUsage[wholelineIdx].argvIndex = ++nArg;
9460 pIdxInfo->aConstraintUsage[wholelineIdx].omit = 1;
9461 }
9462 pIdxInfo->idxNum = idxNum;
9463 pIdxInfo->estimatedCost = (double)5000 - 1000*nArg;
9464 pIdxInfo->estimatedRows = 500 - 100*nArg;
9465 return SQLITE_OK;
9466}
#define COMPLETION_COLUMN_PREFIX
#define COMPLETION_COLUMN_WHOLELINE
#define SQLITE_INDEX_CONSTRAINT_EQ
Definition sqlite3.c:8066
struct sqlite3_index_info::sqlite3_index_constraint * aConstraint
struct sqlite3_index_info::sqlite3_index_constraint_usage * aConstraintUsage
double estimatedCost
Definition sqlite3.c:8008
unsigned char omit
Definition sqlite3.c:8002
sqlite3_int64 estimatedRows
Definition sqlite3.c:8010
int nConstraint
Definition sqlite3.c:7987
int idxNum
Definition sqlite3.c:8004

References sqlite3_index_info::aConstraint, sqlite3_index_info::aConstraintUsage, sqlite3_index_info::sqlite3_index_constraint_usage::argvIndex, COMPLETION_COLUMN_PREFIX, COMPLETION_COLUMN_WHOLELINE, sqlite3_index_info::estimatedCost, sqlite3_index_info::estimatedRows, sqlite3_index_info::idxNum, sqlite3_index_info::nConstraint, sqlite3_index_info::sqlite3_index_constraint_usage::omit, SQLITE_INDEX_CONSTRAINT_EQ, and SQLITE_OK.

◆ completionClose()

int completionClose ( sqlite3_vtab_cursor * cur)
static
9196 {
9198 sqlite3_free(cur);
9199 return SQLITE_OK;
9200}
static void completionCursorReset(completion_cursor *pCur)
Definition shell.c:9186
Definition shell.c:9081

References completionCursorReset(), sqlite3_free, and SQLITE_OK.

Here is the call graph for this function:

◆ completionColumn()

int completionColumn ( sqlite3_vtab_cursor * cur,
sqlite3_context * ctx,
int i )
static
9328 {
9330 switch( i ){
9333 break;
9334 }
9337 break;
9338 }
9341 break;
9342 }
9344 sqlite3_result_int(ctx, pCur->ePhase);
9345 break;
9346 }
9347 }
9348 return SQLITE_OK;
9349}
int szRow
Definition shell.c:9088
#define COMPLETION_COLUMN_PHASE
char * zPrefix
Definition shell.c:9085
#define COMPLETION_COLUMN_CANDIDATE
char * zLine
Definition shell.c:9086
const char * zCurrentRow
Definition shell.c:9087
int ePhase
Definition shell.c:9091
#define SQLITE_TRANSIENT
Definition sqlite3.c:6587
#define sqlite3_result_int
Definition sqlite3ext.h:486

References COMPLETION_COLUMN_CANDIDATE, COMPLETION_COLUMN_PHASE, COMPLETION_COLUMN_PREFIX, COMPLETION_COLUMN_WHOLELINE, completion_cursor::ePhase, sqlite3_result_int, sqlite3_result_text, SQLITE_OK, SQLITE_TRANSIENT, completion_cursor::szRow, completion_cursor::zCurrentRow, completion_cursor::zLine, and completion_cursor::zPrefix.

◆ completionConnect()

int completionConnect ( sqlite3 * db,
void * pAux,
int argc,
const char *const * argv,
sqlite3_vtab ** ppVtab,
char ** pzErr )
static
9129 {
9130 completion_vtab *pNew;
9131 int rc;
9132
9133 (void)(pAux); /* Unused parameter */
9134 (void)(argc); /* Unused parameter */
9135 (void)(argv); /* Unused parameter */
9136 (void)(pzErr); /* Unused parameter */
9137
9138/* Column numbers */
9139#define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
9140#define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
9141#define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
9142#define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
9143
9145 rc = sqlite3_declare_vtab(db,
9146 "CREATE TABLE x("
9147 " candidate TEXT,"
9148 " prefix TEXT HIDDEN,"
9149 " wholeline TEXT HIDDEN,"
9150 " phase INT HIDDEN" /* Used for debugging only */
9151 ")");
9152 if( rc==SQLITE_OK ){
9153 pNew = sqlite3_malloc( sizeof(*pNew) );
9154 *ppVtab = (sqlite3_vtab*)pNew;
9155 if( pNew==0 ) return SQLITE_NOMEM;
9156 memset(pNew, 0, sizeof(*pNew));
9157 pNew->db = db;
9158 }
9159 return rc;
9160}
sqlite3 * db
Definition shell.c:9073
Definition shell.c:9071
#define SQLITE_VTAB_INNOCUOUS
Definition sqlite3.c:10379
Definition sqlite3.c:8165
#define sqlite3_vtab_config
Definition sqlite3ext.h:583
#define sqlite3_declare_vtab
Definition sqlite3ext.h:448

References completion_vtab::db, sqlite3_declare_vtab, sqlite3_malloc, sqlite3_vtab_config, SQLITE_NOMEM, SQLITE_OK, and SQLITE_VTAB_INNOCUOUS.

◆ completionCursorReset()

void completionCursorReset ( completion_cursor * pCur)
static
9186 {
9187 sqlite3_free(pCur->zPrefix); pCur->zPrefix = 0; pCur->nPrefix = 0;
9188 sqlite3_free(pCur->zLine); pCur->zLine = 0; pCur->nLine = 0;
9189 sqlite3_finalize(pCur->pStmt); pCur->pStmt = 0;
9190 pCur->j = 0;
9191}
int nLine
Definition shell.c:9084
int nPrefix
Definition shell.c:9084
int j
Definition shell.c:9092
sqlite3_stmt * pStmt
Definition shell.c:9089
#define sqlite3_finalize
Definition sqlite3ext.h:457

References completion_cursor::j, completion_cursor::nLine, completion_cursor::nPrefix, completion_cursor::pStmt, sqlite3_finalize, sqlite3_free, completion_cursor::zLine, and completion_cursor::zPrefix.

Referenced by completionClose(), and completionFilter().

Here is the caller graph for this function:

◆ completionDisconnect()

int completionDisconnect ( sqlite3_vtab * pVtab)
static
9165 {
9166 sqlite3_free(pVtab);
9167 return SQLITE_OK;
9168}

References sqlite3_free, and SQLITE_OK.

◆ completionEof()

int completionEof ( sqlite3_vtab_cursor * cur)
static
9365 {
9367 return pCur->ePhase >= COMPLETION_EOF;
9368}
#define COMPLETION_EOF
Definition shell.c:9108

References COMPLETION_EOF, and completion_cursor::ePhase.

◆ completionFilter()

int completionFilter ( sqlite3_vtab_cursor * pVtabCursor,
int idxNum,
const char * idxStr,
int argc,
sqlite3_value ** argv )
static
9380 {
9381 completion_cursor *pCur = (completion_cursor *)pVtabCursor;
9382 int iArg = 0;
9383 (void)(idxStr); /* Unused parameter */
9384 (void)(argc); /* Unused parameter */
9386 if( idxNum & 1 ){
9387 pCur->nPrefix = sqlite3_value_bytes(argv[iArg]);
9388 if( pCur->nPrefix>0 ){
9389 pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
9390 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
9391 }
9392 iArg = 1;
9393 }
9394 if( idxNum & 2 ){
9395 pCur->nLine = sqlite3_value_bytes(argv[iArg]);
9396 if( pCur->nLine>0 ){
9397 pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
9398 if( pCur->zLine==0 ) return SQLITE_NOMEM;
9399 }
9400 }
9401 if( pCur->zLine!=0 && pCur->zPrefix==0 ){
9402 int i = pCur->nLine;
9403 while( i>0 && (IsAlnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){
9404 i--;
9405 }
9406 pCur->nPrefix = pCur->nLine - i;
9407 if( pCur->nPrefix>0 ){
9408 pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
9409 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
9410 }
9411 }
9412 pCur->iRowid = 0;
9414 return completionNext(pVtabCursor);
9415}
static int completionNext(sqlite3_vtab_cursor *cur)
Definition shell.c:9216
sqlite3_int64 iRowid
Definition shell.c:9090
#define IsAlnum(X)
Definition shell.c:239
#define COMPLETION_FIRST_PHASE
Definition shell.c:9097

References COMPLETION_FIRST_PHASE, completionCursorReset(), completionNext(), completion_cursor::ePhase, completion_cursor::iRowid, IsAlnum, completion_cursor::nLine, completion_cursor::nPrefix, sqlite3_mprintf, sqlite3_value_bytes, sqlite3_value_text, SQLITE_NOMEM, completion_cursor::zLine, and completion_cursor::zPrefix.

Here is the call graph for this function:

◆ completionNext()

int completionNext ( sqlite3_vtab_cursor * cur)
static
9216 {
9218 int eNextPhase = 0; /* Next phase to try if current phase reaches end */
9219 int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */
9220 pCur->iRowid++;
9221 while( pCur->ePhase!=COMPLETION_EOF ){
9222 switch( pCur->ePhase ){
9223 case COMPLETION_KEYWORDS: {
9224 if( pCur->j >= sqlite3_keyword_count() ){
9225 pCur->zCurrentRow = 0;
9227 }else{
9228 sqlite3_keyword_name(pCur->j++, &pCur->zCurrentRow, &pCur->szRow);
9229 }
9230 iCol = -1;
9231 break;
9232 }
9233 case COMPLETION_DATABASES: {
9234 if( pCur->pStmt==0 ){
9235 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1,
9236 &pCur->pStmt, 0);
9237 }
9238 iCol = 1;
9239 eNextPhase = COMPLETION_TABLES;
9240 break;
9241 }
9242 case COMPLETION_TABLES: {
9243 if( pCur->pStmt==0 ){
9244 sqlite3_stmt *pS2;
9245 char *zSql = 0;
9246 const char *zSep = "";
9247 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
9248 while( sqlite3_step(pS2)==SQLITE_ROW ){
9249 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
9250 zSql = sqlite3_mprintf(
9251 "%z%s"
9252 "SELECT name FROM \"%w\".sqlite_schema",
9253 zSql, zSep, zDb
9254 );
9255 if( zSql==0 ) return SQLITE_NOMEM;
9256 zSep = " UNION ";
9257 }
9258 sqlite3_finalize(pS2);
9259 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
9260 sqlite3_free(zSql);
9261 }
9262 iCol = 0;
9263 eNextPhase = COMPLETION_COLUMNS;
9264 break;
9265 }
9266 case COMPLETION_COLUMNS: {
9267 if( pCur->pStmt==0 ){
9268 sqlite3_stmt *pS2;
9269 char *zSql = 0;
9270 const char *zSep = "";
9271 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
9272 while( sqlite3_step(pS2)==SQLITE_ROW ){
9273 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
9274 zSql = sqlite3_mprintf(
9275 "%z%s"
9276 "SELECT pti.name FROM \"%w\".sqlite_schema AS sm"
9277 " JOIN pragma_table_xinfo(sm.name,%Q) AS pti"
9278 " WHERE sm.type='table'",
9279 zSql, zSep, zDb, zDb
9280 );
9281 if( zSql==0 ) return SQLITE_NOMEM;
9282 zSep = " UNION ";
9283 }
9284 sqlite3_finalize(pS2);
9285 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
9286 sqlite3_free(zSql);
9287 }
9288 iCol = 0;
9289 eNextPhase = COMPLETION_EOF;
9290 break;
9291 }
9292 }
9293 if( iCol<0 ){
9294 /* This case is when the phase presets zCurrentRow */
9295 if( pCur->zCurrentRow==0 ) continue;
9296 }else{
9297 if( sqlite3_step(pCur->pStmt)==SQLITE_ROW ){
9298 /* Extract the next row of content */
9299 pCur->zCurrentRow = (const char*)sqlite3_column_text(pCur->pStmt, iCol);
9300 pCur->szRow = sqlite3_column_bytes(pCur->pStmt, iCol);
9301 }else{
9302 /* When all rows are finished, advance to the next phase */
9303 sqlite3_finalize(pCur->pStmt);
9304 pCur->pStmt = 0;
9305 pCur->ePhase = eNextPhase;
9306 continue;
9307 }
9308 }
9309 if( pCur->nPrefix==0 ) break;
9310 if( pCur->nPrefix<=pCur->szRow
9311 && sqlite3_strnicmp(pCur->zPrefix, pCur->zCurrentRow, pCur->nPrefix)==0
9312 ){
9313 break;
9314 }
9315 }
9316
9317 return SQLITE_OK;
9318}
sqlite3 * db
Definition shell.c:9083
#define COMPLETION_DATABASES
Definition shell.c:9104
#define COMPLETION_COLUMNS
Definition shell.c:9106
#define COMPLETION_KEYWORDS
Definition shell.c:9098
#define COMPLETION_TABLES
Definition shell.c:9105
#define sqlite3_keyword_name
Definition sqlite3ext.h:643
#define sqlite3_column_bytes
Definition sqlite3ext.h:417
#define sqlite3_strnicmp
Definition sqlite3ext.h:577
#define sqlite3_keyword_count
Definition sqlite3ext.h:642
#define sqlite3_column_text
Definition sqlite3ext.h:433

References COMPLETION_COLUMNS, COMPLETION_DATABASES, COMPLETION_EOF, COMPLETION_KEYWORDS, COMPLETION_TABLES, completion_cursor::db, completion_cursor::ePhase, completion_cursor::iRowid, completion_cursor::j, completion_cursor::nPrefix, completion_cursor::pStmt, sqlite3_column_bytes, sqlite3_column_text, sqlite3_finalize, sqlite3_free, sqlite3_keyword_count, sqlite3_keyword_name, sqlite3_mprintf, sqlite3_prepare_v2, sqlite3_step, sqlite3_strnicmp, SQLITE_NOMEM, SQLITE_OK, SQLITE_ROW, completion_cursor::szRow, completion_cursor::zCurrentRow, and completion_cursor::zPrefix.

Referenced by completionFilter().

Here is the caller graph for this function:

◆ completionOpen()

int completionOpen ( sqlite3_vtab * p,
sqlite3_vtab_cursor ** ppCursor )
static
9173 {
9174 completion_cursor *pCur;
9175 pCur = sqlite3_malloc( sizeof(*pCur) );
9176 if( pCur==0 ) return SQLITE_NOMEM;
9177 memset(pCur, 0, sizeof(*pCur));
9178 pCur->db = ((completion_vtab*)p)->db;
9179 *ppCursor = &pCur->base;
9180 return SQLITE_OK;
9181}
sqlite3_vtab_cursor base
Definition shell.c:9082

References completion_cursor::base, completion_cursor::db, sqlite3_malloc, SQLITE_NOMEM, and SQLITE_OK.

◆ completionRowid()

int completionRowid ( sqlite3_vtab_cursor * cur,
sqlite_int64 * pRowid )
static
9355 {
9357 *pRowid = pCur->iRowid;
9358 return SQLITE_OK;
9359}

References completion_cursor::iRowid, and SQLITE_OK.

◆ countNonzeros()

int countNonzeros ( void * pCount,
int nc,
char * azResults[],
char * azColumns[] )
static
13710 {
13711 (void)azColumns; /* Suppress unused parameter warning */
13712 if( nc>0 && (azResults[0][0]!='0' || azResults[0][1]!=0) ){
13713 *((int *)pCount) += 1;
13714 }
13715 return 0;
13716}

Referenced by idxCreateFromCons().

Here is the caller graph for this function:

◆ createSelftestTable()

void createSelftestTable ( ShellState * p)
static
23333 {
23334 char *zErrMsg = 0;
23335 sqlite3_exec(p->db,
23336 "SAVEPOINT selftest_init;\n"
23337 "CREATE TABLE IF NOT EXISTS selftest(\n"
23338 " tno INTEGER PRIMARY KEY,\n" /* Test number */
23339 " op TEXT,\n" /* Operator: memo run */
23340 " cmd TEXT,\n" /* Command text */
23341 " ans TEXT\n" /* Desired answer */
23342 ");"
23343 "CREATE TEMP TABLE [_shell$self](op,cmd,ans);\n"
23344 "INSERT INTO [_shell$self](rowid,op,cmd)\n"
23345 " VALUES(coalesce((SELECT (max(tno)+100)/10 FROM selftest),10),\n"
23346 " 'memo','Tests generated by --init');\n"
23347 "INSERT INTO [_shell$self]\n"
23348 " SELECT 'run',\n"
23349 " 'SELECT hex(sha3_query(''SELECT type,name,tbl_name,sql "
23350 "FROM sqlite_schema ORDER BY 2'',224))',\n"
23351 " hex(sha3_query('SELECT type,name,tbl_name,sql "
23352 "FROM sqlite_schema ORDER BY 2',224));\n"
23353 "INSERT INTO [_shell$self]\n"
23354 " SELECT 'run',"
23355 " 'SELECT hex(sha3_query(''SELECT * FROM \"' ||"
23356 " printf('%w',name) || '\" NOT INDEXED'',224))',\n"
23357 " hex(sha3_query(printf('SELECT * FROM \"%w\" NOT INDEXED',name),224))\n"
23358 " FROM (\n"
23359 " SELECT name FROM sqlite_schema\n"
23360 " WHERE type='table'\n"
23361 " AND name<>'selftest'\n"
23362 " AND coalesce(rootpage,0)>0\n"
23363 " )\n"
23364 " ORDER BY name;\n"
23365 "INSERT INTO [_shell$self]\n"
23366 " VALUES('run','PRAGMA integrity_check','ok');\n"
23367 "INSERT INTO selftest(tno,op,cmd,ans)"
23368 " SELECT rowid*10,op,cmd,ans FROM [_shell$self];\n"
23369 "DROP TABLE [_shell$self];"
23370 ,0,0,&zErrMsg);
23371 if( zErrMsg ){
23372 sqlite3_fprintf(stderr, "SELFTEST initialization failure: %s\n", zErrMsg);
23373 sqlite3_free(zErrMsg);
23374 }

References ShellState::db, sqlite3_exec, sqlite3_fprintf, and sqlite3_free.

Referenced by do_meta_command().

Here is the caller graph for this function:

◆ csv_read_one_field()

char * csv_read_one_field ( ImportCtx * p)
static
26509 {
26510 int c;
26511 int cSep = (u8)p->cColSep;
26512 int rSep = (u8)p->cRowSep;
26513 p->n = 0;
26514 c = fgetc(p->in);
26515 if( c==EOF || seenInterrupt ){
26516 p->cTerm = EOF;
26517 return 0;
26518 }
26519 if( c=='"' ){
26520 int pc, ppc;
26521 int startLine = p->nLine;
26522 int cQuote = c;
26523 pc = ppc = 0;
26524 while( 1 ){
26525 c = fgetc(p->in);
26526 if( c==rSep ) p->nLine++;
26527 if( c==cQuote ){
26528 if( pc==cQuote ){
26529 pc = 0;
26530 continue;
26531 }
26532 }
26533 if( (c==cSep && pc==cQuote)
26534 || (c==rSep && pc==cQuote)
26535 || (c==rSep && pc=='\r' && ppc==cQuote)
26536 || (c==EOF && pc==cQuote)
26537 ){
26538 do{ p->n--; }while( p->z[p->n]!=cQuote );
26539 p->cTerm = c;
26540 break;
26541 }
26542 if( pc==cQuote && c!='\r' ){
26543 sqlite3_fprintf(stderr,"%s:%d: unescaped %c character\n",
26544 p->zFile, p->nLine, cQuote);
26545 }
26546 if( c==EOF ){
26547 sqlite3_fprintf(stderr,"%s:%d: unterminated %c-quoted field\n",
26548 p->zFile, startLine, cQuote);
26549 p->cTerm = c;
26550 break;
26551 }
26553 ppc = pc;
26554 pc = c;
26555 }
26556 }else{
26557 /* If this is the first field being parsed and it begins with the
26558 ** UTF-8 BOM (0xEF BB BF) then skip the BOM */
26559 if( (c&0xff)==0xef && p->bNotFirst==0 ){
26561 c = fgetc(p->in);
26562 if( (c&0xff)==0xbb ){
26564 c = fgetc(p->in);
26565 if( (c&0xff)==0xbf ){
26566 p->bNotFirst = 1;
26567 p->n = 0;
26568 return csv_read_one_field(p);
26569 }
26570 }
26571 }
26572 while( c!=EOF && c!=cSep && c!=rSep ){
26574 c = fgetc(p->in);
26575 }
26576 if( c==rSep ){
26577 p->nLine++;
26578 if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
26579 }
26580 p->cTerm = c;
26581 }
26582 if( p->z ) p->z[p->n] = 0;
26583 p->bNotFirst = 1;
static char * csv_read_one_field(ImportCtx *p)
Definition shell.c:26507
const char * zFile
Definition shell.c:26459
int bNotFirst
Definition shell.c:26468

References ImportCtx::bNotFirst, c, ImportCtx::cColSep, ImportCtx::cRowSep, csv_read_one_field(), ImportCtx::cTerm, import_append_char(), ImportCtx::in, ImportCtx::n, ImportCtx::nLine, seenInterrupt, sqlite3_fprintf, SQLITE_CDECL, ImportCtx::z, and ImportCtx::zFile.

Referenced by csv_read_one_field(), and do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctxErrorMsg()

void ctxErrorMsg ( sqlite3_context * ctx,
const char * zFmt,
... )
static
8168 {
8169 char *zMsg = 0;
8170 va_list ap;
8171 va_start(ap, zFmt);
8172 zMsg = sqlite3_vmprintf(zFmt, ap);
8173 sqlite3_result_error(ctx, zMsg, -1);
8174 sqlite3_free(zMsg);
8175 va_end(ap);
8176}
#define sqlite3_vmprintf
Definition sqlite3ext.h:520

References sqlite3_free, sqlite3_result_error, and sqlite3_vmprintf.

Referenced by writefileFunc().

Here is the caller graph for this function:

◆ db_int()

int db_int ( sqlite3 * db,
const char * zSql,
... )
static
26914 {
26915 sqlite3_stmt *pStmt;
26916 int res = 0;
26917 char *z;
26918 va_list ap;
26919 va_start(ap, zSql);
26920 z = sqlite3_vmprintf(zSql, ap);
26921 va_end(ap);
26922 sqlite3_prepare_v2(db, z, -1, &pStmt, 0);
26923 if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
26924 res = sqlite3_column_int(pStmt,0);
26925 }
26926 sqlite3_finalize(pStmt);
26927 sqlite3_free(z);
#define sqlite3_column_int
Definition sqlite3ext.h:425

References sqlite3_column_int, sqlite3_finalize, sqlite3_free, sqlite3_prepare_v2, sqlite3_step, sqlite3_vmprintf, and SQLITE_ROW.

Referenced by do_meta_command(), and zAutoColumn().

Here is the caller graph for this function:

◆ decimal_add()

void decimal_add ( Decimal * pA,
Decimal * pB )
static
4140 {
4141 int nSig, nFrac, nDigit;
4142 int i, rc;
4143 if( pA==0 ){
4144 return;
4145 }
4146 if( pA->oom || pB==0 || pB->oom ){
4147 pA->oom = 1;
4148 return;
4149 }
4150 if( pA->isNull || pB->isNull ){
4151 pA->isNull = 1;
4152 return;
4153 }
4154 nSig = pA->nDigit - pA->nFrac;
4155 if( nSig && pA->a[0]==0 ) nSig--;
4156 if( nSig<pB->nDigit-pB->nFrac ){
4157 nSig = pB->nDigit - pB->nFrac;
4158 }
4159 nFrac = pA->nFrac;
4160 if( nFrac<pB->nFrac ) nFrac = pB->nFrac;
4161 nDigit = nSig + nFrac + 1;
4162 decimal_expand(pA, nDigit, nFrac);
4163 decimal_expand(pB, nDigit, nFrac);
4164 if( pA->oom || pB->oom ){
4165 pA->oom = 1;
4166 }else{
4167 if( pA->sign==pB->sign ){
4168 int carry = 0;
4169 for(i=nDigit-1; i>=0; i--){
4170 int x = pA->a[i] + pB->a[i] + carry;
4171 if( x>=10 ){
4172 carry = 1;
4173 pA->a[i] = x - 10;
4174 }else{
4175 carry = 0;
4176 pA->a[i] = x;
4177 }
4178 }
4179 }else{
4180 signed char *aA, *aB;
4181 int borrow = 0;
4182 rc = memcmp(pA->a, pB->a, nDigit);
4183 if( rc<0 ){
4184 aA = pB->a;
4185 aB = pA->a;
4186 pA->sign = !pA->sign;
4187 }else{
4188 aA = pA->a;
4189 aB = pB->a;
4190 }
4191 for(i=nDigit-1; i>=0; i--){
4192 int x = aA[i] - aB[i] - borrow;
4193 if( x<0 ){
4194 pA->a[i] = x+10;
4195 borrow = 1;
4196 }else{
4197 pA->a[i] = x;
4198 borrow = 0;
4199 }
4200 }
4201 }
4202 }
4203}
int nDigit
Definition shell.c:3736
static void decimal_expand(Decimal *p, int nDigit, int nFrac)
Definition shell.c:4111
char isNull
Definition shell.c:3734
signed char * a
Definition shell.c:3738
char oom
Definition shell.c:3733
int nFrac
Definition shell.c:3737
char sign
Definition shell.c:3732

References Decimal::a, decimal_expand(), Decimal::isNull, Decimal::nDigit, Decimal::nFrac, Decimal::oom, and Decimal::sign.

Referenced by decimalAddFunc(), decimalSubFunc(), decimalSumInverse(), and decimalSumStep().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimal_clear()

void decimal_clear ( Decimal * p)
static
3744 {
3745 sqlite3_free(p->a);
3746}

References Decimal::a, and sqlite3_free.

Referenced by decimal_free(), and decimalSumFinalize().

Here is the caller graph for this function:

◆ decimal_cmp()

int decimal_cmp ( const Decimal * pA,
const Decimal * pB )
static
4055 {
4056 int nASig, nBSig, rc, n;
4057 if( pA->sign!=pB->sign ){
4058 return pA->sign ? -1 : +1;
4059 }
4060 if( pA->sign ){
4061 const Decimal *pTemp = pA;
4062 pA = pB;
4063 pB = pTemp;
4064 }
4065 nASig = pA->nDigit - pA->nFrac;
4066 nBSig = pB->nDigit - pB->nFrac;
4067 if( nASig!=nBSig ){
4068 return nASig - nBSig;
4069 }
4070 n = pA->nDigit;
4071 if( n>pB->nDigit ) n = pB->nDigit;
4072 rc = memcmp(pA->a, pB->a, n);
4073 if( rc==0 ){
4074 rc = pA->nDigit - pB->nDigit;
4075 }
4076 return rc;
4077}
Definition shell.c:3731

References Decimal::a, Decimal::nDigit, Decimal::nFrac, and Decimal::sign.

Referenced by decimalCmpFunc(), and decimalCollFunc().

Here is the caller graph for this function:

◆ decimal_expand()

void decimal_expand ( Decimal * p,
int nDigit,
int nFrac )
static
4111 {
4112 int nAddSig;
4113 int nAddFrac;
4114 if( p==0 ) return;
4115 nAddFrac = nFrac - p->nFrac;
4116 nAddSig = (nDigit - p->nDigit) - nAddFrac;
4117 if( nAddFrac==0 && nAddSig==0 ) return;
4118 p->a = sqlite3_realloc64(p->a, nDigit+1);
4119 if( p->a==0 ){
4120 p->oom = 1;
4121 return;
4122 }
4123 if( nAddSig ){
4124 memmove(p->a+nAddSig, p->a, p->nDigit);
4125 memset(p->a, 0, nAddSig);
4126 p->nDigit += nAddSig;
4127 }
4128 if( nAddFrac ){
4129 memset(p->a+p->nDigit, 0, nAddFrac);
4130 p->nDigit += nAddFrac;
4131 p->nFrac += nAddFrac;
4132 }
4133}
#define sqlite3_realloc64
Definition sqlite3ext.h:607

References Decimal::a, Decimal::nDigit, Decimal::nFrac, Decimal::oom, and sqlite3_realloc64.

Referenced by decimal_add().

Here is the caller graph for this function:

◆ decimal_free()

void decimal_free ( Decimal * p)
static
3751 {
3752 if( p ){
3753 decimal_clear(p);
3754 sqlite3_free(p);
3755 }
3756}
static void decimal_clear(Decimal *p)
Definition shell.c:3744

References decimal_clear(), and sqlite3_free.

Referenced by decimalAddFunc(), decimalCmpFunc(), decimalCollFunc(), decimalFromDouble(), decimalFunc(), decimalMulFunc(), decimalPow2(), decimalPow2Func(), decimalSubFunc(), decimalSumInverse(), and decimalSumStep().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimal_new()

Decimal * decimal_new ( sqlite3_context * pCtx,
sqlite3_value * pIn,
int bTextOnly )
static
3881 {
3882 Decimal *p = 0;
3883 int eType = sqlite3_value_type(pIn);
3884 if( bTextOnly && (eType==SQLITE_FLOAT || eType==SQLITE_BLOB) ){
3885 eType = SQLITE_TEXT;
3886 }
3887 switch( eType ){
3888 case SQLITE_TEXT:
3889 case SQLITE_INTEGER: {
3890 const char *zIn = (const char*)sqlite3_value_text(pIn);
3891 int n = sqlite3_value_bytes(pIn);
3892 p = decimalNewFromText(zIn, n);
3893 if( p==0 ) goto new_failed;
3894 break;
3895 }
3896
3897 case SQLITE_FLOAT: {
3899 break;
3900 }
3901
3902 case SQLITE_BLOB: {
3903 const unsigned char *x;
3904 unsigned int i;
3905 sqlite3_uint64 v = 0;
3906 double r;
3907
3908 if( sqlite3_value_bytes(pIn)!=sizeof(r) ) break;
3909 x = sqlite3_value_blob(pIn);
3910 for(i=0; i<sizeof(r); i++){
3911 v = (v<<8) | x[i];
3912 }
3913 memcpy(&r, &v, sizeof(r));
3914 p = decimalFromDouble(r);
3915 break;
3916 }
3917
3918 case SQLITE_NULL: {
3919 break;
3920 }
3921 }
3922 return p;
3923
3924new_failed:
3925 if( pCtx ) sqlite3_result_error_nomem(pCtx);
3926 sqlite3_free(p);
3927 return 0;
3928}
static Decimal * decimalFromDouble(double)
Definition shell.c:4296
static Decimal * decimalNewFromText(const char *zIn, int n)
Definition shell.c:3762
#define SQLITE_FLOAT
Definition sqlite3.c:5563
sqlite_uint64 sqlite3_uint64
Definition sqlite3.c:624
#define SQLITE_INTEGER
Definition sqlite3.c:5562
#define SQLITE_NULL
Definition sqlite3.c:5565
#define sqlite3_value_double
Definition sqlite3ext.h:511
#define sqlite3_result_error_nomem
Definition sqlite3ext.h:543

References decimalFromDouble(), decimalNewFromText(), sqlite3_free, sqlite3_result_error_nomem, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_double, sqlite3_value_text, sqlite3_value_type, SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, and SQLITE_TEXT.

Referenced by decimalAddFunc(), decimalCmpFunc(), decimalFunc(), decimalMulFunc(), decimalSubFunc(), decimalSumInverse(), and decimalSumStep().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimal_result()

void decimal_result ( sqlite3_context * pCtx,
Decimal * p )
static
3933 {
3934 char *z;
3935 int i, j;
3936 int n;
3937 if( p==0 || p->oom ){
3939 return;
3940 }
3941 if( p->isNull ){
3942 sqlite3_result_null(pCtx);
3943 return;
3944 }
3945 z = sqlite3_malloc( p->nDigit+4 );
3946 if( z==0 ){
3948 return;
3949 }
3950 i = 0;
3951 if( p->nDigit==0 || (p->nDigit==1 && p->a[0]==0) ){
3952 p->sign = 0;
3953 }
3954 if( p->sign ){
3955 z[0] = '-';
3956 i = 1;
3957 }
3958 n = p->nDigit - p->nFrac;
3959 if( n<=0 ){
3960 z[i++] = '0';
3961 }
3962 j = 0;
3963 while( n>1 && p->a[j]==0 ){
3964 j++;
3965 n--;
3966 }
3967 while( n>0 ){
3968 z[i++] = p->a[j] + '0';
3969 j++;
3970 n--;
3971 }
3972 if( p->nFrac ){
3973 z[i++] = '.';
3974 do{
3975 z[i++] = p->a[j] + '0';
3976 j++;
3977 }while( j<p->nDigit );
3978 }
3979 z[i] = 0;
3980 sqlite3_result_text(pCtx, z, i, sqlite3_free);
3981}
#define sqlite3_result_null
Definition sqlite3ext.h:488

References Decimal::a, Decimal::isNull, Decimal::nDigit, Decimal::nFrac, Decimal::oom, Decimal::sign, sqlite3_free, sqlite3_malloc, sqlite3_result_error_nomem, sqlite3_result_null, and sqlite3_result_text.

Referenced by decimalAddFunc(), decimalFunc(), decimalMulFunc(), decimalSubFunc(), decimalSumFinalize(), and decimalSumValue().

Here is the caller graph for this function:

◆ decimal_result_sci()

void decimal_result_sci ( sqlite3_context * pCtx,
Decimal * p )
static
3988 {
3989 char *z; /* The output buffer */
3990 int i; /* Loop counter */
3991 int nZero; /* Number of leading zeros */
3992 int nDigit; /* Number of digits not counting trailing zeros */
3993 int nFrac; /* Digits to the right of the decimal point */
3994 int exp; /* Exponent value */
3995 signed char zero; /* Zero value */
3996 signed char *a; /* Array of digits */
3997
3998 if( p==0 || p->oom ){
4000 return;
4001 }
4002 if( p->isNull ){
4003 sqlite3_result_null(pCtx);
4004 return;
4005 }
4006 for(nDigit=p->nDigit; nDigit>0 && p->a[nDigit-1]==0; nDigit--){}
4007 for(nZero=0; nZero<nDigit && p->a[nZero]==0; nZero++){}
4008 nFrac = p->nFrac + (nDigit - p->nDigit);
4009 nDigit -= nZero;
4010 z = sqlite3_malloc( nDigit+20 );
4011 if( z==0 ){
4013 return;
4014 }
4015 if( nDigit==0 ){
4016 zero = 0;
4017 a = &zero;
4018 nDigit = 1;
4019 nFrac = 0;
4020 }else{
4021 a = &p->a[nZero];
4022 }
4023 if( p->sign && nDigit>0 ){
4024 z[0] = '-';
4025 }else{
4026 z[0] = '+';
4027 }
4028 z[1] = a[0]+'0';
4029 z[2] = '.';
4030 if( nDigit==1 ){
4031 z[3] = '0';
4032 i = 4;
4033 }else{
4034 for(i=1; i<nDigit; i++){
4035 z[2+i] = a[i]+'0';
4036 }
4037 i = nDigit+2;
4038 }
4039 exp = nDigit - nFrac - 1;
4040 sqlite3_snprintf(nDigit+20-i, &z[i], "e%+03d", exp);
4041 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
4042}

References a, Decimal::a, Decimal::isNull, Decimal::nDigit, Decimal::nFrac, Decimal::oom, Decimal::sign, sqlite3_free, sqlite3_malloc, sqlite3_result_error_nomem, sqlite3_result_null, sqlite3_result_text, and sqlite3_snprintf.

Referenced by decimalFunc(), and decimalPow2Func().

Here is the caller graph for this function:

◆ decimalAddFunc()

void decimalAddFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
4406 {
4407 Decimal *pA = decimal_new(context, argv[0], 1);
4408 Decimal *pB = decimal_new(context, argv[1], 1);
4409 UNUSED_PARAMETER(argc);
4410 decimal_add(pA, pB);
4411 decimal_result(context, pA);
4412 decimal_free(pA);
4413 decimal_free(pB);
4414}
static Decimal * decimal_new(sqlite3_context *pCtx, sqlite3_value *pIn, int bTextOnly)
Definition shell.c:3877
static void decimal_free(Decimal *p)
Definition shell.c:3751
static void decimal_result(sqlite3_context *pCtx, Decimal *p)
Definition shell.c:3933
static void decimal_add(Decimal *pA, Decimal *pB)
Definition shell.c:4140

References decimal_add(), decimal_free(), decimal_new(), decimal_result(), and UNUSED_PARAMETER.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalCmpFunc()

void decimalCmpFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
4089 {
4090 Decimal *pA = 0, *pB = 0;
4091 int rc;
4092
4093 UNUSED_PARAMETER(argc);
4094 pA = decimal_new(context, argv[0], 1);
4095 if( pA==0 || pA->isNull ) goto cmp_done;
4096 pB = decimal_new(context, argv[1], 1);
4097 if( pB==0 || pB->isNull ) goto cmp_done;
4098 rc = decimal_cmp(pA, pB);
4099 if( rc<0 ) rc = -1;
4100 else if( rc>0 ) rc = +1;
4101 sqlite3_result_int(context, rc);
4102cmp_done:
4103 decimal_free(pA);
4104 decimal_free(pB);
4105}
static int decimal_cmp(const Decimal *pA, const Decimal *pB)
Definition shell.c:4055

References decimal_cmp(), decimal_free(), decimal_new(), Decimal::isNull, sqlite3_result_int, and UNUSED_PARAMETER.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalCollFunc()

int decimalCollFunc ( void * notUsed,
int nKey1,
const void * pKey1,
int nKey2,
const void * pKey2 )
static
4378 {
4379 const unsigned char *zA = (const unsigned char*)pKey1;
4380 const unsigned char *zB = (const unsigned char*)pKey2;
4381 Decimal *pA = decimalNewFromText((const char*)zA, nKey1);
4382 Decimal *pB = decimalNewFromText((const char*)zB, nKey2);
4383 int rc;
4384 UNUSED_PARAMETER(notUsed);
4385 if( pA==0 || pB==0 ){
4386 rc = 0;
4387 }else{
4388 rc = decimal_cmp(pA, pB);
4389 }
4390 decimal_free(pA);
4391 decimal_free(pB);
4392 return rc;
4393}

References decimal_cmp(), decimal_free(), decimalNewFromText(), and UNUSED_PARAMETER.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalFromDouble()

Decimal * decimalFromDouble ( double r)
static
4296 {
4297 sqlite3_int64 m, a;
4298 int e;
4299 int isNeg;
4300 Decimal *pA;
4301 Decimal *pX;
4302 char zNum[100];
4303 if( r<0.0 ){
4304 isNeg = 1;
4305 r = -r;
4306 }else{
4307 isNeg = 0;
4308 }
4309 memcpy(&a,&r,sizeof(a));
4310 if( a==0 ){
4311 e = 0;
4312 m = 0;
4313 }else{
4314 e = a>>52;
4315 m = a & ((((sqlite3_int64)1)<<52)-1);
4316 if( e==0 ){
4317 m <<= 1;
4318 }else{
4319 m |= ((sqlite3_int64)1)<<52;
4320 }
4321 while( e<1075 && m>0 && (m&1)==0 ){
4322 m >>= 1;
4323 e++;
4324 }
4325 if( isNeg ) m = -m;
4326 e = e - 1075;
4327 if( e>971 ){
4328 return 0; /* A NaN or an Infinity */
4329 }
4330 }
4331
4332 /* At this point m is the integer significand and e is the exponent */
4333 sqlite3_snprintf(sizeof(zNum), zNum, "%lld", m);
4334 pA = decimalNewFromText(zNum, (int)strlen(zNum));
4335 pX = decimalPow2(e);
4336 decimalMul(pA, pX);
4337 decimal_free(pX);
4338 return pA;
4339}
#define e
static Decimal * decimalPow2(int N)
Definition shell.c:4261
static void decimalMul(Decimal *pA, Decimal *pB)
Definition shell.c:4213

References a, decimal_free(), decimalMul(), decimalNewFromText(), decimalPow2(), e, and sqlite3_snprintf.

Referenced by decimal_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalFunc()

void decimalFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
4358 {
4359 Decimal *p = decimal_new(context, argv[0], 0);
4360 UNUSED_PARAMETER(argc);
4361 if( p ){
4362 if( sqlite3_user_data(context)!=0 ){
4363 decimal_result_sci(context, p);
4364 }else{
4365 decimal_result(context, p);
4366 }
4367 decimal_free(p);
4368 }
4369}
static void decimal_result_sci(sqlite3_context *pCtx, Decimal *p)
Definition shell.c:3988
#define sqlite3_user_data
Definition sqlite3ext.h:507

References decimal_free(), decimal_new(), decimal_result(), decimal_result_sci(), sqlite3_user_data, and UNUSED_PARAMETER.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalMul()

void decimalMul ( Decimal * pA,
Decimal * pB )
static
4213 {
4214 signed char *acc = 0;
4215 int i, j, k;
4216 int minFrac;
4217
4218 if( pA==0 || pA->oom || pA->isNull
4219 || pB==0 || pB->oom || pB->isNull
4220 ){
4221 goto mul_end;
4222 }
4223 acc = sqlite3_malloc64( pA->nDigit + pB->nDigit + 2 );
4224 if( acc==0 ){
4225 pA->oom = 1;
4226 goto mul_end;
4227 }
4228 memset(acc, 0, pA->nDigit + pB->nDigit + 2);
4229 minFrac = pA->nFrac;
4230 if( pB->nFrac<minFrac ) minFrac = pB->nFrac;
4231 for(i=pA->nDigit-1; i>=0; i--){
4232 signed char f = pA->a[i];
4233 int carry = 0, x;
4234 for(j=pB->nDigit-1, k=i+j+3; j>=0; j--, k--){
4235 x = acc[k] + f*pB->a[j] + carry;
4236 acc[k] = x%10;
4237 carry = x/10;
4238 }
4239 x = acc[k] + carry;
4240 acc[k] = x%10;
4241 acc[k-1] += x/10;
4242 }
4243 sqlite3_free(pA->a);
4244 pA->a = acc;
4245 acc = 0;
4246 pA->nDigit += pB->nDigit + 2;
4247 pA->nFrac += pB->nFrac;
4248 pA->sign ^= pB->sign;
4249 while( pA->nFrac>minFrac && pA->a[pA->nDigit-1]==0 ){
4250 pA->nFrac--;
4251 pA->nDigit--;
4252 }
4253
4254mul_end:
4255 sqlite3_free(acc);
4256}

References Decimal::a, Decimal::isNull, Decimal::nDigit, Decimal::nFrac, Decimal::oom, Decimal::sign, sqlite3_free, and sqlite3_malloc64.

Referenced by decimalFromDouble(), decimalMulFunc(), and decimalPow2().

Here is the caller graph for this function:

◆ decimalMulFunc()

void decimalMulFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
4500 {
4501 Decimal *pA = decimal_new(context, argv[0], 1);
4502 Decimal *pB = decimal_new(context, argv[1], 1);
4503 UNUSED_PARAMETER(argc);
4504 if( pA==0 || pA->oom || pA->isNull
4505 || pB==0 || pB->oom || pB->isNull
4506 ){
4507 goto mul_end;
4508 }
4509 decimalMul(pA, pB);
4510 if( pA->oom ){
4511 goto mul_end;
4512 }
4513 decimal_result(context, pA);
4514
4515mul_end:
4516 decimal_free(pA);
4517 decimal_free(pB);
4518}

References decimal_free(), decimal_new(), decimal_result(), decimalMul(), Decimal::isNull, Decimal::oom, and UNUSED_PARAMETER.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalNewFromText()

Decimal * decimalNewFromText ( const char * zIn,
int n )
static
3762 {
3763 Decimal *p = 0;
3764 int i;
3765 int iExp = 0;
3766
3767 p = sqlite3_malloc( sizeof(*p) );
3768 if( p==0 ) goto new_from_text_failed;
3769 p->sign = 0;
3770 p->oom = 0;
3771 p->isInit = 1;
3772 p->isNull = 0;
3773 p->nDigit = 0;
3774 p->nFrac = 0;
3775 p->a = sqlite3_malloc64( n+1 );
3776 if( p->a==0 ) goto new_from_text_failed;
3777 for(i=0; IsSpace(zIn[i]); i++){}
3778 if( zIn[i]=='-' ){
3779 p->sign = 1;
3780 i++;
3781 }else if( zIn[i]=='+' ){
3782 i++;
3783 }
3784 while( i<n && zIn[i]=='0' ) i++;
3785 while( i<n ){
3786 char c = zIn[i];
3787 if( c>='0' && c<='9' ){
3788 p->a[p->nDigit++] = c - '0';
3789 }else if( c=='.' ){
3790 p->nFrac = p->nDigit + 1;
3791 }else if( c=='e' || c=='E' ){
3792 int j = i+1;
3793 int neg = 0;
3794 if( j>=n ) break;
3795 if( zIn[j]=='-' ){
3796 neg = 1;
3797 j++;
3798 }else if( zIn[j]=='+' ){
3799 j++;
3800 }
3801 while( j<n && iExp<1000000 ){
3802 if( zIn[j]>='0' && zIn[j]<='9' ){
3803 iExp = iExp*10 + zIn[j] - '0';
3804 }
3805 j++;
3806 }
3807 if( neg ) iExp = -iExp;
3808 break;
3809 }
3810 i++;
3811 }
3812 if( p->nFrac ){
3813 p->nFrac = p->nDigit - (p->nFrac - 1);
3814 }
3815 if( iExp>0 ){
3816 if( p->nFrac>0 ){
3817 if( iExp<=p->nFrac ){
3818 p->nFrac -= iExp;
3819 iExp = 0;
3820 }else{
3821 iExp -= p->nFrac;
3822 p->nFrac = 0;
3823 }
3824 }
3825 if( iExp>0 ){
3826 p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
3827 if( p->a==0 ) goto new_from_text_failed;
3828 memset(p->a+p->nDigit, 0, iExp);
3829 p->nDigit += iExp;
3830 }
3831 }else if( iExp<0 ){
3832 int nExtra;
3833 iExp = -iExp;
3834 nExtra = p->nDigit - p->nFrac - 1;
3835 if( nExtra ){
3836 if( nExtra>=iExp ){
3837 p->nFrac += iExp;
3838 iExp = 0;
3839 }else{
3840 iExp -= nExtra;
3841 p->nFrac = p->nDigit - 1;
3842 }
3843 }
3844 if( iExp>0 ){
3845 p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
3846 if( p->a==0 ) goto new_from_text_failed;
3847 memmove(p->a+iExp, p->a, p->nDigit);
3848 memset(p->a, 0, iExp);
3849 p->nDigit += iExp;
3850 p->nFrac += iExp;
3851 }
3852 }
3853 return p;
3854
3855new_from_text_failed:
3856 if( p ){
3857 if( p->a ) sqlite3_free(p->a);
3858 sqlite3_free(p);
3859 }
3860 return 0;
3861}
#define IsSpace(X)
Definition shell.c:236
char isInit
Definition shell.c:3735

References Decimal::a, c, Decimal::isInit, Decimal::isNull, IsSpace, Decimal::nDigit, Decimal::nFrac, Decimal::oom, Decimal::sign, sqlite3_free, sqlite3_malloc, sqlite3_malloc64, and sqlite3_realloc64.

Referenced by decimal_new(), decimalCollFunc(), decimalFromDouble(), and decimalPow2().

Here is the caller graph for this function:

◆ decimalPow2()

Decimal * decimalPow2 ( int N)
static
4261 {
4262 Decimal *pA = 0; /* The result to be returned */
4263 Decimal *pX = 0; /* Multiplier */
4264 if( N<-20000 || N>20000 ) goto pow2_fault;
4265 pA = decimalNewFromText("1.0", 3);
4266 if( pA==0 || pA->oom ) goto pow2_fault;
4267 if( N==0 ) return pA;
4268 if( N>0 ){
4269 pX = decimalNewFromText("2.0", 3);
4270 }else{
4271 N = -N;
4272 pX = decimalNewFromText("0.5", 3);
4273 }
4274 if( pX==0 || pX->oom ) goto pow2_fault;
4275 while( 1 /* Exit by break */ ){
4276 if( N & 1 ){
4277 decimalMul(pA, pX);
4278 if( pA->oom ) goto pow2_fault;
4279 }
4280 N >>= 1;
4281 if( N==0 ) break;
4282 decimalMul(pX, pX);
4283 }
4284 decimal_free(pX);
4285 return pA;
4286
4287pow2_fault:
4288 decimal_free(pA);
4289 decimal_free(pX);
4290 return 0;
4291}

References decimal_free(), decimalMul(), decimalNewFromText(), and Decimal::oom.

Referenced by decimalFromDouble(), and decimalPow2Func().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalPow2Func()

void decimalPow2Func ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
4529 {
4530 UNUSED_PARAMETER(argc);
4531 if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){
4532 Decimal *pA = decimalPow2(sqlite3_value_int(argv[0]));
4533 decimal_result_sci(context, pA);
4534 decimal_free(pA);
4535 }
4536}
#define sqlite3_value_int
Definition sqlite3ext.h:512

References decimal_free(), decimal_result_sci(), decimalPow2(), sqlite3_value_int, sqlite3_value_type, SQLITE_INTEGER, and UNUSED_PARAMETER.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalSubFunc()

void decimalSubFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
4419 {
4420 Decimal *pA = decimal_new(context, argv[0], 1);
4421 Decimal *pB = decimal_new(context, argv[1], 1);
4422 UNUSED_PARAMETER(argc);
4423 if( pB ){
4424 pB->sign = !pB->sign;
4425 decimal_add(pA, pB);
4426 decimal_result(context, pA);
4427 }
4428 decimal_free(pA);
4429 decimal_free(pB);
4430}

References decimal_add(), decimal_free(), decimal_new(), decimal_result(), Decimal::sign, and UNUSED_PARAMETER.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalSumFinalize()

void decimalSumFinalize ( sqlite3_context * context)
static
4484 {
4485 Decimal *p = sqlite3_aggregate_context(context, 0);
4486 if( p==0 ) return;
4487 decimal_result(context, p);
4488 decimal_clear(p);
4489}
#define sqlite3_aggregate_context
Definition sqlite3ext.h:395

References decimal_clear(), decimal_result(), and sqlite3_aggregate_context.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalSumInverse()

void decimalSumInverse ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
4467 {
4468 Decimal *p;
4469 Decimal *pArg;
4470 UNUSED_PARAMETER(argc);
4471 p = sqlite3_aggregate_context(context, sizeof(*p));
4472 if( p==0 ) return;
4473 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
4474 pArg = decimal_new(context, argv[0], 1);
4475 if( pArg ) pArg->sign = !pArg->sign;
4476 decimal_add(p, pArg);
4477 decimal_free(pArg);
4478}

References decimal_add(), decimal_free(), decimal_new(), Decimal::sign, sqlite3_aggregate_context, sqlite3_value_type, SQLITE_NULL, and UNUSED_PARAMETER.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalSumStep()

void decimalSumStep ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
4441 {
4442 Decimal *p;
4443 Decimal *pArg;
4444 UNUSED_PARAMETER(argc);
4445 p = sqlite3_aggregate_context(context, sizeof(*p));
4446 if( p==0 ) return;
4447 if( !p->isInit ){
4448 p->isInit = 1;
4449 p->a = sqlite3_malloc(2);
4450 if( p->a==0 ){
4451 p->oom = 1;
4452 }else{
4453 p->a[0] = 0;
4454 }
4455 p->nDigit = 1;
4456 p->nFrac = 0;
4457 }
4458 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
4459 pArg = decimal_new(context, argv[0], 1);
4460 decimal_add(p, pArg);
4461 decimal_free(pArg);
4462}

References Decimal::a, decimal_add(), decimal_free(), decimal_new(), Decimal::isInit, Decimal::nDigit, Decimal::nFrac, Decimal::oom, sqlite3_aggregate_context, sqlite3_malloc, sqlite3_value_type, SQLITE_NULL, and UNUSED_PARAMETER.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalSumValue()

void decimalSumValue ( sqlite3_context * context)
static
4479 {
4480 Decimal *p = sqlite3_aggregate_context(context, 0);
4481 if( p==0 ) return;
4482 decimal_result(context, p);
4483}

References decimal_result(), and sqlite3_aggregate_context.

Referenced by sqlite3_decimal_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeUtf8()

int decodeUtf8 ( const unsigned char * z,
int * pU )
static
1118 {
1119 if( (z[0] & 0xe0)==0xc0 && (z[1] & 0xc0)==0x80 ){
1120 *pU = ((z[0] & 0x1f)<<6) | (z[1] & 0x3f);
1121 return 2;
1122 }
1123 if( (z[0] & 0xf0)==0xe0 && (z[1] & 0xc0)==0x80 && (z[2] & 0xc0)==0x80 ){
1124 *pU = ((z[0] & 0x0f)<<12) | ((z[1] & 0x3f)<<6) | (z[2] & 0x3f);
1125 return 3;
1126 }
1127 if( (z[0] & 0xf8)==0xf0 && (z[1] & 0xc0)==0x80 && (z[2] & 0xc0)==0x80
1128 && (z[3] & 0xc0)==0x80
1129 ){
1130 *pU = ((z[0] & 0x0f)<<18) | ((z[1] & 0x3f)<<12) | ((z[2] & 0x3f))<<6
1131 | (z[4] & 0x3f);
1132 return 4;
1133 }
1134 *pU = 0;
1135 return 1;
1136}

Referenced by translateForDisplayAndDup(), and utf8_width_print().

Here is the caller graph for this function:

◆ deduceDatabaseType()

int deduceDatabaseType ( const char * zName,
int dfltZip )
25789 {
25790 FILE *f = sqlite3_fopen(zName, "rb");
25791 size_t n;
25792 int rc = SHELL_OPEN_UNSPEC;
25793 char zBuf[100];
25794 if( f==0 ){
25795 if( dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
25796 return SHELL_OPEN_ZIPFILE;
25797 }else{
25798 return SHELL_OPEN_NORMAL;
25799 }
25800 }
25801 n = fread(zBuf, 16, 1, f);
25802 if( n==1 && memcmp(zBuf, "SQLite format 3", 16)==0 ){
25803 fclose(f);
25804 return SHELL_OPEN_NORMAL;
25805 }
25806 fseek(f, -25, SEEK_END);
25807 n = fread(zBuf, 25, 1, f);
25808 if( n==1 && memcmp(zBuf, "Start-Of-SQLite3-", 17)==0 ){
25810 }else{
25811 fseek(f, -22, SEEK_END);
25812 n = fread(zBuf, 22, 1, f);
25813 if( n==1 && zBuf[0]==0x50 && zBuf[1]==0x4b && zBuf[2]==0x05
25814 && zBuf[3]==0x06 ){
25815 rc = SHELL_OPEN_ZIPFILE;
25816 }else if( n==0 && dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
25817 rc = SHELL_OPEN_ZIPFILE;
25818 }
25819 }
25820 fclose(f);
#define sqlite3_fopen
Definition shell.c:302
#define SHELL_OPEN_APPENDVFS
Definition shell.c:21766
#define SHELL_OPEN_UNSPEC
Definition shell.c:21764
#define SHELL_OPEN_NORMAL
Definition shell.c:21765
#define SHELL_OPEN_ZIPFILE
Definition shell.c:21767

References SHELL_OPEN_APPENDVFS, SHELL_OPEN_NORMAL, SHELL_OPEN_UNSPEC, SHELL_OPEN_ZIPFILE, sqlite3_fopen, and sqlite3_strlike.

Referenced by open_db().

Here is the caller graph for this function:

◆ disable_debug_trace_modes()

void disable_debug_trace_modes ( void )
static
24020 {
24021 unsigned int zero = 0;
static unsigned int savedSelectTrace
Definition shell.c:24016
static unsigned int savedWhereTrace
Definition shell.c:24017
#define SQLITE_TESTCTRL_TRACEFLAGS
Definition sqlite3.c:8880
#define sqlite3_test_control
Definition sqlite3ext.h:553

References savedSelectTrace, savedWhereTrace, sqlite3_test_control, and SQLITE_TESTCTRL_TRACEFLAGS.

Referenced by shell_exec().

Here is the caller graph for this function:

◆ display_scanstats()

void display_scanstats ( sqlite3 * db,
ShellState * pArg )
static
23975 {
23976#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
23977 UNUSED_PARAMETER(db);
23978 UNUSED_PARAMETER(pArg);
23979#else
23980 if( pArg->scanstatsOn==3 ){
23981 const char *zSql =
23982 " SELECT addr, opcode, p1, p2, p3, p4, p5, comment, nexec,"
23983 " format('% 6s (%.2f%%)',"
23984 " CASE WHEN ncycle<100_000 THEN ncycle || ' '"
23985 " WHEN ncycle<100_000_000 THEN (ncycle/1_000) || 'K'"
23986 " WHEN ncycle<100_000_000_000 THEN (ncycle/1_000_000) || 'M'"
23987 " ELSE (ncycle/1000_000_000) || 'G' END,"
23988 " ncycle*100.0/(sum(ncycle) OVER ())"
23989 " ) AS cycles"
23990 " FROM bytecode(?)";
23991
23992 int rc = SQLITE_OK;
23993 sqlite3_stmt *pStmt = 0;
23994 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
23995 if( rc==SQLITE_OK ){
23996 sqlite3_stmt *pSave = pArg->pStmt;
23997 pArg->pStmt = pStmt;
23998 sqlite3_bind_pointer(pStmt, 1, pSave, "stmt-pointer", 0);
23999
24000 pArg->cnt = 0;
24001 pArg->cMode = MODE_ScanExp;
24002 explain_data_prepare(pArg, pStmt);
24003 exec_prepared_stmt(pArg, pStmt);
24004 explain_data_delete(pArg);
24005
24006 sqlite3_finalize(pStmt);
24007 pArg->pStmt = pSave;
24008 }
24009 }else{
24010 display_explain_scanstats(db, pArg);
24011 }
static void explain_data_delete(ShellState *p)
Definition shell.c:23958
int cnt
Definition shell.c:21690
sqlite3_stmt * pStmt
Definition shell.c:21723
#define MODE_ScanExp
Definition shell.c:21836
static void exec_prepared_stmt(ShellState *, sqlite3_stmt *)
Definition shell.c:24605
int cMode
Definition shell.c:21699
static void explain_data_prepare(ShellState *p, sqlite3_stmt *pSql)
Definition shell.c:23896
u8 scanstatsOn
Definition shell.c:21675
#define sqlite3_bind_pointer
Definition sqlite3ext.h:634

References ShellState::cMode, ShellState::cnt, exec_prepared_stmt(), explain_data_delete(), explain_data_prepare(), MODE_ScanExp, ShellState::pStmt, ShellState::scanstatsOn, sqlite3_bind_pointer, sqlite3_finalize, sqlite3_prepare_v2, SQLITE_OK, and UNUSED_PARAMETER.

Referenced by shell_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_stats()

int display_stats ( sqlite3 * db,
ShellState * pArg,
int bReset )
static
23602 {
23603 int iCur;
23604 int iHiwtr;
23605 FILE *out;
23606 if( pArg==0 || pArg->out==0 ) return 0;
23607 out = pArg->out;
23608
23609 if( pArg->pStmt && pArg->statsOn==2 ){
23610 int nCol, i, x;
23611 sqlite3_stmt *pStmt = pArg->pStmt;
23612 char z[100];
23613 nCol = sqlite3_column_count(pStmt);
23614 sqlite3_fprintf(out, "%-36s %d\n", "Number of output columns:", nCol);
23615 for(i=0; i<nCol; i++){
23616 sqlite3_snprintf(sizeof(z),z,"Column %d %nname:", i, &x);
23617 sqlite3_fprintf(out, "%-36s %s\n", z, sqlite3_column_name(pStmt,i));
23618#ifndef SQLITE_OMIT_DECLTYPE
23619 sqlite3_snprintf(30, z+x, "declared type:");
23620 sqlite3_fprintf(out, "%-36s %s\n", z, sqlite3_column_decltype(pStmt, i));
23621#endif
23622#ifdef SQLITE_ENABLE_COLUMN_METADATA
23623 sqlite3_snprintf(30, z+x, "database name:");
23624 sqlite3_fprintf(out, "%-36s %s\n", z,
23626 sqlite3_snprintf(30, z+x, "table name:");
23627 sqlite3_fprintf(out, "%-36s %s\n", z, sqlite3_column_table_name(pStmt,i));
23628 sqlite3_snprintf(30, z+x, "origin name:");
23629 sqlite3_fprintf(out, "%-36s %s\n", z,sqlite3_column_origin_name(pStmt,i));
23630#endif
23631 }
23632 }
23633
23634 if( pArg->statsOn==3 ){
23635 if( pArg->pStmt ){
23637 sqlite3_fprintf(out, "VM-steps: %d\n", iCur);
23638 }
23639 return 0;
23640 }
23641
23642 displayStatLine(out, "Memory Used:",
23643 "%lld (max %lld) bytes", SQLITE_STATUS_MEMORY_USED, bReset);
23644 displayStatLine(out, "Number of Outstanding Allocations:",
23645 "%lld (max %lld)", SQLITE_STATUS_MALLOC_COUNT, bReset);
23646 if( pArg->shellFlgs & SHFLG_Pagecache ){
23647 displayStatLine(out, "Number of Pcache Pages Used:",
23648 "%lld (max %lld) pages", SQLITE_STATUS_PAGECACHE_USED, bReset);
23649 }
23650 displayStatLine(out, "Number of Pcache Overflow Bytes:",
23651 "%lld (max %lld) bytes", SQLITE_STATUS_PAGECACHE_OVERFLOW, bReset);
23652 displayStatLine(out, "Largest Allocation:",
23653 "%lld bytes", SQLITE_STATUS_MALLOC_SIZE, bReset);
23654 displayStatLine(out, "Largest Pcache Allocation:",
23655 "%lld bytes", SQLITE_STATUS_PAGECACHE_SIZE, bReset);
23656#ifdef YYTRACKMAXSTACKDEPTH
23657 displayStatLine(out, "Deepest Parser Stack:",
23658 "%lld (max %lld)", SQLITE_STATUS_PARSER_STACK, bReset);
23659#endif
23660
23661 if( db ){
23662 if( pArg->shellFlgs & SHFLG_Lookaside ){
23663 iHiwtr = iCur = -1;
23665 &iCur, &iHiwtr, bReset);
23666 sqlite3_fprintf(out,
23667 "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr);
23669 &iCur, &iHiwtr, bReset);
23670 sqlite3_fprintf(out,
23671 "Successful lookaside attempts: %d\n", iHiwtr);
23673 &iCur, &iHiwtr, bReset);
23674 sqlite3_fprintf(out,
23675 "Lookaside failures due to size: %d\n", iHiwtr);
23677 &iCur, &iHiwtr, bReset);
23678 sqlite3_fprintf(out,
23679 "Lookaside failures due to OOM: %d\n", iHiwtr);
23680 }
23681 iHiwtr = iCur = -1;
23682 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
23683 sqlite3_fprintf(out,
23684 "Pager Heap Usage: %d bytes\n", iCur);
23685 iHiwtr = iCur = -1;
23686 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
23687 sqlite3_fprintf(out,
23688 "Page cache hits: %d\n", iCur);
23689 iHiwtr = iCur = -1;
23690 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
23691 sqlite3_fprintf(out,
23692 "Page cache misses: %d\n", iCur);
23693 iHiwtr = iCur = -1;
23694 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
23695 sqlite3_fprintf(out,
23696 "Page cache writes: %d\n", iCur);
23697 iHiwtr = iCur = -1;
23698 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_SPILL, &iCur, &iHiwtr, 1);
23699 sqlite3_fprintf(out,
23700 "Page cache spills: %d\n", iCur);
23701 iHiwtr = iCur = -1;
23702 sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
23703 sqlite3_fprintf(out,
23704 "Schema Heap Usage: %d bytes\n", iCur);
23705 iHiwtr = iCur = -1;
23706 sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
23707 sqlite3_fprintf(out,
23708 "Statement Heap/Lookaside Usage: %d bytes\n", iCur);
23709 }
23710
23711 if( pArg->pStmt ){
23712 int iHit, iMiss;
23714 bReset);
23715 sqlite3_fprintf(out,
23716 "Fullscan Steps: %d\n", iCur);
23717 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
23718 sqlite3_fprintf(out,
23719 "Sort Operations: %d\n", iCur);
23721 sqlite3_fprintf(out,
23722 "Autoindex Inserts: %d\n", iCur);
23724 bReset);
23726 bReset);
23727 if( iHit || iMiss ){
23728 sqlite3_fprintf(out,
23729 "Bloom filter bypass taken: %d/%d\n", iHit, iHit+iMiss);
23730 }
23732 sqlite3_fprintf(out,
23733 "Virtual Machine Steps: %d\n", iCur);
23735 sqlite3_fprintf(out,
23736 "Reprepare operations: %d\n", iCur);
23737 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_RUN, bReset);
23738 sqlite3_fprintf(out,
23739 "Number of times run: %d\n", iCur);
23741 sqlite3_fprintf(out,
23742 "Memory used by prepared stmt: %d\n", iCur);
23743 }
23744
23745#ifdef __linux__
23746 displayLinuxIoStats(pArg->out);
23747#endif
23748
23749 /* Do not remove this machine readable comment: extra-stats-output-here */
23750
#define SHFLG_Pagecache
Definition shell.c:21795
static void displayStatLine(FILE *out, char *zLabel, char *zFormat, int iStatusCtrl, int bReset)
Definition shell.c:23570
#define SHFLG_Lookaside
Definition shell.c:21796
unsigned shellFlgs
Definition shell.c:21707
unsigned statsOn
Definition shell.c:21686
FILE * out
Definition shell.c:21694
#define SQLITE_STMTSTATUS_MEMUSED
Definition sqlite3.c:9435
#define SQLITE_DBSTATUS_CACHE_HIT
Definition sqlite3.c:9327
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE
Definition sqlite3.c:9325
#define SQLITE_DBSTATUS_STMT_USED
Definition sqlite3.c:9323
#define SQLITE_STMTSTATUS_FILTER_HIT
Definition sqlite3.c:9434
#define sqlite3_column_table_name
Definition sqlite3.c:139078
#define SQLITE_STATUS_PAGECACHE_USED
Definition sqlite3.c:9172
#define SQLITE_STATUS_MALLOC_SIZE
Definition sqlite3.c:9176
#define SQLITE_STMTSTATUS_SORT
Definition sqlite3.c:9428
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL
Definition sqlite3.c:9326
#define SQLITE_STMTSTATUS_AUTOINDEX
Definition sqlite3.c:9429
#define SQLITE_DBSTATUS_CACHE_USED
Definition sqlite3.c:9321
#define sqlite3_column_database_name
Definition sqlite3.c:139076
#define SQLITE_STATUS_PAGECACHE_OVERFLOW
Definition sqlite3.c:9173
#define SQLITE_DBSTATUS_LOOKASIDE_HIT
Definition sqlite3.c:9324
#define SQLITE_STATUS_MEMORY_USED
Definition sqlite3.c:9171
#define SQLITE_STMTSTATUS_RUN
Definition sqlite3.c:9432
#define sqlite3_column_origin_name
Definition sqlite3.c:139080
#define SQLITE_DBSTATUS_SCHEMA_USED
Definition sqlite3.c:9322
#define SQLITE_STMTSTATUS_REPREPARE
Definition sqlite3.c:9431
#define SQLITE_DBSTATUS_CACHE_WRITE
Definition sqlite3.c:9329
#define SQLITE_STATUS_PAGECACHE_SIZE
Definition sqlite3.c:9178
#define SQLITE_DBSTATUS_CACHE_SPILL
Definition sqlite3.c:9332
#define SQLITE_STMTSTATUS_FILTER_MISS
Definition sqlite3.c:9433
#define SQLITE_STMTSTATUS_VM_STEP
Definition sqlite3.c:9430
#define SQLITE_DBSTATUS_LOOKASIDE_USED
Definition sqlite3.c:9320
#define SQLITE_STATUS_PARSER_STACK
Definition sqlite3.c:9177
#define SQLITE_DBSTATUS_CACHE_MISS
Definition sqlite3.c:9328
#define SQLITE_STMTSTATUS_FULLSCAN_STEP
Definition sqlite3.c:9427
#define SQLITE_STATUS_MALLOC_COUNT
Definition sqlite3.c:9180
#define sqlite3_column_name
Definition sqlite3ext.h:427
#define sqlite3_stmt_status
Definition sqlite3ext.h:576
#define sqlite3_db_status
Definition sqlite3ext.h:571
#define sqlite3_column_decltype
Definition sqlite3ext.h:422
#define sqlite3_column_count
Definition sqlite3ext.h:419

References displayStatLine(), ShellState::out, ShellState::pStmt, ShellState::shellFlgs, SHFLG_Lookaside, SHFLG_Pagecache, sqlite3_column_count, sqlite3_column_database_name, sqlite3_column_decltype, sqlite3_column_name, sqlite3_column_origin_name, sqlite3_column_table_name, sqlite3_db_status, sqlite3_fprintf, sqlite3_snprintf, sqlite3_stmt_status, SQLITE_DBSTATUS_CACHE_HIT, SQLITE_DBSTATUS_CACHE_MISS, SQLITE_DBSTATUS_CACHE_SPILL, SQLITE_DBSTATUS_CACHE_USED, SQLITE_DBSTATUS_CACHE_WRITE, SQLITE_DBSTATUS_LOOKASIDE_HIT, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, SQLITE_DBSTATUS_LOOKASIDE_USED, SQLITE_DBSTATUS_SCHEMA_USED, SQLITE_DBSTATUS_STMT_USED, SQLITE_STATUS_MALLOC_COUNT, SQLITE_STATUS_MALLOC_SIZE, SQLITE_STATUS_MEMORY_USED, SQLITE_STATUS_PAGECACHE_OVERFLOW, SQLITE_STATUS_PAGECACHE_SIZE, SQLITE_STATUS_PAGECACHE_USED, SQLITE_STATUS_PARSER_STACK, SQLITE_STMTSTATUS_AUTOINDEX, SQLITE_STMTSTATUS_FILTER_HIT, SQLITE_STMTSTATUS_FILTER_MISS, SQLITE_STMTSTATUS_FULLSCAN_STEP, SQLITE_STMTSTATUS_MEMUSED, SQLITE_STMTSTATUS_REPREPARE, SQLITE_STMTSTATUS_RUN, SQLITE_STMTSTATUS_SORT, SQLITE_STMTSTATUS_VM_STEP, and ShellState::statsOn.

Referenced by do_meta_command(), and shell_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ displayStatLine()

void displayStatLine ( FILE * out,
char * zLabel,
char * zFormat,
int iStatusCtrl,
int bReset )
static
23578 {
23579 sqlite3_int64 iCur = -1;
23580 sqlite3_int64 iHiwtr = -1;
23581 int i, nPercent;
23582 char zLine[200];
23583 sqlite3_status64(iStatusCtrl, &iCur, &iHiwtr, bReset);
23584 for(i=0, nPercent=0; zFormat[i]; i++){
23585 if( zFormat[i]=='%' ) nPercent++;
23586 }
23587 if( nPercent>1 ){
23588 sqlite3_snprintf(sizeof(zLine), zLine, zFormat, iCur, iHiwtr);
23589 }else{
23590 sqlite3_snprintf(sizeof(zLine), zLine, zFormat, iHiwtr);
23591 }
#define sqlite3_status64
Definition sqlite3ext.h:621

References sqlite3_fprintf, sqlite3_snprintf, and sqlite3_status64.

Referenced by display_stats().

Here is the caller graph for this function:

◆ do_meta_command()

int do_meta_command ( char * zLine,
ShellState * p )
static
28804 {
28805 int h = 1;
28806 int nArg = 0;
28807 int n, c;
28808 int rc = 0;
28809 char *azArg[52];
28810
28811#ifndef SQLITE_OMIT_VIRTUALTABLE
28812 if( p->expert.pExpert ){
28813 expertFinish(p, 1, 0);
28814 }
28815#endif
28816
28817 /* Parse the input line into tokens.
28818 */
28819 while( zLine[h] && nArg<ArraySize(azArg)-1 ){
28820 while( IsSpace(zLine[h]) ){ h++; }
28821 if( zLine[h]==0 ) break;
28822 if( zLine[h]=='\'' || zLine[h]=='"' ){
28823 int delim = zLine[h++];
28824 azArg[nArg++] = &zLine[h];
28825 while( zLine[h] && zLine[h]!=delim ){
28826 if( zLine[h]=='\\' && delim=='"' && zLine[h+1]!=0 ) h++;
28827 h++;
28828 }
28829 if( zLine[h]==delim ){
28830 zLine[h++] = 0;
28831 }
28832 if( delim=='"' ) resolve_backslashes(azArg[nArg-1]);
28833 }else{
28834 azArg[nArg++] = &zLine[h];
28835 while( zLine[h] && !IsSpace(zLine[h]) ){ h++; }
28836 if( zLine[h] ) zLine[h++] = 0;
28837 }
28838 }
28839 azArg[nArg] = 0;
28840
28841 /* Process the input line.
28842 */
28843 if( nArg==0 ) return 0; /* no tokens, no error */
28844 n = strlen30(azArg[0]);
28845 c = azArg[0][0];
28846 clearTempFile(p);
28847
28848#ifndef SQLITE_OMIT_AUTHORIZATION
28849 if( c=='a' && cli_strncmp(azArg[0], "auth", n)==0 ){
28850 if( nArg!=2 ){
28851 sqlite3_fprintf(stderr, "Usage: .auth ON|OFF\n");
28852 rc = 1;
28853 goto meta_command_exit;
28854 }
28855 open_db(p, 0);
28856 if( booleanValue(azArg[1]) ){
28858 }else if( p->bSafeModePersist ){
28860 }else{
28861 sqlite3_set_authorizer(p->db, 0, 0);
28862 }
28863 }else
28864#endif
28865
28866#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
28867 && !defined(SQLITE_SHELL_FIDDLE)
28868 if( c=='a' && cli_strncmp(azArg[0], "archive", n)==0 ){
28869 open_db(p, 0);
28870 failIfSafeMode(p, "cannot run .archive in safe mode");
28871 rc = arDotCommand(p, 0, azArg, nArg);
28872 }else
28873#endif
28874
28875#ifndef SQLITE_SHELL_FIDDLE
28876 if( (c=='b' && n>=3 && cli_strncmp(azArg[0], "backup", n)==0)
28877 || (c=='s' && n>=3 && cli_strncmp(azArg[0], "save", n)==0)
28878 ){
28879 const char *zDestFile = 0;
28880 const char *zDb = 0;
28881 sqlite3 *pDest;
28882 sqlite3_backup *pBackup;
28883 int j;
28884 int bAsync = 0;
28885 const char *zVfs = 0;
28886 failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]);
28887 for(j=1; j<nArg; j++){
28888 const char *z = azArg[j];
28889 if( z[0]=='-' ){
28890 if( z[1]=='-' ) z++;
28891 if( cli_strcmp(z, "-append")==0 ){
28892 zVfs = "apndvfs";
28893 }else
28894 if( cli_strcmp(z, "-async")==0 ){
28895 bAsync = 1;
28896 }else
28897 {
28898 sqlite3_fprintf(stderr,"unknown option: %s\n", azArg[j]);
28899 return 1;
28900 }
28901 }else if( zDestFile==0 ){
28902 zDestFile = azArg[j];
28903 }else if( zDb==0 ){
28904 zDb = zDestFile;
28905 zDestFile = azArg[j];
28906 }else{
28907 sqlite3_fprintf(stderr, "Usage: .backup ?DB? ?OPTIONS? FILENAME\n");
28908 return 1;
28909 }
28910 }
28911 if( zDestFile==0 ){
28912 sqlite3_fprintf(stderr, "missing FILENAME argument on .backup\n");
28913 return 1;
28914 }
28915 if( zDb==0 ) zDb = "main";
28916 rc = sqlite3_open_v2(zDestFile, &pDest,
28918 if( rc!=SQLITE_OK ){
28919 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zDestFile);
28920 close_db(pDest);
28921 return 1;
28922 }
28923 if( bAsync ){
28924 sqlite3_exec(pDest, "PRAGMA synchronous=OFF; PRAGMA journal_mode=OFF;",
28925 0, 0, 0);
28926 }
28927 open_db(p, 0);
28928 pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
28929 if( pBackup==0 ){
28930 shellDatabaseError(pDest);
28931 close_db(pDest);
28932 return 1;
28933 }
28934 while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){}
28935 sqlite3_backup_finish(pBackup);
28936 if( rc==SQLITE_DONE ){
28937 rc = 0;
28938 }else{
28939 shellDatabaseError(pDest);
28940 rc = 1;
28941 }
28942 close_db(pDest);
28943 }else
28944#endif /* !defined(SQLITE_SHELL_FIDDLE) */
28945
28946 if( c=='b' && n>=3 && cli_strncmp(azArg[0], "bail", n)==0 ){
28947 if( nArg==2 ){
28948 bail_on_error = booleanValue(azArg[1]);
28949 }else{
28950 eputz("Usage: .bail on|off\n");
28951 rc = 1;
28952 }
28953 }else
28954
28955 /* Undocumented. Legacy only. See "crlf" below */
28956 if( c=='b' && n>=3 && cli_strncmp(azArg[0], "binary", n)==0 ){
28957 eputz("The \".binary\" command is deprecated.\n");
28958 rc = 1;
28959 }else
28960
28961 /* The undocumented ".breakpoint" command causes a call to the no-op
28962 ** routine named test_breakpoint().
28963 */
28964 if( c=='b' && n>=3 && cli_strncmp(azArg[0], "breakpoint", n)==0 ){
28966 }else
28967
28968#ifndef SQLITE_SHELL_FIDDLE
28969 if( c=='c' && cli_strcmp(azArg[0],"cd")==0 ){
28970 failIfSafeMode(p, "cannot run .cd in safe mode");
28971 if( nArg==2 ){
28972#if defined(_WIN32) || defined(WIN32)
28973 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
28974 rc = !SetCurrentDirectoryW(z);
28975 sqlite3_free(z);
28976#else
28977 rc = chdir(azArg[1]);
28978#endif
28979 if( rc ){
28980 sqlite3_fprintf(stderr,"Cannot change to directory \"%s\"\n", azArg[1]);
28981 rc = 1;
28982 }
28983 }else{
28984 eputz("Usage: .cd DIRECTORY\n");
28985 rc = 1;
28986 }
28987 }else
28988#endif /* !defined(SQLITE_SHELL_FIDDLE) */
28989
28990 if( c=='c' && n>=3 && cli_strncmp(azArg[0], "changes", n)==0 ){
28991 if( nArg==2 ){
28992 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
28993 }else{
28994 eputz("Usage: .changes on|off\n");
28995 rc = 1;
28996 }
28997 }else
28998
28999#ifndef SQLITE_SHELL_FIDDLE
29000 /* Cancel output redirection, if it is currently set (by .testcase)
29001 ** Then read the content of the testcase-out.txt file and compare against
29002 ** azArg[1]. If there are differences, report an error and exit.
29003 */
29004 if( c=='c' && n>=3 && cli_strncmp(azArg[0], "check", n)==0 ){
29005 char *zRes = 0;
29006 output_reset(p);
29007 if( nArg!=2 ){
29008 eputz("Usage: .check GLOB-PATTERN\n");
29009 rc = 2;
29010 }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){
29011 rc = 2;
29012 }else if( testcase_glob(azArg[1],zRes)==0 ){
29013 sqlite3_fprintf(stderr,
29014 "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
29015 p->zTestcase, azArg[1], zRes);
29016 rc = 1;
29017 }else{
29018 sqlite3_fprintf(p->out, "testcase-%s ok\n", p->zTestcase);
29019 p->nCheck++;
29020 }
29021 sqlite3_free(zRes);
29022 }else
29023#endif /* !defined(SQLITE_SHELL_FIDDLE) */
29024
29025#ifndef SQLITE_SHELL_FIDDLE
29026 if( c=='c' && cli_strncmp(azArg[0], "clone", n)==0 ){
29027 failIfSafeMode(p, "cannot run .clone in safe mode");
29028 if( nArg==2 ){
29029 tryToClone(p, azArg[1]);
29030 }else{
29031 eputz("Usage: .clone FILENAME\n");
29032 rc = 1;
29033 }
29034 }else
29035#endif /* !defined(SQLITE_SHELL_FIDDLE) */
29036
29037 if( c=='c' && cli_strncmp(azArg[0], "connection", n)==0 ){
29038 if( nArg==1 ){
29039 /* List available connections */
29040 int i;
29041 for(i=0; i<ArraySize(p->aAuxDb); i++){
29042 const char *zFile = p->aAuxDb[i].zDbFilename;
29043 if( p->aAuxDb[i].db==0 && p->pAuxDb!=&p->aAuxDb[i] ){
29044 zFile = "(not open)";
29045 }else if( zFile==0 ){
29046 zFile = "(memory)";
29047 }else if( zFile[0]==0 ){
29048 zFile = "(temporary-file)";
29049 }
29050 if( p->pAuxDb == &p->aAuxDb[i] ){
29051 sqlite3_fprintf(stdout, "ACTIVE %d: %s\n", i, zFile);
29052 }else if( p->aAuxDb[i].db!=0 ){
29053 sqlite3_fprintf(stdout, " %d: %s\n", i, zFile);
29054 }
29055 }
29056 }else if( nArg==2 && IsDigit(azArg[1][0]) && azArg[1][1]==0 ){
29057 int i = azArg[1][0] - '0';
29058 if( p->pAuxDb != &p->aAuxDb[i] && i>=0 && i<ArraySize(p->aAuxDb) ){
29059 p->pAuxDb->db = p->db;
29060 p->pAuxDb = &p->aAuxDb[i];
29061 globalDb = p->db = p->pAuxDb->db;
29062 p->pAuxDb->db = 0;
29063 }
29064 }else if( nArg==3 && cli_strcmp(azArg[1], "close")==0
29065 && IsDigit(azArg[2][0]) && azArg[2][1]==0 ){
29066 int i = azArg[2][0] - '0';
29067 if( i<0 || i>=ArraySize(p->aAuxDb) ){
29068 /* No-op */
29069 }else if( p->pAuxDb == &p->aAuxDb[i] ){
29070 eputz("cannot close the active database connection\n");
29071 rc = 1;
29072 }else if( p->aAuxDb[i].db ){
29073 session_close_all(p, i);
29074 close_db(p->aAuxDb[i].db);
29075 p->aAuxDb[i].db = 0;
29076 }
29077 }else{
29078 eputz("Usage: .connection [close] [CONNECTION-NUMBER]\n");
29079 rc = 1;
29080 }
29081 }else
29082
29083 if( c=='c' && n==4
29084 && (cli_strncmp(azArg[0], "crlf", n)==0
29085 || cli_strncmp(azArg[0], "crnl",n)==0)
29086 ){
29087 if( nArg==2 ){
29088#ifdef _WIN32
29089 p->crlfMode = booleanValue(azArg[1]);
29090#else
29091 p->crlfMode = 0;
29092#endif
29093 }
29094 sqlite3_fprintf(stderr, "crlf is %s\n", p->crlfMode ? "ON" : "OFF");
29095 }else
29096
29097 if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){
29098 char **azName = 0;
29099 int nName = 0;
29100 sqlite3_stmt *pStmt;
29101 int i;
29102 open_db(p, 0);
29103 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
29104 if( rc ){
29106 rc = 1;
29107 }else{
29108 while( sqlite3_step(pStmt)==SQLITE_ROW ){
29109 const char *zSchema = (const char *)sqlite3_column_text(pStmt,1);
29110 const char *zFile = (const char*)sqlite3_column_text(pStmt,2);
29111 if( zSchema==0 || zFile==0 ) continue;
29112 azName = sqlite3_realloc(azName, (nName+1)*2*sizeof(char*));
29113 shell_check_oom(azName);
29114 azName[nName*2] = strdup(zSchema);
29115 azName[nName*2+1] = strdup(zFile);
29116 nName++;
29117 }
29118 }
29119 sqlite3_finalize(pStmt);
29120 for(i=0; i<nName; i++){
29121 int eTxn = sqlite3_txn_state(p->db, azName[i*2]);
29122 int bRdonly = sqlite3_db_readonly(p->db, azName[i*2]);
29123 const char *z = azName[i*2+1];
29124 sqlite3_fprintf(p->out, "%s: %s %s%s\n",
29125 azName[i*2], z && z[0] ? z : "\"\"", bRdonly ? "r/o" : "r/w",
29126 eTxn==SQLITE_TXN_NONE ? "" :
29127 eTxn==SQLITE_TXN_READ ? " read-txn" : " write-txn");
29128 free(azName[i*2]);
29129 free(azName[i*2+1]);
29130 }
29131 sqlite3_free(azName);
29132 }else
29133
29134 if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbconfig", n)==0 ){
29135 static const struct DbConfigChoices {
29136 const char *zName;
29137 int op;
29138 } aDbConfig[] = {
29139 { "attach_create", SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE },
29140 { "attach_write", SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE },
29141 { "comments", SQLITE_DBCONFIG_ENABLE_COMMENTS },
29142 { "defensive", SQLITE_DBCONFIG_DEFENSIVE },
29143 { "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
29144 { "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
29145 { "enable_fkey", SQLITE_DBCONFIG_ENABLE_FKEY },
29146 { "enable_qpsg", SQLITE_DBCONFIG_ENABLE_QPSG },
29147 { "enable_trigger", SQLITE_DBCONFIG_ENABLE_TRIGGER },
29148 { "enable_view", SQLITE_DBCONFIG_ENABLE_VIEW },
29149 { "fts3_tokenizer", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
29150 { "legacy_alter_table", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE },
29151 { "legacy_file_format", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT },
29152 { "load_extension", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
29153 { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
29154 { "reset_database", SQLITE_DBCONFIG_RESET_DATABASE },
29155 { "reverse_scanorder", SQLITE_DBCONFIG_REVERSE_SCANORDER },
29156 { "stmt_scanstatus", SQLITE_DBCONFIG_STMT_SCANSTATUS },
29157 { "trigger_eqp", SQLITE_DBCONFIG_TRIGGER_EQP },
29158 { "trusted_schema", SQLITE_DBCONFIG_TRUSTED_SCHEMA },
29159 { "writable_schema", SQLITE_DBCONFIG_WRITABLE_SCHEMA },
29160 };
29161 int ii, v;
29162 open_db(p, 0);
29163 for(ii=0; ii<ArraySize(aDbConfig); ii++){
29164 if( nArg>1 && cli_strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
29165 if( nArg>=3 ){
29166 sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
29167 }
29168 sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
29169 sqlite3_fprintf(p->out, "%19s %s\n",
29170 aDbConfig[ii].zName, v ? "on" : "off");
29171 if( nArg>1 ) break;
29172 }
29173 if( nArg>1 && ii==ArraySize(aDbConfig) ){
29174 sqlite3_fprintf(stderr,"Error: unknown dbconfig \"%s\"\n", azArg[1]);
29175 eputz("Enter \".dbconfig\" with no arguments for a list\n");
29176 }
29177 }else
29178
29179#if SQLITE_SHELL_HAVE_RECOVER
29180 if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbinfo", n)==0 ){
29181 rc = shell_dbinfo_command(p, nArg, azArg);
29182 }else
29183
29184 if( c=='r' && cli_strncmp(azArg[0], "recover", n)==0 ){
29185 open_db(p, 0);
29186 rc = recoverDatabaseCmd(p, nArg, azArg);
29187 }else
29188#endif /* SQLITE_SHELL_HAVE_RECOVER */
29189
29190 if( c=='d' && cli_strncmp(azArg[0], "dump", n)==0 ){
29191 char *zLike = 0;
29192 char *zSql;
29193 int i;
29194 int savedShowHeader = p->showHeader;
29195 int savedShellFlags = p->shellFlgs;
29199 for(i=1; i<nArg; i++){
29200 if( azArg[i][0]=='-' ){
29201 const char *z = azArg[i]+1;
29202 if( z[0]=='-' ) z++;
29203 if( cli_strcmp(z,"preserve-rowids")==0 ){
29204#ifdef SQLITE_OMIT_VIRTUALTABLE
29205 eputz("The --preserve-rowids option is not compatible"
29206 " with SQLITE_OMIT_VIRTUALTABLE\n");
29207 rc = 1;
29208 sqlite3_free(zLike);
29209 goto meta_command_exit;
29210#else
29212#endif
29213 }else
29214 if( cli_strcmp(z,"newlines")==0 ){
29216 }else
29217 if( cli_strcmp(z,"data-only")==0 ){
29219 }else
29220 if( cli_strcmp(z,"nosys")==0 ){
29222 }else
29223 {
29224 sqlite3_fprintf(stderr,
29225 "Unknown option \"%s\" on \".dump\"\n", azArg[i]);
29226 rc = 1;
29227 sqlite3_free(zLike);
29228 goto meta_command_exit;
29229 }
29230 }else{
29231 /* azArg[i] contains a LIKE pattern. This ".dump" request should
29232 ** only dump data for tables for which either the table name matches
29233 ** the LIKE pattern, or the table appears to be a shadow table of
29234 ** a virtual table for which the name matches the LIKE pattern.
29235 */
29236 char *zExpr = sqlite3_mprintf(
29237 "name LIKE %Q ESCAPE '\\' OR EXISTS ("
29238 " SELECT 1 FROM sqlite_schema WHERE "
29239 " name LIKE %Q ESCAPE '\\' AND"
29240 " sql LIKE 'CREATE VIRTUAL TABLE%%' AND"
29241 " substr(o.name, 1, length(name)+1) == (name||'_')"
29242 ")", azArg[i], azArg[i]
29243 );
29244
29245 if( zLike ){
29246 zLike = sqlite3_mprintf("%z OR %z", zLike, zExpr);
29247 }else{
29248 zLike = zExpr;
29249 }
29250 }
29251 }
29252
29253 open_db(p, 0);
29254
29255 outputDumpWarning(p, zLike);
29256 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
29257 /* When playing back a "dump", the content might appear in an order
29258 ** which causes immediate foreign key constraints to be violated.
29259 ** So disable foreign-key constraint enforcement to prevent problems. */
29260 sqlite3_fputs("PRAGMA foreign_keys=OFF;\n", p->out);
29261 sqlite3_fputs("BEGIN TRANSACTION;\n", p->out);
29262 }
29263 p->writableSchema = 0;
29264 p->showHeader = 0;
29265 /* Set writable_schema=ON since doing so forces SQLite to initialize
29266 ** as much of the schema as it can even if the sqlite_schema table is
29267 ** corrupt. */
29268 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
29269 p->nErr = 0;
29270 if( zLike==0 ) zLike = sqlite3_mprintf("true");
29271 zSql = sqlite3_mprintf(
29272 "SELECT name, type, sql FROM sqlite_schema AS o "
29273 "WHERE (%s) AND type=='table'"
29274 " AND sql NOT NULL"
29275 " ORDER BY tbl_name='sqlite_sequence', rowid",
29276 zLike
29277 );
29278 run_schema_dump_query(p,zSql);
29279 sqlite3_free(zSql);
29280 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
29281 zSql = sqlite3_mprintf(
29282 "SELECT sql FROM sqlite_schema AS o "
29283 "WHERE (%s) AND sql NOT NULL"
29284 " AND type IN ('index','trigger','view') "
29285 "ORDER BY type COLLATE NOCASE DESC",
29286 zLike
29287 );
29288 run_table_dump_query(p, zSql);
29289 sqlite3_free(zSql);
29290 }
29291 sqlite3_free(zLike);
29292 if( p->writableSchema ){
29293 sqlite3_fputs("PRAGMA writable_schema=OFF;\n", p->out);
29294 p->writableSchema = 0;
29295 }
29296 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
29297 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
29298 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
29299 sqlite3_fputs(p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n", p->out);
29300 }
29301 p->showHeader = savedShowHeader;
29302 p->shellFlgs = savedShellFlags;
29303 }else
29304
29305 if( c=='e' && cli_strncmp(azArg[0], "echo", n)==0 ){
29306 if( nArg==2 ){
29307 setOrClearFlag(p, SHFLG_Echo, azArg[1]);
29308 }else{
29309 eputz("Usage: .echo on|off\n");
29310 rc = 1;
29311 }
29312 }else
29313
29314 if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbtotxt", n)==0 ){
29315 rc = shell_dbtotxt_command(p, nArg, azArg);
29316 }else
29317
29318 if( c=='e' && cli_strncmp(azArg[0], "eqp", n)==0 ){
29319 if( nArg==2 ){
29320 p->autoEQPtest = 0;
29321 if( p->autoEQPtrace ){
29322 if( p->db ) sqlite3_exec(p->db, "PRAGMA vdbe_trace=OFF;", 0, 0, 0);
29323 p->autoEQPtrace = 0;
29324 }
29325 if( cli_strcmp(azArg[1],"full")==0 ){
29326 p->autoEQP = AUTOEQP_full;
29327 }else if( cli_strcmp(azArg[1],"trigger")==0 ){
29329#ifdef SQLITE_DEBUG
29330 }else if( cli_strcmp(azArg[1],"test")==0 ){
29331 p->autoEQP = AUTOEQP_on;
29332 p->autoEQPtest = 1;
29333 }else if( cli_strcmp(azArg[1],"trace")==0 ){
29334 p->autoEQP = AUTOEQP_full;
29335 p->autoEQPtrace = 1;
29336 open_db(p, 0);
29337 sqlite3_exec(p->db, "SELECT name FROM sqlite_schema LIMIT 1", 0, 0, 0);
29338 sqlite3_exec(p->db, "PRAGMA vdbe_trace=ON;", 0, 0, 0);
29339#endif
29340 }else{
29341 p->autoEQP = (u8)booleanValue(azArg[1]);
29342 }
29343 }else{
29344 eputz("Usage: .eqp off|on|trace|trigger|full\n");
29345 rc = 1;
29346 }
29347 }else
29348
29349#ifndef SQLITE_SHELL_FIDDLE
29350 if( c=='e' && cli_strncmp(azArg[0], "exit", n)==0 ){
29351 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
29352 rc = 2;
29353 }else
29354#endif
29355
29356 /* The ".explain" command is automatic now. It is largely pointless. It
29357 ** retained purely for backwards compatibility */
29358 if( c=='e' && cli_strncmp(azArg[0], "explain", n)==0 ){
29359 int val = 1;
29360 if( nArg>=2 ){
29361 if( cli_strcmp(azArg[1],"auto")==0 ){
29362 val = 99;
29363 }else{
29364 val = booleanValue(azArg[1]);
29365 }
29366 }
29367 if( val==1 && p->mode!=MODE_Explain ){
29368 p->normalMode = p->mode;
29369 p->mode = MODE_Explain;
29370 p->autoExplain = 0;
29371 }else if( val==0 ){
29372 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
29373 p->autoExplain = 0;
29374 }else if( val==99 ){
29375 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
29376 p->autoExplain = 1;
29377 }
29378 }else
29379
29380#ifndef SQLITE_OMIT_VIRTUALTABLE
29381 if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){
29382 if( p->bSafeMode ){
29383 sqlite3_fprintf(stderr,
29384 "Cannot run experimental commands such as \"%s\" in safe mode\n",
29385 azArg[0]);
29386 rc = 1;
29387 }else{
29388 open_db(p, 0);
29389 expertDotCommand(p, azArg, nArg);
29390 }
29391 }else
29392#endif
29393
29394 if( c=='f' && cli_strncmp(azArg[0], "filectrl", n)==0 ){
29395 static const struct {
29396 const char *zCtrlName; /* Name of a test-control option */
29397 int ctrlCode; /* Integer code for that option */
29398 const char *zUsage; /* Usage notes */
29399 } aCtrl[] = {
29400 { "chunk_size", SQLITE_FCNTL_CHUNK_SIZE, "SIZE" },
29401 { "data_version", SQLITE_FCNTL_DATA_VERSION, "" },
29402 { "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
29403 { "lock_timeout", SQLITE_FCNTL_LOCK_TIMEOUT, "MILLISEC" },
29404 { "persist_wal", SQLITE_FCNTL_PERSIST_WAL, "[BOOLEAN]" },
29405 /* { "pragma", SQLITE_FCNTL_PRAGMA, "NAME ARG" },*/
29406 { "psow", SQLITE_FCNTL_POWERSAFE_OVERWRITE, "[BOOLEAN]" },
29407 { "reserve_bytes", SQLITE_FCNTL_RESERVE_BYTES, "[N]" },
29408 { "size_limit", SQLITE_FCNTL_SIZE_LIMIT, "[LIMIT]" },
29409 { "tempfilename", SQLITE_FCNTL_TEMPFILENAME, "" },
29410 /* { "win32_av_retry", SQLITE_FCNTL_WIN32_AV_RETRY, "COUNT DELAY" },*/
29411 };
29412 int filectrl = -1;
29413 int iCtrl = -1;
29414 sqlite3_int64 iRes = 0; /* Integer result to display if rc2==1 */
29415 int isOk = 0; /* 0: usage 1: %lld 2: no-result */
29416 int n2, i;
29417 const char *zCmd = 0;
29418 const char *zSchema = 0;
29419
29420 open_db(p, 0);
29421 zCmd = nArg>=2 ? azArg[1] : "help";
29422
29423 if( zCmd[0]=='-'
29424 && (cli_strcmp(zCmd,"--schema")==0 || cli_strcmp(zCmd,"-schema")==0)
29425 && nArg>=4
29426 ){
29427 zSchema = azArg[2];
29428 for(i=3; i<nArg; i++) azArg[i-2] = azArg[i];
29429 nArg -= 2;
29430 zCmd = azArg[1];
29431 }
29432
29433 /* The argument can optionally begin with "-" or "--" */
29434 if( zCmd[0]=='-' && zCmd[1] ){
29435 zCmd++;
29436 if( zCmd[0]=='-' && zCmd[1] ) zCmd++;
29437 }
29438
29439 /* --help lists all file-controls */
29440 if( cli_strcmp(zCmd,"help")==0 ){
29441 sqlite3_fputs("Available file-controls:\n", p->out);
29442 for(i=0; i<ArraySize(aCtrl); i++){
29444 " .filectrl %s %s\n", aCtrl[i].zCtrlName, aCtrl[i].zUsage);
29445 }
29446 rc = 1;
29447 goto meta_command_exit;
29448 }
29449
29450 /* convert filectrl text option to value. allow any unique prefix
29451 ** of the option name, or a numerical value. */
29452 n2 = strlen30(zCmd);
29453 for(i=0; i<ArraySize(aCtrl); i++){
29454 if( cli_strncmp(zCmd, aCtrl[i].zCtrlName, n2)==0 ){
29455 if( filectrl<0 ){
29456 filectrl = aCtrl[i].ctrlCode;
29457 iCtrl = i;
29458 }else{
29459 sqlite3_fprintf(stderr,"Error: ambiguous file-control: \"%s\"\n"
29460 "Use \".filectrl --help\" for help\n", zCmd);
29461 rc = 1;
29462 goto meta_command_exit;
29463 }
29464 }
29465 }
29466 if( filectrl<0 ){
29467 sqlite3_fprintf(stderr,"Error: unknown file-control: %s\n"
29468 "Use \".filectrl --help\" for help\n", zCmd);
29469 }else{
29470 switch(filectrl){
29472 if( nArg!=2 && nArg!=3 ) break;
29473 iRes = nArg==3 ? integerValue(azArg[2]) : -1;
29474 sqlite3_file_control(p->db, zSchema, SQLITE_FCNTL_SIZE_LIMIT, &iRes);
29475 isOk = 1;
29476 break;
29477 }
29480 int x;
29481 if( nArg!=3 ) break;
29482 x = (int)integerValue(azArg[2]);
29483 sqlite3_file_control(p->db, zSchema, filectrl, &x);
29484 isOk = 2;
29485 break;
29486 }
29489 int x;
29490 if( nArg!=2 && nArg!=3 ) break;
29491 x = nArg==3 ? booleanValue(azArg[2]) : -1;
29492 sqlite3_file_control(p->db, zSchema, filectrl, &x);
29493 iRes = x;
29494 isOk = 1;
29495 break;
29496 }
29499 int x;
29500 if( nArg!=2 ) break;
29501 sqlite3_file_control(p->db, zSchema, filectrl, &x);
29502 iRes = x;
29503 isOk = 1;
29504 break;
29505 }
29507 char *z = 0;
29508 if( nArg!=2 ) break;
29509 sqlite3_file_control(p->db, zSchema, filectrl, &z);
29510 if( z ){
29511 sqlite3_fprintf(p->out, "%s\n", z);
29512 sqlite3_free(z);
29513 }
29514 isOk = 2;
29515 break;
29516 }
29518 int x;
29519 if( nArg>=3 ){
29520 x = atoi(azArg[2]);
29521 sqlite3_file_control(p->db, zSchema, filectrl, &x);
29522 }
29523 x = -1;
29524 sqlite3_file_control(p->db, zSchema, filectrl, &x);
29525 sqlite3_fprintf(p->out, "%d\n", x);
29526 isOk = 2;
29527 break;
29528 }
29529 }
29530 }
29531 if( isOk==0 && iCtrl>=0 ){
29532 sqlite3_fprintf(p->out, "Usage: .filectrl %s %s\n",
29533 zCmd, aCtrl[iCtrl].zUsage);
29534 rc = 1;
29535 }else if( isOk==1 ){
29536 char zBuf[100];
29537 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", iRes);
29538 sqlite3_fprintf(p->out, "%s\n", zBuf);
29539 }
29540 }else
29541
29542 if( c=='f' && cli_strncmp(azArg[0], "fullschema", n)==0 ){
29543 ShellState data;
29544 int doStats = 0;
29545 memcpy(&data, p, sizeof(data));
29546 data.showHeader = 0;
29547 data.cMode = data.mode = MODE_Semi;
29548 if( nArg==2 && optionMatch(azArg[1], "indent") ){
29549 data.cMode = data.mode = MODE_Pretty;
29550 nArg = 1;
29551 }
29552 if( nArg!=1 ){
29553 eputz("Usage: .fullschema ?--indent?\n");
29554 rc = 1;
29555 goto meta_command_exit;
29556 }
29557 open_db(p, 0);
29558 rc = sqlite3_exec(p->db,
29559 "SELECT sql FROM"
29560 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
29561 " FROM sqlite_schema UNION ALL"
29562 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_schema) "
29563 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
29564 "ORDER BY x",
29565 callback, &data, 0
29566 );
29567 if( rc==SQLITE_OK ){
29568 sqlite3_stmt *pStmt;
29569 rc = sqlite3_prepare_v2(p->db,
29570 "SELECT rowid FROM sqlite_schema"
29571 " WHERE name GLOB 'sqlite_stat[134]'",
29572 -1, &pStmt, 0);
29573 if( rc==SQLITE_OK ){
29574 doStats = sqlite3_step(pStmt)==SQLITE_ROW;
29575 sqlite3_finalize(pStmt);
29576 }
29577 }
29578 if( doStats==0 ){
29579 sqlite3_fputs("/* No STAT tables available */\n", p->out);
29580 }else{
29581 sqlite3_fputs("ANALYZE sqlite_schema;\n", p->out);
29582 data.cMode = data.mode = MODE_Insert;
29583 data.zDestTable = "sqlite_stat1";
29584 shell_exec(&data, "SELECT * FROM sqlite_stat1", 0);
29585 data.zDestTable = "sqlite_stat4";
29586 shell_exec(&data, "SELECT * FROM sqlite_stat4", 0);
29587 sqlite3_fputs("ANALYZE sqlite_schema;\n", p->out);
29588 }
29589 }else
29590
29591 if( c=='h' && cli_strncmp(azArg[0], "headers", n)==0 ){
29592 if( nArg==2 ){
29593 p->showHeader = booleanValue(azArg[1]);
29595 }else{
29596 eputz("Usage: .headers on|off\n");
29597 rc = 1;
29598 }
29599 }else
29600
29601 if( c=='h' && cli_strncmp(azArg[0], "help", n)==0 ){
29602 if( nArg>=2 ){
29603 n = showHelp(p->out, azArg[1]);
29604 if( n==0 ){
29605 sqlite3_fprintf(p->out, "Nothing matches '%s'\n", azArg[1]);
29606 }
29607 }else{
29608 showHelp(p->out, 0);
29609 }
29610 }else
29611
29612#ifndef SQLITE_SHELL_FIDDLE
29613 if( c=='i' && cli_strncmp(azArg[0], "import", n)==0 ){
29614 char *zTable = 0; /* Insert data into this table */
29615 char *zSchema = 0; /* Schema of zTable */
29616 char *zFile = 0; /* Name of file to extra content from */
29617 sqlite3_stmt *pStmt = NULL; /* A statement */
29618 int nCol; /* Number of columns in the table */
29619 i64 nByte; /* Number of bytes in an SQL string */
29620 int i, j; /* Loop counters */
29621 int needCommit; /* True to COMMIT or ROLLBACK at end */
29622 int nSep; /* Number of bytes in p->colSeparator[] */
29623 char *zSql = 0; /* An SQL statement */
29624 ImportCtx sCtx; /* Reader context */
29625 char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
29626 int eVerbose = 0; /* Larger for more console output */
29627 int nSkip = 0; /* Initial lines to skip */
29628 int useOutputMode = 1; /* Use output mode to determine separators */
29629 char *zCreate = 0; /* CREATE TABLE statement text */
29630
29631 failIfSafeMode(p, "cannot run .import in safe mode");
29632 memset(&sCtx, 0, sizeof(sCtx));
29633 if( p->mode==MODE_Ascii ){
29634 xRead = ascii_read_one_field;
29635 }else{
29636 xRead = csv_read_one_field;
29637 }
29638 rc = 1;
29639 for(i=1; i<nArg; i++){
29640 char *z = azArg[i];
29641 if( z[0]=='-' && z[1]=='-' ) z++;
29642 if( z[0]!='-' ){
29643 if( zFile==0 ){
29644 zFile = z;
29645 }else if( zTable==0 ){
29646 zTable = z;
29647 }else{
29648 sqlite3_fprintf(p->out, "ERROR: extra argument: \"%s\". Usage:\n",z);
29649 showHelp(p->out, "import");
29650 goto meta_command_exit;
29651 }
29652 }else if( cli_strcmp(z,"-v")==0 ){
29653 eVerbose++;
29654 }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
29655 zSchema = azArg[++i];
29656 }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
29657 nSkip = integerValue(azArg[++i]);
29658 }else if( cli_strcmp(z,"-ascii")==0 ){
29659 sCtx.cColSep = SEP_Unit[0];
29660 sCtx.cRowSep = SEP_Record[0];
29661 xRead = ascii_read_one_field;
29662 useOutputMode = 0;
29663 }else if( cli_strcmp(z,"-csv")==0 ){
29664 sCtx.cColSep = ',';
29665 sCtx.cRowSep = '\n';
29666 xRead = csv_read_one_field;
29667 useOutputMode = 0;
29668 }else{
29669 sqlite3_fprintf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", z);
29670 showHelp(p->out, "import");
29671 goto meta_command_exit;
29672 }
29673 }
29674 if( zTable==0 ){
29675 sqlite3_fprintf(p->out, "ERROR: missing %s argument. Usage:\n",
29676 zFile==0 ? "FILE" : "TABLE");
29677 showHelp(p->out, "import");
29678 goto meta_command_exit;
29679 }
29680 seenInterrupt = 0;
29681 open_db(p, 0);
29682 if( useOutputMode ){
29683 /* If neither the --csv or --ascii options are specified, then set
29684 ** the column and row separator characters from the output mode. */
29685 nSep = strlen30(p->colSeparator);
29686 if( nSep==0 ){
29687 eputz("Error: non-null column separator required for import\n");
29688 goto meta_command_exit;
29689 }
29690 if( nSep>1 ){
29691 eputz("Error: multi-character column separators not allowed"
29692 " for import\n");
29693 goto meta_command_exit;
29694 }
29695 nSep = strlen30(p->rowSeparator);
29696 if( nSep==0 ){
29697 eputz("Error: non-null row separator required for import\n");
29698 goto meta_command_exit;
29699 }
29700 if( nSep==2 && p->mode==MODE_Csv
29702 ){
29703 /* When importing CSV (only), if the row separator is set to the
29704 ** default output row separator, change it to the default input
29705 ** row separator. This avoids having to maintain different input
29706 ** and output row separators. */
29708 nSep = strlen30(p->rowSeparator);
29709 }
29710 if( nSep>1 ){
29711 eputz("Error: multi-character row separators not allowed"
29712 " for import\n");
29713 goto meta_command_exit;
29714 }
29715 sCtx.cColSep = (u8)p->colSeparator[0];
29716 sCtx.cRowSep = (u8)p->rowSeparator[0];
29717 }
29718 sCtx.zFile = zFile;
29719 sCtx.nLine = 1;
29720 if( sCtx.zFile[0]=='|' ){
29721#ifdef SQLITE_OMIT_POPEN
29722 eputz("Error: pipes are not supported in this OS\n");
29723 goto meta_command_exit;
29724#else
29725 sCtx.in = sqlite3_popen(sCtx.zFile+1, "r");
29726 sCtx.zFile = "<pipe>";
29727 sCtx.xCloser = pclose;
29728#endif
29729 }else{
29730 sCtx.in = sqlite3_fopen(sCtx.zFile, "rb");
29731 sCtx.xCloser = fclose;
29732 }
29733 if( sCtx.in==0 ){
29734 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zFile);
29735 goto meta_command_exit;
29736 }
29737 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
29738 char zSep[2];
29739 zSep[1] = 0;
29740 zSep[0] = sCtx.cColSep;
29741 sqlite3_fputs("Column separator ", p->out);
29742 output_c_string(p->out, zSep);
29743 sqlite3_fputs(", row separator ", p->out);
29744 zSep[0] = sCtx.cRowSep;
29745 output_c_string(p->out, zSep);
29746 sqlite3_fputs("\n", p->out);
29747 }
29748 sCtx.z = sqlite3_malloc64(120);
29749 if( sCtx.z==0 ){
29750 import_cleanup(&sCtx);
29752 }
29753 /* Below, resources must be freed before exit. */
29754 while( (nSkip--)>0 ){
29755 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
29756 }
29757 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
29758 if( sqlite3_table_column_metadata(p->db, zSchema, zTable,0,0,0,0,0,0)
29759 && 0==db_int(p->db, "SELECT count(*) FROM \"%w\".sqlite_schema"
29760 " WHERE name=%Q AND type='view'",
29761 zSchema ? zSchema : "main", zTable)
29762 ){
29763 /* Table does not exist. Create it. */
29764 sqlite3 *dbCols = 0;
29765 char *zRenames = 0;
29766 char *zColDefs;
29767 zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"",
29768 zSchema ? zSchema : "main", zTable);
29769 while( xRead(&sCtx) ){
29770 zAutoColumn(sCtx.z, &dbCols, 0);
29771 if( sCtx.cTerm!=sCtx.cColSep ) break;
29772 }
29773 zColDefs = zAutoColumn(0, &dbCols, &zRenames);
29774 if( zRenames!=0 ){
29775 sqlite3_fprintf((stdin_is_interactive && p->in==stdin)? p->out : stderr,
29776 "Columns renamed during .import %s due to duplicates:\n"
29777 "%s\n", sCtx.zFile, zRenames);
29778 sqlite3_free(zRenames);
29779 }
29780 assert(dbCols==0);
29781 if( zColDefs==0 ){
29782 sqlite3_fprintf(stderr,"%s: empty file\n", sCtx.zFile);
29783 import_cleanup(&sCtx);
29784 rc = 1;
29785 sqlite3_free(zCreate);
29786 goto meta_command_exit;
29787 }
29788 zCreate = sqlite3_mprintf("%z%z\n", zCreate, zColDefs);
29789 if( zCreate==0 ){
29790 import_cleanup(&sCtx);
29792 }
29793 if( eVerbose>=1 ){
29794 sqlite3_fprintf(p->out, "%s\n", zCreate);
29795 }
29796 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
29797 if( rc ){
29798 sqlite3_fprintf(stderr,
29799 "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db));
29800 }
29801 sqlite3_free(zCreate);
29802 zCreate = 0;
29803 if( rc ){
29804 import_cleanup(&sCtx);
29805 rc = 1;
29806 goto meta_command_exit;
29807 }
29808 }
29809 zSql = sqlite3_mprintf("SELECT count(*) FROM pragma_table_info(%Q,%Q);",
29810 zTable, zSchema);
29811 if( zSql==0 ){
29812 import_cleanup(&sCtx);
29814 }
29815 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
29816 sqlite3_free(zSql);
29817 zSql = 0;
29818 if( rc ){
29819 if (pStmt) sqlite3_finalize(pStmt);
29821 import_cleanup(&sCtx);
29822 rc = 1;
29823 goto meta_command_exit;
29824 }
29825 if( sqlite3_step(pStmt)==SQLITE_ROW ){
29826 nCol = sqlite3_column_int(pStmt, 0);
29827 }else{
29828 nCol = 0;
29829 }
29830 sqlite3_finalize(pStmt);
29831 pStmt = 0;
29832 if( nCol==0 ) return 0; /* no columns, no error */
29833
29834 nByte = 64 /* space for "INSERT INTO", "VALUES(", ")\0" */
29835 + (zSchema ? strlen(zSchema)*2 + 2: 0) /* Quoted schema name */
29836 + strlen(zTable)*2 + 2 /* Quoted table name */
29837 + nCol*2; /* Space for ",?" for each column */
29838 zSql = sqlite3_malloc64( nByte );
29839 if( zSql==0 ){
29840 import_cleanup(&sCtx);
29842 }
29843 if( zSchema ){
29844 sqlite3_snprintf(nByte, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?",
29845 zSchema, zTable);
29846 }else{
29847 sqlite3_snprintf(nByte, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
29848 }
29849 j = strlen30(zSql);
29850 for(i=1; i<nCol; i++){
29851 zSql[j++] = ',';
29852 zSql[j++] = '?';
29853 }
29854 zSql[j++] = ')';
29855 zSql[j] = 0;
29856 assert( j<nByte );
29857 if( eVerbose>=2 ){
29858 sqlite3_fprintf(p->out, "Insert using: %s\n", zSql);
29859 }
29860 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
29861 sqlite3_free(zSql);
29862 zSql = 0;
29863 if( rc ){
29865 if (pStmt) sqlite3_finalize(pStmt);
29866 import_cleanup(&sCtx);
29867 rc = 1;
29868 goto meta_command_exit;
29869 }
29870 needCommit = sqlite3_get_autocommit(p->db);
29871 if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
29872 do{
29873 int startLine = sCtx.nLine;
29874 for(i=0; i<nCol; i++){
29875 char *z = xRead(&sCtx);
29876 /*
29877 ** Did we reach end-of-file before finding any columns?
29878 ** If so, stop instead of NULL filling the remaining columns.
29879 */
29880 if( z==0 && i==0 ) break;
29881 /*
29882 ** Did we reach end-of-file OR end-of-line before finding any
29883 ** columns in ASCII mode? If so, stop instead of NULL filling
29884 ** the remaining columns.
29885 */
29886 if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
29887 /*
29888 ** For CSV mode, per RFC 4180, accept EOF in lieu of final
29889 ** record terminator but only for last field of multi-field row.
29890 ** (If there are too few fields, it's not valid CSV anyway.)
29891 */
29892 if( z==0 && (xRead==csv_read_one_field) && i==nCol-1 && i>0 ){
29893 z = "";
29894 }
29895 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
29896 if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
29897 sqlite3_fprintf(stderr,"%s:%d: expected %d columns but found %d"
29898 " - filling the rest with NULL\n",
29899 sCtx.zFile, startLine, nCol, i+1);
29900 i += 2;
29901 while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
29902 }
29903 }
29904 if( sCtx.cTerm==sCtx.cColSep ){
29905 do{
29906 xRead(&sCtx);
29907 i++;
29908 }while( sCtx.cTerm==sCtx.cColSep );
29909 sqlite3_fprintf(stderr,
29910 "%s:%d: expected %d columns but found %d - extras ignored\n",
29911 sCtx.zFile, startLine, nCol, i);
29912 }
29913 if( i>=nCol ){
29914 sqlite3_step(pStmt);
29915 rc = sqlite3_reset(pStmt);
29916 if( rc!=SQLITE_OK ){
29917 sqlite3_fprintf(stderr,"%s:%d: INSERT failed: %s\n",
29918 sCtx.zFile, startLine, sqlite3_errmsg(p->db));
29919 sCtx.nErr++;
29920 }else{
29921 sCtx.nRow++;
29922 }
29923 }
29924 }while( sCtx.cTerm!=EOF );
29925
29926 import_cleanup(&sCtx);
29927 sqlite3_finalize(pStmt);
29928 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
29929 if( eVerbose>0 ){
29931 "Added %d rows with %d errors using %d lines of input\n",
29932 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
29933 }
29934 }else
29935#endif /* !defined(SQLITE_SHELL_FIDDLE) */
29936
29937#ifndef SQLITE_UNTESTABLE
29938 if( c=='i' && cli_strncmp(azArg[0], "imposter", n)==0 ){
29939 char *zSql;
29940 char *zCollist = 0;
29941 sqlite3_stmt *pStmt;
29942 int tnum = 0;
29943 int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
29944 int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
29945 int i;
29947 sqlite3_fprintf(stderr,".%s unavailable without --unsafe-testing\n",
29948 "imposter");
29949 rc = 1;
29950 goto meta_command_exit;
29951 }
29952 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
29953 eputz("Usage: .imposter INDEX IMPOSTER\n"
29954 " .imposter off\n");
29955 /* Also allowed, but not documented:
29956 **
29957 ** .imposter TABLE IMPOSTER
29958 **
29959 ** where TABLE is a WITHOUT ROWID table. In that case, the
29960 ** imposter is another WITHOUT ROWID table with the columns in
29961 ** storage order. */
29962 rc = 1;
29963 goto meta_command_exit;
29964 }
29965 open_db(p, 0);
29966 if( nArg==2 ){
29968 goto meta_command_exit;
29969 }
29970 zSql = sqlite3_mprintf(
29971 "SELECT rootpage, 0 FROM sqlite_schema"
29972 " WHERE name='%q' AND type='index'"
29973 "UNION ALL "
29974 "SELECT rootpage, 1 FROM sqlite_schema"
29975 " WHERE name='%q' AND type='table'"
29976 " AND sql LIKE '%%without%%rowid%%'",
29977 azArg[1], azArg[1]
29978 );
29979 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
29980 sqlite3_free(zSql);
29981 if( sqlite3_step(pStmt)==SQLITE_ROW ){
29982 tnum = sqlite3_column_int(pStmt, 0);
29983 isWO = sqlite3_column_int(pStmt, 1);
29984 }
29985 sqlite3_finalize(pStmt);
29986 zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
29987 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
29988 sqlite3_free(zSql);
29989 i = 0;
29990 while( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
29991 char zLabel[20];
29992 const char *zCol = (const char*)sqlite3_column_text(pStmt,2);
29993 i++;
29994 if( zCol==0 ){
29995 if( sqlite3_column_int(pStmt,1)==-1 ){
29996 zCol = "_ROWID_";
29997 }else{
29998 sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
29999 zCol = zLabel;
30000 }
30001 }
30002 if( isWO && lenPK==0 && sqlite3_column_int(pStmt,5)==0 && zCollist ){
30003 lenPK = (int)strlen(zCollist);
30004 }
30005 if( zCollist==0 ){
30006 zCollist = sqlite3_mprintf("\"%w\"", zCol);
30007 }else{
30008 zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
30009 }
30010 }
30011 sqlite3_finalize(pStmt);
30012 if( i==0 || tnum==0 ){
30013 sqlite3_fprintf(stderr,"no such index: \"%s\"\n", azArg[1]);
30014 rc = 1;
30015 sqlite3_free(zCollist);
30016 goto meta_command_exit;
30017 }
30018 if( lenPK==0 ) lenPK = 100000;
30019 zSql = sqlite3_mprintf(
30020 "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%.*s))WITHOUT ROWID",
30021 azArg[2], zCollist, lenPK, zCollist);
30022 sqlite3_free(zCollist);
30023 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
30024 if( rc==SQLITE_OK ){
30025 rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
30027 if( rc ){
30028 sqlite3_fprintf(stderr,
30029 "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
30030 }else{
30031 sqlite3_fprintf(stdout, "%s;\n", zSql);
30032 sqlite3_fprintf(stdout,
30033 "WARNING: writing to an imposter table will corrupt"
30034 " the \"%s\" %s!\n", azArg[1], isWO ? "table" : "index");
30035 }
30036 }else{
30037 sqlite3_fprintf(stderr,"SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
30038 rc = 1;
30039 }
30040 sqlite3_free(zSql);
30041 }else
30042#endif /* !defined(SQLITE_OMIT_TEST_CONTROL) */
30043
30044 if( c=='i' && cli_strncmp(azArg[0], "intck", n)==0 ){
30045 i64 iArg = 0;
30046 if( nArg==2 ){
30047 iArg = integerValue(azArg[1]);
30048 if( iArg==0 ) iArg = -1;
30049 }
30050 if( (nArg!=1 && nArg!=2) || iArg<0 ){
30051 sqlite3_fprintf(stderr,"%s","Usage: .intck STEPS_PER_UNLOCK\n");
30052 rc = 1;
30053 goto meta_command_exit;
30054 }
30055 open_db(p, 0);
30056 rc = intckDatabaseCmd(p, iArg);
30057 }else
30058
30059#ifdef SQLITE_ENABLE_IOTRACE
30060 if( c=='i' && cli_strncmp(azArg[0], "iotrace", n)==0 ){
30061 SQLITE_API extern void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...);
30062 if( iotrace && iotrace!=stdout ) fclose(iotrace);
30063 iotrace = 0;
30064 if( nArg<2 ){
30065 sqlite3IoTrace = 0;
30066 }else if( cli_strcmp(azArg[1], "-")==0 ){
30067 sqlite3IoTrace = iotracePrintf;
30068 iotrace = stdout;
30069 }else{
30070 iotrace = sqlite3_fopen(azArg[1], "w");
30071 if( iotrace==0 ){
30072 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
30073 sqlite3IoTrace = 0;
30074 rc = 1;
30075 }else{
30076 sqlite3IoTrace = iotracePrintf;
30077 }
30078 }
30079 }else
30080#endif
30081
30082 if( c=='l' && n>=5 && cli_strncmp(azArg[0], "limits", n)==0 ){
30083 static const struct {
30084 const char *zLimitName; /* Name of a limit */
30085 int limitCode; /* Integer code for that limit */
30086 } aLimit[] = {
30087 { "length", SQLITE_LIMIT_LENGTH },
30088 { "sql_length", SQLITE_LIMIT_SQL_LENGTH },
30089 { "column", SQLITE_LIMIT_COLUMN },
30090 { "expr_depth", SQLITE_LIMIT_EXPR_DEPTH },
30091 { "compound_select", SQLITE_LIMIT_COMPOUND_SELECT },
30092 { "vdbe_op", SQLITE_LIMIT_VDBE_OP },
30093 { "function_arg", SQLITE_LIMIT_FUNCTION_ARG },
30094 { "attached", SQLITE_LIMIT_ATTACHED },
30095 { "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
30096 { "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER },
30097 { "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH },
30098 { "worker_threads", SQLITE_LIMIT_WORKER_THREADS },
30099 };
30100 int i, n2;
30101 open_db(p, 0);
30102 if( nArg==1 ){
30103 for(i=0; i<ArraySize(aLimit); i++){
30104 sqlite3_fprintf(stdout, "%20s %d\n", aLimit[i].zLimitName,
30105 sqlite3_limit(p->db, aLimit[i].limitCode, -1));
30106 }
30107 }else if( nArg>3 ){
30108 eputz("Usage: .limit NAME ?NEW-VALUE?\n");
30109 rc = 1;
30110 goto meta_command_exit;
30111 }else{
30112 int iLimit = -1;
30113 n2 = strlen30(azArg[1]);
30114 for(i=0; i<ArraySize(aLimit); i++){
30115 if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){
30116 if( iLimit<0 ){
30117 iLimit = i;
30118 }else{
30119 sqlite3_fprintf(stderr,"ambiguous limit: \"%s\"\n", azArg[1]);
30120 rc = 1;
30121 goto meta_command_exit;
30122 }
30123 }
30124 }
30125 if( iLimit<0 ){
30126 sqlite3_fprintf(stderr,"unknown limit: \"%s\"\n"
30127 "enter \".limits\" with no arguments for a list.\n",
30128 azArg[1]);
30129 rc = 1;
30130 goto meta_command_exit;
30131 }
30132 if( nArg==3 ){
30133 sqlite3_limit(p->db, aLimit[iLimit].limitCode,
30134 (int)integerValue(azArg[2]));
30135 }
30136 sqlite3_fprintf(stdout, "%20s %d\n", aLimit[iLimit].zLimitName,
30137 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
30138 }
30139 }else
30140
30141 if( c=='l' && n>2 && cli_strncmp(azArg[0], "lint", n)==0 ){
30142 open_db(p, 0);
30143 lintDotCommand(p, azArg, nArg);
30144 }else
30145
30146#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
30147 if( c=='l' && cli_strncmp(azArg[0], "load", n)==0 ){
30148 const char *zFile, *zProc;
30149 char *zErrMsg = 0;
30150 failIfSafeMode(p, "cannot run .load in safe mode");
30151 if( nArg<2 || azArg[1][0]==0 ){
30152 /* Must have a non-empty FILE. (Will not load self.) */
30153 eputz("Usage: .load FILE ?ENTRYPOINT?\n");
30154 rc = 1;
30155 goto meta_command_exit;
30156 }
30157 zFile = azArg[1];
30158 zProc = nArg>=3 ? azArg[2] : 0;
30159 open_db(p, 0);
30160 rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
30161 if( rc!=SQLITE_OK ){
30162 shellEmitError(zErrMsg);
30163 sqlite3_free(zErrMsg);
30164 rc = 1;
30165 }
30166 }else
30167#endif
30168
30169 if( c=='l' && cli_strncmp(azArg[0], "log", n)==0 ){
30170 if( nArg!=2 ){
30171 eputz("Usage: .log FILENAME\n");
30172 rc = 1;
30173 }else{
30174 const char *zFile = azArg[1];
30175 if( p->bSafeMode
30176 && cli_strcmp(zFile,"on")!=0
30177 && cli_strcmp(zFile,"off")!=0
30178 ){
30179 sputz(stdout, "cannot set .log to anything other"
30180 " than \"on\" or \"off\"\n");
30181 zFile = "off";
30182 }
30184 if( cli_strcmp(zFile,"on")==0 ) zFile = "stdout";
30185 p->pLog = output_file_open(zFile);
30186 }
30187 }else
30188
30189 if( c=='m' && cli_strncmp(azArg[0], "mode", n)==0 ){
30190 const char *zMode = 0;
30191 const char *zTabname = 0;
30192 int i, n2;
30193 int chng = 0; /* 0x01: change to cmopts. 0x02: Any other change */
30195 for(i=1; i<nArg; i++){
30196 const char *z = azArg[i];
30197 if( optionMatch(z,"wrap") && i+1<nArg ){
30198 cmOpts.iWrap = integerValue(azArg[++i]);
30199 chng |= 1;
30200 }else if( optionMatch(z,"ww") ){
30201 cmOpts.bWordWrap = 1;
30202 chng |= 1;
30203 }else if( optionMatch(z,"wordwrap") && i+1<nArg ){
30204 cmOpts.bWordWrap = (u8)booleanValue(azArg[++i]);
30205 chng |= 1;
30206 }else if( optionMatch(z,"quote") ){
30207 cmOpts.bQuote = 1;
30208 chng |= 1;
30209 }else if( optionMatch(z,"noquote") ){
30210 cmOpts.bQuote = 0;
30211 chng |= 1;
30212 }else if( optionMatch(z,"escape") && i+1<nArg ){
30213 /* See similar code at tag-20250224-1 */
30214 const char *zEsc = azArg[++i];
30215 int k;
30216 for(k=0; k<ArraySize(shell_EscModeNames); k++){
30217 if( sqlite3_stricmp(zEsc,shell_EscModeNames[k])==0 ){
30218 p->eEscMode = k;
30219 chng |= 2;
30220 break;
30221 }
30222 }
30223 if( k>=ArraySize(shell_EscModeNames) ){
30224 sqlite3_fprintf(stderr, "unknown control character escape mode \"%s\""
30225 " - choices:", zEsc);
30226 for(k=0; k<ArraySize(shell_EscModeNames); k++){
30227 sqlite3_fprintf(stderr, " %s", shell_EscModeNames[k]);
30228 }
30229 sqlite3_fprintf(stderr, "\n");
30230 rc = 1;
30231 goto meta_command_exit;
30232 }
30233 }else if( zMode==0 ){
30234 zMode = z;
30235 /* Apply defaults for qbox pseudo-mode. If that
30236 * overwrites already-set values, user was informed of this.
30237 */
30238 chng |= 1;
30239 if( cli_strcmp(z, "qbox")==0 ){
30241 zMode = "box";
30242 cmOpts = cmo;
30243 }
30244 }else if( zTabname==0 ){
30245 zTabname = z;
30246 }else if( z[0]=='-' ){
30247 sqlite3_fprintf(stderr,"unknown option: %s\n", z);
30248 eputz("options:\n"
30249 " --escape MODE\n"
30250 " --noquote\n"
30251 " --quote\n"
30252 " --wordwrap on/off\n"
30253 " --wrap N\n"
30254 " --ww\n");
30255 rc = 1;
30256 goto meta_command_exit;
30257 }else{
30258 sqlite3_fprintf(stderr,"extra argument: \"%s\"\n", z);
30259 rc = 1;
30260 goto meta_command_exit;
30261 }
30262 }
30263 if( !chng ){
30264 if( p->mode==MODE_Column
30265 || (p->mode>=MODE_Markdown && p->mode<=MODE_Box)
30266 ){
30268 "current output mode: %s --wrap %d --wordwrap %s "
30269 "--%squote --escape %s\n",
30270 modeDescr[p->mode], p->cmOpts.iWrap,
30271 p->cmOpts.bWordWrap ? "on" : "off",
30272 p->cmOpts.bQuote ? "" : "no",
30274 );
30275 }else{
30277 "current output mode: %s --escape %s\n",
30278 modeDescr[p->mode],
30280 );
30281 }
30282 }
30283 if( zMode==0 ){
30284 zMode = modeDescr[p->mode];
30285 if( (chng&1)==0 ) cmOpts = p->cmOpts;
30286 }
30287 n2 = strlen30(zMode);
30288 if( cli_strncmp(zMode,"lines",n2)==0 ){
30289 p->mode = MODE_Line;
30291 }else if( cli_strncmp(zMode,"columns",n2)==0 ){
30292 p->mode = MODE_Column;
30293 if( (p->shellFlgs & SHFLG_HeaderSet)==0 ){
30294 p->showHeader = 1;
30295 }
30297 p->cmOpts = cmOpts;
30298 }else if( cli_strncmp(zMode,"list",n2)==0 ){
30299 p->mode = MODE_List;
30302 }else if( cli_strncmp(zMode,"html",n2)==0 ){
30303 p->mode = MODE_Html;
30304 }else if( cli_strncmp(zMode,"tcl",n2)==0 ){
30305 p->mode = MODE_Tcl;
30308 }else if( cli_strncmp(zMode,"csv",n2)==0 ){
30309 p->mode = MODE_Csv;
30312 }else if( cli_strncmp(zMode,"tabs",n2)==0 ){
30313 p->mode = MODE_List;
30315 }else if( cli_strncmp(zMode,"insert",n2)==0 ){
30316 p->mode = MODE_Insert;
30317 set_table_name(p, zTabname ? zTabname : "table");
30318 if( p->eEscMode==SHELL_ESC_OFF ){
30320 }else{
30322 }
30323 }else if( cli_strncmp(zMode,"quote",n2)==0 ){
30324 p->mode = MODE_Quote;
30327 }else if( cli_strncmp(zMode,"ascii",n2)==0 ){
30328 p->mode = MODE_Ascii;
30331 }else if( cli_strncmp(zMode,"markdown",n2)==0 ){
30332 p->mode = MODE_Markdown;
30333 p->cmOpts = cmOpts;
30334 }else if( cli_strncmp(zMode,"table",n2)==0 ){
30335 p->mode = MODE_Table;
30336 p->cmOpts = cmOpts;
30337 }else if( cli_strncmp(zMode,"box",n2)==0 ){
30338 p->mode = MODE_Box;
30339 p->cmOpts = cmOpts;
30340 }else if( cli_strncmp(zMode,"count",n2)==0 ){
30341 p->mode = MODE_Count;
30342 }else if( cli_strncmp(zMode,"off",n2)==0 ){
30343 p->mode = MODE_Off;
30344 }else if( cli_strncmp(zMode,"json",n2)==0 ){
30345 p->mode = MODE_Json;
30346 }else{
30347 eputz("Error: mode should be one of: "
30348 "ascii box column csv html insert json line list markdown "
30349 "qbox quote table tabs tcl\n");
30350 rc = 1;
30351 }
30352 p->cMode = p->mode;
30353 }else
30354
30355#ifndef SQLITE_SHELL_FIDDLE
30356 if( c=='n' && cli_strcmp(azArg[0], "nonce")==0 ){
30357 if( nArg!=2 ){
30358 eputz("Usage: .nonce NONCE\n");
30359 rc = 1;
30360 }else if( p->zNonce==0 || cli_strcmp(azArg[1],p->zNonce)!=0 ){
30361 sqlite3_fprintf(stderr,"line %d: incorrect nonce: \"%s\"\n",
30362 p->lineno, azArg[1]);
30363 exit(1);
30364 }else{
30365 p->bSafeMode = 0;
30366 return 0; /* Return immediately to bypass the safe mode reset
30367 ** at the end of this procedure */
30368 }
30369 }else
30370#endif /* !defined(SQLITE_SHELL_FIDDLE) */
30371
30372 if( c=='n' && cli_strncmp(azArg[0], "nullvalue", n)==0 ){
30373 if( nArg==2 ){
30374 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
30375 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
30376 }else{
30377 eputz("Usage: .nullvalue STRING\n");
30378 rc = 1;
30379 }
30380 }else
30381
30382 if( c=='o' && cli_strncmp(azArg[0], "open", n)==0 && n>=2 ){
30383 const char *zFN = 0; /* Pointer to constant filename */
30384 char *zNewFilename = 0; /* Name of the database file to open */
30385 int iName = 1; /* Index in azArg[] of the filename */
30386 int newFlag = 0; /* True to delete file before opening */
30387 int openMode = SHELL_OPEN_UNSPEC;
30388
30389 /* Check for command-line arguments */
30390 for(iName=1; iName<nArg; iName++){
30391 const char *z = azArg[iName];
30392#ifndef SQLITE_SHELL_FIDDLE
30393 if( optionMatch(z,"new") ){
30394 newFlag = 1;
30395#ifdef SQLITE_HAVE_ZLIB
30396 }else if( optionMatch(z, "zip") ){
30397 openMode = SHELL_OPEN_ZIPFILE;
30398#endif
30399 }else if( optionMatch(z, "append") ){
30400 openMode = SHELL_OPEN_APPENDVFS;
30401 }else if( optionMatch(z, "readonly") ){
30402 openMode = SHELL_OPEN_READONLY;
30403 }else if( optionMatch(z, "nofollow") ){
30405#ifndef SQLITE_OMIT_DESERIALIZE
30406 }else if( optionMatch(z, "deserialize") ){
30407 openMode = SHELL_OPEN_DESERIALIZE;
30408 }else if( optionMatch(z, "hexdb") ){
30409 openMode = SHELL_OPEN_HEXDB;
30410 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
30411 p->szMax = integerValue(azArg[++iName]);
30412#endif /* SQLITE_OMIT_DESERIALIZE */
30413 }else
30414#endif /* !SQLITE_SHELL_FIDDLE */
30415 if( z[0]=='-' ){
30416 sqlite3_fprintf(stderr,"unknown option: %s\n", z);
30417 rc = 1;
30418 goto meta_command_exit;
30419 }else if( zFN ){
30420 sqlite3_fprintf(stderr,"extra argument: \"%s\"\n", z);
30421 rc = 1;
30422 goto meta_command_exit;
30423 }else{
30424 zFN = z;
30425 }
30426 }
30427
30428 /* Close the existing database */
30429 session_close_all(p, -1);
30430 close_db(p->db);
30431 p->db = 0;
30432 p->pAuxDb->zDbFilename = 0;
30434 p->pAuxDb->zFreeOnClose = 0;
30435 p->openMode = openMode;
30436 p->openFlags = 0;
30437 p->szMax = 0;
30438
30439 /* If a filename is specified, try to open it first */
30440 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
30441 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
30442#ifndef SQLITE_SHELL_FIDDLE
30443 if( p->bSafeMode
30445 && zFN
30446 && cli_strcmp(zFN,":memory:")!=0
30447 ){
30448 failIfSafeMode(p, "cannot open disk-based database files in safe mode");
30449 }
30450#else
30451 /* WASM mode has its own sandboxed pseudo-filesystem. */
30452#endif
30453 if( zFN ){
30454 zNewFilename = sqlite3_mprintf("%s", zFN);
30455 shell_check_oom(zNewFilename);
30456 }else{
30457 zNewFilename = 0;
30458 }
30459 p->pAuxDb->zDbFilename = zNewFilename;
30461 if( p->db==0 ){
30462 sqlite3_fprintf(stderr,"Error: cannot open '%s'\n", zNewFilename);
30463 sqlite3_free(zNewFilename);
30464 }else{
30465 p->pAuxDb->zFreeOnClose = zNewFilename;
30466 }
30467 }
30468 if( p->db==0 ){
30469 /* As a fall-back open a TEMP database */
30470 p->pAuxDb->zDbFilename = 0;
30471 open_db(p, 0);
30472 }
30473 }else
30474
30475#ifndef SQLITE_SHELL_FIDDLE
30476 if( (c=='o'
30477 && (cli_strncmp(azArg[0], "output", n)==0
30478 || cli_strncmp(azArg[0], "once", n)==0))
30479 || (c=='e' && n==5 && cli_strcmp(azArg[0],"excel")==0)
30480 || (c=='w' && n==3 && cli_strcmp(azArg[0],"www")==0)
30481 ){
30482 char *zFile = 0;
30483 int i;
30484 int eMode = 0; /* 0: .outout/.once, 'x'=.excel, 'w'=.www */
30485 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */
30486 int bPlain = 0; /* --plain option */
30487 static const char *zBomUtf8 = "\357\273\277";
30488 const char *zBom = 0;
30489
30490 failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]);
30491 if( c=='e' ){
30492 eMode = 'x';
30493 bOnce = 2;
30494 }else if( c=='w' ){
30495 eMode = 'w';
30496 bOnce = 2;
30497 }else if( cli_strncmp(azArg[0],"once",n)==0 ){
30498 bOnce = 1;
30499 }
30500 for(i=1; i<nArg; i++){
30501 char *z = azArg[i];
30502 if( z[0]=='-' ){
30503 if( z[1]=='-' ) z++;
30504 if( cli_strcmp(z,"-bom")==0 ){
30505 zBom = zBomUtf8;
30506 }else if( cli_strcmp(z,"-plain")==0 ){
30507 bPlain = 1;
30508 }else if( c=='o' && cli_strcmp(z,"-x")==0 ){
30509 eMode = 'x'; /* spreadsheet */
30510 }else if( c=='o' && cli_strcmp(z,"-e")==0 ){
30511 eMode = 'e'; /* text editor */
30512 }else if( c=='o' && cli_strcmp(z,"-w")==0 ){
30513 eMode = 'w'; /* Web browser */
30514 }else{
30516 "ERROR: unknown option: \"%s\". Usage:\n", azArg[i]);
30517 showHelp(p->out, azArg[0]);
30518 rc = 1;
30519 goto meta_command_exit;
30520 }
30521 }else if( zFile==0 && eMode==0 ){
30522 if( cli_strcmp(z, "off")==0 ){
30523#ifdef _WIN32
30524 zFile = sqlite3_mprintf("nul");
30525#else
30526 zFile = sqlite3_mprintf("/dev/null");
30527#endif
30528 }else{
30529 zFile = sqlite3_mprintf("%s", z);
30530 }
30531 if( zFile && zFile[0]=='|' ){
30532 while( i+1<nArg ) zFile = sqlite3_mprintf("%z %s", zFile, azArg[++i]);
30533 break;
30534 }
30535 }else{
30537 "ERROR: extra parameter: \"%s\". Usage:\n", azArg[i]);
30538 showHelp(p->out, azArg[0]);
30539 rc = 1;
30540 sqlite3_free(zFile);
30541 goto meta_command_exit;
30542 }
30543 }
30544 if( zFile==0 ){
30545 zFile = sqlite3_mprintf("stdout");
30546 }
30547 shell_check_oom(zFile);
30548 if( bOnce ){
30549 p->outCount = 2;
30550 }else{
30551 p->outCount = 0;
30552 }
30553 output_reset(p);
30554#ifndef SQLITE_NOHAVE_SYSTEM
30555 if( eMode=='e' || eMode=='x' || eMode=='w' ){
30556 p->doXdgOpen = 1;
30557 outputModePush(p);
30558 if( eMode=='x' ){
30559 /* spreadsheet mode. Output as CSV. */
30560 newTempFile(p, "csv");
30562 p->mode = MODE_Csv;
30565#ifdef _WIN32
30566 zBom = zBomUtf8; /* Always include the BOM on Windows, as Excel does
30567 ** not work without it. */
30568#endif
30569 }else if( eMode=='w' ){
30570 /* web-browser mode. */
30571 newTempFile(p, "html");
30572 if( !bPlain ) p->mode = MODE_Www;
30573 }else{
30574 /* text editor mode */
30575 newTempFile(p, "txt");
30576 }
30577 sqlite3_free(zFile);
30578 zFile = sqlite3_mprintf("%s", p->zTempFile);
30579 }
30580#endif /* SQLITE_NOHAVE_SYSTEM */
30581 shell_check_oom(zFile);
30582 if( zFile[0]=='|' ){
30583#ifdef SQLITE_OMIT_POPEN
30584 eputz("Error: pipes are not supported in this OS\n");
30585 rc = 1;
30586 output_redir(p, stdout);
30587#else
30588 FILE *pfPipe = sqlite3_popen(zFile + 1, "w");
30589 if( pfPipe==0 ){
30590 assert( stderr!=NULL );
30591 sqlite3_fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
30592 rc = 1;
30593 }else{
30594 output_redir(p, pfPipe);
30595 if( zBom ) sqlite3_fputs(zBom, pfPipe);
30596 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
30597 }
30598#endif
30599 }else{
30600 FILE *pfFile = output_file_open(zFile);
30601 if( pfFile==0 ){
30602 if( cli_strcmp(zFile,"off")!=0 ){
30603 assert( stderr!=NULL );
30604 sqlite3_fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
30605 }
30606 rc = 1;
30607 } else {
30608 output_redir(p, pfFile);
30609 if( zBom ) sqlite3_fputs(zBom, pfFile);
30610 if( bPlain && eMode=='w' ){
30612 "<!DOCTYPE html>\n<BODY>\n<PLAINTEXT>\n",
30613 pfFile
30614 );
30615 }
30616 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
30617 }
30618 }
30619 sqlite3_free(zFile);
30620 }else
30621#endif /* !defined(SQLITE_SHELL_FIDDLE) */
30622
30623 if( c=='p' && n>=3 && cli_strncmp(azArg[0], "parameter", n)==0 ){
30624 open_db(p,0);
30625 if( nArg<=1 ) goto parameter_syntax_error;
30626
30627 /* .parameter clear
30628 ** Clear all bind parameters by dropping the TEMP table that holds them.
30629 */
30630 if( nArg==2 && cli_strcmp(azArg[1],"clear")==0 ){
30631 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.sqlite_parameters;",
30632 0, 0, 0);
30633 }else
30634
30635 /* .parameter list
30636 ** List all bind parameters.
30637 */
30638 if( nArg==2 && cli_strcmp(azArg[1],"list")==0 ){
30639 sqlite3_stmt *pStmt = 0;
30640 int rx;
30641 int len = 0;
30642 rx = sqlite3_prepare_v2(p->db,
30643 "SELECT max(length(key)) "
30644 "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
30645 if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
30646 len = sqlite3_column_int(pStmt, 0);
30647 if( len>40 ) len = 40;
30648 }
30649 sqlite3_finalize(pStmt);
30650 pStmt = 0;
30651 if( len ){
30652 rx = sqlite3_prepare_v2(p->db,
30653 "SELECT key, quote(value) "
30654 "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
30655 while( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
30657 "%-*s %s\n", len, sqlite3_column_text(pStmt,0),
30658 sqlite3_column_text(pStmt,1));
30659 }
30660 sqlite3_finalize(pStmt);
30661 }
30662 }else
30663
30664 /* .parameter init
30665 ** Make sure the TEMP table used to hold bind parameters exists.
30666 ** Create it if necessary.
30667 */
30668 if( nArg==2 && cli_strcmp(azArg[1],"init")==0 ){
30669 bind_table_init(p);
30670 }else
30671
30672 /* .parameter set NAME VALUE
30673 ** Set or reset a bind parameter. NAME should be the full parameter
30674 ** name exactly as it appears in the query. (ex: $abc, @def). The
30675 ** VALUE can be in either SQL literal notation, or if not it will be
30676 ** understood to be a text string.
30677 */
30678 if( nArg==4 && cli_strcmp(azArg[1],"set")==0 ){
30679 int rx;
30680 char *zSql;
30681 sqlite3_stmt *pStmt;
30682 const char *zKey = azArg[2];
30683 const char *zValue = azArg[3];
30684 bind_table_init(p);
30685 zSql = sqlite3_mprintf(
30686 "REPLACE INTO temp.sqlite_parameters(key,value)"
30687 "VALUES(%Q,%s);", zKey, zValue);
30688 shell_check_oom(zSql);
30689 pStmt = 0;
30690 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
30691 sqlite3_free(zSql);
30692 if( rx!=SQLITE_OK ){
30693 sqlite3_finalize(pStmt);
30694 pStmt = 0;
30695 zSql = sqlite3_mprintf(
30696 "REPLACE INTO temp.sqlite_parameters(key,value)"
30697 "VALUES(%Q,%Q);", zKey, zValue);
30698 shell_check_oom(zSql);
30699 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
30700 sqlite3_free(zSql);
30701 if( rx!=SQLITE_OK ){
30702 sqlite3_fprintf(p->out, "Error: %s\n", sqlite3_errmsg(p->db));
30703 sqlite3_finalize(pStmt);
30704 pStmt = 0;
30705 rc = 1;
30706 }
30707 }
30708 bind_prepared_stmt(p, pStmt);
30709 sqlite3_step(pStmt);
30710 sqlite3_finalize(pStmt);
30711 }else
30712
30713 /* .parameter unset NAME
30714 ** Remove the NAME binding from the parameter binding table, if it
30715 ** exists.
30716 */
30717 if( nArg==3 && cli_strcmp(azArg[1],"unset")==0 ){
30718 char *zSql = sqlite3_mprintf(
30719 "DELETE FROM temp.sqlite_parameters WHERE key=%Q", azArg[2]);
30720 shell_check_oom(zSql);
30721 sqlite3_exec(p->db, zSql, 0, 0, 0);
30722 sqlite3_free(zSql);
30723 }else
30724 /* If no command name matches, show a syntax error */
30725 parameter_syntax_error:
30726 showHelp(p->out, "parameter");
30727 }else
30728
30729 if( c=='p' && n>=3 && cli_strncmp(azArg[0], "print", n)==0 ){
30730 int i;
30731 for(i=1; i<nArg; i++){
30732 if( i>1 ) sqlite3_fputs(" ", p->out);
30733 sqlite3_fputs(azArg[i], p->out);
30734 }
30735 sqlite3_fputs("\n", p->out);
30736 }else
30737
30738#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
30739 if( c=='p' && n>=3 && cli_strncmp(azArg[0], "progress", n)==0 ){
30740 int i;
30741 int nn = 0;
30742 p->flgProgress = 0;
30743 p->mxProgress = 0;
30744 p->nProgress = 0;
30745 for(i=1; i<nArg; i++){
30746 const char *z = azArg[i];
30747 if( z[0]=='-' ){
30748 z++;
30749 if( z[0]=='-' ) z++;
30750 if( cli_strcmp(z,"quiet")==0 || cli_strcmp(z,"q")==0 ){
30752 continue;
30753 }
30754 if( cli_strcmp(z,"reset")==0 ){
30756 continue;
30757 }
30758 if( cli_strcmp(z,"once")==0 ){
30760 continue;
30761 }
30762 if( cli_strcmp(z,"limit")==0 ){
30763 if( i+1>=nArg ){
30764 eputz("Error: missing argument on --limit\n");
30765 rc = 1;
30766 goto meta_command_exit;
30767 }else{
30768 p->mxProgress = (int)integerValue(azArg[++i]);
30769 }
30770 continue;
30771 }
30772 sqlite3_fprintf(stderr,"Error: unknown option: \"%s\"\n", azArg[i]);
30773 rc = 1;
30774 goto meta_command_exit;
30775 }else{
30776 nn = (int)integerValue(z);
30777 }
30778 }
30779 open_db(p, 0);
30781 }else
30782#endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
30783
30784 if( c=='p' && cli_strncmp(azArg[0], "prompt", n)==0 ){
30785 if( nArg >= 2) {
30786 shell_strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
30787 }
30788 if( nArg >= 3) {
30790 }
30791 }else
30792
30793#ifndef SQLITE_SHELL_FIDDLE
30794 if( c=='q' && cli_strncmp(azArg[0], "quit", n)==0 ){
30795 rc = 2;
30796 }else
30797#endif
30798
30799#ifndef SQLITE_SHELL_FIDDLE
30800 if( c=='r' && n>=3 && cli_strncmp(azArg[0], "read", n)==0 ){
30801 FILE *inSaved = p->in;
30802 int savedLineno = p->lineno;
30803 failIfSafeMode(p, "cannot run .read in safe mode");
30804 if( nArg!=2 ){
30805 eputz("Usage: .read FILE\n");
30806 rc = 1;
30807 goto meta_command_exit;
30808 }
30809 if( azArg[1][0]=='|' ){
30810#ifdef SQLITE_OMIT_POPEN
30811 eputz("Error: pipes are not supported in this OS\n");
30812 rc = 1;
30813#else
30814 p->in = sqlite3_popen(azArg[1]+1, "r");
30815 if( p->in==0 ){
30816 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
30817 rc = 1;
30818 }else{
30819 rc = process_input(p);
30820 pclose(p->in);
30821 }
30822#endif
30823 }else if( (p->in = openChrSource(azArg[1]))==0 ){
30824 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
30825 rc = 1;
30826 }else{
30827 rc = process_input(p);
30828 fclose(p->in);
30829 }
30830 p->in = inSaved;
30831 p->lineno = savedLineno;
30832 }else
30833#endif /* !defined(SQLITE_SHELL_FIDDLE) */
30834
30835#ifndef SQLITE_SHELL_FIDDLE
30836 if( c=='r' && n>=3 && cli_strncmp(azArg[0], "restore", n)==0 ){
30837 const char *zSrcFile;
30838 const char *zDb;
30839 sqlite3 *pSrc;
30840 sqlite3_backup *pBackup;
30841 int nTimeout = 0;
30842
30843 failIfSafeMode(p, "cannot run .restore in safe mode");
30844 if( nArg==2 ){
30845 zSrcFile = azArg[1];
30846 zDb = "main";
30847 }else if( nArg==3 ){
30848 zSrcFile = azArg[2];
30849 zDb = azArg[1];
30850 }else{
30851 eputz("Usage: .restore ?DB? FILE\n");
30852 rc = 1;
30853 goto meta_command_exit;
30854 }
30855 rc = sqlite3_open(zSrcFile, &pSrc);
30856 if( rc!=SQLITE_OK ){
30857 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zSrcFile);
30858 close_db(pSrc);
30859 return 1;
30860 }
30861 open_db(p, 0);
30862 pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
30863 if( pBackup==0 ){
30865 close_db(pSrc);
30866 return 1;
30867 }
30868 while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK
30869 || rc==SQLITE_BUSY ){
30870 if( rc==SQLITE_BUSY ){
30871 if( nTimeout++ >= 3 ) break;
30872 sqlite3_sleep(100);
30873 }
30874 }
30875 sqlite3_backup_finish(pBackup);
30876 if( rc==SQLITE_DONE ){
30877 rc = 0;
30878 }else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){
30879 eputz("Error: source database is busy\n");
30880 rc = 1;
30881 }else{
30883 rc = 1;
30884 }
30885 close_db(pSrc);
30886 }else
30887#endif /* !defined(SQLITE_SHELL_FIDDLE) */
30888
30889 if( c=='s' &&
30890 (cli_strncmp(azArg[0], "scanstats", n)==0 ||
30891 cli_strncmp(azArg[0], "scanstatus", n)==0)
30892 ){
30893 if( nArg==2 ){
30894 if( cli_strcmp(azArg[1], "vm")==0 ){
30895 p->scanstatsOn = 3;
30896 }else
30897 if( cli_strcmp(azArg[1], "est")==0 ){
30898 p->scanstatsOn = 2;
30899 }else{
30900 p->scanstatsOn = (u8)booleanValue(azArg[1]);
30901 }
30902 open_db(p, 0);
30905 );
30906#if !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
30907 eputz("Warning: .scanstats not available in this build.\n");
30908#elif !defined(SQLITE_ENABLE_BYTECODE_VTAB)
30909 if( p->scanstatsOn==3 ){
30910 eputz("Warning: \".scanstats vm\" not available in this build.\n");
30911 }
30912#endif
30913 }else{
30914 eputz("Usage: .scanstats on|off|est\n");
30915 rc = 1;
30916 }
30917 }else
30918
30919 if( c=='s' && cli_strncmp(azArg[0], "schema", n)==0 ){
30920 ShellText sSelect;
30921 ShellState data;
30922 char *zErrMsg = 0;
30923 const char *zDiv = "(";
30924 const char *zName = 0;
30925 int iSchema = 0;
30926 int bDebug = 0;
30927 int bNoSystemTabs = 0;
30928 int ii;
30929
30930 open_db(p, 0);
30931 memcpy(&data, p, sizeof(data));
30932 data.showHeader = 0;
30933 data.cMode = data.mode = MODE_Semi;
30934 initText(&sSelect);
30935 for(ii=1; ii<nArg; ii++){
30936 if( optionMatch(azArg[ii],"indent") ){
30937 data.cMode = data.mode = MODE_Pretty;
30938 }else if( optionMatch(azArg[ii],"debug") ){
30939 bDebug = 1;
30940 }else if( optionMatch(azArg[ii],"nosys") ){
30941 bNoSystemTabs = 1;
30942 }else if( azArg[ii][0]=='-' ){
30943 sqlite3_fprintf(stderr,"Unknown option: \"%s\"\n", azArg[ii]);
30944 rc = 1;
30945 goto meta_command_exit;
30946 }else if( zName==0 ){
30947 zName = azArg[ii];
30948 }else{
30949 eputz("Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?\n");
30950 rc = 1;
30951 goto meta_command_exit;
30952 }
30953 }
30954 if( zName!=0 ){
30955 int isSchema = sqlite3_strlike(zName, "sqlite_master", '\\')==0
30956 || sqlite3_strlike(zName, "sqlite_schema", '\\')==0
30957 || sqlite3_strlike(zName,"sqlite_temp_master", '\\')==0
30958 || sqlite3_strlike(zName,"sqlite_temp_schema", '\\')==0;
30959 if( isSchema ){
30960 char *new_argv[2], *new_colv[2];
30961 new_argv[0] = sqlite3_mprintf(
30962 "CREATE TABLE %s (\n"
30963 " type text,\n"
30964 " name text,\n"
30965 " tbl_name text,\n"
30966 " rootpage integer,\n"
30967 " sql text\n"
30968 ")", zName);
30969 shell_check_oom(new_argv[0]);
30970 new_argv[1] = 0;
30971 new_colv[0] = "sql";
30972 new_colv[1] = 0;
30973 callback(&data, 1, new_argv, new_colv);
30974 sqlite3_free(new_argv[0]);
30975 }
30976 }
30977 if( zDiv ){
30978 sqlite3_stmt *pStmt = 0;
30979 rc = sqlite3_prepare_v2(p->db, "SELECT name FROM pragma_database_list",
30980 -1, &pStmt, 0);
30981 if( rc ){
30983 sqlite3_finalize(pStmt);
30984 rc = 1;
30985 goto meta_command_exit;
30986 }
30987 appendText(&sSelect, "SELECT sql FROM", 0);
30988 iSchema = 0;
30989 while( sqlite3_step(pStmt)==SQLITE_ROW ){
30990 const char *zDb = (const char*)sqlite3_column_text(pStmt, 0);
30991 char zScNum[30];
30992 sqlite3_snprintf(sizeof(zScNum), zScNum, "%d", ++iSchema);
30993 appendText(&sSelect, zDiv, 0);
30994 zDiv = " UNION ALL ";
30995 appendText(&sSelect, "SELECT shell_add_schema(sql,", 0);
30996 if( sqlite3_stricmp(zDb, "main")!=0 ){
30997 appendText(&sSelect, zDb, '\'');
30998 }else{
30999 appendText(&sSelect, "NULL", 0);
31000 }
31001 appendText(&sSelect, ",name) AS sql, type, tbl_name, name, rowid,", 0);
31002 appendText(&sSelect, zScNum, 0);
31003 appendText(&sSelect, " AS snum, ", 0);
31004 appendText(&sSelect, zDb, '\'');
31005 appendText(&sSelect, " AS sname FROM ", 0);
31006 appendText(&sSelect, zDb, quoteChar(zDb));
31007 appendText(&sSelect, ".sqlite_schema", 0);
31008 }
31009 sqlite3_finalize(pStmt);
31010#ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
31011 if( zName ){
31012 appendText(&sSelect,
31013 " UNION ALL SELECT shell_module_schema(name),"
31014 " 'table', name, name, name, 9e+99, 'main' FROM pragma_module_list",
31015 0);
31016 }
31017#endif
31018 appendText(&sSelect, ") WHERE ", 0);
31019 if( zName ){
31020 char *zQarg = sqlite3_mprintf("%Q", zName);
31021 int bGlob;
31022 shell_check_oom(zQarg);
31023 bGlob = strchr(zName, '*') != 0 || strchr(zName, '?') != 0 ||
31024 strchr(zName, '[') != 0;
31025 if( strchr(zName, '.') ){
31026 appendText(&sSelect, "lower(printf('%s.%s',sname,tbl_name))", 0);
31027 }else{
31028 appendText(&sSelect, "lower(tbl_name)", 0);
31029 }
31030 appendText(&sSelect, bGlob ? " GLOB " : " LIKE ", 0);
31031 appendText(&sSelect, zQarg, 0);
31032 if( !bGlob ){
31033 appendText(&sSelect, " ESCAPE '\\' ", 0);
31034 }
31035 appendText(&sSelect, " AND ", 0);
31036 sqlite3_free(zQarg);
31037 }
31038 if( bNoSystemTabs ){
31039 appendText(&sSelect, "name NOT LIKE 'sqlite_%%' AND ", 0);
31040 }
31041 appendText(&sSelect, "sql IS NOT NULL"
31042 " ORDER BY snum, rowid", 0);
31043 if( bDebug ){
31044 sqlite3_fprintf(p->out, "SQL: %s;\n", sSelect.z);
31045 }else{
31046 rc = sqlite3_exec(p->db, sSelect.z, callback, &data, &zErrMsg);
31047 }
31048 freeText(&sSelect);
31049 }
31050 if( zErrMsg ){
31051 shellEmitError(zErrMsg);
31052 sqlite3_free(zErrMsg);
31053 rc = 1;
31054 }else if( rc != SQLITE_OK ){
31055 eputz("Error: querying schema information\n");
31056 rc = 1;
31057 }else{
31058 rc = 0;
31059 }
31060 }else
31061
31062 if( (c=='s' && n==11 && cli_strncmp(azArg[0], "selecttrace", n)==0)
31063 || (c=='t' && n==9 && cli_strncmp(azArg[0], "treetrace", n)==0)
31064 ){
31065 unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
31067 }else
31068
31069#if defined(SQLITE_ENABLE_SESSION)
31070 if( c=='s' && cli_strncmp(azArg[0],"session",n)==0 && n>=3 ){
31071 struct AuxDb *pAuxDb = p->pAuxDb;
31072 OpenSession *pSession = &pAuxDb->aSession[0];
31073 char **azCmd = &azArg[1];
31074 int iSes = 0;
31075 int nCmd = nArg - 1;
31076 int i;
31077 if( nArg<=1 ) goto session_syntax_error;
31078 open_db(p, 0);
31079 if( nArg>=3 ){
31080 for(iSes=0; iSes<pAuxDb->nSession; iSes++){
31081 if( cli_strcmp(pAuxDb->aSession[iSes].zName, azArg[1])==0 ) break;
31082 }
31083 if( iSes<pAuxDb->nSession ){
31084 pSession = &pAuxDb->aSession[iSes];
31085 azCmd++;
31086 nCmd--;
31087 }else{
31088 pSession = &pAuxDb->aSession[0];
31089 iSes = 0;
31090 }
31091 }
31092
31093 /* .session attach TABLE
31094 ** Invoke the sqlite3session_attach() interface to attach a particular
31095 ** table so that it is never filtered.
31096 */
31097 if( cli_strcmp(azCmd[0],"attach")==0 ){
31098 if( nCmd!=2 ) goto session_syntax_error;
31099 if( pSession->p==0 ){
31100 session_not_open:
31101 eputz("ERROR: No sessions are open\n");
31102 }else{
31103 rc = sqlite3session_attach(pSession->p, azCmd[1]);
31104 if( rc ){
31105 sqlite3_fprintf(stderr,
31106 "ERROR: sqlite3session_attach() returns %d\n",rc);
31107 rc = 0;
31108 }
31109 }
31110 }else
31111
31112 /* .session changeset FILE
31113 ** .session patchset FILE
31114 ** Write a changeset or patchset into a file. The file is overwritten.
31115 */
31116 if( cli_strcmp(azCmd[0],"changeset")==0
31117 || cli_strcmp(azCmd[0],"patchset")==0
31118 ){
31119 FILE *out = 0;
31120 failIfSafeMode(p, "cannot run \".session %s\" in safe mode", azCmd[0]);
31121 if( nCmd!=2 ) goto session_syntax_error;
31122 if( pSession->p==0 ) goto session_not_open;
31123 out = sqlite3_fopen(azCmd[1], "wb");
31124 if( out==0 ){
31125 sqlite3_fprintf(stderr,"ERROR: cannot open \"%s\" for writing\n",
31126 azCmd[1]);
31127 }else{
31128 int szChng;
31129 void *pChng;
31130 if( azCmd[0][0]=='c' ){
31131 rc = sqlite3session_changeset(pSession->p, &szChng, &pChng);
31132 }else{
31133 rc = sqlite3session_patchset(pSession->p, &szChng, &pChng);
31134 }
31135 if( rc ){
31136 sqlite3_fprintf(stdout, "Error: error code %d\n", rc);
31137 rc = 0;
31138 }
31139 if( pChng
31140 && fwrite(pChng, szChng, 1, out)!=1 ){
31141 sqlite3_fprintf(stderr,
31142 "ERROR: Failed to write entire %d-byte output\n", szChng);
31143 }
31144 sqlite3_free(pChng);
31145 fclose(out);
31146 }
31147 }else
31148
31149 /* .session close
31150 ** Close the identified session
31151 */
31152 if( cli_strcmp(azCmd[0], "close")==0 ){
31153 if( nCmd!=1 ) goto session_syntax_error;
31154 if( pAuxDb->nSession ){
31155 session_close(pSession);
31156 pAuxDb->aSession[iSes] = pAuxDb->aSession[--pAuxDb->nSession];
31157 }
31158 }else
31159
31160 /* .session enable ?BOOLEAN?
31161 ** Query or set the enable flag
31162 */
31163 if( cli_strcmp(azCmd[0], "enable")==0 ){
31164 int ii;
31165 if( nCmd>2 ) goto session_syntax_error;
31166 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
31167 if( pAuxDb->nSession ){
31168 ii = sqlite3session_enable(pSession->p, ii);
31170 "session %s enable flag = %d\n", pSession->zName, ii);
31171 }
31172 }else
31173
31174 /* .session filter GLOB ....
31175 ** Set a list of GLOB patterns of table names to be excluded.
31176 */
31177 if( cli_strcmp(azCmd[0], "filter")==0 ){
31178 int ii, nByte;
31179 if( nCmd<2 ) goto session_syntax_error;
31180 if( pAuxDb->nSession ){
31181 for(ii=0; ii<pSession->nFilter; ii++){
31182 sqlite3_free(pSession->azFilter[ii]);
31183 }
31184 sqlite3_free(pSession->azFilter);
31185 nByte = sizeof(pSession->azFilter[0])*(nCmd-1);
31186 pSession->azFilter = sqlite3_malloc( nByte );
31187 shell_check_oom( pSession->azFilter );
31188 for(ii=1; ii<nCmd; ii++){
31189 char *x = pSession->azFilter[ii-1] = sqlite3_mprintf("%s", azCmd[ii]);
31190 shell_check_oom(x);
31191 }
31192 pSession->nFilter = ii-1;
31193 }
31194 }else
31195
31196 /* .session indirect ?BOOLEAN?
31197 ** Query or set the indirect flag
31198 */
31199 if( cli_strcmp(azCmd[0], "indirect")==0 ){
31200 int ii;
31201 if( nCmd>2 ) goto session_syntax_error;
31202 ii = nCmd==1 ? -1 : booleanValue(azCmd[1]);
31203 if( pAuxDb->nSession ){
31204 ii = sqlite3session_indirect(pSession->p, ii);
31206 "session %s indirect flag = %d\n", pSession->zName, ii);
31207 }
31208 }else
31209
31210 /* .session isempty
31211 ** Determine if the session is empty
31212 */
31213 if( cli_strcmp(azCmd[0], "isempty")==0 ){
31214 int ii;
31215 if( nCmd!=1 ) goto session_syntax_error;
31216 if( pAuxDb->nSession ){
31217 ii = sqlite3session_isempty(pSession->p);
31219 "session %s isempty flag = %d\n", pSession->zName, ii);
31220 }
31221 }else
31222
31223 /* .session list
31224 ** List all currently open sessions
31225 */
31226 if( cli_strcmp(azCmd[0],"list")==0 ){
31227 for(i=0; i<pAuxDb->nSession; i++){
31228 sqlite3_fprintf(p->out, "%d %s\n", i, pAuxDb->aSession[i].zName);
31229 }
31230 }else
31231
31232 /* .session open DB NAME
31233 ** Open a new session called NAME on the attached database DB.
31234 ** DB is normally "main".
31235 */
31236 if( cli_strcmp(azCmd[0],"open")==0 ){
31237 char *zName;
31238 if( nCmd!=3 ) goto session_syntax_error;
31239 zName = azCmd[2];
31240 if( zName[0]==0 ) goto session_syntax_error;
31241 for(i=0; i<pAuxDb->nSession; i++){
31242 if( cli_strcmp(pAuxDb->aSession[i].zName,zName)==0 ){
31243 sqlite3_fprintf(stderr,"Session \"%s\" already exists\n", zName);
31244 goto meta_command_exit;
31245 }
31246 }
31247 if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){
31248 sqlite3_fprintf(stderr,
31249 "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession));
31250 goto meta_command_exit;
31251 }
31252 pSession = &pAuxDb->aSession[pAuxDb->nSession];
31253 rc = sqlite3session_create(p->db, azCmd[1], &pSession->p);
31254 if( rc ){
31255 sqlite3_fprintf(stderr,"Cannot open session: error code=%d\n", rc);
31256 rc = 0;
31257 goto meta_command_exit;
31258 }
31259 pSession->nFilter = 0;
31260 sqlite3session_table_filter(pSession->p, session_filter, pSession);
31261 pAuxDb->nSession++;
31262 pSession->zName = sqlite3_mprintf("%s", zName);
31263 shell_check_oom(pSession->zName);
31264 }else
31265 /* If no command name matches, show a syntax error */
31266 session_syntax_error:
31267 showHelp(p->out, "session");
31268 }else
31269#endif
31270
31271#ifdef SQLITE_DEBUG
31272 /* Undocumented commands for internal testing. Subject to change
31273 ** without notice. */
31274 if( c=='s' && n>=10 && cli_strncmp(azArg[0], "selftest-", 9)==0 ){
31275 if( cli_strncmp(azArg[0]+9, "boolean", n-9)==0 ){
31276 int i, v;
31277 for(i=1; i<nArg; i++){
31278 v = booleanValue(azArg[i]);
31279 sqlite3_fprintf(p->out, "%s: %d 0x%x\n", azArg[i], v, v);
31280 }
31281 }
31282 if( cli_strncmp(azArg[0]+9, "integer", n-9)==0 ){
31283 int i; sqlite3_int64 v;
31284 for(i=1; i<nArg; i++){
31285 char zBuf[200];
31286 v = integerValue(azArg[i]);
31287 sqlite3_snprintf(sizeof(zBuf),zBuf,"%s: %lld 0x%llx\n", azArg[i],v,v);
31288 sqlite3_fputs(zBuf, p->out);
31289 }
31290 }
31291 }else
31292#endif
31293
31294 if( c=='s' && n>=4 && cli_strncmp(azArg[0],"selftest",n)==0 ){
31295 int bIsInit = 0; /* True to initialize the SELFTEST table */
31296 int bVerbose = 0; /* Verbose output */
31297 int bSelftestExists; /* True if SELFTEST already exists */
31298 int i, k; /* Loop counters */
31299 int nTest = 0; /* Number of tests runs */
31300 int nErr = 0; /* Number of errors seen */
31301 ShellText str; /* Answer for a query */
31302 sqlite3_stmt *pStmt = 0; /* Query against the SELFTEST table */
31303
31304 open_db(p,0);
31305 for(i=1; i<nArg; i++){
31306 const char *z = azArg[i];
31307 if( z[0]=='-' && z[1]=='-' ) z++;
31308 if( cli_strcmp(z,"-init")==0 ){
31309 bIsInit = 1;
31310 }else
31311 if( cli_strcmp(z,"-v")==0 ){
31312 bVerbose++;
31313 }else
31314 {
31315 sqlite3_fprintf(stderr,
31316 "Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]);
31317 sqlite3_fputs("Should be one of: --init -v\n", stderr);
31318 rc = 1;
31319 goto meta_command_exit;
31320 }
31321 }
31322 if( sqlite3_table_column_metadata(p->db,"main","selftest",0,0,0,0,0,0)
31323 != SQLITE_OK ){
31324 bSelftestExists = 0;
31325 }else{
31326 bSelftestExists = 1;
31327 }
31328 if( bIsInit ){
31330 bSelftestExists = 1;
31331 }
31332 initText(&str);
31333 appendText(&str, "x", 0);
31334 for(k=bSelftestExists; k>=0; k--){
31335 if( k==1 ){
31336 rc = sqlite3_prepare_v2(p->db,
31337 "SELECT tno,op,cmd,ans FROM selftest ORDER BY tno",
31338 -1, &pStmt, 0);
31339 }else{
31340 rc = sqlite3_prepare_v2(p->db,
31341 "VALUES(0,'memo','Missing SELFTEST table - default checks only',''),"
31342 " (1,'run','PRAGMA integrity_check','ok')",
31343 -1, &pStmt, 0);
31344 }
31345 if( rc ){
31346 eputz("Error querying the selftest table\n");
31347 rc = 1;
31348 sqlite3_finalize(pStmt);
31349 goto meta_command_exit;
31350 }
31351 for(i=1; sqlite3_step(pStmt)==SQLITE_ROW; i++){
31352 int tno = sqlite3_column_int(pStmt, 0);
31353 const char *zOp = (const char*)sqlite3_column_text(pStmt, 1);
31354 const char *zSql = (const char*)sqlite3_column_text(pStmt, 2);
31355 const char *zAns = (const char*)sqlite3_column_text(pStmt, 3);
31356
31357 if( zOp==0 ) continue;
31358 if( zSql==0 ) continue;
31359 if( zAns==0 ) continue;
31360 k = 0;
31361 if( bVerbose>0 ){
31362 sqlite3_fprintf(stdout, "%d: %s %s\n", tno, zOp, zSql);
31363 }
31364 if( cli_strcmp(zOp,"memo")==0 ){
31365 sqlite3_fprintf(p->out, "%s\n", zSql);
31366 }else
31367 if( cli_strcmp(zOp,"run")==0 ){
31368 char *zErrMsg = 0;
31369 str.n = 0;
31370 str.z[0] = 0;
31371 rc = sqlite3_exec(p->db, zSql, captureOutputCallback, &str, &zErrMsg);
31372 nTest++;
31373 if( bVerbose ){
31374 sqlite3_fprintf(p->out, "Result: %s\n", str.z);
31375 }
31376 if( rc || zErrMsg ){
31377 nErr++;
31378 rc = 1;
31379 sqlite3_fprintf(p->out, "%d: error-code-%d: %s\n", tno, rc,zErrMsg);
31380 sqlite3_free(zErrMsg);
31381 }else if( cli_strcmp(zAns,str.z)!=0 ){
31382 nErr++;
31383 rc = 1;
31384 sqlite3_fprintf(p->out, "%d: Expected: [%s]\n", tno, zAns);
31385 sqlite3_fprintf(p->out, "%d: Got: [%s]\n", tno, str.z);
31386 }
31387 }
31388 else{
31389 sqlite3_fprintf(stderr,
31390 "Unknown operation \"%s\" on selftest line %d\n", zOp, tno);
31391 rc = 1;
31392 break;
31393 }
31394 } /* End loop over rows of content from SELFTEST */
31395 sqlite3_finalize(pStmt);
31396 } /* End loop over k */
31397 freeText(&str);
31398 sqlite3_fprintf(p->out, "%d errors out of %d tests\n", nErr, nTest);
31399 }else
31400
31401 if( c=='s' && cli_strncmp(azArg[0], "separator", n)==0 ){
31402 if( nArg<2 || nArg>3 ){
31403 eputz("Usage: .separator COL ?ROW?\n");
31404 rc = 1;
31405 }
31406 if( nArg>=2 ){
31408 "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]);
31409 }
31410 if( nArg>=3 ){
31412 "%.*s", (int)ArraySize(p->rowSeparator)-1, azArg[2]);
31413 }
31414 }else
31415
31416 if( c=='s' && n>=4 && cli_strncmp(azArg[0],"sha3sum",n)==0 ){
31417 const char *zLike = 0; /* Which table to checksum. 0 means everything */
31418 int i; /* Loop counter */
31419 int bSchema = 0; /* Also hash the schema */
31420 int bSeparate = 0; /* Hash each table separately */
31421 int iSize = 224; /* Hash algorithm to use */
31422 int bDebug = 0; /* Only show the query that would have run */
31423 sqlite3_stmt *pStmt; /* For querying tables names */
31424 char *zSql; /* SQL to be run */
31425 char *zSep; /* Separator */
31426 ShellText sSql; /* Complete SQL for the query to run the hash */
31427 ShellText sQuery; /* Set of queries used to read all content */
31428 open_db(p, 0);
31429 for(i=1; i<nArg; i++){
31430 const char *z = azArg[i];
31431 if( z[0]=='-' ){
31432 z++;
31433 if( z[0]=='-' ) z++;
31434 if( cli_strcmp(z,"schema")==0 ){
31435 bSchema = 1;
31436 }else
31437 if( cli_strcmp(z,"sha3-224")==0 || cli_strcmp(z,"sha3-256")==0
31438 || cli_strcmp(z,"sha3-384")==0 || cli_strcmp(z,"sha3-512")==0
31439 ){
31440 iSize = atoi(&z[5]);
31441 }else
31442 if( cli_strcmp(z,"debug")==0 ){
31443 bDebug = 1;
31444 }else
31445 {
31446 sqlite3_fprintf(stderr,
31447 "Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]);
31448 showHelp(p->out, azArg[0]);
31449 rc = 1;
31450 goto meta_command_exit;
31451 }
31452 }else if( zLike ){
31453 eputz("Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n");
31454 rc = 1;
31455 goto meta_command_exit;
31456 }else{
31457 zLike = z;
31458 bSeparate = 1;
31459 if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1;
31460 }
31461 }
31462 if( bSchema ){
31463 zSql = "SELECT lower(name) as tname FROM sqlite_schema"
31464 " WHERE type='table' AND coalesce(rootpage,0)>1"
31465 " UNION ALL SELECT 'sqlite_schema'"
31466 " ORDER BY 1 collate nocase";
31467 }else{
31468 zSql = "SELECT lower(name) as tname FROM sqlite_schema"
31469 " WHERE type='table' AND coalesce(rootpage,0)>1"
31470 " AND name NOT LIKE 'sqlite_%'"
31471 " ORDER BY 1 collate nocase";
31472 }
31473 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
31474 initText(&sQuery);
31475 initText(&sSql);
31476 appendText(&sSql, "WITH [sha3sum$query](a,b) AS(",0);
31477 zSep = "VALUES(";
31478 while( SQLITE_ROW==sqlite3_step(pStmt) ){
31479 const char *zTab = (const char*)sqlite3_column_text(pStmt,0);
31480 if( zTab==0 ) continue;
31481 if( zLike && sqlite3_strlike(zLike, zTab, 0)!=0 ) continue;
31482 if( cli_strncmp(zTab, "sqlite_",7)!=0 ){
31483 appendText(&sQuery,"SELECT * FROM ", 0);
31484 appendText(&sQuery,zTab,'"');
31485 appendText(&sQuery," NOT INDEXED;", 0);
31486 }else if( cli_strcmp(zTab, "sqlite_schema")==0 ){
31487 appendText(&sQuery,"SELECT type,name,tbl_name,sql FROM sqlite_schema"
31488 " ORDER BY name;", 0);
31489 }else if( cli_strcmp(zTab, "sqlite_sequence")==0 ){
31490 appendText(&sQuery,"SELECT name,seq FROM sqlite_sequence"
31491 " ORDER BY name;", 0);
31492 }else if( cli_strcmp(zTab, "sqlite_stat1")==0 ){
31493 appendText(&sQuery,"SELECT tbl,idx,stat FROM sqlite_stat1"
31494 " ORDER BY tbl,idx;", 0);
31495 }else if( cli_strcmp(zTab, "sqlite_stat4")==0 ){
31496 appendText(&sQuery, "SELECT * FROM ", 0);
31497 appendText(&sQuery, zTab, 0);
31498 appendText(&sQuery, " ORDER BY tbl, idx, rowid;\n", 0);
31499 }
31500 appendText(&sSql, zSep, 0);
31501 appendText(&sSql, sQuery.z, '\'');
31502 sQuery.n = 0;
31503 appendText(&sSql, ",", 0);
31504 appendText(&sSql, zTab, '\'');
31505 zSep = "),(";
31506 }
31507 sqlite3_finalize(pStmt);
31508 if( bSeparate ){
31509 zSql = sqlite3_mprintf(
31510 "%s))"
31511 " SELECT lower(hex(sha3_query(a,%d))) AS hash, b AS label"
31512 " FROM [sha3sum$query]",
31513 sSql.z, iSize);
31514 }else{
31515 zSql = sqlite3_mprintf(
31516 "%s))"
31517 " SELECT lower(hex(sha3_query(group_concat(a,''),%d))) AS hash"
31518 " FROM [sha3sum$query]",
31519 sSql.z, iSize);
31520 }
31521 shell_check_oom(zSql);
31522 freeText(&sQuery);
31523 freeText(&sSql);
31524 if( bDebug ){
31525 sqlite3_fprintf(p->out, "%s\n", zSql);
31526 }else{
31527 shell_exec(p, zSql, 0);
31528 }
31529#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && !defined(SQLITE_OMIT_VIRTUALTABLE)
31530 {
31531 int lrc;
31532 char *zRevText = /* Query for reversible to-blob-to-text check */
31533 "SELECT lower(name) as tname FROM sqlite_schema\n"
31534 "WHERE type='table' AND coalesce(rootpage,0)>1\n"
31535 "AND name NOT LIKE 'sqlite_%%'%s\n"
31536 "ORDER BY 1 collate nocase";
31537 zRevText = sqlite3_mprintf(zRevText, zLike? " AND name LIKE $tspec" : "");
31538 zRevText = sqlite3_mprintf(
31539 /* lower-case query is first run, producing upper-case query. */
31540 "with tabcols as materialized(\n"
31541 "select tname, cname\n"
31542 "from ("
31543 " select printf('\"%%w\"',ss.tname) as tname,"
31544 " printf('\"%%w\"',ti.name) as cname\n"
31545 " from (%z) ss\n inner join pragma_table_info(tname) ti))\n"
31546 "select 'SELECT total(bad_text_count) AS bad_text_count\n"
31547 "FROM ('||group_concat(query, ' UNION ALL ')||')' as btc_query\n"
31548 " from (select 'SELECT COUNT(*) AS bad_text_count\n"
31549 "FROM '||tname||' WHERE '\n"
31550 "||group_concat('CAST(CAST('||cname||' AS BLOB) AS TEXT)<>'||cname\n"
31551 "|| ' AND typeof('||cname||')=''text'' ',\n"
31552 "' OR ') as query, tname from tabcols group by tname)"
31553 , zRevText);
31554 shell_check_oom(zRevText);
31555 if( bDebug ) sqlite3_fprintf(p->out, "%s\n", zRevText);
31556 lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
31557 if( lrc!=SQLITE_OK ){
31558 /* assert(lrc==SQLITE_NOMEM); // might also be SQLITE_ERROR if the
31559 ** user does cruel and unnatural things like ".limit expr_depth 0". */
31560 rc = 1;
31561 }else{
31562 if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
31563 lrc = SQLITE_ROW==sqlite3_step(pStmt);
31564 if( lrc ){
31565 const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
31566 sqlite3_stmt *pCheckStmt;
31567 lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
31568 if( bDebug ) sqlite3_fprintf(p->out, "%s\n", zGenQuery);
31569 if( lrc!=SQLITE_OK ){
31570 rc = 1;
31571 }else{
31572 if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
31573 double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
31574 if( countIrreversible>0 ){
31575 int sz = (int)(countIrreversible + 0.5);
31576 sqlite3_fprintf(stderr,
31577 "Digest includes %d invalidly encoded text field%s.\n",
31578 sz, (sz>1)? "s": "");
31579 }
31580 }
31581 sqlite3_finalize(pCheckStmt);
31582 }
31583 sqlite3_finalize(pStmt);
31584 }
31585 }
31586 if( rc ) eputz(".sha3sum failed.\n");
31587 sqlite3_free(zRevText);
31588 }
31589#endif /* !defined(*_OMIT_SCHEMA_PRAGMAS) && !defined(*_OMIT_VIRTUALTABLE) */
31590 sqlite3_free(zSql);
31591 }else
31592
31593#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
31594 if( c=='s'
31595 && (cli_strncmp(azArg[0], "shell", n)==0
31596 || cli_strncmp(azArg[0],"system",n)==0)
31597 ){
31598 char *zCmd;
31599 int i, x;
31600 failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]);
31601 if( nArg<2 ){
31602 eputz("Usage: .system COMMAND\n");
31603 rc = 1;
31604 goto meta_command_exit;
31605 }
31606 zCmd = sqlite3_mprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]);
31607 for(i=2; i<nArg && zCmd!=0; i++){
31608 zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"",
31609 zCmd, azArg[i]);
31610 }
31611 /*consoleRestore();*/
31612 x = zCmd!=0 ? system(zCmd) : 1;
31613 /*consoleRenewSetup();*/
31614 sqlite3_free(zCmd);
31615 if( x ) sqlite3_fprintf(stderr,"System command returns %d\n", x);
31616 }else
31617#endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE) */
31618
31619 if( c=='s' && cli_strncmp(azArg[0], "show", n)==0 ){
31620 static const char *azBool[] = { "off", "on", "trigger", "full"};
31621 const char *zOut;
31622 int i;
31623 if( nArg!=1 ){
31624 eputz("Usage: .show\n");
31625 rc = 1;
31626 goto meta_command_exit;
31627 }
31628 sqlite3_fprintf(p->out, "%12.12s: %s\n","echo",
31629 azBool[ShellHasFlag(p, SHFLG_Echo)]);
31630 sqlite3_fprintf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
31631 sqlite3_fprintf(p->out, "%12.12s: %s\n","explain",
31632 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
31633 sqlite3_fprintf(p->out, "%12.12s: %s\n","headers",
31634 azBool[p->showHeader!=0]);
31635 if( p->mode==MODE_Column
31636 || (p->mode>=MODE_Markdown && p->mode<=MODE_Box)
31637 ){
31639 "%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode",
31640 modeDescr[p->mode], p->cmOpts.iWrap,
31641 p->cmOpts.bWordWrap ? "on" : "off",
31642 p->cmOpts.bQuote ? "" : "no");
31643 }else{
31644 sqlite3_fprintf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
31645 }
31646 sqlite3_fprintf(p->out, "%12.12s: ", "nullvalue");
31648 sqlite3_fputs("\n", p->out);
31649 sqlite3_fprintf(p->out, "%12.12s: %s\n","output",
31650 strlen30(p->outfile) ? p->outfile : "stdout");
31651 sqlite3_fprintf(p->out, "%12.12s: ", "colseparator");
31653 sqlite3_fputs("\n", p->out);
31654 sqlite3_fprintf(p->out, "%12.12s: ", "rowseparator");
31656 sqlite3_fputs("\n", p->out);
31657 switch( p->statsOn ){
31658 case 0: zOut = "off"; break;
31659 default: zOut = "on"; break;
31660 case 2: zOut = "stmt"; break;
31661 case 3: zOut = "vmstep"; break;
31662 }
31663 sqlite3_fprintf(p->out, "%12.12s: %s\n","stats", zOut);
31664 sqlite3_fprintf(p->out, "%12.12s: ", "width");
31665 for (i=0;i<p->nWidth;i++) {
31666 sqlite3_fprintf(p->out, "%d ", p->colWidth[i]);
31667 }
31668 sqlite3_fputs("\n", p->out);
31669 sqlite3_fprintf(p->out, "%12.12s: %s\n", "filename",
31670 p->pAuxDb->zDbFilename ? p->pAuxDb->zDbFilename : "");
31671 }else
31672
31673 if( c=='s' && cli_strncmp(azArg[0], "stats", n)==0 ){
31674 if( nArg==2 ){
31675 if( cli_strcmp(azArg[1],"stmt")==0 ){
31676 p->statsOn = 2;
31677 }else if( cli_strcmp(azArg[1],"vmstep")==0 ){
31678 p->statsOn = 3;
31679 }else{
31680 p->statsOn = (u8)booleanValue(azArg[1]);
31681 }
31682 }else if( nArg==1 ){
31683 display_stats(p->db, p, 0);
31684 }else{
31685 eputz("Usage: .stats ?on|off|stmt|vmstep?\n");
31686 rc = 1;
31687 }
31688 }else
31689
31690 if( (c=='t' && n>1 && cli_strncmp(azArg[0], "tables", n)==0)
31691 || (c=='i' && (cli_strncmp(azArg[0], "indices", n)==0
31692 || cli_strncmp(azArg[0], "indexes", n)==0) )
31693 ){
31694 sqlite3_stmt *pStmt;
31695 char **azResult;
31696 int nRow, nAlloc;
31697 int ii;
31698 ShellText s;
31699 initText(&s);
31700 open_db(p, 0);
31701 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
31702 if( rc ){
31703 sqlite3_finalize(pStmt);
31704 return shellDatabaseError(p->db);
31705 }
31706
31707 if( nArg>2 && c=='i' ){
31708 /* It is an historical accident that the .indexes command shows an error
31709 ** when called with the wrong number of arguments whereas the .tables
31710 ** command does not. */
31711 eputz("Usage: .indexes ?LIKE-PATTERN?\n");
31712 rc = 1;
31713 sqlite3_finalize(pStmt);
31714 goto meta_command_exit;
31715 }
31716 for(ii=0; sqlite3_step(pStmt)==SQLITE_ROW; ii++){
31717 const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
31718 if( zDbName==0 ) continue;
31719 if( s.z && s.z[0] ) appendText(&s, " UNION ALL ", 0);
31720 if( sqlite3_stricmp(zDbName, "main")==0 ){
31721 appendText(&s, "SELECT name FROM ", 0);
31722 }else{
31723 appendText(&s, "SELECT ", 0);
31724 appendText(&s, zDbName, '\'');
31725 appendText(&s, "||'.'||name FROM ", 0);
31726 }
31727 appendText(&s, zDbName, '"');
31728 appendText(&s, ".sqlite_schema ", 0);
31729 if( c=='t' ){
31730 appendText(&s," WHERE type IN ('table','view')"
31731 " AND name NOT LIKE 'sqlite_%'"
31732 " AND name LIKE ?1", 0);
31733 }else{
31734 appendText(&s," WHERE type='index'"
31735 " AND tbl_name LIKE ?1", 0);
31736 }
31737 }
31738 rc = sqlite3_finalize(pStmt);
31739 if( rc==SQLITE_OK ){
31740 appendText(&s, " ORDER BY 1", 0);
31741 rc = sqlite3_prepare_v2(p->db, s.z, -1, &pStmt, 0);
31742 }
31743 freeText(&s);
31744 if( rc ) return shellDatabaseError(p->db);
31745
31746 /* Run the SQL statement prepared by the above block. Store the results
31747 ** as an array of nul-terminated strings in azResult[]. */
31748 nRow = nAlloc = 0;
31749 azResult = 0;
31750 if( nArg>1 ){
31751 sqlite3_bind_text(pStmt, 1, azArg[1], -1, SQLITE_TRANSIENT);
31752 }else{
31753 sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC);
31754 }
31755 while( sqlite3_step(pStmt)==SQLITE_ROW ){
31756 if( nRow>=nAlloc ){
31757 char **azNew;
31758 int n2 = nAlloc*2 + 10;
31759 azNew = sqlite3_realloc64(azResult, sizeof(azResult[0])*n2);
31760 shell_check_oom(azNew);
31761 nAlloc = n2;
31762 azResult = azNew;
31763 }
31764 azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
31765 shell_check_oom(azResult[nRow]);
31766 nRow++;
31767 }
31768 if( sqlite3_finalize(pStmt)!=SQLITE_OK ){
31769 rc = shellDatabaseError(p->db);
31770 }
31771
31772 /* Pretty-print the contents of array azResult[] to the output */
31773 if( rc==0 && nRow>0 ){
31774 int len, maxlen = 0;
31775 int i, j;
31776 int nPrintCol, nPrintRow;
31777 for(i=0; i<nRow; i++){
31778 len = strlen30(azResult[i]);
31779 if( len>maxlen ) maxlen = len;
31780 }
31781 nPrintCol = 80/(maxlen+2);
31782 if( nPrintCol<1 ) nPrintCol = 1;
31783 nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
31784 for(i=0; i<nPrintRow; i++){
31785 for(j=i; j<nRow; j+=nPrintRow){
31786 char *zSp = j<nPrintRow ? "" : " ";
31788 "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:"");
31789 }
31790 sqlite3_fputs("\n", p->out);
31791 }
31792 }
31793
31794 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
31795 sqlite3_free(azResult);
31796 }else
31797
31798#ifndef SQLITE_SHELL_FIDDLE
31799 /* Begin redirecting output to the file "testcase-out.txt" */
31800 if( c=='t' && cli_strcmp(azArg[0],"testcase")==0 ){
31801 output_reset(p);
31802 p->out = output_file_open("testcase-out.txt");
31803 if( p->out==0 ){
31804 eputz("Error: cannot open 'testcase-out.txt'\n");
31805 }
31806 if( nArg>=2 ){
31807 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
31808 }else{
31809 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
31810 }
31811 }else
31812#endif /* !defined(SQLITE_SHELL_FIDDLE) */
31813
31814#ifndef SQLITE_UNTESTABLE
31815 if( c=='t' && n>=8 && cli_strncmp(azArg[0], "testctrl", n)==0 ){
31816 static const struct {
31817 const char *zCtrlName; /* Name of a test-control option */
31818 int ctrlCode; /* Integer code for that option */
31819 int unSafe; /* Not valid unless --unsafe-testing */
31820 const char *zUsage; /* Usage notes */
31821 } aCtrl[] = {
31822 {"always", SQLITE_TESTCTRL_ALWAYS, 1, "BOOLEAN" },
31823 {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
31824 /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
31825 /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
31826 {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
31827 {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
31828 {"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
31829 {"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
31830 {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
31831 {"internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" },
31832 {"json_selfcheck", SQLITE_TESTCTRL_JSON_SELFCHECK ,0,"BOOLEAN" },
31833 {"localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,0,"BOOLEAN" },
31834 {"never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT,1, "BOOLEAN" },
31835 {"optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS,0,"DISABLE-MASK ..."},
31836#ifdef YYCOVERAGE
31837 {"parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE,0,"" },
31838#endif
31839 {"pending_byte", SQLITE_TESTCTRL_PENDING_BYTE,1, "OFFSET " },
31840 {"prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE,0, "" },
31841 {"prng_save", SQLITE_TESTCTRL_PRNG_SAVE, 0, "" },
31842 {"prng_seed", SQLITE_TESTCTRL_PRNG_SEED, 0, "SEED ?db?" },
31843 {"seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" },
31844 {"sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" },
31845 {"tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" },
31846 };
31847 int testctrl = -1;
31848 int iCtrl = -1;
31849 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
31850 int isOk = 0;
31851 int i, n2;
31852 const char *zCmd = 0;
31853
31854 open_db(p, 0);
31855 zCmd = nArg>=2 ? azArg[1] : "help";
31856
31857 /* The argument can optionally begin with "-" or "--" */
31858 if( zCmd[0]=='-' && zCmd[1] ){
31859 zCmd++;
31860 if( zCmd[0]=='-' && zCmd[1] ) zCmd++;
31861 }
31862
31863 /* --help lists all test-controls */
31864 if( cli_strcmp(zCmd,"help")==0 ){
31865 sqlite3_fputs("Available test-controls:\n", p->out);
31866 for(i=0; i<ArraySize(aCtrl); i++){
31867 if( aCtrl[i].unSafe && !ShellHasFlag(p,SHFLG_TestingMode) ) continue;
31868 sqlite3_fprintf(p->out, " .testctrl %s %s\n",
31869 aCtrl[i].zCtrlName, aCtrl[i].zUsage);
31870 }
31871 rc = 1;
31872 goto meta_command_exit;
31873 }
31874
31875 /* convert testctrl text option to value. allow any unique prefix
31876 ** of the option name, or a numerical value. */
31877 n2 = strlen30(zCmd);
31878 for(i=0; i<ArraySize(aCtrl); i++){
31879 if( aCtrl[i].unSafe && !ShellHasFlag(p,SHFLG_TestingMode) ) continue;
31880 if( cli_strncmp(zCmd, aCtrl[i].zCtrlName, n2)==0 ){
31881 if( testctrl<0 ){
31882 testctrl = aCtrl[i].ctrlCode;
31883 iCtrl = i;
31884 }else{
31885 sqlite3_fprintf(stderr,"Error: ambiguous test-control: \"%s\"\n"
31886 "Use \".testctrl --help\" for help\n", zCmd);
31887 rc = 1;
31888 goto meta_command_exit;
31889 }
31890 }
31891 }
31892 if( testctrl<0 ){
31893 sqlite3_fprintf(stderr,"Error: unknown test-control: %s\n"
31894 "Use \".testctrl --help\" for help\n", zCmd);
31895 }else{
31896 switch(testctrl){
31897
31898 /* Special processing for .testctrl opt MASK ...
31899 ** Each MASK argument can be one of:
31900 **
31901 ** +LABEL Enable the named optimization
31902 **
31903 ** -LABEL Disable the named optimization
31904 **
31905 ** INTEGER Mask of optimizations to disable
31906 */
31908 static const struct {
31909 unsigned int mask; /* Mask for this optimization */
31910 unsigned int bDsply; /* Display this on output */
31911 const char *zLabel; /* Name of optimization */
31912 } aLabel[] = {
31913 { 0x00000001, 1, "QueryFlattener" },
31914 { 0x00000001, 0, "Flatten" },
31915 { 0x00000002, 1, "WindowFunc" },
31916 { 0x00000004, 1, "GroupByOrder" },
31917 { 0x00000008, 1, "FactorOutConst" },
31918 { 0x00000010, 1, "DistinctOpt" },
31919 { 0x00000020, 1, "CoverIdxScan" },
31920 { 0x00000040, 1, "OrderByIdxJoin" },
31921 { 0x00000080, 1, "Transitive" },
31922 { 0x00000100, 1, "OmitNoopJoin" },
31923 { 0x00000200, 1, "CountOfView" },
31924 { 0x00000400, 1, "CurosrHints" },
31925 { 0x00000800, 1, "Stat4" },
31926 { 0x00001000, 1, "PushDown" },
31927 { 0x00002000, 1, "SimplifyJoin" },
31928 { 0x00004000, 1, "SkipScan" },
31929 { 0x00008000, 1, "PropagateConst" },
31930 { 0x00010000, 1, "MinMaxOpt" },
31931 { 0x00020000, 1, "SeekScan" },
31932 { 0x00040000, 1, "OmitOrderBy" },
31933 { 0x00080000, 1, "BloomFilter" },
31934 { 0x00100000, 1, "BloomPulldown" },
31935 { 0x00200000, 1, "BalancedMerge" },
31936 { 0x00400000, 1, "ReleaseReg" },
31937 { 0x00800000, 1, "FlttnUnionAll" },
31938 { 0x01000000, 1, "IndexedEXpr" },
31939 { 0x02000000, 1, "Coroutines" },
31940 { 0x04000000, 1, "NullUnusedCols" },
31941 { 0x08000000, 1, "OnePass" },
31942 { 0x10000000, 1, "OrderBySubq" },
31943 { 0x20000000, 1, "StarQuery" },
31944 { 0xffffffff, 0, "All" },
31945 };
31946 unsigned int curOpt;
31947 unsigned int newOpt;
31948 unsigned int m;
31949 int ii;
31950 int nOff;
31952 newOpt = curOpt;
31953 for(ii=2; ii<nArg; ii++){
31954 const char *z = azArg[ii];
31955 int useLabel = 0;
31956 const char *zLabel = 0;
31957 if( (z[0]=='+'|| z[0]=='-') && !IsDigit(z[1]) ){
31958 useLabel = z[0];
31959 zLabel = &z[1];
31960 }else if( !IsDigit(z[0]) && z[0]!=0 && !IsDigit(z[1]) ){
31961 useLabel = '+';
31962 zLabel = z;
31963 }else{
31964 newOpt = (unsigned int)strtol(z,0,0);
31965 }
31966 if( useLabel ){
31967 int jj;
31968 for(jj=0; jj<ArraySize(aLabel); jj++){
31969 if( sqlite3_stricmp(zLabel, aLabel[jj].zLabel)==0 ) break;
31970 }
31971 if( jj>=ArraySize(aLabel) ){
31972 sqlite3_fprintf(stderr,
31973 "Error: no such optimization: \"%s\"\n", zLabel);
31974 sqlite3_fputs("Should be one of:", stderr);
31975 for(jj=0; jj<ArraySize(aLabel); jj++){
31976 sqlite3_fprintf(stderr," %s", aLabel[jj].zLabel);
31977 }
31978 sqlite3_fputs("\n", stderr);
31979 rc = 1;
31980 goto meta_command_exit;
31981 }
31982 if( useLabel=='+' ){
31983 newOpt &= ~aLabel[jj].mask;
31984 }else{
31985 newOpt |= aLabel[jj].mask;
31986 }
31987 }
31988 }
31989 if( curOpt!=newOpt ){
31991 }
31992 for(ii=nOff=0, m=1; ii<32; ii++, m <<= 1){
31993 if( m & newOpt ) nOff++;
31994 }
31995 if( nOff<12 ){
31996 sqlite3_fputs("+All", p->out);
31997 for(ii=0; ii<ArraySize(aLabel); ii++){
31998 if( !aLabel[ii].bDsply ) continue;
31999 if( (newOpt & aLabel[ii].mask)!=0 ){
32000 sqlite3_fprintf(p->out, " -%s", aLabel[ii].zLabel);
32001 }
32002 }
32003 }else{
32004 sqlite3_fputs("-All", p->out);
32005 for(ii=0; ii<ArraySize(aLabel); ii++){
32006 if( !aLabel[ii].bDsply ) continue;
32007 if( (newOpt & aLabel[ii].mask)==0 ){
32008 sqlite3_fprintf(p->out, " +%s", aLabel[ii].zLabel);
32009 }
32010 }
32011 }
32012 sqlite3_fputs("\n", p->out);
32013 rc2 = isOk = 3;
32014 break;
32015 }
32016
32017 /* sqlite3_test_control(int, db, int) */
32019 if( nArg==3 ){
32020 unsigned int opt = (unsigned int)strtol(azArg[2], 0, 0);
32021 rc2 = sqlite3_test_control(testctrl, p->db, opt);
32022 isOk = 3;
32023 }
32024 break;
32025
32026 /* sqlite3_test_control(int) */
32030 if( nArg==2 ){
32031 rc2 = sqlite3_test_control(testctrl);
32032 isOk = testctrl==SQLITE_TESTCTRL_BYTEORDER ? 1 : 3;
32033 }
32034 break;
32035
32036 /* sqlite3_test_control(int, uint) */
32038 if( nArg==3 ){
32039 unsigned int opt = (unsigned int)integerValue(azArg[2]);
32040 rc2 = sqlite3_test_control(testctrl, opt);
32041 isOk = 3;
32042 }
32043 break;
32044
32045 /* sqlite3_test_control(int, int, sqlite3*) */
32047 if( nArg==3 || nArg==4 ){
32048 int ii = (int)integerValue(azArg[2]);
32049 sqlite3 *db;
32050 if( ii==0 && cli_strcmp(azArg[2],"random")==0 ){
32051 sqlite3_randomness(sizeof(ii),&ii);
32052 sqlite3_fprintf(stdout, "-- random seed: %d\n", ii);
32053 }
32054 if( nArg==3 ){
32055 db = 0;
32056 }else{
32057 db = p->db;
32058 /* Make sure the schema has been loaded */
32059 sqlite3_table_column_metadata(db, 0, "x", 0, 0, 0, 0, 0, 0);
32060 }
32061 rc2 = sqlite3_test_control(testctrl, ii, db);
32062 isOk = 3;
32063 }
32064 break;
32065
32066 /* sqlite3_test_control(int, int) */
32069 if( nArg==3 ){
32070 int opt = booleanValue(azArg[2]);
32071 rc2 = sqlite3_test_control(testctrl, opt);
32072 isOk = 1;
32073 }
32074 break;
32075
32076 /* sqlite3_test_control(int, int) */
32079 if( nArg==3 ){
32080 int opt = booleanValue(azArg[2]);
32081 rc2 = sqlite3_test_control(testctrl, opt);
32082 isOk = 3;
32083 }
32084 break;
32085
32086 /* sqlite3_test_control(sqlite3*) */
32088 rc2 = sqlite3_test_control(testctrl, p->db);
32089 isOk = 3;
32090 break;
32091
32093 if( nArg==5 ){
32094 rc2 = sqlite3_test_control(testctrl, p->db,
32095 azArg[2],
32096 integerValue(azArg[3]),
32097 integerValue(azArg[4]));
32098 isOk = 3;
32099 }
32100 break;
32101
32103 u64 x = 0;
32104 rc2 = sqlite3_test_control(testctrl, p->db, &x);
32105 sqlite3_fprintf(p->out, "%llu\n", x);
32106 isOk = 3;
32107 break;
32108 }
32109
32110#ifdef YYCOVERAGE
32112 if( nArg==2 ){
32113 sqlite3_test_control(testctrl, p->out);
32114 isOk = 3;
32115 }
32116 break;
32117 }
32118#endif
32119#ifdef SQLITE_DEBUG
32120 case SQLITE_TESTCTRL_TUNE: {
32121 if( nArg==4 ){
32122 int id = (int)integerValue(azArg[2]);
32123 int val = (int)integerValue(azArg[3]);
32124 sqlite3_test_control(testctrl, id, &val);
32125 isOk = 3;
32126 }else if( nArg==3 ){
32127 int id = (int)integerValue(azArg[2]);
32128 sqlite3_test_control(testctrl, -id, &rc2);
32129 isOk = 1;
32130 }else if( nArg==2 ){
32131 int id = 1;
32132 while(1){
32133 int val = 0;
32134 rc2 = sqlite3_test_control(testctrl, -id, &val);
32135 if( rc2!=SQLITE_OK ) break;
32136 if( id>1 ) sqlite3_fputs(" ", p->out);
32137 sqlite3_fprintf(p->out, "%d: %d", id, val);
32138 id++;
32139 }
32140 if( id>1 ) sqlite3_fputs("\n", p->out);
32141 isOk = 3;
32142 }
32143 break;
32144 }
32145#endif
32147 if( nArg==3 ){
32148 int opt = (unsigned int)integerValue(azArg[2]);
32149 rc2 = sqlite3_test_control(testctrl, p->db, opt);
32150 isOk = 3;
32151 }
32152 break;
32154 if( nArg==2 ){
32155 rc2 = -1;
32156 isOk = 1;
32157 }else{
32158 rc2 = booleanValue(azArg[2]);
32159 isOk = 3;
32160 }
32161 sqlite3_test_control(testctrl, &rc2);
32162 break;
32164 int kk;
32165 int bShowHelp = nArg<=2;
32166 isOk = 3;
32167 for(kk=2; kk<nArg; kk++){
32168 const char *z = azArg[kk];
32169 if( z[0]=='-' && z[1]=='-' ) z++;
32170 if( cli_strcmp(z,"off")==0 ){
32171 sqlite3_test_control(testctrl, 0);
32172 }else if( cli_strcmp(z,"on")==0 ){
32173 faultsim_state.iCnt = faultsim_state.nSkip;
32174 if( faultsim_state.iErr==0 ) faultsim_state.iErr = 1;
32175 faultsim_state.nHit = 0;
32177 }else if( cli_strcmp(z,"reset")==0 ){
32178 faultsim_state.iCnt = faultsim_state.nSkip;
32179 faultsim_state.nHit = 0;
32181 }else if( cli_strcmp(z,"status")==0 ){
32182 sqlite3_fprintf(p->out, "faultsim.iId: %d\n",
32183 faultsim_state.iId);
32184 sqlite3_fprintf(p->out, "faultsim.iErr: %d\n",
32185 faultsim_state.iErr);
32186 sqlite3_fprintf(p->out, "faultsim.iCnt: %d\n",
32187 faultsim_state.iCnt);
32188 sqlite3_fprintf(p->out, "faultsim.nHit: %d\n",
32189 faultsim_state.nHit);
32190 sqlite3_fprintf(p->out, "faultsim.iInterval: %d\n",
32191 faultsim_state.iInterval);
32192 sqlite3_fprintf(p->out, "faultsim.eVerbose: %d\n",
32193 faultsim_state.eVerbose);
32194 sqlite3_fprintf(p->out, "faultsim.nRepeat: %d\n",
32195 faultsim_state.nRepeat);
32196 sqlite3_fprintf(p->out, "faultsim.nSkip: %d\n",
32197 faultsim_state.nSkip);
32198 }else if( cli_strcmp(z,"-v")==0 ){
32199 if( faultsim_state.eVerbose<2 ) faultsim_state.eVerbose++;
32200 }else if( cli_strcmp(z,"-q")==0 ){
32201 if( faultsim_state.eVerbose>0 ) faultsim_state.eVerbose--;
32202 }else if( cli_strcmp(z,"-id")==0 && kk+1<nArg ){
32203 faultsim_state.iId = atoi(azArg[++kk]);
32204 }else if( cli_strcmp(z,"-errcode")==0 && kk+1<nArg ){
32205 faultsim_state.iErr = atoi(azArg[++kk]);
32206 }else if( cli_strcmp(z,"-interval")==0 && kk+1<nArg ){
32207 faultsim_state.iInterval = atoi(azArg[++kk]);
32208 }else if( cli_strcmp(z,"-repeat")==0 && kk+1<nArg ){
32209 faultsim_state.nRepeat = atoi(azArg[++kk]);
32210 }else if( cli_strcmp(z,"-skip")==0 && kk+1<nArg ){
32211 faultsim_state.nSkip = atoi(azArg[++kk]);
32212 }else if( cli_strcmp(z,"-?")==0 || sqlite3_strglob("*help*",z)==0){
32213 bShowHelp = 1;
32214 }else{
32215 sqlite3_fprintf(stderr,
32216 "Unrecognized fault_install argument: \"%s\"\n",
32217 azArg[kk]);
32218 rc = 1;
32219 bShowHelp = 1;
32220 break;
32221 }
32222 }
32223 if( bShowHelp ){
32225 "Usage: .testctrl fault_install ARGS\n"
32226 "Possible arguments:\n"
32227 " off Disable faultsim\n"
32228 " on Activate faultsim\n"
32229 " reset Reset the trigger counter\n"
32230 " status Show current status\n"
32231 " -v Increase verbosity\n"
32232 " -q Decrease verbosity\n"
32233 " --errcode N When triggered, return N as error code\n"
32234 " --id ID Trigger only for the ID specified\n"
32235 " --interval N Trigger only after every N-th call\n"
32236 " --repeat N Turn off after N hits. 0 means never\n"
32237 " --skip N Skip the first N encounters\n"
32238 ,p->out
32239 );
32240 }
32241 break;
32242 }
32243 }
32244 }
32245 if( isOk==0 && iCtrl>=0 ){
32247 "Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage);
32248 rc = 1;
32249 }else if( isOk==1 ){
32250 sqlite3_fprintf(p->out, "%d\n", rc2);
32251 }else if( isOk==2 ){
32252 sqlite3_fprintf(p->out, "0x%08x\n", rc2);
32253 }
32254 }else
32255#endif /* !defined(SQLITE_UNTESTABLE) */
32256
32257 if( c=='t' && n>4 && cli_strncmp(azArg[0], "timeout", n)==0 ){
32258 open_db(p, 0);
32259 sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0);
32260 }else
32261
32262 if( c=='t' && n>=5 && cli_strncmp(azArg[0], "timer", n)==0 ){
32263 if( nArg==2 ){
32264 enableTimer = booleanValue(azArg[1]);
32265 if( enableTimer && !HAS_TIMER ){
32266 eputz("Error: timer not available on this system.\n");
32267 enableTimer = 0;
32268 }
32269 }else{
32270 eputz("Usage: .timer on|off\n");
32271 rc = 1;
32272 }
32273 }else
32274
32275#ifndef SQLITE_OMIT_TRACE
32276 if( c=='t' && cli_strncmp(azArg[0], "trace", n)==0 ){
32277 int mType = 0;
32278 int jj;
32279 open_db(p, 0);
32280 for(jj=1; jj<nArg; jj++){
32281 const char *z = azArg[jj];
32282 if( z[0]=='-' ){
32283 if( optionMatch(z, "expanded") ){
32285 }
32286#ifdef SQLITE_ENABLE_NORMALIZE
32287 else if( optionMatch(z, "normalized") ){
32289 }
32290#endif
32291 else if( optionMatch(z, "plain") ){
32293 }
32294 else if( optionMatch(z, "profile") ){
32295 mType |= SQLITE_TRACE_PROFILE;
32296 }
32297 else if( optionMatch(z, "row") ){
32298 mType |= SQLITE_TRACE_ROW;
32299 }
32300 else if( optionMatch(z, "stmt") ){
32301 mType |= SQLITE_TRACE_STMT;
32302 }
32303 else if( optionMatch(z, "close") ){
32304 mType |= SQLITE_TRACE_CLOSE;
32305 }
32306 else {
32307 sqlite3_fprintf(stderr,"Unknown option \"%s\" on \".trace\"\n", z);
32308 rc = 1;
32309 goto meta_command_exit;
32310 }
32311 }else{
32313 p->traceOut = output_file_open(z);
32314 }
32315 }
32316 if( p->traceOut==0 ){
32317 sqlite3_trace_v2(p->db, 0, 0, 0);
32318 }else{
32319 if( mType==0 ) mType = SQLITE_TRACE_STMT;
32320 sqlite3_trace_v2(p->db, mType, sql_trace_callback, p);
32321 }
32322 }else
32323#endif /* !defined(SQLITE_OMIT_TRACE) */
32324
32325#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_VIRTUALTABLE)
32326 if( c=='u' && cli_strncmp(azArg[0], "unmodule", n)==0 ){
32327 int ii;
32328 int lenOpt;
32329 char *zOpt;
32330 if( nArg<2 ){
32331 eputz("Usage: .unmodule [--allexcept] NAME ...\n");
32332 rc = 1;
32333 goto meta_command_exit;
32334 }
32335 open_db(p, 0);
32336 zOpt = azArg[1];
32337 if( zOpt[0]=='-' && zOpt[1]=='-' && zOpt[2]!=0 ) zOpt++;
32338 lenOpt = (int)strlen(zOpt);
32339 if( lenOpt>=3 && cli_strncmp(zOpt, "-allexcept",lenOpt)==0 ){
32340 assert( azArg[nArg]==0 );
32341 sqlite3_drop_modules(p->db, nArg>2 ? (const char**)(azArg+2) : 0);
32342 }else{
32343 for(ii=1; ii<nArg; ii++){
32344 sqlite3_create_module(p->db, azArg[ii], 0, 0);
32345 }
32346 }
32347 }else
32348#endif
32349
32350 if( c=='v' && cli_strncmp(azArg[0], "version", n)==0 ){
32351 char *zPtrSz = sizeof(void*)==8 ? "64-bit" : "32-bit";
32352 sqlite3_fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
32354#if SQLITE_HAVE_ZLIB
32355 sqlite3_fprintf(p->out, "zlib version %s\n", zlibVersion());
32356#endif
32357#define CTIMEOPT_VAL_(opt) #opt
32358#define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
32359#if defined(__clang__) && defined(__clang_major__)
32360 sqlite3_fprintf(p->out, "clang-" CTIMEOPT_VAL(__clang_major__) "."
32361 CTIMEOPT_VAL(__clang_minor__) "."
32362 CTIMEOPT_VAL(__clang_patchlevel__) " (%s)\n", zPtrSz);
32363#elif defined(_MSC_VER)
32364 sqlite3_fprintf(p->out, "msvc-" CTIMEOPT_VAL(_MSC_VER) " (%s)\n", zPtrSz);
32365#elif defined(__GNUC__) && defined(__VERSION__)
32366 sqlite3_fprintf(p->out, "gcc-" __VERSION__ " (%s)\n", zPtrSz);
32367#endif
32368 }else
32369
32370 if( c=='v' && cli_strncmp(azArg[0], "vfsinfo", n)==0 ){
32371 const char *zDbName = nArg==2 ? azArg[1] : "main";
32372 sqlite3_vfs *pVfs = 0;
32373 if( p->db ){
32375 if( pVfs ){
32376 sqlite3_fprintf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName);
32377 sqlite3_fprintf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
32378 sqlite3_fprintf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile);
32379 sqlite3_fprintf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname);
32380 }
32381 }
32382 }else
32383
32384 if( c=='v' && cli_strncmp(azArg[0], "vfslist", n)==0 ){
32385 sqlite3_vfs *pVfs;
32386 sqlite3_vfs *pCurrent = 0;
32387 if( p->db ){
32388 sqlite3_file_control(p->db, "main", SQLITE_FCNTL_VFS_POINTER, &pCurrent);
32389 }
32390 for(pVfs=sqlite3_vfs_find(0); pVfs; pVfs=pVfs->pNext){
32391 sqlite3_fprintf(p->out, "vfs.zName = \"%s\"%s\n", pVfs->zName,
32392 pVfs==pCurrent ? " <--- CURRENT" : "");
32393 sqlite3_fprintf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
32394 sqlite3_fprintf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile);
32395 sqlite3_fprintf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname);
32396 if( pVfs->pNext ){
32397 sqlite3_fputs("-----------------------------------\n", p->out);
32398 }
32399 }
32400 }else
32401
32402 if( c=='v' && cli_strncmp(azArg[0], "vfsname", n)==0 ){
32403 const char *zDbName = nArg==2 ? azArg[1] : "main";
32404 char *zVfsName = 0;
32405 if( p->db ){
32406 sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName);
32407 if( zVfsName ){
32408 sqlite3_fprintf(p->out, "%s\n", zVfsName);
32409 sqlite3_free(zVfsName);
32410 }
32411 }
32412 }else
32413
32414 if( c=='w' && cli_strncmp(azArg[0], "wheretrace", n)==0 ){
32415 unsigned int x = nArg>=2? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
32417 }else
32418
32419 if( c=='w' && cli_strncmp(azArg[0], "width", n)==0 ){
32420 int j;
32421 assert( nArg<=ArraySize(azArg) );
32422 p->nWidth = nArg-1;
32423 p->colWidth = realloc(p->colWidth, (p->nWidth+1)*sizeof(int)*2);
32424 if( p->colWidth==0 && p->nWidth>0 ) shell_out_of_memory();
32425 if( p->nWidth ) p->actualWidth = &p->colWidth[p->nWidth];
32426 for(j=1; j<nArg; j++){
32427 p->colWidth[j-1] = (int)integerValue(azArg[j]);
32428 }
32429 }else
32430
32431 {
32432 sqlite3_fprintf(stderr,"Error: unknown command or invalid arguments: "
32433 " \"%s\". Enter \".help\" for help\n", azArg[0]);
32434 rc = 1;
32435 }
32436
32437meta_command_exit:
32438 if( p->outCount ){
32439 p->outCount--;
32440 if( p->outCount==0 ) output_reset(p);
32441 }
static void output_c_string(FILE *out, const char *z)
Definition shell.c:22280
int nErr
Definition shell.c:21696
struct ShellState::AuxDb aAuxDb[5]
static struct @001052170001011011035007213325114067113271343130 faultsim_state
#define SEP_Row
Definition shell.c:21868
static int progress_handler(void *pClientData)
Definition shell.c:22821
static int bail_on_error
Definition shell.c:819
int nCheck
Definition shell.c:21703
#define MODE_Quote
Definition shell.c:21823
static int callback(void *pArg, int nArg, char **azArg, char **azCol)
Definition shell.c:23306
#define SHFLG_DumpDataOnly
Definition shell.c:21803
u8 autoExplain
Definition shell.c:21671
static int shellDatabaseError(sqlite3 *db)
Definition shell.c:27140
char * zDestTable
Definition shell.c:21710
int iWrap
Definition shell.c:21657
static int shell_dbtotxt_command(ShellState *p, int nArg, char **azArg)
Definition shell.c:27043
#define sputz(fp, z)
Definition shell.c:634
static void test_breakpoint(void)
Definition shell.c:26449
#define MODE_Explain
Definition shell.c:21826
static int process_input(ShellState *p)
Definition shell.c:32768
int * colWidth
Definition shell.c:21717
#define SEP_Comma
Definition shell.c:21871
#define MODE_Line
Definition shell.c:21817
static void freeText(ShellText *p)
Definition shell.c:1473
static FILE * output_file_open(const char *zFile)
Definition shell.c:26364
static char continuePrompt[128]
Definition shell.c:860
static FILE * openChrSource(const char *zFile)
Definition shell.c:1286
sqlite3_int64 szMax
Definition shell.c:21709
#define MODE_Html
Definition shell.c:21821
struct ShellState::AuxDb * pAuxDb[5]
FILE * traceOut
Definition shell.c:21695
int(* xCloser)(FILE *)
Definition shell.c:26461
static int optionMatch(const char *zStr, const char *zOpt)
Definition shell.c:27247
static void bind_table_init(ShellState *p)
Definition shell.c:24031
#define ShellSetFlag(P, X)
Definition shell.c:21811
#define sqlite3_popen
Definition shell.c:303
static int shell_exec(ShellState *pArg, const char *zSql, char **pzErrMsg)
Definition shell.c:24829
u8 bWordWrap
Definition shell.c:21659
#define MODE_Insert
Definition shell.c:21822
static char quoteChar(const char *zName)
Definition shell.c:1530
static int showHelp(FILE *out, const char *zPattern)
Definition shell.c:25601
#define SHFLG_PreserveRowid
Definition shell.c:21798
static int expertDotCommand(ShellState *pState, char **azArg, int nArg)
Definition shell.c:24763
static void resolve_backslashes(char *z)
Definition shell.c:26265
void close_db(sqlite3 *db)
Definition shell.c:26160
#define SHELL_TRACE_PLAIN
Definition shell.c:21774
#define SEP_Tab
Definition shell.c:21869
u8 bQuote
Definition shell.c:21658
#define SHELL_TRACE_NORMALIZED
Definition shell.c:21776
static int expertFinish(ShellState *pState, int bCancel, char **pzErr)
Definition shell.c:24717
#define SHELL_PROGRESS_QUIET
Definition shell.c:21779
#define ArraySize(X)
Definition shell.c:813
#define HAS_TIMER
Definition shell.c:718
const char * zDbFilename
Definition shell.c:21727
static char * zAutoColumn(const char *zColNew, sqlite3 **pDb, char **pzRenamed)
Definition shell.c:28554
#define MODE_Count
Definition shell.c:21834
static void open_db(ShellState *p, int openFlags)
Definition shell.c:25975
static void output_redir(ShellState *p, FILE *pfNew)
Definition shell.c:26841
#define AUTOEQP_full
Definition shell.c:21760
sqlite3_uint64 u64
Definition shell.c:123
static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt)
Definition shell.c:24060
int mode
Definition shell.c:21697
#define MODE_Box
Definition shell.c:21833
#define SHELL_OPEN_HEXDB
Definition shell.c:21770
#define SHELL_ESC_OFF
Definition shell.c:21788
#define ColModeOpts_default_qbox
Definition shell.c:21662
static void newTempFile(ShellState *p, const char *zSuffix)
Definition shell.c:27284
char rowSeparator[20]
Definition shell.c:21714
static const char * modeDescr[]
Definition shell.c:21839
sqlite3expert * pExpert
Definition shell.c:21634
#define MODE_Json
Definition shell.c:21830
u8 autoEQPtest
Definition shell.c:21673
#define MODE_Off
Definition shell.c:21835
u8 bSafeModePersist
Definition shell.c:21681
static const char * shell_EscModeNames[]
Definition shell.c:21790
u8 bSafeMode
Definition shell.c:21680
char * zFreeOnClose
Definition shell.c:21728
static int safeModeAuth(void *pClientData, int op, const char *zA1, const char *zA2, const char *zA3, const char *zA4)
Definition shell.c:22574
static int testcase_glob(const char *zGlob, const char *z)
Definition shell.c:27168
#define OPEN_DB_KEEPALIVE
Definition shell.c:25968
char nullValue[20]
Definition shell.c:21720
unsigned nProgress
Definition shell.c:21704
#define MODE_Www
Definition shell.c:21837
#define SEP_Record
Definition shell.c:21874
int * actualWidth
Definition shell.c:21718
#define SHFLG_DumpNoSys
Definition shell.c:21804
#define AUTOEQP_trigger
Definition shell.c:21759
#define SHELL_OPEN_DESERIALIZE
Definition shell.c:21769
#define ShellClearFlag(P, X)
Definition shell.c:21812
ExpertInfo expert
Definition shell.c:21740
#define SHELL_TRACE_EXPANDED
Definition shell.c:21775
int writableSchema
Definition shell.c:21701
#define MODE_List
Definition shell.c:21819
u8 eEscMode
Definition shell.c:21684
static int run_table_dump_query(ShellState *p, const char *zSelect)
Definition shell.c:23461
int nRow
Definition shell.c:26466
static char * shell_strncpy(char *dest, const char *src, size_t n)
Definition shell.c:867
int lineno
Definition shell.c:21691
#define ColModeOpts_default
Definition shell.c:21661
#define SHFLG_Newlines
Definition shell.c:21799
#define ShellHasFlag(P, X)
Definition shell.c:21810
char zTestcase[30]
Definition shell.c:21712
static void tryToClone(ShellState *p, const char *zNewDb)
Definition shell.c:26815
#define SHELL_OPEN_READONLY
Definition shell.c:21768
#define SHFLG_Echo
Definition shell.c:21801
static int faultsim_callback(int iArg)
Definition shell.c:28772
static int cli_strcmp(const char *a, const char *b)
Definition shell.c:640
static void setOrClearFlag(ShellState *p, unsigned mFlag, const char *zArg)
Definition shell.c:26344
static void shellEmitError(const char *zErr)
Definition shell.c:27134
int pclose(FILE *)
static int cli_strncmp(const char *a, const char *b, size_t n)
Definition shell.c:645
#define CTIMEOPT_VAL(opt)
unsigned mxProgress
Definition shell.c:21705
static int sql_trace_callback(unsigned mType, void *pArg, void *pP, void *pX)
Definition shell.c:26385
static void output_file_close(FILE *f)
Definition shell.c:26355
#define MODE_Table
Definition shell.c:21832
FILE * pLog
Definition shell.c:21724
static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az)
Definition shell.c:23315
int outCount
Definition shell.c:21689
#define MODE_Column
Definition shell.c:21818
u8 autoEQP
Definition shell.c:21672
sqlite3 * db
Definition shell.c:21726
static void outputModePush(ShellState *p)
Definition shell.c:22076
#define AUTOEQP_on
Definition shell.c:21758
#define MODE_Csv
Definition shell.c:21825
char outfile[FILENAME_MAX]
Definition shell.c:21722
#define SEP_Unit
Definition shell.c:21873
static void createSelftestTable(ShellState *p)
Definition shell.c:23331
#define SHFLG_CountChanges
Definition shell.c:21800
u8 eTraceType
Definition shell.c:21679
static void import_cleanup(ImportCtx *p)
Definition shell.c:26475
int normalMode
Definition shell.c:21700
static int lintDotCommand(ShellState *pState, char **azArg, int nArg)
Definition shell.c:27546
static int shellAuth(void *pClientData, int op, const char *zA1, const char *zA2, const char *zA3, const char *zA4)
Definition shell.c:22622
static int outputDumpWarning(ShellState *p, const char *zLike)
Definition shell.c:28738
static char * readFile(const char *zName, int *pnByte)
Definition shell.c:25697
u8 autoEQPtrace
Definition shell.c:21674
#define MODE_Tcl
Definition shell.c:21824
static void failIfSafeMode(ShellState *p, const char *zErrMsg,...)
Definition shell.c:21913
#define SHFLG_HeaderSet
Definition shell.c:21802
#define SEP_Space
Definition shell.c:21870
#define SHFLG_TestingMode
Definition shell.c:21805
#define MODE_Markdown
Definition shell.c:21831
#define MODE_Pretty
Definition shell.c:21828
static int booleanValue(const char *zArg)
Definition shell.c:26322
static void set_table_name(ShellState *p, const char *zName)
Definition shell.c:23382
#define SHELL_PROGRESS_RESET
Definition shell.c:21780
ColModeOpts cmOpts
Definition shell.c:21685
static int display_stats(sqlite3 *db, ShellState *pArg, int bReset)
Definition shell.c:23596
static int run_schema_dump_query(ShellState *p, const char *zQuery)
Definition shell.c:25236
unsigned flgProgress
Definition shell.c:21706
static void shell_out_of_memory(void)
Definition shell.c:969
#define SEP_CrLf
Definition shell.c:21872
static int intckDatabaseCmd(ShellState *pState, i64 nStepPerUnlock)
Definition shell.c:28480
char * zNonce
Definition shell.c:21738
u8 openMode
Definition shell.c:21676
int showHeader
Definition shell.c:21702
static char mainPrompt[128]
Definition shell.c:858
static void initText(ShellText *p)
Definition shell.c:1470
static sqlite3 * globalDb
Definition shell.c:839
static void output_reset(ShellState *p)
Definition shell.c:26864
FILE * in
Definition shell.c:21693
static void clearTempFile(ShellState *p)
Definition shell.c:27273
#define SEP_Column
Definition shell.c:21867
int nErr
Definition shell.c:26467
char colSeparator[20]
Definition shell.c:21713
#define SHELL_PROGRESS_ONCE
Definition shell.c:21781
#define session_close_all(X, Y)
Definition shell.c:25760
#define eputz(z)
Definition shell.c:633
#define MODE_Semi
Definition shell.c:21820
#define MODE_Ascii
Definition shell.c:21827
static int db_int(sqlite3 *db, const char *zSql,...)
Definition shell.c:26912
static char * ascii_read_one_field(ImportCtx *p)
Definition shell.c:26597
int openFlags
Definition shell.c:21692
#define IsDigit(X)
Definition shell.c:237
u8 crlfMode
Definition shell.c:21683
int nWidth
Definition shell.c:21719
Definition shell.c:21656
Definition shell.c:26458
Definition shell.c:21669
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
Definition sqlite3.c:2972
#define SQLITE_TESTCTRL_PARSER_COVERAGE
Definition sqlite3.c:8875
#define SQLITE_FCNTL_DATA_VERSION
Definition sqlite3.c:1578
#define SQLITE_FCNTL_SIZE_LIMIT
Definition sqlite3.c:1579
#define SQLITE_TESTCTRL_ALWAYS
Definition sqlite3.c:8858
#define SQLITE_API
Definition sqlite3.c:394
#define SQLITE_CDECL
Definition sqlite3.c:397
#define SQLITE_LIMIT_ATTACHED
Definition sqlite3.c:4648
#define SQLITE_DBCONFIG_ENABLE_COMMENTS
Definition sqlite3.c:2989
#define SQLITE_TESTCTRL_LOCALTIME_FAULT
Definition sqlite3.c:8866
#define SQLITE_TESTCTRL_IMPOSTER
Definition sqlite3.c:8874
#define SQLITE_DBCONFIG_DQS_DDL
Definition sqlite3.c:2981
#define SQLITE_LIMIT_COLUMN
Definition sqlite3.c:4643
#define SQLITE_BUSY
Definition sqlite3.c:771
#define SQLITE_DBCONFIG_ENABLE_TRIGGER
Definition sqlite3.c:2970
#define SQLITE_LIMIT_WORKER_THREADS
Definition sqlite3.c:4652
#define SQLITE_OPEN_READWRITE
Definition sqlite3.c:915
#define SQLITE_LIMIT_COMPOUND_SELECT
Definition sqlite3.c:4645
#define SQLITE_TESTCTRL_SORTER_MMAP
Definition sqlite3.c:8873
#define SQLITE_TESTCTRL_PRNG_SAVE
Definition sqlite3.c:8849
#define SQLITE_TESTCTRL_FK_NO_ACTION
Definition sqlite3.c:8852
#define SQLITE_LIMIT_FUNCTION_ARG
Definition sqlite3.c:4647
#define SQLITE_LIMIT_VDBE_OP
Definition sqlite3.c:4646
#define SQLITE_DBCONFIG_ENABLE_FKEY
Definition sqlite3.c:2969
#define SQLITE_TESTCTRL_PENDING_BYTE
Definition sqlite3.c:8856
#define SQLITE_TESTCTRL_PRNG_SEED
Definition sqlite3.c:8877
#define SQLITE_FCNTL_CHUNK_SIZE
Definition sqlite3.c:1550
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
Definition sqlite3.c:2971
#define SQLITE_LIMIT_SQL_LENGTH
Definition sqlite3.c:4642
#define SQLITE_LIMIT_EXPR_DEPTH
Definition sqlite3.c:4644
#define SQLITE_FCNTL_LOCK_TIMEOUT
Definition sqlite3.c:1577
#define SQLITE_TRACE_PROFILE
Definition sqlite3.c:3896
#define SQLITE_TESTCTRL_PRNG_RESTORE
Definition sqlite3.c:8850
#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS
Definition sqlite3.c:8878
#define SQLITE_TESTCTRL_NEVER_CORRUPT
Definition sqlite3.c:8869
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA
Definition sqlite3.c:2984
#define SQLITE_DBCONFIG_RESET_DATABASE
Definition sqlite3.c:2976
#define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE
Definition sqlite3.c:2987
#define SQLITE_DBCONFIG_DQS_DML
Definition sqlite3.c:2980
#define SQLITE_TESTCTRL_GETOPT
Definition sqlite3.c:8863
#define SQLITE_TRACE_ROW
Definition sqlite3.c:3897
#define SQLITE_TESTCTRL_ASSERT
Definition sqlite3.c:8857
#define SQLITE_TESTCTRL_OPTIMIZATIONS
Definition sqlite3.c:8861
#define SQLITE_DBCONFIG_ENABLE_QPSG
Definition sqlite3.c:2974
#define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE
Definition sqlite3.c:2988
#define SQLITE_TESTCTRL_JSON_SELFCHECK
Definition sqlite3.c:8860
#define SQLITE_FCNTL_POWERSAFE_OVERWRITE
Definition sqlite3.c:1557
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH
Definition sqlite3.c:4649
#define SQLITE_FCNTL_VFS_POINTER
Definition sqlite3.c:1570
#define SQLITE_FCNTL_HAS_MOVED
Definition sqlite3.c:1563
#define SQLITE_TESTCTRL_SEEK_COUNT
Definition sqlite3.c:8879
#define SQLITE_FCNTL_TEMPFILENAME
Definition sqlite3.c:1560
#define SQLITE_TESTCTRL_TUNE
Definition sqlite3.c:8881
#define SQLITE_DBCONFIG_STMT_SCANSTATUS
Definition sqlite3.c:2985
#define SQLITE_LOCKED
Definition sqlite3.c:772
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
Definition sqlite3.c:2979
#define SQLITE_LIMIT_TRIGGER_DEPTH
Definition sqlite3.c:4651
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
Definition sqlite3.c:2973
#define SQLITE_TXN_NONE
Definition sqlite3.c:7244
#define SQLITE_OPEN_NOFOLLOW
Definition sqlite3.c:934
#define SQLITE_DBCONFIG_REVERSE_SCANORDER
Definition sqlite3.c:2986
#define SQLITE_TRACE_CLOSE
Definition sqlite3.c:3898
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
Definition sqlite3.c:2983
#define SQLITE_LIMIT_VARIABLE_NUMBER
Definition sqlite3.c:4650
#define SQLITE_FCNTL_PERSIST_WAL
Definition sqlite3.c:1554
#define SQLITE_DBCONFIG_ENABLE_VIEW
Definition sqlite3.c:2982
#define SQLITE_FCNTL_RESERVE_BYTES
Definition sqlite3.c:1581
#define SQLITE_TRACE_STMT
Definition sqlite3.c:3895
#define SQLITE_TESTCTRL_FAULT_INSTALL
Definition sqlite3.c:8854
#define SQLITE_TESTCTRL_BYTEORDER
Definition sqlite3.c:8871
#define SQLITE_TXN_READ
Definition sqlite3.c:7245
#define SQLITE_DBCONFIG_TRIGGER_EQP
Definition sqlite3.c:2975
#define SQLITE_DONE
Definition sqlite3.c:796
#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
Definition sqlite3.c:8865
Definition sqlite3.c:18034
Definition sqlite3.c:83080
const char * zName
Definition sqlite3.c:1813
sqlite3_vfs * pNext
Definition sqlite3.c:1812
int iVersion
Definition sqlite3.c:1809
int mxPathname
Definition sqlite3.c:1811
#define sqlite3_open
Definition sqlite3ext.h:472
#define sqlite3_busy_timeout
Definition sqlite3ext.h:411
#define sqlite3_sourceid
Definition sqlite3ext.h:575
#define sqlite3_strglob
Definition sqlite3ext.h:611
#define sqlite3_realloc
Definition sqlite3ext.h:480
#define sqlite3_column_double
Definition sqlite3ext.h:424
#define sqlite3_drop_modules
Definition sqlite3ext.h:664
#define sqlite3_randomness
Definition sqlite3ext.h:554
#define sqlite3_set_authorizer
Definition sqlite3ext.h:495
#define sqlite3_backup_init
Definition sqlite3ext.h:562
#define sqlite3_load_extension
Definition sqlite3ext.h:604
#define sqlite3_open_v2
Definition sqlite3ext.h:541
#define sqlite3_get_autocommit
Definition sqlite3ext.h:460
#define sqlite3_libversion
Definition sqlite3ext.h:468
#define sqlite3_vfs_find
Definition sqlite3ext.h:547
#define sqlite3_backup_finish
Definition sqlite3ext.h:561
#define sqlite3_file_control
Definition sqlite3ext.h:533
#define sqlite3_backup_step
Definition sqlite3ext.h:565
#define sqlite3_sleep
Definition sqlite3ext.h:545
#define sqlite3_txn_state
Definition sqlite3ext.h:676
#define sqlite3_create_module
Definition sqlite3ext.h:444
#define sqlite3_db_readonly
Definition sqlite3ext.h:588
#define sqlite3_progress_handler
Definition sqlite3ext.h:479
#define sqlite3_trace_v2
Definition sqlite3ext.h:627

References ShellState::aAuxDb, ShellState::actualWidth, appendText(), ArraySize, ascii_read_one_field(), ShellState::autoEQP, AUTOEQP_full, AUTOEQP_on, AUTOEQP_trigger, ShellState::autoEQPtest, ShellState::autoEQPtrace, ShellState::autoExplain, bail_on_error, bind_prepared_stmt(), bind_table_init(), booleanValue(), ColModeOpts::bQuote, ShellState::bSafeMode, ShellState::bSafeModePersist, ColModeOpts::bWordWrap, c, callback(), captureOutputCallback(), ImportCtx::cColSep, clearTempFile(), cli_strcmp(), cli_strncmp(), close_db(), ShellState::cMode, ShellState::cmOpts, ColModeOpts_default, ColModeOpts_default_qbox, ShellState::colSeparator, ShellState::colWidth, continuePrompt, createSelftestTable(), ShellState::crlfMode, ImportCtx::cRowSep, csv_read_one_field(), ImportCtx::cTerm, CTIMEOPT_VAL, ShellState::AuxDb::db, ShellState::db, db_int(), display_stats(), ShellState::doXdgOpen, ShellState::eEscMode, enableTimer, eputz, ShellState::eTraceType, ShellState::expert, expertDotCommand(), expertFinish(), failIfSafeMode(), faultsim_callback(), faultsim_state, ShellState::flgProgress, freeText(), globalDb, HAS_TIMER, import_append_char(), import_cleanup(), ImportCtx::in, ShellState::in, initText(), intckDatabaseCmd(), integerValue(), IsDigit, IsSpace, sqlite3_vfs::iVersion, ColModeOpts::iWrap, ShellState::lineno, lintDotCommand(), mainPrompt, ShellState::mode, MODE_Ascii, MODE_Box, MODE_Column, MODE_Count, MODE_Csv, MODE_Explain, MODE_Html, MODE_Insert, MODE_Json, MODE_Line, MODE_List, MODE_Markdown, MODE_Off, MODE_Pretty, MODE_Quote, MODE_Semi, MODE_Table, MODE_Tcl, MODE_Www, modeDescr, sqlite3_vfs::mxPathname, ShellState::mxProgress, ShellText::n, ShellState::nCheck, ImportCtx::nErr, ShellState::nErr, newTempFile(), ImportCtx::nLine, ShellState::normalMode, ShellState::nProgress, ImportCtx::nRow, ShellState::nullValue, ShellState::nWidth, open_db(), OPEN_DB_KEEPALIVE, openChrSource(), ShellState::openFlags, ShellState::openMode, optionMatch(), ShellState::out, ShellState::outCount, ShellState::outfile, output_c_string(), output_file_close(), output_file_open(), output_redir(), output_reset(), outputDumpWarning(), outputModePush(), ShellState::pAuxDb, pclose(), ExpertInfo::pExpert, ShellState::pLog, sqlite3_vfs::pNext, process_input(), progress_handler(), quoteChar(), readFile(), resolve_backslashes(), ShellState::rowSeparator, run_schema_dump_query(), run_table_dump_query(), safeModeAuth(), ShellState::scanstatsOn, seenInterrupt, SEP_Column, SEP_Comma, SEP_CrLf, SEP_Record, SEP_Row, SEP_Space, SEP_Tab, SEP_Unit, session_close_all, set_table_name(), setOrClearFlag(), shell_check_oom(), shell_dbtotxt_command(), SHELL_ESC_OFF, shell_EscModeNames, shell_exec(), SHELL_OPEN_APPENDVFS, SHELL_OPEN_DESERIALIZE, SHELL_OPEN_HEXDB, SHELL_OPEN_READONLY, SHELL_OPEN_UNSPEC, SHELL_OPEN_ZIPFILE, shell_out_of_memory(), SHELL_PROGRESS_ONCE, SHELL_PROGRESS_QUIET, SHELL_PROGRESS_RESET, shell_strncpy(), SHELL_TRACE_EXPANDED, SHELL_TRACE_NORMALIZED, SHELL_TRACE_PLAIN, shellAuth(), ShellClearFlag, shellDatabaseError(), shellDeleteFile(), shellEmitError(), ShellState::shellFlgs, ShellHasFlag, ShellSetFlag, SHFLG_CountChanges, SHFLG_DumpDataOnly, SHFLG_DumpNoSys, SHFLG_Echo, SHFLG_HeaderSet, SHFLG_Newlines, SHFLG_PreserveRowid, SHFLG_TestingMode, ShellState::showHeader, showHelp(), sputz, sql_trace_callback(), sqlite3_backup_finish, sqlite3_backup_init, sqlite3_backup_step, sqlite3_bind_null, sqlite3_bind_text, sqlite3_busy_timeout, sqlite3_column_double, sqlite3_column_int, sqlite3_column_text, sqlite3_create_module, sqlite3_db_config, sqlite3_db_readonly, sqlite3_drop_modules, sqlite3_errmsg, sqlite3_exec, sqlite3_file_control, sqlite3_finalize, sqlite3_fopen, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_get_autocommit, sqlite3_libversion, sqlite3_limit, sqlite3_load_extension, sqlite3_malloc, sqlite3_malloc64, sqlite3_mprintf, sqlite3_open, sqlite3_open_v2, sqlite3_popen, sqlite3_prepare_v2, sqlite3_progress_handler, sqlite3_randomness, sqlite3_realloc, sqlite3_realloc64, sqlite3_reset, sqlite3_set_authorizer, sqlite3_sleep, sqlite3_snprintf, sqlite3_sourceid, sqlite3_step, sqlite3_strglob, sqlite3_stricmp, sqlite3_strlike, sqlite3_strnicmp, sqlite3_table_column_metadata, sqlite3_test_control, sqlite3_trace_v2, sqlite3_txn_state, sqlite3_vfs_find, SQLITE_API, SQLITE_BUSY, SQLITE_CDECL, SQLITE_DBCONFIG_DEFENSIVE, SQLITE_DBCONFIG_DQS_DDL, SQLITE_DBCONFIG_DQS_DML, SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE, SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE, SQLITE_DBCONFIG_ENABLE_COMMENTS, SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_DBCONFIG_ENABLE_VIEW, SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, SQLITE_DBCONFIG_LEGACY_FILE_FORMAT, SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_DBCONFIG_RESET_DATABASE, SQLITE_DBCONFIG_REVERSE_SCANORDER, SQLITE_DBCONFIG_STMT_SCANSTATUS, SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_DBCONFIG_TRUSTED_SCHEMA, SQLITE_DBCONFIG_WRITABLE_SCHEMA, SQLITE_DONE, SQLITE_FCNTL_CHUNK_SIZE, SQLITE_FCNTL_DATA_VERSION, SQLITE_FCNTL_HAS_MOVED, SQLITE_FCNTL_LOCK_TIMEOUT, SQLITE_FCNTL_PERSIST_WAL, SQLITE_FCNTL_POWERSAFE_OVERWRITE, SQLITE_FCNTL_RESERVE_BYTES, SQLITE_FCNTL_SIZE_LIMIT, SQLITE_FCNTL_TEMPFILENAME, SQLITE_FCNTL_VFS_POINTER, SQLITE_FCNTL_VFSNAME, SQLITE_LIMIT_ATTACHED, SQLITE_LIMIT_COLUMN, SQLITE_LIMIT_COMPOUND_SELECT, SQLITE_LIMIT_EXPR_DEPTH, SQLITE_LIMIT_FUNCTION_ARG, SQLITE_LIMIT_LENGTH, SQLITE_LIMIT_LIKE_PATTERN_LENGTH, SQLITE_LIMIT_SQL_LENGTH, SQLITE_LIMIT_TRIGGER_DEPTH, SQLITE_LIMIT_VARIABLE_NUMBER, SQLITE_LIMIT_VDBE_OP, SQLITE_LIMIT_WORKER_THREADS, SQLITE_LOCKED, SQLITE_OK, SQLITE_OPEN_CREATE, SQLITE_OPEN_NOFOLLOW, SQLITE_OPEN_READWRITE, SQLITE_ROW, SQLITE_STATIC, SQLITE_TESTCTRL_ALWAYS, SQLITE_TESTCTRL_ASSERT, SQLITE_TESTCTRL_BYTEORDER, SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, SQLITE_TESTCTRL_FAULT_INSTALL, SQLITE_TESTCTRL_FK_NO_ACTION, SQLITE_TESTCTRL_GETOPT, SQLITE_TESTCTRL_IMPOSTER, SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, SQLITE_TESTCTRL_JSON_SELFCHECK, SQLITE_TESTCTRL_LOCALTIME_FAULT, SQLITE_TESTCTRL_NEVER_CORRUPT, SQLITE_TESTCTRL_OPTIMIZATIONS, SQLITE_TESTCTRL_PARSER_COVERAGE, SQLITE_TESTCTRL_PENDING_BYTE, SQLITE_TESTCTRL_PRNG_RESTORE, SQLITE_TESTCTRL_PRNG_SAVE, SQLITE_TESTCTRL_PRNG_SEED, SQLITE_TESTCTRL_SEEK_COUNT, SQLITE_TESTCTRL_SORTER_MMAP, SQLITE_TESTCTRL_TRACEFLAGS, SQLITE_TESTCTRL_TUNE, SQLITE_TRACE_CLOSE, SQLITE_TRACE_PROFILE, SQLITE_TRACE_ROW, SQLITE_TRACE_STMT, SQLITE_TRANSIENT, SQLITE_TXN_NONE, SQLITE_TXN_READ, ShellState::statsOn, stdin_is_interactive, strlen30(), ShellState::szMax, sqlite3_vfs::szOsFile, test_breakpoint(), testcase_glob(), ShellState::traceOut, tryToClone(), ShellState::writableSchema, ImportCtx::xCloser, ImportCtx::z, ShellText::z, zAutoColumn(), ShellState::AuxDb::zDbFilename, ShellState::zDestTable, ImportCtx::zFile, ShellState::AuxDb::zFreeOnClose, sqlite3_vfs::zName, ShellState::zNonce, ShellState::zTempFile, and ShellState::zTestcase.

Referenced by main(), and process_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doAutoDetectRestore()

int doAutoDetectRestore ( ShellState * p,
const char * zSql )
static
32600 : Nothing left to do. This function becomes a no-op.
32601*/
32602static int doAutoDetectRestore(ShellState *p, const char *zSql){
32603 int rc = SQLITE_OK;
32604
32605 if( p->eRestoreState<7 ){
32606 switch( p->eRestoreState ){
32607 case 0: {
32608 const char *zExpect = "PRAGMA foreign_keys=OFF;";
32609 assert( strlen(zExpect)==24 );
32610 if( p->bSafeMode==0
32611 && strlen(zSql)>=24
32612 && memcmp(zSql, zExpect, 25)==0
32613 ){
32614 p->eRestoreState = 1;
32615 }else{
32616 p->eRestoreState = 7;
32617 }
32618 break;
32619 };
32620
32621 case 1: {
32622 int bIsDump = 0;
32623 const char *zExpect = "BEGIN TRANSACTION;";
32624 assert( strlen(zExpect)==18 );
32625 if( memcmp(zSql, zExpect, 19)==0 ){
32626 /* Now check if the database is empty. */
32627 const char *zQuery = "SELECT 1 FROM sqlite_schema LIMIT 1";
32628 sqlite3_stmt *pStmt = 0;
32629
32630 bIsDump = 1;
32631 shellPrepare(p->db, &rc, zQuery, &pStmt);
32632 if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
32633 bIsDump = 0;
32634 }
32635 shellFinalize(&rc, pStmt);
32636 }
32637 if( bIsDump && rc==SQLITE_OK ){
32638 int bDefense = 0;
32639 int bDqsDdl = 0;
32641 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, -1, &bDqsDdl);
32644 p->eRestoreState = (bDefense ? 2 : 0) + (bDqsDdl ? 4 : 0);
32645 }else{
32646 p->eRestoreState = 7;
32647 }
32648 break;
32649 }
32650
32651 default: {
32652 if( sqlite3_get_autocommit(p->db) ){
32653 if( (p->eRestoreState & 2) ){
32655 }
32656 if( (p->eRestoreState & 4) ){
32658 }
32659 p->eRestoreState = 7;
32660 }
32661 break;
32662 }
32663 }
32664 }
32665
u8 eRestoreState
Definition shell.c:21682
static void shellFinalize(int *pRc, sqlite3_stmt *pStmt)
Definition shell.c:27609
static int doAutoDetectRestore(ShellState *p, const char *zSql)
Definition shell.c:32600
static void shellPrepare(sqlite3 *db, int *pRc, const char *zSql, sqlite3_stmt **ppStmt)
Definition shell.c:27563

References ShellState::bSafeMode, ShellState::db, ShellState::eRestoreState, shellFinalize(), shellPrepare(), sqlite3_db_config, sqlite3_get_autocommit, sqlite3_step, SQLITE_DBCONFIG_DEFENSIVE, SQLITE_DBCONFIG_DQS_DDL, SQLITE_OK, and SQLITE_ROW.

Referenced by runOneSqlLine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dummyCompare()

int dummyCompare ( void * up1,
int up2,
const void * up3,
int up4,
const void * up5 )
14660 {
14661 (void)up1;
14662 (void)up2;
14663 (void)up3;
14664 (void)up4;
14665 (void)up5;
14666 assert(0); /* VDBE should never be run. */
14667 return 0;
14668}

Referenced by useDummyCS().

Here is the caller graph for this function:

◆ dummyUDF()

void dummyUDF ( sqlite3_context * up1,
int up2,
sqlite3_value ** up3 )
14680 {
14681 (void)up1;
14682 (void)up2;
14683 (void)up3;
14684 assert(0); /* VDBE should never be run. */
14685}

Referenced by registerUDFs().

Here is the caller graph for this function:

◆ dummyUDFvalue()

void dummyUDFvalue ( sqlite3_context * up1)
14686 {
14687 (void)up1;
14688 assert(0); /* VDBE should never be run. */
14689}

Referenced by registerUDFs().

Here is the caller graph for this function:

◆ dump_callback()

int dump_callback ( void * pArg,
int nArg,
char ** azArg,
char ** azNotUsed )
static
25117 {
25118 int rc;
25119 const char *zTable;
25120 const char *zType;
25121 const char *zSql;
25122 ShellState *p = (ShellState *)pArg;
25123 int dataOnly;
25124 int noSys;
25125
25126 UNUSED_PARAMETER(azNotUsed);
25127 if( nArg!=3 || azArg==0 ) return 0;
25128 zTable = azArg[0];
25129 zType = azArg[1];
25130 zSql = azArg[2];
25131 if( zTable==0 ) return 0;
25132 if( zType==0 ) return 0;
25133 dataOnly = (p->shellFlgs & SHFLG_DumpDataOnly)!=0;
25134 noSys = (p->shellFlgs & SHFLG_DumpNoSys)!=0;
25135
25136 if( cli_strcmp(zTable, "sqlite_sequence")==0 && !noSys ){
25137 /* no-op */
25138 }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 && !noSys ){
25139 if( !dataOnly ) sqlite3_fputs("ANALYZE sqlite_schema;\n", p->out);
25140 }else if( cli_strncmp(zTable, "sqlite_", 7)==0 ){
25141 return 0;
25142 }else if( dataOnly ){
25143 /* no-op */
25144 }else if( cli_strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
25145 char *zIns;
25146 if( !p->writableSchema ){
25147 sqlite3_fputs("PRAGMA writable_schema=ON;\n", p->out);
25148 p->writableSchema = 1;
25149 }
25150 zIns = sqlite3_mprintf(
25151 "INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)"
25152 "VALUES('table','%q','%q',0,'%q');",
25153 zTable, zTable, zSql);
25154 shell_check_oom(zIns);
25155 sqlite3_fprintf(p->out, "%s\n", zIns);
25156 sqlite3_free(zIns);
25157 return 0;
25158 }else{
25159 printSchemaLine(p->out, zSql, ";\n");
25160 }
25161
25162 if( cli_strcmp(zType, "table")==0 ){
25163 ShellText sSelect;
25164 ShellText sTable;
25165 char **azCol;
25166 int i;
25167 char *savedDestTable;
25168 int savedMode;
25169
25170 azCol = tableColumnList(p, zTable);
25171 if( azCol==0 ){
25172 p->nErr++;
25173 return 0;
25174 }
25175
25176 /* Always quote the table name, even if it appears to be pure ascii,
25177 ** in case it is a keyword. Ex: INSERT INTO "table" ... */
25178 initText(&sTable);
25179 appendText(&sTable, zTable, quoteChar(zTable));
25180 /* If preserving the rowid, add a column list after the table name.
25181 ** In other words: "INSERT INTO tab(rowid,a,b,c,...) VALUES(...)"
25182 ** instead of the usual "INSERT INTO tab VALUES(...)".
25183 */
25184 if( azCol[0] ){
25185 appendText(&sTable, "(", 0);
25186 appendText(&sTable, azCol[0], 0);
25187 for(i=1; azCol[i]; i++){
25188 appendText(&sTable, ",", 0);
25189 appendText(&sTable, azCol[i], quoteChar(azCol[i]));
25190 }
25191 appendText(&sTable, ")", 0);
25192 }
25193
25194 /* Build an appropriate SELECT statement */
25195 initText(&sSelect);
25196 appendText(&sSelect, "SELECT ", 0);
25197 if( azCol[0] ){
25198 appendText(&sSelect, azCol[0], 0);
25199 appendText(&sSelect, ",", 0);
25200 }
25201 for(i=1; azCol[i]; i++){
25202 appendText(&sSelect, azCol[i], quoteChar(azCol[i]));
25203 if( azCol[i+1] ){
25204 appendText(&sSelect, ",", 0);
25205 }
25206 }
25207 freeColumnList(azCol);
25208 appendText(&sSelect, " FROM ", 0);
25209 appendText(&sSelect, zTable, quoteChar(zTable));
25210
25211 savedDestTable = p->zDestTable;
25212 savedMode = p->mode;
25213 p->zDestTable = sTable.z;
25214 p->mode = p->cMode = MODE_Insert;
25215 rc = shell_exec(p, sSelect.z, 0);
25216 if( (rc&0xff)==SQLITE_CORRUPT ){
25217 sqlite3_fputs("/****** CORRUPTION ERROR *******/\n", p->out);
25219 shell_exec(p, sSelect.z, 0);
25221 }
25222 p->zDestTable = savedDestTable;
25223 p->mode = savedMode;
25224 freeText(&sTable);
25225 freeText(&sSelect);
25226 if( rc ) p->nErr++;
25227 }
static char ** tableColumnList(ShellState *p, const char *zTab)
Definition shell.c:25001
static void toggleSelectOrder(sqlite3 *db)
Definition shell.c:25095
static void printSchemaLine(FILE *out, const char *z, const char *zTail)
Definition shell.c:22675
static void freeColumnList(char **azCol)
Definition shell.c:24979
#define SQLITE_CORRUPT
Definition sqlite3.c:777

References appendText(), cli_strcmp(), cli_strncmp(), ShellState::cMode, ShellState::db, freeColumnList(), freeText(), initText(), ShellState::mode, MODE_Insert, ShellState::nErr, ShellState::out, printSchemaLine(), quoteChar(), shell_check_oom(), shell_exec(), ShellState::shellFlgs, SHFLG_DumpDataOnly, SHFLG_DumpNoSys, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_mprintf, sqlite3_strglob, SQLITE_CORRUPT, tableColumnList(), toggleSelectOrder(), UNUSED_PARAMETER, ShellState::writableSchema, ShellText::z, and ShellState::zDestTable.

Referenced by run_schema_dump_query().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dynamicContinuePrompt()

char * dynamicContinuePrompt ( void )
static
938 {
939 if( continuePrompt[0]==0
940 || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
941 return continuePrompt;
942 }else{
943 if( dynPrompt.zScannerAwaits ){
944 size_t ncp = strlen(continuePrompt);
945 size_t ndp = strlen(dynPrompt.zScannerAwaits);
946 if( ndp > ncp-3 ) return continuePrompt;
947 shell_strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
948 while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
949 shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
951 }else{
952 if( dynPrompt.inParenLevel>9 ){
953 shell_strncpy(dynPrompt.dynamicPrompt, "(..", 4);
954 }else if( dynPrompt.inParenLevel<0 ){
955 shell_strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
956 }else{
957 shell_strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
958 dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
959 }
960 shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
962 }
963 }
964 return dynPrompt.dynamicPrompt;
965}
static struct DynaPrompt dynPrompt
static void shell_strcpy(char *dest, const char *src)
Definition shell.c:878
#define PROMPT_LEN_MAX
Definition shell.c:856

References continuePrompt, dynPrompt, PROMPT_LEN_MAX, shell_strcpy(), and shell_strncpy().

Here is the call graph for this function:

◆ echo_group_input()

void echo_group_input ( ShellState * p,
const char * zDo )
static
32721 {
32722 if( ShellHasFlag(p, SHFLG_Echo) ){
32723 sqlite3_fprintf(p->out, "%s\n", zDo);
32724 fflush(p->out);

Referenced by main(), and process_input().

Here is the caller graph for this function:

◆ editFunc()

void editFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
21952 {
21953 const char *zEditor;
21954 char *zTempFile = 0;
21955 sqlite3 *db;
21956 char *zCmd = 0;
21957 int bBin;
21958 int rc;
21959 int hasCRLF = 0;
21960 FILE *f = 0;
21961 sqlite3_int64 sz;
21962 sqlite3_int64 x;
21963 unsigned char *p = 0;
21964
21965 if( argc==2 ){
21966 zEditor = (const char*)sqlite3_value_text(argv[1]);
21967 }else{
21968 zEditor = getenv("VISUAL");
21969 }
21970 if( zEditor==0 ){
21971 sqlite3_result_error(context, "no editor for edit()", -1);
21972 return;
21973 }
21974 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
21975 sqlite3_result_error(context, "NULL input to edit()", -1);
21976 return;
21977 }
21978 db = sqlite3_context_db_handle(context);
21979 zTempFile = 0;
21981 if( zTempFile==0 ){
21982 sqlite3_uint64 r = 0;
21983 sqlite3_randomness(sizeof(r), &r);
21984 zTempFile = sqlite3_mprintf("temp%llx", r);
21985 if( zTempFile==0 ){
21987 return;
21988 }
21989 }
21990 bBin = sqlite3_value_type(argv[0])==SQLITE_BLOB;
21991 /* When writing the file to be edited, do \n to \r\n conversions on systems
21992 ** that want \r\n line endings */
21993 f = sqlite3_fopen(zTempFile, bBin ? "wb" : "w");
21994 if( f==0 ){
21995 sqlite3_result_error(context, "edit() cannot open temp file", -1);
21996 goto edit_func_end;
21997 }
21998 sz = sqlite3_value_bytes(argv[0]);
21999 if( bBin ){
22000 x = fwrite(sqlite3_value_blob(argv[0]), 1, (size_t)sz, f);
22001 }else{
22002 const char *z = (const char*)sqlite3_value_text(argv[0]);
22003 /* Remember whether or not the value originally contained \r\n */
22004 if( z && strstr(z,"\r\n")!=0 ) hasCRLF = 1;
22005 x = fwrite(sqlite3_value_text(argv[0]), 1, (size_t)sz, f);
22006 }
22007 fclose(f);
22008 f = 0;
22009 if( x!=sz ){
22010 sqlite3_result_error(context, "edit() could not write the whole file", -1);
22011 goto edit_func_end;
22012 }
22013 zCmd = sqlite3_mprintf("%s \"%s\"", zEditor, zTempFile);
22014 if( zCmd==0 ){
22016 goto edit_func_end;
22017 }
22018 rc = system(zCmd);
22019 sqlite3_free(zCmd);
22020 if( rc ){
22021 sqlite3_result_error(context, "EDITOR returned non-zero", -1);
22022 goto edit_func_end;
22023 }
22024 f = sqlite3_fopen(zTempFile, "rb");
22025 if( f==0 ){
22026 sqlite3_result_error(context,
22027 "edit() cannot reopen temp file after edit", -1);
22028 goto edit_func_end;
22029 }
22030 fseek(f, 0, SEEK_END);
22031 sz = ftell(f);
22032 rewind(f);
22033 p = sqlite3_malloc64( sz+1 );
22034 if( p==0 ){
22036 goto edit_func_end;
22037 }
22038 x = fread(p, 1, (size_t)sz, f);
22039 fclose(f);
22040 f = 0;
22041 if( x!=sz ){
22042 sqlite3_result_error(context, "could not read back the whole file", -1);
22043 goto edit_func_end;
22044 }
22045 if( bBin ){
22046 sqlite3_result_blob64(context, p, sz, sqlite3_free);
22047 }else{
22048 sqlite3_int64 i, j;
22049 if( hasCRLF ){
22050 /* If the original contains \r\n then do no conversions back to \n */
22051 }else{
22052 /* If the file did not originally contain \r\n then convert any new
22053 ** \r\n back into \n */
22054 p[sz] = 0;
22055 for(i=j=0; i<sz; i++){
22056 if( p[i]=='\r' && p[i+1]=='\n' ) i++;
22057 p[j++] = p[i];
22058 }
22059 sz = j;
22060 p[sz] = 0;
22061 }
22062 sqlite3_result_text64(context, (const char*)p, sz,
22064 }
22065 p = 0;
22066
22067edit_func_end:
22068 if( f ) fclose(f);
22069 unlink(zTempFile);
22070 sqlite3_free(zTempFile);
#define sqlite3_result_text64
Definition sqlite3ext.h:610
#define sqlite3_result_blob64
Definition sqlite3ext.h:609

References sqlite3_context_db_handle, sqlite3_file_control, sqlite3_fopen, sqlite3_free, sqlite3_malloc64, sqlite3_mprintf, sqlite3_randomness, sqlite3_result_blob64, sqlite3_result_error, sqlite3_result_error_nomem, sqlite3_result_text64, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_text, sqlite3_value_type, SQLITE_BLOB, SQLITE_FCNTL_TEMPFILENAME, SQLITE_NULL, and SQLITE_UTF8.

Referenced by open_db().

Here is the caller graph for this function:

◆ endTimer()

void endTimer ( FILE * out)
static
704 {
705 if( enableTimer ){
706 sqlite3_int64 iEnd = timeOfDay();
707 struct rusage sEnd;
708 getrusage(RUSAGE_SELF, &sEnd);
709 sqlite3_fprintf(out, "Run Time: real %.3f user %f sys %f\n",
710 (iEnd - iBegin)*0.001,
711 timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
712 timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
713 }
714}
static double timeDiff(struct timeval *pStart, struct timeval *pEnd)
Definition shell.c:696

References enableTimer, iBegin, sBegin, sqlite3_fprintf, timeDiff(), and timeOfDay().

Here is the call graph for this function:

◆ eqp_append()

void eqp_append ( ShellState * p,
int iEqpId,
int p2,
const char * zText )
static
22730 {
22731 EQPGraphRow *pNew;
22732 i64 nText;
22733 if( zText==0 ) return;
22734 nText = strlen(zText);
22735 if( p->autoEQPtest ){
22736 sqlite3_fprintf(p->out, "%d,%d,%s\n", iEqpId, p2, zText);
22737 }
22738 pNew = sqlite3_malloc64( sizeof(*pNew) + nText );
22739 shell_check_oom(pNew);
22740 pNew->iEqpId = iEqpId;
22741 pNew->iParentId = p2;
22742 memcpy(pNew->zText, zText, nText+1);
22743 pNew->pNext = 0;
22744 if( p->sGraph.pLast ){
22745 p->sGraph.pLast->pNext = pNew;
22746 }else{
22747 p->sGraph.pRow = pNew;
22748 }
int iParentId
Definition shell.c:21642
EQPGraphRow * pLast
Definition shell.c:21651
int iEqpId
Definition shell.c:21641
EQPGraphRow * pNext
Definition shell.c:21643
char zText[1]
Definition shell.c:21644
EQPGraph sGraph
Definition shell.c:21739
EQPGraphRow * pRow
Definition shell.c:21650
Definition shell.c:21640

References ShellState::autoEQPtest, EQPGraphRow::iEqpId, EQPGraphRow::iParentId, ShellState::out, EQPGraph::pLast, EQPGraphRow::pNext, EQPGraph::pRow, ShellState::sGraph, shell_check_oom(), sqlite3_fprintf, sqlite3_malloc64, and EQPGraphRow::zText.

Referenced by shell_callback(), and shell_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eqp_next_row()

EQPGraphRow * eqp_next_row ( ShellState * p,
int iEqpId,
EQPGraphRow * pOld )
static
22768 {
22769 EQPGraphRow *pRow = pOld ? pOld->pNext : p->sGraph.pRow;
22770 while( pRow && pRow->iParentId!=iEqpId ) pRow = pRow->pNext;

References EQPGraphRow::iParentId, EQPGraphRow::pNext, EQPGraph::pRow, and ShellState::sGraph.

Referenced by eqp_render_level().

Here is the caller graph for this function:

◆ eqp_render()

void eqp_render ( ShellState * p,
i64 nCycle )
static
22797 {
22798 EQPGraphRow *pRow = p->sGraph.pRow;
22799 if( pRow ){
22800 if( pRow->zText[0]=='-' ){
22801 if( pRow->pNext==0 ){
22802 eqp_reset(p);
22803 return;
22804 }
22805 sqlite3_fprintf(p->out, "%s\n", pRow->zText+3);
22806 p->sGraph.pRow = pRow->pNext;
22807 sqlite3_free(pRow);
22808 }else if( nCycle>0 ){
22809 sqlite3_fprintf(p->out, "QUERY PLAN (cycles=%lld [100%%])\n", nCycle);
22810 }else{
22811 sqlite3_fputs("QUERY PLAN\n", p->out);
22812 }
22813 p->sGraph.zPrefix[0] = 0;
22814 eqp_render_level(p, 0);
22815 eqp_reset(p);
char zPrefix[100]
Definition shell.c:21652
static void eqp_render_level(ShellState *p, int iEqpId)
Definition shell.c:22775
static void eqp_reset(ShellState *p)
Definition shell.c:22754

References eqp_render_level(), eqp_reset(), ShellState::out, EQPGraphRow::pNext, EQPGraph::pRow, ShellState::sGraph, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, EQPGraph::zPrefix, and EQPGraphRow::zText.

Referenced by shell_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eqp_render_level()

void eqp_render_level ( ShellState * p,
int iEqpId )
static
22777 {
22778 EQPGraphRow *pRow, *pNext;
22779 i64 n = strlen(p->sGraph.zPrefix);
22780 char *z;
22781 for(pRow = eqp_next_row(p, iEqpId, 0); pRow; pRow = pNext){
22782 pNext = eqp_next_row(p, iEqpId, pRow);
22783 z = pRow->zText;
22784 sqlite3_fprintf(p->out, "%s%s%s\n", p->sGraph.zPrefix,
22785 pNext ? "|--" : "`--", z);
22786 if( n<(i64)sizeof(p->sGraph.zPrefix)-7 ){
22787 memcpy(&p->sGraph.zPrefix[n], pNext ? "| " : " ", 4);
22788 eqp_render_level(p, pRow->iEqpId);
22789 p->sGraph.zPrefix[n] = 0;
22790 }
static EQPGraphRow * eqp_next_row(ShellState *p, int iEqpId, EQPGraphRow *pOld)
Definition shell.c:22766

References eqp_next_row(), eqp_render_level(), EQPGraphRow::iEqpId, ShellState::out, ShellState::sGraph, sqlite3_fprintf, EQPGraph::zPrefix, and EQPGraphRow::zText.

Referenced by eqp_render(), and eqp_render_level().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eqp_reset()

void eqp_reset ( ShellState * p)
static
22756 {
22757 EQPGraphRow *pRow, *pNext;
22758 for(pRow = p->sGraph.pRow; pRow; pRow = pNext){
22759 pNext = pRow->pNext;
22760 sqlite3_free(pRow);
22761 }

References EQPGraphRow::pNext, EQPGraph::pRow, ShellState::sGraph, and sqlite3_free.

Referenced by eqp_render().

Here is the caller graph for this function:

◆ escapeOutput()

const char * escapeOutput ( ShellState * p,
const char * zInX,
char ** ppFree )
static
22392 {
22393 i64 i, j;
22394 i64 nCtrl = 0;
22395 unsigned char *zIn;
22396 unsigned char c;
22397 unsigned char *zOut;
22398
22399
22400 /* No escaping if disabled */
22401 if( p->eEscMode==SHELL_ESC_OFF ){
22402 *ppFree = 0;
22403 return zInX;
22404 }
22405
22406 /* Count the number of control characters in the string. */
22407 zIn = (unsigned char*)zInX;
22408 for(i=0; (c = zIn[i])!=0; i++){
22409 if( c<=0x1f
22410 && c!='\t'
22411 && c!='\n'
22412 && (c!='\r' || zIn[i+1]!='\n')
22413 ){
22414 nCtrl++;
22415 }
22416 }
22417 if( nCtrl==0 ){
22418 *ppFree = 0;
22419 return zInX;
22420 }
22421 if( p->eEscMode==SHELL_ESC_SYMBOL ) nCtrl *= 2;
22422 zOut = sqlite3_malloc64( i + nCtrl + 1 );
22423 shell_check_oom(zOut);
22424 for(i=j=0; (c = zIn[i])!=0; i++){
22425 if( c>0x1f
22426 || c=='\t'
22427 || c=='\n'
22428 || (c=='\r' && zIn[i+1]=='\n')
22429 ){
22430 continue;
22431 }
22432 if( i>0 ){
22433 memcpy(&zOut[j], zIn, i);
22434 j += i;
22435 }
22436 zIn += i+1;
22437 i = -1;
22438 switch( p->eEscMode ){
22439 case SHELL_ESC_SYMBOL:
22440 zOut[j++] = 0xe2;
22441 zOut[j++] = 0x90;
22442 zOut[j++] = 0x80+c;
22443 break;
22444 case SHELL_ESC_ASCII:
22445 zOut[j++] = '^';
22446 zOut[j++] = 0x40+c;
22447 break;
22448 }
22449 }
22450 if( i>0 ){
22451 memcpy(&zOut[j], zIn, i);
22452 j += i;
22453 }
22454 zOut[j] = 0;
22455 *ppFree = (char*)zOut;
#define SHELL_ESC_SYMBOL
Definition shell.c:21787
#define SHELL_ESC_ASCII
Definition shell.c:21786

References c, ShellState::eEscMode, shell_check_oom(), SHELL_ESC_ASCII, SHELL_ESC_OFF, SHELL_ESC_SYMBOL, and sqlite3_malloc64.

Referenced by shell_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec_prepared_stmt()

void exec_prepared_stmt ( ShellState * pArg,
sqlite3_stmt * pStmt )
static
24610 {
24611 int rc;
24612 sqlite3_uint64 nRow = 0;
24613
24614 if( pArg->cMode==MODE_Column
24615 || pArg->cMode==MODE_Table
24616 || pArg->cMode==MODE_Box
24617 || pArg->cMode==MODE_Markdown
24618 ){
24619 exec_prepared_stmt_columnar(pArg, pStmt);
24620 return;
24621 }
24622
24623 /* perform the first step. this will tell us if we
24624 ** have a result set or not and how wide it is.
24625 */
24626 rc = sqlite3_step(pStmt);
24627 /* if we have a result set... */
24628 if( SQLITE_ROW == rc ){
24629 /* allocate space for col name ptr, value ptr, and type */
24630 int nCol = sqlite3_column_count(pStmt);
24631 void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
24632 if( !pData ){
24634 }else{
24635 char **azCols = (char **)pData; /* Names of result columns */
24636 char **azVals = &azCols[nCol]; /* Results */
24637 int *aiTypes = (int *)&azVals[nCol]; /* Result types */
24638 int i, x;
24639 assert(sizeof(int) <= sizeof(char *));
24640 /* save off ptrs to column names */
24641 for(i=0; i<nCol; i++){
24642 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
24643 }
24644 do{
24645 nRow++;
24646 /* extract the data and data types */
24647 for(i=0; i<nCol; i++){
24648 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
24649 if( x==SQLITE_BLOB
24650 && pArg
24651 && (pArg->cMode==MODE_Insert || pArg->cMode==MODE_Quote)
24652 ){
24653 azVals[i] = "";
24654 }else{
24655 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
24656 }
24657 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
24658 rc = SQLITE_NOMEM;
24659 break; /* from for */
24660 }
24661 } /* end for */
24662
24663 /* if data and types extracted successfully... */
24664 if( SQLITE_ROW == rc ){
24665 /* call the supplied callback with the result row data */
24666 if( shell_callback(pArg, nCol, azVals, azCols, aiTypes) ){
24667 rc = SQLITE_ABORT;
24668 }else{
24669 rc = sqlite3_step(pStmt);
24670 }
24671 }
24672 } while( SQLITE_ROW == rc );
24673 sqlite3_free(pData);
24674 if( pArg->cMode==MODE_Json ){
24675 sqlite3_fputs("]\n", pArg->out);
24676 }else if( pArg->cMode==MODE_Www ){
24677 sqlite3_fputs("</TABLE>\n<PRE>\n", pArg->out);
24678 }else if( pArg->cMode==MODE_Count ){
24679 char zBuf[200];
24680 sqlite3_snprintf(sizeof(zBuf), zBuf, "%llu row%s\n",
24681 nRow, nRow!=1 ? "s" : "");
24682 printf("%s", zBuf);
24683 }
24684 }
static void exec_prepared_stmt_columnar(ShellState *p, sqlite3_stmt *pStmt)
Definition shell.c:24376
static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int *aiType)
Definition shell.c:22875
#define SQLITE_ABORT
Definition sqlite3.c:770
#define sqlite3_column_type
Definition sqlite3ext.h:435

References ShellState::cMode, exec_prepared_stmt_columnar(), MODE_Box, MODE_Column, MODE_Count, MODE_Insert, MODE_Json, MODE_Markdown, MODE_Quote, MODE_Table, MODE_Www, ShellState::out, shell_callback(), shell_out_of_memory(), sqlite3_column_count, sqlite3_column_name, sqlite3_column_text, sqlite3_column_type, sqlite3_fputs, sqlite3_free, sqlite3_malloc64, sqlite3_snprintf, sqlite3_step, SQLITE_ABORT, SQLITE_BLOB, SQLITE_NOMEM, SQLITE_NULL, and SQLITE_ROW.

Referenced by display_scanstats(), and shell_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec_prepared_stmt_columnar()

void exec_prepared_stmt_columnar ( ShellState * p,
sqlite3_stmt * pStmt )
static
24381 {
24382 sqlite3_int64 nRow = 0;
24383 int nColumn = 0;
24384 char **azData = 0;
24385 sqlite3_int64 nAlloc = 0;
24386 char *abRowDiv = 0;
24387 const unsigned char *uz;
24388 const char *z;
24389 char **azQuoted = 0;
24390 int rc;
24391 sqlite3_int64 i, nData;
24392 int j, nTotal, w, n;
24393 const char *colSep = 0;
24394 const char *rowSep = 0;
24395 const unsigned char **azNextLine = 0;
24396 int bNextLine = 0;
24397 int bMultiLineRowExists = 0;
24398 int bw = p->cmOpts.bWordWrap;
24399 const char *zEmpty = "";
24400 const char *zShowNull = p->nullValue;
24401
24402 rc = sqlite3_step(pStmt);
24403 if( rc!=SQLITE_ROW ) return;
24404 nColumn = sqlite3_column_count(pStmt);
24405 if( nColumn==0 ) goto columnar_end;
24406 nAlloc = nColumn*4;
24407 if( nAlloc<=0 ) nAlloc = 1;
24408 azData = sqlite3_malloc64( nAlloc*sizeof(char*) );
24409 shell_check_oom(azData);
24410 azNextLine = sqlite3_malloc64( nColumn*sizeof(char*) );
24411 shell_check_oom(azNextLine);
24412 memset((void*)azNextLine, 0, nColumn*sizeof(char*) );
24413 if( p->cmOpts.bQuote ){
24414 azQuoted = sqlite3_malloc64( nColumn*sizeof(char*) );
24415 shell_check_oom(azQuoted);
24416 memset(azQuoted, 0, nColumn*sizeof(char*) );
24417 }
24418 abRowDiv = sqlite3_malloc64( nAlloc/nColumn );
24419 shell_check_oom(abRowDiv);
24420 if( nColumn>p->nWidth ){
24421 p->colWidth = realloc(p->colWidth, (nColumn+1)*2*sizeof(int));
24423 for(i=p->nWidth; i<nColumn; i++) p->colWidth[i] = 0;
24424 p->nWidth = nColumn;
24425 p->actualWidth = &p->colWidth[nColumn];
24426 }
24427 memset(p->actualWidth, 0, nColumn*sizeof(int));
24428 for(i=0; i<nColumn; i++){
24429 w = p->colWidth[i];
24430 if( w<0 ) w = -w;
24431 p->actualWidth[i] = w;
24432 }
24433 for(i=0; i<nColumn; i++){
24434 const unsigned char *zNotUsed;
24435 int wx = p->colWidth[i];
24436 if( wx==0 ){
24437 wx = p->cmOpts.iWrap;
24438 }
24439 if( wx<0 ) wx = -wx;
24440 uz = (const unsigned char*)sqlite3_column_name(pStmt,i);
24441 if( uz==0 ) uz = (u8*)"";
24442 azData[i] = translateForDisplayAndDup(p, uz, &zNotUsed, wx, bw);
24443 }
24444 do{
24445 int useNextLine = bNextLine;
24446 bNextLine = 0;
24447 if( (nRow+2)*nColumn >= nAlloc ){
24448 nAlloc *= 2;
24449 azData = sqlite3_realloc64(azData, nAlloc*sizeof(char*));
24450 shell_check_oom(azData);
24451 abRowDiv = sqlite3_realloc64(abRowDiv, nAlloc/nColumn);
24452 shell_check_oom(abRowDiv);
24453 }
24454 abRowDiv[nRow] = 1;
24455 nRow++;
24456 for(i=0; i<nColumn; i++){
24457 int wx = p->colWidth[i];
24458 if( wx==0 ){
24459 wx = p->cmOpts.iWrap;
24460 }
24461 if( wx<0 ) wx = -wx;
24462 if( useNextLine ){
24463 uz = azNextLine[i];
24464 if( uz==0 ) uz = (u8*)zEmpty;
24465 }else if( p->cmOpts.bQuote ){
24466 assert( azQuoted!=0 );
24467 sqlite3_free(azQuoted[i]);
24468 azQuoted[i] = quoted_column(pStmt,i);
24469 uz = (const unsigned char*)azQuoted[i];
24470 }else{
24471 uz = (const unsigned char*)sqlite3_column_text(pStmt,i);
24472 if( uz==0 ) uz = (u8*)zShowNull;
24473 }
24474 azData[nRow*nColumn + i]
24475 = translateForDisplayAndDup(p, uz, &azNextLine[i], wx, bw);
24476 if( azNextLine[i] ){
24477 bNextLine = 1;
24478 abRowDiv[nRow-1] = 0;
24479 bMultiLineRowExists = 1;
24480 }
24481 }
24482 }while( bNextLine || sqlite3_step(pStmt)==SQLITE_ROW );
24483 nTotal = nColumn*(nRow+1);
24484 for(i=0; i<nTotal; i++){
24485 z = azData[i];
24486 if( z==0 ) z = (char*)zEmpty;
24487 n = strlenChar(z);
24488 j = i%nColumn;
24489 if( n>p->actualWidth[j] ) p->actualWidth[j] = n;
24490 }
24491 if( seenInterrupt ) goto columnar_end;
24492 switch( p->cMode ){
24493 case MODE_Column: {
24494 colSep = " ";
24495 rowSep = "\n";
24496 if( p->showHeader ){
24497 for(i=0; i<nColumn; i++){
24498 w = p->actualWidth[i];
24499 if( p->colWidth[i]<0 ) w = -w;
24500 utf8_width_print(p->out, w, azData[i]);
24501 sqlite3_fputs(i==nColumn-1?"\n":" ", p->out);
24502 }
24503 for(i=0; i<nColumn; i++){
24504 print_dashes(p->out, p->actualWidth[i]);
24505 sqlite3_fputs(i==nColumn-1?"\n":" ", p->out);
24506 }
24507 }
24508 break;
24509 }
24510 case MODE_Table: {
24511 colSep = " | ";
24512 rowSep = " |\n";
24513 print_row_separator(p, nColumn, "+");
24514 sqlite3_fputs("| ", p->out);
24515 for(i=0; i<nColumn; i++){
24516 w = p->actualWidth[i];
24517 n = strlenChar(azData[i]);
24518 sqlite3_fprintf(p->out, "%*s%s%*s", (w-n)/2, "",
24519 azData[i], (w-n+1)/2, "");
24520 sqlite3_fputs(i==nColumn-1?" |\n":" | ", p->out);
24521 }
24522 print_row_separator(p, nColumn, "+");
24523 break;
24524 }
24525 case MODE_Markdown: {
24526 colSep = " | ";
24527 rowSep = " |\n";
24528 sqlite3_fputs("| ", p->out);
24529 for(i=0; i<nColumn; i++){
24530 w = p->actualWidth[i];
24531 n = strlenChar(azData[i]);
24532 sqlite3_fprintf(p->out, "%*s%s%*s", (w-n)/2, "",
24533 azData[i], (w-n+1)/2, "");
24534 sqlite3_fputs(i==nColumn-1?" |\n":" | ", p->out);
24535 }
24536 print_row_separator(p, nColumn, "|");
24537 break;
24538 }
24539 case MODE_Box: {
24540 colSep = " " BOX_13 " ";
24541 rowSep = " " BOX_13 "\n";
24543 sqlite3_fputs(BOX_13 " ", p->out);
24544 for(i=0; i<nColumn; i++){
24545 w = p->actualWidth[i];
24546 n = strlenChar(azData[i]);
24547 sqlite3_fprintf(p->out, "%*s%s%*s%s",
24548 (w-n)/2, "", azData[i], (w-n+1)/2, "",
24549 i==nColumn-1?" "BOX_13"\n":" "BOX_13" ");
24550 }
24552 break;
24553 }
24554 }
24555 for(i=nColumn, j=0; i<nTotal; i++, j++){
24556 if( j==0 && p->cMode!=MODE_Column ){
24557 sqlite3_fputs(p->cMode==MODE_Box?BOX_13" ":"| ", p->out);
24558 }
24559 z = azData[i];
24560 if( z==0 ) z = p->nullValue;
24561 w = p->actualWidth[j];
24562 if( p->colWidth[j]<0 ) w = -w;
24563 utf8_width_print(p->out, w, z);
24564 if( j==nColumn-1 ){
24565 sqlite3_fputs(rowSep, p->out);
24566 if( bMultiLineRowExists && abRowDiv[i/nColumn-1] && i+1<nTotal ){
24567 if( p->cMode==MODE_Table ){
24568 print_row_separator(p, nColumn, "+");
24569 }else if( p->cMode==MODE_Box ){
24571 }else if( p->cMode==MODE_Column ){
24572 sqlite3_fputs("\n", p->out);
24573 }
24574 }
24575 j = -1;
24576 if( seenInterrupt ) goto columnar_end;
24577 }else{
24578 sqlite3_fputs(colSep, p->out);
24579 }
24580 }
24581 if( p->cMode==MODE_Table ){
24582 print_row_separator(p, nColumn, "+");
24583 }else if( p->cMode==MODE_Box ){
24585 }
24586columnar_end:
24587 if( seenInterrupt ){
24588 sqlite3_fputs("Interrupt\n", p->out);
24589 }
24590 nData = (nRow+1)*nColumn;
24591 for(i=0; i<nData; i++){
24592 z = azData[i];
24593 if( z!=zEmpty && z!=zShowNull ) free(azData[i]);
24594 }
24595 sqlite3_free(azData);
24596 sqlite3_free((void*)azNextLine);
24597 sqlite3_free(abRowDiv);
24598 if( azQuoted ){
24599 for(i=0; i<nColumn; i++) sqlite3_free(azQuoted[i]);
24600 sqlite3_free(azQuoted);
#define BOX_124
Definition shell.c:24134
static char * quoted_column(sqlite3_stmt *pStmt, int i)
Definition shell.c:24337
#define BOX_12
Definition shell.c:24129
#define BOX_234
Definition shell.c:24133
static char * translateForDisplayAndDup(ShellState *p, const unsigned char *z, const unsigned char **pzTail, int mxWidth, u8 bWordWrap)
Definition shell.c:24187
static void print_row_separator(ShellState *p, int nArg, const char *zSep)
Definition shell.c:22853
static void utf8_width_print(FILE *out, int w, const char *zUtf)
Definition shell.c:1195
#define BOX_34
Definition shell.c:24128
#define BOX_23
Definition shell.c:24127
static int strlenChar(const char *z)
Definition shell.c:1273
static void print_box_row_separator(ShellState *p, int nArg, const char *zSep1, const char *zSep2, const char *zSep3)
Definition shell.c:24156
#define BOX_13
Definition shell.c:24126
static void print_dashes(FILE *out, int N)
Definition shell.c:22840
#define BOX_134
Definition shell.c:24132
#define BOX_1234
Definition shell.c:24135
#define BOX_123
Definition shell.c:24131
#define BOX_14
Definition shell.c:24130

References ShellState::actualWidth, BOX_12, BOX_123, BOX_1234, BOX_124, BOX_13, BOX_134, BOX_14, BOX_23, BOX_234, BOX_34, ColModeOpts::bQuote, ColModeOpts::bWordWrap, ShellState::cMode, ShellState::cmOpts, ShellState::colWidth, ColModeOpts::iWrap, MODE_Box, MODE_Column, MODE_Markdown, MODE_Table, ShellState::nullValue, ShellState::nWidth, ShellState::out, print_box_row_separator(), print_dashes(), print_row_separator(), quoted_column(), seenInterrupt, shell_check_oom(), ShellState::showHeader, sqlite3_column_count, sqlite3_column_name, sqlite3_column_text, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_malloc64, sqlite3_realloc64, sqlite3_step, SQLITE_ROW, strlenChar(), translateForDisplayAndDup(), and utf8_width_print().

Referenced by exec_prepared_stmt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expertBestIndex()

int expertBestIndex ( sqlite3_vtab * pVtab,
sqlite3_index_info * pIdxInfo )
static
13209 {
13210 ExpertVtab *p = (ExpertVtab*)pVtab;
13211 int rc = SQLITE_OK;
13212 int n = 0;
13213 IdxScan *pScan;
13214 const int opmask =
13218
13219 pScan = idxMalloc(&rc, sizeof(IdxScan));
13220 if( pScan ){
13221 int i;
13222
13223 /* Link the new scan object into the list */
13224 pScan->pTab = p->pTab;
13225 pScan->pNextScan = p->pExpert->pScan;
13226 p->pExpert->pScan = pScan;
13227
13228 /* Add the constraints to the IdxScan object */
13229 for(i=0; i<pIdxInfo->nConstraint; i++){
13230 struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
13231 if( pCons->usable
13232 && pCons->iColumn>=0
13233 && p->pTab->aCol[pCons->iColumn].iPk==0
13234 && (pCons->op & opmask)
13235 ){
13236 IdxConstraint *pNew;
13237 const char *zColl = sqlite3_vtab_collation(pIdxInfo, i);
13238 pNew = idxNewConstraint(&rc, zColl);
13239 if( pNew ){
13240 pNew->iCol = pCons->iColumn;
13241 if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
13242 pNew->pNext = pScan->pEq;
13243 pScan->pEq = pNew;
13244 }else{
13245 pNew->bRange = 1;
13246 pNew->pNext = pScan->pRange;
13247 pScan->pRange = pNew;
13248 }
13249 }
13250 n++;
13251 pIdxInfo->aConstraintUsage[i].argvIndex = n;
13252 }
13253 }
13254
13255 /* Add the ORDER BY to the IdxScan object */
13256 for(i=pIdxInfo->nOrderBy-1; i>=0; i--){
13257 int iCol = pIdxInfo->aOrderBy[i].iColumn;
13258 if( iCol>=0 ){
13259 IdxConstraint *pNew = idxNewConstraint(&rc, p->pTab->aCol[iCol].zColl);
13260 if( pNew ){
13261 pNew->iCol = iCol;
13262 pNew->bDesc = pIdxInfo->aOrderBy[i].desc;
13263 pNew->pNext = pScan->pOrder;
13264 pNew->pLink = pScan->pOrder;
13265 pScan->pOrder = pNew;
13266 n++;
13267 }
13268 }
13269 }
13270 }
13271
13272 pIdxInfo->estimatedCost = 1000000.0 / (n+1);
13273 return rc;
13274}
IdxConstraint * pLink
Definition shell.c:12826
static void * idxMalloc(int *pRc, int nByte)
Definition shell.c:12930
char * zColl
Definition shell.c:12848
IdxColumn * aCol
Definition shell.c:12854
IdxScan * pNextScan
Definition shell.c:12839
IdxConstraint * pEq
Definition shell.c:12837
int bRange
Definition shell.c:12821
IdxConstraint * pNext
Definition shell.c:12825
int iCol
Definition shell.c:12822
IdxConstraint * pRange
Definition shell.c:12838
static IdxConstraint * idxNewConstraint(int *pRc, const char *zColl)
Definition shell.c:13052
IdxTable * pTab
Definition shell.c:13125
int iPk
Definition shell.c:12849
int bDesc
Definition shell.c:12824
IdxTable * pTab
Definition shell.c:12833
sqlite3expert * pExpert
Definition shell.c:13126
IdxScan * pScan
Definition shell.c:12915
IdxConstraint * pOrder
Definition shell.c:12836
Definition shell.c:13123
Definition shell.c:12819
Definition shell.c:12832
#define SQLITE_INDEX_CONSTRAINT_LT
Definition sqlite3.c:8069
#define SQLITE_INDEX_CONSTRAINT_LE
Definition sqlite3.c:8068
#define SQLITE_INDEX_CONSTRAINT_GE
Definition sqlite3.c:8070
#define SQLITE_INDEX_CONSTRAINT_GT
Definition sqlite3.c:8067
unsigned char desc
Definition sqlite3.c:7997
int iColumn
Definition sqlite3.c:7996
int nOrderBy
Definition sqlite3.c:7994
struct sqlite3_index_info::sqlite3_index_orderby * aOrderBy
#define sqlite3_vtab_collation
Definition sqlite3ext.h:640

References IdxTable::aCol, sqlite3_index_info::aConstraint, sqlite3_index_info::aConstraintUsage, sqlite3_index_info::aOrderBy, sqlite3_index_info::sqlite3_index_constraint_usage::argvIndex, IdxConstraint::bDesc, IdxConstraint::bRange, sqlite3_index_info::sqlite3_index_orderby::desc, sqlite3_index_info::estimatedCost, IdxConstraint::iCol, sqlite3_index_info::sqlite3_index_orderby::iColumn, idxMalloc(), idxNewConstraint(), IdxColumn::iPk, sqlite3_index_info::nConstraint, sqlite3_index_info::nOrderBy, IdxScan::pEq, ExpertVtab::pExpert, IdxConstraint::pLink, IdxConstraint::pNext, IdxScan::pNextScan, IdxScan::pOrder, IdxScan::pRange, sqlite3expert::pScan, ExpertVtab::pTab, IdxScan::pTab, sqlite3_vtab_collation, SQLITE_INDEX_CONSTRAINT_EQ, SQLITE_INDEX_CONSTRAINT_GE, SQLITE_INDEX_CONSTRAINT_GT, SQLITE_INDEX_CONSTRAINT_LE, SQLITE_INDEX_CONSTRAINT_LT, SQLITE_OK, and IdxColumn::zColl.

Referenced by idxRegisterVtab().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expertClose()

int expertClose ( sqlite3_vtab_cursor * cur)
static
13304 {
13305 ExpertCsr *pCsr = (ExpertCsr*)cur;
13306 sqlite3_finalize(pCsr->pData);
13307 sqlite3_free(pCsr);
13308 return SQLITE_OK;
13309}
sqlite3_stmt * pData
Definition shell.c:13132
Definition shell.c:13130

References ExpertCsr::pData, sqlite3_finalize, sqlite3_free, and SQLITE_OK.

Referenced by idxRegisterVtab().

Here is the caller graph for this function:

◆ expertColumn()

int expertColumn ( sqlite3_vtab_cursor * cur,
sqlite3_context * ctx,
int i )
static
13353 {
13354 ExpertCsr *pCsr = (ExpertCsr*)cur;
13355 sqlite3_value *pVal;
13356 pVal = sqlite3_column_value(pCsr->pData, i);
13357 if( pVal ){
13358 sqlite3_result_value(ctx, pVal);
13359 }
13360 return SQLITE_OK;
13361}
Definition sqlite3.c:23807
#define sqlite3_result_value
Definition sqlite3ext.h:493

References ExpertCsr::pData, sqlite3_column_value, sqlite3_result_value, and SQLITE_OK.

Referenced by idxRegisterVtab().

Here is the caller graph for this function:

◆ expertConnect()

int expertConnect ( sqlite3 * db,
void * pAux,
int argc,
const char *const * argv,
sqlite3_vtab ** ppVtab,
char ** pzErr )
static
13173 {
13174 sqlite3expert *pExpert = (sqlite3expert*)pAux;
13175 ExpertVtab *p = 0;
13176 int rc;
13177
13178 if( argc!=4 ){
13179 *pzErr = sqlite3_mprintf("internal error!");
13180 rc = SQLITE_ERROR;
13181 }else{
13182 char *zCreateTable = expertDequote(argv[3]);
13183 if( zCreateTable ){
13184 rc = sqlite3_declare_vtab(db, zCreateTable);
13185 if( rc==SQLITE_OK ){
13186 p = idxMalloc(&rc, sizeof(ExpertVtab));
13187 }
13188 if( rc==SQLITE_OK ){
13189 p->pExpert = pExpert;
13190 p->pTab = pExpert->pTable;
13191 assert( sqlite3_stricmp(p->pTab->zName, argv[2])==0 );
13192 }
13193 sqlite3_free(zCreateTable);
13194 }else{
13195 rc = SQLITE_NOMEM;
13196 }
13197 }
13198
13199 *ppVtab = (sqlite3_vtab*)p;
13200 return rc;
13201}
static char * expertDequote(const char *zIn)
Definition shell.c:13135
IdxTable * pTable
Definition shell.c:12914
char * zName
Definition shell.c:12853
Definition shell.c:12909
#define SQLITE_ERROR
Definition sqlite3.c:767

References expertDequote(), idxMalloc(), ExpertVtab::pExpert, ExpertVtab::pTab, sqlite3expert::pTable, sqlite3_declare_vtab, sqlite3_free, sqlite3_mprintf, sqlite3_stricmp, SQLITE_ERROR, SQLITE_NOMEM, SQLITE_OK, and IdxTable::zName.

Referenced by idxRegisterVtab().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expertDbContainsObject()

int expertDbContainsObject ( sqlite3 * db,
const char * zTab,
int * pbContains )
static
14162 {
14163 const char *zSql = "SELECT 1 FROM sqlite_schema WHERE name = ?";
14164 sqlite3_stmt *pSql = 0;
14165 int rc = SQLITE_OK;
14166 int ret = 0;
14167
14168 rc = sqlite3_prepare_v2(db, zSql, -1, &pSql, 0);
14169 if( rc==SQLITE_OK ){
14170 sqlite3_bind_text(pSql, 1, zTab, -1, SQLITE_STATIC);
14171 if( SQLITE_ROW==sqlite3_step(pSql) ){
14172 ret = 1;
14173 }
14174 rc = sqlite3_finalize(pSql);
14175 }
14176
14177 *pbContains = ret;
14178 return rc;
14179}

References sqlite3_bind_text, sqlite3_finalize, sqlite3_prepare_v2, sqlite3_step, SQLITE_OK, SQLITE_ROW, and SQLITE_STATIC.

Referenced by idxCreateVtabSchema(), and sqlite3_expert_new().

Here is the caller graph for this function:

◆ expertDequote()

char * expertDequote ( const char * zIn)
static
13135 {
13136 int n = STRLEN(zIn);
13137 char *zRet = sqlite3_malloc(n);
13138
13139 assert( zIn[0]=='\'' );
13140 assert( zIn[n-1]=='\'' );
13141
13142 if( zRet ){
13143 int iOut = 0;
13144 int iIn = 0;
13145 for(iIn=1; iIn<(n-1); iIn++){
13146 if( zIn[iIn]=='\'' ){
13147 assert( zIn[iIn+1]=='\'' );
13148 iIn++;
13149 }
13150 zRet[iOut++] = zIn[iIn];
13151 }
13152 zRet[iOut] = '\0';
13153 }
13154
13155 return zRet;
13156}
#define STRLEN
Definition shell.c:12802

References sqlite3_malloc, and STRLEN.

Referenced by expertConnect().

Here is the caller graph for this function:

◆ expertDisconnect()

int expertDisconnect ( sqlite3_vtab * pVtab)
static
13203 {
13204 ExpertVtab *p = (ExpertVtab*)pVtab;
13205 sqlite3_free(p);
13206 return SQLITE_OK;
13207}

References sqlite3_free, and SQLITE_OK.

Referenced by idxRegisterVtab().

Here is the caller graph for this function:

◆ expertDotCommand()

int expertDotCommand ( ShellState * pState,
char ** azArg,
int nArg )
static
24769 {
24770 int rc = SQLITE_OK;
24771 char *zErr = 0;
24772 int i;
24773 int iSample = 0;
24774
24775 assert( pState->expert.pExpert==0 );
24776 memset(&pState->expert, 0, sizeof(ExpertInfo));
24777
24778 for(i=1; rc==SQLITE_OK && i<nArg; i++){
24779 char *z = azArg[i];
24780 int n;
24781 if( z[0]=='-' && z[1]=='-' ) z++;
24782 n = strlen30(z);
24783 if( n>=2 && 0==cli_strncmp(z, "-verbose", n) ){
24784 pState->expert.bVerbose = 1;
24785 }
24786 else if( n>=2 && 0==cli_strncmp(z, "-sample", n) ){
24787 if( i==(nArg-1) ){
24788 sqlite3_fprintf(stderr, "option requires an argument: %s\n", z);
24789 rc = SQLITE_ERROR;
24790 }else{
24791 iSample = (int)integerValue(azArg[++i]);
24792 if( iSample<0 || iSample>100 ){
24793 sqlite3_fprintf(stderr,"value out of range: %s\n", azArg[i]);
24794 rc = SQLITE_ERROR;
24795 }
24796 }
24797 }
24798 else{
24799 sqlite3_fprintf(stderr,"unknown option: %s\n", z);
24800 rc = SQLITE_ERROR;
24801 }
24802 }
24803
24804 if( rc==SQLITE_OK ){
24805 pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
24806 if( pState->expert.pExpert==0 ){
24807 sqlite3_fprintf(stderr,
24808 "sqlite3_expert_new: %s\n", zErr ? zErr : "out of memory");
24809 rc = SQLITE_ERROR;
24810 }else{
24812 pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
24813 );
24814 }
24815 }
24816 sqlite3_free(zErr);
24817
sqlite3expert * sqlite3_expert_new(sqlite3 *db, char **pzErr)
Definition shell.c:14741
int sqlite3_expert_config(sqlite3expert *p, int op,...)
Definition shell.c:14822
int bVerbose
Definition shell.c:21635
#define EXPERT_CONFIG_SAMPLE
Definition shell.c:12644
Definition shell.c:21633

References ExpertInfo::bVerbose, cli_strncmp(), ShellState::db, ShellState::expert, EXPERT_CONFIG_SAMPLE, integerValue(), ExpertInfo::pExpert, sqlite3_expert_config(), sqlite3_expert_new(), sqlite3_fprintf, sqlite3_free, SQLITE_ERROR, SQLITE_OK, and strlen30().

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expertEof()

int expertEof ( sqlite3_vtab_cursor * cur)
static
13317 {
13318 ExpertCsr *pCsr = (ExpertCsr*)cur;
13319 return pCsr->pData==0;
13320}

References ExpertCsr::pData.

Referenced by idxRegisterVtab().

Here is the caller graph for this function:

◆ expertFilter()

int expertFilter ( sqlite3_vtab_cursor * cur,
int idxNum,
const char * idxStr,
int argc,
sqlite3_value ** argv )
static
13370 {
13371 ExpertCsr *pCsr = (ExpertCsr*)cur;
13372 ExpertVtab *pVtab = (ExpertVtab*)(cur->pVtab);
13373 sqlite3expert *pExpert = pVtab->pExpert;
13374 int rc;
13375
13376 (void)idxNum;
13377 (void)idxStr;
13378 (void)argc;
13379 (void)argv;
13380 rc = sqlite3_finalize(pCsr->pData);
13381 pCsr->pData = 0;
13382 if( rc==SQLITE_OK ){
13383 rc = idxPrintfPrepareStmt(pExpert->db, &pCsr->pData, &pVtab->base.zErrMsg,
13384 "SELECT * FROM main.%Q WHERE sqlite_expert_sample()", pVtab->pTab->zName
13385 );
13386 }
13387
13388 if( rc==SQLITE_OK ){
13389 rc = expertNext(cur);
13390 }
13391 return rc;
13392}
sqlite3_vtab base
Definition shell.c:13124
static int expertNext(sqlite3_vtab_cursor *cur)
Definition shell.c:13325
sqlite3 * db
Definition shell.c:12911
static int idxPrintfPrepareStmt(sqlite3 *db, sqlite3_stmt **ppStmt, char **pzErrmsg, const char *zFmt,...)
Definition shell.c:13096
char * zErrMsg
Definition sqlite3.c:8168
sqlite3_vtab * pVtab
Definition sqlite3.c:8190

References ExpertVtab::base, sqlite3expert::db, expertNext(), idxPrintfPrepareStmt(), ExpertCsr::pData, ExpertVtab::pExpert, ExpertVtab::pTab, sqlite3_vtab_cursor::pVtab, sqlite3_finalize, SQLITE_OK, sqlite3_vtab::zErrMsg, and IdxTable::zName.

Referenced by idxRegisterVtab().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expertFinish()

int expertFinish ( ShellState * pState,
int bCancel,
char ** pzErr )
static
24723 {
24724 int rc = SQLITE_OK;
24725 sqlite3expert *p = pState->expert.pExpert;
24726 FILE *out = pState->out;
24727 assert( p );
24728 assert( bCancel || pzErr==0 || *pzErr==0 );
24729 if( bCancel==0 ){
24730 int bVerbose = pState->expert.bVerbose;
24731
24732 rc = sqlite3_expert_analyze(p, pzErr);
24733 if( rc==SQLITE_OK ){
24734 int nQuery = sqlite3_expert_count(p);
24735 int i;
24736
24737 if( bVerbose ){
24738 const char *zCand = sqlite3_expert_report(p,0,EXPERT_REPORT_CANDIDATES);
24739 sqlite3_fputs("-- Candidates -----------------------------\n", out);
24740 sqlite3_fprintf(out, "%s\n", zCand);
24741 }
24742 for(i=0; i<nQuery; i++){
24743 const char *zSql = sqlite3_expert_report(p, i, EXPERT_REPORT_SQL);
24744 const char *zIdx = sqlite3_expert_report(p, i, EXPERT_REPORT_INDEXES);
24745 const char *zEQP = sqlite3_expert_report(p, i, EXPERT_REPORT_PLAN);
24746 if( zIdx==0 ) zIdx = "(no new indexes)\n";
24747 if( bVerbose ){
24748 sqlite3_fprintf(out,
24749 "-- Query %d --------------------------------\n"
24750 "%s\n\n"
24751 ,i+1, zSql);
24752 }
24753 sqlite3_fprintf(out, "%s\n%s\n", zIdx, zEQP);
24754 }
24755 }
24756 }
24758 pState->expert.pExpert = 0;
#define EXPERT_REPORT_PLAN
Definition shell.c:12742
int sqlite3_expert_count(sqlite3expert *)
Definition shell.c:14940
#define EXPERT_REPORT_CANDIDATES
Definition shell.c:12743
int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr)
Definition shell.c:14895
const char * sqlite3_expert_report(sqlite3expert *, int iStmt, int eReport)
Definition shell.c:14949
#define EXPERT_REPORT_SQL
Definition shell.c:12740
void sqlite3_expert_destroy(sqlite3expert *)
Definition shell.c:14975
#define EXPERT_REPORT_INDEXES
Definition shell.c:12741

References ExpertInfo::bVerbose, ShellState::expert, EXPERT_REPORT_CANDIDATES, EXPERT_REPORT_INDEXES, EXPERT_REPORT_PLAN, EXPERT_REPORT_SQL, ShellState::out, ExpertInfo::pExpert, sqlite3_expert_analyze(), sqlite3_expert_count(), sqlite3_expert_destroy(), sqlite3_expert_report(), sqlite3_fprintf, sqlite3_fputs, and SQLITE_OK.

Referenced by do_meta_command(), main(), and shell_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expertHandleSQL()

int expertHandleSQL ( ShellState * pState,
const char * zSql,
char ** pzErr )
static
24703 {
24704 assert( pState->expert.pExpert );
24705 assert( pzErr==0 || *pzErr==0 );

References ShellState::expert, ExpertInfo::pExpert, and sqlite3_expert_sql().

Referenced by shell_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expertNext()

int expertNext ( sqlite3_vtab_cursor * cur)
static
13325 {
13326 ExpertCsr *pCsr = (ExpertCsr*)cur;
13327 int rc = SQLITE_OK;
13328
13329 assert( pCsr->pData );
13330 rc = sqlite3_step(pCsr->pData);
13331 if( rc!=SQLITE_ROW ){
13332 rc = sqlite3_finalize(pCsr->pData);
13333 pCsr->pData = 0;
13334 }else{
13335 rc = SQLITE_OK;
13336 }
13337
13338 return rc;
13339}

References ExpertCsr::pData, sqlite3_finalize, sqlite3_step, SQLITE_OK, and SQLITE_ROW.

Referenced by expertFilter(), and idxRegisterVtab().

Here is the caller graph for this function:

◆ expertOpen()

int expertOpen ( sqlite3_vtab * pVTab,
sqlite3_vtab_cursor ** ppCursor )
static
13292 {
13293 int rc = SQLITE_OK;
13294 ExpertCsr *pCsr;
13295 (void)pVTab;
13296 pCsr = idxMalloc(&rc, sizeof(ExpertCsr));
13297 *ppCursor = (sqlite3_vtab_cursor*)pCsr;
13298 return rc;
13299}
Definition sqlite3.c:8189

References idxMalloc(), and SQLITE_OK.

Referenced by idxRegisterVtab().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expertRowid()

int expertRowid ( sqlite3_vtab_cursor * cur,
sqlite_int64 * pRowid )
static
13344 {
13345 (void)cur;
13346 *pRowid = 0;
13347 return SQLITE_OK;
13348}

References SQLITE_OK.

Referenced by idxRegisterVtab().

Here is the caller graph for this function:

◆ expertSchemaSql()

int expertSchemaSql ( sqlite3 * db,
const char * zSql,
char ** pzErr )
static
14193 {
14194 int rc = SQLITE_OK;
14195 char *zErr = 0;
14196
14197 rc = sqlite3_exec(db, zSql, 0, 0, &zErr);
14198 if( rc!=SQLITE_OK && zErr ){
14199 int nErr = STRLEN(zErr);
14200 if( nErr>=15 && memcmp(zErr, "no such module:", 15)==0 ){
14201 sqlite3_free(zErr);
14202 rc = SQLITE_OK;
14203 zErr = 0;
14204 }
14205 }
14206
14207 *pzErr = zErr;
14208 return rc;
14209}

References sqlite3_exec, sqlite3_free, SQLITE_OK, and STRLEN.

Referenced by idxCreateVtabSchema(), and sqlite3_expert_new().

Here is the caller graph for this function:

◆ expertUpdate()

int expertUpdate ( sqlite3_vtab * pVtab,
int nData,
sqlite3_value ** azData,
sqlite_int64 * pRowid )
static
13281 {
13282 (void)pVtab;
13283 (void)nData;
13284 (void)azData;
13285 (void)pRowid;
13286 return SQLITE_OK;
13287}

References SQLITE_OK.

Referenced by idxRegisterVtab().

Here is the caller graph for this function:

◆ explain_data_delete()

void explain_data_delete ( ShellState * p)
static
23960 {
23962 p->aiIndent = 0;
23963 p->nIndent = 0;
int * aiIndent
Definition shell.c:21735
int nIndent
Definition shell.c:21736

References ShellState::aiIndent, ShellState::iIndent, ShellState::nIndent, and sqlite3_free.

Referenced by display_scanstats(), and shell_exec().

Here is the caller graph for this function:

◆ explain_data_prepare()

void explain_data_prepare ( ShellState * p,
sqlite3_stmt * pSql )
static
23898 {
23899 int *abYield = 0; /* True if op is an OP_Yield */
23900 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
23901 int iOp; /* Index of operation in p->aiIndent[] */
23902
23903 const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
23904 "Return", 0 };
23905 const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead",
23906 "Rewind", 0 };
23907 const char *azGoto[] = { "Goto", 0 };
23908
23909 /* The caller guarantees that the leftmost 4 columns of the statement
23910 ** passed to this function are equivalent to the leftmost 4 columns
23911 ** of EXPLAIN statement output. In practice the statement may be
23912 ** an EXPLAIN, or it may be a query on the bytecode() virtual table. */
23913 assert( sqlite3_column_count(pSql)>=4 );
23914 assert( 0==sqlite3_stricmp( sqlite3_column_name(pSql, 0), "addr" ) );
23915 assert( 0==sqlite3_stricmp( sqlite3_column_name(pSql, 1), "opcode" ) );
23916 assert( 0==sqlite3_stricmp( sqlite3_column_name(pSql, 2), "p1" ) );
23917 assert( 0==sqlite3_stricmp( sqlite3_column_name(pSql, 3), "p2" ) );
23918
23919 for(iOp=0; SQLITE_ROW==sqlite3_step(pSql); iOp++){
23920 int i;
23921 int iAddr = sqlite3_column_int(pSql, 0);
23922 const char *zOp = (const char*)sqlite3_column_text(pSql, 1);
23923 int p1 = sqlite3_column_int(pSql, 2);
23924 int p2 = sqlite3_column_int(pSql, 3);
23925
23926 /* Assuming that p2 is an instruction address, set variable p2op to the
23927 ** index of that instruction in the aiIndent[] array. p2 and p2op may be
23928 ** different if the current instruction is part of a sub-program generated
23929 ** by an SQL trigger or foreign key. */
23930 int p2op = (p2 + (iOp-iAddr));
23931
23932 /* Grow the p->aiIndent array as required */
23933 if( iOp>=nAlloc ){
23934 nAlloc += 100;
23935 p->aiIndent = (int*)sqlite3_realloc64(p->aiIndent, nAlloc*sizeof(int));
23937 abYield = (int*)sqlite3_realloc64(abYield, nAlloc*sizeof(int));
23938 shell_check_oom(abYield);
23939 }
23940
23941 abYield[iOp] = str_in_array(zOp, azYield);
23942 p->aiIndent[iOp] = 0;
23943 p->nIndent = iOp+1;
23944 if( str_in_array(zOp, azNext) && p2op>0 ){
23945 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
23946 }
23947 if( str_in_array(zOp, azGoto) && p2op<iOp && (abYield[p2op] || p1) ){
23948 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
23949 }
23950 }
23951
23952 p->iIndent = 0;
23953 sqlite3_free(abYield);
int iIndent
Definition shell.c:21737
static int str_in_array(const char *zStr, const char **azArray)
Definition shell.c:23867

References ShellState::aiIndent, ShellState::iIndent, ShellState::nIndent, shell_check_oom(), sqlite3_column_count, sqlite3_column_int, sqlite3_column_name, sqlite3_column_text, sqlite3_free, sqlite3_realloc64, sqlite3_reset, sqlite3_step, sqlite3_stricmp, SQLITE_ROW, and str_in_array().

Referenced by display_scanstats(), and shell_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ failIfSafeMode()

void failIfSafeMode ( ShellState * p,
const char * zErrMsg,
... )
static
21919 {
21920 if( p->bSafeMode ){
21921 va_list ap;
21922 char *zMsg;
21923 va_start(ap, zErrMsg);
21924 zMsg = sqlite3_vmprintf(zErrMsg, ap);
21925 va_end(ap);
21926 sqlite3_fprintf(stderr, "line %d: %s\n", p->lineno, zMsg);
21927 exit(1);

References ShellState::bSafeMode, ShellState::lineno, sqlite3_fprintf, and sqlite3_vmprintf.

Referenced by do_meta_command(), and safeModeAuth().

Here is the caller graph for this function:

◆ faultsim_callback()

int faultsim_callback ( int iArg)
static
28774 {
28775 if( faultsim_state.iId>0 && faultsim_state.iId!=iArg ){
28776 return SQLITE_OK;
28777 }
28778 if( faultsim_state.iCnt ){
28779 if( faultsim_state.iCnt>0 ) faultsim_state.iCnt--;
28780 if( faultsim_state.eVerbose>=2 ){
28781 sqlite3_fprintf(stdout,
28782 "FAULT-SIM id=%d no-fault (cnt=%d)\n", iArg, faultsim_state.iCnt);
28783 }
28784 return SQLITE_OK;
28785 }
28786 if( faultsim_state.eVerbose>=1 ){
28787 sqlite3_fprintf(stdout,
28788 "FAULT-SIM id=%d returns %d\n", iArg, faultsim_state.iErr);
28789 }
28790 faultsim_state.iCnt = faultsim_state.iInterval;
28791 faultsim_state.nHit++;
28792 if( faultsim_state.nRepeat>0 && faultsim_state.nRepeat<=faultsim_state.nHit ){
28793 faultsim_state.iCnt = -1;
28794 }

References faultsim_state, sqlite3_fprintf, and SQLITE_OK.

Referenced by do_meta_command().

Here is the caller graph for this function:

◆ fileLinkStat()

int fileLinkStat ( const char * zPath,
struct stat * pStatBuf )
static
8281 {
8282#if defined(_WIN32)
8283 return fileStat(zPath, pStatBuf);
8284#else
8285 return lstat(zPath, pStatBuf);
8286#endif
8287}
static int fileStat(const char *zPath, struct stat *pStatBuf)
Definition shell.c:8254

References fileStat(), and STRUCT_STAT.

Referenced by fsdirFilter(), and fsdirNext().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fileStat()

int fileStat ( const char * zPath,
struct stat * pStatBuf )
static
8257 {
8258#if defined(_WIN32)
8259 sqlite3_int64 sz = strlen(zPath);
8260 wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
8261 int rc;
8262 if( b1==0 ) return 1;
8263 sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
8264 b1[sz] = 0;
8265 rc = _wstat(b1, pStatBuf);
8266 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
8267 return rc;
8268#else
8269 return stat(zPath, pStatBuf);
8270#endif
8271}

References sqlite3_malloc64, and STRUCT_STAT.

Referenced by fileLinkStat(), makeDirectory(), and writeFile().

Here is the caller graph for this function:

◆ fileTail()

const char * fileTail ( const char * z)
static
16448 {
16449 size_t i;
16450 if( z==0 ) return 0;
16451 i = strlen(z)-1;
16452 while( i>0 && z[i-1]!='/' ){ i--; }
16453 return &z[i];
16454}

Referenced by vfstraceOpen().

Here is the caller graph for this function:

◆ find_home_dir()

char * find_home_dir ( int clearFlag)
static
32884 {
32885 static char *home_dir = NULL;
32886 if( clearFlag ){
32887 free(home_dir);
32888 home_dir = 0;
32889 return 0;
32890 }
32891 if( home_dir ) return home_dir;
32892
32893#if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) \
32894 && !defined(__RTP__) && !defined(_WRS_KERNEL) && !defined(SQLITE_WASI)
32895 {
32896 struct passwd *pwent;
32897 uid_t uid = getuid();
32898 if( (pwent=getpwuid(uid)) != NULL) {
32899 home_dir = pwent->pw_dir;
32900 }
32901 }
32902#endif
32903
32904#if defined(_WIN32_WCE)
32905 /* Windows CE (arm-wince-mingw32ce-gcc) does not provide getenv()
32906 */
32907 home_dir = "/";
32908#else
32909
32910#if defined(_WIN32) || defined(WIN32)
32911 if (!home_dir) {
32912 home_dir = getenv("USERPROFILE");
32913 }
32914#endif
32915
32916 if (!home_dir) {
32917 home_dir = getenv("HOME");
32918 }
32919
32920#if defined(_WIN32) || defined(WIN32)
32921 if (!home_dir) {
32922 char *zDrive, *zPath;
32923 int n;
32924 zDrive = getenv("HOMEDRIVE");
32925 zPath = getenv("HOMEPATH");
32926 if( zDrive && zPath ){
32927 n = strlen30(zDrive) + strlen30(zPath) + 1;
32928 home_dir = malloc( n );
32929 if( home_dir==0 ) return 0;
32930 sqlite3_snprintf(n, home_dir, "%s%s", zDrive, zPath);
32931 return home_dir;
32932 }
32933 home_dir = "c:\\";
32934 }
32935#endif
32936
32937#endif /* !_WIN32_WCE */
32938
32939 if( home_dir ){
32940 i64 n = strlen(home_dir) + 1;
32941 char *z = malloc( n );
32942 if( z ) memcpy(z, home_dir, n);
32943 home_dir = z;
32944 }
32945

References sqlite3_snprintf, and strlen30().

Referenced by main(), and process_sqliterc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_xdg_config()

char * find_xdg_config ( void )
static
32959 {
32960#if defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE) \
32961 || defined(__RTP__) || defined(_WRS_KERNEL)
32962 return 0;
32963#else
32964 char *zConfig = 0;
32965 const char *zXdgHome;
32966
32967 zXdgHome = getenv("XDG_CONFIG_HOME");
32968 if( zXdgHome==0 ){
32969 const char *zHome = getenv("HOME");
32970 if( zHome==0 ) return 0;
32971 zConfig = sqlite3_mprintf("%s/.config/sqlite3/sqliterc", zHome);
32972 }else{
32973 zConfig = sqlite3_mprintf("%s/sqlite3/sqliterc", zXdgHome);
32974 }
32975 shell_check_oom(zConfig);
32976 if( access(zConfig,0)!=0 ){
32977 sqlite3_free(zConfig);
32978 zConfig = 0;
32979 }
32980 return zConfig;

References shell_check_oom(), sqlite3_free, and sqlite3_mprintf.

Referenced by process_sqliterc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ freeColumnList()

void freeColumnList ( char ** azCol)
static
24981 {
24982 int i;
24983 for(i=1; azCol[i]; i++){
24984 sqlite3_free(azCol[i]);
24985 }
24986 /* azCol[0] is a static string */

References sqlite3_free.

Referenced by dump_callback(), and tableColumnList().

Here is the caller graph for this function:

◆ freeText()

void freeText ( ShellText * p)
static
1473 {
1474 free(p->z);
1475 initText(p);
1476}

References initText(), and ShellText::z.

Referenced by do_meta_command(), dump_callback(), and shellFakeSchema().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromBase64()

u8 * fromBase64 ( char * pIn,
int ncIn,
u8 * pOut )
static
5251 {
5252 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
5253 while( ncIn>0 && *pIn!=PAD_CHAR ){
5254 static signed char nboi[] = { 0, 0, 1, 2, 3 };
5255 char *pUse = skipNonB64(pIn, ncIn);
5256 unsigned long qv = 0L;
5257 int nti, nbo, nac;
5258 ncIn -= (pUse - pIn);
5259 pIn = pUse;
5260 nti = (ncIn>4)? 4 : ncIn;
5261 ncIn -= nti;
5262 nbo = nboi[nti];
5263 if( nbo==0 ) break;
5264 for( nac=0; nac<4; ++nac ){
5265 char c = (nac<nti)? *pIn++ : b64Numerals[0];
5266 u8 bdp = BX_DV_PROTO(c);
5267 switch( bdp ){
5268 case ND:
5269 /* Treat dark non-digits as pad, but they terminate decode too. */
5270 ncIn = 0;
5271 deliberate_fall_through; /* FALLTHRU */
5272 case WS:
5273 /* Treat whitespace as pad and terminate this group.*/
5274 nti = nac;
5275 deliberate_fall_through; /* FALLTHRU */
5276 case PC:
5277 bdp = 0;
5278 --nbo;
5279 deliberate_fall_through; /* FALLTHRU */
5280 default: /* bdp is the digit value. */
5281 qv = qv<<6 | bdp;
5282 break;
5283 }
5284 }
5285 switch( nbo ){
5286 case 3:
5287 pOut[2] = (qv) & 0xff;
5288 deliberate_fall_through; /* FALLTHRU */
5289 case 2:
5290 pOut[1] = (qv>>8) & 0xff;
5291 deliberate_fall_through; /* FALLTHRU */
5292 case 1:
5293 pOut[0] = (qv>>16) & 0xff;
5294 break;
5295 }
5296 pOut += nbo;
5297 }
5298 return pOut;
5299}
#define BX_DV_PROTO(c)
Definition shell.c:5195
#define ND
Definition shell.c:5164
#define PAD_CHAR
Definition shell.c:5165
static char * skipNonB64(char *s, int nc)
Definition shell.c:5244
#define deliberate_fall_through
Definition shell.c:190

References b64Numerals, BX_DV_PROTO, c, deliberate_fall_through, ND, PAD_CHAR, PC, skipNonB64(), and WS.

Referenced by base64().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromBase85()

u8 * fromBase85 ( char * pIn,
int ncIn,
u8 * pOut )
static
5605 {
5606 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
5607 while( ncIn>0 ){
5608 static signed char nboi[] = { 0, 0, 1, 2, 3, 4 };
5609 char *pUse = skipNonB85(pIn, ncIn);
5610 unsigned long qv = 0L;
5611 int nti, nbo;
5612 ncIn -= (pUse - pIn);
5613 pIn = pUse;
5614 nti = (ncIn>5)? 5 : ncIn;
5615 nbo = nboi[nti];
5616 if( nbo==0 ) break;
5617 while( nti>0 ){
5618 char c = *pIn++;
5619 u8 cdo = B85_DNOS(c);
5620 --ncIn;
5621 if( cdo==0 ) break;
5622 qv = 85 * qv + (c - cdo);
5623 --nti;
5624 }
5625 nbo -= nti; /* Adjust for early (non-digit) end of group. */
5626 switch( nbo ){
5627 case 4:
5628 *pOut++ = (qv >> 24)&0xff;
5629 /* FALLTHRU */
5630 case 3:
5631 *pOut++ = (qv >> 16)&0xff;
5632 /* FALLTHRU */
5633 case 2:
5634 *pOut++ = (qv >> 8)&0xff;
5635 /* FALLTHRU */
5636 case 1:
5637 *pOut++ = qv&0xff;
5638 /* FALLTHRU */
5639 case 0:
5640 break;
5641 }
5642 }
5643 return pOut;
5644}
#define B85_DNOS(c)
Definition shell.c:5520
static char * skipNonB85(char *s, int nc)
Definition shell.c:5537

References B85_DNOS, c, and skipNonB85().

Referenced by base85().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fsdirBestIndex()

int fsdirBestIndex ( sqlite3_vtab * tab,
sqlite3_index_info * pIdxInfo )
static
8881 {
8882 int i; /* Loop over constraints */
8883 int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
8884 int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
8885 int seenPath = 0; /* True if an unusable PATH= constraint is seen */
8886 int seenDir = 0; /* True if an unusable DIR= constraint is seen */
8887 const struct sqlite3_index_constraint *pConstraint;
8888
8889 (void)tab;
8890 pConstraint = pIdxInfo->aConstraint;
8891 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
8892 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
8893 switch( pConstraint->iColumn ){
8894 case FSDIR_COLUMN_PATH: {
8895 if( pConstraint->usable ){
8896 idxPath = i;
8897 seenPath = 0;
8898 }else if( idxPath<0 ){
8899 seenPath = 1;
8900 }
8901 break;
8902 }
8903 case FSDIR_COLUMN_DIR: {
8904 if( pConstraint->usable ){
8905 idxDir = i;
8906 seenDir = 0;
8907 }else if( idxDir<0 ){
8908 seenDir = 1;
8909 }
8910 break;
8911 }
8912 }
8913 }
8914 if( seenPath || seenDir ){
8915 /* If input parameters are unusable, disallow this plan */
8916 return SQLITE_CONSTRAINT;
8917 }
8918
8919 if( idxPath<0 ){
8920 pIdxInfo->idxNum = 0;
8921 /* The pIdxInfo->estimatedCost should have been initialized to a huge
8922 ** number. Leave it unchanged. */
8923 pIdxInfo->estimatedRows = 0x7fffffff;
8924 }else{
8925 pIdxInfo->aConstraintUsage[idxPath].omit = 1;
8926 pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
8927 if( idxDir>=0 ){
8928 pIdxInfo->aConstraintUsage[idxDir].omit = 1;
8929 pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
8930 pIdxInfo->idxNum = 2;
8931 pIdxInfo->estimatedCost = 10.0;
8932 }else{
8933 pIdxInfo->idxNum = 1;
8934 pIdxInfo->estimatedCost = 100.0;
8935 }
8936 }
8937
8938 return SQLITE_OK;
8939}
#define FSDIR_COLUMN_PATH
Definition shell.c:8061
#define FSDIR_COLUMN_DIR
Definition shell.c:8062
#define SQLITE_CONSTRAINT
Definition sqlite3.c:785

References sqlite3_index_info::aConstraint, sqlite3_index_info::aConstraintUsage, sqlite3_index_info::sqlite3_index_constraint_usage::argvIndex, sqlite3_index_info::estimatedCost, sqlite3_index_info::estimatedRows, FSDIR_COLUMN_DIR, FSDIR_COLUMN_PATH, sqlite3_index_info::idxNum, sqlite3_index_info::nConstraint, sqlite3_index_info::sqlite3_index_constraint_usage::omit, SQLITE_CONSTRAINT, SQLITE_INDEX_CONSTRAINT_EQ, and SQLITE_OK.

Referenced by fsdirRegister().

Here is the caller graph for this function:

◆ fsdirClose()

int fsdirClose ( sqlite3_vtab_cursor * cur)
static
8649 {
8650 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8651
8652 fsdirResetCursor(pCur);
8653 sqlite3_free(pCur);
8654 return SQLITE_OK;
8655}
static void fsdirResetCursor(fsdir_cursor *pCur)
Definition shell.c:8628
Definition shell.c:8555

References fsdirResetCursor(), sqlite3_free, and SQLITE_OK.

Referenced by fsdirRegister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fsdirColumn()

int fsdirColumn ( sqlite3_vtab_cursor * cur,
sqlite3_context * ctx,
int i )
static
8740 {
8741 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8742 switch( i ){
8743 case FSDIR_COLUMN_NAME: {
8744 sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
8745 break;
8746 }
8747
8748 case FSDIR_COLUMN_MODE:
8749 sqlite3_result_int64(ctx, pCur->sStat.st_mode);
8750 break;
8751
8752 case FSDIR_COLUMN_MTIME:
8753 sqlite3_result_int64(ctx, pCur->sStat.st_mtime);
8754 break;
8755
8756 case FSDIR_COLUMN_DATA: {
8757 mode_t m = pCur->sStat.st_mode;
8758 if( S_ISDIR(m) ){
8760#if !defined(_WIN32) && !defined(WIN32)
8761 }else if( S_ISLNK(m) ){
8762 char aStatic[64];
8763 char *aBuf = aStatic;
8764 sqlite3_int64 nBuf = 64;
8765 int n;
8766
8767 while( 1 ){
8768 n = readlink(pCur->zPath, aBuf, nBuf);
8769 if( n<nBuf ) break;
8770 if( aBuf!=aStatic ) sqlite3_free(aBuf);
8771 nBuf = nBuf*2;
8772 aBuf = sqlite3_malloc64(nBuf);
8773 if( aBuf==0 ){
8775 return SQLITE_NOMEM;
8776 }
8777 }
8778
8780 if( aBuf!=aStatic ) sqlite3_free(aBuf);
8781#endif
8782 }else{
8783 readFileContents(ctx, pCur->zPath);
8784 }
8785 }
8786 case FSDIR_COLUMN_PATH:
8787 default: {
8788 /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
8789 ** always return their values as NULL */
8790 break;
8791 }
8792 }
8793 return SQLITE_OK;
8794}
static void readFileContents(sqlite3_context *ctx, const char *zName)
Definition shell.c:8110
char * zPath
Definition shell.c:8566
#define FSDIR_COLUMN_MTIME
Definition shell.c:8059
#define FSDIR_COLUMN_DATA
Definition shell.c:8060
#define FSDIR_COLUMN_MODE
Definition shell.c:8058
struct stat sStat
Definition shell.c:8565
int nBase
Definition shell.c:8563
#define FSDIR_COLUMN_NAME
Definition shell.c:8057
#define sqlite3_result_int64
Definition sqlite3ext.h:487

References FSDIR_COLUMN_DATA, FSDIR_COLUMN_MODE, FSDIR_COLUMN_MTIME, FSDIR_COLUMN_NAME, FSDIR_COLUMN_PATH, fsdir_cursor::nBase, readFileContents(), sqlite3_free, sqlite3_malloc64, sqlite3_result_error_nomem, sqlite3_result_int64, sqlite3_result_null, sqlite3_result_text, SQLITE_NOMEM, SQLITE_OK, SQLITE_TRANSIENT, fsdir_cursor::sStat, and fsdir_cursor::zPath.

Referenced by fsdirRegister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fsdirConnect()

int fsdirConnect ( sqlite3 * db,
void * pAux,
int argc,
const char *const * argv,
sqlite3_vtab ** ppVtab,
char ** pzErr )
static
8584 {
8585 fsdir_tab *pNew = 0;
8586 int rc;
8587 (void)pAux;
8588 (void)argc;
8589 (void)argv;
8590 (void)pzErr;
8591 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
8592 if( rc==SQLITE_OK ){
8593 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
8594 if( pNew==0 ) return SQLITE_NOMEM;
8595 memset(pNew, 0, sizeof(*pNew));
8597 }
8598 *ppVtab = (sqlite3_vtab*)pNew;
8599 return rc;
8600}
#define FSDIR_SCHEMA
Definition shell.c:8056
Definition shell.c:8571
#define SQLITE_VTAB_DIRECTONLY
Definition sqlite3.c:10380

References FSDIR_SCHEMA, sqlite3_declare_vtab, sqlite3_malloc, sqlite3_vtab_config, SQLITE_NOMEM, SQLITE_OK, and SQLITE_VTAB_DIRECTONLY.

Referenced by fsdirRegister().

Here is the caller graph for this function:

◆ fsdirDisconnect()

int fsdirDisconnect ( sqlite3_vtab * pVtab)
static
8605 {
8606 sqlite3_free(pVtab);
8607 return SQLITE_OK;
8608}

References sqlite3_free, and SQLITE_OK.

Referenced by fsdirRegister().

Here is the caller graph for this function:

◆ fsdirEof()

int fsdirEof ( sqlite3_vtab_cursor * cur)
static
8811 {
8812 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8813 return (pCur->zPath==0);
8814}

References fsdir_cursor::zPath.

Referenced by fsdirRegister().

Here is the caller graph for this function:

◆ fsdirFilter()

int fsdirFilter ( sqlite3_vtab_cursor * cur,
int idxNum,
const char * idxStr,
int argc,
sqlite3_value ** argv )
static
8826 {
8827 const char *zDir = 0;
8828 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8829 (void)idxStr;
8830 fsdirResetCursor(pCur);
8831
8832 if( idxNum==0 ){
8833 fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
8834 return SQLITE_ERROR;
8835 }
8836
8837 assert( argc==idxNum && (argc==1 || argc==2) );
8838 zDir = (const char*)sqlite3_value_text(argv[0]);
8839 if( zDir==0 ){
8840 fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
8841 return SQLITE_ERROR;
8842 }
8843 if( argc==2 ){
8844 pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
8845 }
8846 if( pCur->zBase ){
8847 pCur->nBase = (int)strlen(pCur->zBase)+1;
8848 pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
8849 }else{
8850 pCur->zPath = sqlite3_mprintf("%s", zDir);
8851 }
8852
8853 if( pCur->zPath==0 ){
8854 return SQLITE_NOMEM;
8855 }
8856 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
8857 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
8858 return SQLITE_ERROR;
8859 }
8860
8861 return SQLITE_OK;
8862}
static void fsdirSetErrmsg(fsdir_cursor *pCur, const char *zFmt,...)
Definition shell.c:8661
static int fileLinkStat(const char *zPath, struct stat *pStatBuf)
Definition shell.c:8278
const char * zBase
Definition shell.c:8562

References fileLinkStat(), fsdirResetCursor(), fsdirSetErrmsg(), fsdir_cursor::nBase, sqlite3_mprintf, sqlite3_value_text, SQLITE_ERROR, SQLITE_NOMEM, SQLITE_OK, fsdir_cursor::sStat, fsdir_cursor::zBase, and fsdir_cursor::zPath.

Referenced by fsdirRegister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fsdirNext()

int fsdirNext ( sqlite3_vtab_cursor * cur)
static
8672 {
8673 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8674 mode_t m = pCur->sStat.st_mode;
8675
8676 pCur->iRowid++;
8677 if( S_ISDIR(m) ){
8678 /* Descend into this directory */
8679 int iNew = pCur->iLvl + 1;
8680 FsdirLevel *pLvl;
8681 if( iNew>=pCur->nLvl ){
8682 int nNew = iNew+1;
8683 sqlite3_int64 nByte = nNew*sizeof(FsdirLevel);
8684 FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc64(pCur->aLvl, nByte);
8685 if( aNew==0 ) return SQLITE_NOMEM;
8686 memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl));
8687 pCur->aLvl = aNew;
8688 pCur->nLvl = nNew;
8689 }
8690 pCur->iLvl = iNew;
8691 pLvl = &pCur->aLvl[iNew];
8692
8693 pLvl->zDir = pCur->zPath;
8694 pCur->zPath = 0;
8695 pLvl->pDir = opendir(pLvl->zDir);
8696 if( pLvl->pDir==0 ){
8697 fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath);
8698 return SQLITE_ERROR;
8699 }
8700 }
8701
8702 while( pCur->iLvl>=0 ){
8703 FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl];
8704 struct dirent *pEntry = readdir(pLvl->pDir);
8705 if( pEntry ){
8706 if( pEntry->d_name[0]=='.' ){
8707 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue;
8708 if( pEntry->d_name[1]=='\0' ) continue;
8709 }
8710 sqlite3_free(pCur->zPath);
8711 pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
8712 if( pCur->zPath==0 ) return SQLITE_NOMEM;
8713 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
8714 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
8715 return SQLITE_ERROR;
8716 }
8717 return SQLITE_OK;
8718 }
8719 closedir(pLvl->pDir);
8720 sqlite3_free(pLvl->zDir);
8721 pLvl->pDir = 0;
8722 pLvl->zDir = 0;
8723 pCur->iLvl--;
8724 }
8725
8726 /* EOF */
8727 sqlite3_free(pCur->zPath);
8728 pCur->zPath = 0;
8729 return SQLITE_OK;
8730}
DIR * pDir
Definition shell.c:8551
int iLvl
Definition shell.c:8559
int nLvl
Definition shell.c:8558
char * zDir
Definition shell.c:8552
FsdirLevel * aLvl
Definition shell.c:8560
sqlite3_int64 iRowid
Definition shell.c:8567
Definition shell.c:8550

References fsdir_cursor::aLvl, fileLinkStat(), fsdirSetErrmsg(), fsdir_cursor::iLvl, fsdir_cursor::iRowid, fsdir_cursor::nLvl, FsdirLevel::pDir, sqlite3_free, sqlite3_mprintf, sqlite3_realloc64, SQLITE_ERROR, SQLITE_NOMEM, SQLITE_OK, fsdir_cursor::sStat, FsdirLevel::zDir, and fsdir_cursor::zPath.

Referenced by fsdirRegister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fsdirOpen()

int fsdirOpen ( sqlite3_vtab * p,
sqlite3_vtab_cursor ** ppCursor )
static
8613 {
8614 fsdir_cursor *pCur;
8615 (void)p;
8616 pCur = sqlite3_malloc( sizeof(*pCur) );
8617 if( pCur==0 ) return SQLITE_NOMEM;
8618 memset(pCur, 0, sizeof(*pCur));
8619 pCur->iLvl = -1;
8620 *ppCursor = &pCur->base;
8621 return SQLITE_OK;
8622}
sqlite3_vtab_cursor base
Definition shell.c:8556

References fsdir_cursor::base, fsdir_cursor::iLvl, sqlite3_malloc, SQLITE_NOMEM, and SQLITE_OK.

Referenced by fsdirRegister().

Here is the caller graph for this function:

◆ fsdirRegister()

int fsdirRegister ( sqlite3 * db)
static
8944 {
8945 static sqlite3_module fsdirModule = {
8946 0, /* iVersion */
8947 0, /* xCreate */
8948 fsdirConnect, /* xConnect */
8949 fsdirBestIndex, /* xBestIndex */
8950 fsdirDisconnect, /* xDisconnect */
8951 0, /* xDestroy */
8952 fsdirOpen, /* xOpen - open a cursor */
8953 fsdirClose, /* xClose - close a cursor */
8954 fsdirFilter, /* xFilter - configure scan constraints */
8955 fsdirNext, /* xNext - advance a cursor */
8956 fsdirEof, /* xEof - check for end of scan */
8957 fsdirColumn, /* xColumn - read data */
8958 fsdirRowid, /* xRowid - read data */
8959 0, /* xUpdate */
8960 0, /* xBegin */
8961 0, /* xSync */
8962 0, /* xCommit */
8963 0, /* xRollback */
8964 0, /* xFindMethod */
8965 0, /* xRename */
8966 0, /* xSavepoint */
8967 0, /* xRelease */
8968 0, /* xRollbackTo */
8969 0, /* xShadowName */
8970 0 /* xIntegrity */
8971 };
8972
8973 int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
8974 return rc;
8975}
static int fsdirFilter(sqlite3_vtab_cursor *cur, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
Definition shell.c:8822
static int fsdirBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo)
Definition shell.c:8878
static int fsdirRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid)
Definition shell.c:8801
static int fsdirColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
Definition shell.c:8736
static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor)
Definition shell.c:8613
static int fsdirConnect(sqlite3 *db, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVtab, char **pzErr)
Definition shell.c:8578
static int fsdirClose(sqlite3_vtab_cursor *cur)
Definition shell.c:8649
static int fsdirNext(sqlite3_vtab_cursor *cur)
Definition shell.c:8672
static int fsdirEof(sqlite3_vtab_cursor *cur)
Definition shell.c:8811
static int fsdirDisconnect(sqlite3_vtab *pVtab)
Definition shell.c:8605
Definition sqlite3.c:7839

References fsdirBestIndex(), fsdirClose(), fsdirColumn(), fsdirConnect(), fsdirDisconnect(), fsdirEof(), fsdirFilter(), fsdirNext(), fsdirOpen(), fsdirRowid(), and sqlite3_create_module.

Referenced by sqlite3_fileio_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fsdirResetCursor()

void fsdirResetCursor ( fsdir_cursor * pCur)
static
8628 {
8629 int i;
8630 for(i=0; i<=pCur->iLvl; i++){
8631 FsdirLevel *pLvl = &pCur->aLvl[i];
8632 if( pLvl->pDir ) closedir(pLvl->pDir);
8633 sqlite3_free(pLvl->zDir);
8634 }
8635 sqlite3_free(pCur->zPath);
8636 sqlite3_free(pCur->aLvl);
8637 pCur->aLvl = 0;
8638 pCur->zPath = 0;
8639 pCur->zBase = 0;
8640 pCur->nBase = 0;
8641 pCur->nLvl = 0;
8642 pCur->iLvl = -1;
8643 pCur->iRowid = 1;
8644}

References fsdir_cursor::aLvl, fsdir_cursor::iLvl, fsdir_cursor::iRowid, fsdir_cursor::nBase, fsdir_cursor::nLvl, FsdirLevel::pDir, sqlite3_free, fsdir_cursor::zBase, FsdirLevel::zDir, and fsdir_cursor::zPath.

Referenced by fsdirClose(), and fsdirFilter().

Here is the caller graph for this function:

◆ fsdirRowid()

int fsdirRowid ( sqlite3_vtab_cursor * cur,
sqlite_int64 * pRowid )
static
8801 {
8802 fsdir_cursor *pCur = (fsdir_cursor*)cur;
8803 *pRowid = pCur->iRowid;
8804 return SQLITE_OK;
8805}

References fsdir_cursor::iRowid, and SQLITE_OK.

Referenced by fsdirRegister().

Here is the caller graph for this function:

◆ fsdirSetErrmsg()

void fsdirSetErrmsg ( fsdir_cursor * pCur,
const char * zFmt,
... )
static
8661 {
8662 va_list ap;
8663 va_start(ap, zFmt);
8664 pCur->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
8665 va_end(ap);
8666}

References fsdir_cursor::base, sqlite3_vtab_cursor::pVtab, sqlite3_vmprintf, and sqlite3_vtab::zErrMsg.

Referenced by fsdirFilter(), and fsdirNext().

Here is the caller graph for this function:

◆ genSeqMember()

sqlite3_int64 genSeqMember ( sqlite3_int64 smBase,
sqlite3_int64 smStep,
sqlite3_uint64 ix )
static
6308 {
6309 static const sqlite3_uint64 mxI64 =
6310 ((sqlite3_uint64)0x7fffffff)<<32 | 0xffffffff;
6311 if( ix>=mxI64 ){
6312 /* Get ix into signed i64 range. */
6313 ix -= mxI64;
6314 /* With 2's complement ALU, this next can be 1 step, but is split into
6315 * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */
6316 smBase += (mxI64/2) * smStep;
6317 smBase += (mxI64 - mxI64/2) * smStep;
6318 }
6319 /* Under UBSAN (or on 1's complement machines), must do this last term
6320 * in steps to avoid the dreaded (and harmless) signed multiply overflow. */
6321 if( ix>=2 ){
6322 sqlite3_int64 ix2 = (sqlite3_int64)ix/2;
6323 smBase += ix2*smStep;
6324 ix -= ix2;
6325 }
6326 return smBase + ((sqlite3_int64)ix)*smStep;
6327}

Referenced by setupSequence().

Here is the caller graph for this function:

◆ hash_finish()

void hash_finish ( SHA1Context * p,
char * zOut,
int bAsBinary )
static
3389 {
3390 unsigned int i;
3391 unsigned char finalcount[8];
3392 unsigned char digest[20];
3393 static const char zEncode[] = "0123456789abcdef";
3394
3395 for (i = 0; i < 8; i++){
3396 finalcount[i] = (unsigned char)((p->count[(i >= 4 ? 0 : 1)]
3397 >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
3398 }
3399 hash_step(p, (const unsigned char *)"\200", 1);
3400 while ((p->count[0] & 504) != 448){
3401 hash_step(p, (const unsigned char *)"\0", 1);
3402 }
3403 hash_step(p, finalcount, 8); /* Should cause a SHA1Transform() */
3404 for (i = 0; i < 20; i++){
3405 digest[i] = (unsigned char)((p->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
3406 }
3407 if( bAsBinary ){
3408 memcpy(zOut, digest, 20);
3409 }else{
3410 for(i=0; i<20; i++){
3411 zOut[i*2] = zEncode[(digest[i]>>4)&0xf];
3412 zOut[i*2+1] = zEncode[digest[i] & 0xf];
3413 }
3414 zOut[i*2]= 0;
3415 }
3416}
unsigned int state[5]
Definition shell.c:3225
static void hash_step(SHA1Context *p, const unsigned char *data, unsigned int len)
Definition shell.c:3340
unsigned int count[2]
Definition shell.c:3226

References SHA1Context::count, hash_step(), and SHA1Context::state.

Referenced by sha1Func(), and sha1QueryFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash_init()

void hash_init ( SHA1Context * p)
static
3329 {
3330 /* SHA1 initialization constants */
3331 p->state[0] = 0x67452301;
3332 p->state[1] = 0xEFCDAB89;
3333 p->state[2] = 0x98BADCFE;
3334 p->state[3] = 0x10325476;
3335 p->state[4] = 0xC3D2E1F0;
3336 p->count[0] = p->count[1] = 0;
3337}

References SHA1Context::count, and SHA1Context::state.

Referenced by sha1Func(), and sha1QueryFunc().

Here is the caller graph for this function:

◆ hash_step()

void hash_step ( SHA1Context * p,
const unsigned char * data,
unsigned int len )
static
3344 {
3345 unsigned int i, j;
3346
3347 j = p->count[0];
3348 if( (p->count[0] += len << 3) < j ){
3349 p->count[1] += (len>>29)+1;
3350 }
3351 j = (j >> 3) & 63;
3352 if( (j + len) > 63 ){
3353 (void)memcpy(&p->buffer[j], data, (i = 64-j));
3354 SHA1Transform(p->state, p->buffer);
3355 for(; i + 63 < len; i += 64){
3356 SHA1Transform(p->state, &data[i]);
3357 }
3358 j = 0;
3359 }else{
3360 i = 0;
3361 }
3362 (void)memcpy(&p->buffer[j], &data[i], len - i);
3363}
unsigned char buffer[64]
Definition shell.c:3227
static void SHA1Transform(unsigned int state[5], const unsigned char buffer[64])
Definition shell.c:3262

References SHA1Context::buffer, SHA1Context::count, SHA1Transform(), and SHA1Context::state.

Referenced by hash_finish(), hash_step_vformat(), sha1Func(), and sha1QueryFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash_step_vformat()

void hash_step_vformat ( SHA1Context * p,
const char * zFormat,
... )
static
3370 {
3371 va_list ap;
3372 int n;
3373 char zBuf[50];
3374 va_start(ap, zFormat);
3375 sqlite3_vsnprintf(sizeof(zBuf),zBuf,zFormat,ap);
3376 va_end(ap);
3377 n = (int)strlen(zBuf);
3378 hash_step(p, (unsigned char*)zBuf, n);
3379}
#define sqlite3_vsnprintf
Definition sqlite3ext.h:521

References hash_step(), and sqlite3_vsnprintf.

Referenced by sha1QueryFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hexDigitValue()

int hexDigitValue ( char c)
static
1404 {
1405 if( c>='0' && c<='9' ) return c - '0';
1406 if( c>='a' && c<='f' ) return c - 'a' + 10;
1407 if( c>='A' && c<='F' ) return c - 'A' + 10;
1408 return -1;
1409}

References c.

Referenced by booleanValue(), integerValue(), and resolve_backslashes().

Here is the caller graph for this function:

◆ idxAppendColDefn()

char * idxAppendColDefn ( int * pRc,
char * zIn,
IdxTable * pTab,
IdxConstraint * pCons )
static
13604 {
13605 char *zRet = zIn;
13606 IdxColumn *p = &pTab->aCol[pCons->iCol];
13607 if( zRet ) zRet = idxAppendText(pRc, zRet, ", ");
13608
13610 zRet = idxAppendText(pRc, zRet, "%Q", p->zName);
13611 }else{
13612 zRet = idxAppendText(pRc, zRet, "%s", p->zName);
13613 }
13614
13615 if( sqlite3_stricmp(p->zColl, pCons->zColl) ){
13616 if( idxIdentifierRequiresQuotes(pCons->zColl) ){
13617 zRet = idxAppendText(pRc, zRet, " COLLATE %Q", pCons->zColl);
13618 }else{
13619 zRet = idxAppendText(pRc, zRet, " COLLATE %s", pCons->zColl);
13620 }
13621 }
13622
13623 if( pCons->bDesc ){
13624 zRet = idxAppendText(pRc, zRet, " DESC");
13625 }
13626 return zRet;
13627}
char * zColl
Definition shell.c:12820
static int idxIdentifierRequiresQuotes(const char *zId)
Definition shell.c:13577
char * zName
Definition shell.c:12847
static char * idxAppendText(int *pRc, char *zIn, const char *zFmt,...)
Definition shell.c:13545
Definition shell.c:12846

References IdxTable::aCol, IdxConstraint::bDesc, IdxConstraint::iCol, idxAppendText(), idxIdentifierRequiresQuotes(), sqlite3_stricmp, IdxColumn::zColl, IdxConstraint::zColl, and IdxColumn::zName.

Referenced by idxCreateFromCons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxAppendText()

char * idxAppendText ( int * pRc,
char * zIn,
const char * zFmt,
... )
static
13545 {
13546 va_list ap;
13547 char *zAppend = 0;
13548 char *zRet = 0;
13549 int nIn = zIn ? STRLEN(zIn) : 0;
13550 int nAppend = 0;
13551 va_start(ap, zFmt);
13552 if( *pRc==SQLITE_OK ){
13553 zAppend = sqlite3_vmprintf(zFmt, ap);
13554 if( zAppend ){
13555 nAppend = STRLEN(zAppend);
13556 zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
13557 }
13558 if( zAppend && zRet ){
13559 if( nIn ) memcpy(zRet, zIn, nIn);
13560 memcpy(&zRet[nIn], zAppend, nAppend+1);
13561 }else{
13562 sqlite3_free(zRet);
13563 zRet = 0;
13564 *pRc = SQLITE_NOMEM;
13565 }
13566 sqlite3_free(zAppend);
13567 sqlite3_free(zIn);
13568 }
13569 va_end(ap);
13570 return zRet;
13571}

References sqlite3_free, sqlite3_malloc, sqlite3_vmprintf, SQLITE_NOMEM, SQLITE_OK, and STRLEN.

Referenced by idxAppendColDefn(), idxCreateVtabSchema(), idxFindIndexes(), idxPopulateOneStat1(), idxProcessOneTrigger(), and sqlite3_expert_analyze().

Here is the caller graph for this function:

◆ idxAuthCallback()

int idxAuthCallback ( void * pCtx,
int eOp,
const char * z3,
const char * z4,
const char * zDb,
const char * zTrigger )
static
14019 {
14020 int rc = SQLITE_OK;
14021 (void)z4;
14022 (void)zTrigger;
14023 if( eOp==SQLITE_INSERT || eOp==SQLITE_UPDATE || eOp==SQLITE_DELETE ){
14024 if( sqlite3_stricmp(zDb, "main")==0 ){
14025 sqlite3expert *p = (sqlite3expert*)pCtx;
14026 IdxTable *pTab;
14027 for(pTab=p->pTable; pTab; pTab=pTab->pNext){
14028 if( 0==sqlite3_stricmp(z3, pTab->zName) ) break;
14029 }
14030 if( pTab ){
14031 IdxWrite *pWrite;
14032 for(pWrite=p->pWrite; pWrite; pWrite=pWrite->pNext){
14033 if( pWrite->pTab==pTab && pWrite->eOp==eOp ) break;
14034 }
14035 if( pWrite==0 ){
14036 pWrite = idxMalloc(&rc, sizeof(IdxWrite));
14037 if( rc==SQLITE_OK ){
14038 pWrite->pTab = pTab;
14039 pWrite->eOp = eOp;
14040 pWrite->pNext = p->pWrite;
14041 p->pWrite = pWrite;
14042 }
14043 }
14044 }
14045 }
14046 }
14047 return rc;
14048}
IdxWrite * pWrite
Definition shell.c:12916
IdxTable * pTab
Definition shell.c:12864
IdxWrite * pNext
Definition shell.c:12866
IdxTable * pNext
Definition shell.c:12855
int eOp
Definition shell.c:12865
Definition shell.c:12851
Definition shell.c:12863
#define SQLITE_INSERT
Definition sqlite3.c:3788
#define SQLITE_UPDATE
Definition sqlite3.c:3793
#define SQLITE_DELETE
Definition sqlite3.c:3779

References IdxWrite::eOp, idxMalloc(), IdxTable::pNext, IdxWrite::pNext, IdxWrite::pTab, sqlite3expert::pTable, sqlite3expert::pWrite, sqlite3_stricmp, SQLITE_DELETE, SQLITE_INSERT, SQLITE_OK, SQLITE_UPDATE, and IdxTable::zName.

Referenced by sqlite3_expert_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxBuildSampleTable()

int idxBuildSampleTable ( sqlite3expert * p,
const char * zTab )
static
14532 {
14533 int rc;
14534 char *zSql;
14535
14536 rc = sqlite3_exec(p->dbv,"DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
14537 if( rc!=SQLITE_OK ) return rc;
14538
14539 zSql = sqlite3_mprintf(
14540 "CREATE TABLE temp." UNIQUE_TABLE_NAME " AS SELECT * FROM %Q", zTab
14541 );
14542 if( zSql==0 ) return SQLITE_NOMEM;
14543 rc = sqlite3_exec(p->dbv, zSql, 0, 0, 0);
14544 sqlite3_free(zSql);
14545
14546 return rc;
14547}
#define UNIQUE_TABLE_NAME
Definition shell.c:12809
sqlite3 * dbv
Definition shell.c:12913

References sqlite3expert::dbv, sqlite3_exec, sqlite3_free, sqlite3_mprintf, SQLITE_NOMEM, SQLITE_OK, and UNIQUE_TABLE_NAME.

Referenced by idxPopulateStat1().

Here is the caller graph for this function:

◆ idxConstraintFree()

void idxConstraintFree ( IdxConstraint * pConstraint)
static
13870 {
13871 IdxConstraint *pNext;
13872 IdxConstraint *p;
13873
13874 for(p=pConstraint; p; p=pNext){
13875 pNext = p->pNext;
13876 sqlite3_free(p);
13877 }
13878}

References IdxConstraint::pNext, and sqlite3_free.

Referenced by idxScanFree().

Here is the caller graph for this function:

◆ idxCreateCandidates()

int idxCreateCandidates ( sqlite3expert * p)
static
13853 {
13854 int rc = SQLITE_OK;
13855 IdxScan *pIter;
13856
13857 for(pIter=p->pScan; pIter && rc==SQLITE_OK; pIter=pIter->pNextScan){
13858 rc = idxCreateFromWhere(p, pIter, 0);
13859 if( rc==SQLITE_OK && pIter->pOrder ){
13860 rc = idxCreateFromWhere(p, pIter, pIter->pOrder);
13861 }
13862 }
13863
13864 return rc;
13865}
static int idxCreateFromWhere(sqlite3expert *p, IdxScan *pScan, IdxConstraint *pTail)
Definition shell.c:13814

References idxCreateFromWhere(), IdxScan::pNextScan, IdxScan::pOrder, sqlite3expert::pScan, and SQLITE_OK.

Referenced by sqlite3_expert_analyze().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxCreateFromCons()

int idxCreateFromCons ( sqlite3expert * p,
IdxScan * pScan,
IdxConstraint * pEq,
IdxConstraint * pTail )
static
13723 {
13724 sqlite3 *dbm = p->dbm;
13725 int rc = SQLITE_OK;
13726 if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){
13727 IdxTable *pTab = pScan->pTab;
13728 char *zCols = 0;
13729 char *zIdx = 0;
13730 IdxConstraint *pCons;
13731 unsigned int h = 0;
13732 const char *zFmt;
13733
13734 for(pCons=pEq; pCons; pCons=pCons->pLink){
13735 zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
13736 }
13737 for(pCons=pTail; pCons; pCons=pCons->pLink){
13738 zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
13739 }
13740
13741 if( rc==SQLITE_OK ){
13742 /* Hash the list of columns to come up with a name for the index */
13743 const char *zTable = pScan->pTab->zName;
13744 int quoteTable = idxIdentifierRequiresQuotes(zTable);
13745 char *zName = 0; /* Index name */
13746 int collisions = 0;
13747 do{
13748 int i;
13749 char *zFind;
13750 for(i=0; zCols[i]; i++){
13751 h += ((h<<3) + zCols[i]);
13752 }
13753 sqlite3_free(zName);
13754 zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
13755 if( zName==0 ) break;
13756 /* Is is unique among table, view and index names? */
13757 zFmt = "SELECT count(*) FROM sqlite_schema WHERE name=%Q"
13758 " AND type in ('index','table','view')";
13759 zFind = sqlite3_mprintf(zFmt, zName);
13760 i = 0;
13761 rc = sqlite3_exec(dbm, zFind, countNonzeros, &i, 0);
13762 assert(rc==SQLITE_OK);
13763 sqlite3_free(zFind);
13764 if( i==0 ){
13765 collisions = 0;
13766 break;
13767 }
13768 ++collisions;
13769 }while( collisions<50 && zName!=0 );
13770 if( collisions ){
13771 /* This return means "Gave up trying to find a unique index name." */
13773 }else if( zName==0 ){
13774 rc = SQLITE_NOMEM;
13775 }else{
13776 if( quoteTable ){
13777 zFmt = "CREATE INDEX \"%w\" ON \"%w\"(%s)";
13778 }else{
13779 zFmt = "CREATE INDEX %s ON %s(%s)";
13780 }
13781 zIdx = sqlite3_mprintf(zFmt, zName, zTable, zCols);
13782 if( !zIdx ){
13783 rc = SQLITE_NOMEM;
13784 }else{
13785 rc = sqlite3_exec(dbm, zIdx, 0, 0, p->pzErrmsg);
13786 if( rc!=SQLITE_OK ){
13788 }else{
13789 idxHashAdd(&rc, &p->hIdx, zName, zIdx);
13790 }
13791 }
13792 sqlite3_free(zName);
13793 sqlite3_free(zIdx);
13794 }
13795 }
13796
13797 sqlite3_free(zCols);
13798 }
13799 return rc;
13800}
sqlite3 * dbm
Definition shell.c:12912
IdxHash hIdx
Definition shell.c:12921
static int countNonzeros(void *pCount, int nc, char *azResults[], char *azColumns[])
Definition shell.c:13709
static int idxHashAdd(int *pRc, IdxHash *pHash, const char *zKey, const char *zVal)
Definition shell.c:12985
static int idxFindCompatible(int *pRc, sqlite3 *dbm, IdxScan *pScan, IdxConstraint *pEq, IdxConstraint *pTail)
Definition shell.c:13637
static char * idxAppendColDefn(int *pRc, char *zIn, IdxTable *pTab, IdxConstraint *pCons)
Definition shell.c:13599
char ** pzErrmsg
Definition shell.c:12919
#define SQLITE_BUSY_TIMEOUT
Definition sqlite3.c:857

References countNonzeros(), sqlite3expert::dbm, sqlite3expert::hIdx, idxAppendColDefn(), idxFindCompatible(), idxHashAdd(), idxIdentifierRequiresQuotes(), IdxConstraint::pLink, IdxScan::pTab, sqlite3expert::pzErrmsg, sqlite3_exec, sqlite3_free, sqlite3_mprintf, SQLITE_BUSY_TIMEOUT, SQLITE_NOMEM, SQLITE_OK, and IdxTable::zName.

Referenced by idxCreateFromWhere().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxCreateFromWhere()

int idxCreateFromWhere ( sqlite3expert * p,
IdxScan * pScan,
IdxConstraint * pTail )
static
13818 {
13819 IdxConstraint *p1 = 0;
13820 IdxConstraint *pCon;
13821 int rc;
13822
13823 /* Gather up all the == constraints. */
13824 for(pCon=pScan->pEq; pCon; pCon=pCon->pNext){
13825 if( !idxFindConstraint(p1, pCon) && !idxFindConstraint(pTail, pCon) ){
13826 pCon->pLink = p1;
13827 p1 = pCon;
13828 }
13829 }
13830
13831 /* Create an index using the == constraints collected above. And the
13832 ** range constraint/ORDER BY terms passed in by the caller, if any. */
13833 rc = idxCreateFromCons(p, pScan, p1, pTail);
13834
13835 /* If no range/ORDER BY passed by the caller, create a version of the
13836 ** index for each range constraint. */
13837 if( pTail==0 ){
13838 for(pCon=pScan->pRange; rc==SQLITE_OK && pCon; pCon=pCon->pNext){
13839 assert( pCon->pLink==0 );
13840 if( !idxFindConstraint(p1, pCon) && !idxFindConstraint(pTail, pCon) ){
13841 rc = idxCreateFromCons(p, pScan, p1, pCon);
13842 }
13843 }
13844 }
13845
13846 return rc;
13847}
static int idxFindConstraint(IdxConstraint *pList, IdxConstraint *p)
Definition shell.c:13806
static int idxCreateFromCons(sqlite3expert *p, IdxScan *pScan, IdxConstraint *pEq, IdxConstraint *pTail)
Definition shell.c:13718

References idxCreateFromCons(), idxFindConstraint(), IdxScan::pEq, IdxConstraint::pLink, IdxConstraint::pNext, IdxScan::pRange, and SQLITE_OK.

Referenced by idxCreateCandidates().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxCreateVtabSchema()

int idxCreateVtabSchema ( sqlite3expert * p,
char ** pzErrmsg )
static
14211 {
14212 int rc = idxRegisterVtab(p);
14213 sqlite3_stmt *pSchema = 0;
14214
14215 /* For each table in the main db schema:
14216 **
14217 ** 1) Add an entry to the p->pTable list, and
14218 ** 2) Create the equivalent virtual table in dbv.
14219 */
14220 rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg,
14221 "SELECT type, name, sql, 1, "
14222 " substr(sql,1,14)=='create virtual' COLLATE nocase "
14223 "FROM sqlite_schema "
14224 "WHERE type IN ('table','view') AND "
14225 " substr(name,1,7)!='sqlite_' COLLATE nocase "
14226 " UNION ALL "
14227 "SELECT type, name, sql, 2, 0 FROM sqlite_schema "
14228 "WHERE type = 'trigger'"
14229 " AND tbl_name IN(SELECT name FROM sqlite_schema WHERE type = 'view') "
14230 "ORDER BY 4, 5 DESC, 1"
14231 );
14232 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSchema) ){
14233 const char *zType = (const char*)sqlite3_column_text(pSchema, 0);
14234 const char *zName = (const char*)sqlite3_column_text(pSchema, 1);
14235 const char *zSql = (const char*)sqlite3_column_text(pSchema, 2);
14236 int bVirtual = sqlite3_column_int(pSchema, 4);
14237 int bExists = 0;
14238
14239 if( zType==0 || zName==0 ) continue;
14240 rc = expertDbContainsObject(p->dbv, zName, &bExists);
14241 if( rc || bExists ) continue;
14242
14243 if( zType[0]=='v' || zType[1]=='r' || bVirtual ){
14244 /* A view. Or a trigger on a view. */
14245 if( zSql ) rc = expertSchemaSql(p->dbv, zSql, pzErrmsg);
14246 }else{
14247 IdxTable *pTab;
14248 rc = idxGetTableInfo(p->db, zName, &pTab, pzErrmsg);
14249 if( rc==SQLITE_OK && ALWAYS(pTab!=0) ){
14250 int i;
14251 char *zInner = 0;
14252 char *zOuter = 0;
14253 pTab->pNext = p->pTable;
14254 p->pTable = pTab;
14255
14256 /* The statement the vtab will pass to sqlite3_declare_vtab() */
14257 zInner = idxAppendText(&rc, 0, "CREATE TABLE x(");
14258 for(i=0; i<pTab->nCol; i++){
14259 zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s",
14260 (i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl
14261 );
14262 }
14263 zInner = idxAppendText(&rc, zInner, ")");
14264
14265 /* The CVT statement to create the vtab */
14266 zOuter = idxAppendText(&rc, 0,
14267 "CREATE VIRTUAL TABLE %Q USING expert(%Q)", zName, zInner
14268 );
14269 if( rc==SQLITE_OK ){
14270 rc = sqlite3_exec(p->dbv, zOuter, 0, 0, pzErrmsg);
14271 }
14272 sqlite3_free(zInner);
14273 sqlite3_free(zOuter);
14274 }
14275 }
14276 }
14277 idxFinalize(&rc, pSchema);
14278 return rc;
14279}
static int expertDbContainsObject(sqlite3 *db, const char *zTab, int *pbContains)
Definition shell.c:14158
static int idxPrepareStmt(sqlite3 *db, sqlite3_stmt **ppStmt, char **pzErrmsg, const char *zSql)
Definition shell.c:13079
#define ALWAYS(X)
Definition shell.c:12781
static int idxGetTableInfo(sqlite3 *db, const char *zTab, IdxTable **ppOut, char **pzErrmsg)
Definition shell.c:13448
static int idxRegisterVtab(sqlite3expert *p)
Definition shell.c:13394
int nCol
Definition shell.c:12852
static int expertSchemaSql(sqlite3 *db, const char *zSql, char **pzErr)
Definition shell.c:14193
static void idxFinalize(int *pRc, sqlite3_stmt *pStmt)
Definition shell.c:13433

References IdxTable::aCol, ALWAYS, sqlite3expert::db, sqlite3expert::dbv, expertDbContainsObject(), expertSchemaSql(), idxAppendText(), idxFinalize(), idxGetTableInfo(), idxPrepareStmt(), idxRegisterVtab(), IdxTable::nCol, IdxTable::pNext, sqlite3expert::pTable, sqlite3_column_int, sqlite3_column_text, sqlite3_exec, sqlite3_free, sqlite3_step, SQLITE_OK, SQLITE_ROW, IdxColumn::zColl, and IdxColumn::zName.

Referenced by sqlite3_expert_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxDatabaseError()

void idxDatabaseError ( sqlite3 * db,
char ** pzErrmsg )
static
13072 {
13073 *pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
13074}

References sqlite3_errmsg, and sqlite3_mprintf.

Referenced by idxPrepareStmt(), idxProcessOneTrigger(), and sqlite3_expert_sql().

Here is the caller graph for this function:

◆ idxFinalize()

void idxFinalize ( int * pRc,
sqlite3_stmt * pStmt )
static
13433 {
13434 int rc = sqlite3_finalize(pStmt);
13435 if( *pRc==SQLITE_OK ) *pRc = rc;
13436}

References sqlite3_finalize, and SQLITE_OK.

Referenced by idxCreateVtabSchema(), idxFindCompatible(), idxFindIndexes(), idxGetTableInfo(), idxLargestIndex(), idxPopulateOneStat1(), idxPopulateStat1(), idxProcessOneTrigger(), and sqlite3_expert_new().

Here is the caller graph for this function:

◆ idxFindCompatible()

int idxFindCompatible ( int * pRc,
sqlite3 * dbm,
IdxScan * pScan,
IdxConstraint * pEq,
IdxConstraint * pTail )
static
13643 {
13644 const char *zTbl = pScan->pTab->zName;
13645 sqlite3_stmt *pIdxList = 0;
13646 IdxConstraint *pIter;
13647 int nEq = 0; /* Number of elements in pEq */
13648 int rc;
13649
13650 /* Count the elements in list pEq */
13651 for(pIter=pEq; pIter; pIter=pIter->pLink) nEq++;
13652
13653 rc = idxPrintfPrepareStmt(dbm, &pIdxList, 0, "PRAGMA index_list=%Q", zTbl);
13654 while( rc==SQLITE_OK && sqlite3_step(pIdxList)==SQLITE_ROW ){
13655 int bMatch = 1;
13656 IdxConstraint *pT = pTail;
13657 sqlite3_stmt *pInfo = 0;
13658 const char *zIdx = (const char*)sqlite3_column_text(pIdxList, 1);
13659 if( zIdx==0 ) continue;
13660
13661 /* Zero the IdxConstraint.bFlag values in the pEq list */
13662 for(pIter=pEq; pIter; pIter=pIter->pLink) pIter->bFlag = 0;
13663
13664 rc = idxPrintfPrepareStmt(dbm, &pInfo, 0, "PRAGMA index_xInfo=%Q", zIdx);
13665 while( rc==SQLITE_OK && sqlite3_step(pInfo)==SQLITE_ROW ){
13666 int iIdx = sqlite3_column_int(pInfo, 0);
13667 int iCol = sqlite3_column_int(pInfo, 1);
13668 const char *zColl = (const char*)sqlite3_column_text(pInfo, 4);
13669
13670 if( iIdx<nEq ){
13671 for(pIter=pEq; pIter; pIter=pIter->pLink){
13672 if( pIter->bFlag ) continue;
13673 if( pIter->iCol!=iCol ) continue;
13674 if( sqlite3_stricmp(pIter->zColl, zColl) ) continue;
13675 pIter->bFlag = 1;
13676 break;
13677 }
13678 if( pIter==0 ){
13679 bMatch = 0;
13680 break;
13681 }
13682 }else{
13683 if( pT ){
13684 if( pT->iCol!=iCol || sqlite3_stricmp(pT->zColl, zColl) ){
13685 bMatch = 0;
13686 break;
13687 }
13688 pT = pT->pLink;
13689 }
13690 }
13691 }
13692 idxFinalize(&rc, pInfo);
13693
13694 if( rc==SQLITE_OK && bMatch ){
13695 sqlite3_finalize(pIdxList);
13696 return 1;
13697 }
13698 }
13699 idxFinalize(&rc, pIdxList);
13700
13701 *pRc = rc;
13702 return 0;
13703}
int bFlag
Definition shell.c:12823

References IdxConstraint::bFlag, IdxConstraint::iCol, idxFinalize(), idxPrintfPrepareStmt(), IdxConstraint::pLink, IdxScan::pTab, sqlite3_column_int, sqlite3_column_text, sqlite3_finalize, sqlite3_step, sqlite3_stricmp, SQLITE_OK, SQLITE_ROW, IdxConstraint::zColl, and IdxTable::zName.

Referenced by idxCreateFromCons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxFindConstraint()

int idxFindConstraint ( IdxConstraint * pList,
IdxConstraint * p )
static
13806 {
13807 IdxConstraint *pCmp;
13808 for(pCmp=pList; pCmp; pCmp=pCmp->pLink){
13809 if( p->iCol==pCmp->iCol ) return 1;
13810 }
13811 return 0;
13812}

References IdxConstraint::iCol, and IdxConstraint::pLink.

Referenced by idxCreateFromWhere().

Here is the caller graph for this function:

◆ idxFindIndexes()

int idxFindIndexes ( sqlite3expert * p,
char ** pzErr )
static
13945 {
13946 IdxStatement *pStmt;
13947 sqlite3 *dbm = p->dbm;
13948 int rc = SQLITE_OK;
13949
13950 IdxHash hIdx;
13951 idxHashInit(&hIdx);
13952
13953 for(pStmt=p->pStatement; rc==SQLITE_OK && pStmt; pStmt=pStmt->pNext){
13954 IdxHashEntry *pEntry;
13955 sqlite3_stmt *pExplain = 0;
13956 idxHashClear(&hIdx);
13957 rc = idxPrintfPrepareStmt(dbm, &pExplain, pzErr,
13958 "EXPLAIN QUERY PLAN %s", pStmt->zSql
13959 );
13960 while( rc==SQLITE_OK && sqlite3_step(pExplain)==SQLITE_ROW ){
13961 /* int iId = sqlite3_column_int(pExplain, 0); */
13962 /* int iParent = sqlite3_column_int(pExplain, 1); */
13963 /* int iNotUsed = sqlite3_column_int(pExplain, 2); */
13964 const char *zDetail = (const char*)sqlite3_column_text(pExplain, 3);
13965 int nDetail;
13966 int i;
13967
13968 if( !zDetail ) continue;
13969 nDetail = STRLEN(zDetail);
13970
13971 for(i=0; i<nDetail; i++){
13972 const char *zIdx = 0;
13973 if( i+13<nDetail && memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){
13974 zIdx = &zDetail[i+13];
13975 }else if( i+22<nDetail
13976 && memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0
13977 ){
13978 zIdx = &zDetail[i+22];
13979 }
13980 if( zIdx ){
13981 const char *zSql;
13982 int nIdx = 0;
13983 while( zIdx[nIdx]!='\0' && (zIdx[nIdx]!=' ' || zIdx[nIdx+1]!='(') ){
13984 nIdx++;
13985 }
13986 zSql = idxHashSearch(&p->hIdx, zIdx, nIdx);
13987 if( zSql ){
13988 idxHashAdd(&rc, &hIdx, zSql, 0);
13989 if( rc ) goto find_indexes_out;
13990 }
13991 break;
13992 }
13993 }
13994
13995 if( zDetail[0]!='-' ){
13996 pStmt->zEQP = idxAppendText(&rc, pStmt->zEQP, "%s\n", zDetail);
13997 }
13998 }
13999
14000 for(pEntry=hIdx.pFirst; pEntry; pEntry=pEntry->pNext){
14001 pStmt->zIdx = idxAppendText(&rc, pStmt->zIdx, "%s;\n", pEntry->zKey);
14002 }
14003
14004 idxFinalize(&rc, pExplain);
14005 }
14006
14007 find_indexes_out:
14008 idxHashClear(&hIdx);
14009 return rc;
14010}
char * zIdx
Definition shell.c:12876
static const char * idxHashSearch(IdxHash *pHash, const char *zKey, int nKey)
Definition shell.c:13042
IdxStatement * pNext
Definition shell.c:12878
IdxHashEntry * pFirst
Definition shell.c:12902
char * zKey
Definition shell.c:12895
static void idxHashInit(IdxHash *pHash)
Definition shell.c:12946
IdxHashEntry * pNext
Definition shell.c:12899
IdxStatement * pStatement
Definition shell.c:12917
static void idxHashClear(IdxHash *pHash)
Definition shell.c:12953
char * zSql
Definition shell.c:12875
char * zEQP
Definition shell.c:12877
Definition shell.c:12901
Definition shell.c:12894
Definition shell.c:12873

References sqlite3expert::dbm, sqlite3expert::hIdx, idxAppendText(), idxFinalize(), idxHashAdd(), idxHashClear(), idxHashInit(), idxHashSearch(), idxPrintfPrepareStmt(), IdxHash::pFirst, IdxHashEntry::pNext, IdxStatement::pNext, sqlite3expert::pStatement, sqlite3_column_text, sqlite3_step, SQLITE_OK, SQLITE_ROW, STRLEN, IdxStatement::zEQP, IdxStatement::zIdx, IdxHashEntry::zKey, and IdxStatement::zSql.

Referenced by sqlite3_expert_analyze().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxGetTableInfo()

int idxGetTableInfo ( sqlite3 * db,
const char * zTab,
IdxTable ** ppOut,
char ** pzErrmsg )
static
13453 {
13454 sqlite3_stmt *p1 = 0;
13455 int nCol = 0;
13456 int nTab;
13457 int nByte;
13458 IdxTable *pNew = 0;
13459 int rc, rc2;
13460 char *pCsr = 0;
13461 int nPk = 0;
13462
13463 *ppOut = 0;
13464 if( zTab==0 ) return SQLITE_ERROR;
13465 nTab = STRLEN(zTab);
13466 nByte = sizeof(IdxTable) + nTab + 1;
13467 rc = idxPrintfPrepareStmt(db, &p1, pzErrmsg, "PRAGMA table_xinfo=%Q", zTab);
13468 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
13469 const char *zCol = (const char*)sqlite3_column_text(p1, 1);
13470 const char *zColSeq = 0;
13471 if( zCol==0 ){
13472 rc = SQLITE_ERROR;
13473 break;
13474 }
13475 nByte += 1 + STRLEN(zCol);
13477 db, "main", zTab, zCol, 0, &zColSeq, 0, 0, 0
13478 );
13479 if( zColSeq==0 ) zColSeq = "binary";
13480 nByte += 1 + STRLEN(zColSeq);
13481 nCol++;
13482 nPk += (sqlite3_column_int(p1, 5)>0);
13483 }
13484 rc2 = sqlite3_reset(p1);
13485 if( rc==SQLITE_OK ) rc = rc2;
13486
13487 nByte += sizeof(IdxColumn) * nCol;
13488 if( rc==SQLITE_OK ){
13489 pNew = idxMalloc(&rc, nByte);
13490 }
13491 if( rc==SQLITE_OK ){
13492 pNew->aCol = (IdxColumn*)&pNew[1];
13493 pNew->nCol = nCol;
13494 pCsr = (char*)&pNew->aCol[nCol];
13495 }
13496
13497 nCol = 0;
13498 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
13499 const char *zCol = (const char*)sqlite3_column_text(p1, 1);
13500 const char *zColSeq = 0;
13501 int nCopy;
13502 if( zCol==0 ) continue;
13503 nCopy = STRLEN(zCol) + 1;
13504 pNew->aCol[nCol].zName = pCsr;
13505 pNew->aCol[nCol].iPk = (sqlite3_column_int(p1, 5)==1 && nPk==1);
13506 memcpy(pCsr, zCol, nCopy);
13507 pCsr += nCopy;
13508
13510 db, "main", zTab, zCol, 0, &zColSeq, 0, 0, 0
13511 );
13512 if( rc==SQLITE_OK ){
13513 if( zColSeq==0 ) zColSeq = "binary";
13514 nCopy = STRLEN(zColSeq) + 1;
13515 pNew->aCol[nCol].zColl = pCsr;
13516 memcpy(pCsr, zColSeq, nCopy);
13517 pCsr += nCopy;
13518 }
13519
13520 nCol++;
13521 }
13522 idxFinalize(&rc, p1);
13523
13524 if( rc!=SQLITE_OK ){
13525 sqlite3_free(pNew);
13526 pNew = 0;
13527 }else if( ALWAYS(pNew!=0) ){
13528 pNew->zName = pCsr;
13529 if( ALWAYS(pNew->zName!=0) ) memcpy(pNew->zName, zTab, nTab+1);
13530 }
13531
13532 *ppOut = pNew;
13533 return rc;
13534}

References IdxTable::aCol, ALWAYS, idxFinalize(), idxMalloc(), idxPrintfPrepareStmt(), IdxColumn::iPk, IdxTable::nCol, sqlite3_column_int, sqlite3_column_text, sqlite3_free, sqlite3_reset, sqlite3_step, sqlite3_table_column_metadata, SQLITE_ERROR, SQLITE_OK, SQLITE_ROW, STRLEN, IdxColumn::zColl, IdxColumn::zName, and IdxTable::zName.

Referenced by idxCreateVtabSchema().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxHashAdd()

int idxHashAdd ( int * pRc,
IdxHash * pHash,
const char * zKey,
const char * zVal )
static
12990 {
12991 int nKey = STRLEN(zKey);
12992 int iHash = idxHashString(zKey, nKey);
12993 int nVal = (zVal ? STRLEN(zVal) : 0);
12994 IdxHashEntry *pEntry;
12995 assert( iHash>=0 );
12996 for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){
12997 if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){
12998 return 1;
12999 }
13000 }
13001 pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + nKey+1 + nVal+1);
13002 if( pEntry ){
13003 pEntry->zKey = (char*)&pEntry[1];
13004 memcpy(pEntry->zKey, zKey, nKey);
13005 if( zVal ){
13006 pEntry->zVal = &pEntry->zKey[nKey+1];
13007 memcpy(pEntry->zVal, zVal, nVal);
13008 }
13009 pEntry->pHashNext = pHash->aHash[iHash];
13010 pHash->aHash[iHash] = pEntry;
13011
13012 pEntry->pNext = pHash->pFirst;
13013 pHash->pFirst = pEntry;
13014 }
13015 return 0;
13016}
static int idxHashString(const char *z, int n)
Definition shell.c:12971
IdxHashEntry * pHashNext
Definition shell.c:12898
IdxHashEntry * aHash[1023]
Definition shell.c:12903
char * zVal
Definition shell.c:12896

References IdxHash::aHash, idxHashString(), idxMalloc(), IdxHash::pFirst, IdxHashEntry::pHashNext, IdxHashEntry::pNext, STRLEN, IdxHashEntry::zKey, and IdxHashEntry::zVal.

Referenced by idxCreateFromCons(), and idxFindIndexes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxHashClear()

void idxHashClear ( IdxHash * pHash)
static
12953 {
12954 int i;
12955 for(i=0; i<IDX_HASH_SIZE; i++){
12956 IdxHashEntry *pEntry;
12957 IdxHashEntry *pNext;
12958 for(pEntry=pHash->aHash[i]; pEntry; pEntry=pNext){
12959 pNext = pEntry->pHashNext;
12960 sqlite3_free(pEntry->zVal2);
12961 sqlite3_free(pEntry);
12962 }
12963 }
12964 memset(pHash, 0, sizeof(IdxHash));
12965}
char * zVal2
Definition shell.c:12897
#define IDX_HASH_SIZE
Definition shell.c:12891

References IdxHash::aHash, IDX_HASH_SIZE, IdxHashEntry::pHashNext, sqlite3_free, and IdxHashEntry::zVal2.

Referenced by idxFindIndexes(), and sqlite3_expert_destroy().

Here is the caller graph for this function:

◆ idxHashFind()

IdxHashEntry * idxHashFind ( IdxHash * pHash,
const char * zKey,
int nKey )
static
13022 {
13023 int iHash;
13024 IdxHashEntry *pEntry;
13025 if( nKey<0 ) nKey = STRLEN(zKey);
13026 iHash = idxHashString(zKey, nKey);
13027 assert( iHash>=0 );
13028 for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){
13029 if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){
13030 return pEntry;
13031 }
13032 }
13033 return 0;
13034}

References IdxHash::aHash, idxHashString(), IdxHashEntry::pHashNext, STRLEN, and IdxHashEntry::zKey.

Referenced by idxHashSearch(), and idxPopulateOneStat1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxHashInit()

void idxHashInit ( IdxHash * pHash)
static
12946 {
12947 memset(pHash, 0, sizeof(IdxHash));
12948}

Referenced by idxFindIndexes().

Here is the caller graph for this function:

◆ idxHashSearch()

const char * idxHashSearch ( IdxHash * pHash,
const char * zKey,
int nKey )
static
13042 {
13043 IdxHashEntry *pEntry = idxHashFind(pHash, zKey, nKey);
13044 if( pEntry ) return pEntry->zVal;
13045 return 0;
13046}
static IdxHashEntry * idxHashFind(IdxHash *pHash, const char *zKey, int nKey)
Definition shell.c:13022

References idxHashFind(), and IdxHashEntry::zVal.

Referenced by idxFindIndexes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxHashString()

int idxHashString ( const char * z,
int n )
static
12971 {
12972 unsigned int ret = 0;
12973 int i;
12974 for(i=0; i<n; i++){
12975 ret += (ret<<3) + (unsigned char)(z[i]);
12976 }
12977 return (int)(ret % IDX_HASH_SIZE);
12978}

References IDX_HASH_SIZE.

Referenced by idxHashAdd(), and idxHashFind().

Here is the caller graph for this function:

◆ idxIdentifierRequiresQuotes()

int idxIdentifierRequiresQuotes ( const char * zId)
static
13577 {
13578 int i;
13579 int nId = STRLEN(zId);
13580
13581 if( sqlite3_keyword_check(zId, nId) ) return 1;
13582
13583 for(i=0; zId[i]; i++){
13584 if( !(zId[i]=='_')
13585 && !(zId[i]>='0' && zId[i]<='9')
13586 && !(zId[i]>='a' && zId[i]<='z')
13587 && !(zId[i]>='A' && zId[i]<='Z')
13588 ){
13589 return 1;
13590 }
13591 }
13592 return 0;
13593}
#define sqlite3_keyword_check
Definition sqlite3ext.h:644

References sqlite3_keyword_check, and STRLEN.

Referenced by idxAppendColDefn(), and idxCreateFromCons().

Here is the caller graph for this function:

◆ idxLargestIndex()

int idxLargestIndex ( sqlite3 * db,
int * pnMax,
char ** pzErr )
static
14405 {
14406 int rc = SQLITE_OK;
14407 const char *zMax =
14408 "SELECT max(i.seqno) FROM "
14409 " sqlite_schema AS s, "
14410 " pragma_index_list(s.name) AS l, "
14411 " pragma_index_info(l.name) AS i "
14412 "WHERE s.type = 'table'";
14413 sqlite3_stmt *pMax = 0;
14414
14415 *pnMax = 0;
14416 rc = idxPrepareStmt(db, &pMax, pzErr, zMax);
14417 if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pMax) ){
14418 *pnMax = sqlite3_column_int(pMax, 0) + 1;
14419 }
14420 idxFinalize(&rc, pMax);
14421
14422 return rc;
14423}

References idxFinalize(), idxPrepareStmt(), sqlite3_column_int, sqlite3_step, SQLITE_OK, and SQLITE_ROW.

Referenced by idxPopulateStat1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxMalloc()

void * idxMalloc ( int * pRc,
int nByte )
static
12930 {
12931 void *pRet;
12932 assert( *pRc==SQLITE_OK );
12933 assert( nByte>0 );
12934 pRet = sqlite3_malloc(nByte);
12935 if( pRet ){
12936 memset(pRet, 0, nByte);
12937 }else{
12938 *pRc = SQLITE_NOMEM;
12939 }
12940 return pRet;
12941}

References sqlite3_malloc, SQLITE_NOMEM, and SQLITE_OK.

Referenced by expertBestIndex(), expertConnect(), expertOpen(), idxAuthCallback(), idxGetTableInfo(), idxHashAdd(), idxNewConstraint(), idxPopulateOneStat1(), idxPopulateStat1(), sqlite3_expert_new(), and sqlite3_expert_sql().

Here is the caller graph for this function:

◆ idxNewConstraint()

IdxConstraint * idxNewConstraint ( int * pRc,
const char * zColl )
static
13052 {
13053 IdxConstraint *pNew;
13054 int nColl = STRLEN(zColl);
13055
13056 assert( *pRc==SQLITE_OK );
13057 pNew = (IdxConstraint*)idxMalloc(pRc, sizeof(IdxConstraint) * nColl + 1);
13058 if( pNew ){
13059 pNew->zColl = (char*)&pNew[1];
13060 memcpy(pNew->zColl, zColl, nColl+1);
13061 }
13062 return pNew;
13063}

References idxMalloc(), SQLITE_OK, STRLEN, and IdxConstraint::zColl.

Referenced by expertBestIndex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxPopulateOneStat1()

int idxPopulateOneStat1 ( sqlite3expert * p,
sqlite3_stmt * pIndexXInfo,
sqlite3_stmt * pWriteStat,
const char * zTab,
const char * zIdx,
char ** pzErr )
static
14432 {
14433 char *zCols = 0;
14434 char *zOrder = 0;
14435 char *zQuery = 0;
14436 int nCol = 0;
14437 int i;
14438 sqlite3_stmt *pQuery = 0;
14439 int *aStat = 0;
14440 int rc = SQLITE_OK;
14441
14442 assert( p->iSample>0 );
14443
14444 /* Formulate the query text */
14445 sqlite3_bind_text(pIndexXInfo, 1, zIdx, -1, SQLITE_STATIC);
14446 while( SQLITE_OK==rc && SQLITE_ROW==sqlite3_step(pIndexXInfo) ){
14447 const char *zComma = zCols==0 ? "" : ", ";
14448 const char *zName = (const char*)sqlite3_column_text(pIndexXInfo, 0);
14449 const char *zColl = (const char*)sqlite3_column_text(pIndexXInfo, 1);
14450 if( zName==0 ){
14451 /* This index contains an expression. Ignore it. */
14452 sqlite3_free(zCols);
14453 sqlite3_free(zOrder);
14454 return sqlite3_reset(pIndexXInfo);
14455 }
14456 zCols = idxAppendText(&rc, zCols,
14457 "%sx.%Q IS sqlite_expert_rem(%d, x.%Q) COLLATE %s",
14458 zComma, zName, nCol, zName, zColl
14459 );
14460 zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol);
14461 }
14462 sqlite3_reset(pIndexXInfo);
14463 if( rc==SQLITE_OK ){
14464 if( p->iSample==100 ){
14465 zQuery = sqlite3_mprintf(
14466 "SELECT %s FROM %Q x ORDER BY %s", zCols, zTab, zOrder
14467 );
14468 }else{
14469 zQuery = sqlite3_mprintf(
14470 "SELECT %s FROM temp."UNIQUE_TABLE_NAME" x ORDER BY %s", zCols, zOrder
14471 );
14472 }
14473 }
14474 sqlite3_free(zCols);
14475 sqlite3_free(zOrder);
14476
14477 /* Formulate the query text */
14478 if( rc==SQLITE_OK ){
14479 sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv);
14480 rc = idxPrepareStmt(dbrem, &pQuery, pzErr, zQuery);
14481 }
14482 sqlite3_free(zQuery);
14483
14484 if( rc==SQLITE_OK ){
14485 aStat = (int*)idxMalloc(&rc, sizeof(int)*(nCol+1));
14486 }
14487 if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pQuery) ){
14488 IdxHashEntry *pEntry;
14489 char *zStat = 0;
14490 for(i=0; i<=nCol; i++) aStat[i] = 1;
14491 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pQuery) ){
14492 aStat[0]++;
14493 for(i=0; i<nCol; i++){
14494 if( sqlite3_column_int(pQuery, i)==0 ) break;
14495 }
14496 for(/*no-op*/; i<nCol; i++){
14497 aStat[i+1]++;
14498 }
14499 }
14500
14501 if( rc==SQLITE_OK ){
14502 int s0 = aStat[0];
14503 zStat = sqlite3_mprintf("%d", s0);
14504 if( zStat==0 ) rc = SQLITE_NOMEM;
14505 for(i=1; rc==SQLITE_OK && i<=nCol; i++){
14506 zStat = idxAppendText(&rc, zStat, " %d", (s0+aStat[i]/2) / aStat[i]);
14507 }
14508 }
14509
14510 if( rc==SQLITE_OK ){
14511 sqlite3_bind_text(pWriteStat, 1, zTab, -1, SQLITE_STATIC);
14512 sqlite3_bind_text(pWriteStat, 2, zIdx, -1, SQLITE_STATIC);
14513 sqlite3_bind_text(pWriteStat, 3, zStat, -1, SQLITE_STATIC);
14514 sqlite3_step(pWriteStat);
14515 rc = sqlite3_reset(pWriteStat);
14516 }
14517
14518 pEntry = idxHashFind(&p->hIdx, zIdx, STRLEN(zIdx));
14519 if( pEntry ){
14520 assert( pEntry->zVal2==0 );
14521 pEntry->zVal2 = zStat;
14522 }else{
14523 sqlite3_free(zStat);
14524 }
14525 }
14526 sqlite3_free(aStat);
14527 idxFinalize(&rc, pQuery);
14528
14529 return rc;
14530}
int iSample
Definition shell.c:12910

References sqlite3expert::db, sqlite3expert::dbv, sqlite3expert::hIdx, idxAppendText(), idxFinalize(), idxHashFind(), idxMalloc(), idxPrepareStmt(), sqlite3expert::iSample, sqlite3_bind_text, sqlite3_column_int, sqlite3_column_text, sqlite3_free, sqlite3_mprintf, sqlite3_reset, sqlite3_step, SQLITE_NOMEM, SQLITE_OK, SQLITE_ROW, SQLITE_STATIC, STRLEN, UNIQUE_TABLE_NAME, and IdxHashEntry::zVal2.

Referenced by idxPopulateStat1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxPopulateStat1()

int idxPopulateStat1 ( sqlite3expert * p,
char ** pzErr )
static
14556 {
14557 int rc = SQLITE_OK;
14558 int nMax =0;
14559 struct IdxRemCtx *pCtx = 0;
14560 struct IdxSampleCtx samplectx;
14561 int i;
14562 i64 iPrev = -100000;
14563 sqlite3_stmt *pAllIndex = 0;
14564 sqlite3_stmt *pIndexXInfo = 0;
14565 sqlite3_stmt *pWrite = 0;
14566
14567 const char *zAllIndex =
14568 "SELECT s.rowid, s.name, l.name FROM "
14569 " sqlite_schema AS s, "
14570 " pragma_index_list(s.name) AS l "
14571 "WHERE s.type = 'table'";
14572 const char *zIndexXInfo =
14573 "SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
14574 const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
14575
14576 /* If iSample==0, no sqlite_stat1 data is required. */
14577 if( p->iSample==0 ) return SQLITE_OK;
14578
14579 rc = idxLargestIndex(p->dbm, &nMax, pzErr);
14580 if( nMax<=0 || rc!=SQLITE_OK ) return rc;
14581
14582 rc = sqlite3_exec(p->dbm, "ANALYZE; PRAGMA writable_schema=1", 0, 0, 0);
14583
14584 if( rc==SQLITE_OK ){
14585 int nByte = sizeof(struct IdxRemCtx) + (sizeof(struct IdxRemSlot) * nMax);
14586 pCtx = (struct IdxRemCtx*)idxMalloc(&rc, nByte);
14587 }
14588
14589 if( rc==SQLITE_OK ){
14590 sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv);
14591 rc = sqlite3_create_function(dbrem, "sqlite_expert_rem",
14592 2, SQLITE_UTF8, (void*)pCtx, idxRemFunc, 0, 0
14593 );
14594 }
14595 if( rc==SQLITE_OK ){
14596 rc = sqlite3_create_function(p->db, "sqlite_expert_sample",
14597 0, SQLITE_UTF8, (void*)&samplectx, idxSampleFunc, 0, 0
14598 );
14599 }
14600
14601 if( rc==SQLITE_OK ){
14602 pCtx->nSlot = nMax+1;
14603 rc = idxPrepareStmt(p->dbm, &pAllIndex, pzErr, zAllIndex);
14604 }
14605 if( rc==SQLITE_OK ){
14606 rc = idxPrepareStmt(p->dbm, &pIndexXInfo, pzErr, zIndexXInfo);
14607 }
14608 if( rc==SQLITE_OK ){
14609 rc = idxPrepareStmt(p->dbm, &pWrite, pzErr, zWrite);
14610 }
14611
14612 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pAllIndex) ){
14613 i64 iRowid = sqlite3_column_int64(pAllIndex, 0);
14614 const char *zTab = (const char*)sqlite3_column_text(pAllIndex, 1);
14615 const char *zIdx = (const char*)sqlite3_column_text(pAllIndex, 2);
14616 if( zTab==0 || zIdx==0 ) continue;
14617 if( p->iSample<100 && iPrev!=iRowid ){
14618 samplectx.target = (double)p->iSample / 100.0;
14619 samplectx.iTarget = p->iSample;
14620 samplectx.nRow = 0.0;
14621 samplectx.nRet = 0.0;
14622 rc = idxBuildSampleTable(p, zTab);
14623 if( rc!=SQLITE_OK ) break;
14624 }
14625 rc = idxPopulateOneStat1(p, pIndexXInfo, pWrite, zTab, zIdx, pzErr);
14626 iPrev = iRowid;
14627 }
14628 if( rc==SQLITE_OK && p->iSample<100 ){
14629 rc = sqlite3_exec(p->dbv,
14630 "DROP TABLE IF EXISTS temp." UNIQUE_TABLE_NAME, 0,0,0
14631 );
14632 }
14633
14634 idxFinalize(&rc, pAllIndex);
14635 idxFinalize(&rc, pIndexXInfo);
14636 idxFinalize(&rc, pWrite);
14637
14638 if( pCtx ){
14639 for(i=0; i<pCtx->nSlot; i++){
14640 sqlite3_free(pCtx->aSlot[i].z);
14641 }
14642 sqlite3_free(pCtx);
14643 }
14644
14645 if( rc==SQLITE_OK ){
14646 rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_schema", 0, 0, 0);
14647 }
14648
14649 sqlite3_create_function(p->db, "sqlite_expert_rem", 2, SQLITE_UTF8, 0,0,0,0);
14650 sqlite3_create_function(p->db, "sqlite_expert_sample", 0,SQLITE_UTF8,0,0,0,0);
14651
14652 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
14653 return rc;
14654}
static int idxLargestIndex(sqlite3 *db, int *pnMax, char **pzErr)
Definition shell.c:14405
int nSlot
Definition shell.c:14315
struct IdxRemCtx::IdxRemSlot aSlot[1]
static void idxSampleFunc(sqlite3_context *pCtx, int argc, sqlite3_value **argv)
Definition shell.c:14288
char * z
Definition shell.c:14322
static int idxBuildSampleTable(sqlite3expert *p, const char *zTab)
Definition shell.c:14532
static int idxPopulateOneStat1(sqlite3expert *p, sqlite3_stmt *pIndexXInfo, sqlite3_stmt *pWriteStat, const char *zTab, const char *zIdx, char **pzErr)
Definition shell.c:14425
static void idxRemFunc(sqlite3_context *pCtx, int argc, sqlite3_value **argv)
Definition shell.c:14329
Definition shell.c:14314
Definition shell.c:14281
#define sqlite3_column_int64
Definition sqlite3ext.h:426
#define sqlite3_create_function
Definition sqlite3ext.h:442

References IdxRemCtx::aSlot, sqlite3expert::db, sqlite3expert::dbm, sqlite3expert::dbv, idxBuildSampleTable(), idxFinalize(), idxLargestIndex(), idxMalloc(), idxPopulateOneStat1(), idxPrepareStmt(), idxRemFunc(), idxSampleFunc(), sqlite3expert::iSample, IdxSampleCtx::iTarget, IdxSampleCtx::nRet, IdxSampleCtx::nRow, IdxRemCtx::nSlot, sqlite3_column_int64, sqlite3_column_text, sqlite3_create_function, sqlite3_exec, sqlite3_free, sqlite3_step, SQLITE_OK, SQLITE_ROW, SQLITE_UTF8, IdxSampleCtx::target, UNIQUE_TABLE_NAME, and IdxRemCtx::IdxRemSlot::z.

Referenced by sqlite3_expert_analyze().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxPrepareStmt()

int idxPrepareStmt ( sqlite3 * db,
sqlite3_stmt ** ppStmt,
char ** pzErrmsg,
const char * zSql )
static
13084 {
13085 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
13086 if( rc!=SQLITE_OK ){
13087 *ppStmt = 0;
13088 idxDatabaseError(db, pzErrmsg);
13089 }
13090 return rc;
13091}
static void idxDatabaseError(sqlite3 *db, char **pzErrmsg)
Definition shell.c:13069

References idxDatabaseError(), sqlite3_prepare_v2, and SQLITE_OK.

Referenced by idxCreateVtabSchema(), idxLargestIndex(), idxPopulateOneStat1(), idxPopulateStat1(), idxPrintfPrepareStmt(), and sqlite3_expert_sql().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxPrintfPrepareStmt()

int idxPrintfPrepareStmt ( sqlite3 * db,
sqlite3_stmt ** ppStmt,
char ** pzErrmsg,
const char * zFmt,
... )
static
13102 {
13103 va_list ap;
13104 int rc;
13105 char *zSql;
13106 va_start(ap, zFmt);
13107 zSql = sqlite3_vmprintf(zFmt, ap);
13108 if( zSql==0 ){
13109 rc = SQLITE_NOMEM;
13110 }else{
13111 rc = idxPrepareStmt(db, ppStmt, pzErrmsg, zSql);
13112 sqlite3_free(zSql);
13113 }
13114 va_end(ap);
13115 return rc;
13116}

References idxPrepareStmt(), sqlite3_free, sqlite3_vmprintf, and SQLITE_NOMEM.

Referenced by expertFilter(), idxFindCompatible(), idxFindIndexes(), idxGetTableInfo(), idxProcessOneTrigger(), and sqlite3_expert_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxProcessOneTrigger()

int idxProcessOneTrigger ( sqlite3expert * p,
IdxWrite * pWrite,
char ** pzErr )
static
14054 {
14055 static const char *zInt = UNIQUE_TABLE_NAME;
14056 static const char *zDrop = "DROP TABLE " UNIQUE_TABLE_NAME;
14057 IdxTable *pTab = pWrite->pTab;
14058 const char *zTab = pTab->zName;
14059 const char *zSql =
14060 "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_schema "
14061 "WHERE tbl_name = %Q AND type IN ('table', 'trigger') "
14062 "ORDER BY type;";
14063 sqlite3_stmt *pSelect = 0;
14064 int rc = SQLITE_OK;
14065 char *zWrite = 0;
14066
14067 /* Create the table and its triggers in the temp schema */
14068 rc = idxPrintfPrepareStmt(p->db, &pSelect, pzErr, zSql, zTab, zTab);
14069 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSelect) ){
14070 const char *zCreate = (const char*)sqlite3_column_text(pSelect, 0);
14071 if( zCreate==0 ) continue;
14072 rc = sqlite3_exec(p->dbv, zCreate, 0, 0, pzErr);
14073 }
14074 idxFinalize(&rc, pSelect);
14075
14076 /* Rename the table in the temp schema to zInt */
14077 if( rc==SQLITE_OK ){
14078 char *z = sqlite3_mprintf("ALTER TABLE temp.%Q RENAME TO %Q", zTab, zInt);
14079 if( z==0 ){
14080 rc = SQLITE_NOMEM;
14081 }else{
14082 rc = sqlite3_exec(p->dbv, z, 0, 0, pzErr);
14083 sqlite3_free(z);
14084 }
14085 }
14086
14087 switch( pWrite->eOp ){
14088 case SQLITE_INSERT: {
14089 int i;
14090 zWrite = idxAppendText(&rc, zWrite, "INSERT INTO %Q VALUES(", zInt);
14091 for(i=0; i<pTab->nCol; i++){
14092 zWrite = idxAppendText(&rc, zWrite, "%s?", i==0 ? "" : ", ");
14093 }
14094 zWrite = idxAppendText(&rc, zWrite, ")");
14095 break;
14096 }
14097 case SQLITE_UPDATE: {
14098 int i;
14099 zWrite = idxAppendText(&rc, zWrite, "UPDATE %Q SET ", zInt);
14100 for(i=0; i<pTab->nCol; i++){
14101 zWrite = idxAppendText(&rc, zWrite, "%s%Q=?", i==0 ? "" : ", ",
14102 pTab->aCol[i].zName
14103 );
14104 }
14105 break;
14106 }
14107 default: {
14108 assert( pWrite->eOp==SQLITE_DELETE );
14109 if( rc==SQLITE_OK ){
14110 zWrite = sqlite3_mprintf("DELETE FROM %Q", zInt);
14111 if( zWrite==0 ) rc = SQLITE_NOMEM;
14112 }
14113 }
14114 }
14115
14116 if( rc==SQLITE_OK ){
14117 sqlite3_stmt *pX = 0;
14118 rc = sqlite3_prepare_v2(p->dbv, zWrite, -1, &pX, 0);
14119 idxFinalize(&rc, pX);
14120 if( rc!=SQLITE_OK ){
14121 idxDatabaseError(p->dbv, pzErr);
14122 }
14123 }
14124 sqlite3_free(zWrite);
14125
14126 if( rc==SQLITE_OK ){
14127 rc = sqlite3_exec(p->dbv, zDrop, 0, 0, pzErr);
14128 }
14129
14130 return rc;
14131}

References IdxTable::aCol, sqlite3expert::db, sqlite3expert::dbv, IdxWrite::eOp, idxAppendText(), idxDatabaseError(), idxFinalize(), idxPrintfPrepareStmt(), IdxTable::nCol, IdxWrite::pTab, sqlite3_column_text, sqlite3_exec, sqlite3_free, sqlite3_mprintf, sqlite3_prepare_v2, sqlite3_step, SQLITE_DELETE, SQLITE_INSERT, SQLITE_NOMEM, SQLITE_OK, SQLITE_ROW, SQLITE_UPDATE, UNIQUE_TABLE_NAME, IdxColumn::zName, and IdxTable::zName.

Referenced by idxProcessTriggers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxProcessTriggers()

int idxProcessTriggers ( sqlite3expert * p,
char ** pzErr )
static
14133 {
14134 int rc = SQLITE_OK;
14135 IdxWrite *pEnd = 0;
14136 IdxWrite *pFirst = p->pWrite;
14137
14138 while( rc==SQLITE_OK && pFirst!=pEnd ){
14139 IdxWrite *pIter;
14140 for(pIter=pFirst; rc==SQLITE_OK && pIter!=pEnd; pIter=pIter->pNext){
14141 rc = idxProcessOneTrigger(p, pIter, pzErr);
14142 }
14143 pEnd = pFirst;
14144 pFirst = p->pWrite;
14145 }
14146
14147 return rc;
14148}
static int idxProcessOneTrigger(sqlite3expert *p, IdxWrite *pWrite, char **pzErr)
Definition shell.c:14050

References idxProcessOneTrigger(), IdxWrite::pNext, sqlite3expert::pWrite, and SQLITE_OK.

Referenced by sqlite3_expert_analyze().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxRegisterVtab()

int idxRegisterVtab ( sqlite3expert * p)
static
13394 {
13395 static sqlite3_module expertModule = {
13396 2, /* iVersion */
13397 expertConnect, /* xCreate - create a table */
13398 expertConnect, /* xConnect - connect to an existing table */
13399 expertBestIndex, /* xBestIndex - Determine search strategy */
13400 expertDisconnect, /* xDisconnect - Disconnect from a table */
13401 expertDisconnect, /* xDestroy - Drop a table */
13402 expertOpen, /* xOpen - open a cursor */
13403 expertClose, /* xClose - close a cursor */
13404 expertFilter, /* xFilter - configure scan constraints */
13405 expertNext, /* xNext - advance a cursor */
13406 expertEof, /* xEof */
13407 expertColumn, /* xColumn - read data */
13408 expertRowid, /* xRowid - read data */
13409 expertUpdate, /* xUpdate - write data */
13410 0, /* xBegin - begin transaction */
13411 0, /* xSync - sync transaction */
13412 0, /* xCommit - commit transaction */
13413 0, /* xRollback - rollback transaction */
13414 0, /* xFindFunction - function overloading */
13415 0, /* xRename - rename the table */
13416 0, /* xSavepoint */
13417 0, /* xRelease */
13418 0, /* xRollbackTo */
13419 0, /* xShadowName */
13420 0, /* xIntegrity */
13421 };
13422
13423 return sqlite3_create_module(p->dbv, "expert", &expertModule, (void*)p);
13424}
static int expertEof(sqlite3_vtab_cursor *cur)
Definition shell.c:13317
static int expertClose(sqlite3_vtab_cursor *cur)
Definition shell.c:13304
static int expertFilter(sqlite3_vtab_cursor *cur, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
Definition shell.c:13366
static int expertConnect(sqlite3 *db, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVtab, char **pzErr)
Definition shell.c:13167
static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor)
Definition shell.c:13292
static int expertDisconnect(sqlite3_vtab *pVtab)
Definition shell.c:13203
static int expertColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
Definition shell.c:13353
static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo)
Definition shell.c:13209
static int expertUpdate(sqlite3_vtab *pVtab, int nData, sqlite3_value **azData, sqlite_int64 *pRowid)
Definition shell.c:13276
static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid)
Definition shell.c:13344

References sqlite3expert::dbv, expertBestIndex(), expertClose(), expertColumn(), expertConnect(), expertDisconnect(), expertEof(), expertFilter(), expertNext(), expertOpen(), expertRowid(), expertUpdate(), and sqlite3_create_module.

Referenced by idxCreateVtabSchema().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxRemFunc()

void idxRemFunc ( sqlite3_context * pCtx,
int argc,
sqlite3_value ** argv )
static
14333 {
14334 struct IdxRemCtx *p = (struct IdxRemCtx*)sqlite3_user_data(pCtx);
14335 struct IdxRemSlot *pSlot;
14336 int iSlot;
14337 assert( argc==2 );
14338
14339 iSlot = sqlite3_value_int(argv[0]);
14340 assert( iSlot<p->nSlot );
14341 pSlot = &p->aSlot[iSlot];
14342
14343 switch( pSlot->eType ){
14344 case SQLITE_NULL:
14345 /* no-op */
14346 break;
14347
14348 case SQLITE_INTEGER:
14349 sqlite3_result_int64(pCtx, pSlot->iVal);
14350 break;
14351
14352 case SQLITE_FLOAT:
14353 sqlite3_result_double(pCtx, pSlot->rVal);
14354 break;
14355
14356 case SQLITE_BLOB:
14357 sqlite3_result_blob(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
14358 break;
14359
14360 case SQLITE_TEXT:
14361 sqlite3_result_text(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
14362 break;
14363 }
14364
14365 pSlot->eType = sqlite3_value_type(argv[1]);
14366 switch( pSlot->eType ){
14367 case SQLITE_NULL:
14368 /* no-op */
14369 break;
14370
14371 case SQLITE_INTEGER:
14372 pSlot->iVal = sqlite3_value_int64(argv[1]);
14373 break;
14374
14375 case SQLITE_FLOAT:
14376 pSlot->rVal = sqlite3_value_double(argv[1]);
14377 break;
14378
14379 case SQLITE_BLOB:
14380 case SQLITE_TEXT: {
14381 int nByte = sqlite3_value_bytes(argv[1]);
14382 const void *pData = 0;
14383 if( nByte>pSlot->nByte ){
14384 char *zNew = (char*)sqlite3_realloc(pSlot->z, nByte*2);
14385 if( zNew==0 ){
14387 return;
14388 }
14389 pSlot->nByte = nByte*2;
14390 pSlot->z = zNew;
14391 }
14392 pSlot->n = nByte;
14393 if( pSlot->eType==SQLITE_BLOB ){
14394 pData = sqlite3_value_blob(argv[1]);
14395 if( pData ) memcpy(pSlot->z, pData, nByte);
14396 }else{
14397 pData = sqlite3_value_text(argv[1]);
14398 memcpy(pSlot->z, pData, nByte);
14399 }
14400 break;
14401 }
14402 }
14403}
int eType
Definition shell.c:14317
#define sqlite3_value_int64
Definition sqlite3ext.h:513
#define sqlite3_result_double
Definition sqlite3ext.h:483

References IdxRemCtx::aSlot, IdxRemCtx::IdxRemSlot::eType, sqlite3_realloc, sqlite3_result_blob, sqlite3_result_double, sqlite3_result_error_nomem, sqlite3_result_int64, sqlite3_result_text, sqlite3_user_data, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_double, sqlite3_value_int, sqlite3_value_int64, sqlite3_value_text, sqlite3_value_type, SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, SQLITE_TEXT, and SQLITE_TRANSIENT.

Referenced by idxPopulateStat1().

Here is the caller graph for this function:

◆ idxSampleFunc()

void idxSampleFunc ( sqlite3_context * pCtx,
int argc,
sqlite3_value ** argv )
static
14292 {
14293 struct IdxSampleCtx *p = (struct IdxSampleCtx*)sqlite3_user_data(pCtx);
14294 int bRet;
14295
14296 (void)argv;
14297 assert( argc==0 );
14298 if( p->nRow==0.0 ){
14299 bRet = 1;
14300 }else{
14301 bRet = (p->nRet / p->nRow) <= p->target;
14302 if( bRet==0 ){
14303 unsigned short rnd;
14304 sqlite3_randomness(2, (void*)&rnd);
14305 bRet = ((int)rnd % 100) <= p->iTarget;
14306 }
14307 }
14308
14309 sqlite3_result_int(pCtx, bRet);
14310 p->nRow += 1.0;
14311 p->nRet += (double)bRet;
14312}
int iTarget
Definition shell.c:14282
double target
Definition shell.c:14283
double nRow
Definition shell.c:14284
double nRet
Definition shell.c:14285

References IdxSampleCtx::iTarget, IdxSampleCtx::nRet, IdxSampleCtx::nRow, sqlite3_randomness, sqlite3_result_int, sqlite3_user_data, and IdxSampleCtx::target.

Referenced by idxPopulateStat1().

Here is the caller graph for this function:

◆ idxScanFree()

void idxScanFree ( IdxScan * pScan,
IdxScan * pLast )
static
13884 {
13885 IdxScan *p;
13886 IdxScan *pNext;
13887 for(p=pScan; p!=pLast; p=pNext){
13888 pNext = p->pNextScan;
13892 sqlite3_free(p);
13893 }
13894}
static void idxConstraintFree(IdxConstraint *pConstraint)
Definition shell.c:13870

References idxConstraintFree(), IdxScan::pEq, IdxScan::pNextScan, IdxScan::pOrder, IdxScan::pRange, and sqlite3_free.

Referenced by sqlite3_expert_destroy(), and sqlite3_expert_sql().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idxStatementFree()

void idxStatementFree ( IdxStatement * pStatement,
IdxStatement * pLast )
static
13900 {
13901 IdxStatement *p;
13902 IdxStatement *pNext;
13903 for(p=pStatement; p!=pLast; p=pNext){
13904 pNext = p->pNext;
13905 sqlite3_free(p->zEQP);
13906 sqlite3_free(p->zIdx);
13907 sqlite3_free(p);
13908 }
13909}

References IdxStatement::pNext, sqlite3_free, IdxStatement::zEQP, and IdxStatement::zIdx.

Referenced by sqlite3_expert_destroy(), and sqlite3_expert_sql().

Here is the caller graph for this function:

◆ idxTableFree()

void idxTableFree ( IdxTable * pTab)
static
13914 {
13915 IdxTable *pIter;
13916 IdxTable *pNext;
13917 for(pIter=pTab; pIter; pIter=pNext){
13918 pNext = pIter->pNext;
13919 sqlite3_free(pIter);
13920 }
13921}

References IdxTable::pNext, and sqlite3_free.

Referenced by sqlite3_expert_destroy().

Here is the caller graph for this function:

◆ idxWriteFree()

void idxWriteFree ( IdxWrite * pTab)
static
13926 {
13927 IdxWrite *pIter;
13928 IdxWrite *pNext;
13929 for(pIter=pTab; pIter; pIter=pNext){
13930 pNext = pIter->pNext;
13931 sqlite3_free(pIter);
13932 }
13933}

References IdxWrite::pNext, and sqlite3_free.

Referenced by sqlite3_expert_destroy().

Here is the caller graph for this function:

◆ ieee754func()

void ieee754func ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
5957 {
5958 if( argc==1 ){
5959 sqlite3_int64 m, a;
5960 double r;
5961 int e;
5962 int isNeg;
5963 char zResult[100];
5964 assert( sizeof(m)==sizeof(r) );
5965 if( sqlite3_value_type(argv[0])==SQLITE_BLOB
5966 && sqlite3_value_bytes(argv[0])==sizeof(r)
5967 ){
5968 const unsigned char *x = sqlite3_value_blob(argv[0]);
5969 unsigned int i;
5970 sqlite3_uint64 v = 0;
5971 for(i=0; i<sizeof(r); i++){
5972 v = (v<<8) | x[i];
5973 }
5974 memcpy(&r, &v, sizeof(r));
5975 }else{
5976 r = sqlite3_value_double(argv[0]);
5977 }
5978 if( r<0.0 ){
5979 isNeg = 1;
5980 r = -r;
5981 }else{
5982 isNeg = 0;
5983 }
5984 memcpy(&a,&r,sizeof(a));
5985 if( a==0 ){
5986 e = 0;
5987 m = 0;
5988 }else{
5989 e = a>>52;
5990 m = a & ((((sqlite3_int64)1)<<52)-1);
5991 if( e==0 ){
5992 m <<= 1;
5993 }else{
5994 m |= ((sqlite3_int64)1)<<52;
5995 }
5996 while( e<1075 && m>0 && (m&1)==0 ){
5997 m >>= 1;
5998 e++;
5999 }
6000 if( isNeg ) m = -m;
6001 }
6002 switch( *(int*)sqlite3_user_data(context) ){
6003 case 0:
6004 sqlite3_snprintf(sizeof(zResult), zResult, "ieee754(%lld,%d)",
6005 m, e-1075);
6006 sqlite3_result_text(context, zResult, -1, SQLITE_TRANSIENT);
6007 break;
6008 case 1:
6009 sqlite3_result_int64(context, m);
6010 break;
6011 case 2:
6012 sqlite3_result_int(context, e-1075);
6013 break;
6014 }
6015 }else{
6016 sqlite3_int64 m, e, a;
6017 double r;
6018 int isNeg = 0;
6019 m = sqlite3_value_int64(argv[0]);
6020 e = sqlite3_value_int64(argv[1]);
6021
6022 /* Limit the range of e. Ticket 22dea1cfdb9151e4 2021-03-02 */
6023 if( e>10000 ){
6024 e = 10000;
6025 }else if( e<-10000 ){
6026 e = -10000;
6027 }
6028
6029 if( m<0 ){
6030 isNeg = 1;
6031 m = -m;
6032 if( m<0 ) return;
6033 }else if( m==0 && e>-1000 && e<1000 ){
6034 sqlite3_result_double(context, 0.0);
6035 return;
6036 }
6037 while( (m>>32)&0xffe00000 ){
6038 m >>= 1;
6039 e++;
6040 }
6041 while( m!=0 && ((m>>32)&0xfff00000)==0 ){
6042 m <<= 1;
6043 e--;
6044 }
6045 e += 1075;
6046 if( e<=0 ){
6047 /* Subnormal */
6048 if( 1-e >= 64 ){
6049 m = 0;
6050 }else{
6051 m >>= 1-e;
6052 }
6053 e = 0;
6054 }else if( e>0x7ff ){
6055 e = 0x7ff;
6056 }
6057 a = m & ((((sqlite3_int64)1)<<52)-1);
6058 a |= e<<52;
6059 if( isNeg ) a |= ((sqlite3_uint64)1)<<63;
6060 memcpy(&r, &a, sizeof(r));
6061 sqlite3_result_double(context, r);
6062 }
6063}

References a, e, sqlite3_result_double, sqlite3_result_int, sqlite3_result_int64, sqlite3_result_text, sqlite3_snprintf, sqlite3_user_data, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_double, sqlite3_value_int64, sqlite3_value_type, SQLITE_BLOB, and SQLITE_TRANSIENT.

Referenced by sqlite3_ieee_init().

Here is the caller graph for this function:

◆ ieee754func_from_blob()

void ieee754func_from_blob ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
6072 {
6073 UNUSED_PARAMETER(argc);
6074 if( sqlite3_value_type(argv[0])==SQLITE_BLOB
6075 && sqlite3_value_bytes(argv[0])==sizeof(double)
6076 ){
6077 double r;
6078 const unsigned char *x = sqlite3_value_blob(argv[0]);
6079 unsigned int i;
6080 sqlite3_uint64 v = 0;
6081 for(i=0; i<sizeof(r); i++){
6082 v = (v<<8) | x[i];
6083 }
6084 memcpy(&r, &v, sizeof(r));
6085 sqlite3_result_double(context, r);
6086 }
6087}

References sqlite3_result_double, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_type, SQLITE_BLOB, and UNUSED_PARAMETER.

Referenced by sqlite3_ieee_init().

Here is the caller graph for this function:

◆ ieee754func_to_blob()

void ieee754func_to_blob ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
6092 {
6093 UNUSED_PARAMETER(argc);
6094 if( sqlite3_value_type(argv[0])==SQLITE_FLOAT
6096 ){
6097 double r = sqlite3_value_double(argv[0]);
6099 unsigned char a[sizeof(r)];
6100 unsigned int i;
6101 memcpy(&v, &r, sizeof(r));
6102 for(i=1; i<=sizeof(r); i++){
6103 a[sizeof(r)-i] = v&0xff;
6104 v >>= 8;
6105 }
6106 sqlite3_result_blob(context, a, sizeof(r), SQLITE_TRANSIENT);
6107 }
6108}

References a, sqlite3_result_blob, sqlite3_value_double, sqlite3_value_type, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_TRANSIENT, and UNUSED_PARAMETER.

Referenced by sqlite3_ieee_init().

Here is the caller graph for this function:

◆ ieee754inc()

void ieee754inc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
6127 {
6128 double r;
6129 sqlite3_int64 N;
6130 sqlite3_uint64 m1, m2;
6131 double r2;
6132 UNUSED_PARAMETER(argc);
6133 r = sqlite3_value_double(argv[0]);
6134 N = sqlite3_value_int64(argv[1]);
6135 memcpy(&m1, &r, 8);
6136 m2 = m1 + N;
6137 memcpy(&r2, &m2, 8);
6138 sqlite3_result_double(context, r2);
6139}

References sqlite3_result_double, sqlite3_value_double, sqlite3_value_int64, and UNUSED_PARAMETER.

Referenced by sqlite3_ieee_init().

Here is the caller graph for this function:

◆ import_append_char()

void import_append_char ( ImportCtx * p,
int c )
static
26487 {
26488 if( p->n+1>=p->nAlloc ){
26489 p->nAlloc += p->nAlloc + 100;
26490 p->z = sqlite3_realloc64(p->z, p->nAlloc);
26491 shell_check_oom(p->z);
26492 }
int nAlloc
Definition shell.c:26464

References c, ImportCtx::n, ImportCtx::nAlloc, shell_check_oom(), sqlite3_realloc64, and ImportCtx::z.

Referenced by ascii_read_one_field(), csv_read_one_field(), and do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_cleanup()

void import_cleanup ( ImportCtx * p)
static
26477 {
26478 if( p->in!=0 && p->xCloser!=0 ){
26479 p->xCloser(p->in);
26480 p->in = 0;
26481 }
26482 sqlite3_free(p->z);

References ImportCtx::in, sqlite3_free, ImportCtx::xCloser, and ImportCtx::z.

Referenced by do_meta_command().

Here is the caller graph for this function:

◆ initText()

void initText ( ShellText * p)
static
1470 {
1471 memset(p, 0, sizeof(*p));
1472}

Referenced by do_meta_command(), dump_callback(), freeText(), and shellFakeSchema().

Here is the caller graph for this function:

◆ intckCheckObjectSql()

char * intckCheckObjectSql ( sqlite3_intck * p,
const char * zObj,
const char * zPrev,
int * pnKeyVal )
static
15678 {
15679 char *zRet = 0;
15680 sqlite3_stmt *pStmt = 0;
15681 int bAutoIndex = 0;
15682 int bIsIndex = 0;
15683
15684 const char *zCommon =
15685 /* Relation without_rowid also contains just one row. Column "b" is
15686 ** set to true if the table being examined is a WITHOUT ROWID table,
15687 ** or false otherwise. */
15688 ", without_rowid(b) AS ("
15689 " SELECT EXISTS ("
15690 " SELECT 1 FROM tabname, pragma_index_list(tab, db) AS l"
15691 " WHERE origin='pk' "
15692 " AND NOT EXISTS (SELECT 1 FROM sqlite_schema WHERE name=l.name)"
15693 " )"
15694 ")"
15695 ""
15696 /* Table idx_cols contains 1 row for each column in each index on the
15697 ** table being checked. Columns are:
15698 **
15699 ** idx_name: Name of the index.
15700 ** idx_ispk: True if this index is the PK of a WITHOUT ROWID table.
15701 ** col_name: Name of indexed column, or NULL for index on expression.
15702 ** col_expr: Indexed expression, including COLLATE clause.
15703 ** col_alias: Alias used for column in 'intck_wrapper' table.
15704 */
15705 ", idx_cols(idx_name, idx_ispk, col_name, col_expr, col_alias) AS ("
15706 " SELECT l.name, (l.origin=='pk' AND w.b), i.name, COALESCE(("
15707 " SELECT parse_create_index(sql, i.seqno) FROM "
15708 " sqlite_schema WHERE name = l.name"
15709 " ), format('\"%w\"', i.name) || ' COLLATE ' || quote(i.coll)),"
15710 " 'c' || row_number() OVER ()"
15711 " FROM "
15712 " tabname t,"
15713 " without_rowid w,"
15714 " pragma_index_list(t.tab, t.db) l,"
15715 " pragma_index_xinfo(l.name) i"
15716 " WHERE i.key"
15717 " UNION ALL"
15718 " SELECT '', 1, '_rowid_', '_rowid_', 'r1' FROM without_rowid WHERE b=0"
15719 ")"
15720 ""
15721 ""
15722 /*
15723 ** For a PK declared as "PRIMARY KEY(a, b) ... WITHOUT ROWID", where
15724 ** the intck_wrapper aliases of "a" and "b" are "c1" and "c2":
15725 **
15726 ** o_pk: "o.c1, o.c2"
15727 ** i_pk: "i.'a', i.'b'"
15728 ** ...
15729 ** n_pk: 2
15730 */
15731 ", tabpk(db, tab, idx, o_pk, i_pk, q_pk, eq_pk, ps_pk, pk_pk, n_pk) AS ("
15732 " WITH pkfields(f, a) AS ("
15733 " SELECT i.col_name, i.col_alias FROM idx_cols i WHERE i.idx_ispk"
15734 " )"
15735 " SELECT t.db, t.tab, t.idx, "
15736 " group_concat(a, ', '), "
15737 " group_concat('i.'||quote(f), ', '), "
15738 " group_concat('quote(o.'||a||')', ' || '','' || '), "
15739 " format('(%s)==(%s)',"
15740 " group_concat('o.'||a, ', '), "
15741 " group_concat(format('\"%w\"', f), ', ')"
15742 " ),"
15743 " group_concat('%s', ','),"
15744 " group_concat('quote('||a||')', ', '), "
15745 " count(*)"
15746 " FROM tabname t, pkfields"
15747 ")"
15748 ""
15749 ", idx(name, match_expr, partial, partial_alias, idx_ps, idx_idx) AS ("
15750 " SELECT idx_name,"
15751 " format('(%s,%s) IS (%s,%s)', "
15752 " group_concat(i.col_expr, ', '), i_pk,"
15753 " group_concat('o.'||i.col_alias, ', '), o_pk"
15754 " ), "
15755 " parse_create_index("
15756 " (SELECT sql FROM sqlite_schema WHERE name=idx_name), -1"
15757 " ),"
15758 " 'cond' || row_number() OVER ()"
15759 " , group_concat('%s', ',')"
15760 " , group_concat('quote('||i.col_alias||')', ', ')"
15761 " FROM tabpk t, "
15762 " without_rowid w,"
15763 " idx_cols i"
15764 " WHERE i.idx_ispk==0 "
15765 " GROUP BY idx_name"
15766 ")"
15767 ""
15768 ", wrapper_with(s) AS ("
15769 " SELECT 'intck_wrapper AS (\n SELECT\n ' || ("
15770 " WITH f(a, b) AS ("
15771 " SELECT col_expr, col_alias FROM idx_cols"
15772 " UNION ALL "
15773 " SELECT partial, partial_alias FROM idx WHERE partial IS NOT NULL"
15774 " )"
15775 " SELECT group_concat(format('%s AS %s', a, b), ',\n ') FROM f"
15776 " )"
15777 " || format('\n FROM %Q.%Q ', t.db, t.tab)"
15778 /* If the object being checked is a table, append "NOT INDEXED".
15779 ** Otherwise, append "INDEXED BY <index>", and then, if the index
15780 ** is a partial index " WHERE <condition>". */
15781 " || CASE WHEN t.idx IS NULL THEN "
15782 " 'NOT INDEXED'"
15783 " ELSE"
15784 " format('INDEXED BY %Q%s', t.idx, ' WHERE '||i.partial)"
15785 " END"
15786 " || '\n)'"
15787 " FROM tabname t LEFT JOIN idx i ON (i.name=t.idx)"
15788 ")"
15789 ""
15790 ;
15791
15792 bAutoIndex = intckGetAutoIndex(p);
15793 if( bAutoIndex ) intckExec(p, "PRAGMA automatic_index = 0");
15794
15795 bIsIndex = intckIsIndex(p, zObj);
15796 if( bIsIndex ){
15797 pStmt = intckPrepareFmt(p,
15798 /* Table idxname contains a single row. The first column, "db", contains
15799 ** the name of the db containing the table (e.g. "main") and the second,
15800 ** "tab", the name of the table itself. */
15801 "WITH tabname(db, tab, idx) AS ("
15802 " SELECT %Q, (SELECT tbl_name FROM %Q.sqlite_schema WHERE name=%Q), %Q "
15803 ")"
15804 ""
15805 ", whereclause(w_c) AS (%s)"
15806 ""
15807 "%s" /* zCommon */
15808 ""
15809 ", case_statement(c) AS ("
15810 " SELECT "
15811 " 'CASE WHEN (' || group_concat(col_alias, ', ') || ', 1) IS (\n' "
15812 " || ' SELECT ' || group_concat(col_expr, ', ') || ', 1 FROM '"
15813 " || format('%%Q.%%Q NOT INDEXED WHERE %%s\n', t.db, t.tab, p.eq_pk)"
15814 " || ' )\n THEN NULL\n '"
15815 " || 'ELSE format(''surplus entry ('"
15816 " || group_concat('%%s', ',') || ',' || p.ps_pk"
15817 " || ') in index ' || t.idx || ''', ' "
15818 " || group_concat('quote('||i.col_alias||')', ', ') || ', ' || p.pk_pk"
15819 " || ')'"
15820 " || '\n END AS error_message'"
15821 " FROM tabname t, tabpk p, idx_cols i WHERE i.idx_name=t.idx"
15822 ")"
15823 ""
15824 ", thiskey(k, n) AS ("
15825 " SELECT group_concat(i.col_alias, ', ') || ', ' || p.o_pk, "
15826 " count(*) + p.n_pk "
15827 " FROM tabpk p, idx_cols i WHERE i.idx_name=p.idx"
15828 ")"
15829 ""
15830 ", main_select(m, n) AS ("
15831 " SELECT format("
15832 " 'WITH %%s\n' ||"
15833 " ', idx_checker AS (\n' ||"
15834 " ' SELECT %%s,\n' ||"
15835 " ' %%s\n' || "
15836 " ' FROM intck_wrapper AS o\n' ||"
15837 " ')\n',"
15838 " ww.s, c, t.k"
15839 " ), t.n"
15840 " FROM case_statement, wrapper_with ww, thiskey t"
15841 ")"
15842
15843 "SELECT m || "
15844 " group_concat('SELECT * FROM idx_checker ' || w_c, ' UNION ALL '), n"
15845 " FROM "
15846 "main_select, whereclause "
15847 , p->zDb, p->zDb, zObj, zObj
15848 , zPrev ? zPrev : "VALUES('')", zCommon
15849 );
15850 }else{
15851 pStmt = intckPrepareFmt(p,
15852 /* Table tabname contains a single row. The first column, "db", contains
15853 ** the name of the db containing the table (e.g. "main") and the second,
15854 ** "tab", the name of the table itself. */
15855 "WITH tabname(db, tab, idx, prev) AS (SELECT %Q, %Q, NULL, %Q)"
15856 ""
15857 "%s" /* zCommon */
15858
15859 /* expr(e) contains one row for each index on table zObj. Value e
15860 ** is set to an expression that evaluates to NULL if the required
15861 ** entry is present in the index, or an error message otherwise. */
15862 ", expr(e, p) AS ("
15863 " SELECT format('CASE WHEN EXISTS \n"
15864 " (SELECT 1 FROM %%Q.%%Q AS i INDEXED BY %%Q WHERE %%s%%s)\n"
15865 " THEN NULL\n"
15866 " ELSE format(''entry (%%s,%%s) missing from index %%s'', %%s, %%s)\n"
15867 " END\n'"
15868 " , t.db, t.tab, i.name, i.match_expr, ' AND (' || partial || ')',"
15869 " i.idx_ps, t.ps_pk, i.name, i.idx_idx, t.pk_pk),"
15870 " CASE WHEN partial IS NULL THEN NULL ELSE i.partial_alias END"
15871 " FROM tabpk t, idx i"
15872 ")"
15873
15874 ", numbered(ii, cond, e) AS ("
15875 " SELECT 0, 'n.ii=0', 'NULL'"
15876 " UNION ALL "
15877 " SELECT row_number() OVER (),"
15878 " '(n.ii='||row_number() OVER ()||COALESCE(' AND '||p||')', ')'), e"
15879 " FROM expr"
15880 ")"
15881
15882 ", counter_with(w) AS ("
15883 " SELECT 'WITH intck_counter(ii) AS (\n ' || "
15884 " group_concat('SELECT '||ii, ' UNION ALL\n ') "
15885 " || '\n)' FROM numbered"
15886 ")"
15887 ""
15888 ", case_statement(c) AS ("
15889 " SELECT 'CASE ' || "
15890 " group_concat(format('\n WHEN %%s THEN (%%s)', cond, e), '') ||"
15891 " '\nEND AS error_message'"
15892 " FROM numbered"
15893 ")"
15894 ""
15895
15896 /* This table contains a single row consisting of a single value -
15897 ** the text of an SQL expression that may be used by the main SQL
15898 ** statement to output an SQL literal that can be used to resume
15899 ** the scan if it is suspended. e.g. for a rowid table, an expression
15900 ** like:
15901 **
15902 ** format('(%d,%d)', _rowid_, n.ii)
15903 */
15904 ", thiskey(k, n) AS ("
15905 " SELECT o_pk || ', ii', n_pk+1 FROM tabpk"
15906 ")"
15907 ""
15908 ", whereclause(w_c) AS ("
15909 " SELECT CASE WHEN prev!='' THEN "
15910 " '\nWHERE (' || o_pk ||', n.ii) > ' || prev"
15911 " ELSE ''"
15912 " END"
15913 " FROM tabpk, tabname"
15914 ")"
15915 ""
15916 ", main_select(m, n) AS ("
15917 " SELECT format("
15918 " '%%s, %%s\nSELECT %%s,\n%%s\nFROM intck_wrapper AS o"
15919 ", intck_counter AS n%%s\nORDER BY %%s', "
15920 " w, ww.s, c, thiskey.k, whereclause.w_c, t.o_pk"
15921 " ), thiskey.n"
15922 " FROM case_statement, tabpk t, counter_with, "
15923 " wrapper_with ww, thiskey, whereclause"
15924 ")"
15925
15926 "SELECT m, n FROM main_select",
15927 p->zDb, zObj, zPrev, zCommon
15928 );
15929 }
15930
15931 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
15932 zRet = intckMprintf(p, "%s", (const char*)sqlite3_column_text(pStmt, 0));
15933 if( pnKeyVal ){
15934 *pnKeyVal = sqlite3_column_int(pStmt, 1);
15935 }
15936 }
15937 intckFinalize(p, pStmt);
15938
15939 if( bAutoIndex ) intckExec(p, "PRAGMA automatic_index = 1");
15940 return zRet;
15941}
static sqlite3_stmt * intckPrepareFmt(sqlite3_intck *p, const char *zFmt,...)
Definition shell.c:15264
static void intckFinalize(sqlite3_intck *p, sqlite3_stmt *pStmt)
Definition shell.c:15284
static void intckExec(sqlite3_intck *p, const char *zSql)
Definition shell.c:15305
static char * intckMprintf(sqlite3_intck *p, const char *zFmt,...)
Definition shell.c:15316
static int intckIsIndex(sqlite3_intck *p, const char *zObj)
Definition shell.c:15649
int rc
Definition shell.c:15218
static int intckGetAutoIndex(sqlite3_intck *p)
Definition shell.c:15635
const char * zDb
Definition shell.c:15208

References intckExec(), intckFinalize(), intckGetAutoIndex(), intckIsIndex(), intckMprintf(), intckPrepareFmt(), sqlite3_intck::rc, sqlite3_column_int, sqlite3_column_text, sqlite3_step, SQLITE_OK, SQLITE_ROW, and sqlite3_intck::zDb.

Referenced by sqlite3_intck_step(), and sqlite3_intck_test_sql().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckDatabaseCmd()

int intckDatabaseCmd ( ShellState * pState,
i64 nStepPerUnlock )
static
28482 {
28483 sqlite3_intck *p = 0;
28484 int rc = SQLITE_OK;
28485
28486 rc = sqlite3_intck_open(pState->db, "main", &p);
28487 if( rc==SQLITE_OK ){
28488 i64 nStep = 0;
28489 i64 nError = 0;
28490 const char *zErr = 0;
28491 while( SQLITE_OK==sqlite3_intck_step(p) ){
28492 const char *zMsg = sqlite3_intck_message(p);
28493 if( zMsg ){
28494 sqlite3_fprintf(pState->out, "%s\n", zMsg);
28495 nError++;
28496 }
28497 nStep++;
28498 if( nStepPerUnlock && (nStep % nStepPerUnlock)==0 ){
28500 }
28501 }
28502 rc = sqlite3_intck_error(p, &zErr);
28503 if( zErr ){
28504 sqlite3_fprintf(stderr,"%s\n", zErr);
28505 }
28507
28508 sqlite3_fprintf(pState->out, "%lld steps, %lld errors\n", nStep, nError);
28509 }
28510
int sqlite3_intck_open(sqlite3 *db, const char *zDb, sqlite3_intck **ppOut)
Definition shell.c:15946
const char * sqlite3_intck_message(sqlite3_intck *pCk)
Definition shell.c:16056
int sqlite3_intck_error(sqlite3_intck *pCk, const char **pzErr)
Definition shell.c:16070
void sqlite3_intck_close(sqlite3_intck *pCk)
Definition shell.c:15980
int sqlite3_intck_unlock(sqlite3_intck *pCk)
Definition shell.c:16079
int sqlite3_intck_step(sqlite3_intck *pCk)
Definition shell.c:15998
Definition shell.c:15206

References ShellState::db, ShellState::out, sqlite3_fprintf, sqlite3_intck_close(), sqlite3_intck_error(), sqlite3_intck_message(), sqlite3_intck_open(), sqlite3_intck_step(), sqlite3_intck_unlock(), and SQLITE_OK.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckExec()

void intckExec ( sqlite3_intck * p,
const char * zSql )
static
15305 {
15306 sqlite3_stmt *pStmt = 0;
15307 pStmt = intckPrepare(p, zSql);
15308 intckStep(p, pStmt);
15309 intckFinalize(p, pStmt);
15310}
static int intckStep(sqlite3_intck *p, sqlite3_stmt *pStmt)
Definition shell.c:15295
static sqlite3_stmt * intckPrepare(sqlite3_intck *p, const char *zSql)
Definition shell.c:15242

References intckFinalize(), intckPrepare(), and intckStep().

Referenced by intckCheckObjectSql().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckFinalize()

void intckFinalize ( sqlite3_intck * p,
sqlite3_stmt * pStmt )
static
15284 {
15285 int rc = sqlite3_finalize(pStmt);
15286 if( p->rc==SQLITE_OK && rc!=SQLITE_OK ){
15287 intckSaveErrmsg(p);
15288 }
15289}
static void intckSaveErrmsg(sqlite3_intck *p)
Definition shell.c:15228

References intckSaveErrmsg(), sqlite3_intck::rc, sqlite3_finalize, and SQLITE_OK.

Referenced by intckCheckObjectSql(), intckExec(), intckFindObject(), intckGetAutoIndex(), intckIsIndex(), intckSaveKey(), sqlite3_intck_step(), and sqlite3_intck_unlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckFindObject()

void intckFindObject ( sqlite3_intck * p)
static
15437 {
15438 sqlite3_stmt *pStmt = 0;
15439 char *zPrev = p->zObj;
15440 p->zObj = 0;
15441
15442 assert( p->rc==SQLITE_OK );
15443 assert( p->pCheck==0 );
15444
15445 pStmt = intckPrepareFmt(p,
15446 "WITH tables(table_name) AS ("
15447 " SELECT name"
15448 " FROM %Q.sqlite_schema WHERE (type='table' OR type='index') AND rootpage"
15449 " UNION ALL "
15450 " SELECT 'sqlite_schema'"
15451 ")"
15452 "SELECT table_name FROM tables "
15453 "WHERE ?1 IS NULL OR table_name%s?1 "
15454 "ORDER BY 1"
15455 , p->zDb, (p->zKey ? ">=" : ">")
15456 );
15457
15458 if( p->rc==SQLITE_OK ){
15459 sqlite3_bind_text(pStmt, 1, zPrev, -1, SQLITE_TRANSIENT);
15460 if( sqlite3_step(pStmt)==SQLITE_ROW ){
15461 p->zObj = intckMprintf(p,"%s",(const char*)sqlite3_column_text(pStmt, 0));
15462 }
15463 }
15464 intckFinalize(p, pStmt);
15465
15466 /* If this is a new object, ensure the previous key value is cleared. */
15467 if( sqlite3_stricmp(p->zObj, zPrev) ){
15468 sqlite3_free(p->zKey);
15469 p->zKey = 0;
15470 }
15471
15472 sqlite3_free(zPrev);
15473}
char * zKey
Definition shell.c:15212
sqlite3_stmt * pCheck
Definition shell.c:15211
char * zObj
Definition shell.c:15209

References intckFinalize(), intckMprintf(), intckPrepareFmt(), sqlite3_intck::pCheck, sqlite3_intck::rc, sqlite3_bind_text, sqlite3_column_text, sqlite3_free, sqlite3_step, sqlite3_stricmp, SQLITE_OK, SQLITE_ROW, SQLITE_TRANSIENT, sqlite3_intck::zDb, sqlite3_intck::zKey, and sqlite3_intck::zObj.

Referenced by sqlite3_intck_step().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckGetAutoIndex()

int intckGetAutoIndex ( sqlite3_intck * p)
static
15635 {
15636 int bRet = 0;
15637 sqlite3_stmt *pStmt = 0;
15638 pStmt = intckPrepare(p, "PRAGMA automatic_index");
15639 if( SQLITE_ROW==intckStep(p, pStmt) ){
15640 bRet = sqlite3_column_int(pStmt, 0);
15641 }
15642 intckFinalize(p, pStmt);
15643 return bRet;
15644}

References intckFinalize(), intckPrepare(), intckStep(), sqlite3_column_int, and SQLITE_ROW.

Referenced by intckCheckObjectSql().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckGetToken()

int intckGetToken ( const char * z)
static
15483 {
15484 char c = z[0];
15485 int iRet = 1;
15486 if( c=='\'' || c=='"' || c=='`' ){
15487 while( 1 ){
15488 if( z[iRet]==c ){
15489 iRet++;
15490 if( z[iRet]!=c ) break;
15491 }
15492 iRet++;
15493 }
15494 }
15495 else if( c=='[' ){
15496 while( z[iRet++]!=']' && z[iRet] );
15497 }
15498 else if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){
15499 while( (z[iRet]>='A' && z[iRet]<='Z') || (z[iRet]>='a' && z[iRet]<='z') ){
15500 iRet++;
15501 }
15502 }
15503
15504 return iRet;
15505}

References c.

Referenced by intckParseCreateIndex().

Here is the caller graph for this function:

◆ intckIsIndex()

int intckIsIndex ( sqlite3_intck * p,
const char * zObj )
static
15649 {
15650 int bRet = 0;
15651 sqlite3_stmt *pStmt = 0;
15652 pStmt = intckPrepareFmt(p,
15653 "SELECT 1 FROM %Q.sqlite_schema WHERE name=%Q AND type='index'",
15654 p->zDb, zObj
15655 );
15656 if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
15657 bRet = 1;
15658 }
15659 intckFinalize(p, pStmt);
15660 return bRet;
15661}

References intckFinalize(), intckPrepareFmt(), sqlite3_intck::rc, sqlite3_step, SQLITE_OK, SQLITE_ROW, and sqlite3_intck::zDb.

Referenced by intckCheckObjectSql().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckIsSpace()

int intckIsSpace ( char c)
static
15510 {
15511 return (c==' ' || c=='\t' || c=='\n' || c=='\r');
15512}

References c.

Referenced by intckParseCreateIndex().

Here is the caller graph for this function:

◆ intckMprintf()

char * intckMprintf ( sqlite3_intck * p,
const char * zFmt,
... )
static
15316 {
15317 va_list ap;
15318 char *zRet = 0;
15319 va_start(ap, zFmt);
15320 zRet = sqlite3_vmprintf(zFmt, ap);
15321 if( p->rc==SQLITE_OK ){
15322 if( zRet==0 ){
15323 p->rc = SQLITE_NOMEM;
15324 }
15325 }else{
15326 sqlite3_free(zRet);
15327 zRet = 0;
15328 }
15329 return zRet;
15330}

References sqlite3_intck::rc, sqlite3_free, sqlite3_vmprintf, SQLITE_NOMEM, and SQLITE_OK.

Referenced by intckCheckObjectSql(), intckFindObject(), intckSaveKey(), and sqlite3_intck_step().

Here is the caller graph for this function:

◆ intckParseCreateIndex()

const char * intckParseCreateIndex ( const char * z,
int iCol,
int * pnByte )
static
15529 {
15530 int iOff = 0;
15531 int iThisCol = 0;
15532 int iStart = 0;
15533 int nOpen = 0;
15534
15535 const char *zRet = 0;
15536 int nRet = 0;
15537
15538 int iEndOfCol = 0;
15539
15540 /* Skip forward until the first "(" token */
15541 while( z[iOff]!='(' ){
15542 iOff += intckGetToken(&z[iOff]);
15543 if( z[iOff]=='\0' ) return 0;
15544 }
15545 assert( z[iOff]=='(' );
15546
15547 nOpen = 1;
15548 iOff++;
15549 iStart = iOff;
15550 while( z[iOff] ){
15551 const char *zToken = &z[iOff];
15552 int nToken = 0;
15553
15554 /* Check if this is the end of the current column - either a "," or ")"
15555 ** when nOpen==1. */
15556 if( nOpen==1 ){
15557 if( z[iOff]==',' || z[iOff]==')' ){
15558 if( iCol==iThisCol ){
15559 int iEnd = iEndOfCol ? iEndOfCol : iOff;
15560 nRet = (iEnd - iStart);
15561 zRet = &z[iStart];
15562 break;
15563 }
15564 iStart = iOff+1;
15565 while( intckIsSpace(z[iStart]) ) iStart++;
15566 iThisCol++;
15567 }
15568 if( z[iOff]==')' ) break;
15569 }
15570 if( z[iOff]=='(' ) nOpen++;
15571 if( z[iOff]==')' ) nOpen--;
15572 nToken = intckGetToken(zToken);
15573
15574 if( (nToken==3 && 0==sqlite3_strnicmp(zToken, "ASC", nToken))
15575 || (nToken==4 && 0==sqlite3_strnicmp(zToken, "DESC", nToken))
15576 ){
15577 iEndOfCol = iOff;
15578 }else if( 0==intckIsSpace(zToken[0]) ){
15579 iEndOfCol = 0;
15580 }
15581
15582 iOff += nToken;
15583 }
15584
15585 /* iStart is now the byte offset of 1 byte passed the final ')' in the
15586 ** CREATE INDEX statement. Try to find a WHERE clause to return. */
15587 while( zRet==0 && z[iOff] ){
15588 int n = intckGetToken(&z[iOff]);
15589 if( n==5 && 0==sqlite3_strnicmp(&z[iOff], "where", 5) ){
15590 zRet = &z[iOff+5];
15591 nRet = (int)strlen(zRet);
15592 }
15593 iOff += n;
15594 }
15595
15596 /* Trim any whitespace from the start and end of the returned string. */
15597 if( zRet ){
15598 while( intckIsSpace(zRet[0]) ){
15599 nRet--;
15600 zRet++;
15601 }
15602 while( nRet>0 && intckIsSpace(zRet[nRet-1]) ) nRet--;
15603 }
15604
15605 *pnByte = nRet;
15606 return zRet;
15607}
static int intckGetToken(const char *z)
Definition shell.c:15483
static int intckIsSpace(char c)
Definition shell.c:15510

References intckGetToken(), intckIsSpace(), and sqlite3_strnicmp.

Referenced by intckParseCreateIndexFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckParseCreateIndexFunc()

void intckParseCreateIndexFunc ( sqlite3_context * pCtx,
int nVal,
sqlite3_value ** apVal )
static
15618 {
15619 const char *zSql = (const char*)sqlite3_value_text(apVal[0]);
15620 int idx = sqlite3_value_int(apVal[1]);
15621 const char *zRes = 0;
15622 int nRes = 0;
15623
15624 assert( nVal==2 );
15625 if( zSql ){
15626 zRes = intckParseCreateIndex(zSql, idx, &nRes);
15627 }
15628 sqlite3_result_text(pCtx, zRes, nRes, SQLITE_TRANSIENT);
15629}
static const char * intckParseCreateIndex(const char *z, int iCol, int *pnByte)
Definition shell.c:15529

References intckParseCreateIndex(), sqlite3_result_text, sqlite3_value_int, sqlite3_value_text, and SQLITE_TRANSIENT.

Referenced by sqlite3_intck_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckPrepare()

sqlite3_stmt * intckPrepare ( sqlite3_intck * p,
const char * zSql )
static
15242 {
15243 sqlite3_stmt *pRet = 0;
15244 if( p->rc==SQLITE_OK ){
15245 p->rc = sqlite3_prepare_v2(p->db, zSql, -1, &pRet, 0);
15246 if( p->rc!=SQLITE_OK ){
15247 intckSaveErrmsg(p);
15248 assert( pRet==0 );
15249 }
15250 }
15251 return pRet;
15252}
sqlite3 * db
Definition shell.c:15207

References sqlite3_intck::db, intckSaveErrmsg(), sqlite3_intck::rc, sqlite3_prepare_v2, and SQLITE_OK.

Referenced by intckExec(), intckGetAutoIndex(), intckPrepareFmt(), intckSaveKey(), and sqlite3_intck_step().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckPrepareFmt()

sqlite3_stmt * intckPrepareFmt ( sqlite3_intck * p,
const char * zFmt,
... )
static
15264 {
15265 sqlite3_stmt *pRet = 0;
15266 va_list ap;
15267 char *zSql = 0;
15268 va_start(ap, zFmt);
15269 zSql = sqlite3_vmprintf(zFmt, ap);
15270 if( p->rc==SQLITE_OK && zSql==0 ){
15271 p->rc = SQLITE_NOMEM;
15272 }
15273 pRet = intckPrepare(p, zSql);
15274 sqlite3_free(zSql);
15275 va_end(ap);
15276 return pRet;
15277}

References intckPrepare(), sqlite3_intck::rc, sqlite3_free, sqlite3_vmprintf, SQLITE_NOMEM, and SQLITE_OK.

Referenced by intckCheckObjectSql(), intckFindObject(), intckIsIndex(), and intckSaveKey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckSaveErrmsg()

void intckSaveErrmsg ( sqlite3_intck * p)
static
15228 {
15229 p->rc = sqlite3_errcode(p->db);
15230 sqlite3_free(p->zErr);
15231 p->zErr = sqlite3_mprintf("%s", sqlite3_errmsg(p->db));
15232}
char * zErr
Definition shell.c:15219

References sqlite3_intck::db, sqlite3_intck::rc, sqlite3_errcode, sqlite3_errmsg, sqlite3_free, sqlite3_mprintf, and sqlite3_intck::zErr.

Referenced by intckFinalize(), and intckPrepare().

Here is the caller graph for this function:

◆ intckSaveKey()

void intckSaveKey ( sqlite3_intck * p)
static
15337 {
15338 int ii;
15339 char *zSql = 0;
15340 sqlite3_stmt *pStmt = 0;
15341 sqlite3_stmt *pXinfo = 0;
15342 const char *zDir = 0;
15343
15344 assert( p->pCheck );
15345 assert( p->zKey==0 );
15346
15347 pXinfo = intckPrepareFmt(p,
15348 "SELECT group_concat(desc, '') FROM %Q.sqlite_schema s, "
15349 "pragma_index_xinfo(%Q, %Q) "
15350 "WHERE s.type='index' AND s.name=%Q",
15351 p->zDb, p->zObj, p->zDb, p->zObj
15352 );
15353 if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXinfo) ){
15354 zDir = (const char*)sqlite3_column_text(pXinfo, 0);
15355 }
15356
15357 if( zDir==0 ){
15358 /* Object is a table, not an index. This is the easy case,as there are
15359 ** no DESC columns or NULL values in a primary key. */
15360 const char *zSep = "SELECT '(' || ";
15361 for(ii=0; ii<p->nKeyVal; ii++){
15362 zSql = intckMprintf(p, "%z%squote(?)", zSql, zSep);
15363 zSep = " || ', ' || ";
15364 }
15365 zSql = intckMprintf(p, "%z || ')'", zSql);
15366 }else{
15367
15368 /* Object is an index. */
15369 assert( p->nKeyVal>1 );
15370 for(ii=p->nKeyVal; ii>0; ii--){
15371 int bLastIsDesc = zDir[ii-1]=='1';
15372 int bLastIsNull = sqlite3_column_type(p->pCheck, ii)==SQLITE_NULL;
15373 const char *zLast = sqlite3_column_name(p->pCheck, ii);
15374 char *zLhs = 0;
15375 char *zRhs = 0;
15376 char *zWhere = 0;
15377
15378 if( bLastIsNull ){
15379 if( bLastIsDesc ) continue;
15380 zWhere = intckMprintf(p, "'%s IS NOT NULL'", zLast);
15381 }else{
15382 const char *zOp = bLastIsDesc ? "<" : ">";
15383 zWhere = intckMprintf(p, "'%s %s ' || quote(?%d)", zLast, zOp, ii);
15384 }
15385
15386 if( ii>1 ){
15387 const char *zLhsSep = "";
15388 const char *zRhsSep = "";
15389 int jj;
15390 for(jj=0; jj<ii-1; jj++){
15391 const char *zAlias = (const char*)sqlite3_column_name(p->pCheck,jj+1);
15392 zLhs = intckMprintf(p, "%z%s%s", zLhs, zLhsSep, zAlias);
15393 zRhs = intckMprintf(p, "%z%squote(?%d)", zRhs, zRhsSep, jj+1);
15394 zLhsSep = ",";
15395 zRhsSep = " || ',' || ";
15396 }
15397
15398 zWhere = intckMprintf(p,
15399 "'(%z) IS (' || %z || ') AND ' || %z",
15400 zLhs, zRhs, zWhere);
15401 }
15402 zWhere = intckMprintf(p, "'WHERE ' || %z", zWhere);
15403
15404 zSql = intckMprintf(p, "%z%s(quote( %z ) )",
15405 zSql,
15406 (zSql==0 ? "VALUES" : ",\n "),
15407 zWhere
15408 );
15409 }
15410 zSql = intckMprintf(p,
15411 "WITH wc(q) AS (\n%z\n)"
15412 "SELECT 'VALUES' || group_concat('(' || q || ')', ',\n ') FROM wc"
15413 , zSql
15414 );
15415 }
15416
15417 pStmt = intckPrepare(p, zSql);
15418 if( p->rc==SQLITE_OK ){
15419 for(ii=0; ii<p->nKeyVal; ii++){
15420 sqlite3_bind_value(pStmt, ii+1, sqlite3_column_value(p->pCheck, ii+1));
15421 }
15422 if( SQLITE_ROW==sqlite3_step(pStmt) ){
15423 p->zKey = intckMprintf(p,"%s",(const char*)sqlite3_column_text(pStmt, 0));
15424 }
15425 intckFinalize(p, pStmt);
15426 }
15427
15428 sqlite3_free(zSql);
15429 intckFinalize(p, pXinfo);
15430}
int nKeyVal
Definition shell.c:15213

References intckFinalize(), intckMprintf(), intckPrepare(), intckPrepareFmt(), sqlite3_intck::nKeyVal, sqlite3_intck::pCheck, sqlite3_intck::rc, sqlite3_bind_value, sqlite3_column_name, sqlite3_column_text, sqlite3_column_type, sqlite3_column_value, sqlite3_free, sqlite3_step, SQLITE_NULL, SQLITE_OK, SQLITE_ROW, sqlite3_intck::zDb, sqlite3_intck::zKey, and sqlite3_intck::zObj.

Referenced by sqlite3_intck_unlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intckStep()

int intckStep ( sqlite3_intck * p,
sqlite3_stmt * pStmt )
static
15295 {
15296 if( p->rc ) return p->rc;
15297 return sqlite3_step(pStmt);
15298}

References sqlite3_intck::rc, and sqlite3_step.

Referenced by intckExec(), and intckGetAutoIndex().

Here is the caller graph for this function:

◆ integerValue()

sqlite3_int64 integerValue ( const char * zArg)
static
1414 {
1415 sqlite3_int64 v = 0;
1416 static const struct { char *zSuffix; int iMult; } aMult[] = {
1417 { "KiB", 1024 },
1418 { "MiB", 1024*1024 },
1419 { "GiB", 1024*1024*1024 },
1420 { "KB", 1000 },
1421 { "MB", 1000000 },
1422 { "GB", 1000000000 },
1423 { "K", 1000 },
1424 { "M", 1000000 },
1425 { "G", 1000000000 },
1426 };
1427 int i;
1428 int isNeg = 0;
1429 if( zArg[0]=='-' ){
1430 isNeg = 1;
1431 zArg++;
1432 }else if( zArg[0]=='+' ){
1433 zArg++;
1434 }
1435 if( zArg[0]=='0' && zArg[1]=='x' ){
1436 int x;
1437 zArg += 2;
1438 while( (x = hexDigitValue(zArg[0]))>=0 ){
1439 v = (v<<4) + x;
1440 zArg++;
1441 }
1442 }else{
1443 while( IsDigit(zArg[0]) ){
1444 v = v*10 + zArg[0] - '0';
1445 zArg++;
1446 }
1447 }
1448 for(i=0; i<ArraySize(aMult); i++){
1449 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
1450 v *= aMult[i].iMult;
1451 break;
1452 }
1453 }
1454 return isNeg? -v : v;
1455}

References ArraySize, hexDigitValue(), IsDigit, and sqlite3_stricmp.

Referenced by booleanValue(), do_meta_command(), expertDotCommand(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interrupt_handler()

void interrupt_handler ( int NotUsed)
static
22551 {
22552 UNUSED_PARAMETER(NotUsed);
22553 if( ++seenInterrupt>1 ) exit(1);

References globalDb, seenInterrupt, sqlite3_interrupt, and UNUSED_PARAMETER.

Referenced by main().

Here is the caller graph for this function:

◆ isatty()

int isatty ( int )
extern

Referenced by main().

Here is the caller graph for this function:

◆ isNumber()

int isNumber ( const char * z,
int * realnum )
static
1235 {
1236 if( *z=='-' || *z=='+' ) z++;
1237 if( !IsDigit(*z) ){
1238 return 0;
1239 }
1240 z++;
1241 if( realnum ) *realnum = 0;
1242 while( IsDigit(*z) ){ z++; }
1243 if( *z=='.' ){
1244 z++;
1245 if( !IsDigit(*z) ) return 0;
1246 while( IsDigit(*z) ){ z++; }
1247 if( realnum ) *realnum = 1;
1248 }
1249 if( *z=='e' || *z=='E' ){
1250 z++;
1251 if( *z=='+' || *z=='-' ) z++;
1252 if( !IsDigit(*z) ) return 0;
1253 while( IsDigit(*z) ){ z++; }
1254 if( realnum ) *realnum = 1;
1255 }
1256 return *z==0;
1257}

References IsDigit.

Referenced by shell_callback().

Here is the caller graph for this function:

◆ isVt100()

int isVt100 ( const unsigned char * z)
static
1175 {
1176 int i;
1177 if( z[1]!='[' ) return 0;
1178 i = 2;
1179 while( z[i]>=0x30 && z[i]<=0x3f ){ i++; }
1180 while( z[i]>=0x20 && z[i]<=0x2f ){ i++; }
1181 if( z[i]<0x40 || z[i]>0x7e ) return 0;
1182 return i+1;
1183}

Referenced by translateForDisplayAndDup(), and utf8_width_print().

Here is the caller graph for this function:

◆ KeccakF1600Step()

void KeccakF1600Step ( SHA3Context * p)
static
2487 {
2488 int i;
2489 u64 b0, b1, b2, b3, b4;
2490 u64 c0, c1, c2, c3, c4;
2491 u64 d0, d1, d2, d3, d4;
2492 static const u64 RC[] = {
2493 0x0000000000000001ULL, 0x0000000000008082ULL,
2494 0x800000000000808aULL, 0x8000000080008000ULL,
2495 0x000000000000808bULL, 0x0000000080000001ULL,
2496 0x8000000080008081ULL, 0x8000000000008009ULL,
2497 0x000000000000008aULL, 0x0000000000000088ULL,
2498 0x0000000080008009ULL, 0x000000008000000aULL,
2499 0x000000008000808bULL, 0x800000000000008bULL,
2500 0x8000000000008089ULL, 0x8000000000008003ULL,
2501 0x8000000000008002ULL, 0x8000000000000080ULL,
2502 0x000000000000800aULL, 0x800000008000000aULL,
2503 0x8000000080008081ULL, 0x8000000000008080ULL,
2504 0x0000000080000001ULL, 0x8000000080008008ULL
2505 };
2506# define a00 (p->u.s[0])
2507# define a01 (p->u.s[1])
2508# define a02 (p->u.s[2])
2509# define a03 (p->u.s[3])
2510# define a04 (p->u.s[4])
2511# define a10 (p->u.s[5])
2512# define a11 (p->u.s[6])
2513# define a12 (p->u.s[7])
2514# define a13 (p->u.s[8])
2515# define a14 (p->u.s[9])
2516# define a20 (p->u.s[10])
2517# define a21 (p->u.s[11])
2518# define a22 (p->u.s[12])
2519# define a23 (p->u.s[13])
2520# define a24 (p->u.s[14])
2521# define a30 (p->u.s[15])
2522# define a31 (p->u.s[16])
2523# define a32 (p->u.s[17])
2524# define a33 (p->u.s[18])
2525# define a34 (p->u.s[19])
2526# define a40 (p->u.s[20])
2527# define a41 (p->u.s[21])
2528# define a42 (p->u.s[22])
2529# define a43 (p->u.s[23])
2530# define a44 (p->u.s[24])
2531# define ROL64(a,x) ((a<<x)|(a>>(64-x)))
2532
2533 for(i=0; i<24; i+=4){
2534 c0 = a00^a10^a20^a30^a40;
2535 c1 = a01^a11^a21^a31^a41;
2536 c2 = a02^a12^a22^a32^a42;
2537 c3 = a03^a13^a23^a33^a43;
2538 c4 = a04^a14^a24^a34^a44;
2539 d0 = c4^ROL64(c1, 1);
2540 d1 = c0^ROL64(c2, 1);
2541 d2 = c1^ROL64(c3, 1);
2542 d3 = c2^ROL64(c4, 1);
2543 d4 = c3^ROL64(c0, 1);
2544
2545 b0 = (a00^d0);
2546 b1 = ROL64((a11^d1), 44);
2547 b2 = ROL64((a22^d2), 43);
2548 b3 = ROL64((a33^d3), 21);
2549 b4 = ROL64((a44^d4), 14);
2550 a00 = b0 ^((~b1)& b2 );
2551 a00 ^= RC[i];
2552 a11 = b1 ^((~b2)& b3 );
2553 a22 = b2 ^((~b3)& b4 );
2554 a33 = b3 ^((~b4)& b0 );
2555 a44 = b4 ^((~b0)& b1 );
2556
2557 b2 = ROL64((a20^d0), 3);
2558 b3 = ROL64((a31^d1), 45);
2559 b4 = ROL64((a42^d2), 61);
2560 b0 = ROL64((a03^d3), 28);
2561 b1 = ROL64((a14^d4), 20);
2562 a20 = b0 ^((~b1)& b2 );
2563 a31 = b1 ^((~b2)& b3 );
2564 a42 = b2 ^((~b3)& b4 );
2565 a03 = b3 ^((~b4)& b0 );
2566 a14 = b4 ^((~b0)& b1 );
2567
2568 b4 = ROL64((a40^d0), 18);
2569 b0 = ROL64((a01^d1), 1);
2570 b1 = ROL64((a12^d2), 6);
2571 b2 = ROL64((a23^d3), 25);
2572 b3 = ROL64((a34^d4), 8);
2573 a40 = b0 ^((~b1)& b2 );
2574 a01 = b1 ^((~b2)& b3 );
2575 a12 = b2 ^((~b3)& b4 );
2576 a23 = b3 ^((~b4)& b0 );
2577 a34 = b4 ^((~b0)& b1 );
2578
2579 b1 = ROL64((a10^d0), 36);
2580 b2 = ROL64((a21^d1), 10);
2581 b3 = ROL64((a32^d2), 15);
2582 b4 = ROL64((a43^d3), 56);
2583 b0 = ROL64((a04^d4), 27);
2584 a10 = b0 ^((~b1)& b2 );
2585 a21 = b1 ^((~b2)& b3 );
2586 a32 = b2 ^((~b3)& b4 );
2587 a43 = b3 ^((~b4)& b0 );
2588 a04 = b4 ^((~b0)& b1 );
2589
2590 b3 = ROL64((a30^d0), 41);
2591 b4 = ROL64((a41^d1), 2);
2592 b0 = ROL64((a02^d2), 62);
2593 b1 = ROL64((a13^d3), 55);
2594 b2 = ROL64((a24^d4), 39);
2595 a30 = b0 ^((~b1)& b2 );
2596 a41 = b1 ^((~b2)& b3 );
2597 a02 = b2 ^((~b3)& b4 );
2598 a13 = b3 ^((~b4)& b0 );
2599 a24 = b4 ^((~b0)& b1 );
2600
2601 c0 = a00^a20^a40^a10^a30;
2602 c1 = a11^a31^a01^a21^a41;
2603 c2 = a22^a42^a12^a32^a02;
2604 c3 = a33^a03^a23^a43^a13;
2605 c4 = a44^a14^a34^a04^a24;
2606 d0 = c4^ROL64(c1, 1);
2607 d1 = c0^ROL64(c2, 1);
2608 d2 = c1^ROL64(c3, 1);
2609 d3 = c2^ROL64(c4, 1);
2610 d4 = c3^ROL64(c0, 1);
2611
2612 b0 = (a00^d0);
2613 b1 = ROL64((a31^d1), 44);
2614 b2 = ROL64((a12^d2), 43);
2615 b3 = ROL64((a43^d3), 21);
2616 b4 = ROL64((a24^d4), 14);
2617 a00 = b0 ^((~b1)& b2 );
2618 a00 ^= RC[i+1];
2619 a31 = b1 ^((~b2)& b3 );
2620 a12 = b2 ^((~b3)& b4 );
2621 a43 = b3 ^((~b4)& b0 );
2622 a24 = b4 ^((~b0)& b1 );
2623
2624 b2 = ROL64((a40^d0), 3);
2625 b3 = ROL64((a21^d1), 45);
2626 b4 = ROL64((a02^d2), 61);
2627 b0 = ROL64((a33^d3), 28);
2628 b1 = ROL64((a14^d4), 20);
2629 a40 = b0 ^((~b1)& b2 );
2630 a21 = b1 ^((~b2)& b3 );
2631 a02 = b2 ^((~b3)& b4 );
2632 a33 = b3 ^((~b4)& b0 );
2633 a14 = b4 ^((~b0)& b1 );
2634
2635 b4 = ROL64((a30^d0), 18);
2636 b0 = ROL64((a11^d1), 1);
2637 b1 = ROL64((a42^d2), 6);
2638 b2 = ROL64((a23^d3), 25);
2639 b3 = ROL64((a04^d4), 8);
2640 a30 = b0 ^((~b1)& b2 );
2641 a11 = b1 ^((~b2)& b3 );
2642 a42 = b2 ^((~b3)& b4 );
2643 a23 = b3 ^((~b4)& b0 );
2644 a04 = b4 ^((~b0)& b1 );
2645
2646 b1 = ROL64((a20^d0), 36);
2647 b2 = ROL64((a01^d1), 10);
2648 b3 = ROL64((a32^d2), 15);
2649 b4 = ROL64((a13^d3), 56);
2650 b0 = ROL64((a44^d4), 27);
2651 a20 = b0 ^((~b1)& b2 );
2652 a01 = b1 ^((~b2)& b3 );
2653 a32 = b2 ^((~b3)& b4 );
2654 a13 = b3 ^((~b4)& b0 );
2655 a44 = b4 ^((~b0)& b1 );
2656
2657 b3 = ROL64((a10^d0), 41);
2658 b4 = ROL64((a41^d1), 2);
2659 b0 = ROL64((a22^d2), 62);
2660 b1 = ROL64((a03^d3), 55);
2661 b2 = ROL64((a34^d4), 39);
2662 a10 = b0 ^((~b1)& b2 );
2663 a41 = b1 ^((~b2)& b3 );
2664 a22 = b2 ^((~b3)& b4 );
2665 a03 = b3 ^((~b4)& b0 );
2666 a34 = b4 ^((~b0)& b1 );
2667
2668 c0 = a00^a40^a30^a20^a10;
2669 c1 = a31^a21^a11^a01^a41;
2670 c2 = a12^a02^a42^a32^a22;
2671 c3 = a43^a33^a23^a13^a03;
2672 c4 = a24^a14^a04^a44^a34;
2673 d0 = c4^ROL64(c1, 1);
2674 d1 = c0^ROL64(c2, 1);
2675 d2 = c1^ROL64(c3, 1);
2676 d3 = c2^ROL64(c4, 1);
2677 d4 = c3^ROL64(c0, 1);
2678
2679 b0 = (a00^d0);
2680 b1 = ROL64((a21^d1), 44);
2681 b2 = ROL64((a42^d2), 43);
2682 b3 = ROL64((a13^d3), 21);
2683 b4 = ROL64((a34^d4), 14);
2684 a00 = b0 ^((~b1)& b2 );
2685 a00 ^= RC[i+2];
2686 a21 = b1 ^((~b2)& b3 );
2687 a42 = b2 ^((~b3)& b4 );
2688 a13 = b3 ^((~b4)& b0 );
2689 a34 = b4 ^((~b0)& b1 );
2690
2691 b2 = ROL64((a30^d0), 3);
2692 b3 = ROL64((a01^d1), 45);
2693 b4 = ROL64((a22^d2), 61);
2694 b0 = ROL64((a43^d3), 28);
2695 b1 = ROL64((a14^d4), 20);
2696 a30 = b0 ^((~b1)& b2 );
2697 a01 = b1 ^((~b2)& b3 );
2698 a22 = b2 ^((~b3)& b4 );
2699 a43 = b3 ^((~b4)& b0 );
2700 a14 = b4 ^((~b0)& b1 );
2701
2702 b4 = ROL64((a10^d0), 18);
2703 b0 = ROL64((a31^d1), 1);
2704 b1 = ROL64((a02^d2), 6);
2705 b2 = ROL64((a23^d3), 25);
2706 b3 = ROL64((a44^d4), 8);
2707 a10 = b0 ^((~b1)& b2 );
2708 a31 = b1 ^((~b2)& b3 );
2709 a02 = b2 ^((~b3)& b4 );
2710 a23 = b3 ^((~b4)& b0 );
2711 a44 = b4 ^((~b0)& b1 );
2712
2713 b1 = ROL64((a40^d0), 36);
2714 b2 = ROL64((a11^d1), 10);
2715 b3 = ROL64((a32^d2), 15);
2716 b4 = ROL64((a03^d3), 56);
2717 b0 = ROL64((a24^d4), 27);
2718 a40 = b0 ^((~b1)& b2 );
2719 a11 = b1 ^((~b2)& b3 );
2720 a32 = b2 ^((~b3)& b4 );
2721 a03 = b3 ^((~b4)& b0 );
2722 a24 = b4 ^((~b0)& b1 );
2723
2724 b3 = ROL64((a20^d0), 41);
2725 b4 = ROL64((a41^d1), 2);
2726 b0 = ROL64((a12^d2), 62);
2727 b1 = ROL64((a33^d3), 55);
2728 b2 = ROL64((a04^d4), 39);
2729 a20 = b0 ^((~b1)& b2 );
2730 a41 = b1 ^((~b2)& b3 );
2731 a12 = b2 ^((~b3)& b4 );
2732 a33 = b3 ^((~b4)& b0 );
2733 a04 = b4 ^((~b0)& b1 );
2734
2735 c0 = a00^a30^a10^a40^a20;
2736 c1 = a21^a01^a31^a11^a41;
2737 c2 = a42^a22^a02^a32^a12;
2738 c3 = a13^a43^a23^a03^a33;
2739 c4 = a34^a14^a44^a24^a04;
2740 d0 = c4^ROL64(c1, 1);
2741 d1 = c0^ROL64(c2, 1);
2742 d2 = c1^ROL64(c3, 1);
2743 d3 = c2^ROL64(c4, 1);
2744 d4 = c3^ROL64(c0, 1);
2745
2746 b0 = (a00^d0);
2747 b1 = ROL64((a01^d1), 44);
2748 b2 = ROL64((a02^d2), 43);
2749 b3 = ROL64((a03^d3), 21);
2750 b4 = ROL64((a04^d4), 14);
2751 a00 = b0 ^((~b1)& b2 );
2752 a00 ^= RC[i+3];
2753 a01 = b1 ^((~b2)& b3 );
2754 a02 = b2 ^((~b3)& b4 );
2755 a03 = b3 ^((~b4)& b0 );
2756 a04 = b4 ^((~b0)& b1 );
2757
2758 b2 = ROL64((a10^d0), 3);
2759 b3 = ROL64((a11^d1), 45);
2760 b4 = ROL64((a12^d2), 61);
2761 b0 = ROL64((a13^d3), 28);
2762 b1 = ROL64((a14^d4), 20);
2763 a10 = b0 ^((~b1)& b2 );
2764 a11 = b1 ^((~b2)& b3 );
2765 a12 = b2 ^((~b3)& b4 );
2766 a13 = b3 ^((~b4)& b0 );
2767 a14 = b4 ^((~b0)& b1 );
2768
2769 b4 = ROL64((a20^d0), 18);
2770 b0 = ROL64((a21^d1), 1);
2771 b1 = ROL64((a22^d2), 6);
2772 b2 = ROL64((a23^d3), 25);
2773 b3 = ROL64((a24^d4), 8);
2774 a20 = b0 ^((~b1)& b2 );
2775 a21 = b1 ^((~b2)& b3 );
2776 a22 = b2 ^((~b3)& b4 );
2777 a23 = b3 ^((~b4)& b0 );
2778 a24 = b4 ^((~b0)& b1 );
2779
2780 b1 = ROL64((a30^d0), 36);
2781 b2 = ROL64((a31^d1), 10);
2782 b3 = ROL64((a32^d2), 15);
2783 b4 = ROL64((a33^d3), 56);
2784 b0 = ROL64((a34^d4), 27);
2785 a30 = b0 ^((~b1)& b2 );
2786 a31 = b1 ^((~b2)& b3 );
2787 a32 = b2 ^((~b3)& b4 );
2788 a33 = b3 ^((~b4)& b0 );
2789 a34 = b4 ^((~b0)& b1 );
2790
2791 b3 = ROL64((a40^d0), 41);
2792 b4 = ROL64((a41^d1), 2);
2793 b0 = ROL64((a42^d2), 62);
2794 b1 = ROL64((a43^d3), 55);
2795 b2 = ROL64((a44^d4), 39);
2796 a40 = b0 ^((~b1)& b2 );
2797 a41 = b1 ^((~b2)& b3 );
2798 a42 = b2 ^((~b3)& b4 );
2799 a43 = b3 ^((~b4)& b0 );
2800 a44 = b4 ^((~b0)& b1 );
2801 }
2802}
#define a20
#define a24
#define a14
#define a32
#define a04
#define a22
#define a02
#define a34
#define a40
#define a12
#define a13
#define a01
#define a41
#define a42
#define a11
#define a30
#define a10
#define ROL64(a, x)
#define a31
#define a21
#define a43
#define a00
#define a03
#define a44
#define a33
#define a23

References a00, a01, a02, a03, a04, a10, a11, a12, a13, a14, a20, a21, a22, a23, a24, a30, a31, a32, a33, a34, a40, a41, a42, a43, a44, and ROL64.

Referenced by SHA3Update().

Here is the caller graph for this function:

◆ line_is_command_terminator()

int line_is_command_terminator ( char * zLine)
static
32551 {
32552 while( IsSpace(zLine[0]) ){ zLine++; };
32553 if( zLine[0]=='/' )
32554 zLine += 1; /* Oracle */
32555 else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
32556 zLine += 2; /* SQL Server */
32557 else
32558 return 0;
#define ToLower(X)
Definition shell.c:238

References IsSpace, QSS_Start, quickscan(), and ToLower.

Referenced by process_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ line_is_complete()

int line_is_complete ( char * zSql,
int nSql )
static
32574 {
32575 int rc;
32576 if( zSql==0 ) return 1;
32577 zSql[nSql] = ';';
32578 zSql[nSql+1] = 0;
32579 rc = sqlite3_complete(zSql);
32580 zSql[nSql] = 0;
#define sqlite3_complete
Definition sqlite3ext.h:438

References sqlite3_complete.

Referenced by process_input().

Here is the caller graph for this function:

◆ lintDotCommand()

int lintDotCommand ( ShellState * pState,
char ** azArg,
int nArg )
static
27552 {
27553 int n;
27554 n = (nArg>=2 ? strlen30(azArg[1]) : 0);
27555 if( n<1 || sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ) goto usage;
27556 return lintFkeyIndexes(pState, azArg, nArg);
27557
27558 usage:
27559 sqlite3_fprintf(stderr,"Usage %s sub-command ?switches...?\n", azArg[0]);
27560 sqlite3_fprintf(stderr, "Where sub-commands are:\n");
27561 sqlite3_fprintf(stderr, " fkey-indexes\n");
static void usage(int showDetail)
Definition shell.c:33096
static int lintFkeyIndexes(ShellState *pState, char **azArg, int nArg)
Definition shell.c:27370

References lintFkeyIndexes(), sqlite3_fprintf, sqlite3_strnicmp, SQLITE_ERROR, strlen30(), and usage().

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lintFkeyIndexes()

int lintFkeyIndexes ( ShellState * pState,
char ** azArg,
int nArg )
static
27376 {
27377 sqlite3 *db = pState->db; /* Database handle to query "main" db of */
27378 int bVerbose = 0; /* If -verbose is present */
27379 int bGroupByParent = 0; /* If -groupbyparent is present */
27380 int i; /* To iterate through azArg[] */
27381 const char *zIndent = ""; /* How much to indent CREATE INDEX by */
27382 int rc; /* Return code */
27383 sqlite3_stmt *pSql = 0; /* Compiled version of SQL statement below */
27384 FILE *out = pState->out; /* Send output here */
27385
27386 /*
27387 ** This SELECT statement returns one row for each foreign key constraint
27388 ** in the schema of the main database. The column values are:
27389 **
27390 ** 0. The text of an SQL statement similar to:
27391 **
27392 ** "EXPLAIN QUERY PLAN SELECT 1 FROM child_table WHERE child_key=?"
27393 **
27394 ** This SELECT is similar to the one that the foreign keys implementation
27395 ** needs to run internally on child tables. If there is an index that can
27396 ** be used to optimize this query, then it can also be used by the FK
27397 ** implementation to optimize DELETE or UPDATE statements on the parent
27398 ** table.
27399 **
27400 ** 1. A GLOB pattern suitable for sqlite3_strglob(). If the plan output by
27401 ** the EXPLAIN QUERY PLAN command matches this pattern, then the schema
27402 ** contains an index that can be used to optimize the query.
27403 **
27404 ** 2. Human readable text that describes the child table and columns. e.g.
27405 **
27406 ** "child_table(child_key1, child_key2)"
27407 **
27408 ** 3. Human readable text that describes the parent table and columns. e.g.
27409 **
27410 ** "parent_table(parent_key1, parent_key2)"
27411 **
27412 ** 4. A full CREATE INDEX statement for an index that could be used to
27413 ** optimize DELETE or UPDATE statements on the parent table. e.g.
27414 **
27415 ** "CREATE INDEX child_table_child_key ON child_table(child_key)"
27416 **
27417 ** 5. The name of the parent table.
27418 **
27419 ** These six values are used by the C logic below to generate the report.
27420 */
27421 const char *zSql =
27422 "SELECT "
27423 " 'EXPLAIN QUERY PLAN SELECT 1 FROM ' || quote(s.name) || ' WHERE '"
27424 " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
27425 " || fkey_collate_clause("
27426 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
27427 ", "
27428 " 'SEARCH ' || s.name || ' USING COVERING INDEX*('"
27429 " || group_concat('*=?', ' AND ') || ')'"
27430 ", "
27431 " s.name || '(' || group_concat(f.[from], ', ') || ')'"
27432 ", "
27433 " f.[table] || '(' || group_concat(COALESCE(f.[to], p.[name])) || ')'"
27434 ", "
27435 " 'CREATE INDEX ' || quote(s.name ||'_'|| group_concat(f.[from], '_'))"
27436 " || ' ON ' || quote(s.name) || '('"
27437 " || group_concat(quote(f.[from]) ||"
27438 " fkey_collate_clause("
27439 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]), ', ')"
27440 " || ');'"
27441 ", "
27442 " f.[table] "
27443 "FROM sqlite_schema AS s, pragma_foreign_key_list(s.name) AS f "
27444 "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
27445 "GROUP BY s.name, f.id "
27446 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
27447 ;
27448 const char *zGlobIPK = "SEARCH * USING INTEGER PRIMARY KEY (rowid=?)";
27449
27450 for(i=2; i<nArg; i++){
27451 int n = strlen30(azArg[i]);
27452 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
27453 bVerbose = 1;
27454 }
27455 else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){
27456 bGroupByParent = 1;
27457 zIndent = " ";
27458 }
27459 else{
27460 sqlite3_fprintf(stderr,
27461 "Usage: %s %s ?-verbose? ?-groupbyparent?\n", azArg[0], azArg[1]);
27462 return SQLITE_ERROR;
27463 }
27464 }
27465
27466 /* Register the fkey_collate_clause() SQL function */
27467 rc = sqlite3_create_function(db, "fkey_collate_clause", 4, SQLITE_UTF8,
27468 0, shellFkeyCollateClause, 0, 0
27469 );
27470
27471
27472 if( rc==SQLITE_OK ){
27473 rc = sqlite3_prepare_v2(db, zSql, -1, &pSql, 0);
27474 }
27475 if( rc==SQLITE_OK ){
27476 sqlite3_bind_int(pSql, 1, bGroupByParent);
27477 }
27478
27479 if( rc==SQLITE_OK ){
27480 int rc2;
27481 char *zPrev = 0;
27482 while( SQLITE_ROW==sqlite3_step(pSql) ){
27483 int res = -1;
27484 sqlite3_stmt *pExplain = 0;
27485 const char *zEQP = (const char*)sqlite3_column_text(pSql, 0);
27486 const char *zGlob = (const char*)sqlite3_column_text(pSql, 1);
27487 const char *zFrom = (const char*)sqlite3_column_text(pSql, 2);
27488 const char *zTarget = (const char*)sqlite3_column_text(pSql, 3);
27489 const char *zCI = (const char*)sqlite3_column_text(pSql, 4);
27490 const char *zParent = (const char*)sqlite3_column_text(pSql, 5);
27491
27492 if( zEQP==0 ) continue;
27493 if( zGlob==0 ) continue;
27494 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
27495 if( rc!=SQLITE_OK ) break;
27496 if( SQLITE_ROW==sqlite3_step(pExplain) ){
27497 const char *zPlan = (const char*)sqlite3_column_text(pExplain, 3);
27498 res = zPlan!=0 && ( 0==sqlite3_strglob(zGlob, zPlan)
27499 || 0==sqlite3_strglob(zGlobIPK, zPlan));
27500 }
27501 rc = sqlite3_finalize(pExplain);
27502 if( rc!=SQLITE_OK ) break;
27503
27504 if( res<0 ){
27505 sqlite3_fputs("Error: internal error", stderr);
27506 break;
27507 }else{
27508 if( bGroupByParent
27509 && (bVerbose || res==0)
27510 && (zPrev==0 || sqlite3_stricmp(zParent, zPrev))
27511 ){
27512 sqlite3_fprintf(out, "-- Parent table %s\n", zParent);
27513 sqlite3_free(zPrev);
27514 zPrev = sqlite3_mprintf("%s", zParent);
27515 }
27516
27517 if( res==0 ){
27518 sqlite3_fprintf(out, "%s%s --> %s\n", zIndent, zCI, zTarget);
27519 }else if( bVerbose ){
27520 sqlite3_fprintf(out,
27521 "%s/* no extra indexes required for %s -> %s */\n",
27522 zIndent, zFrom, zTarget
27523 );
27524 }
27525 }
27526 }
27527 sqlite3_free(zPrev);
27528
27529 if( rc!=SQLITE_OK ){
27530 sqlite3_fprintf(stderr,"%s\n", sqlite3_errmsg(db));
27531 }
27532
27533 rc2 = sqlite3_finalize(pSql);
27534 if( rc==SQLITE_OK && rc2!=SQLITE_OK ){
27535 rc = rc2;
27536 sqlite3_fprintf(stderr,"%s\n", sqlite3_errmsg(db));
27537 }
27538 }else{
27539 sqlite3_fprintf(stderr,"%s\n", sqlite3_errmsg(db));
27540 }
27541
static void shellFkeyCollateClause(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
Definition shell.c:27329

References ShellState::db, ShellState::out, shellFkeyCollateClause(), sqlite3_bind_int, sqlite3_column_text, sqlite3_create_function, sqlite3_errmsg, sqlite3_finalize, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_mprintf, sqlite3_prepare_v2, sqlite3_step, sqlite3_strglob, sqlite3_stricmp, sqlite3_strnicmp, SQLITE_ERROR, SQLITE_OK, SQLITE_ROW, SQLITE_UTF8, and strlen30().

Referenced by lintDotCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ local_getline()

char * local_getline ( char * zLine,
FILE * in )
static
1324 {
1325 int nLine = zLine==0 ? 0 : 100;
1326 int n = 0;
1327
1328 while( 1 ){
1329 if( n+100>nLine ){
1330 nLine = nLine*2 + 100;
1331 zLine = realloc(zLine, nLine);
1332 shell_check_oom(zLine);
1333 }
1334 if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){
1335 if( n==0 ){
1336 free(zLine);
1337 return 0;
1338 }
1339 zLine[n] = 0;
1340 break;
1341 }
1342 while( zLine[n] ) n++;
1343 if( n>0 && zLine[n-1]=='\n' ){
1344 n--;
1345 if( n>0 && zLine[n-1]=='\r' ) n--;
1346 zLine[n] = 0;
1347 break;
1348 }
1349 }
1350 return zLine;
1351}
#define sqlite3_fgets
Definition shell.c:304

References shell_check_oom(), and sqlite3_fgets.

Referenced by one_input_line().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lockName()

const char * lockName ( int eLock)
static
16694 {
16695 const char *azLockNames[] = {
16696 "NONE", "SHARED", "RESERVED", "PENDING", "EXCLUSIVE"
16697 };
16698 if( eLock<0 || eLock>=(int)(sizeof(azLockNames)/sizeof(azLockNames[0])) ){
16699 return "???";
16700 }else{
16701 return azLockNames[eLock];
16702 }
16703}

Referenced by vfstraceLock(), and vfstraceUnlock().

Here is the caller graph for this function:

◆ lsModeFunc()

void lsModeFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
8517 {
8518 int i;
8519 int iMode = sqlite3_value_int(argv[0]);
8520 char z[16];
8521 (void)argc;
8522 if( S_ISLNK(iMode) ){
8523 z[0] = 'l';
8524 }else if( S_ISREG(iMode) ){
8525 z[0] = '-';
8526 }else if( S_ISDIR(iMode) ){
8527 z[0] = 'd';
8528 }else{
8529 z[0] = '?';
8530 }
8531 for(i=0; i<3; i++){
8532 int m = (iMode >> ((2-i)*3));
8533 char *a = &z[1 + i*3];
8534 a[0] = (m & 0x4) ? 'r' : '-';
8535 a[1] = (m & 0x2) ? 'w' : '-';
8536 a[2] = (m & 0x1) ? 'x' : '-';
8537 }
8538 z[10] = '\0';
8539 sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
8540}

References a, sqlite3_result_text, sqlite3_value_int, and SQLITE_TRANSIENT.

Referenced by sqlite3_fileio_init().

Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )
33210 {
33211#else
33212int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
33213 char **argv;
33214#endif
33215#ifdef SQLITE_DEBUG
33216 sqlite3_int64 mem_main_enter = 0;
33217#endif
33218 char *zErrMsg = 0;
33219#ifdef SQLITE_SHELL_FIDDLE
33220# define data shellState
33221#else
33222 ShellState data;
33223#endif
33224 const char *zInitFile = 0;
33225 int i;
33226 int rc = 0;
33227 int warnInmemoryDb = 0;
33228 int readStdin = 1;
33229 int nCmd = 0;
33230 int nOptsEnd = argc;
33231 int bEnableVfstrace = 0;
33232 char **azCmd = 0;
33233 const char *zVfs = 0; /* Value of -vfs command-line option */
33234#if !SQLITE_SHELL_IS_UTF8
33235 char **argvToFree = 0;
33236 int argcToFree = 0;
33237#endif
33238 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
33239
33240#ifdef SQLITE_SHELL_FIDDLE
33243 data.wasm.zDefaultDbName = "/fiddle.sqlite3";
33244#else
33247#endif
33248 atexit(sayAbnormalExit);
33249#ifdef SQLITE_DEBUG
33250 mem_main_enter = sqlite3_memory_used();
33251#endif
33252#if !defined(_WIN32_WCE)
33253 if( getenv("SQLITE_DEBUG_BREAK") ){
33254 if( isatty(0) && isatty(2) ){
33255 char zLine[100];
33256 sqlite3_fprintf(stderr,
33257 "attach debugger to process %d and press ENTER to continue...",
33258 GETPID());
33259 if( sqlite3_fgets(zLine, sizeof(zLine), stdin)!=0
33260 && cli_strcmp(zLine,"stop")==0
33261 ){
33262 exit(1);
33263 }
33264 }else{
33265#if defined(_WIN32) || defined(WIN32)
33266#if SQLITE_OS_WINRT
33267 __debugbreak();
33268#else
33269 DebugBreak();
33270#endif
33271#elif defined(SIGTRAP)
33272 raise(SIGTRAP);
33273#endif
33274 }
33275 }
33276#endif
33277 /* Register a valid signal handler early, before much else is done. */
33278#ifdef SIGINT
33279 signal(SIGINT, interrupt_handler);
33280#elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
33281 if( !SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE) ){
33282 eputz("No ^C handler.\n");
33283 }
33284#endif
33285
33286#if USE_SYSTEM_SQLITE+0!=1
33288 sqlite3_fprintf(stderr,
33289 "SQLite header and source version mismatch\n%s\n%s\n",
33291 exit(1);
33292 }
33293#endif
33294 main_init(&data);
33295
33296 /* On Windows, we must translate command-line arguments into UTF-8.
33297 ** The SQLite memory allocator subsystem has to be enabled in order to
33298 ** do this. But we want to run an sqlite3_shutdown() afterwards so that
33299 ** subsequent sqlite3_config() calls will work. So copy all results into
33300 ** memory that does not come from the SQLite memory allocator.
33301 */
33302#if !SQLITE_SHELL_IS_UTF8
33304 argvToFree = malloc(sizeof(argv[0])*argc*2);
33305 shell_check_oom(argvToFree);
33306 argcToFree = argc;
33307 argv = argvToFree + argc;
33308 for(i=0; i<argc; i++){
33309 char *z = sqlite3_win32_unicode_to_utf8(wargv[i]);
33310 i64 n;
33311 shell_check_oom(z);
33312 n = strlen(z);
33313 argv[i] = malloc( n+1 );
33314 shell_check_oom(argv[i]);
33315 memcpy(argv[i], z, n+1);
33316 argvToFree[i] = argv[i];
33317 sqlite3_free(z);
33318 }
33320#endif
33321
33322 assert( argc>=1 && argv && argv[0] );
33323 Argv0 = argv[0];
33324
33325#ifdef SQLITE_SHELL_DBNAME_PROC
33326 {
33327 /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
33328 ** of a C-function that will provide the name of the database file. Use
33329 ** this compile-time option to embed this shell program in larger
33330 ** applications. */
33331 extern void SQLITE_SHELL_DBNAME_PROC(const char**);
33332 SQLITE_SHELL_DBNAME_PROC(&data.pAuxDb->zDbFilename);
33333 warnInmemoryDb = 0;
33334 }
33335#endif
33336
33337 /* Do an initial pass through the command-line argument to locate
33338 ** the name of the database file, the name of the initialization file,
33339 ** the size of the alternative malloc heap, options affecting commands
33340 ** or SQL run from the command line, and the first command to execute.
33341 */
33342#ifndef SQLITE_SHELL_FIDDLE
33344#endif
33345 for(i=1; i<argc; i++){
33346 char *z;
33347 z = argv[i];
33348 if( z[0]!='-' || i>nOptsEnd ){
33349 if( data.aAuxDb->zDbFilename==0 ){
33350 data.aAuxDb->zDbFilename = z;
33351 }else{
33352 /* Excess arguments are interpreted as SQL (or dot-commands) and
33353 ** mean that nothing is read from stdin */
33354 readStdin = 0;
33355 nCmd++;
33356 azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
33357 shell_check_oom(azCmd);
33358 azCmd[nCmd-1] = z;
33359 }
33360 continue;
33361 }
33362 if( z[1]=='-' ) z++;
33363 if( cli_strcmp(z, "-")==0 ){
33364 nOptsEnd = i;
33365 continue;
33366 }else if( cli_strcmp(z,"-separator")==0
33367 || cli_strcmp(z,"-nullvalue")==0
33368 || cli_strcmp(z,"-newline")==0
33369 || cli_strcmp(z,"-cmd")==0
33370 ){
33371 (void)cmdline_option_value(argc, argv, ++i);
33372 }else if( cli_strcmp(z,"-init")==0 ){
33373 zInitFile = cmdline_option_value(argc, argv, ++i);
33374 }else if( cli_strcmp(z,"-interactive")==0 ){
33375 }else if( cli_strcmp(z,"-batch")==0 ){
33376 /* Need to check for batch mode here to so we can avoid printing
33377 ** informational messages (like from process_sqliterc) before
33378 ** we do the actual processing of arguments later in a second pass.
33379 */
33381 }else if( cli_strcmp(z,"-utf8")==0 ){
33382 }else if( cli_strcmp(z,"-no-utf8")==0 ){
33383 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
33384 int val = 0;
33386 assert( val==0 );
33387 }else if( cli_strcmp(z,"-heap")==0 ){
33388#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
33389 const char *zSize;
33390 sqlite3_int64 szHeap;
33391
33392 zSize = cmdline_option_value(argc, argv, ++i);
33393 szHeap = integerValue(zSize);
33394 if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
33396 sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
33397#else
33398 (void)cmdline_option_value(argc, argv, ++i);
33399#endif
33400 }else if( cli_strcmp(z,"-pagecache")==0 ){
33401 sqlite3_int64 n, sz;
33402 sz = integerValue(cmdline_option_value(argc,argv,++i));
33403 if( sz>70000 ) sz = 70000;
33404 if( sz<0 ) sz = 0;
33405 n = integerValue(cmdline_option_value(argc,argv,++i));
33406 if( sz>0 && n>0 && 0xffffffffffffLL/sz<n ){
33407 n = 0xffffffffffffLL/sz;
33408 }
33411 (n>0 && sz>0) ? malloc(n*sz) : 0, sz, n);
33412 data.shellFlgs |= SHFLG_Pagecache;
33413 }else if( cli_strcmp(z,"-lookaside")==0 ){
33414 int n, sz;
33415 sz = (int)integerValue(cmdline_option_value(argc,argv,++i));
33416 if( sz<0 ) sz = 0;
33417 n = (int)integerValue(cmdline_option_value(argc,argv,++i));
33418 if( n<0 ) n = 0;
33421 if( sz*n==0 ) data.shellFlgs &= ~SHFLG_Lookaside;
33422 }else if( cli_strcmp(z,"-threadsafe")==0 ){
33423 int n;
33424 n = (int)integerValue(cmdline_option_value(argc,argv,++i));
33426 switch( n ){
33430 }
33431 }else if( cli_strcmp(z,"-vfstrace")==0 ){
33432 bEnableVfstrace = 1;
33433#ifdef SQLITE_ENABLE_MULTIPLEX
33434 }else if( cli_strcmp(z,"-multiplex")==0 ){
33435 extern int sqlite3_multiplex_initialize(const char*,int);
33436 sqlite3_multiplex_initialize(0, 1);
33437#endif
33438 }else if( cli_strcmp(z,"-mmap")==0 ){
33439 sqlite3_int64 sz = integerValue(cmdline_option_value(argc,argv,++i));
33442#if defined(SQLITE_ENABLE_SORTER_REFERENCES)
33443 }else if( cli_strcmp(z,"-sorterref")==0 ){
33444 sqlite3_int64 sz = integerValue(cmdline_option_value(argc,argv,++i));
33447#endif
33448 }else if( cli_strcmp(z,"-vfs")==0 ){
33449 zVfs = cmdline_option_value(argc, argv, ++i);
33450#ifdef SQLITE_HAVE_ZLIB
33451 }else if( cli_strcmp(z,"-zip")==0 ){
33453#endif
33454 }else if( cli_strcmp(z,"-append")==0 ){
33456#ifndef SQLITE_OMIT_DESERIALIZE
33457 }else if( cli_strcmp(z,"-deserialize")==0 ){
33459 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
33460 data.szMax = integerValue(argv[++i]);
33461#endif
33462 }else if( cli_strcmp(z,"-readonly")==0 ){
33464 }else if( cli_strcmp(z,"-nofollow")==0 ){
33466#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
33467 }else if( cli_strncmp(z, "-A",2)==0 ){
33468 /* All remaining command-line arguments are passed to the ".archive"
33469 ** command, so ignore them */
33470 break;
33471#endif
33472 }else if( cli_strcmp(z, "-memtrace")==0 ){
33474 }else if( cli_strcmp(z, "-pcachetrace")==0 ){
33476 }else if( cli_strcmp(z,"-bail")==0 ){
33477 bail_on_error = 1;
33478 }else if( cli_strcmp(z,"-nonce")==0 ){
33479 free(data.zNonce);
33480 data.zNonce = strdup(cmdline_option_value(argc, argv, ++i));
33481 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
33483 }else if( cli_strcmp(z,"-safe")==0 ){
33484 /* no-op - catch this on the second pass */
33485 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
33486 /* skip over the argument */
33487 i++;
33488 }
33489 }
33490#ifndef SQLITE_SHELL_FIDDLE
33491 if( !bEnableVfstrace ) verify_uninitialized();
33492#endif
33493
33494
33495#ifdef SQLITE_SHELL_INIT_PROC
33496 {
33497 /* If the SQLITE_SHELL_INIT_PROC macro is defined, then it is the name
33498 ** of a C-function that will perform initialization actions on SQLite that
33499 ** occur just before or after sqlite3_initialize(). Use this compile-time
33500 ** option to embed this shell program in larger applications. */
33501 extern void SQLITE_SHELL_INIT_PROC(void);
33502 SQLITE_SHELL_INIT_PROC();
33503 }
33504#else
33505 /* All the sqlite3_config() calls have now been made. So it is safe
33506 ** to call sqlite3_initialize() and process any command line -vfs option. */
33508#endif
33509
33510 if( zVfs ){
33511 sqlite3_vfs *pVfs = sqlite3_vfs_find(zVfs);
33512 if( pVfs ){
33513 sqlite3_vfs_register(pVfs, 1);
33514 }else{
33515 sqlite3_fprintf(stderr,"no such VFS: \"%s\"\n", zVfs);
33516 exit(1);
33517 }
33518 }
33519
33520 if( data.pAuxDb->zDbFilename==0 ){
33521#ifndef SQLITE_OMIT_MEMORYDB
33522 data.pAuxDb->zDbFilename = ":memory:";
33523 warnInmemoryDb = argc==1;
33524#else
33525 sqlite3_fprintf(stderr,
33526 "%s: Error: no database filename specified\n", Argv0);
33527 return 1;
33528#endif
33529 }
33530 data.out = stdout;
33531 if( bEnableVfstrace ){
33532 vfstrace_register("trace",0,vfstraceOut, &data, 1);
33533 }
33534#ifndef SQLITE_SHELL_FIDDLE
33536#endif
33537
33538 /* Go ahead and open the database file if it already exists. If the
33539 ** file does not exist, delay opening it. This prevents empty database
33540 ** files from being created if a user mistypes the database name argument
33541 ** to the sqlite command-line tool.
33542 */
33543 if( access(data.pAuxDb->zDbFilename, 0)==0 ){
33544 open_db(&data, 0);
33545 }
33546
33547 /* Process the initialization file if there is one. If no -init option
33548 ** is given on the command line, look for a file named ~/.sqliterc and
33549 ** try to process it.
33550 */
33551 process_sqliterc(&data,zInitFile);
33552
33553 /* Make a second pass through the command-line argument and set
33554 ** options. This second pass is delayed until after the initialization
33555 ** file is processed so that the command-line arguments will override
33556 ** settings in the initialization file.
33557 */
33558 for(i=1; i<argc; i++){
33559 char *z = argv[i];
33560 if( z[0]!='-' || i>=nOptsEnd ) continue;
33561 if( z[1]=='-' ){ z++; }
33562 if( cli_strcmp(z,"-init")==0 ){
33563 i++;
33564 }else if( cli_strcmp(z,"-html")==0 ){
33565 data.mode = MODE_Html;
33566 }else if( cli_strcmp(z,"-list")==0 ){
33567 data.mode = MODE_List;
33568 }else if( cli_strcmp(z,"-quote")==0 ){
33569 data.mode = MODE_Quote;
33572 }else if( cli_strcmp(z,"-line")==0 ){
33573 data.mode = MODE_Line;
33574 }else if( cli_strcmp(z,"-column")==0 ){
33575 data.mode = MODE_Column;
33576 }else if( cli_strcmp(z,"-json")==0 ){
33577 data.mode = MODE_Json;
33578 }else if( cli_strcmp(z,"-markdown")==0 ){
33579 data.mode = MODE_Markdown;
33580 }else if( cli_strcmp(z,"-table")==0 ){
33581 data.mode = MODE_Table;
33582 }else if( cli_strcmp(z,"-box")==0 ){
33583 data.mode = MODE_Box;
33584 }else if( cli_strcmp(z,"-csv")==0 ){
33585 data.mode = MODE_Csv;
33586 memcpy(data.colSeparator,",",2);
33587 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
33588 /* See similar code at tag-20250224-1 */
33589 const char *zEsc = argv[++i];
33590 int k;
33591 for(k=0; k<ArraySize(shell_EscModeNames); k++){
33592 if( sqlite3_stricmp(zEsc,shell_EscModeNames[k])==0 ){
33593 data.eEscMode = k;
33594 break;
33595 }
33596 }
33597 if( k>=ArraySize(shell_EscModeNames) ){
33598 sqlite3_fprintf(stderr, "unknown control character escape mode \"%s\""
33599 " - choices:", zEsc);
33600 for(k=0; k<ArraySize(shell_EscModeNames); k++){
33601 sqlite3_fprintf(stderr, " %s", shell_EscModeNames[k]);
33602 }
33603 sqlite3_fprintf(stderr, "\n");
33604 exit(1);
33605 }
33606#ifdef SQLITE_HAVE_ZLIB
33607 }else if( cli_strcmp(z,"-zip")==0 ){
33609#endif
33610 }else if( cli_strcmp(z,"-append")==0 ){
33612#ifndef SQLITE_OMIT_DESERIALIZE
33613 }else if( cli_strcmp(z,"-deserialize")==0 ){
33615 }else if( cli_strcmp(z,"-maxsize")==0 && i+1<argc ){
33616 data.szMax = integerValue(argv[++i]);
33617#endif
33618 }else if( cli_strcmp(z,"-readonly")==0 ){
33620 }else if( cli_strcmp(z,"-nofollow")==0 ){
33622 }else if( cli_strcmp(z,"-ascii")==0 ){
33623 data.mode = MODE_Ascii;
33626 }else if( cli_strcmp(z,"-tabs")==0 ){
33627 data.mode = MODE_List;
33630 }else if( cli_strcmp(z,"-separator")==0 ){
33631 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
33632 "%s",cmdline_option_value(argc,argv,++i));
33633 }else if( cli_strcmp(z,"-newline")==0 ){
33634 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
33635 "%s",cmdline_option_value(argc,argv,++i));
33636 }else if( cli_strcmp(z,"-nullvalue")==0 ){
33637 sqlite3_snprintf(sizeof(data.nullValue), data.nullValue,
33638 "%s",cmdline_option_value(argc,argv,++i));
33639 }else if( cli_strcmp(z,"-header")==0 ){
33640 data.showHeader = 1;
33642 }else if( cli_strcmp(z,"-noheader")==0 ){
33643 data.showHeader = 0;
33645 }else if( cli_strcmp(z,"-echo")==0 ){
33646 ShellSetFlag(&data, SHFLG_Echo);
33647 }else if( cli_strcmp(z,"-eqp")==0 ){
33648 data.autoEQP = AUTOEQP_on;
33649 }else if( cli_strcmp(z,"-eqpfull")==0 ){
33650 data.autoEQP = AUTOEQP_full;
33651 }else if( cli_strcmp(z,"-stats")==0 ){
33652 data.statsOn = 1;
33653 }else if( cli_strcmp(z,"-scanstats")==0 ){
33654 data.scanstatsOn = 1;
33655 }else if( cli_strcmp(z,"-backslash")==0 ){
33656 /* Undocumented command-line option: -backslash
33657 ** Causes C-style backslash escapes to be evaluated in SQL statements
33658 ** prior to sending the SQL into SQLite. Useful for injecting
33659 ** crazy bytes in the middle of SQL statements for testing and debugging.
33660 */
33662 }else if( cli_strcmp(z,"-bail")==0 ){
33663 /* No-op. The bail_on_error flag should already be set. */
33664 }else if( cli_strcmp(z,"-version")==0 ){
33665 sqlite3_fprintf(stdout, "%s %s (%d-bit)\n",
33666 sqlite3_libversion(), sqlite3_sourceid(), 8*(int)sizeof(char*));
33667 return 0;
33668 }else if( cli_strcmp(z,"-interactive")==0 ){
33669 /* Need to check for interactive override here to so that it can
33670 ** affect console setup (for Windows only) and testing thereof.
33671 */
33673 }else if( cli_strcmp(z,"-batch")==0 ){
33674 /* already handled */
33675 }else if( cli_strcmp(z,"-utf8")==0 ){
33676 /* already handled */
33677 }else if( cli_strcmp(z,"-no-utf8")==0 ){
33678 /* already handled */
33679 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
33680 /* already handled */
33681 }else if( cli_strcmp(z,"-heap")==0 ){
33682 i++;
33683 }else if( cli_strcmp(z,"-pagecache")==0 ){
33684 i+=2;
33685 }else if( cli_strcmp(z,"-lookaside")==0 ){
33686 i+=2;
33687 }else if( cli_strcmp(z,"-threadsafe")==0 ){
33688 i+=2;
33689 }else if( cli_strcmp(z,"-nonce")==0 ){
33690 i += 2;
33691 }else if( cli_strcmp(z,"-mmap")==0 ){
33692 i++;
33693 }else if( cli_strcmp(z,"-memtrace")==0 ){
33694 i++;
33695 }else if( cli_strcmp(z,"-pcachetrace")==0 ){
33696 i++;
33697#ifdef SQLITE_ENABLE_SORTER_REFERENCES
33698 }else if( cli_strcmp(z,"-sorterref")==0 ){
33699 i++;
33700#endif
33701 }else if( cli_strcmp(z,"-vfs")==0 ){
33702 i++;
33703 }else if( cli_strcmp(z,"-vfstrace")==0 ){
33704 i++;
33705#ifdef SQLITE_ENABLE_MULTIPLEX
33706 }else if( cli_strcmp(z,"-multiplex")==0 ){
33707 i++;
33708#endif
33709 }else if( cli_strcmp(z,"-help")==0 ){
33710 usage(1);
33711 }else if( cli_strcmp(z,"-cmd")==0 ){
33712 /* Run commands that follow -cmd first and separately from commands
33713 ** that simply appear on the command-line. This seems goofy. It would
33714 ** be better if all commands ran in the order that they appear. But
33715 ** we retain the goofy behavior for historical compatibility. */
33716 if( i==argc-1 ) break;
33717 z = cmdline_option_value(argc,argv,++i);
33718 if( z[0]=='.' ){
33719 rc = do_meta_command(z, &data);
33720 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
33721 }else{
33722 open_db(&data, 0);
33723 rc = shell_exec(&data, z, &zErrMsg);
33724 if( zErrMsg!=0 ){
33725 shellEmitError(zErrMsg);
33726 if( bail_on_error ) return rc!=0 ? rc : 1;
33727 }else if( rc!=0 ){
33728 sqlite3_fprintf(stderr,"Error: unable to process SQL \"%s\"\n", z);
33729 if( bail_on_error ) return rc;
33730 }
33731 }
33732#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
33733 }else if( cli_strncmp(z, "-A", 2)==0 ){
33734 if( nCmd>0 ){
33735 sqlite3_fprintf(stderr,"Error: cannot mix regular SQL or dot-commands"
33736 " with \"%s\"\n", z);
33737 return 1;
33738 }
33739 open_db(&data, OPEN_DB_ZIPFILE);
33740 if( z[2] ){
33741 argv[i] = &z[2];
33742 arDotCommand(&data, 1, argv+(i-1), argc-(i-1));
33743 }else{
33744 arDotCommand(&data, 1, argv+i, argc-i);
33745 }
33746 readStdin = 0;
33747 break;
33748#endif
33749 }else if( cli_strcmp(z,"-safe")==0 ){
33750 data.bSafeMode = data.bSafeModePersist = 1;
33751 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
33752 /* Acted upon in first pass. */
33753 }else{
33754 sqlite3_fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
33755 eputz("Use -help for a list of options.\n");
33756 return 1;
33757 }
33758 data.cMode = data.mode;
33759 }
33760
33761 if( !readStdin ){
33762 /* Run all arguments that do not begin with '-' as if they were separate
33763 ** command-line inputs, except for the argToSkip argument which contains
33764 ** the database filename.
33765 */
33766 for(i=0; i<nCmd; i++){
33767 echo_group_input(&data, azCmd[i]);
33768 if( azCmd[i][0]=='.' ){
33769 rc = do_meta_command(azCmd[i], &data);
33770 if( rc ){
33771 if( rc==2 ) rc = 0;
33772 goto shell_main_exit;
33773 }
33774 }else{
33775 open_db(&data, 0);
33776 rc = shell_exec(&data, azCmd[i], &zErrMsg);
33777 if( zErrMsg || rc ){
33778 if( zErrMsg!=0 ){
33779 shellEmitError(zErrMsg);
33780 }else{
33781 sqlite3_fprintf(stderr,
33782 "Error: unable to process SQL: %s\n", azCmd[i]);
33783 }
33784 sqlite3_free(zErrMsg);
33785 if( rc==0 ) rc = 1;
33786 goto shell_main_exit;
33787 }
33788 }
33789 }
33790 }else{
33791 /* Run commands received from standard input
33792 */
33794 char *zHome;
33795 char *zHistory;
33796 int nHistory;
33797 sqlite3_fprintf(stdout,
33798 "SQLite version %s %.19s\n" /*extra-version-info*/
33799 "Enter \".help\" for usage hints.\n",
33801 if( warnInmemoryDb ){
33802 sputz(stdout, "Connected to a ");
33803 printBold("transient in-memory database");
33804 sputz(stdout, ".\nUse \".open FILENAME\" to reopen on a"
33805 " persistent database.\n");
33806 }
33807 zHistory = getenv("SQLITE_HISTORY");
33808 if( zHistory ){
33809 zHistory = strdup(zHistory);
33810 }else if( (zHome = find_home_dir(0))!=0 ){
33811 nHistory = strlen30(zHome) + 20;
33812 if( (zHistory = malloc(nHistory))!=0 ){
33813 sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
33814 }
33815 }
33816 if( zHistory ){ shell_read_history(zHistory); }
33817#if (HAVE_READLINE || HAVE_EDITLINE) && !defined(SQLITE_OMIT_READLINE_COMPLETION)
33818 rl_attempted_completion_function = readline_completion;
33819#elif HAVE_LINENOISE==1
33820 linenoiseSetCompletionCallback(linenoise_completion);
33821#elif HAVE_LINENOISE==2
33822 linenoiseSetCompletionCallback(linenoise_completion, NULL);
33823#endif
33824 data.in = 0;
33825 rc = process_input(&data);
33826 if( zHistory ){
33828 shell_write_history(zHistory);
33829 free(zHistory);
33830 }
33831 }else{
33832 data.in = stdin;
33833 rc = process_input(&data);
33834 }
33835 }
33836#ifndef SQLITE_SHELL_FIDDLE
33837 /* In WASM mode we have to leave the db state in place so that
33838 ** client code can "push" SQL into it after this call returns. */
33839#ifndef SQLITE_OMIT_VIRTUALTABLE
33840 if( data.expert.pExpert ){
33841 expertFinish(&data, 1, 0);
33842 }
33843#endif
33844 shell_main_exit:
33845 free(azCmd);
33846 set_table_name(&data, 0);
33847 if( data.db ){
33848 session_close_all(&data, -1);
33849 close_db(data.db);
33850 }
33851 for(i=0; i<ArraySize(data.aAuxDb); i++){
33853 if( data.aAuxDb[i].db ){
33854 session_close_all(&data, i);
33855 close_db(data.aAuxDb[i].db);
33856 }
33857 }
33858 find_home_dir(1);
33859 output_reset(&data);
33860 data.doXdgOpen = 0;
33861 clearTempFile(&data);
33862#if !SQLITE_SHELL_IS_UTF8
33863 for(i=0; i<argcToFree; i++) free(argvToFree[i]);
33864 free(argvToFree);
33865#endif
33866 free(data.colWidth);
33867 free(data.zNonce);
33868 /* Clear the global data structure so that valgrind will detect memory
33869 ** leaks */
33870 memset(&data, 0, sizeof(data));
33871 if( bEnableVfstrace ){
33872 vfstrace_unregister("trace");
33873 }
33874#ifdef SQLITE_DEBUG
33875 if( sqlite3_memory_used()>mem_main_enter ){
33876 sqlite3_fprintf(stderr,"Memory leaked: %u bytes\n",
33877 (unsigned int)(sqlite3_memory_used()-mem_main_enter));
33878 }
33879#endif
33880#else /* SQLITE_SHELL_FIDDLE... */
33881 shell_main_exit:
33882#endif
static int stdout_is_console
Definition shell.c:832
static void process_sqliterc(ShellState *p, const char *sqliterc_override)
Definition shell.c:32989
static void echo_group_input(ShellState *p, const char *zDo)
Definition shell.c:32719
static void printBold(const char *zText)
Definition shell.c:33163
static int vfstraceOut(const char *z, void *pArg)
Definition shell.c:33187
static void sayAbnormalExit(void)
Definition shell.c:33181
int sqlite3PcacheTraceActivate(FILE *out)
Definition shell.c:2305
static char * find_home_dir(int clearFlag)
Definition shell.c:32882
#define SHFLG_Backslash
Definition shell.c:21797
static void verify_uninitialized(void)
Definition shell.c:33112
int sqlite3_appendvfs_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:10177
int vfstrace_register(const char *zTraceName, const char *zOldVfsName, int(*xOut)(const char *, void *), void *pOutArg, int makeDefault)
Definition shell.c:17347
static void interrupt_handler(int NotUsed)
Definition shell.c:22549
static void main_init(ShellState *data)
Definition shell.c:33122
#define GETPID
Definition shell.c:137
#define shell_stifle_history(X)
Definition shell.c:180
#define OPEN_DB_ZIPFILE
Definition shell.c:25969
#define shell_write_history(X)
Definition shell.c:179
int sqlite3MemTraceActivate(FILE *out)
Definition shell.c:2123
int isatty(int)
static char * cmdline_option_value(int argc, char **argv, int i)
Definition shell.c:33172
static char * Argv0
Definition shell.c:850
void vfstrace_unregister(const char *zTraceName)
Definition shell.c:17414
#define shell_read_history(X)
Definition shell.c:178
static int do_meta_command(char *zLine, ShellState *p)
Definition shell.c:28802
int sqlite3_initialize(void)
Definition sqlite3.c:182783
#define SQLITE_CONFIG_HEAP
Definition sqlite3.c:2515
#define SQLITE_SOURCE_ID
Definition sqlite3.c:470
#define SQLITE_CONFIG_PAGECACHE
Definition sqlite3.c:2514
#define SQLITE_CONFIG_MULTITHREAD
Definition sqlite3.c:2509
int sqlite3_shutdown(void)
Definition sqlite3.c:182965
#define SQLITE_CONFIG_LOOKASIDE
Definition sqlite3.c:2520
int sqlite3_config(int,...)
Definition sqlite3.c:183019
#define SQLITE_CONFIG_MMAP_SIZE
Definition sqlite3.c:2529
#define SQLITE_CONFIG_ROWID_IN_VIEW
Definition sqlite3.c:2537
#define SQLITE_CONFIG_SERIALIZED
Definition sqlite3.c:2510
#define SQLITE_CONFIG_SINGLETHREAD
Definition sqlite3.c:2508
#define SQLITE_CONFIG_SORTERREF_SIZE
Definition sqlite3.c:2535
#define sqlite3_vfs_register
Definition sqlite3ext.h:548
#define sqlite3_memory_used
Definition sqlite3ext.h:535

References a, ShellState::aAuxDb, Argv0, ArraySize, ShellState::autoEQP, AUTOEQP_full, AUTOEQP_on, b, bail_on_error, ShellState::bSafeMode, ShellState::bSafeModePersist, clearTempFile(), cli_strcmp(), cli_strncmp(), close_db(), cmdline_option_value(), ShellState::cMode, ShellState::colSeparator, ShellState::colWidth, ShellState::AuxDb::db, ShellState::db, do_meta_command(), ShellState::doXdgOpen, echo_group_input(), ShellState::eEscMode, eputz, ShellState::expert, expertFinish(), find_home_dir(), GETPID, globalDb, ShellState::in, integerValue(), interrupt_handler(), isatty(), main_init(), ShellState::mode, MODE_Ascii, MODE_Box, MODE_Column, MODE_Csv, MODE_Html, MODE_Json, MODE_Line, MODE_List, MODE_Markdown, MODE_Quote, MODE_Table, ShellState::nullValue, open_db(), OPEN_DB_ZIPFILE, ShellState::openFlags, ShellState::openMode, ShellState::out, output_reset(), ShellState::pAuxDb, ExpertInfo::pExpert, sqlite3_file::pMethods, printBold(), process_input(), process_sqliterc(), ShellState::rowSeparator, sayAbnormalExit(), ShellState::scanstatsOn, SEP_Comma, SEP_Record, SEP_Row, SEP_Tab, SEP_Unit, session_close_all, set_table_name(), shell_check_oom(), shell_EscModeNames, shell_exec(), SHELL_OPEN_APPENDVFS, SHELL_OPEN_DESERIALIZE, SHELL_OPEN_READONLY, SHELL_OPEN_ZIPFILE, shell_read_history, shell_stifle_history, shell_write_history, shellEmitError(), ShellState::shellFlgs, ShellSetFlag, SHFLG_Backslash, SHFLG_Echo, SHFLG_HeaderSet, SHFLG_Lookaside, SHFLG_Pagecache, SHFLG_TestingMode, ShellState::showHeader, sputz, sqlite3_appendvfs_init(), sqlite3_config(), sqlite3_db_config, sqlite3_db_filename, sqlite3_exec, sqlite3_fgets, sqlite3_file_control, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_initialize(), sqlite3_interrupt, sqlite3_libversion, sqlite3_memory_used, sqlite3_shutdown(), sqlite3_snprintf, sqlite3_sourceid, sqlite3_stricmp, sqlite3_txn_state, sqlite3_vfs_find, sqlite3_vfs_register, sqlite3MemTraceActivate(), sqlite3PcacheTraceActivate(), SQLITE_CDECL, SQLITE_CONFIG_HEAP, SQLITE_CONFIG_LOOKASIDE, SQLITE_CONFIG_MMAP_SIZE, SQLITE_CONFIG_MULTITHREAD, SQLITE_CONFIG_PAGECACHE, SQLITE_CONFIG_ROWID_IN_VIEW, SQLITE_CONFIG_SERIALIZED, SQLITE_CONFIG_SINGLETHREAD, SQLITE_CONFIG_SORTERREF_SIZE, SQLITE_DBCONFIG_RESET_DATABASE, SQLITE_FCNTL_FILE_POINTER, SQLITE_FCNTL_VFS_POINTER, SQLITE_IOERR_SHORT_READ, SQLITE_NOTFOUND, SQLITE_OPEN_NOFOLLOW, SQLITE_SOURCE_ID, ShellState::statsOn, stdin_is_interactive, stdout_is_console, strlen30(), ShellState::szMax, usage(), verify_uninitialized(), vfstrace_register(), vfstrace_unregister(), vfstraceOut(), sqlite3_io_methods::xFileSize, sqlite3_io_methods::xRead, ShellState::AuxDb::zDbFilename, ShellState::AuxDb::zFreeOnClose, and ShellState::zNonce.

Here is the call graph for this function:

◆ main_init()

void main_init ( ShellState * data)
static
33124 {
33125 memset(data, 0, sizeof(*data));
33126 data->normalMode = data->cMode = data->mode = MODE_List;
33127 data->autoExplain = 1;
33128#ifdef _WIN32
33129 data->crlfMode = 1;
33130#endif
33131 data->pAuxDb = &data->aAuxDb[0];
33132 memcpy(data->colSeparator,SEP_Column, 2);
33133 memcpy(data->rowSeparator,SEP_Row, 2);
33134 data->showHeader = 0;
33135 data->shellFlgs = SHFLG_Lookaside;
33137#if !defined(SQLITE_SHELL_FIDDLE)
33139#endif
33142 sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
static void shellLog(void *pArg, int iErrCode, const char *zMsg)
Definition shell.c:21885
#define SQLITE_CONFIG_LOG
Definition sqlite3.c:2523
#define SQLITE_CONFIG_URI
Definition sqlite3.c:2524

References ShellState::aAuxDb, ShellState::autoExplain, ShellState::cMode, ShellState::colSeparator, continuePrompt, ShellState::crlfMode, mainPrompt, ShellState::mode, MODE_List, ShellState::normalMode, ShellState::pAuxDb, ShellState::rowSeparator, SEP_Column, SEP_Row, ShellState::shellFlgs, shellLog(), SHFLG_Lookaside, ShellState::showHeader, sqlite3_config(), sqlite3_snprintf, SQLITE_CONFIG_LOG, SQLITE_CONFIG_MULTITHREAD, SQLITE_CONFIG_URI, and verify_uninitialized().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeDirectory()

int makeDirectory ( const char * zFile)
static
8302 {
8303 char *zCopy = sqlite3_mprintf("%s", zFile);
8304 int rc = SQLITE_OK;
8305
8306 if( zCopy==0 ){
8307 rc = SQLITE_NOMEM;
8308 }else{
8309 int nCopy = (int)strlen(zCopy);
8310 int i = 1;
8311
8312 while( rc==SQLITE_OK ){
8313 STRUCT_STAT sStat;
8314 int rc2;
8315
8316 for(; zCopy[i]!='/' && i<nCopy; i++);
8317 if( i==nCopy ) break;
8318 zCopy[i] = '\0';
8319
8320 rc2 = fileStat(zCopy, &sStat);
8321 if( rc2!=0 ){
8322 if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
8323 }else{
8324 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
8325 }
8326 zCopy[i] = '/';
8327 i++;
8328 }
8329
8330 sqlite3_free(zCopy);
8331 }
8332
8333 return rc;
8334}
#define STRUCT_STAT
Definition shell.c:8030

References fileStat(), sqlite3_free, sqlite3_mprintf, SQLITE_ERROR, SQLITE_NOMEM, SQLITE_OK, and STRUCT_STAT.

Referenced by writefileFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memtraceFree()

void memtraceFree ( void * p)
static
2078 {
2079 if( p==0 ) return;
2080 if( memtraceOut ){
2081 fprintf(memtraceOut, "MEMTRACE: free %d bytes\n", memtraceBase.xSize(p));
2082 }
2083 memtraceBase.xFree(p);
2084}
static FILE * memtraceOut
Definition shell.c:2068
static sqlite3_mem_methods memtraceBase
Definition shell.c:2067

References memtraceBase, and memtraceOut.

Referenced by memtraceRealloc().

Here is the caller graph for this function:

◆ memtraceInit()

int memtraceInit ( void * p)
static
2103 {
2104 return memtraceBase.xInit(p);
2105}

References memtraceBase.

◆ memtraceMalloc()

void * memtraceMalloc ( int n)
static
2071 {
2072 if( memtraceOut ){
2073 fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
2074 memtraceBase.xRoundup(n));
2075 }
2076 return memtraceBase.xMalloc(n);
2077}

References memtraceBase, and memtraceOut.

Referenced by memtraceRealloc().

Here is the caller graph for this function:

◆ memtraceRealloc()

void * memtraceRealloc ( void * p,
int n )
static
2085 {
2086 if( p==0 ) return memtraceMalloc(n);
2087 if( n==0 ){
2088 memtraceFree(p);
2089 return 0;
2090 }
2091 if( memtraceOut ){
2092 fprintf(memtraceOut, "MEMTRACE: resize %d -> %d bytes\n",
2093 memtraceBase.xSize(p), memtraceBase.xRoundup(n));
2094 }
2095 return memtraceBase.xRealloc(p, n);
2096}
static void memtraceFree(void *p)
Definition shell.c:2078
static void * memtraceMalloc(int n)
Definition shell.c:2071

References memtraceBase, memtraceFree(), memtraceMalloc(), and memtraceOut.

Here is the call graph for this function:

◆ memtraceRoundup()

int memtraceRoundup ( int n)
static
2100 {
2101 return memtraceBase.xRoundup(n);
2102}

References memtraceBase.

◆ memtraceShutdown()

void memtraceShutdown ( void * p)
static
2106 {
2107 memtraceBase.xShutdown(p);
2108}

References memtraceBase.

◆ memtraceSize()

int memtraceSize ( void * p)
static
2097 {
2098 return memtraceBase.xSize(p);
2099}

References memtraceBase.

◆ needUnistr()

int needUnistr ( const unsigned char * z)
static
24328 {
24329 unsigned char c;
24330 if( z==0 ) return 0;
24331 while( (c = *z)>0x1f || c=='\t' || c=='\n' || (c=='\r' && z[1]=='\n') ){ z++; }

References c.

Referenced by output_quoted_string(), and quoted_column().

Here is the caller graph for this function:

◆ newTempFile()

void newTempFile ( ShellState * p,
const char * zSuffix )
static
27286 {
27287 clearTempFile(p);
27289 p->zTempFile = 0;
27290 if( p->db ){
27292 }
27293 if( p->zTempFile==0 ){
27294 /* If p->db is an in-memory database then the TEMPFILENAME file-control
27295 ** will not work and we will need to fallback to guessing */
27296 char *zTemp;
27298 sqlite3_randomness(sizeof(r), &r);
27299 zTemp = getenv("TEMP");
27300 if( zTemp==0 ) zTemp = getenv("TMP");
27301 if( zTemp==0 ){
27302#ifdef _WIN32
27303 zTemp = "\\tmp";
27304#else
27305 zTemp = "/tmp";
27306#endif
27307 }
27308 p->zTempFile = sqlite3_mprintf("%s/temp%llx.%s", zTemp, r, zSuffix);
27309 }else{
27310 p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix);
27311 }

References clearTempFile(), ShellState::db, shell_check_oom(), sqlite3_file_control, sqlite3_free, sqlite3_mprintf, sqlite3_randomness, SQLITE_FCNTL_TEMPFILENAME, and ShellState::zTempFile.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ one_input_line()

char * one_input_line ( FILE * in,
char * zPrior,
int isContinuation )
static
1368 {
1369 char *zPrompt;
1370 char *zResult;
1371 if( in!=0 ){
1372 zResult = local_getline(zPrior, in);
1373 }else{
1374 zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
1375#if SHELL_USE_LOCAL_GETLINE
1376 sputz(stdout, zPrompt);
1377 fflush(stdout);
1378 do{
1379 zResult = local_getline(zPrior, stdin);
1380 zPrior = 0;
1381 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
1382 if( zResult==0 ) sqlite3_sleep(50);
1383 }while( zResult==0 && seenInterrupt>0 );
1384#else
1385 free(zPrior);
1386 zResult = shell_readline(zPrompt);
1387 while( zResult==0 ){
1388 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
1389 sqlite3_sleep(50);
1390 if( seenInterrupt==0 ) break;
1391 zResult = shell_readline("");
1392 }
1393 if( zResult && *zResult ) shell_add_history(zResult);
1394#endif
1395 }
1396 return zResult;
1397}
static char * local_getline(char *zLine, FILE *in)
Definition shell.c:1324
#define CONTINUATION_PROMPT
Definition shell.c:899

References CONTINUATION_PROMPT, local_getline(), mainPrompt, seenInterrupt, sputz, and sqlite3_sleep.

Referenced by process_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_db()

void open_db ( ShellState * p,
int openFlags )
static
25977 {
25978 if( p->db==0 ){
25979 const char *zDbFilename = p->pAuxDb->zDbFilename;
25980 if( p->openMode==SHELL_OPEN_UNSPEC ){
25981 if( zDbFilename==0 || zDbFilename[0]==0 ){
25983 }else{
25984 p->openMode = (u8)deduceDatabaseType(zDbFilename,
25985 (openFlags & OPEN_DB_ZIPFILE)!=0);
25986 }
25987 }
25988 switch( p->openMode ){
25989 case SHELL_OPEN_APPENDVFS: {
25990 sqlite3_open_v2(zDbFilename, &p->db,
25992 break;
25993 }
25994 case SHELL_OPEN_HEXDB:
25996 sqlite3_open(0, &p->db);
25997 break;
25998 }
25999 case SHELL_OPEN_ZIPFILE: {
26000 sqlite3_open(":memory:", &p->db);
26001 break;
26002 }
26003 case SHELL_OPEN_READONLY: {
26004 sqlite3_open_v2(zDbFilename, &p->db,
26006 break;
26007 }
26008 case SHELL_OPEN_UNSPEC:
26009 case SHELL_OPEN_NORMAL: {
26010 sqlite3_open_v2(zDbFilename, &p->db,
26012 break;
26013 }
26014 }
26015 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
26016 sqlite3_fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
26017 zDbFilename, sqlite3_errmsg(p->db));
26018 if( (openFlags & OPEN_DB_KEEPALIVE)==0 ){
26019 exit(1);
26020 }
26021 sqlite3_close(p->db);
26022 sqlite3_open(":memory:", &p->db);
26023 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
26024 sqlite3_fputs("Also: unable to open substitute in-memory database.\n",
26025 stderr);
26026 exit(1);
26027 }else{
26028 sqlite3_fprintf(stderr,
26029 "Notice: using substitute in-memory database instead of \"%s\"\n",
26030 zDbFilename);
26031 }
26032 }
26033 globalDb = p->db;
26035
26036 /* Reflect the use or absence of --unsafe-testing invocation. */
26037 {
26038 int testmode_on = ShellHasFlag(p,SHFLG_TestingMode);
26040 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, !testmode_on,0);
26041 }
26042
26043#ifndef SQLITE_OMIT_LOAD_EXTENSION
26045#endif
26046 sqlite3_sha_init(p->db, 0, 0);
26047 sqlite3_shathree_init(p->db, 0, 0);
26048 sqlite3_uint_init(p->db, 0, 0);
26049 sqlite3_stmtrand_init(p->db, 0, 0);
26050 sqlite3_decimal_init(p->db, 0, 0);
26051 sqlite3_percentile_init(p->db, 0, 0);
26052 sqlite3_base64_init(p->db, 0, 0);
26053 sqlite3_base85_init(p->db, 0, 0);
26054 sqlite3_regexp_init(p->db, 0, 0);
26055 sqlite3_ieee_init(p->db, 0, 0);
26056 sqlite3_series_init(p->db, 0, 0);
26057#ifndef SQLITE_SHELL_FIDDLE
26058 sqlite3_fileio_init(p->db, 0, 0);
26059 sqlite3_completion_init(p->db, 0, 0);
26060#endif
26061#ifdef SQLITE_HAVE_ZLIB
26062 if( !p->bSafeModePersist ){
26063 sqlite3_zipfile_init(p->db, 0, 0);
26064 sqlite3_sqlar_init(p->db, 0, 0);
26065 }
26066#endif
26067#ifdef SQLITE_SHELL_EXTFUNCS
26068 /* Create a preprocessing mechanism for extensions to make
26069 * their own provisions for being built into the shell.
26070 * This is a short-span macro. See further below for usage.
26071 */
26072#define SHELL_SUB_MACRO(base, variant) base ## _ ## variant
26073#define SHELL_SUBMACRO(base, variant) SHELL_SUB_MACRO(base, variant)
26074 /* Let custom-included extensions get their ..._init() called.
26075 * The WHATEVER_INIT( db, pzErrorMsg, pApi ) macro should cause
26076 * the extension's sqlite3_*_init( db, pzErrorMsg, pApi )
26077 * initialization routine to be called.
26078 */
26079 {
26080 int irc = SHELL_SUBMACRO(SQLITE_SHELL_EXTFUNCS, INIT)(p->db);
26081 /* Let custom-included extensions expose their functionality.
26082 * The WHATEVER_EXPOSE( db, pzErrorMsg ) macro should cause
26083 * the SQL functions, virtual tables, collating sequences or
26084 * VFS's implemented by the extension to be registered.
26085 */
26086 if( irc==SQLITE_OK
26088 SHELL_SUBMACRO(SQLITE_SHELL_EXTFUNCS, EXPOSE)(p->db, 0);
26089 }
26090#undef SHELL_SUB_MACRO
26091#undef SHELL_SUBMACRO
26092 }
26093#endif
26094
26095 sqlite3_create_function(p->db, "strtod", 1, SQLITE_UTF8, 0,
26096 shellStrtod, 0, 0);
26097 sqlite3_create_function(p->db, "dtostr", 1, SQLITE_UTF8, 0,
26098 shellDtostr, 0, 0);
26099 sqlite3_create_function(p->db, "dtostr", 2, SQLITE_UTF8, 0,
26100 shellDtostr, 0, 0);
26101 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
26102 shellAddSchemaName, 0, 0);
26103 sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, p,
26104 shellModuleSchema, 0, 0);
26105 sqlite3_create_function(p->db, "shell_putsnl", 1, SQLITE_UTF8, p,
26106 shellPutsFunc, 0, 0);
26107 sqlite3_create_function(p->db, "usleep",1,SQLITE_UTF8,0,
26108 shellUSleepFunc, 0, 0);
26109#ifndef SQLITE_NOHAVE_SYSTEM
26110 sqlite3_create_function(p->db, "edit", 1, SQLITE_UTF8, 0,
26111 editFunc, 0, 0);
26112 sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
26113 editFunc, 0, 0);
26114#endif
26115
26116 if( p->openMode==SHELL_OPEN_ZIPFILE ){
26117 char *zSql = sqlite3_mprintf(
26118 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
26119 shell_check_oom(zSql);
26120 sqlite3_exec(p->db, zSql, 0, 0, 0);
26121 sqlite3_free(zSql);
26122 }
26123#ifndef SQLITE_OMIT_DESERIALIZE
26124 else
26126 int rc;
26127 int nData = 0;
26128 unsigned char *aData;
26130 aData = (unsigned char*)readFile(zDbFilename, &nData);
26131 }else{
26132 aData = readHexDb(p, &nData);
26133 }
26134 if( aData==0 ){
26135 return;
26136 }
26137 rc = sqlite3_deserialize(p->db, "main", aData, nData, nData,
26140 if( rc ){
26141 sqlite3_fprintf(stderr,"Error: sqlite3_deserialize() returns %d\n", rc);
26142 }
26143 if( p->szMax>0 ){
26145 }
26146 }
26147#endif
26148 }
26149 if( p->db!=0 ){
26150 if( p->bSafeModePersist ){
26152 }
26155 );
int sqlite3_stmtrand_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:16191
int sqlite3_ieee_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:6145
int sqlite3_series_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:7030
int sqlite3_regexp_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:7905
static void shellPutsFunc(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
Definition shell.c:21898
int sqlite3_uint_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:3684
int sqlite3_fileio_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:8983
int sqlite3_shathree_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:3148
int sqlite3_percentile_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:5065
static void shellDtostr(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
Definition shell.c:1613
int deduceDatabaseType(const char *zName, int dfltZip)
Definition shell.c:25787
static void editFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:21946
int sqlite3_decimal_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:4541
int sqlite3_completion_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:9513
static unsigned char * readHexDb(ShellState *p, int *pnData)
Definition shell.c:25828
static void shellAddSchemaName(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
Definition shell.c:1646
static void shellStrtod(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
Definition shell.c:1595
static void shellModuleSchema(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
Definition shell.c:25931
static void shellUSleepFunc(sqlite3_context *context, int argcUnused, sqlite3_value **argv)
Definition shell.c:25914
int sqlite3_sha_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi)
Definition shell.c:3574
#define SQLITE_DESERIALIZE_FREEONCLOSE
Definition sqlite3.c:11372
#define SQLITE_OK_LOAD_PERMANENTLY
Definition sqlite3.c:891
int sqlite3_enable_load_extension(sqlite3 *db, int onoff)
Definition sqlite3.c:139784
#define SQLITE_DESERIALIZE_RESIZEABLE
Definition sqlite3.c:11373
#define SQLITE_OPEN_READONLY
Definition sqlite3.c:914
#define sqlite3_deserialize
Definition sqlite3ext.h:691

References ShellState::bSafeModePersist, ShellState::db, deduceDatabaseType(), editFunc(), globalDb, OPEN_DB_KEEPALIVE, OPEN_DB_ZIPFILE, ShellState::openFlags, ShellState::openMode, ShellState::pAuxDb, readFile(), readHexDb(), safeModeAuth(), ShellState::scanstatsOn, shell_check_oom(), SHELL_OPEN_APPENDVFS, SHELL_OPEN_DESERIALIZE, SHELL_OPEN_HEXDB, SHELL_OPEN_NORMAL, SHELL_OPEN_READONLY, SHELL_OPEN_UNSPEC, SHELL_OPEN_ZIPFILE, shellAddSchemaName(), shellDtostr(), ShellHasFlag, shellModuleSchema(), shellPutsFunc(), shellStrtod(), shellUSleepFunc(), SHFLG_TestingMode, sqlite3_base64_init(), sqlite3_base85_init(), sqlite3_close, sqlite3_completion_init(), sqlite3_create_function, sqlite3_db_config, sqlite3_decimal_init(), sqlite3_deserialize, sqlite3_enable_load_extension(), sqlite3_errcode, sqlite3_errmsg, sqlite3_exec, sqlite3_file_control, sqlite3_fileio_init(), sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_ieee_init(), sqlite3_mprintf, sqlite3_open, sqlite3_open_v2, sqlite3_percentile_init(), sqlite3_regexp_init(), sqlite3_series_init(), sqlite3_set_authorizer, sqlite3_sha_init(), sqlite3_shathree_init(), sqlite3_stmtrand_init(), sqlite3_uint_init(), SQLITE_DBCONFIG_DEFENSIVE, SQLITE_DBCONFIG_STMT_SCANSTATUS, SQLITE_DBCONFIG_TRUSTED_SCHEMA, SQLITE_DESERIALIZE_FREEONCLOSE, SQLITE_DESERIALIZE_RESIZEABLE, SQLITE_FCNTL_SIZE_LIMIT, SQLITE_OK, SQLITE_OK_LOAD_PERMANENTLY, SQLITE_OPEN_CREATE, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_UTF8, ShellState::szMax, and ShellState::AuxDb::zDbFilename.

Referenced by do_meta_command(), main(), and runOneSqlLine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openChrSource()

FILE * openChrSource ( const char * zFile)
static
1286 {
1287#if defined(_WIN32) || defined(WIN32)
1288 struct __stat64 x = {0};
1289# define STAT_CHR_SRC(mode) ((mode & (_S_IFCHR|_S_IFIFO|_S_IFREG))!=0)
1290 /* On Windows, open first, then check the stream nature. This order
1291 ** is necessary because _stat() and sibs, when checking a named pipe,
1292 ** effectively break the pipe as its supplier sees it. */
1293 FILE *rv = sqlite3_fopen(zFile, "rb");
1294 if( rv==0 ) return 0;
1295 if( _fstat64(_fileno(rv), &x) != 0
1296 || !STAT_CHR_SRC(x.st_mode)){
1297 fclose(rv);
1298 rv = 0;
1299 }
1300 return rv;
1301#else
1302 struct stat x = {0};
1303 int rc = stat(zFile, &x);
1304# define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode))
1305 if( rc!=0 ) return 0;
1306 if( STAT_CHR_SRC(x.st_mode) ){
1307 return sqlite3_fopen(zFile, "rb");
1308 }else{
1309 return 0;
1310 }
1311#endif
1312#undef STAT_CHR_SRC
1313}
#define STAT_CHR_SRC(mode)

References sqlite3_fopen, and STAT_CHR_SRC.

Referenced by do_meta_command().

Here is the caller graph for this function:

◆ optionMatch()

int optionMatch ( const char * zStr,
const char * zOpt )
static
27249 {
27250 if( zStr[0]!='-' ) return 0;
27251 zStr++;
27252 if( zStr[0]=='-' ) zStr++;

References cli_strcmp().

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_c_string()

void output_c_string ( FILE * out,
const char * z )
static
22282 {
22283 char c;
22284 static const char *zq = "\"";
22285 static long ctrlMask = ~0L;
22286 static const char *zDQBSRO = "\"\\\x7f"; /* double-quote, backslash, rubout */
22287 char ace[3] = "\\?";
22288 char cbsSay;
22289 sqlite3_fputs(zq, out);
22290 while( *z!=0 ){
22291 const char *pcDQBSRO = anyOfInStr(z, zDQBSRO, ~(size_t)0);
22292 const char *pcPast = zSkipValidUtf8(z, INT_MAX, ctrlMask);
22293 const char *pcEnd = (pcDQBSRO && pcDQBSRO < pcPast)? pcDQBSRO : pcPast;
22294 if( pcEnd > z ){
22295 sqlite3_fprintf(out, "%.*s", (int)(pcEnd-z), z);
22296 }
22297 if( (c = *pcEnd)==0 ) break;
22298 ++pcEnd;
22299 switch( c ){
22300 case '\\': case '"':
22301 cbsSay = (char)c;
22302 break;
22303 case '\t': cbsSay = 't'; break;
22304 case '\n': cbsSay = 'n'; break;
22305 case '\r': cbsSay = 'r'; break;
22306 case '\f': cbsSay = 'f'; break;
22307 default: cbsSay = 0; break;
22308 }
22309 if( cbsSay ){
22310 ace[1] = cbsSay;
22311 sqlite3_fputs(ace, out);
22312 }else if( !isprint(c&0xff) ){
22313 sqlite3_fprintf(out, "\\%03o", c&0xff);
22314 }else{
22315 ace[1] = (char)c;
22316 sqlite3_fputs(ace+1, out);
22317 }
22318 z = pcEnd;
22319 }
const char * zSkipValidUtf8(const char *z, int nAccept, long ccm)
Definition shell.c:22248
static const char * anyOfInStr(const char *s, const char *zAny, size_t ns)
Definition shell.c:22228

References anyOfInStr(), c, sqlite3_fprintf, sqlite3_fputs, and zSkipValidUtf8().

Referenced by do_meta_command(), shell_callback(), and shellAuth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_csv()

void output_csv ( ShellState * p,
const char * z,
int bSep )
static
22523 {
22524 if( z==0 ){
22525 sqlite3_fprintf(p->out, "%s",p->nullValue);
22526 }else{
22527 unsigned i;
22528 for(i=0; z[i]; i++){
22529 if( needCsvQuote[((unsigned char*)z)[i]] ){
22530 i = 0;
22531 break;
22532 }
22533 }
22534 if( i==0 || strstr(z, p->colSeparator)!=0 ){
22535 char *zQuoted = sqlite3_mprintf("\"%w\"", z);
22536 shell_check_oom(zQuoted);
22537 sqlite3_fputs(zQuoted, p->out);
22538 sqlite3_free(zQuoted);
22539 }else{
22540 sqlite3_fputs(z, p->out);
22541 }
22542 }
22543 if( bSep ){
static const char needCsvQuote[]
Definition shell.c:22496

References ShellState::colSeparator, needCsvQuote, ShellState::nullValue, ShellState::out, shell_check_oom(), sqlite3_fprintf, sqlite3_fputs, sqlite3_free, and sqlite3_mprintf.

Referenced by shell_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_file_close()

void output_file_close ( FILE * f)
static
26357 {

Referenced by do_meta_command(), and output_reset().

Here is the caller graph for this function:

◆ output_file_open()

FILE * output_file_open ( const char * zFile)
static
26366 {
26367 FILE *f;
26368 if( cli_strcmp(zFile,"stdout")==0 ){
26369 f = stdout;
26370 }else if( cli_strcmp(zFile, "stderr")==0 ){
26371 f = stderr;
26372 }else if( cli_strcmp(zFile, "off")==0 ){
26373 f = 0;
26374 }else{
26375 f = sqlite3_fopen(zFile, "w");
26376 if( f==0 ){
26377 sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zFile);
26378 }
26379 }

References cli_strcmp(), sqlite3_fopen, and sqlite3_fprintf.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_hex_blob()

void output_hex_blob ( FILE * out,
const void * pBlob,
int nBlob )
static
22109 {
22110 int i;
22111 unsigned char *aBlob = (unsigned char*)pBlob;
22112
22113 char *zStr = sqlite3_malloc(nBlob*2 + 1);
22114 shell_check_oom(zStr);
22115
22116 for(i=0; i<nBlob; i++){
22117 static const char aHex[] = {
22118 '0', '1', '2', '3', '4', '5', '6', '7',
22119 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
22120 };
22121 zStr[i*2] = aHex[ (aBlob[i] >> 4) ];
22122 zStr[i*2+1] = aHex[ (aBlob[i] & 0x0F) ];
22123 }
22124 zStr[i*2] = '\0';
22125
22126 sqlite3_fprintf(out, "X'%s'", zStr);

References shell_check_oom(), sqlite3_fprintf, sqlite3_free, and sqlite3_malloc.

Referenced by shell_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_html_string()

void output_html_string ( FILE * out,
const char * z )
static
22463 {
22464 int i;
22465 if( z==0 ) z = "";
22466 while( *z ){
22467 for(i=0; z[i]
22468 && z[i]!='<'
22469 && z[i]!='&'
22470 && z[i]!='>'
22471 && z[i]!='\"'
22472 && z[i]!='\'';
22473 i++){}
22474 if( i>0 ){
22475 sqlite3_fprintf(out, "%.*s",i,z);
22476 }
22477 if( z[i]=='<' ){
22478 sqlite3_fputs("&lt;", out);
22479 }else if( z[i]=='&' ){
22480 sqlite3_fputs("&amp;", out);
22481 }else if( z[i]=='>' ){
22482 sqlite3_fputs("&gt;", out);
22483 }else if( z[i]=='\"' ){
22484 sqlite3_fputs("&quot;", out);
22485 }else if( z[i]=='\'' ){
22486 sqlite3_fputs("&#39;", out);
22487 }else{
22488 break;
22489 }
22490 z += i + 1;

References sqlite3_fprintf, and sqlite3_fputs.

Referenced by shell_callback().

Here is the caller graph for this function:

◆ output_json_string()

void output_json_string ( FILE * out,
const char * z,
i64 n )
static
22326 {
22327 unsigned char c;
22328 static const char *zq = "\"";
22329 static long ctrlMask = ~0L;
22330 static const char *zDQBS = "\"\\";
22331 const char *pcLimit;
22332 char ace[3] = "\\?";
22333 char cbsSay;
22334
22335 if( z==0 ) z = "";
22336 pcLimit = z + ((n<0)? strlen(z) : (size_t)n);
22337 sqlite3_fputs(zq, out);
22338 while( z < pcLimit ){
22339 const char *pcDQBS = anyOfInStr(z, zDQBS, pcLimit-z);
22340 const char *pcPast = zSkipValidUtf8(z, (int)(pcLimit-z), ctrlMask);
22341 const char *pcEnd = (pcDQBS && pcDQBS < pcPast)? pcDQBS : pcPast;
22342 if( pcEnd > z ){
22343 sqlite3_fprintf(out, "%.*s", (int)(pcEnd-z), z);
22344 z = pcEnd;
22345 }
22346 if( z >= pcLimit ) break;
22347 c = (unsigned char)*(z++);
22348 switch( c ){
22349 case '"': case '\\':
22350 cbsSay = (char)c;
22351 break;
22352 case '\b': cbsSay = 'b'; break;
22353 case '\f': cbsSay = 'f'; break;
22354 case '\n': cbsSay = 'n'; break;
22355 case '\r': cbsSay = 'r'; break;
22356 case '\t': cbsSay = 't'; break;
22357 default: cbsSay = 0; break;
22358 }
22359 if( cbsSay ){
22360 ace[1] = cbsSay;
22361 sqlite3_fputs(ace, out);
22362 }else if( c<=0x1f || c>=0x7f ){
22363 sqlite3_fprintf(out, "\\u%04x", c);
22364 }else{
22365 ace[1] = (char)c;
22366 sqlite3_fputs(ace+1, out);
22367 }
22368 }

References anyOfInStr(), c, sqlite3_fprintf, sqlite3_fputs, and zSkipValidUtf8().

Referenced by shell_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_quoted_escaped_string()

void output_quoted_escaped_string ( ShellState * p,
const char * z )
static
22213 {
22214 char *zEscaped;
22215 sqlite3_fsetmode(p->out, _O_BINARY);
22216 if( p->eEscMode==SHELL_ESC_OFF ){
22217 zEscaped = sqlite3_mprintf("%Q", z);
22218 }else{
22219 zEscaped = sqlite3_mprintf("%#Q", z);
22220 }
22221 sqlite3_fputs(zEscaped, p->out);
22222 sqlite3_free(zEscaped);
#define sqlite3_fsetmode(F, X)
Definition shell.c:307

References ShellState::eEscMode, ShellState::out, setCrlfMode(), SHELL_ESC_OFF, sqlite3_fputs, sqlite3_free, sqlite3_fsetmode, and sqlite3_mprintf.

Referenced by shell_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_quoted_string()

void output_quoted_string ( ShellState * p,
const char * zInX )
static
22144 {
22145 int i;
22146 int needUnistr = 0;
22147 int needDblQuote = 0;
22148 const unsigned char *z = (const unsigned char*)zInX;
22149 unsigned char c;
22150 FILE *out = p->out;
22151 sqlite3_fsetmode(out, _O_BINARY);
22152 if( z==0 ) return;
22153 for(i=0; (c = z[i])!=0; i++){
22154 if( c=='\'' ){ needDblQuote = 1; }
22155 if( c>0x1f ) continue;
22156 if( c=='\t' || c=='\n' ) continue;
22157 if( c=='\r' && z[i+1]=='\n' ) continue;
22158 needUnistr = 1;
22159 break;
22160 }
22161 if( (needDblQuote==0 && needUnistr==0)
22162 || (needDblQuote==0 && p->eEscMode==SHELL_ESC_OFF)
22163 ){
22164 sqlite3_fprintf(out, "'%s'",z);
22165 }else if( p->eEscMode==SHELL_ESC_OFF ){
22166 char *zEncoded = sqlite3_mprintf("%Q", z);
22167 sqlite3_fputs(zEncoded, out);
22168 sqlite3_free(zEncoded);
22169 }else{
22170 if( needUnistr ){
22171 sqlite3_fputs("unistr('", out);
22172 }else{
22173 sqlite3_fputs("'", out);
22174 }
22175 while( *z ){
22176 for(i=0; (c = z[i])!=0; i++){
22177 if( c=='\'' ) break;
22178 if( c>0x1f ) continue;
22179 if( c=='\t' || c=='\n' ) continue;
22180 if( c=='\r' && z[i+1]=='\n' ) continue;
22181 break;
22182 }
22183 if( i ){
22184 sqlite3_fprintf(out, "%.*s", i, z);
22185 z += i;
22186 }
22187 if( c==0 ) break;
22188 if( c=='\'' ){
22189 sqlite3_fputs("''", out);
22190 }else{
22191 sqlite3_fprintf(out, "\\u%04x", c);
22192 }
22193 z++;
22194 }
22195 if( needUnistr ){
22196 sqlite3_fputs("')", out);
22197 }else{
22198 sqlite3_fputs("'", out);
22199 }
22200 }
static int needUnistr(const unsigned char *z)
Definition shell.c:24326

References c, ShellState::eEscMode, needUnistr(), ShellState::out, setCrlfMode(), SHELL_ESC_OFF, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_fsetmode, and sqlite3_mprintf.

Referenced by shell_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_redir()

void output_redir ( ShellState * p,
FILE * pfNew )
static
26843 {
26844 if( p->out != stdout ){
26845 sqlite3_fputs("Output already redirected.\n", stderr);
26846 }else{
26847 p->out = pfNew;
26848 setCrlfMode(p);
26849 if( p->mode==MODE_Www ){
26851 "<!DOCTYPE html>\n"
26852 "<HTML><BODY><PRE>\n",
26853 p->out
26854 );
26855 }
static void setCrlfMode(ShellState *p)
Definition shell.c:22092

References ShellState::mode, MODE_Www, ShellState::out, setCrlfMode(), and sqlite3_fputs.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_reset()

void output_reset ( ShellState * p)
static
26866 {
26867 if( p->outfile[0]=='|' ){
26868#ifndef SQLITE_OMIT_POPEN
26869 pclose(p->out);
26870#endif
26871 }else{
26872 if( p->mode==MODE_Www ){
26873 sqlite3_fputs("</PRE></BODY></HTML>\n", p->out);
26874 }
26876#ifndef SQLITE_NOHAVE_SYSTEM
26877 if( p->doXdgOpen ){
26878 const char *zXdgOpenCmd =
26879#if defined(_WIN32)
26880 "start";
26881#elif defined(__APPLE__)
26882 "open";
26883#else
26884 "xdg-open";
26885#endif
26886 char *zCmd;
26887 zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
26888 if( system(zCmd) ){
26889 sqlite3_fprintf(stderr,"Failed: [%s]\n", zCmd);
26890 }else{
26891 /* Give the start/open/xdg-open command some time to get
26892 ** going before we continue, and potential delete the
26893 ** p->zTempFile data file out from under it */
26894 sqlite3_sleep(2000);
26895 }
26896 sqlite3_free(zCmd);
26897 outputModePop(p);
26898 p->doXdgOpen = 0;
26899 }
26900#endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
26901 }
26902 p->outfile[0] = 0;
26903 p->out = stdout;
static void outputModePop(ShellState *p)
Definition shell.c:22082

References ShellState::doXdgOpen, ShellState::mode, MODE_Www, ShellState::out, ShellState::outfile, output_file_close(), outputModePop(), pclose(), setCrlfMode(), sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_mprintf, sqlite3_sleep, and ShellState::zTempFile.

Referenced by do_meta_command(), main(), and process_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ outputDumpWarning()

int outputDumpWarning ( ShellState * p,
const char * zLike )
static
28738 : Script requires that SQLITE_DBCONFIG_DEFENSIVE be disabled
28739*/
28740static int outputDumpWarning(ShellState *p, const char *zLike){
28741 int rc = SQLITE_OK;
28742 sqlite3_stmt *pStmt = 0;
28743 shellPreparePrintf(p->db, &rc, &pStmt,
28744 "SELECT 1 FROM sqlite_schema o WHERE "
28745 "sql LIKE 'CREATE VIRTUAL TABLE%%' AND %s", zLike ? zLike : "true"
28746 );
28747 if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
28748 sqlite3_fputs("/* WARNING: "
28749 "Script requires that SQLITE_DBCONFIG_DEFENSIVE be disabled */\n",
28750 p->out
28751 );
28752 }
28753 shellFinalize(&rc, pStmt);
static void shellPreparePrintf(sqlite3 *db, int *pRc, sqlite3_stmt **ppStmt, const char *zFmt,...)
Definition shell.c:27583

References ShellState::db, ShellState::out, shellFinalize(), shellPreparePrintf(), sqlite3_fputs, sqlite3_step, SQLITE_OK, and SQLITE_ROW.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ outputModePop()

void outputModePop ( ShellState * p)
static
22084 {
22085 p->mode = p->modePrior;
22086 p->shellFlgs = p->priorShFlgs;
22087 memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
int modePrior
Definition shell.c:21698
unsigned priorShFlgs
Definition shell.c:21708
char colSepPrior[20]
Definition shell.c:21715

Referenced by output_reset().

Here is the caller graph for this function:

◆ outputModePush()

void outputModePush ( ShellState * p)
static
22078 {
22079 p->modePrior = p->mode;
22080 p->priorShFlgs = p->shellFlgs;
22081 memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator));

References ShellState::colSeparator, ShellState::colSepPrior, ShellState::mode, ShellState::modePrior, ShellState::priorShFlgs, and ShellState::shellFlgs.

Referenced by do_meta_command().

Here is the caller graph for this function:

◆ pcachetraceCachesize()

void pcachetraceCachesize ( sqlite3_pcache * p,
int nCachesize )
static
2212 {
2213 if( pcachetraceOut ){
2214 fprintf(pcachetraceOut, "PCACHETRACE: xCachesize(%p, %d)\n", p, nCachesize);
2215 }
2216 pcacheBase.xCachesize(p, nCachesize);
2217}
static sqlite3_pcache_methods2 pcacheBase
Definition shell.c:2178
static FILE * pcachetraceOut
Definition shell.c:2179

References pcacheBase, and pcachetraceOut.

◆ pcachetraceCreate()

sqlite3_pcache * pcachetraceCreate ( int szPage,
int szExtra,
int bPurge )
static
2199 {
2200 sqlite3_pcache *pRes;
2201 if( pcachetraceOut ){
2202 fprintf(pcachetraceOut, "PCACHETRACE: xCreate(%d,%d,%d)\n",
2203 szPage, szExtra, bPurge);
2204 }
2205 pRes = pcacheBase.xCreate(szPage, szExtra, bPurge);
2206 if( pcachetraceOut ){
2207 fprintf(pcachetraceOut, "PCACHETRACE: xCreate(%d,%d,%d) -> %p\n",
2208 szPage, szExtra, bPurge, pRes);
2209 }
2210 return pRes;
2211}
struct sqlite3_pcache sqlite3_pcache
Definition sqlite3.c:9448

References pcacheBase, and pcachetraceOut.

◆ pcachetraceDestroy()

void pcachetraceDestroy ( sqlite3_pcache * p)
static
2274 {
2275 if( pcachetraceOut ){
2276 fprintf(pcachetraceOut, "PCACHETRACE: xDestroy(%p)\n", p);
2277 }
2278 pcacheBase.xDestroy(p);
2279}

References pcacheBase, and pcachetraceOut.

◆ pcachetraceFetch()

sqlite3_pcache_page * pcachetraceFetch ( sqlite3_pcache * p,
unsigned key,
int crFg )
static
2233 {
2234 sqlite3_pcache_page *pRes;
2235 if( pcachetraceOut ){
2236 fprintf(pcachetraceOut, "PCACHETRACE: xFetch(%p,%u,%d)\n", p, key, crFg);
2237 }
2238 pRes = pcacheBase.xFetch(p, key, crFg);
2239 if( pcachetraceOut ){
2240 fprintf(pcachetraceOut, "PCACHETRACE: xFetch(%p,%u,%d) -> %p\n",
2241 p, key, crFg, pRes);
2242 }
2243 return pRes;
2244}
Definition sqlite3.c:9461

References pcacheBase, and pcachetraceOut.

◆ pcachetraceInit()

int pcachetraceInit ( void * pArg)
static
2182 {
2183 int nRes;
2184 if( pcachetraceOut ){
2185 fprintf(pcachetraceOut, "PCACHETRACE: xInit(%p)\n", pArg);
2186 }
2187 nRes = pcacheBase.xInit(pArg);
2188 if( pcachetraceOut ){
2189 fprintf(pcachetraceOut, "PCACHETRACE: xInit(%p) -> %d\n", pArg, nRes);
2190 }
2191 return nRes;
2192}

References pcacheBase, and pcachetraceOut.

◆ pcachetracePagecount()

int pcachetracePagecount ( sqlite3_pcache * p)
static
2218 {
2219 int nRes;
2220 if( pcachetraceOut ){
2221 fprintf(pcachetraceOut, "PCACHETRACE: xPagecount(%p)\n", p);
2222 }
2223 nRes = pcacheBase.xPagecount(p);
2224 if( pcachetraceOut ){
2225 fprintf(pcachetraceOut, "PCACHETRACE: xPagecount(%p) -> %d\n", p, nRes);
2226 }
2227 return nRes;
2228}

References pcacheBase, and pcachetraceOut.

◆ pcachetraceRekey()

void pcachetraceRekey ( sqlite3_pcache * p,
sqlite3_pcache_page * pPg,
unsigned oldKey,
unsigned newKey )
static
2261 {
2262 if( pcachetraceOut ){
2263 fprintf(pcachetraceOut, "PCACHETRACE: xRekey(%p, %p, %u, %u)\n",
2264 p, pPg, oldKey, newKey);
2265 }
2266 pcacheBase.xRekey(p, pPg, oldKey, newKey);
2267}

References pcacheBase, and pcachetraceOut.

◆ pcachetraceShrink()

void pcachetraceShrink ( sqlite3_pcache * p)
static
2280 {
2281 if( pcachetraceOut ){
2282 fprintf(pcachetraceOut, "PCACHETRACE: xShrink(%p)\n", p);
2283 }
2284 pcacheBase.xShrink(p);
2285}

References pcacheBase, and pcachetraceOut.

◆ pcachetraceShutdown()

void pcachetraceShutdown ( void * pArg)
static
2193 {
2194 if( pcachetraceOut ){
2195 fprintf(pcachetraceOut, "PCACHETRACE: xShutdown(%p)\n", pArg);
2196 }
2197 pcacheBase.xShutdown(pArg);
2198}

References pcacheBase, and pcachetraceOut.

◆ pcachetraceTruncate()

void pcachetraceTruncate ( sqlite3_pcache * p,
unsigned n )
static
2268 {
2269 if( pcachetraceOut ){
2270 fprintf(pcachetraceOut, "PCACHETRACE: xTruncate(%p, %u)\n", p, n);
2271 }
2272 pcacheBase.xTruncate(p, n);
2273}

References pcacheBase, and pcachetraceOut.

◆ pcachetraceUnpin()

void pcachetraceUnpin ( sqlite3_pcache * p,
sqlite3_pcache_page * pPg,
int bDiscard )
static
2249 {
2250 if( pcachetraceOut ){
2251 fprintf(pcachetraceOut, "PCACHETRACE: xUnpin(%p, %p, %d)\n",
2252 p, pPg, bDiscard);
2253 }
2254 pcacheBase.xUnpin(p, pPg, bDiscard);
2255}

References pcacheBase, and pcachetraceOut.

◆ pclose()

int pclose ( FILE * )
extern

Referenced by do_meta_command(), and output_reset().

Here is the caller graph for this function:

◆ percentBinarySearch()

int percentBinarySearch ( Percentile * p,
double y,
int bExact )
static
4772 {
4773 int iFirst = 0; /* First element of search range */
4774 int iLast = p->nUsed - 1; /* Last element of search range */
4775 while( iLast>=iFirst ){
4776 int iMid = (iFirst+iLast)/2;
4777 double x = p->a[iMid];
4778 if( x<y ){
4779 iFirst = iMid + 1;
4780 }else if( x>y ){
4781 iLast = iMid - 1;
4782 }else{
4783 return iMid;
4784 }
4785 }
4786 if( bExact ) return -1;
4787 return iFirst;
4788}
unsigned nUsed
Definition shell.c:4720
double * a
Definition shell.c:4725

References Percentile::a, and Percentile::nUsed.

Referenced by percentInverse(), and percentStep().

Here is the caller graph for this function:

◆ percentCompute()

void percentCompute ( sqlite3_context * pCtx,
int bIsFinal )
static
5021 {
5022 Percentile *p;
5024 unsigned i1, i2;
5025 double v1, v2;
5026 double ix, vx;
5028 if( p==0 ) return;
5029 if( p->a==0 ) return;
5030 if( p->nUsed ){
5031 if( p->bSorted==0 ){
5032 assert( p->nUsed>1 );
5033 percentSort(p->a, p->nUsed);
5034 p->bSorted = 1;
5035 }
5036 ix = p->rPct*(p->nUsed-1);
5037 i1 = (unsigned)ix;
5038 if( pFunc->bDiscrete ){
5039 vx = p->a[i1];
5040 }else{
5041 i2 = ix==(double)i1 || i1==p->nUsed-1 ? i1 : i1+1;
5042 v1 = p->a[i1];
5043 v2 = p->a[i2];
5044 vx = v1 + (v2-v1)*(ix-i1);
5045 }
5046 sqlite3_result_double(pCtx, vx);
5047 }
5048 if( bIsFinal ){
5049 sqlite3_free(p->a);
5050 memset(p, 0, sizeof(*p));
5051 }else{
5052 p->bKeepSorted = 1;
5053 }
5054}
double rPct
Definition shell.c:4724
static void percentSort(double *a, unsigned int n)
Definition shell.c:4923
char bSorted
Definition shell.c:4721
char bDiscrete
Definition shell.c:4734
char bKeepSorted
Definition shell.c:4722
Definition shell.c:4718
Definition shell.c:4730

References Percentile::a, PercentileFunc::bDiscrete, Percentile::bKeepSorted, Percentile::bSorted, Percentile::nUsed, percentSort(), Percentile::rPct, sqlite3_aggregate_context, sqlite3_free, sqlite3_result_double, and sqlite3_user_data.

Referenced by percentFinal(), and percentValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ percentError()

void percentError ( sqlite3_context * pCtx,
const char * zFormat,
... )
static
4797 {
4799 char *zMsg1;
4800 char *zMsg2;
4801 va_list ap;
4802
4803 va_start(ap, zFormat);
4804 zMsg1 = sqlite3_vmprintf(zFormat, ap);
4805 va_end(ap);
4806 zMsg2 = zMsg1 ? sqlite3_mprintf(zMsg1, pFunc->zName) : 0;
4807 sqlite3_result_error(pCtx, zMsg2, -1);
4808 sqlite3_free(zMsg1);
4809 sqlite3_free(zMsg2);
4810}
const char * zName
Definition shell.c:4731

References sqlite3_free, sqlite3_mprintf, sqlite3_result_error, sqlite3_user_data, sqlite3_vmprintf, and PercentileFunc::zName.

Referenced by percentStep().

Here is the caller graph for this function:

◆ percentFinal()

void percentFinal ( sqlite3_context * pCtx)
static
5055 {
5056 percentCompute(pCtx, 1);
5057}
static void percentCompute(sqlite3_context *pCtx, int bIsFinal)
Definition shell.c:5021

References percentCompute().

Referenced by sqlite3_percentile_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ percentInverse()

void percentInverse ( sqlite3_context * pCtx,
int argc,
sqlite3_value ** argv )
static
4974 {
4975 Percentile *p;
4976 int eType;
4977 double y;
4978 int i;
4979 assert( argc==2 || argc==1 );
4980
4981 /* Allocate the session context. */
4982 p = (Percentile*)sqlite3_aggregate_context(pCtx, sizeof(*p));
4983 assert( p!=0 );
4984
4985 /* Ignore rows for which Y is NULL */
4986 eType = sqlite3_value_type(argv[0]);
4987 if( eType==SQLITE_NULL ) return;
4988
4989 /* If not NULL, then Y must be numeric. Otherwise throw an error.
4990 ** Requirement 4 */
4991 if( eType!=SQLITE_INTEGER && eType!=SQLITE_FLOAT ){
4992 return;
4993 }
4994
4995 /* Ignore the Y value if it is infinity or NaN */
4996 y = sqlite3_value_double(argv[0]);
4997 if( percentIsInfinity(y) ){
4998 return;
4999 }
5000 if( p->bSorted==0 ){
5001 assert( p->nUsed>1 );
5002 percentSort(p->a, p->nUsed);
5003 p->bSorted = 1;
5004 }
5005 p->bKeepSorted = 1;
5006
5007 /* Find and remove the row */
5008 i = percentBinarySearch(p, y, 1);
5009 if( i>=0 ){
5010 p->nUsed--;
5011 if( i<(int)p->nUsed ){
5012 memmove(&p->a[i], &p->a[i+1], (p->nUsed - i)*sizeof(p->a[0]));
5013 }
5014 }
5015}
static int percentIsInfinity(double r)
Definition shell.c:4746
static int percentBinarySearch(Percentile *p, double y, int bExact)
Definition shell.c:4772

References Percentile::a, Percentile::bKeepSorted, Percentile::bSorted, Percentile::nUsed, percentBinarySearch(), percentIsInfinity(), percentSort(), sqlite3_aggregate_context, sqlite3_value_double, sqlite3_value_type, SQLITE_FLOAT, SQLITE_INTEGER, and SQLITE_NULL.

Referenced by sqlite3_percentile_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ percentIsInfinity()

int percentIsInfinity ( double r)
static
4746 {
4748 assert( sizeof(u)==sizeof(r) );
4749 memcpy(&u, &r, sizeof(u));
4750 return ((u>>52)&0x7ff)==0x7ff;
4751}

Referenced by percentInverse(), and percentStep().

Here is the caller graph for this function:

◆ percentSameValue()

int percentSameValue ( double a,
double b )
static
4756 {
4757 a -= b;
4758 return a>=-0.001 && a<=0.001;
4759}

References a, and b.

Referenced by percentStep().

Here is the caller graph for this function:

◆ percentSort()

void percentSort ( double * a,
unsigned int n )
static
4923 {
4924 int iLt; /* Entries before a[iLt] are less than rPivot */
4925 int iGt; /* Entries at or after a[iGt] are greater than rPivot */
4926 int i; /* Loop counter */
4927 double rPivot; /* The pivot value */
4928
4929 assert( n>=2 );
4930 if( a[0]>a[n-1] ){
4931 SWAP_DOUBLE(a[0],a[n-1])
4932 }
4933 if( n==2 ) return;
4934 iGt = n-1;
4935 i = n/2;
4936 if( a[0]>a[i] ){
4937 SWAP_DOUBLE(a[0],a[i])
4938 }else if( a[i]>a[iGt] ){
4939 SWAP_DOUBLE(a[i],a[iGt])
4940 }
4941 if( n==3 ) return;
4942 rPivot = a[i];
4943 iLt = i = 1;
4944 do{
4945 if( a[i]<rPivot ){
4946 if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt])
4947 iLt++;
4948 i++;
4949 }else if( a[i]>rPivot ){
4950 do{
4951 iGt--;
4952 }while( iGt>i && a[iGt]>rPivot );
4953 SWAP_DOUBLE(a[i],a[iGt])
4954 }else{
4955 i++;
4956 }
4957 }while( i<iGt );
4958 if( iLt>=2 ) percentSort(a, iLt);
4959 if( n-iGt>=2 ) percentSort(a+iGt, n-iGt);
4960
4961/* Uncomment for testing */
4962#if 0
4963 for(i=0; i<n-1; i++){
4964 assert( a[i]<=a[i+1] );
4965 }
4966#endif
4967}
#define SWAP_DOUBLE(X, Y)
Definition shell.c:4909

References a, percentSort(), and SWAP_DOUBLE.

Referenced by percentCompute(), percentInverse(), and percentSort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ percentStep()

void percentStep ( sqlite3_context * pCtx,
int argc,
sqlite3_value ** argv )
static
4816 {
4817 Percentile *p;
4818 double rPct;
4819 int eType;
4820 double y;
4821 assert( argc==2 || argc==1 );
4822
4823 if( argc==1 ){
4824 /* Requirement 13: median(Y) is the same as percentile(Y,50). */
4825 rPct = 0.5;
4826 }else{
4827 /* Requirement 3: P must be a number between 0 and 100 */
4829 eType = sqlite3_value_numeric_type(argv[1]);
4830 rPct = sqlite3_value_double(argv[1])/(double)pFunc->mxFrac;
4831 if( (eType!=SQLITE_INTEGER && eType!=SQLITE_FLOAT)
4832 || rPct<0.0 || rPct>1.0
4833 ){
4834 percentError(pCtx, "the fraction argument to %%s()"
4835 " is not between 0.0 and %.1f",
4836 (double)pFunc->mxFrac);
4837 return;
4838 }
4839 }
4840
4841 /* Allocate the session context. */
4842 p = (Percentile*)sqlite3_aggregate_context(pCtx, sizeof(*p));
4843 if( p==0 ) return;
4844
4845 /* Remember the P value. Throw an error if the P value is different
4846 ** from any prior row, per Requirement (2). */
4847 if( !p->bPctValid ){
4848 p->rPct = rPct;
4849 p->bPctValid = 1;
4850 }else if( !percentSameValue(p->rPct,rPct) ){
4851 percentError(pCtx, "the fraction argument to %%s()"
4852 " is not the same for all input rows");
4853 return;
4854 }
4855
4856 /* Ignore rows for which Y is NULL */
4857 eType = sqlite3_value_type(argv[0]);
4858 if( eType==SQLITE_NULL ) return;
4859
4860 /* If not NULL, then Y must be numeric. Otherwise throw an error.
4861 ** Requirement 4 */
4862 if( eType!=SQLITE_INTEGER && eType!=SQLITE_FLOAT ){
4863 percentError(pCtx, "input to %%s() is not numeric");
4864 return;
4865 }
4866
4867 /* Throw an error if the Y value is infinity or NaN */
4868 y = sqlite3_value_double(argv[0]);
4869 if( percentIsInfinity(y) ){
4870 percentError(pCtx, "Inf input to %%s()");
4871 return;
4872 }
4873
4874 /* Allocate and store the Y */
4875 if( p->nUsed>=p->nAlloc ){
4876 unsigned n = p->nAlloc*2 + 250;
4877 double *a = sqlite3_realloc64(p->a, sizeof(double)*n);
4878 if( a==0 ){
4879 sqlite3_free(p->a);
4880 memset(p, 0, sizeof(*p));
4882 return;
4883 }
4884 p->nAlloc = n;
4885 p->a = a;
4886 }
4887 if( p->nUsed==0 ){
4888 p->a[p->nUsed++] = y;
4889 p->bSorted = 1;
4890 }else if( !p->bSorted || y>=p->a[p->nUsed-1] ){
4891 p->a[p->nUsed++] = y;
4892 }else if( p->bKeepSorted ){
4893 int i;
4894 i = percentBinarySearch(p, y, 0);
4895 if( i<(int)p->nUsed ){
4896 memmove(&p->a[i+1], &p->a[i], (p->nUsed-i)*sizeof(p->a[0]));
4897 }
4898 p->a[i] = y;
4899 p->nUsed++;
4900 }else{
4901 p->a[p->nUsed++] = y;
4902 p->bSorted = 0;
4903 }
4904}
char mxFrac
Definition shell.c:4733
unsigned nAlloc
Definition shell.c:4719
static int percentSameValue(double a, double b)
Definition shell.c:4756
static void percentError(sqlite3_context *pCtx, const char *zFormat,...)
Definition shell.c:4797
char bPctValid
Definition shell.c:4723
#define sqlite3_value_numeric_type
Definition sqlite3ext.h:514

References a, Percentile::a, Percentile::bKeepSorted, Percentile::bPctValid, Percentile::bSorted, PercentileFunc::mxFrac, Percentile::nAlloc, Percentile::nUsed, percentBinarySearch(), percentError(), percentIsInfinity(), percentSameValue(), Percentile::rPct, sqlite3_aggregate_context, sqlite3_free, sqlite3_realloc64, sqlite3_result_error_nomem, sqlite3_user_data, sqlite3_value_double, sqlite3_value_numeric_type, sqlite3_value_type, SQLITE_FLOAT, SQLITE_INTEGER, and SQLITE_NULL.

Referenced by sqlite3_percentile_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ percentValue()

void percentValue ( sqlite3_context * pCtx)
static
5058 {
5059 percentCompute(pCtx, 0);
5060}

References percentCompute().

Referenced by sqlite3_percentile_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ popen()

FILE * popen ( const char * ,
const char *  )
extern

◆ print_box_line()

void print_box_line ( FILE * out,
int N )
static
24142 {
24143 const char zDash[] =
24146 const int nDash = sizeof(zDash) - 1;
24147 N *= 3;
24148 while( N>nDash ){
24149 sqlite3_fputs(zDash, out);
24150 N -= nDash;
24151 }
#define BOX_24
Definition shell.c:24125

References BOX_24, sqlite3_fprintf, and sqlite3_fputs.

Referenced by print_box_row_separator().

Here is the caller graph for this function:

◆ print_box_row_separator()

void print_box_row_separator ( ShellState * p,
int nArg,
const char * zSep1,
const char * zSep2,
const char * zSep3 )
static
24164 {
24165 int i;
24166 if( nArg>0 ){
24167 sqlite3_fputs(zSep1, p->out);
24168 print_box_line(p->out, p->actualWidth[0]+2);
24169 for(i=1; i<nArg; i++){
24170 sqlite3_fputs(zSep2, p->out);
24171 print_box_line(p->out, p->actualWidth[i]+2);
24172 }
24173 sqlite3_fputs(zSep3, p->out);
24174 }
static void print_box_line(FILE *out, int N)
Definition shell.c:24140

References ShellState::actualWidth, ShellState::out, print_box_line(), and sqlite3_fputs.

Referenced by exec_prepared_stmt_columnar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_dashes()

void print_dashes ( FILE * out,
int N )
static
22842 {
22843 const char zDash[] = "--------------------------------------------------";
22844 const int nDash = sizeof(zDash) - 1;
22845 while( N>nDash ){
22846 sqlite3_fputs(zDash, out);
22847 N -= nDash;
22848 }

References sqlite3_fprintf, and sqlite3_fputs.

Referenced by exec_prepared_stmt_columnar(), print_row_separator(), and shell_callback().

Here is the caller graph for this function:

◆ print_row_separator()

void print_row_separator ( ShellState * p,
int nArg,
const char * zSep )
static
22859 {
22860 int i;
22861 if( nArg>0 ){
22862 sqlite3_fputs(zSep, p->out);
22863 print_dashes(p->out, p->actualWidth[0]+2);
22864 for(i=1; i<nArg; i++){
22865 sqlite3_fputs(zSep, p->out);
22866 print_dashes(p->out, p->actualWidth[i]+2);
22867 }
22868 sqlite3_fputs(zSep, p->out);
22869 }

References ShellState::actualWidth, ShellState::out, print_dashes(), and sqlite3_fputs.

Referenced by exec_prepared_stmt_columnar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printBold()

void printBold ( const char * zText)
static
33165 {

Referenced by main().

Here is the caller graph for this function:

◆ printSchemaLine()

void printSchemaLine ( FILE * out,
const char * z,
const char * zTail )
static
22675 ://sqlite.org/forum/forumpost/d7be961c5c
22676*/
22677static void printSchemaLine(FILE *out, const char *z, const char *zTail){
22678 char *zToFree = 0;
22679 if( z==0 ) return;
22680 if( zTail==0 ) return;
22681 if( zTail[0]==';' && (strstr(z, "/*")!=0 || strstr(z,"--")!=0) ){
22682 const char *zOrig = z;
22683 static const char *azTerm[] = { "", "*/", "\n" };
22684 int i;
22685 for(i=0; i<ArraySize(azTerm); i++){
22686 char *zNew = sqlite3_mprintf("%s%s;", zOrig, azTerm[i]);
22687 shell_check_oom(zNew);
22688 if( sqlite3_complete(zNew) ){
22689 size_t n = strlen(zNew);
22690 zNew[n-1] = 0;
22691 zToFree = zNew;
22692 z = zNew;
22693 break;
22694 }
22695 sqlite3_free(zNew);
22696 }
22697 }
22698 if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){
22699 sqlite3_fprintf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail);
22700 }else{
22701 sqlite3_fprintf(out, "%s%s", z, zTail);
22702 }

References ArraySize, shell_check_oom(), sqlite3_complete, sqlite3_fprintf, sqlite3_free, sqlite3_mprintf, and sqlite3_strglob.

Referenced by dump_callback(), and shell_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printSchemaLineN()

void printSchemaLineN ( FILE * out,
char * z,
int n,
const char * zTail )
static
22705 {
22706 char c = z[n];
22707 z[n] = 0;
22708 printSchemaLine(out, z, zTail);

Referenced by shell_callback().

Here is the caller graph for this function:

◆ process_input()

int process_input ( ShellState * p)
static
32770 {
32771 char *zLine = 0; /* A single input line */
32772 char *zSql = 0; /* Accumulated SQL text */
32773 i64 nLine; /* Length of current line */
32774 i64 nSql = 0; /* Bytes of zSql[] used */
32775 i64 nAlloc = 0; /* Allocated zSql[] space */
32776 int rc; /* Error code */
32777 int errCnt = 0; /* Number of errors seen */
32778 i64 startline = 0; /* Line number for start of current input */
32779 QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */
32780
32782 /* This will be more informative in a later version. */
32783 sqlite3_fprintf(stderr,"Input nesting limit (%d) reached at line %d."
32784 " Check recursion.\n", MAX_INPUT_NESTING, p->lineno);
32785 return 1;
32786 }
32787 ++p->inputNesting;
32788 p->lineno = 0;
32790 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
32791 fflush(p->out);
32792 zLine = one_input_line(p->in, zLine, nSql>0);
32793 if( zLine==0 ){
32794 /* End of input */
32795 if( p->in==0 && stdin_is_interactive ) sqlite3_fputs("\n", p->out);
32796 break;
32797 }
32798 if( seenInterrupt ){
32799 if( p->in!=0 ) break;
32800 seenInterrupt = 0;
32801 }
32802 p->lineno++;
32803 if( QSS_INPLAIN(qss)
32805 && line_is_complete(zSql, nSql) ){
32806 memcpy(zLine,";",2);
32807 }
32808 qss = quickscan(zLine, qss, CONTINUE_PROMPT_PSTATE);
32809 if( QSS_PLAINWHITE(qss) && nSql==0 ){
32810 /* Just swallow single-line whitespace */
32811 echo_group_input(p, zLine);
32812 qss = QSS_Start;
32813 continue;
32814 }
32815 if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
32817 echo_group_input(p, zLine);
32818 if( zLine[0]=='.' ){
32819 rc = do_meta_command(zLine, p);
32820 if( rc==2 ){ /* exit requested */
32821 break;
32822 }else if( rc ){
32823 errCnt++;
32824 }
32825 }
32826 qss = QSS_Start;
32827 continue;
32828 }
32829 /* No single-line dispositions remain; accumulate line(s). */
32830 nLine = strlen(zLine);
32831 if( nSql+nLine+2>=nAlloc ){
32832 /* Grow buffer by half-again increments when big. */
32833 nAlloc = nSql+(nSql>>1)+nLine+100;
32834 zSql = realloc(zSql, nAlloc);
32835 shell_check_oom(zSql);
32836 }
32837 if( nSql==0 ){
32838 i64 i;
32839 for(i=0; zLine[i] && IsSpace(zLine[i]); i++){}
32840 assert( nAlloc>0 && zSql!=0 );
32841 memcpy(zSql, zLine+i, nLine+1-i);
32842 startline = p->lineno;
32843 nSql = nLine-i;
32844 }else{
32845 zSql[nSql++] = '\n';
32846 memcpy(zSql+nSql, zLine, nLine+1);
32847 nSql += nLine;
32848 }
32849 if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){
32850 echo_group_input(p, zSql);
32851 errCnt += runOneSqlLine(p, zSql, p->in, startline);
32853 nSql = 0;
32854 if( p->outCount ){
32855 output_reset(p);
32856 p->outCount = 0;
32857 }else{
32858 clearTempFile(p);
32859 }
32861 qss = QSS_Start;
32862 }else if( nSql && QSS_PLAINWHITE(qss) ){
32863 echo_group_input(p, zSql);
32864 nSql = 0;
32865 qss = QSS_Start;
32866 }
32867 }
32868 if( nSql ){
32869 /* This may be incomplete. Let the SQL parser deal with that. */
32870 echo_group_input(p, zSql);
32871 errCnt += runOneSqlLine(p, zSql, p->in, startline);
32873 }
32874 free(zSql);
32875 free(zLine);
32876 --p->inputNesting;
#define MAX_INPUT_NESTING
Definition shell.c:21880
static int line_is_complete(char *zSql, int nSql)
Definition shell.c:32572
#define QSS_INPLAIN(qss)
Definition shell.c:32455
#define QSS_SEMITERM(qss)
Definition shell.c:32458
#define QSS_PLAINWHITE(qss)
Definition shell.c:32456
static QuickScanState quickscan(char *zLine, QuickScanState qss, t_DynaPromptRef pst)
Definition shell.c:32465
#define CONTINUE_PROMPT_PSTATE
Definition shell.c:908
int inputNesting
Definition shell.c:21688
QuickScanState
Definition shell.c:32449
static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline)
Definition shell.c:32670
#define CONTINUE_PROMPT_RESET
Definition shell.c:900
static char * one_input_line(FILE *in, char *zPrior, int isContinuation)
Definition shell.c:1368
static int line_is_command_terminator(char *zLine)
Definition shell.c:32549

References bail_on_error, ShellState::bSafeMode, ShellState::bSafeModePersist, clearTempFile(), CONTINUE_PROMPT_PSTATE, CONTINUE_PROMPT_RESET, do_meta_command(), echo_group_input(), ShellState::in, ShellState::inputNesting, IsSpace, line_is_command_terminator(), line_is_complete(), ShellState::lineno, MAX_INPUT_NESTING, one_input_line(), ShellState::out, ShellState::outCount, output_reset(), QSS_INPLAIN, QSS_PLAINWHITE, QSS_SEMITERM, QSS_Start, quickscan(), runOneSqlLine(), seenInterrupt, shell_check_oom(), sqlite3_complete, sqlite3_fprintf, sqlite3_fputs, and stdin_is_interactive.

Referenced by do_meta_command(), main(), and process_sqliterc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_sqliterc()

void process_sqliterc ( ShellState * p,
const char * sqliterc_override )
static
32994 {
32995 char *home_dir = NULL;
32996 const char *sqliterc = sqliterc_override;
32997 char *zBuf = 0;
32998 FILE *inSaved = p->in;
32999 int savedLineno = p->lineno;
33000
33001 if( sqliterc == NULL ){
33002 sqliterc = zBuf = find_xdg_config();
33003 }
33004 if( sqliterc == NULL ){
33005 home_dir = find_home_dir(0);
33006 if( home_dir==0 ){
33007 eputz("-- warning: cannot find home directory;"
33008 " cannot read ~/.sqliterc\n");
33009 return;
33010 }
33011 zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
33012 shell_check_oom(zBuf);
33013 sqliterc = zBuf;
33014 }
33015 p->in = sqlite3_fopen(sqliterc,"rb");
33016 if( p->in ){
33018 sqlite3_fprintf(stderr,"-- Loading resources from %s\n", sqliterc);
33019 }
33020 if( process_input(p) && bail_on_error ) exit(1);
33021 fclose(p->in);
33022 }else if( sqliterc_override!=0 ){
33023 sqlite3_fprintf(stderr,"cannot open: \"%s\"\n", sqliterc);
33024 if( bail_on_error ) exit(1);
33025 }
33026 p->in = inSaved;
33027 p->lineno = savedLineno;
static char * find_xdg_config(void)
Definition shell.c:32957

References bail_on_error, eputz, find_home_dir(), find_xdg_config(), ShellState::in, ShellState::lineno, process_input(), shell_check_oom(), sqlite3_fopen, sqlite3_fprintf, sqlite3_free, sqlite3_mprintf, and stdin_is_interactive.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ progress_handler()

int progress_handler ( void * pClientData)
static
22823 {
22824 ShellState *p = (ShellState*)pClientData;
22825 p->nProgress++;
22826 if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){
22827 sqlite3_fprintf(p->out, "Progress limit reached (%u)\n", p->nProgress);
22828 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
22829 if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0;
22830 return 1;
22831 }
22832 if( (p->flgProgress & SHELL_PROGRESS_QUIET)==0 ){
22833 sqlite3_fprintf(p->out, "Progress %u\n", p->nProgress);
22834 }

References ShellState::flgProgress, ShellState::mxProgress, ShellState::nProgress, ShellState::out, SHELL_PROGRESS_ONCE, SHELL_PROGRESS_QUIET, SHELL_PROGRESS_RESET, and sqlite3_fprintf.

Referenced by do_meta_command().

Here is the caller graph for this function:

◆ progressSequence()

int progressSequence ( SequenceSpec * pss)
static
6403 {
6404 if( !pss->isNotEOF ) return 0;
6405 if( pss->isReversing ){
6406 if( pss->uSeqIndexNow > 0 ){
6407 pss->uSeqIndexNow--;
6408 pss->iValueNow -= pss->iStep;
6409 }else{
6410 pss->isNotEOF = 0;
6411 }
6412 }else{
6413 if( pss->uSeqIndexNow < pss->uSeqIndexMax ){
6414 pss->uSeqIndexNow++;
6415 pss->iValueNow += pss->iStep;
6416 }else{
6417 pss->isNotEOF = 0;
6418 }
6419 }
6420 return pss->isNotEOF;
6421}
u8 isReversing
Definition shell.c:6341
sqlite3_int64 iValueNow
Definition shell.c:6339
sqlite3_uint64 uSeqIndexNow
Definition shell.c:6338
sqlite3_int64 iStep
Definition shell.c:6336
sqlite3_uint64 uSeqIndexMax
Definition shell.c:6337
u8 isNotEOF
Definition shell.c:6340

References SequenceSpec::isNotEOF, SequenceSpec::isReversing, SequenceSpec::iStep, SequenceSpec::iValueNow, SequenceSpec::uSeqIndexMax, and SequenceSpec::uSeqIndexNow.

Referenced by seriesNext().

Here is the caller graph for this function:

◆ putcs()

char * putcs ( char * pc,
char * s )
static
5554 {
5555 char c;
5556 while( (c = *s++)!=0 ) *pc++ = c;
5557 return pc;
5558}

References c.

Referenced by toBase85().

Here is the caller graph for this function:

◆ quickscan()

QuickScanState quickscan ( char * zLine,
QuickScanState qss,
t_DynaPromptRef pst )
static
32468 {
32469 char cin;
32470 char cWait = (char)qss; /* intentional narrowing loss */
32471 if( cWait==0 ){
32472 PlainScan:
32473 while( (cin = *zLine++)!=0 ){
32474 if( IsSpace(cin) )
32475 continue;
32476 switch (cin){
32477 case '-':
32478 if( *zLine!='-' )
32479 break;
32480 while((cin = *++zLine)!=0 )
32481 if( cin=='\n')
32482 goto PlainScan;
32483 return qss;
32484 case ';':
32485 qss |= QSS_EndingSemi;
32486 continue;
32487 case '/':
32488 if( *zLine=='*' ){
32489 ++zLine;
32490 cWait = '*';
32491 CONTINUE_PROMPT_AWAITS(pst, "/*");
32492 qss = QSS_SETV(qss, cWait);
32493 goto TermScan;
32494 }
32495 break;
32496 case '[':
32497 cin = ']';
32498 deliberate_fall_through; /* FALLTHRU */
32499 case '`': case '\'': case '"':
32500 cWait = cin;
32501 qss = QSS_HasDark | cWait;
32502 CONTINUE_PROMPT_AWAITC(pst, cin);
32503 goto TermScan;
32504 case '(':
32505 CONTINUE_PAREN_INCR(pst, 1);
32506 break;
32507 case ')':
32508 CONTINUE_PAREN_INCR(pst, -1);
32509 break;
32510 default:
32511 break;
32512 }
32513 qss = (qss & ~QSS_EndingSemi) | QSS_HasDark;
32514 }
32515 }else{
32516 TermScan:
32517 while( (cin = *zLine++)!=0 ){
32518 if( cin==cWait ){
32519 switch( cWait ){
32520 case '*':
32521 if( *zLine != '/' )
32522 continue;
32523 ++zLine;
32524 CONTINUE_PROMPT_AWAITC(pst, 0);
32525 qss = QSS_SETV(qss, 0);
32526 goto PlainScan;
32527 case '`': case '\'': case '"':
32528 if(*zLine==cWait){
32529 /* Swallow doubled end-delimiter.*/
32530 ++zLine;
32531 continue;
32532 }
32533 deliberate_fall_through; /* FALLTHRU */
32534 case ']':
32535 CONTINUE_PROMPT_AWAITC(pst, 0);
32536 qss = QSS_SETV(qss, 0);
32537 goto PlainScan;
32538 default: assert(0);
32539 }
32540 }
32541 }
32542 }
#define CONTINUE_PAREN_INCR(p, n)
Definition shell.c:906
#define CONTINUE_PROMPT_AWAITS(p, s)
Definition shell.c:902
#define CONTINUE_PROMPT_AWAITC(p, c)
Definition shell.c:904
#define QSS_SETV(qss, newst)
Definition shell.c:32454

References CONTINUE_PAREN_INCR, CONTINUE_PROMPT_AWAITC, CONTINUE_PROMPT_AWAITS, deliberate_fall_through, IsSpace, QSS_EndingSemi, QSS_HasDark, QSS_SETV, and SCAN_TRACKER_REFTYPE.

Referenced by line_is_command_terminator(), and process_input().

Here is the caller graph for this function:

◆ quoteChar()

char quoteChar ( const char * zName)
static
1530 {
1531 int i;
1532 if( zName==0 ) return '"';
1533 if( !IsAlpha(zName[0]) && zName[0]!='_' ) return '"';
1534 for(i=0; zName[i]; i++){
1535 if( !IsAlnum(zName[i]) && zName[i]!='_' ) return '"';
1536 }
1537 return sqlite3_keyword_check(zName, i) ? '"' : 0;
1538}
#define IsAlpha(X)
Definition shell.c:240

References IsAlnum, IsAlpha, and sqlite3_keyword_check.

Referenced by do_meta_command(), dump_callback(), set_table_name(), shell_callback(), shellAddSchemaName(), and shellFakeSchema().

Here is the caller graph for this function:

◆ quoted_column()

char * quoted_column ( sqlite3_stmt * pStmt,
int i )
static
24339 {
24340 switch( sqlite3_column_type(pStmt, i) ){
24341 case SQLITE_NULL: {
24342 return sqlite3_mprintf("NULL");
24343 }
24344 case SQLITE_INTEGER:
24345 case SQLITE_FLOAT: {
24346 return sqlite3_mprintf("%s",sqlite3_column_text(pStmt,i));
24347 }
24348 case SQLITE_TEXT: {
24349 const unsigned char *zText = sqlite3_column_text(pStmt,i);
24350 return sqlite3_mprintf(needUnistr(zText)?"%#Q":"%Q",zText);
24351 }
24352 case SQLITE_BLOB: {
24353 int j;
24354 sqlite3_str *pStr = sqlite3_str_new(0);
24355 const unsigned char *a = sqlite3_column_blob(pStmt,i);
24356 int n = sqlite3_column_bytes(pStmt,i);
24357 sqlite3_str_append(pStr, "x'", 2);
24358 for(j=0; j<n; j++){
24359 sqlite3_str_appendf(pStr, "%02x", a[j]);
24360 }
24361 sqlite3_str_append(pStr, "'", 1);
24362 return sqlite3_str_finish(pStr);
24363 }
24364 }
Definition sqlite3.c:20564
#define sqlite3_str_appendf
Definition sqlite3ext.h:647
#define sqlite3_str_new
Definition sqlite3ext.h:645
#define sqlite3_str_append
Definition sqlite3ext.h:649
#define sqlite3_str_finish
Definition sqlite3ext.h:646
#define sqlite3_column_blob
Definition sqlite3ext.h:416

References a, needUnistr(), sqlite3_column_blob, sqlite3_column_bytes, sqlite3_column_text, sqlite3_column_type, sqlite3_mprintf, sqlite3_str_append, sqlite3_str_appendf, sqlite3_str_finish, sqlite3_str_new, SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, and SQLITE_TEXT.

Referenced by exec_prepared_stmt_columnar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rc_err_oom_die()

void rc_err_oom_die ( int rc)
static
28531 :%d\n",rc), assert(0)
28532#else
28533static void rc_err_oom_die(int rc){
28534 if( rc==SQLITE_NOMEM ) shell_check_oom(0);

References shell_check_oom(), SQLITE_DONE, SQLITE_NOMEM, and SQLITE_OK.

Referenced by zAutoColumn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ re_add_state()

void re_add_state ( ReStateSet * pSet,
int newState )
static
7213 {
7214 unsigned i;
7215 for(i=0; i<pSet->nState; i++) if( pSet->aState[i]==newState ) return;
7216 pSet->aState[pSet->nState++] = (ReStateNumber)newState;
7217}
unsigned short ReStateNumber
Definition shell.c:7175
unsigned nState
Definition shell.c:7183
ReStateNumber * aState
Definition shell.c:7184

References ReStateSet::aState, and ReStateSet::nState.

Referenced by sqlite3re_match().

Here is the caller graph for this function:

◆ re_append()

int re_append ( ReCompiled * p,
int op,
int arg )
static
7455 {
7456 return re_insert(p, p->nState, op, arg);
7457}
static int re_insert(ReCompiled *p, int iBefore, int op, int arg)
Definition shell.c:7440
unsigned nState
Definition shell.c:7208

References ReCompiled::nState, and re_insert().

Referenced by re_subcompile_re(), re_subcompile_string(), and sqlite3re_compile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ re_copy()

void re_copy ( ReCompiled * p,
int iStart,
int N )
static
7462 {
7463 if( p->nState+N>=p->nAlloc && re_resize(p, p->nAlloc*2+N) ) return;
7464 memcpy(&p->aOp[p->nState], &p->aOp[iStart], N*sizeof(p->aOp[0]));
7465 memcpy(&p->aArg[p->nState], &p->aArg[iStart], N*sizeof(p->aArg[0]));
7466 p->nState += N;
7467}
unsigned nAlloc
Definition shell.c:7209
static int re_resize(ReCompiled *p, int N)
Definition shell.c:7424
char * aOp
Definition shell.c:7203
int * aArg
Definition shell.c:7204

References ReCompiled::aArg, ReCompiled::aOp, ReCompiled::nAlloc, ReCompiled::nState, and re_resize().

Referenced by re_subcompile_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ re_digit_char()

int re_digit_char ( int c)
static
7262 {
7263 return (c>='0' && c<='9');
7264}

References c.

Referenced by sqlite3re_match().

Here is the caller graph for this function:

◆ re_esc_char()

unsigned re_esc_char ( ReCompiled * p)
static
7490 {
7491 static const char zEsc[] = "afnrtv\\()*.+?[$^{|}]";
7492 static const char zTrans[] = "\a\f\n\r\t\v";
7493 int i, v = 0;
7494 char c;
7495 if( p->sIn.i>=p->sIn.mx ) return 0;
7496 c = p->sIn.z[p->sIn.i];
7497 if( c=='u' && p->sIn.i+4<p->sIn.mx ){
7498 const unsigned char *zIn = p->sIn.z + p->sIn.i;
7499 if( re_hex(zIn[1],&v)
7500 && re_hex(zIn[2],&v)
7501 && re_hex(zIn[3],&v)
7502 && re_hex(zIn[4],&v)
7503 ){
7504 p->sIn.i += 5;
7505 return v;
7506 }
7507 }
7508 if( c=='x' && p->sIn.i+2<p->sIn.mx ){
7509 const unsigned char *zIn = p->sIn.z + p->sIn.i;
7510 if( re_hex(zIn[1],&v)
7511 && re_hex(zIn[2],&v)
7512 ){
7513 p->sIn.i += 3;
7514 return v;
7515 }
7516 }
7517 for(i=0; zEsc[i] && zEsc[i]!=c; i++){}
7518 if( zEsc[i] ){
7519 if( i<6 ) c = zTrans[i];
7520 p->sIn.i++;
7521 }else{
7522 p->zErr = "unknown \\ escape";
7523 }
7524 return c;
7525}
static int re_hex(int c, int *pV)
Definition shell.c:7473
const unsigned char * z
Definition shell.c:7191
int i
Definition shell.c:7192
ReInput sIn
Definition shell.c:7201
const char * zErr
Definition shell.c:7202
int mx
Definition shell.c:7193

References c, ReInput::i, ReInput::mx, re_hex(), ReCompiled::sIn, ReInput::z, and ReCompiled::zErr.

Referenced by re_subcompile_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ re_hex()

int re_hex ( int c,
int * pV )
static
7473 {
7474 if( c>='0' && c<='9' ){
7475 c -= '0';
7476 }else if( c>='a' && c<='f' ){
7477 c -= 'a' - 10;
7478 }else if( c>='A' && c<='F' ){
7479 c -= 'A' - 10;
7480 }else{
7481 return 0;
7482 }
7483 *pV = (*pV)*16 + (c & 0xff);
7484 return 1;
7485}

References c.

Referenced by re_esc_char().

Here is the caller graph for this function:

◆ re_insert()

int re_insert ( ReCompiled * p,
int iBefore,
int op,
int arg )
static
7440 {
7441 int i;
7442 if( p->nAlloc<=p->nState && re_resize(p, p->nAlloc*2) ) return 0;
7443 for(i=p->nState; i>iBefore; i--){
7444 p->aOp[i] = p->aOp[i-1];
7445 p->aArg[i] = p->aArg[i-1];
7446 }
7447 p->nState++;
7448 p->aOp[iBefore] = (char)op;
7449 p->aArg[iBefore] = arg;
7450 return iBefore;
7451}

References ReCompiled::aArg, ReCompiled::aOp, ReCompiled::nAlloc, ReCompiled::nState, and re_resize().

Referenced by re_append(), re_subcompile_re(), and re_subcompile_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ re_next_char()

unsigned re_next_char ( ReInput * p)
static
7224 {
7225 unsigned c;
7226 if( p->i>=p->mx ) return 0;
7227 c = p->z[p->i++];
7228 if( c>=0x80 ){
7229 if( (c&0xe0)==0xc0 && p->i<p->mx && (p->z[p->i]&0xc0)==0x80 ){
7230 c = (c&0x1f)<<6 | (p->z[p->i++]&0x3f);
7231 if( c<0x80 ) c = 0xfffd;
7232 }else if( (c&0xf0)==0xe0 && p->i+1<p->mx && (p->z[p->i]&0xc0)==0x80
7233 && (p->z[p->i+1]&0xc0)==0x80 ){
7234 c = (c&0x0f)<<12 | ((p->z[p->i]&0x3f)<<6) | (p->z[p->i+1]&0x3f);
7235 p->i += 2;
7236 if( c<=0x7ff || (c>=0xd800 && c<=0xdfff) ) c = 0xfffd;
7237 }else if( (c&0xf8)==0xf0 && p->i+2<p->mx && (p->z[p->i]&0xc0)==0x80
7238 && (p->z[p->i+1]&0xc0)==0x80 && (p->z[p->i+2]&0xc0)==0x80 ){
7239 c = (c&0x07)<<18 | ((p->z[p->i]&0x3f)<<12) | ((p->z[p->i+1]&0x3f)<<6)
7240 | (p->z[p->i+2]&0x3f);
7241 p->i += 3;
7242 if( c<=0xffff || c>0x10ffff ) c = 0xfffd;
7243 }else{
7244 c = 0xfffd;
7245 }
7246 }
7247 return c;
7248}

References c, ReInput::i, ReInput::mx, and ReInput::z.

Referenced by re_next_char_nocase(), and sqlite3re_compile().

Here is the caller graph for this function:

◆ re_next_char_nocase()

unsigned re_next_char_nocase ( ReInput * p)
static
7249 {
7250 unsigned c = re_next_char(p);
7251 if( c>='A' && c<='Z' ) c += 'a' - 'A';
7252 return c;
7253}
static unsigned re_next_char(ReInput *p)
Definition shell.c:7224

References c, and re_next_char().

Referenced by sqlite3re_compile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ re_resize()

int re_resize ( ReCompiled * p,
int N )
static
7424 {
7425 char *aOp;
7426 int *aArg;
7427 aOp = sqlite3_realloc64(p->aOp, N*sizeof(p->aOp[0]));
7428 if( aOp==0 ) return 1;
7429 p->aOp = aOp;
7430 aArg = sqlite3_realloc64(p->aArg, N*sizeof(p->aArg[0]));
7431 if( aArg==0 ) return 1;
7432 p->aArg = aArg;
7433 p->nAlloc = N;
7434 return 0;
7435}

References ReCompiled::aArg, ReCompiled::aOp, ReCompiled::nAlloc, and sqlite3_realloc64.

Referenced by re_copy(), re_insert(), and sqlite3re_compile().

Here is the caller graph for this function:

◆ re_space_char()

int re_space_char ( int c)
static
7267 {
7268 return c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='\v' || c=='\f';
7269}

References c.

Referenced by sqlite3re_match().

Here is the caller graph for this function:

◆ re_sql_func()

void re_sql_func ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
7803 {
7804 ReCompiled *pRe; /* Compiled regular expression */
7805 const char *zPattern; /* The regular expression */
7806 const unsigned char *zStr;/* String being searched */
7807 const char *zErr; /* Compile error message */
7808 int setAux = 0; /* True to invoke sqlite3_set_auxdata() */
7809
7810 (void)argc; /* Unused */
7811 pRe = sqlite3_get_auxdata(context, 0);
7812 if( pRe==0 ){
7813 zPattern = (const char*)sqlite3_value_text(argv[0]);
7814 if( zPattern==0 ) return;
7815 zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
7816 if( zErr ){
7817 re_free(pRe);
7818 sqlite3_result_error(context, zErr, -1);
7819 return;
7820 }
7821 if( pRe==0 ){
7823 return;
7824 }
7825 setAux = 1;
7826 }
7827 zStr = (const unsigned char*)sqlite3_value_text(argv[1]);
7828 if( zStr!=0 ){
7829 sqlite3_result_int(context, re_match(pRe, zStr, -1));
7830 }
7831 if( setAux ){
7832 sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
7833 }
7834}
#define re_match
Definition shell.c:7118
#define re_compile
Definition shell.c:7119
#define re_free
Definition shell.c:7120
Definition shell.c:7200
#define sqlite3_get_auxdata
Definition sqlite3ext.h:461
#define sqlite3_set_auxdata
Definition sqlite3ext.h:496

References re_compile, re_free, re_match, sqlite3_get_auxdata, sqlite3_result_error, sqlite3_result_error_nomem, sqlite3_result_int, sqlite3_set_auxdata, sqlite3_user_data, and sqlite3_value_text.

Referenced by sqlite3_regexp_init().

Here is the caller graph for this function:

◆ re_subcompile_re()

const char * re_subcompile_re ( ReCompiled * p)
static
7539 {
7540 const char *zErr;
7541 int iStart, iEnd, iGoto;
7542 iStart = p->nState;
7543 zErr = re_subcompile_string(p);
7544 if( zErr ) return zErr;
7545 while( rePeek(p)=='|' ){
7546 iEnd = p->nState;
7547 re_insert(p, iStart, RE_OP_FORK, iEnd + 2 - iStart);
7548 iGoto = re_append(p, RE_OP_GOTO, 0);
7549 p->sIn.i++;
7550 zErr = re_subcompile_string(p);
7551 if( zErr ) return zErr;
7552 p->aArg[iGoto] = p->nState - iGoto;
7553 }
7554 return 0;
7555}
#define RE_OP_FORK
Definition shell.c:7132
static int re_append(ReCompiled *p, int op, int arg)
Definition shell.c:7455
static const char * re_subcompile_string(ReCompiled *)
Definition shell.c:7561
#define RE_OP_GOTO
Definition shell.c:7133
static unsigned char rePeek(ReCompiled *p)
Definition shell.c:7531

References ReCompiled::aArg, ReInput::i, ReCompiled::nState, re_append(), re_insert(), RE_OP_FORK, RE_OP_GOTO, re_subcompile_string(), rePeek(), and ReCompiled::sIn.

Referenced by re_subcompile_string(), and sqlite3re_compile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ re_subcompile_string()

const char * re_subcompile_string ( ReCompiled * p)
static
7561 {
7562 int iPrev = -1;
7563 int iStart;
7564 unsigned c;
7565 const char *zErr;
7566 while( (c = p->xNextChar(&p->sIn))!=0 ){
7567 iStart = p->nState;
7568 switch( c ){
7569 case '|':
7570 case ')': {
7571 p->sIn.i--;
7572 return 0;
7573 }
7574 case '(': {
7575 zErr = re_subcompile_re(p);
7576 if( zErr ) return zErr;
7577 if( rePeek(p)!=')' ) return "unmatched '('";
7578 p->sIn.i++;
7579 break;
7580 }
7581 case '.': {
7582 if( rePeek(p)=='*' ){
7583 re_append(p, RE_OP_ANYSTAR, 0);
7584 p->sIn.i++;
7585 }else{
7586 re_append(p, RE_OP_ANY, 0);
7587 }
7588 break;
7589 }
7590 case '*': {
7591 if( iPrev<0 ) return "'*' without operand";
7592 re_insert(p, iPrev, RE_OP_GOTO, p->nState - iPrev + 1);
7593 re_append(p, RE_OP_FORK, iPrev - p->nState + 1);
7594 break;
7595 }
7596 case '+': {
7597 if( iPrev<0 ) return "'+' without operand";
7598 re_append(p, RE_OP_FORK, iPrev - p->nState);
7599 break;
7600 }
7601 case '?': {
7602 if( iPrev<0 ) return "'?' without operand";
7603 re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
7604 break;
7605 }
7606 case '$': {
7608 break;
7609 }
7610 case '^': {
7611 re_append(p, RE_OP_ATSTART, 0);
7612 break;
7613 }
7614 case '{': {
7615 int m = 0, n = 0;
7616 int sz, j;
7617 if( iPrev<0 ) return "'{m,n}' without operand";
7618 while( (c=rePeek(p))>='0' && c<='9' ){ m = m*10 + c - '0'; p->sIn.i++; }
7619 n = m;
7620 if( c==',' ){
7621 p->sIn.i++;
7622 n = 0;
7623 while( (c=rePeek(p))>='0' && c<='9' ){ n = n*10 + c-'0'; p->sIn.i++; }
7624 }
7625 if( c!='}' ) return "unmatched '{'";
7626 if( n>0 && n<m ) return "n less than m in '{m,n}'";
7627 p->sIn.i++;
7628 sz = p->nState - iPrev;
7629 if( m==0 ){
7630 if( n==0 ) return "both m and n are zero in '{m,n}'";
7631 re_insert(p, iPrev, RE_OP_FORK, sz+1);
7632 iPrev++;
7633 n--;
7634 }else{
7635 for(j=1; j<m; j++) re_copy(p, iPrev, sz);
7636 }
7637 for(j=m; j<n; j++){
7638 re_append(p, RE_OP_FORK, sz+1);
7639 re_copy(p, iPrev, sz);
7640 }
7641 if( n==0 && m>0 ){
7642 re_append(p, RE_OP_FORK, -sz);
7643 }
7644 break;
7645 }
7646 case '[': {
7647 unsigned int iFirst = p->nState;
7648 if( rePeek(p)=='^' ){
7649 re_append(p, RE_OP_CC_EXC, 0);
7650 p->sIn.i++;
7651 }else{
7652 re_append(p, RE_OP_CC_INC, 0);
7653 }
7654 while( (c = p->xNextChar(&p->sIn))!=0 ){
7655 if( c=='[' && rePeek(p)==':' ){
7656 return "POSIX character classes not supported";
7657 }
7658 if( c=='\\' ) c = re_esc_char(p);
7659 if( rePeek(p)=='-' ){
7661 p->sIn.i++;
7662 c = p->xNextChar(&p->sIn);
7663 if( c=='\\' ) c = re_esc_char(p);
7665 }else{
7667 }
7668 if( rePeek(p)==']' ){ p->sIn.i++; break; }
7669 }
7670 if( c==0 ) return "unclosed '['";
7671 if( p->nState>iFirst ) p->aArg[iFirst] = p->nState - iFirst;
7672 break;
7673 }
7674 case '\\': {
7675 int specialOp = 0;
7676 switch( rePeek(p) ){
7677 case 'b': specialOp = RE_OP_BOUNDARY; break;
7678 case 'd': specialOp = RE_OP_DIGIT; break;
7679 case 'D': specialOp = RE_OP_NOTDIGIT; break;
7680 case 's': specialOp = RE_OP_SPACE; break;
7681 case 'S': specialOp = RE_OP_NOTSPACE; break;
7682 case 'w': specialOp = RE_OP_WORD; break;
7683 case 'W': specialOp = RE_OP_NOTWORD; break;
7684 }
7685 if( specialOp ){
7686 p->sIn.i++;
7687 re_append(p, specialOp, 0);
7688 }else{
7689 c = re_esc_char(p);
7690 re_append(p, RE_OP_MATCH, c);
7691 }
7692 break;
7693 }
7694 default: {
7695 re_append(p, RE_OP_MATCH, c);
7696 break;
7697 }
7698 }
7699 iPrev = iStart;
7700 }
7701 return 0;
7702}
static unsigned re_esc_char(ReCompiled *p)
Definition shell.c:7490
#define RE_OP_CC_VALUE
Definition shell.c:7137
#define RE_OP_SPACE
Definition shell.c:7143
#define RE_OP_DIGIT
Definition shell.c:7141
#define RE_OP_ATSTART
Definition shell.c:7146
#define RE_EOF
Definition shell.c:7123
#define RE_OP_ANY
Definition shell.c:7130
static void re_copy(ReCompiled *p, int iStart, int N)
Definition shell.c:7462
#define RE_OP_BOUNDARY
Definition shell.c:7145
#define RE_OP_WORD
Definition shell.c:7139
#define RE_OP_CC_RANGE
Definition shell.c:7138
#define RE_OP_MATCH
Definition shell.c:7129
#define RE_OP_CC_INC
Definition shell.c:7135
#define RE_OP_NOTSPACE
Definition shell.c:7144
unsigned(* xNextChar)(ReInput *)
Definition shell.c:7205
#define RE_OP_CC_EXC
Definition shell.c:7136
#define RE_OP_NOTWORD
Definition shell.c:7140
#define RE_OP_ANYSTAR
Definition shell.c:7131
static const char * re_subcompile_re(ReCompiled *p)
Definition shell.c:7539
#define RE_OP_NOTDIGIT
Definition shell.c:7142

References ReCompiled::aArg, c, ReInput::i, ReCompiled::nState, re_append(), re_copy(), RE_EOF, re_esc_char(), re_insert(), RE_OP_ANY, RE_OP_ANYSTAR, RE_OP_ATSTART, RE_OP_BOUNDARY, RE_OP_CC_EXC, RE_OP_CC_INC, RE_OP_CC_RANGE, RE_OP_CC_VALUE, RE_OP_DIGIT, RE_OP_FORK, RE_OP_GOTO, RE_OP_MATCH, RE_OP_NOTDIGIT, RE_OP_NOTSPACE, RE_OP_NOTWORD, RE_OP_SPACE, RE_OP_WORD, re_subcompile_re(), rePeek(), ReCompiled::sIn, and ReCompiled::xNextChar.

Referenced by re_subcompile_re().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ re_word_char()

int re_word_char ( int c)
static
7256 {
7257 return (c>='0' && c<='9') || (c>='a' && c<='z')
7258 || (c>='A' && c<='Z') || c=='_';
7259}

References c.

Referenced by sqlite3re_match().

Here is the caller graph for this function:

◆ readFile()

char * readFile ( const char * zName,
int * pnByte )
static
25699 {
25700 FILE *in = sqlite3_fopen(zName, "rb");
25701 long nIn;
25702 size_t nRead;
25703 char *pBuf;
25704 int rc;
25705 if( in==0 ) return 0;
25706 rc = fseek(in, 0, SEEK_END);
25707 if( rc!=0 ){
25708 sqlite3_fprintf(stderr,"Error: '%s' not seekable\n", zName);
25709 fclose(in);
25710 return 0;
25711 }
25712 nIn = ftell(in);
25713 rewind(in);
25714 pBuf = sqlite3_malloc64( nIn+1 );
25715 if( pBuf==0 ){
25716 sqlite3_fputs("Error: out of memory\n", stderr);
25717 fclose(in);
25718 return 0;
25719 }
25720 nRead = fread(pBuf, nIn, 1, in);
25721 fclose(in);
25722 if( nRead!=1 ){
25723 sqlite3_free(pBuf);
25724 sqlite3_fprintf(stderr,"Error: cannot read '%s'\n", zName);
25725 return 0;
25726 }
25727 pBuf[nIn] = 0;
25728 if( pnByte ) *pnByte = nIn;

References sqlite3_fopen, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, and sqlite3_malloc64.

Referenced by do_meta_command(), and open_db().

Here is the caller graph for this function:

◆ readFileContents()

void readFileContents ( sqlite3_context * ctx,
const char * zName )
static
8110 {
8111 FILE *in;
8112 sqlite3_int64 nIn;
8113 void *pBuf;
8114 sqlite3 *db;
8115 int mxBlob;
8116
8117 in = sqlite3_fopen(zName, "rb");
8118 if( in==0 ){
8119 /* File does not exist or is unreadable. Leave the result set to NULL. */
8120 return;
8121 }
8122 fseek(in, 0, SEEK_END);
8123 nIn = ftell(in);
8124 rewind(in);
8125 db = sqlite3_context_db_handle(ctx);
8126 mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
8127 if( nIn>mxBlob ){
8129 fclose(in);
8130 return;
8131 }
8132 pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
8133 if( pBuf==0 ){
8135 fclose(in);
8136 return;
8137 }
8138 if( nIn==(sqlite3_int64)fread(pBuf, 1, (size_t)nIn, in) ){
8139 sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
8140 }else{
8142 sqlite3_free(pBuf);
8143 }
8144 fclose(in);
8145}
#define SQLITE_TOOBIG
Definition sqlite3.c:784
#define sqlite3_result_error_code
Definition sqlite3ext.h:552

References sqlite3_context_db_handle, sqlite3_fopen, sqlite3_free, sqlite3_limit, sqlite3_malloc64, sqlite3_result_blob64, sqlite3_result_error_code, sqlite3_result_error_nomem, SQLITE_IOERR, SQLITE_LIMIT_LENGTH, and SQLITE_TOOBIG.

Referenced by fsdirColumn(), and readfileFunc().

Here is the caller graph for this function:

◆ readfileFunc()

void readfileFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
8156 {
8157 const char *zName;
8158 (void)(argc); /* Unused parameter */
8159 zName = (const char*)sqlite3_value_text(argv[0]);
8160 if( zName==0 ) return;
8161 readFileContents(context, zName);
8162}

References readFileContents(), and sqlite3_value_text.

Referenced by sqlite3_fileio_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readHexDb()

unsigned char * readHexDb ( ShellState * p,
int * pnData )
static
25830 {
25831 unsigned char *a = 0;
25832 int nLine;
25833 int n = 0;
25834 int pgsz = 0;
25835 int iOffset = 0;
25836 int j, k;
25837 int rc;
25838 FILE *in;
25839 const char *zDbFilename = p->pAuxDb->zDbFilename;
25840 unsigned int x[16];
25841 char zLine[1000];
25842 if( zDbFilename ){
25843 in = sqlite3_fopen(zDbFilename, "r");
25844 if( in==0 ){
25845 sqlite3_fprintf(stderr,"cannot open \"%s\" for reading\n", zDbFilename);
25846 return 0;
25847 }
25848 nLine = 0;
25849 }else{
25850 in = p->in;
25851 nLine = p->lineno;
25852 if( in==0 ) in = stdin;
25853 }
25854 *pnData = 0;
25855 nLine++;
25856 if( sqlite3_fgets(zLine, sizeof(zLine), in)==0 ) goto readHexDb_error;
25857 rc = sscanf(zLine, "| size %d pagesize %d", &n, &pgsz);
25858 if( rc!=2 ) goto readHexDb_error;
25859 if( n<0 ) goto readHexDb_error;
25860 if( pgsz<512 || pgsz>65536 || (pgsz&(pgsz-1))!=0 ) goto readHexDb_error;
25861 n = (n+pgsz-1)&~(pgsz-1); /* Round n up to the next multiple of pgsz */
25862 a = sqlite3_malloc( n ? n : 1 );
25864 memset(a, 0, n);
25865 if( pgsz<512 || pgsz>65536 || (pgsz & (pgsz-1))!=0 ){
25866 sqlite3_fputs("invalid pagesize\n", stderr);
25867 goto readHexDb_error;
25868 }
25869 for(nLine++; sqlite3_fgets(zLine, sizeof(zLine), in)!=0; nLine++){
25870 rc = sscanf(zLine, "| page %d offset %d", &j, &k);
25871 if( rc==2 ){
25872 iOffset = k;
25873 continue;
25874 }
25875 if( cli_strncmp(zLine, "| end ", 6)==0 ){
25876 break;
25877 }
25878 rc = sscanf(zLine,"| %d: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
25879 &j, &x[0], &x[1], &x[2], &x[3], &x[4], &x[5], &x[6], &x[7],
25880 &x[8], &x[9], &x[10], &x[11], &x[12], &x[13], &x[14], &x[15]);
25881 if( rc==17 ){
25882 k = iOffset+j;
25883 if( k+16<=n && k>=0 ){
25884 int ii;
25885 for(ii=0; ii<16; ii++) a[k+ii] = x[ii]&0xff;
25886 }
25887 }
25888 }
25889 *pnData = n;
25890 if( in!=p->in ){
25891 fclose(in);
25892 }else{
25893 p->lineno = nLine;
25894 }
25895 return a;
25896
25897readHexDb_error:
25898 if( in!=p->in ){
25899 fclose(in);
25900 }else{
25901 while( sqlite3_fgets(zLine, sizeof(zLine), p->in)!=0 ){
25902 nLine++;
25903 if(cli_strncmp(zLine, "| end ", 6)==0 ) break;
25904 }
25905 p->lineno = nLine;
25906 }
25907 sqlite3_free(a);
25908 sqlite3_fprintf(stderr,"Error on line %d of --hexdb input\n", nLine);

References a, cli_strncmp(), ShellState::in, ShellState::lineno, ShellState::pAuxDb, shell_check_oom(), sqlite3_fgets, sqlite3_fopen, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_malloc, and ShellState::AuxDb::zDbFilename.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerUDFs()

int registerUDFs ( sqlite3 * dbSrc,
sqlite3 * dbDst )
14694 {
14695 sqlite3_stmt *pStmt;
14696 int rc = sqlite3_prepare_v2(dbSrc,
14697 "SELECT name,type,enc,narg,flags "
14698 "FROM pragma_function_list() "
14699 "WHERE builtin==0", -1, &pStmt, 0);
14700 if( rc==SQLITE_OK ){
14701 while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
14702 int nargs = sqlite3_column_int(pStmt,3);
14703 int flags = sqlite3_column_int(pStmt,4);
14704 const char *name = (char*)sqlite3_column_text(pStmt,0);
14705 const char *type = (char*)sqlite3_column_text(pStmt,1);
14706 const char *enc = (char*)sqlite3_column_text(pStmt,2);
14707 if( name==0 || type==0 || enc==0 ){
14708 /* no-op. Only happens on OOM */
14709 }else{
14710 int ienc = SQLITE_UTF8;
14711 int rcf = SQLITE_ERROR;
14712 if( strcmp(enc,"utf16le")==0 ) ienc = SQLITE_UTF16LE;
14713 else if( strcmp(enc,"utf16be")==0 ) ienc = SQLITE_UTF16BE;
14714 ienc |= (flags & (SQLITE_DETERMINISTIC|SQLITE_DIRECTONLY));
14715 if( strcmp(type,"w")==0 ){
14716 rcf = sqlite3_create_window_function(dbDst,name,nargs,ienc,0,
14717 dummyUDF,dummyUDFvalue,0,0,0);
14718 }else if( strcmp(type,"a")==0 ){
14719 rcf = sqlite3_create_function(dbDst,name,nargs,ienc,0,
14721 }else if( strcmp(type,"s")==0 ){
14722 rcf = sqlite3_create_function(dbDst,name,nargs,ienc,0,
14723 dummyUDF,0,0);
14724 }
14725 if( rcf!=SQLITE_OK ){
14726 rc = rcf;
14727 break;
14728 }
14729 }
14730 }
14731 sqlite3_finalize(pStmt);
14732 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
14733 }
14734 return rc;
14735}
void dummyUDFvalue(sqlite3_context *up1)
Definition shell.c:14686
void dummyUDF(sqlite3_context *up1, int up2, sqlite3_value **up3)
Definition shell.c:14680
#define SQLITE_DETERMINISTIC
Definition sqlite3.c:6144
#define SQLITE_DIRECTONLY
Definition sqlite3.c:6145
#define SQLITE_UTF16BE
Definition sqlite3.c:6040
#define SQLITE_UTF16LE
Definition sqlite3.c:6039
#define sqlite3_create_window_function
Definition sqlite3ext.h:657

References dummyUDF(), dummyUDFvalue(), sqlite3_column_int, sqlite3_column_text, sqlite3_create_function, sqlite3_create_window_function, sqlite3_finalize, sqlite3_prepare_v2, sqlite3_step, SQLITE_DETERMINISTIC, SQLITE_DIRECTONLY, SQLITE_DONE, SQLITE_ERROR, SQLITE_OK, SQLITE_ROW, SQLITE_UTF16BE, SQLITE_UTF16LE, and SQLITE_UTF8.

Referenced by sqlite3_expert_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rePeek()

unsigned char rePeek ( ReCompiled * p)
static
7531 {
7532 return p->sIn.i<p->sIn.mx ? p->sIn.z[p->sIn.i] : 0;
7533}

References ReInput::i, ReInput::mx, ReCompiled::sIn, and ReInput::z.

Referenced by re_subcompile_re(), and re_subcompile_string().

Here is the caller graph for this function:

◆ resolve_backslashes()

void resolve_backslashes ( char * z)
static
26267 {
26268 int i, j;
26269 char c;
26270 while( *z && *z!='\\' ) z++;
26271 for(i=j=0; (c = z[i])!=0; i++, j++){
26272 if( c=='\\' && z[i+1]!=0 ){
26273 c = z[++i];
26274 if( c=='a' ){
26275 c = '\a';
26276 }else if( c=='b' ){
26277 c = '\b';
26278 }else if( c=='t' ){
26279 c = '\t';
26280 }else if( c=='n' ){
26281 c = '\n';
26282 }else if( c=='v' ){
26283 c = '\v';
26284 }else if( c=='f' ){
26285 c = '\f';
26286 }else if( c=='r' ){
26287 c = '\r';
26288 }else if( c=='"' ){
26289 c = '"';
26290 }else if( c=='\'' ){
26291 c = '\'';
26292 }else if( c=='\\' ){
26293 c = '\\';
26294 }else if( c=='x' ){
26295 int nhd = 0, hdv;
26296 u8 hv = 0;
26297 while( nhd<2 && (c=z[i+1+nhd])!=0 && (hdv=hexDigitValue(c))>=0 ){
26298 hv = (u8)((hv<<4)|hdv);
26299 ++nhd;
26300 }
26301 i += nhd;
26302 c = (u8)hv;
26303 }else if( c>='0' && c<='7' ){
26304 c -= '0';
26305 if( z[i+1]>='0' && z[i+1]<='7' ){
26306 i++;
26307 c = (c<<3) + z[i] - '0';
26308 if( z[i+1]>='0' && z[i+1]<='7' ){
26309 i++;
26310 c = (c<<3) + z[i] - '0';
26311 }
26312 }
26313 }
26314 }
26315 z[j] = c;
26316 }

References c, and hexDigitValue().

Referenced by do_meta_command(), and runOneSqlLine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_debug_trace_modes()

void restore_debug_trace_modes ( void )
static

References SQLITE_TESTCTRL_TRACEFLAGS.

Referenced by shell_exec().

Here is the caller graph for this function:

◆ run_schema_dump_query()

int run_schema_dump_query ( ShellState * p,
const char * zQuery )
static
25241 {
25242 int rc;
25243 char *zErr = 0;
25244 rc = sqlite3_exec(p->db, zQuery, dump_callback, p, &zErr);
25245 if( rc==SQLITE_CORRUPT ){
25246 char *zQ2;
25247 int len = strlen30(zQuery);
25248 sqlite3_fputs("/****** CORRUPTION ERROR *******/\n", p->out);
25249 if( zErr ){
25250 sqlite3_fprintf(p->out, "/****** %s ******/\n", zErr);
25251 sqlite3_free(zErr);
25252 zErr = 0;
25253 }
25254 zQ2 = malloc( len+100 );
25255 if( zQ2==0 ) return rc;
25256 sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery);
25257 rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr);
25258 if( rc ){
25259 sqlite3_fprintf(p->out, "/****** ERROR: %s ******/\n", zErr);
25260 }else{
25261 rc = SQLITE_CORRUPT;
25262 }
25263 free(zQ2);
25264 }
25265 sqlite3_free(zErr);
static int dump_callback(void *pArg, int nArg, char **azArg, char **azNotUsed)
Definition shell.c:25115

References ShellState::db, dump_callback(), ShellState::out, sqlite3_exec, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_snprintf, SQLITE_CORRUPT, and strlen30().

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_table_dump_query()

int run_table_dump_query ( ShellState * p,
const char * zSelect )
static
23466 {
23467 sqlite3_stmt *pSelect;
23468 int rc;
23469 int nResult;
23470 int i;
23471 const char *z;
23472 rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
23473 if( rc!=SQLITE_OK || !pSelect ){
23474 char *zContext = shell_error_context(zSelect, p->db);
23475 sqlite3_fprintf(p->out, "/**** ERROR: (%d) %s *****/\n%s",
23476 rc, sqlite3_errmsg(p->db), zContext);
23477 sqlite3_free(zContext);
23478 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
23479 return rc;
23480 }
23481 rc = sqlite3_step(pSelect);
23482 nResult = sqlite3_column_count(pSelect);
23483 while( rc==SQLITE_ROW ){
23484 z = (const char*)sqlite3_column_text(pSelect, 0);
23485 sqlite3_fprintf(p->out, "%s", z);
23486 for(i=1; i<nResult; i++){
23487 sqlite3_fprintf(p->out, ",%s", sqlite3_column_text(pSelect, i));
23488 }
23489 if( z==0 ) z = "";
23490 while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
23491 if( z[0] ){
23492 sqlite3_fputs("\n;\n", p->out);
23493 }else{
23494 sqlite3_fputs(";\n", p->out);
23495 }
23496 rc = sqlite3_step(pSelect);
23497 }
23498 rc = sqlite3_finalize(pSelect);
23499 if( rc!=SQLITE_OK ){
23500 sqlite3_fprintf(p->out, "/**** ERROR: (%d) %s *****/\n",
23501 rc, sqlite3_errmsg(p->db));
23502 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
23503 }
static char * shell_error_context(const char *zSql, sqlite3 *db)
Definition shell.c:23416

References ShellState::db, ShellState::nErr, ShellState::out, shell_error_context(), sqlite3_column_count, sqlite3_column_text, sqlite3_errmsg, sqlite3_finalize, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_prepare_v2, sqlite3_step, SQLITE_CORRUPT, SQLITE_OK, and SQLITE_ROW.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ runOneSqlLine()

int runOneSqlLine ( ShellState * p,
char * zSql,
FILE * in,
int startline )
static
32672 {
32673 int rc;
32674 char *zErrMsg = 0;
32675
32676 open_db(p, 0);
32678 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
32680 rc = shell_exec(p, zSql, &zErrMsg);
32681 END_TIMER(p->out);
32682 if( rc || zErrMsg ){
32683 char zPrefix[100];
32684 const char *zErrorTail;
32685 const char *zErrorType;
32686 if( zErrMsg==0 ){
32687 zErrorType = "Error";
32688 zErrorTail = sqlite3_errmsg(p->db);
32689 }else if( cli_strncmp(zErrMsg, "in prepare, ",12)==0 ){
32690 zErrorType = "Parse error";
32691 zErrorTail = &zErrMsg[12];
32692 }else if( cli_strncmp(zErrMsg, "stepping, ", 10)==0 ){
32693 zErrorType = "Runtime error";
32694 zErrorTail = &zErrMsg[10];
32695 }else{
32696 zErrorType = "Error";
32697 zErrorTail = zErrMsg;
32698 }
32699 if( in!=0 || !stdin_is_interactive ){
32700 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
32701 "%s near line %d:", zErrorType, startline);
32702 }else{
32703 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType);
32704 }
32705 sqlite3_fprintf(stderr,"%s %s\n", zPrefix, zErrorTail);
32706 sqlite3_free(zErrMsg);
32707 zErrMsg = 0;
32708 return 1;
32709 }else if( ShellHasFlag(p, SHFLG_CountChanges) ){
32710 char zLineBuf[2000];
32711 sqlite3_snprintf(sizeof(zLineBuf), zLineBuf,
32712 "changes: %lld total_changes: %lld",
32714 sqlite3_fprintf(p->out, "%s\n", zLineBuf);
32715 }
32716
32717 if( doAutoDetectRestore(p, zSql) ) return 1;
#define END_TIMER(X)
Definition shell.c:717
#define BEGIN_TIMER
Definition shell.c:716
#define sqlite3_total_changes64
Definition sqlite3ext.h:679
#define sqlite3_changes64
Definition sqlite3ext.h:678

References BEGIN_TIMER, cli_strncmp(), ShellState::db, doAutoDetectRestore(), END_TIMER, ShellState::flgProgress, ShellState::nProgress, open_db(), ShellState::out, resolve_backslashes(), shell_exec(), SHELL_PROGRESS_RESET, ShellHasFlag, SHFLG_Backslash, SHFLG_CountChanges, sqlite3_changes64, sqlite3_errmsg, sqlite3_fprintf, sqlite3_free, sqlite3_snprintf, sqlite3_total_changes64, and stdin_is_interactive.

Referenced by process_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ safeModeAuth()

int safeModeAuth ( void * pClientData,
int op,
const char * zA1,
const char * zA2,
const char * zA3,
const char * zA4 )
static
22583 {
22584 ShellState *p = (ShellState*)pClientData;
22585 static const char *azProhibitedFunctions[] = {
22586 "edit",
22587 "fts3_tokenizer",
22588 "load_extension",
22589 "readfile",
22590 "writefile",
22591 "zipfile",
22592 "zipfile_cds",
22593 };
22594 UNUSED_PARAMETER(zA1);
22595 UNUSED_PARAMETER(zA3);
22596 UNUSED_PARAMETER(zA4);
22597 switch( op ){
22598 case SQLITE_ATTACH: {
22599#ifndef SQLITE_SHELL_FIDDLE
22600 /* In WASM builds the filesystem is a virtual sandbox, so
22601 ** there's no harm in using ATTACH. */
22602 failIfSafeMode(p, "cannot run ATTACH in safe mode");
22603#endif
22604 break;
22605 }
22606 case SQLITE_FUNCTION: {
22607 int i;
22608 for(i=0; i<ArraySize(azProhibitedFunctions); i++){
22609 if( sqlite3_stricmp(zA2, azProhibitedFunctions[i])==0 ){
22610 failIfSafeMode(p, "cannot use the %s() function in safe mode",
22611 azProhibitedFunctions[i]);
22612 }
22613 }
22614 break;
22615 }
22616 }
#define SQLITE_FUNCTION
Definition sqlite3.c:3801
#define SQLITE_ATTACH
Definition sqlite3.c:3794

References ArraySize, failIfSafeMode(), sqlite3_stricmp, SQLITE_ATTACH, SQLITE_FUNCTION, SQLITE_OK, and UNUSED_PARAMETER.

Referenced by do_meta_command(), open_db(), and shellAuth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_err_msg()

char * save_err_msg ( sqlite3 * db,
const char * zPhase,
int rc,
const char * zSql )
static
23515 {
23516 char *zErr;
23517 char *zContext;
23518 sqlite3_str *pStr = sqlite3_str_new(0);
23519 sqlite3_str_appendf(pStr, "%s, %s", zPhase, sqlite3_errmsg(db));
23520 if( rc>1 ){
23521 sqlite3_str_appendf(pStr, " (%d)", rc);
23522 }
23523 zContext = shell_error_context(zSql, db);
23524 if( zContext ){
23525 sqlite3_str_appendall(pStr, zContext);
23526 sqlite3_free(zContext);
23527 }
23528 zErr = sqlite3_str_finish(pStr);
23529 shell_check_oom(zErr);
#define sqlite3_str_appendall
Definition sqlite3ext.h:650

References shell_check_oom(), shell_error_context(), sqlite3_errmsg, sqlite3_free, sqlite3_str_appendall, sqlite3_str_appendf, sqlite3_str_finish, and sqlite3_str_new.

Referenced by shell_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sayAbnormalExit()

void sayAbnormalExit ( void )
static
33183 {

Referenced by main().

Here is the caller graph for this function:

◆ seriesBestIndex()

int seriesBestIndex ( sqlite3_vtab * pVTab,
sqlite3_index_info * pIdxInfo )
static
6824 {
6825 int i, j; /* Loop over constraints */
6826 int idxNum = 0; /* The query plan bitmask */
6827#ifndef ZERO_ARGUMENT_GENERATE_SERIES
6828 int bStartSeen = 0; /* EQ constraint seen on the START column */
6829#endif
6830 int unusableMask = 0; /* Mask of unusable constraints */
6831 int nArg = 0; /* Number of arguments that seriesFilter() expects */
6832 int aIdx[7]; /* Constraints on start, stop, step, LIMIT, OFFSET,
6833 ** and value. aIdx[5] covers value=, value>=, and
6834 ** value>, aIdx[6] covers value<= and value< */
6835 const struct sqlite3_index_constraint *pConstraint;
6836
6837 /* This implementation assumes that the start, stop, and step columns
6838 ** are the last three columns in the virtual table. */
6841
6842 aIdx[0] = aIdx[1] = aIdx[2] = aIdx[3] = aIdx[4] = aIdx[5] = aIdx[6] = -1;
6843 pConstraint = pIdxInfo->aConstraint;
6844 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
6845 int iCol; /* 0 for start, 1 for stop, 2 for step */
6846 int iMask; /* bitmask for those column */
6847 int op = pConstraint->op;
6850 ){
6851 if( pConstraint->usable==0 ){
6852 /* do nothing */
6853 }else if( op==SQLITE_INDEX_CONSTRAINT_LIMIT ){
6854 aIdx[3] = i;
6855 idxNum |= 0x20;
6856 }else{
6857 assert( op==SQLITE_INDEX_CONSTRAINT_OFFSET );
6858 aIdx[4] = i;
6859 idxNum |= 0x40;
6860 }
6861 continue;
6862 }
6863 if( pConstraint->iColumn<SERIES_COLUMN_START ){
6864 if( (pConstraint->iColumn==SERIES_COLUMN_VALUE ||
6865 pConstraint->iColumn==SERIES_COLUMN_ROWID)
6866 && pConstraint->usable
6867 ){
6868 switch( op ){
6871 idxNum |= 0x0080;
6872 idxNum &= ~0x3300;
6873 aIdx[5] = i;
6874 aIdx[6] = -1;
6875#ifndef ZERO_ARGUMENT_GENERATE_SERIES
6876 bStartSeen = 1;
6877#endif
6878 break;
6879 }
6881 if( idxNum & 0x0080 ) break;
6882 idxNum |= 0x0100;
6883 idxNum &= ~0x0200;
6884 aIdx[5] = i;
6885#ifndef ZERO_ARGUMENT_GENERATE_SERIES
6886 bStartSeen = 1;
6887#endif
6888 break;
6889 }
6891 if( idxNum & 0x0080 ) break;
6892 idxNum |= 0x0200;
6893 idxNum &= ~0x0100;
6894 aIdx[5] = i;
6895#ifndef ZERO_ARGUMENT_GENERATE_SERIES
6896 bStartSeen = 1;
6897#endif
6898 break;
6899 }
6901 if( idxNum & 0x0080 ) break;
6902 idxNum |= 0x1000;
6903 idxNum &= ~0x2000;
6904 aIdx[6] = i;
6905 break;
6906 }
6908 if( idxNum & 0x0080 ) break;
6909 idxNum |= 0x2000;
6910 idxNum &= ~0x1000;
6911 aIdx[6] = i;
6912 break;
6913 }
6914 }
6915 }
6916 continue;
6917 }
6918 iCol = pConstraint->iColumn - SERIES_COLUMN_START;
6919 assert( iCol>=0 && iCol<=2 );
6920 iMask = 1 << iCol;
6921#ifndef ZERO_ARGUMENT_GENERATE_SERIES
6922 if( iCol==0 && op==SQLITE_INDEX_CONSTRAINT_EQ ){
6923 bStartSeen = 1;
6924 }
6925#endif
6926 if( pConstraint->usable==0 ){
6927 unusableMask |= iMask;
6928 continue;
6929 }else if( op==SQLITE_INDEX_CONSTRAINT_EQ ){
6930 idxNum |= iMask;
6931 aIdx[iCol] = i;
6932 }
6933 }
6934 if( aIdx[3]==0 ){
6935 /* Ignore OFFSET if LIMIT is omitted */
6936 idxNum &= ~0x60;
6937 aIdx[4] = 0;
6938 }
6939 for(i=0; i<7; i++){
6940 if( (j = aIdx[i])>=0 ){
6941 pIdxInfo->aConstraintUsage[j].argvIndex = ++nArg;
6942 pIdxInfo->aConstraintUsage[j].omit =
6944 }
6945 }
6946 /* The current generate_column() implementation requires at least one
6947 ** argument (the START value). Legacy versions assumed START=0 if the
6948 ** first argument was omitted. Compile with -DZERO_ARGUMENT_GENERATE_SERIES
6949 ** to obtain the legacy behavior */
6950#ifndef ZERO_ARGUMENT_GENERATE_SERIES
6951 if( !bStartSeen ){
6952 sqlite3_free(pVTab->zErrMsg);
6953 pVTab->zErrMsg = sqlite3_mprintf(
6954 "first argument to \"generate_series()\" missing or unusable");
6955 return SQLITE_ERROR;
6956 }
6957#endif
6958 if( (unusableMask & ~idxNum)!=0 ){
6959 /* The start, stop, and step columns are inputs. Therefore if there
6960 ** are unusable constraints on any of start, stop, or step then
6961 ** this plan is unusable */
6962 return SQLITE_CONSTRAINT;
6963 }
6964 if( (idxNum & 0x03)==0x03 ){
6965 /* Both start= and stop= boundaries are available. This is the
6966 ** the preferred case */
6967 pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0));
6968 pIdxInfo->estimatedRows = 1000;
6969 if( pIdxInfo->nOrderBy>=1 && pIdxInfo->aOrderBy[0].iColumn==0 ){
6970 if( pIdxInfo->aOrderBy[0].desc ){
6971 idxNum |= 0x08;
6972 }else{
6973 idxNum |= 0x10;
6974 }
6975 pIdxInfo->orderByConsumed = 1;
6976 }
6977 }else if( (idxNum & 0x21)==0x21 ){
6978 /* We have start= and LIMIT */
6979 pIdxInfo->estimatedRows = 2500;
6980 }else{
6981 /* If either boundary is missing, we have to generate a huge span
6982 ** of numbers. Make this case very expensive so that the query
6983 ** planner will work hard to avoid it. */
6984 pIdxInfo->estimatedRows = 2147483647;
6985 }
6986 pIdxInfo->idxNum = idxNum;
6987#ifdef SQLITE_INDEX_SCAN_HEX
6988 pIdxInfo->idxFlags = SQLITE_INDEX_SCAN_HEX;
6989#endif
6990 return SQLITE_OK;
6991}
#define SERIES_COLUMN_STEP
#define SERIES_COLUMN_START
#define SQLITE_SERIES_CONSTRAINT_VERIFY
Definition shell.c:6567
#define SERIES_COLUMN_ROWID
#define SERIES_COLUMN_STOP
#define SERIES_COLUMN_VALUE
#define SQLITE_INDEX_CONSTRAINT_IS
Definition sqlite3.c:8079
#define SQLITE_INDEX_CONSTRAINT_OFFSET
Definition sqlite3.c:8081
#define SQLITE_INDEX_SCAN_HEX
Definition sqlite3.c:8025
#define SQLITE_INDEX_CONSTRAINT_LIMIT
Definition sqlite3.c:8080
int orderByConsumed
Definition sqlite3.c:8007
int idxFlags
Definition sqlite3.c:8012

References sqlite3_index_info::aConstraint, sqlite3_index_info::aConstraintUsage, sqlite3_index_info::aOrderBy, sqlite3_index_info::sqlite3_index_constraint_usage::argvIndex, sqlite3_index_info::sqlite3_index_orderby::desc, sqlite3_index_info::estimatedCost, sqlite3_index_info::estimatedRows, sqlite3_index_info::sqlite3_index_orderby::iColumn, sqlite3_index_info::idxFlags, sqlite3_index_info::idxNum, sqlite3_index_info::nConstraint, sqlite3_index_info::nOrderBy, sqlite3_index_info::sqlite3_index_constraint_usage::omit, sqlite3_index_info::orderByConsumed, SERIES_COLUMN_ROWID, SERIES_COLUMN_START, SERIES_COLUMN_STEP, SERIES_COLUMN_STOP, SERIES_COLUMN_VALUE, sqlite3_free, sqlite3_mprintf, SQLITE_CONSTRAINT, SQLITE_ERROR, SQLITE_INDEX_CONSTRAINT_EQ, SQLITE_INDEX_CONSTRAINT_GE, SQLITE_INDEX_CONSTRAINT_GT, SQLITE_INDEX_CONSTRAINT_IS, SQLITE_INDEX_CONSTRAINT_LE, SQLITE_INDEX_CONSTRAINT_LIMIT, SQLITE_INDEX_CONSTRAINT_LT, SQLITE_INDEX_CONSTRAINT_OFFSET, SQLITE_INDEX_SCAN_HEX, SQLITE_OK, SQLITE_SERIES_CONSTRAINT_VERIFY, and sqlite3_vtab::zErrMsg.

◆ seriesClose()

int seriesClose ( sqlite3_vtab_cursor * cur)
static
6502 {
6503 sqlite3_free(cur);
6504 return SQLITE_OK;
6505}

References sqlite3_free, and SQLITE_OK.

◆ seriesColumn()

int seriesColumn ( sqlite3_vtab_cursor * cur,
sqlite3_context * ctx,
int i )
static
6525 {
6526 series_cursor *pCur = (series_cursor*)cur;
6527 sqlite3_int64 x = 0;
6528 switch( i ){
6529 case SERIES_COLUMN_START: x = pCur->ss.iOBase; break;
6530 case SERIES_COLUMN_STOP: x = pCur->ss.iOTerm; break;
6531 case SERIES_COLUMN_STEP: x = pCur->ss.iStep; break;
6532 default: x = pCur->ss.iValueNow; break;
6533 }
6534 sqlite3_result_int64(ctx, x);
6535 return SQLITE_OK;
6536}
sqlite3_int64 iOTerm
Definition shell.c:6333
SequenceSpec ss
Definition shell.c:6430
sqlite3_int64 iOBase
Definition shell.c:6332
Definition shell.c:6428

References SequenceSpec::iOBase, SequenceSpec::iOTerm, SequenceSpec::iStep, SequenceSpec::iValueNow, SERIES_COLUMN_START, SERIES_COLUMN_STEP, SERIES_COLUMN_STOP, sqlite3_result_int64, SQLITE_OK, and series_cursor::ss.

◆ seriesConnect()

int seriesConnect ( sqlite3 * db,
void * pUnused,
int argcUnused,
const char *const * argvUnused,
sqlite3_vtab ** ppVtab,
char ** pzErrUnused )
static
6452 {
6453 sqlite3_vtab *pNew;
6454 int rc;
6455
6456/* Column numbers */
6457#define SERIES_COLUMN_ROWID (-1)
6458#define SERIES_COLUMN_VALUE 0
6459#define SERIES_COLUMN_START 1
6460#define SERIES_COLUMN_STOP 2
6461#define SERIES_COLUMN_STEP 3
6462
6463 (void)pUnused;
6464 (void)argcUnused;
6465 (void)argvUnused;
6466 (void)pzErrUnused;
6467 rc = sqlite3_declare_vtab(db,
6468 "CREATE TABLE x(value,start hidden,stop hidden,step hidden)");
6469 if( rc==SQLITE_OK ){
6470 pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
6471 if( pNew==0 ) return SQLITE_NOMEM;
6472 memset(pNew, 0, sizeof(*pNew));
6474 }
6475 return rc;
6476}

References sqlite3_declare_vtab, sqlite3_malloc, sqlite3_vtab_config, SQLITE_NOMEM, SQLITE_OK, and SQLITE_VTAB_INNOCUOUS.

◆ seriesDisconnect()

int seriesDisconnect ( sqlite3_vtab * pVtab)
static
6481 {
6482 sqlite3_free(pVtab);
6483 return SQLITE_OK;
6484}

References sqlite3_free, and SQLITE_OK.

◆ seriesEof()

int seriesEof ( sqlite3_vtab_cursor * cur)
static
6557 {
6558 series_cursor *pCur = (series_cursor*)cur;
6559 return !pCur->ss.isNotEOF;
6560}

References SequenceSpec::isNotEOF, and series_cursor::ss.

◆ seriesFilter()

int seriesFilter ( sqlite3_vtab_cursor * pVtabCursor,
int idxNum,
const char * idxStrUnused,
int argc,
sqlite3_value ** argv )
static
6601 {
6602 series_cursor *pCur = (series_cursor *)pVtabCursor;
6603 int i = 0;
6604 int returnNoRows = 0;
6607 sqlite3_int64 iLimit = 0;
6608 sqlite3_int64 iOffset = 0;
6609
6610 (void)idxStrUnused;
6611 if( idxNum & 0x01 ){
6612 pCur->ss.iBase = sqlite3_value_int64(argv[i++]);
6613 }else{
6614 pCur->ss.iBase = 0;
6615 }
6616 if( idxNum & 0x02 ){
6617 pCur->ss.iTerm = sqlite3_value_int64(argv[i++]);
6618 }else{
6619 pCur->ss.iTerm = 0xffffffff;
6620 }
6621 if( idxNum & 0x04 ){
6622 pCur->ss.iStep = sqlite3_value_int64(argv[i++]);
6623 if( pCur->ss.iStep==0 ){
6624 pCur->ss.iStep = 1;
6625 }else if( pCur->ss.iStep<0 ){
6626 if( (idxNum & 0x10)==0 ) idxNum |= 0x08;
6627 }
6628 }else{
6629 pCur->ss.iStep = 1;
6630 }
6631
6632 /* If there are constraints on the value column but there are
6633 ** no constraints on the start, stop, and step columns, then
6634 ** initialize the default range to be the entire range of 64-bit signed
6635 ** integers. This range will contracted by the value column constraints
6636 ** further below.
6637 */
6638 if( (idxNum & 0x05)==0 && (idxNum & 0x0380)!=0 ){
6639 pCur->ss.iBase = SMALLEST_INT64;
6640 }
6641 if( (idxNum & 0x06)==0 && (idxNum & 0x3080)!=0 ){
6642 pCur->ss.iTerm = LARGEST_INT64;
6643 }
6644 pCur->ss.iOBase = pCur->ss.iBase;
6645 pCur->ss.iOTerm = pCur->ss.iTerm;
6646
6647 /* Extract the LIMIT and OFFSET values, but do not apply them yet.
6648 ** The range must first be constrained by the limits on value.
6649 */
6650 if( idxNum & 0x20 ){
6651 iLimit = sqlite3_value_int64(argv[i++]);
6652 if( idxNum & 0x40 ){
6653 iOffset = sqlite3_value_int64(argv[i++]);
6654 }
6655 }
6656
6657 if( idxNum & 0x3380 ){
6658 /* Extract the maximum range of output values determined by
6659 ** constraints on the "value" column.
6660 */
6661 if( idxNum & 0x0080 ){
6663 double r = sqlite3_value_double(argv[i++]);
6664 if( r==ceil(r) ){
6665 iMin = iMax = (sqlite3_int64)r;
6666 }else{
6667 returnNoRows = 1;
6668 }
6669 }else{
6670 iMin = iMax = sqlite3_value_int64(argv[i++]);
6671 }
6672 }else{
6673 if( idxNum & 0x0300 ){
6675 double r = sqlite3_value_double(argv[i++]);
6676 if( idxNum & 0x0200 && r==ceil(r) ){
6677 iMin = (sqlite3_int64)ceil(r+1.0);
6678 }else{
6679 iMin = (sqlite3_int64)ceil(r);
6680 }
6681 }else{
6682 iMin = sqlite3_value_int64(argv[i++]);
6683 if( idxNum & 0x0200 ){
6684 if( iMin==LARGEST_INT64 ){
6685 returnNoRows = 1;
6686 }else{
6687 iMin++;
6688 }
6689 }
6690 }
6691 }
6692 if( idxNum & 0x3000 ){
6694 double r = sqlite3_value_double(argv[i++]);
6695 if( (idxNum & 0x2000)!=0 && r==floor(r) ){
6696 iMax = (sqlite3_int64)(r-1.0);
6697 }else{
6698 iMax = (sqlite3_int64)floor(r);
6699 }
6700 }else{
6701 iMax = sqlite3_value_int64(argv[i++]);
6702 if( idxNum & 0x2000 ){
6703 if( iMax==SMALLEST_INT64 ){
6704 returnNoRows = 1;
6705 }else{
6706 iMax--;
6707 }
6708 }
6709 }
6710 }
6711 if( iMin>iMax ){
6712 returnNoRows = 1;
6713 }
6714 }
6715
6716 /* Try to reduce the range of values to be generated based on
6717 ** constraints on the "value" column.
6718 */
6719 if( pCur->ss.iStep>0 ){
6720 sqlite3_int64 szStep = pCur->ss.iStep;
6721 if( pCur->ss.iBase<iMin ){
6722 sqlite3_uint64 d = iMin - pCur->ss.iBase;
6723 pCur->ss.iBase += ((d+szStep-1)/szStep)*szStep;
6724 }
6725 if( pCur->ss.iTerm>iMax ){
6726 pCur->ss.iTerm = iMax;
6727 }
6728 }else{
6729 sqlite3_int64 szStep = -pCur->ss.iStep;
6730 assert( szStep>0 );
6731 if( pCur->ss.iBase>iMax ){
6732 sqlite3_uint64 d = pCur->ss.iBase - iMax;
6733 pCur->ss.iBase -= ((d+szStep-1)/szStep)*szStep;
6734 }
6735 if( pCur->ss.iTerm<iMin ){
6736 pCur->ss.iTerm = iMin;
6737 }
6738 }
6739 }
6740
6741 /* Apply LIMIT and OFFSET constraints, if any */
6742 if( idxNum & 0x20 ){
6743 if( iOffset>0 ){
6744 pCur->ss.iBase += pCur->ss.iStep*iOffset;
6745 }
6746 if( iLimit>=0 ){
6747 sqlite3_int64 iTerm;
6748 iTerm = pCur->ss.iBase + (iLimit - 1)*pCur->ss.iStep;
6749 if( pCur->ss.iStep<0 ){
6750 if( iTerm>pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
6751 }else{
6752 if( iTerm<pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
6753 }
6754 }
6755 }
6756
6757
6758 for(i=0; i<argc; i++){
6759 if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
6760 /* If any of the constraints have a NULL value, then return no rows.
6761 ** See ticket https://sqlite.org/src/info/fac496b61722daf2 */
6762 returnNoRows = 1;
6763 break;
6764 }
6765 }
6766 if( returnNoRows ){
6767 pCur->ss.iBase = 1;
6768 pCur->ss.iTerm = 0;
6769 pCur->ss.iStep = 1;
6770 }
6771 if( idxNum & 0x08 ){
6772 pCur->ss.isReversing = pCur->ss.iStep > 0;
6773 }else{
6774 pCur->ss.isReversing = pCur->ss.iStep < 0;
6775 }
6776 setupSequence( &pCur->ss );
6777 return SQLITE_OK;
6778}
static void setupSequence(SequenceSpec *pss)
Definition shell.c:6349
#define d
#define LARGEST_INT64
Definition shell.c:6539
sqlite3_int64 iBase
Definition shell.c:6334
sqlite3_int64 iTerm
Definition shell.c:6335
#define SMALLEST_INT64
Definition shell.c:6541

References d, SequenceSpec::iBase, SequenceSpec::iOBase, SequenceSpec::iOTerm, SequenceSpec::isReversing, SequenceSpec::iStep, SequenceSpec::iTerm, LARGEST_INT64, setupSequence(), SMALLEST_INT64, sqlite3_value_double, sqlite3_value_int64, sqlite3_value_numeric_type, sqlite3_value_type, SQLITE_FLOAT, SQLITE_NULL, SQLITE_OK, and series_cursor::ss.

Here is the call graph for this function:

◆ seriesNext()

int seriesNext ( sqlite3_vtab_cursor * cur)
static
6511 {
6512 series_cursor *pCur = (series_cursor*)cur;
6513 progressSequence( & pCur->ss );
6514 return SQLITE_OK;
6515}
static int progressSequence(SequenceSpec *pss)
Definition shell.c:6403

References progressSequence(), SQLITE_OK, and series_cursor::ss.

Here is the call graph for this function:

◆ seriesOpen()

int seriesOpen ( sqlite3_vtab * pUnused,
sqlite3_vtab_cursor ** ppCursor )
static
6489 {
6490 series_cursor *pCur;
6491 (void)pUnused;
6492 pCur = sqlite3_malloc( sizeof(*pCur) );
6493 if( pCur==0 ) return SQLITE_NOMEM;
6494 memset(pCur, 0, sizeof(*pCur));
6495 *ppCursor = &pCur->base;
6496 return SQLITE_OK;
6497}
sqlite3_vtab_cursor base
Definition shell.c:6429

References series_cursor::base, sqlite3_malloc, SQLITE_NOMEM, and SQLITE_OK.

◆ seriesRowid()

int seriesRowid ( sqlite3_vtab_cursor * cur,
sqlite_int64 * pRowid )
static
6547 {
6548 series_cursor *pCur = (series_cursor*)cur;
6549 *pRowid = pCur->ss.iValueNow;
6550 return SQLITE_OK;
6551}

References SequenceSpec::iValueNow, SQLITE_OK, and series_cursor::ss.

◆ set_table_name()

void set_table_name ( ShellState * p,
const char * zName )
static
23384 {
23385 int i, n;
23386 char cQuote;
23387 char *z;
23388
23389 if( p->zDestTable ){
23390 free(p->zDestTable);
23391 p->zDestTable = 0;
23392 }
23393 if( zName==0 ) return;
23394 cQuote = quoteChar(zName);
23395 n = strlen30(zName);
23396 if( cQuote ) n += n+2;
23397 z = p->zDestTable = malloc( n+1 );
23398 shell_check_oom(z);
23399 n = 0;
23400 if( cQuote ) z[n++] = cQuote;
23401 for(i=0; zName[i]; i++){
23402 z[n++] = zName[i];
23403 if( zName[i]==cQuote ) z[n++] = cQuote;
23404 }
23405 if( cQuote ) z[n++] = cQuote;

References quoteChar(), shell_check_oom(), strlen30(), and ShellState::zDestTable.

Referenced by do_meta_command(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCrlfMode()

void setCrlfMode ( ShellState * p)
static
22094 {
22095#ifdef _WIN32
22096 if( p->crlfMode ){
22097 sqlite3_fsetmode(p->out, _O_TEXT);
22098 }else{
22099 sqlite3_fsetmode(p->out, _O_BINARY);
22100 }
22101#else

References ShellState::crlfMode, ShellState::out, sqlite3_fsetmode, and UNUSED_PARAMETER.

Referenced by output_quoted_escaped_string(), output_quoted_string(), output_redir(), output_reset(), and shell_callback().

Here is the caller graph for this function:

◆ setLexemeOpen()

void setLexemeOpen ( struct DynaPrompt * p,
char * s,
char c )
static
927 {
928 if( s!=0 || c==0 ){
929 p->zScannerAwaits = s;
930 p->acAwait[0] = 0;
931 }else{
932 p->acAwait[0] = c;
933 p->zScannerAwaits = p->acAwait;
934 }
935}
char * zScannerAwaits
Definition shell.c:916
char acAwait[2]
Definition shell.c:914

References DynaPrompt::acAwait, c, and DynaPrompt::zScannerAwaits.

◆ setOrClearFlag()

void setOrClearFlag ( ShellState * p,
unsigned mFlag,
const char * zArg )
static
26346 {
26347 if( booleanValue(zArg) ){
26348 ShellSetFlag(p, mFlag);
26349 }else{
26350 ShellClearFlag(p, mFlag);

References booleanValue(), ShellClearFlag, and ShellSetFlag.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setupSequence()

void setupSequence ( SequenceSpec * pss)
static
6349 {
6350 int bSameSigns;
6351 pss->uSeqIndexMax = 0;
6352 pss->isNotEOF = 0;
6353 bSameSigns = (pss->iBase < 0)==(pss->iTerm < 0);
6354 if( pss->iTerm < pss->iBase ){
6355 sqlite3_uint64 nuspan = 0;
6356 if( bSameSigns ){
6357 nuspan = (sqlite3_uint64)(pss->iBase - pss->iTerm);
6358 }else{
6359 /* Under UBSAN (or on 1's complement machines), must do this in steps.
6360 * In this clause, iBase>=0 and iTerm<0 . */
6361 nuspan = 1;
6362 nuspan += pss->iBase;
6363 nuspan += -(pss->iTerm+1);
6364 }
6365 if( pss->iStep<0 ){
6366 pss->isNotEOF = 1;
6367 if( nuspan==ULONG_MAX ){
6368 pss->uSeqIndexMax = ( pss->iStep>LLONG_MIN )? nuspan/-pss->iStep : 1;
6369 }else if( pss->iStep>LLONG_MIN ){
6370 pss->uSeqIndexMax = nuspan/-pss->iStep;
6371 }
6372 }
6373 }else if( pss->iTerm > pss->iBase ){
6374 sqlite3_uint64 puspan = 0;
6375 if( bSameSigns ){
6376 puspan = (sqlite3_uint64)(pss->iTerm - pss->iBase);
6377 }else{
6378 /* Under UBSAN (or on 1's complement machines), must do this in steps.
6379 * In this clause, iTerm>=0 and iBase<0 . */
6380 puspan = 1;
6381 puspan += pss->iTerm;
6382 puspan += -(pss->iBase+1);
6383 }
6384 if( pss->iStep>0 ){
6385 pss->isNotEOF = 1;
6386 pss->uSeqIndexMax = puspan/pss->iStep;
6387 }
6388 }else if( pss->iTerm == pss->iBase ){
6389 pss->isNotEOF = 1;
6390 pss->uSeqIndexMax = 0;
6391 }
6392 pss->uSeqIndexNow = (pss->isReversing)? pss->uSeqIndexMax : 0;
6393 pss->iValueNow = (pss->isReversing)
6394 ? genSeqMember(pss->iBase, pss->iStep, pss->uSeqIndexMax)
6395 : pss->iBase;
6396}
static sqlite3_int64 genSeqMember(sqlite3_int64 smBase, sqlite3_int64 smStep, sqlite3_uint64 ix)
Definition shell.c:6304

References genSeqMember(), SequenceSpec::iBase, SequenceSpec::isNotEOF, SequenceSpec::isReversing, SequenceSpec::iStep, SequenceSpec::iTerm, SequenceSpec::iValueNow, SequenceSpec::uSeqIndexMax, and SequenceSpec::uSeqIndexNow.

Referenced by seriesFilter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sha1Func()

void sha1Func ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
3433 {
3434 SHA1Context cx;
3435 int eType = sqlite3_value_type(argv[0]);
3436 int nByte = sqlite3_value_bytes(argv[0]);
3437 char zOut[44];
3438
3439 assert( argc==1 );
3440 if( eType==SQLITE_NULL ) return;
3441 hash_init(&cx);
3442 if( eType==SQLITE_BLOB ){
3443 hash_step(&cx, sqlite3_value_blob(argv[0]), nByte);
3444 }else{
3445 hash_step(&cx, sqlite3_value_text(argv[0]), nByte);
3446 }
3447 if( sqlite3_user_data(context)!=0 ){
3448 hash_finish(&cx, zOut, 1);
3449 sqlite3_result_blob(context, zOut, 20, SQLITE_TRANSIENT);
3450 }else{
3451 hash_finish(&cx, zOut, 0);
3452 sqlite3_result_blob(context, zOut, 40, SQLITE_TRANSIENT);
3453 }
3454}
static void hash_finish(SHA1Context *p, char *zOut, int bAsBinary)
Definition shell.c:3385
static void hash_init(SHA1Context *p)
Definition shell.c:3329
Definition shell.c:3224

References hash_finish(), hash_init(), hash_step(), sqlite3_result_blob, sqlite3_user_data, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_text, sqlite3_value_type, SQLITE_BLOB, SQLITE_NULL, and SQLITE_TRANSIENT.

Referenced by sqlite3_sha_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sha1QueryFunc()

void sha1QueryFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
3472 {
3473 sqlite3 *db = sqlite3_context_db_handle(context);
3474 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
3475 sqlite3_stmt *pStmt = 0;
3476 int nCol; /* Number of columns in the result set */
3477 int i; /* Loop counter */
3478 int rc;
3479 int n;
3480 const char *z;
3481 SHA1Context cx;
3482 char zOut[44];
3483
3484 assert( argc==1 );
3485 if( zSql==0 ) return;
3486 hash_init(&cx);
3487 while( zSql[0] ){
3488 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zSql);
3489 if( rc ){
3490 char *zMsg = sqlite3_mprintf("error SQL statement [%s]: %s",
3491 zSql, sqlite3_errmsg(db));
3492 sqlite3_finalize(pStmt);
3493 sqlite3_result_error(context, zMsg, -1);
3494 sqlite3_free(zMsg);
3495 return;
3496 }
3497 if( !sqlite3_stmt_readonly(pStmt) ){
3498 char *zMsg = sqlite3_mprintf("non-query: [%s]", sqlite3_sql(pStmt));
3499 sqlite3_finalize(pStmt);
3500 sqlite3_result_error(context, zMsg, -1);
3501 sqlite3_free(zMsg);
3502 return;
3503 }
3504 nCol = sqlite3_column_count(pStmt);
3505 z = sqlite3_sql(pStmt);
3506 n = (int)strlen(z);
3507 hash_step_vformat(&cx,"S%d:",n);
3508 hash_step(&cx,(unsigned char*)z,n);
3509
3510 /* Compute a hash over the result of the query */
3511 while( SQLITE_ROW==sqlite3_step(pStmt) ){
3512 hash_step(&cx,(const unsigned char*)"R",1);
3513 for(i=0; i<nCol; i++){
3514 switch( sqlite3_column_type(pStmt,i) ){
3515 case SQLITE_NULL: {
3516 hash_step(&cx, (const unsigned char*)"N",1);
3517 break;
3518 }
3519 case SQLITE_INTEGER: {
3521 int j;
3522 unsigned char x[9];
3524 memcpy(&u, &v, 8);
3525 for(j=8; j>=1; j--){
3526 x[j] = u & 0xff;
3527 u >>= 8;
3528 }
3529 x[0] = 'I';
3530 hash_step(&cx, x, 9);
3531 break;
3532 }
3533 case SQLITE_FLOAT: {
3535 int j;
3536 unsigned char x[9];
3537 double r = sqlite3_column_double(pStmt,i);
3538 memcpy(&u, &r, 8);
3539 for(j=8; j>=1; j--){
3540 x[j] = u & 0xff;
3541 u >>= 8;
3542 }
3543 x[0] = 'F';
3544 hash_step(&cx,x,9);
3545 break;
3546 }
3547 case SQLITE_TEXT: {
3548 int n2 = sqlite3_column_bytes(pStmt, i);
3549 const unsigned char *z2 = sqlite3_column_text(pStmt, i);
3550 hash_step_vformat(&cx,"T%d:",n2);
3551 hash_step(&cx, z2, n2);
3552 break;
3553 }
3554 case SQLITE_BLOB: {
3555 int n2 = sqlite3_column_bytes(pStmt, i);
3556 const unsigned char *z2 = sqlite3_column_blob(pStmt, i);
3557 hash_step_vformat(&cx,"B%d:",n2);
3558 hash_step(&cx, z2, n2);
3559 break;
3560 }
3561 }
3562 }
3563 }
3564 sqlite3_finalize(pStmt);
3565 }
3566 hash_finish(&cx, zOut, 0);
3567 sqlite3_result_text(context, zOut, 40, SQLITE_TRANSIENT);
3568}
static void hash_step_vformat(SHA1Context *p, const char *zFormat,...)
Definition shell.c:3366
#define sqlite3_sql
Definition sqlite3ext.h:559
#define sqlite3_stmt_readonly
Definition sqlite3ext.h:592

References hash_finish(), hash_init(), hash_step(), hash_step_vformat(), sqlite3_column_blob, sqlite3_column_bytes, sqlite3_column_count, sqlite3_column_double, sqlite3_column_int64, sqlite3_column_text, sqlite3_column_type, sqlite3_context_db_handle, sqlite3_errmsg, sqlite3_finalize, sqlite3_free, sqlite3_mprintf, sqlite3_prepare_v2, sqlite3_result_error, sqlite3_result_text, sqlite3_sql, sqlite3_step, sqlite3_stmt_readonly, sqlite3_value_text, SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, SQLITE_ROW, SQLITE_TEXT, and SQLITE_TRANSIENT.

Referenced by sqlite3_sha_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SHA1Transform()

void SHA1Transform ( unsigned int state[5],
const unsigned char buffer[64] )
static
3262 {
3263 unsigned int qq[5]; /* a, b, c, d, e; */
3264 static int one = 1;
3265 unsigned int block[16];
3266 memcpy(block, buffer, 64);
3267 memcpy(qq,state,5*sizeof(unsigned int));
3268
3269#define a qq[0]
3270#define b qq[1]
3271#define c qq[2]
3272#define d qq[3]
3273#define e qq[4]
3274
3275 /* Copy p->state[] to working vars */
3276 /*
3277 a = state[0];
3278 b = state[1];
3279 c = state[2];
3280 d = state[3];
3281 e = state[4];
3282 */
3283
3284 /* 4 rounds of 20 operations each. Loop unrolled. */
3285 if( 1 == *(unsigned char*)&one ){
3286 Rl0(a,b,c,d,e, 0); Rl0(e,a,b,c,d, 1); Rl0(d,e,a,b,c, 2); Rl0(c,d,e,a,b, 3);
3287 Rl0(b,c,d,e,a, 4); Rl0(a,b,c,d,e, 5); Rl0(e,a,b,c,d, 6); Rl0(d,e,a,b,c, 7);
3288 Rl0(c,d,e,a,b, 8); Rl0(b,c,d,e,a, 9); Rl0(a,b,c,d,e,10); Rl0(e,a,b,c,d,11);
3289 Rl0(d,e,a,b,c,12); Rl0(c,d,e,a,b,13); Rl0(b,c,d,e,a,14); Rl0(a,b,c,d,e,15);
3290 }else{
3291 Rb0(a,b,c,d,e, 0); Rb0(e,a,b,c,d, 1); Rb0(d,e,a,b,c, 2); Rb0(c,d,e,a,b, 3);
3292 Rb0(b,c,d,e,a, 4); Rb0(a,b,c,d,e, 5); Rb0(e,a,b,c,d, 6); Rb0(d,e,a,b,c, 7);
3293 Rb0(c,d,e,a,b, 8); Rb0(b,c,d,e,a, 9); Rb0(a,b,c,d,e,10); Rb0(e,a,b,c,d,11);
3294 Rb0(d,e,a,b,c,12); Rb0(c,d,e,a,b,13); Rb0(b,c,d,e,a,14); Rb0(a,b,c,d,e,15);
3295 }
3296 R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
3297 R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
3298 R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
3299 R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
3300 R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
3301 R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
3302 R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
3303 R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
3304 R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
3305 R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
3306 R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
3307 R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
3308 R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
3309 R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
3310 R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
3311 R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
3312
3313 /* Add the working vars back into context.state[] */
3314 state[0] += a;
3315 state[1] += b;
3316 state[2] += c;
3317 state[3] += d;
3318 state[4] += e;
3319
3320#undef a
3321#undef b
3322#undef c
3323#undef d
3324#undef e
3325}
#define R1(v, w, x, y, z, i)
Definition shell.c:3250
#define R2(v, w, x, y, z, i)
Definition shell.c:3252
#define Rl0(v, w, x, y, z, i)
Definition shell.c:3246
#define R3(v, w, x, y, z, i)
Definition shell.c:3254
#define Rb0(v, w, x, y, z, i)
Definition shell.c:3248
#define R4(v, w, x, y, z, i)
Definition shell.c:3256

References a, b, c, d, e, R1, R2, R3, R4, Rb0, and Rl0.

Referenced by hash_step().

Here is the caller graph for this function:

◆ sha3_step_vformat()

void sha3_step_vformat ( SHA3Context * p,
const char * zFormat,
... )
static
2944 {
2945 va_list ap;
2946 int n;
2947 char zBuf[50];
2948 va_start(ap, zFormat);
2949 sqlite3_vsnprintf(sizeof(zBuf),zBuf,zFormat,ap);
2950 va_end(ap);
2951 n = (int)strlen(zBuf);
2952 SHA3Update(p, (unsigned char*)zBuf, n);
2953}
static void SHA3Update(SHA3Context *p, const unsigned char *aData, unsigned int nData)
Definition shell.c:2839

References SHA3Update(), and sqlite3_vsnprintf.

Referenced by sha3QueryFunc(), and sha3UpdateFromValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sha3AggFinal()

void sha3AggFinal ( sqlite3_context * context)
static
3134 {
3135 SHA3Context *p;
3136 p = (SHA3Context*)sqlite3_aggregate_context(context, sizeof(*p));
3137 if( p==0 ) return;
3138 if( p->iSize ){
3140 }
3141}
unsigned iSize
Definition shell.c:2481
static unsigned char * SHA3Final(SHA3Context *p)
Definition shell.c:2879
Definition shell.c:2473

References SHA3Context::iSize, SHA3Final(), sqlite3_aggregate_context, sqlite3_result_blob, and SQLITE_TRANSIENT.

Referenced by sqlite3_shathree_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sha3AggStep()

void sha3AggStep ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
3113 {
3114 SHA3Context *p;
3115 p = (SHA3Context*)sqlite3_aggregate_context(context, sizeof(*p));
3116 if( p==0 ) return;
3117 if( p->nRate==0 ){
3118 int sz = 256;
3119 if( argc==2 ){
3120 sz = sqlite3_value_int(argv[1]);
3121 if( sz!=224 && sz!=384 && sz!=512 ){
3122 sz = 256;
3123 }
3124 }
3125 SHA3Init(p, sz);
3126 }
3127 sha3UpdateFromValue(p, argv[0]);
3128}
unsigned nRate
Definition shell.c:2478
static void SHA3Init(SHA3Context *p, int iSize)
Definition shell.c:2809
static void sha3UpdateFromValue(SHA3Context *p, sqlite3_value *pVal)
Definition shell.c:2958

References SHA3Context::nRate, SHA3Init(), sha3UpdateFromValue(), sqlite3_aggregate_context, and sqlite3_value_int.

Referenced by sqlite3_shathree_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SHA3Final()

unsigned char * SHA3Final ( SHA3Context * p)
static
2879 {
2880 unsigned int i;
2881 if( p->nLoaded==p->nRate-1 ){
2882 const unsigned char c1 = 0x86;
2883 SHA3Update(p, &c1, 1);
2884 }else{
2885 const unsigned char c2 = 0x06;
2886 const unsigned char c3 = 0x80;
2887 SHA3Update(p, &c2, 1);
2888 p->nLoaded = p->nRate - 1;
2889 SHA3Update(p, &c3, 1);
2890 }
2891 for(i=0; i<p->nRate; i++){
2892 p->u.x[i+p->nRate] = p->u.x[i^p->ixMask];
2893 }
2894 return &p->u.x[p->nRate];
2895}
unsigned ixMask
Definition shell.c:2480
unsigned nLoaded
Definition shell.c:2479
union SHA3Context::@170030113152035301337133235341244320100212322150 u

References SHA3Context::ixMask, SHA3Context::nLoaded, SHA3Context::nRate, SHA3Update(), and SHA3Context::u.

Referenced by sha3AggFinal(), sha3Func(), and sha3QueryFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sha3Func()

void sha3Func ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
2912 {
2913 SHA3Context cx;
2914 int eType = sqlite3_value_type(argv[0]);
2915 int nByte = sqlite3_value_bytes(argv[0]);
2916 int iSize;
2917 if( argc==1 ){
2918 iSize = 256;
2919 }else{
2920 iSize = sqlite3_value_int(argv[1]);
2921 if( iSize!=224 && iSize!=256 && iSize!=384 && iSize!=512 ){
2922 sqlite3_result_error(context, "SHA3 size should be one of: 224 256 "
2923 "384 512", -1);
2924 return;
2925 }
2926 }
2927 if( eType==SQLITE_NULL ) return;
2928 SHA3Init(&cx, iSize);
2929 if( eType==SQLITE_BLOB ){
2930 SHA3Update(&cx, sqlite3_value_blob(argv[0]), nByte);
2931 }else{
2932 SHA3Update(&cx, sqlite3_value_text(argv[0]), nByte);
2933 }
2934 sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT);
2935}

References SHA3Final(), SHA3Init(), SHA3Update(), sqlite3_result_blob, sqlite3_result_error, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_int, sqlite3_value_text, sqlite3_value_type, SQLITE_BLOB, SQLITE_NULL, and SQLITE_TRANSIENT.

Referenced by sqlite3_shathree_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SHA3Init()

void SHA3Init ( SHA3Context * p,
int iSize )
static
2809 {
2810 memset(p, 0, sizeof(*p));
2811 p->iSize = iSize;
2812 if( iSize>=128 && iSize<=512 ){
2813 p->nRate = (1600 - ((iSize + 31)&~31)*2)/8;
2814 }else{
2815 p->nRate = (1600 - 2*256)/8;
2816 }
2817#if SHA3_BYTEORDER==1234
2818 /* Known to be little-endian at compile-time. No-op */
2819#elif SHA3_BYTEORDER==4321
2820 p->ixMask = 7; /* Big-endian */
2821#else
2822 {
2823 static unsigned int one = 1;
2824 if( 1==*(unsigned char*)&one ){
2825 /* Little endian. No byte swapping. */
2826 p->ixMask = 0;
2827 }else{
2828 /* Big endian. Byte swap. */
2829 p->ixMask = 7;
2830 }
2831 }
2832#endif
2833}

References SHA3Context::iSize, SHA3Context::ixMask, and SHA3Context::nRate.

Referenced by sha3AggStep(), sha3Func(), and sha3QueryFunc().

Here is the caller graph for this function:

◆ sha3QueryFunc()

void sha3QueryFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
3045 {
3046 sqlite3 *db = sqlite3_context_db_handle(context);
3047 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
3048 sqlite3_stmt *pStmt = 0;
3049 int nCol; /* Number of columns in the result set */
3050 int i; /* Loop counter */
3051 int rc;
3052 int n;
3053 const char *z;
3054 SHA3Context cx;
3055 int iSize;
3056
3057 if( argc==1 ){
3058 iSize = 256;
3059 }else{
3060 iSize = sqlite3_value_int(argv[1]);
3061 if( iSize!=224 && iSize!=256 && iSize!=384 && iSize!=512 ){
3062 sqlite3_result_error(context, "SHA3 size should be one of: 224 256 "
3063 "384 512", -1);
3064 return;
3065 }
3066 }
3067 if( zSql==0 ) return;
3068 SHA3Init(&cx, iSize);
3069 while( zSql[0] ){
3070 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zSql);
3071 if( rc ){
3072 char *zMsg = sqlite3_mprintf("error SQL statement [%s]: %s",
3073 zSql, sqlite3_errmsg(db));
3074 sqlite3_finalize(pStmt);
3075 sqlite3_result_error(context, zMsg, -1);
3076 sqlite3_free(zMsg);
3077 return;
3078 }
3079 if( !sqlite3_stmt_readonly(pStmt) ){
3080 char *zMsg = sqlite3_mprintf("non-query: [%s]", sqlite3_sql(pStmt));
3081 sqlite3_finalize(pStmt);
3082 sqlite3_result_error(context, zMsg, -1);
3083 sqlite3_free(zMsg);
3084 return;
3085 }
3086 nCol = sqlite3_column_count(pStmt);
3087 z = sqlite3_sql(pStmt);
3088 if( z ){
3089 n = (int)strlen(z);
3090 sha3_step_vformat(&cx,"S%d:",n);
3091 SHA3Update(&cx,(unsigned char*)z,n);
3092 }
3093
3094 /* Compute a hash over the result of the query */
3095 while( SQLITE_ROW==sqlite3_step(pStmt) ){
3096 SHA3Update(&cx,(const unsigned char*)"R",1);
3097 for(i=0; i<nCol; i++){
3099 }
3100 }
3101 sqlite3_finalize(pStmt);
3102 }
3103 sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT);
3104}
static void sha3_step_vformat(SHA3Context *p, const char *zFormat,...)
Definition shell.c:2940

References sha3_step_vformat(), SHA3Final(), SHA3Init(), SHA3Update(), sha3UpdateFromValue(), sqlite3_column_count, sqlite3_column_value, sqlite3_context_db_handle, sqlite3_errmsg, sqlite3_finalize, sqlite3_free, sqlite3_mprintf, sqlite3_prepare_v2, sqlite3_result_blob, sqlite3_result_error, sqlite3_sql, sqlite3_step, sqlite3_stmt_readonly, sqlite3_value_int, sqlite3_value_text, SQLITE_ROW, and SQLITE_TRANSIENT.

Referenced by sqlite3_shathree_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SHA3Update()

void SHA3Update ( SHA3Context * p,
const unsigned char * aData,
unsigned int nData )
static
2843 {
2844 unsigned int i = 0;
2845 if( aData==0 ) return;
2846#if SHA3_BYTEORDER==1234
2847 if( (p->nLoaded % 8)==0 && ((aData - (const unsigned char*)0)&7)==0 ){
2848 for(; i+7<nData; i+=8){
2849 p->u.s[p->nLoaded/8] ^= *(u64*)&aData[i];
2850 p->nLoaded += 8;
2851 if( p->nLoaded>=p->nRate ){
2852 KeccakF1600Step(p);
2853 p->nLoaded = 0;
2854 }
2855 }
2856 }
2857#endif
2858 for(; i<nData; i++){
2859#if SHA3_BYTEORDER==1234
2860 p->u.x[p->nLoaded] ^= aData[i];
2861#elif SHA3_BYTEORDER==4321
2862 p->u.x[p->nLoaded^0x07] ^= aData[i];
2863#else
2864 p->u.x[p->nLoaded^p->ixMask] ^= aData[i];
2865#endif
2866 p->nLoaded++;
2867 if( p->nLoaded==p->nRate ){
2868 KeccakF1600Step(p);
2869 p->nLoaded = 0;
2870 }
2871 }
2872}
static void KeccakF1600Step(SHA3Context *p)
Definition shell.c:2487

References SHA3Context::ixMask, KeccakF1600Step(), SHA3Context::nLoaded, SHA3Context::nRate, and SHA3Context::u.

Referenced by sha3_step_vformat(), SHA3Final(), sha3Func(), sha3QueryFunc(), and sha3UpdateFromValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sha3UpdateFromValue()

void sha3UpdateFromValue ( SHA3Context * p,
sqlite3_value * pVal )
static
2958 {
2959 switch( sqlite3_value_type(pVal) ){
2960 case SQLITE_NULL: {
2961 SHA3Update(p, (const unsigned char*)"N",1);
2962 break;
2963 }
2964 case SQLITE_INTEGER: {
2966 int j;
2967 unsigned char x[9];
2969 memcpy(&u, &v, 8);
2970 for(j=8; j>=1; j--){
2971 x[j] = u & 0xff;
2972 u >>= 8;
2973 }
2974 x[0] = 'I';
2975 SHA3Update(p, x, 9);
2976 break;
2977 }
2978 case SQLITE_FLOAT: {
2980 int j;
2981 unsigned char x[9];
2982 double r = sqlite3_value_double(pVal);
2983 memcpy(&u, &r, 8);
2984 for(j=8; j>=1; j--){
2985 x[j] = u & 0xff;
2986 u >>= 8;
2987 }
2988 x[0] = 'F';
2989 SHA3Update(p,x,9);
2990 break;
2991 }
2992 case SQLITE_TEXT: {
2993 int n2 = sqlite3_value_bytes(pVal);
2994 const unsigned char *z2 = sqlite3_value_text(pVal);
2995 sha3_step_vformat(p,"T%d:",n2);
2996 SHA3Update(p, z2, n2);
2997 break;
2998 }
2999 case SQLITE_BLOB: {
3000 int n2 = sqlite3_value_bytes(pVal);
3001 const unsigned char *z2 = sqlite3_value_blob(pVal);
3002 sha3_step_vformat(p,"B%d:",n2);
3003 SHA3Update(p, z2, n2);
3004 break;
3005 }
3006 }
3007}

References sha3_step_vformat(), SHA3Update(), sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_double, sqlite3_value_int64, sqlite3_value_text, sqlite3_value_type, SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, and SQLITE_TEXT.

Referenced by sha3AggStep(), and sha3QueryFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shell_callback()

int shell_callback ( void * pArg,
int nArg,
char ** azArg,
char ** azCol,
int * aiType )
static
22883 {
22884 int i;
22885 ShellState *p = (ShellState*)pArg;
22886
22887 if( azArg==0 ) return 0;
22888 switch( p->cMode ){
22889 case MODE_Count:
22890 case MODE_Off: {
22891 break;
22892 }
22893 case MODE_Line: {
22894 int w = 5;
22895 if( azArg==0 ) break;
22896 for(i=0; i<nArg; i++){
22897 int len = strlen30(azCol[i] ? azCol[i] : "");
22898 if( len>w ) w = len;
22899 }
22900 if( p->cnt++>0 ) sqlite3_fputs(p->rowSeparator, p->out);
22901 for(i=0; i<nArg; i++){
22902 char *pFree = 0;
22903 const char *pDisplay;
22904 pDisplay = escapeOutput(p, azArg[i] ? azArg[i] : p->nullValue, &pFree);
22905 sqlite3_fprintf(p->out, "%*s = %s%s", w, azCol[i],
22906 pDisplay, p->rowSeparator);
22907 if( pFree ) sqlite3_free(pFree);
22908 }
22909 break;
22910 }
22911 case MODE_ScanExp:
22912 case MODE_Explain: {
22913 static const int aExplainWidth[] = {4, 13, 4, 4, 4, 13, 2, 13};
22914 static const int aExplainMap[] = {0, 1, 2, 3, 4, 5, 6, 7 };
22915 static const int aScanExpWidth[] = {4, 15, 6, 13, 4, 4, 4, 13, 2, 13};
22916 static const int aScanExpMap[] = {0, 9, 8, 1, 2, 3, 4, 5, 6, 7 };
22917
22918 const int *aWidth = aExplainWidth;
22919 const int *aMap = aExplainMap;
22920 int nWidth = ArraySize(aExplainWidth);
22921 int iIndent = 1;
22922
22923 if( p->cMode==MODE_ScanExp ){
22924 aWidth = aScanExpWidth;
22925 aMap = aScanExpMap;
22926 nWidth = ArraySize(aScanExpWidth);
22927 iIndent = 3;
22928 }
22929 if( nArg>nWidth ) nArg = nWidth;
22930
22931 /* If this is the first row seen, print out the headers */
22932 if( p->cnt++==0 ){
22933 for(i=0; i<nArg; i++){
22934 utf8_width_print(p->out, aWidth[i], azCol[ aMap[i] ]);
22935 sqlite3_fputs(i==nArg-1 ? "\n" : " ", p->out);
22936 }
22937 for(i=0; i<nArg; i++){
22938 print_dashes(p->out, aWidth[i]);
22939 sqlite3_fputs(i==nArg-1 ? "\n" : " ", p->out);
22940 }
22941 }
22942
22943 /* If there is no data, exit early. */
22944 if( azArg==0 ) break;
22945
22946 for(i=0; i<nArg; i++){
22947 const char *zSep = " ";
22948 int w = aWidth[i];
22949 const char *zVal = azArg[ aMap[i] ];
22950 if( i==nArg-1 ) w = 0;
22951 if( zVal && strlenChar(zVal)>w ){
22952 w = strlenChar(zVal);
22953 zSep = " ";
22954 }
22955 if( i==iIndent && p->aiIndent && p->pStmt ){
22956 if( p->iIndent<p->nIndent ){
22957 sqlite3_fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
22958 }
22959 p->iIndent++;
22960 }
22961 utf8_width_print(p->out, w, zVal ? zVal : p->nullValue);
22962 sqlite3_fputs(i==nArg-1 ? "\n" : zSep, p->out);
22963 }
22964 break;
22965 }
22966 case MODE_Semi: { /* .schema and .fullschema output */
22967 printSchemaLine(p->out, azArg[0], ";\n");
22968 break;
22969 }
22970 case MODE_Pretty: { /* .schema and .fullschema with --indent */
22971 char *z;
22972 int j;
22973 int nParen = 0;
22974 char cEnd = 0;
22975 char c;
22976 int nLine = 0;
22977 int isIndex;
22978 int isWhere = 0;
22979 assert( nArg==1 );
22980 if( azArg[0]==0 ) break;
22981 if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0
22982 || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0
22983 ){
22984 sqlite3_fprintf(p->out, "%s;\n", azArg[0]);
22985 break;
22986 }
22987 isIndex = sqlite3_strlike("CREATE INDEX%", azArg[0], 0)==0
22988 || sqlite3_strlike("CREATE UNIQUE INDEX%", azArg[0], 0)==0;
22989 z = sqlite3_mprintf("%s", azArg[0]);
22990 shell_check_oom(z);
22991 j = 0;
22992 for(i=0; IsSpace(z[i]); i++){}
22993 for(; (c = z[i])!=0; i++){
22994 if( IsSpace(c) ){
22995 if( z[j-1]=='\r' ) z[j-1] = '\n';
22996 if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
22997 }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
22998 j--;
22999 }
23000 z[j++] = c;
23001 }
23002 while( j>0 && IsSpace(z[j-1]) ){ j--; }
23003 z[j] = 0;
23004 if( strlen30(z)>=79 ){
23005 for(i=j=0; (c = z[i])!=0; i++){ /* Copy from z[i] back to z[j] */
23006 if( c==cEnd ){
23007 cEnd = 0;
23008 }else if( c=='"' || c=='\'' || c=='`' ){
23009 cEnd = c;
23010 }else if( c=='[' ){
23011 cEnd = ']';
23012 }else if( c=='-' && z[i+1]=='-' ){
23013 cEnd = '\n';
23014 }else if( c=='(' ){
23015 nParen++;
23016 }else if( c==')' ){
23017 nParen--;
23018 if( nLine>0 && nParen==0 && j>0 && !isWhere ){
23019 printSchemaLineN(p->out, z, j, "\n");
23020 j = 0;
23021 }
23022 }else if( (c=='w' || c=='W')
23023 && nParen==0 && isIndex
23024 && sqlite3_strnicmp("WHERE",&z[i],5)==0
23025 && !IsAlnum(z[i+5]) && z[i+5]!='_' ){
23026 isWhere = 1;
23027 }else if( isWhere && (c=='A' || c=='a')
23028 && nParen==0
23029 && sqlite3_strnicmp("AND",&z[i],3)==0
23030 && !IsAlnum(z[i+3]) && z[i+3]!='_' ){
23031 printSchemaLineN(p->out, z, j, "\n ");
23032 j = 0;
23033 }
23034 z[j++] = c;
23035 if( nParen==1 && cEnd==0
23036 && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1)))
23037 && !isWhere
23038 ){
23039 if( c=='\n' ) j--;
23040 printSchemaLineN(p->out, z, j, "\n ");
23041 j = 0;
23042 nLine++;
23043 while( IsSpace(z[i+1]) ){ i++; }
23044 }
23045 }
23046 z[j] = 0;
23047 }
23048 printSchemaLine(p->out, z, ";\n");
23049 sqlite3_free(z);
23050 break;
23051 }
23052 case MODE_List: {
23053 if( p->cnt++==0 && p->showHeader ){
23054 for(i=0; i<nArg; i++){
23055 char *z = azCol[i];
23056 char *pFree;
23057 const char *zOut = escapeOutput(p, z, &pFree);
23058 sqlite3_fprintf(p->out, "%s%s", zOut,
23059 i==nArg-1 ? p->rowSeparator : p->colSeparator);
23060 if( pFree ) sqlite3_free(pFree);
23061 }
23062 }
23063 if( azArg==0 ) break;
23064 for(i=0; i<nArg; i++){
23065 char *z = azArg[i];
23066 char *pFree;
23067 const char *zOut;
23068 if( z==0 ) z = p->nullValue;
23069 zOut = escapeOutput(p, z, &pFree);
23070 sqlite3_fputs(zOut, p->out);
23071 if( pFree ) sqlite3_free(pFree);
23072 sqlite3_fputs((i<nArg-1)? p->colSeparator : p->rowSeparator, p->out);
23073 }
23074 break;
23075 }
23076 case MODE_Www:
23077 case MODE_Html: {
23078 if( p->cnt==0 && p->cMode==MODE_Www ){
23080 "</PRE>\n"
23081 "<TABLE border='1' cellspacing='0' cellpadding='2'>\n"
23082 ,p->out
23083 );
23084 }
23085 if( p->cnt==0 && (p->showHeader || p->cMode==MODE_Www) ){
23086 sqlite3_fputs("<TR>", p->out);
23087 for(i=0; i<nArg; i++){
23088 sqlite3_fputs("<TH>", p->out);
23089 output_html_string(p->out, azCol[i]);
23090 sqlite3_fputs("</TH>\n", p->out);
23091 }
23092 sqlite3_fputs("</TR>\n", p->out);
23093 }
23094 p->cnt++;
23095 if( azArg==0 ) break;
23096 sqlite3_fputs("<TR>", p->out);
23097 for(i=0; i<nArg; i++){
23098 sqlite3_fputs("<TD>", p->out);
23099 output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
23100 sqlite3_fputs("</TD>\n", p->out);
23101 }
23102 sqlite3_fputs("</TR>\n", p->out);
23103 break;
23104 }
23105 case MODE_Tcl: {
23106 if( p->cnt++==0 && p->showHeader ){
23107 for(i=0; i<nArg; i++){
23108 output_c_string(p->out, azCol[i] ? azCol[i] : "");
23109 if(i<nArg-1) sqlite3_fputs(p->colSeparator, p->out);
23110 }
23112 }
23113 if( azArg==0 ) break;
23114 for(i=0; i<nArg; i++){
23115 output_c_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
23116 if(i<nArg-1) sqlite3_fputs(p->colSeparator, p->out);
23117 }
23119 break;
23120 }
23121 case MODE_Csv: {
23122 sqlite3_fsetmode(p->out, _O_BINARY);
23123 if( p->cnt++==0 && p->showHeader ){
23124 for(i=0; i<nArg; i++){
23125 output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
23126 }
23128 }
23129 if( nArg>0 ){
23130 for(i=0; i<nArg; i++){
23131 output_csv(p, azArg[i], i<nArg-1);
23132 }
23134 }
23135 setCrlfMode(p);
23136 break;
23137 }
23138 case MODE_Insert: {
23139 if( azArg==0 ) break;
23140 sqlite3_fprintf(p->out, "INSERT INTO %s",p->zDestTable);
23141 if( p->showHeader ){
23142 sqlite3_fputs("(", p->out);
23143 for(i=0; i<nArg; i++){
23144 if( i>0 ) sqlite3_fputs(",", p->out);
23145 if( quoteChar(azCol[i]) ){
23146 char *z = sqlite3_mprintf("\"%w\"", azCol[i]);
23147 shell_check_oom(z);
23148 sqlite3_fputs(z, p->out);
23149 sqlite3_free(z);
23150 }else{
23151 sqlite3_fprintf(p->out, "%s", azCol[i]);
23152 }
23153 }
23154 sqlite3_fputs(")", p->out);
23155 }
23156 p->cnt++;
23157 for(i=0; i<nArg; i++){
23158 sqlite3_fputs(i>0 ? "," : " VALUES(", p->out);
23159 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
23160 sqlite3_fputs("NULL", p->out);
23161 }else if( aiType && aiType[i]==SQLITE_TEXT ){
23162 if( ShellHasFlag(p, SHFLG_Newlines) ){
23163 output_quoted_string(p, azArg[i]);
23164 }else{
23165 output_quoted_escaped_string(p, azArg[i]);
23166 }
23167 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
23168 sqlite3_fputs(azArg[i], p->out);
23169 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
23170 char z[50];
23171 double r = sqlite3_column_double(p->pStmt, i);
23172 sqlite3_uint64 ur;
23173 memcpy(&ur,&r,sizeof(r));
23174 if( ur==0x7ff0000000000000LL ){
23175 sqlite3_fputs("9.0e+999", p->out);
23176 }else if( ur==0xfff0000000000000LL ){
23177 sqlite3_fputs("-9.0e+999", p->out);
23178 }else{
23180 if( r==(double)ir ){
23181 sqlite3_snprintf(50,z,"%lld.0", ir);
23182 }else{
23183 sqlite3_snprintf(50,z,"%!.20g", r);
23184 }
23185 sqlite3_fputs(z, p->out);
23186 }
23187 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
23188 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
23189 int nBlob = sqlite3_column_bytes(p->pStmt, i);
23190 output_hex_blob(p->out, pBlob, nBlob);
23191 }else if( isNumber(azArg[i], 0) ){
23192 sqlite3_fputs(azArg[i], p->out);
23193 }else if( ShellHasFlag(p, SHFLG_Newlines) ){
23194 output_quoted_string(p, azArg[i]);
23195 }else{
23196 output_quoted_escaped_string(p, azArg[i]);
23197 }
23198 }
23199 sqlite3_fputs(");\n", p->out);
23200 break;
23201 }
23202 case MODE_Json: {
23203 if( azArg==0 ) break;
23204 if( p->cnt==0 ){
23205 sqlite3_fputs("[{", p->out);
23206 }else{
23207 sqlite3_fputs(",\n{", p->out);
23208 }
23209 p->cnt++;
23210 for(i=0; i<nArg; i++){
23211 output_json_string(p->out, azCol[i], -1);
23212 sqlite3_fputs(":", p->out);
23213 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
23214 sqlite3_fputs("null", p->out);
23215 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
23216 char z[50];
23217 double r = sqlite3_column_double(p->pStmt, i);
23218 sqlite3_uint64 ur;
23219 memcpy(&ur,&r,sizeof(r));
23220 if( ur==0x7ff0000000000000LL ){
23221 sqlite3_fputs("9.0e+999", p->out);
23222 }else if( ur==0xfff0000000000000LL ){
23223 sqlite3_fputs("-9.0e+999", p->out);
23224 }else{
23225 sqlite3_snprintf(50,z,"%!.20g", r);
23226 sqlite3_fputs(z, p->out);
23227 }
23228 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
23229 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
23230 int nBlob = sqlite3_column_bytes(p->pStmt, i);
23231 output_json_string(p->out, pBlob, nBlob);
23232 }else if( aiType && aiType[i]==SQLITE_TEXT ){
23233 output_json_string(p->out, azArg[i], -1);
23234 }else{
23235 sqlite3_fputs(azArg[i], p->out);
23236 }
23237 if( i<nArg-1 ){
23238 sqlite3_fputs(",", p->out);
23239 }
23240 }
23241 sqlite3_fputs("}", p->out);
23242 break;
23243 }
23244 case MODE_Quote: {
23245 if( azArg==0 ) break;
23246 if( p->cnt==0 && p->showHeader ){
23247 for(i=0; i<nArg; i++){
23248 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
23249 output_quoted_string(p, azCol[i]);
23250 }
23252 }
23253 p->cnt++;
23254 for(i=0; i<nArg; i++){
23255 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
23256 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
23257 sqlite3_fputs("NULL", p->out);
23258 }else if( aiType && aiType[i]==SQLITE_TEXT ){
23259 output_quoted_string(p, azArg[i]);
23260 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
23261 sqlite3_fputs(azArg[i], p->out);
23262 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
23263 char z[50];
23264 double r = sqlite3_column_double(p->pStmt, i);
23265 sqlite3_snprintf(50,z,"%!.20g", r);
23266 sqlite3_fputs(z, p->out);
23267 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
23268 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
23269 int nBlob = sqlite3_column_bytes(p->pStmt, i);
23270 output_hex_blob(p->out, pBlob, nBlob);
23271 }else if( isNumber(azArg[i], 0) ){
23272 sqlite3_fputs(azArg[i], p->out);
23273 }else{
23274 output_quoted_string(p, azArg[i]);
23275 }
23276 }
23278 break;
23279 }
23280 case MODE_Ascii: {
23281 if( p->cnt++==0 && p->showHeader ){
23282 for(i=0; i<nArg; i++){
23283 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
23284 sqlite3_fputs(azCol[i] ? azCol[i] : "", p->out);
23285 }
23287 }
23288 if( azArg==0 ) break;
23289 for(i=0; i<nArg; i++){
23290 if( i>0 ) sqlite3_fputs(p->colSeparator, p->out);
23291 sqlite3_fputs(azArg[i] ? azArg[i] : p->nullValue, p->out);
23292 }
23294 break;
23295 }
23296 case MODE_EQP: {
23297 eqp_append(p, atoi(azArg[0]), atoi(azArg[1]), azArg[3]);
23298 break;
23299 }
23300 }
static void output_quoted_escaped_string(ShellState *p, const char *z)
Definition shell.c:22211
#define MODE_EQP
Definition shell.c:21829
static void output_csv(ShellState *p, const char *z, int bSep)
Definition shell.c:22521
static void eqp_append(ShellState *p, int iEqpId, int p2, const char *zText)
Definition shell.c:22728
static void output_hex_blob(FILE *out, const void *pBlob, int nBlob)
Definition shell.c:22107
static void output_html_string(FILE *out, const char *z)
Definition shell.c:22461
static int wsToEol(const char *z)
Definition shell.c:22714
static int isNumber(const char *z, int *realnum)
Definition shell.c:1235
static void output_json_string(FILE *out, const char *z, i64 n)
Definition shell.c:22324
static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail)
Definition shell.c:22703
static void output_quoted_string(ShellState *p, const char *zInX)
Definition shell.c:22142
static const char * escapeOutput(ShellState *p, const char *zInX, char **ppFree)
Definition shell.c:22386

References ShellState::aiIndent, ArraySize, c, ShellState::cMode, ShellState::cnt, ShellState::colSeparator, eqp_append(), escapeOutput(), ShellState::iIndent, IsAlnum, isNumber(), IsSpace, MODE_Ascii, MODE_Count, MODE_Csv, MODE_EQP, MODE_Explain, MODE_Html, MODE_Insert, MODE_Json, MODE_Line, MODE_List, MODE_Off, MODE_Pretty, MODE_Quote, MODE_ScanExp, MODE_Semi, MODE_Tcl, MODE_Www, ShellState::nIndent, ShellState::nullValue, ShellState::out, output_c_string(), output_csv(), output_hex_blob(), output_html_string(), output_json_string(), output_quoted_escaped_string(), output_quoted_string(), print_dashes(), printSchemaLine(), printSchemaLineN(), ShellState::pStmt, quoteChar(), ShellState::rowSeparator, setCrlfMode(), shell_check_oom(), ShellHasFlag, SHFLG_Newlines, ShellState::showHeader, sqlite3_column_blob, sqlite3_column_bytes, sqlite3_column_double, sqlite3_fprintf, sqlite3_fputs, sqlite3_free, sqlite3_fsetmode, sqlite3_mprintf, sqlite3_snprintf, sqlite3_strlike, sqlite3_strnicmp, SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, SQLITE_TEXT, strlen30(), strlenChar(), utf8_width_print(), wsToEol(), and ShellState::zDestTable.

Referenced by callback(), and exec_prepared_stmt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shell_check_oom()

◆ shell_dbtotxt_command()

int shell_dbtotxt_command ( ShellState * p,
int nArg,
char ** azArg )
static
27045 {
27046 sqlite3_stmt *pStmt = 0;
27047 sqlite3_int64 nPage = 0;
27048 int pgSz = 0;
27049 const char *zTail;
27050 char *zName = 0;
27051 int rc, i, j;
27052 unsigned char bShow[256]; /* Characters ok to display */
27053
27054 UNUSED_PARAMETER(nArg);
27055 UNUSED_PARAMETER(azArg);
27056 memset(bShow, '.', sizeof(bShow));
27057 for(i=' '; i<='~'; i++){
27058 if( i!='{' && i!='}' && i!='"' && i!='\\' ) bShow[i] = (unsigned char)i;
27059 }
27060 rc = sqlite3_prepare_v2(p->db, "PRAGMA page_size", -1, &pStmt, 0);
27061 if( rc ) goto dbtotxt_error;
27062 rc = 0;
27063 if( sqlite3_step(pStmt)!=SQLITE_ROW ) goto dbtotxt_error;
27064 pgSz = sqlite3_column_int(pStmt, 0);
27065 sqlite3_finalize(pStmt);
27066 pStmt = 0;
27067 if( pgSz<512 || pgSz>65536 || (pgSz&(pgSz-1))!=0 ) goto dbtotxt_error;
27068 rc = sqlite3_prepare_v2(p->db, "PRAGMA page_count", -1, &pStmt, 0);
27069 if( rc ) goto dbtotxt_error;
27070 rc = 0;
27071 if( sqlite3_step(pStmt)!=SQLITE_ROW ) goto dbtotxt_error;
27072 nPage = sqlite3_column_int64(pStmt, 0);
27073 sqlite3_finalize(pStmt);
27074 pStmt = 0;
27075 if( nPage<1 ) goto dbtotxt_error;
27076 rc = sqlite3_prepare_v2(p->db, "PRAGMA databases", -1, &pStmt, 0);
27077 if( rc ) goto dbtotxt_error;
27078 if( sqlite3_step(pStmt)!=SQLITE_ROW ){
27079 zTail = "unk.db";
27080 }else{
27081 const char *zFilename = (const char*)sqlite3_column_text(pStmt, 2);
27082 if( zFilename==0 || zFilename[0]==0 ) zFilename = "unk.db";
27083 zTail = strrchr(zFilename, '/');
27084#if defined(_WIN32)
27085 if( zTail==0 ) zTail = strrchr(zFilename, '\\');
27086#endif
27087 }
27088 zName = strdup(zTail);
27089 shell_check_oom(zName);
27090 sqlite3_fprintf(p->out, "| size %lld pagesize %d filename %s\n",
27091 nPage*pgSz, pgSz, zName);
27092 sqlite3_finalize(pStmt);
27093 pStmt = 0;
27094 rc = sqlite3_prepare_v2(p->db,
27095 "SELECT pgno, data FROM sqlite_dbpage ORDER BY pgno", -1, &pStmt, 0);
27096 if( rc ) goto dbtotxt_error;
27097 while( sqlite3_step(pStmt)==SQLITE_ROW ){
27098 sqlite3_int64 pgno = sqlite3_column_int64(pStmt, 0);
27099 const u8 *aData = sqlite3_column_blob(pStmt, 1);
27100 int seenPageLabel = 0;
27101 for(i=0; i<pgSz; i+=16){
27102 const u8 *aLine = aData+i;
27103 for(j=0; j<16 && aLine[j]==0; j++){}
27104 if( j==16 ) continue;
27105 if( !seenPageLabel ){
27106 sqlite3_fprintf(p->out, "| page %lld offset %lld\n",pgno,(pgno-1)*pgSz);
27107 seenPageLabel = 1;
27108 }
27109 sqlite3_fprintf(p->out, "| %5d:", i);
27110 for(j=0; j<16; j++) sqlite3_fprintf(p->out, " %02x", aLine[j]);
27111 sqlite3_fprintf(p->out, " ");
27112 for(j=0; j<16; j++){
27113 unsigned char c = (unsigned char)aLine[j];
27114 sqlite3_fprintf(p->out, "%c", bShow[c]);
27115 }
27116 sqlite3_fprintf(p->out, "\n");
27117 }
27118 }
27119 sqlite3_finalize(pStmt);
27120 sqlite3_fprintf(p->out, "| end %s\n", zName);
27121 free(zName);
27122 return 0;
27123
27124dbtotxt_error:
27125 if( rc ){
27126 sqlite3_fprintf(stderr, "ERROR: %s\n", sqlite3_errmsg(p->db));
27127 }
27128 sqlite3_finalize(pStmt);
27129 free(zName);

References c, ShellState::db, ShellState::out, shell_check_oom(), sqlite3_column_blob, sqlite3_column_int, sqlite3_column_int64, sqlite3_column_text, sqlite3_errmsg, sqlite3_finalize, sqlite3_fprintf, sqlite3_prepare_v2, sqlite3_step, SQLITE_ROW, and UNUSED_PARAMETER.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shell_error_context()

char * shell_error_context ( const char * zSql,
sqlite3 * db )
static
23418 {
23419 int iOffset;
23420 size_t len;
23421 char *zCode;
23422 char *zMsg;
23423 int i;
23424 if( db==0
23425 || zSql==0
23426 || (iOffset = sqlite3_error_offset(db))<0
23427 || iOffset>=(int)strlen(zSql)
23428 ){
23429 return sqlite3_mprintf("");
23430 }
23431 while( iOffset>50 ){
23432 iOffset--;
23433 zSql++;
23434 while( (zSql[0]&0xc0)==0x80 ){ zSql++; iOffset--; }
23435 }
23436 len = strlen(zSql);
23437 if( len>78 ){
23438 len = 78;
23439 while( len>0 && (zSql[len]&0xc0)==0x80 ) len--;
23440 }
23441 zCode = sqlite3_mprintf("%.*s", len, zSql);
23442 shell_check_oom(zCode);
23443 for(i=0; zCode[i]; i++){ if( IsSpace(zSql[i]) ) zCode[i] = ' '; }
23444 if( iOffset<25 ){
23445 zMsg = sqlite3_mprintf("\n %z\n %*s^--- error here", zCode,iOffset,"");
23446 }else{
23447 zMsg = sqlite3_mprintf("\n %z\n %*serror here ---^", zCode,iOffset-14,"");
23448 }
#define sqlite3_error_offset
Definition sqlite3ext.h:683

References IsSpace, shell_check_oom(), sqlite3_error_offset, and sqlite3_mprintf.

Referenced by run_table_dump_query(), and save_err_msg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shell_exec()

int shell_exec ( ShellState * pArg,
const char * zSql,
char ** pzErrMsg )
static
24835 {
24836 sqlite3_stmt *pStmt = NULL; /* Statement to execute. */
24837 int rc = SQLITE_OK; /* Return Code */
24838 int rc2;
24839 const char *zLeftover; /* Tail of unprocessed SQL */
24840 sqlite3 *db = pArg->db;
24841
24842 if( pzErrMsg ){
24843 *pzErrMsg = NULL;
24844 }
24845
24846#ifndef SQLITE_OMIT_VIRTUALTABLE
24847 if( pArg->expert.pExpert ){
24848 rc = expertHandleSQL(pArg, zSql, pzErrMsg);
24849 return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
24850 }
24851#endif
24852
24853 while( zSql[0] && (SQLITE_OK == rc) ){
24854 static const char *zStmtSql;
24855 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
24856 if( SQLITE_OK != rc ){
24857 if( pzErrMsg ){
24858 *pzErrMsg = save_err_msg(db, "in prepare", rc, zSql);
24859 }
24860 }else{
24861 if( !pStmt ){
24862 /* this happens for a comment or white-space */
24863 zSql = zLeftover;
24864 while( IsSpace(zSql[0]) ) zSql++;
24865 continue;
24866 }
24867 zStmtSql = sqlite3_sql(pStmt);
24868 if( zStmtSql==0 ) zStmtSql = "";
24869 while( IsSpace(zStmtSql[0]) ) zStmtSql++;
24870
24871 /* save off the prepared statement handle and reset row count */
24872 if( pArg ){
24873 pArg->pStmt = pStmt;
24874 pArg->cnt = 0;
24875 }
24876
24877 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
24878 if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
24879 sqlite3_stmt *pExplain;
24880 int triggerEQP = 0;
24882 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
24883 if( pArg->autoEQP>=AUTOEQP_trigger ){
24885 }
24886 pExplain = pStmt;
24887 sqlite3_reset(pExplain);
24888 rc = sqlite3_stmt_explain(pExplain, 2);
24889 if( rc==SQLITE_OK ){
24890 bind_prepared_stmt(pArg, pExplain);
24891 while( sqlite3_step(pExplain)==SQLITE_ROW ){
24892 const char *zEQPLine = (const char*)sqlite3_column_text(pExplain,3);
24893 int iEqpId = sqlite3_column_int(pExplain, 0);
24894 int iParentId = sqlite3_column_int(pExplain, 1);
24895 if( zEQPLine==0 ) zEQPLine = "";
24896 if( zEQPLine[0]=='-' ) eqp_render(pArg, 0);
24897 eqp_append(pArg, iEqpId, iParentId, zEQPLine);
24898 }
24899 eqp_render(pArg, 0);
24900 }
24901 if( pArg->autoEQP>=AUTOEQP_full ){
24902 /* Also do an EXPLAIN for ".eqp full" mode */
24903 sqlite3_reset(pExplain);
24904 rc = sqlite3_stmt_explain(pExplain, 1);
24905 if( rc==SQLITE_OK ){
24906 pArg->cMode = MODE_Explain;
24907 assert( sqlite3_stmt_isexplain(pExplain)==1 );
24908 bind_prepared_stmt(pArg, pExplain);
24909 explain_data_prepare(pArg, pExplain);
24910 exec_prepared_stmt(pArg, pExplain);
24911 explain_data_delete(pArg);
24912 }
24913 }
24914 if( pArg->autoEQP>=AUTOEQP_trigger && triggerEQP==0 ){
24916 }
24917 sqlite3_reset(pStmt);
24918 sqlite3_stmt_explain(pStmt, 0);
24920 }
24921
24922 if( pArg ){
24923 int bIsExplain = (sqlite3_stmt_isexplain(pStmt)==1);
24924 pArg->cMode = pArg->mode;
24925 if( pArg->autoExplain ){
24926 if( bIsExplain ){
24927 pArg->cMode = MODE_Explain;
24928 }
24929 if( sqlite3_stmt_isexplain(pStmt)==2 ){
24930 pArg->cMode = MODE_EQP;
24931 }
24932 }
24933
24934 /* If the shell is currently in ".explain" mode, gather the extra
24935 ** data required to add indents to the output.*/
24936 if( pArg->cMode==MODE_Explain && bIsExplain ){
24937 explain_data_prepare(pArg, pStmt);
24938 }
24939 }
24940
24941 bind_prepared_stmt(pArg, pStmt);
24942 exec_prepared_stmt(pArg, pStmt);
24943 explain_data_delete(pArg);
24944 eqp_render(pArg, 0);
24945
24946 /* print usage stats if stats on */
24947 if( pArg && pArg->statsOn ){
24948 display_stats(db, pArg, 0);
24949 }
24950
24951 /* print loop-counters if required */
24952 if( pArg && pArg->scanstatsOn ){
24953 display_scanstats(db, pArg);
24954 }
24955
24956 /* Finalize the statement just executed. If this fails, save a
24957 ** copy of the error message. Otherwise, set zSql to point to the
24958 ** next statement to execute. */
24959 rc2 = sqlite3_finalize(pStmt);
24960 if( rc!=SQLITE_NOMEM ) rc = rc2;
24961 if( rc==SQLITE_OK ){
24962 zSql = zLeftover;
24963 while( IsSpace(zSql[0]) ) zSql++;
24964 }else if( pzErrMsg ){
24965 *pzErrMsg = save_err_msg(db, "stepping", rc, 0);
24966 }
24967
24968 /* clear saved stmt handle */
24969 if( pArg ){
24970 pArg->pStmt = NULL;
24971 }
24972 }
24973 } /* end while */
24974
static char * save_err_msg(sqlite3 *db, const char *zPhase, int rc, const char *zSql)
Definition shell.c:23508
static void display_scanstats(sqlite3 *db, ShellState *pArg)
Definition shell.c:23970
static void eqp_render(ShellState *p, i64 nCycle)
Definition shell.c:22795
static void restore_debug_trace_modes(void)
Definition shell.c:24025
static void disable_debug_trace_modes(void)
Definition shell.c:24018
static int expertHandleSQL(ShellState *pState, const char *zSql, char **pzErr)
Definition shell.c:24697
#define sqlite3_stmt_explain
Definition sqlite3ext.h:700
#define sqlite3_stmt_isexplain
Definition sqlite3ext.h:661

References ShellState::autoEQP, AUTOEQP_full, AUTOEQP_trigger, ShellState::autoExplain, bind_prepared_stmt(), ShellState::cMode, ShellState::cnt, ShellState::db, disable_debug_trace_modes(), display_scanstats(), display_stats(), eqp_append(), eqp_render(), exec_prepared_stmt(), ShellState::expert, expertFinish(), expertHandleSQL(), explain_data_delete(), explain_data_prepare(), IsSpace, ShellState::mode, MODE_EQP, MODE_Explain, ExpertInfo::pExpert, ShellState::pStmt, restore_debug_trace_modes(), save_err_msg(), ShellState::scanstatsOn, sqlite3_column_int, sqlite3_column_text, sqlite3_db_config, sqlite3_finalize, sqlite3_prepare_v2, sqlite3_reset, sqlite3_sql, sqlite3_step, sqlite3_stmt_explain, sqlite3_stmt_isexplain, SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_NOMEM, SQLITE_OK, SQLITE_ROW, and ShellState::statsOn.

Referenced by do_meta_command(), dump_callback(), main(), and runOneSqlLine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shell_out_of_memory()

void shell_out_of_memory ( void )
static
969 {
970 eputz("Error: out of memory\n");
971 exit(1);
972}

References eputz.

Referenced by do_meta_command(), exec_prepared_stmt(), and shell_check_oom().

Here is the caller graph for this function:

◆ shell_strcpy()

void shell_strcpy ( char * dest,
const char * src )
static
878 {
879 while( (*(dest++) = *(src++))!=0 ){}
880}

Referenced by dynamicContinuePrompt().

Here is the caller graph for this function:

◆ shell_strncpy()

char * shell_strncpy ( char * dest,
const char * src,
size_t n )
static
867 {
868 size_t i;
869 for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i];
870 dest[i] = 0;
871 return dest;
872}

Referenced by do_meta_command(), and dynamicContinuePrompt().

Here is the caller graph for this function:

◆ shellAddSchemaName()

void shellAddSchemaName ( sqlite3_context * pCtx,
int nVal,
sqlite3_value ** apVal )
static
1650 {
1651 static const char *aPrefix[] = {
1652 "TABLE",
1653 "INDEX",
1654 "UNIQUE INDEX",
1655 "VIEW",
1656 "TRIGGER",
1657 "VIRTUAL TABLE"
1658 };
1659 int i = 0;
1660 const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
1661 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
1662 const char *zName = (const char*)sqlite3_value_text(apVal[2]);
1664 UNUSED_PARAMETER(nVal);
1665 if( zIn!=0 && cli_strncmp(zIn, "CREATE ", 7)==0 ){
1666 for(i=0; i<ArraySize(aPrefix); i++){
1667 int n = strlen30(aPrefix[i]);
1668 if( cli_strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
1669 char *z = 0;
1670 char *zFake = 0;
1671 if( zSchema ){
1672 char cQuote = quoteChar(zSchema);
1673 if( cQuote && sqlite3_stricmp(zSchema,"temp")!=0 ){
1674 z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
1675 }else{
1676 z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
1677 }
1678 }
1679 if( zName
1680 && aPrefix[i][0]=='V'
1681 && (zFake = shellFakeSchema(db, zSchema, zName))!=0
1682 ){
1683 if( z==0 ){
1684 z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
1685 }else{
1686 z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
1687 }
1688 free(zFake);
1689 }
1690 if( z ){
1691 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
1692 return;
1693 }
1694 }
1695 }
1696 }
1697 sqlite3_result_value(pCtx, apVal[0]);
1698}
static char * shellFakeSchema(sqlite3 *db, const char *zSchema, const char *zName)
Definition shell.c:1544
static const char aPrefix[]
Definition sqlite3.c:31716

References aPrefix, ArraySize, cli_strncmp(), quoteChar(), shellFakeSchema(), sqlite3_context_db_handle, sqlite3_free, sqlite3_mprintf, sqlite3_result_text, sqlite3_result_value, sqlite3_stricmp, sqlite3_value_text, strlen30(), and UNUSED_PARAMETER.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shellAuth()

int shellAuth ( void * pClientData,
int op,
const char * zA1,
const char * zA2,
const char * zA3,
const char * zA4 )
static
22631 {
22632 ShellState *p = (ShellState*)pClientData;
22633 static const char *azAction[] = { 0,
22634 "CREATE_INDEX", "CREATE_TABLE", "CREATE_TEMP_INDEX",
22635 "CREATE_TEMP_TABLE", "CREATE_TEMP_TRIGGER", "CREATE_TEMP_VIEW",
22636 "CREATE_TRIGGER", "CREATE_VIEW", "DELETE",
22637 "DROP_INDEX", "DROP_TABLE", "DROP_TEMP_INDEX",
22638 "DROP_TEMP_TABLE", "DROP_TEMP_TRIGGER", "DROP_TEMP_VIEW",
22639 "DROP_TRIGGER", "DROP_VIEW", "INSERT",
22640 "PRAGMA", "READ", "SELECT",
22641 "TRANSACTION", "UPDATE", "ATTACH",
22642 "DETACH", "ALTER_TABLE", "REINDEX",
22643 "ANALYZE", "CREATE_VTABLE", "DROP_VTABLE",
22644 "FUNCTION", "SAVEPOINT", "RECURSIVE"
22645 };
22646 int i;
22647 const char *az[4];
22648 az[0] = zA1;
22649 az[1] = zA2;
22650 az[2] = zA3;
22651 az[3] = zA4;
22652 sqlite3_fprintf(p->out, "authorizer: %s", azAction[op]);
22653 for(i=0; i<4; i++){
22654 sqlite3_fputs(" ", p->out);
22655 if( az[i] ){
22656 output_c_string(p->out, az[i]);
22657 }else{
22658 sqlite3_fputs("NULL", p->out);
22659 }
22660 }
22661 sqlite3_fputs("\n", p->out);
22662 if( p->bSafeMode ) (void)safeModeAuth(pClientData, op, zA1, zA2, zA3, zA4);

References ShellState::bSafeMode, ShellState::out, output_c_string(), safeModeAuth(), sqlite3_fprintf, sqlite3_fputs, and SQLITE_OK.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shellDatabaseError()

int shellDatabaseError ( sqlite3 * db)
static
27142 {

References shellEmitError(), and sqlite3_errmsg.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shellDeleteFile()

int shellDeleteFile ( const char * zFilename)
27259 {
27260 int rc;
27261#ifdef _WIN32
27262 wchar_t *z = sqlite3_win32_utf8_to_unicode(zFilename);
27263 rc = _wunlink(z);
27264 sqlite3_free(z);
27265#else
27266 rc = unlink(zFilename);
27267#endif

References sqlite3_free.

Referenced by clearTempFile(), and do_meta_command().

Here is the caller graph for this function:

◆ shellDtostr()

void shellDtostr ( sqlite3_context * pCtx,
int nVal,
sqlite3_value ** apVal )
static
1617 {
1618 double r = sqlite3_value_double(apVal[0]);
1619 int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26;
1620 char z[400];
1621 if( n<1 ) n = 1;
1622 if( n>350 ) n = 350;
1623 sqlite3_snprintf(sizeof(z), z, "%#+.*e", n, r);
1625}

References sqlite3_result_text, sqlite3_snprintf, sqlite3_value_double, sqlite3_value_int, and SQLITE_TRANSIENT.

Referenced by open_db().

Here is the caller graph for this function:

◆ shellEmitError()

void shellEmitError ( const char * zErr)
static
27136 {

References sqlite3_fprintf.

Referenced by do_meta_command(), main(), and shellDatabaseError().

Here is the caller graph for this function:

◆ shellFakeSchema()

char * shellFakeSchema ( sqlite3 * db,
const char * zSchema,
const char * zName )
static
1548 {
1549 sqlite3_stmt *pStmt = 0;
1550 char *zSql;
1551 ShellText s;
1552 char cQuote;
1553 char *zDiv = "(";
1554 int nRow = 0;
1555
1556 zSql = sqlite3_mprintf("PRAGMA \"%w\".table_info=%Q;",
1557 zSchema ? zSchema : "main", zName);
1558 shell_check_oom(zSql);
1559 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
1560 sqlite3_free(zSql);
1561 initText(&s);
1562 if( zSchema ){
1563 cQuote = quoteChar(zSchema);
1564 if( cQuote && sqlite3_stricmp(zSchema,"temp")==0 ) cQuote = 0;
1565 appendText(&s, zSchema, cQuote);
1566 appendText(&s, ".", 0);
1567 }
1568 cQuote = quoteChar(zName);
1569 appendText(&s, zName, cQuote);
1570 while( sqlite3_step(pStmt)==SQLITE_ROW ){
1571 const char *zCol = (const char*)sqlite3_column_text(pStmt, 1);
1572 nRow++;
1573 appendText(&s, zDiv, 0);
1574 zDiv = ",";
1575 if( zCol==0 ) zCol = "";
1576 cQuote = quoteChar(zCol);
1577 appendText(&s, zCol, cQuote);
1578 }
1579 appendText(&s, ")", 0);
1580 sqlite3_finalize(pStmt);
1581 if( nRow==0 ){
1582 freeText(&s);
1583 s.z = 0;
1584 }
1585 return s.z;
1586}

References appendText(), freeText(), initText(), quoteChar(), shell_check_oom(), sqlite3_column_text, sqlite3_finalize, sqlite3_free, sqlite3_mprintf, sqlite3_prepare_v2, sqlite3_step, sqlite3_stricmp, SQLITE_ROW, and ShellText::z.

Referenced by shellAddSchemaName(), and shellModuleSchema().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shellFinalize()

void shellFinalize ( int * pRc,
sqlite3_stmt * pStmt )
static
27614 {
27615 if( pStmt ){
27616 sqlite3 *db = sqlite3_db_handle(pStmt);
27617 int rc = sqlite3_finalize(pStmt);
27618 if( *pRc==SQLITE_OK ){
27619 if( rc!=SQLITE_OK ){
27620 sqlite3_fprintf(stderr,"SQL error: %s\n", sqlite3_errmsg(db));
27621 }
27622 *pRc = rc;
27623 }
#define sqlite3_db_handle
Definition sqlite3ext.h:447

References sqlite3_db_handle, sqlite3_errmsg, sqlite3_finalize, sqlite3_fprintf, and SQLITE_OK.

Referenced by doAutoDetectRestore(), and outputDumpWarning().

Here is the caller graph for this function:

◆ shellFkeyCollateClause()

void shellFkeyCollateClause ( sqlite3_context * pCtx,
int nVal,
sqlite3_value ** apVal )
static
27335 {
27337 const char *zParent;
27338 const char *zParentCol;
27339 const char *zParentSeq;
27340 const char *zChild;
27341 const char *zChildCol;
27342 const char *zChildSeq = 0; /* Initialize to avoid false-positive warning */
27343 int rc;
27344
27345 assert( nVal==4 );
27346 zParent = (const char*)sqlite3_value_text(apVal[0]);
27347 zParentCol = (const char*)sqlite3_value_text(apVal[1]);
27348 zChild = (const char*)sqlite3_value_text(apVal[2]);
27349 zChildCol = (const char*)sqlite3_value_text(apVal[3]);
27350
27351 sqlite3_result_text(pCtx, "", -1, SQLITE_STATIC);
27353 db, "main", zParent, zParentCol, 0, &zParentSeq, 0, 0, 0
27354 );
27355 if( rc==SQLITE_OK ){
27357 db, "main", zChild, zChildCol, 0, &zChildSeq, 0, 0, 0
27358 );
27359 }
27360
27361 if( rc==SQLITE_OK && sqlite3_stricmp(zParentSeq, zChildSeq) ){
27362 char *z = sqlite3_mprintf(" COLLATE %s", zParentSeq);
27364 sqlite3_free(z);

References sqlite3_context_db_handle, sqlite3_free, sqlite3_mprintf, sqlite3_result_text, sqlite3_stricmp, sqlite3_table_column_metadata, sqlite3_value_text, SQLITE_OK, SQLITE_STATIC, and SQLITE_TRANSIENT.

Referenced by lintFkeyIndexes().

Here is the caller graph for this function:

◆ shellLog()

void shellLog ( void * pArg,
int iErrCode,
const char * zMsg )
static
21887 {
21888 ShellState *p = (ShellState*)pArg;
21889 if( p->pLog==0 ) return;
21890 sqlite3_fprintf(p->pLog, "(%d) %s\n", iErrCode, zMsg);

References ShellState::pLog, and sqlite3_fprintf.

Referenced by main_init().

Here is the caller graph for this function:

◆ shellModuleSchema()

void shellModuleSchema ( sqlite3_context * pCtx,
int nVal,
sqlite3_value ** apVal )
static
25937 {
25938 const char *zName;
25939 char *zFake;
25941 FILE *pSavedLog = p->pLog;
25942 UNUSED_PARAMETER(nVal);
25943 zName = (const char*)sqlite3_value_text(apVal[0]);
25944
25945 /* Temporarily disable the ".log" when calling shellFakeSchema() because
25946 ** shellFakeSchema() might generate failures for some ephemeral virtual
25947 ** tables due to missing arguments. Example: fts4aux.
25948 ** https://sqlite.org/forum/forumpost/42fe6520b803be51 */
25949 p->pLog = 0;
25950 zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
25951 p->pLog = pSavedLog;
25952
25953 if( zFake ){
25954 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
25955 -1, sqlite3_free);
25956 free(zFake);

References ShellState::pLog, shellFakeSchema(), sqlite3_context_db_handle, sqlite3_free, sqlite3_mprintf, sqlite3_result_text, sqlite3_user_data, sqlite3_value_text, and UNUSED_PARAMETER.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shellPrepare()

void shellPrepare ( sqlite3 * db,
int * pRc,
const char * zSql,
sqlite3_stmt ** ppStmt )
static
27570 {
27571 *ppStmt = 0;
27572 if( *pRc==SQLITE_OK ){
27573 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
27574 if( rc!=SQLITE_OK ){
27575 sqlite3_fprintf(stderr,
27576 "sql error: %s (%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db));
27577 *pRc = rc;
27578 }

Referenced by doAutoDetectRestore(), and shellPreparePrintf().

Here is the caller graph for this function:

◆ shellPreparePrintf()

void shellPreparePrintf ( sqlite3 * db,
int * pRc,
sqlite3_stmt ** ppStmt,
const char * zFmt,
... )
static
27591 {
27592 *ppStmt = 0;
27593 if( *pRc==SQLITE_OK ){
27594 va_list ap;
27595 char *z;
27596 va_start(ap, zFmt);
27597 z = sqlite3_vmprintf(zFmt, ap);
27598 va_end(ap);
27599 if( z==0 ){
27600 *pRc = SQLITE_NOMEM;
27601 }else{
27602 shellPrepare(db, pRc, z, ppStmt);
27603 sqlite3_free(z);
27604 }

References shellPrepare(), sqlite3_free, sqlite3_vmprintf, SQLITE_NOMEM, and SQLITE_OK.

Referenced by outputDumpWarning().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shellPutsFunc()

void shellPutsFunc ( sqlite3_context * pCtx,
int nVal,
sqlite3_value ** apVal )
static
21904 {
21906 (void)nVal;
21907 sqlite3_fprintf(p->out, "%s\n", sqlite3_value_text(apVal[0]));

References ShellState::out, sqlite3_fprintf, sqlite3_result_value, sqlite3_user_data, and sqlite3_value_text.

Referenced by open_db().

Here is the caller graph for this function:

◆ shellReset()

void shellReset ( int * pRc,
sqlite3_stmt * pStmt )
27637 {
27638 int rc = sqlite3_reset(pStmt);
27639 if( *pRc==SQLITE_OK ){
27640 if( rc!=SQLITE_OK ){
27641 sqlite3 *db = sqlite3_db_handle(pStmt);
27642 sqlite3_fprintf(stderr,"SQL error: %s\n", sqlite3_errmsg(db));
27643 }
27644 *pRc = rc;

References sqlite3_db_handle, sqlite3_errmsg, sqlite3_fprintf, sqlite3_reset, and SQLITE_OK.

◆ shellStrtod()

void shellStrtod ( sqlite3_context * pCtx,
int nVal,
sqlite3_value ** apVal )
static
1599 {
1600 char *z = (char*)sqlite3_value_text(apVal[0]);
1601 UNUSED_PARAMETER(nVal);
1602 if( z==0 ) return;
1603 sqlite3_result_double(pCtx, strtod(z,0));
1604}

References sqlite3_result_double, sqlite3_value_text, and UNUSED_PARAMETER.

Referenced by open_db().

Here is the caller graph for this function:

◆ shellUSleepFunc()

void shellUSleepFunc ( sqlite3_context * context,
int argcUnused,
sqlite3_value ** argv )
static
25920 {
25921 int sleep = sqlite3_value_int(argv[0]);
25922 (void)argcUnused;
25923 sqlite3_sleep(sleep/1000);

References sqlite3_result_int, sqlite3_sleep, and sqlite3_value_int.

Referenced by open_db().

Here is the caller graph for this function:

◆ showHelp()

int showHelp ( FILE * out,
const char * zPattern )
static
25603 {
25604 int i = 0;
25605 int j = 0;
25606 int n = 0;
25607 char *zPat;
25608 if( zPattern==0 ){
25609 /* Show just the first line for all help topics */
25610 zPattern = "[a-z]";
25611 }else if( cli_strcmp(zPattern,"-a")==0
25612 || cli_strcmp(zPattern,"-all")==0
25613 || cli_strcmp(zPattern,"--all")==0
25614 ){
25615 /* Show everything except undocumented commands */
25616 zPattern = ".";
25617 }else if( cli_strcmp(zPattern,"0")==0 ){
25618 /* Show complete help text of undocumented commands */
25619 int show = 0;
25620 for(i=0; i<ArraySize(azHelp); i++){
25621 if( azHelp[i][0]=='.' ){
25622 show = 0;
25623 }else if( azHelp[i][0]==',' ){
25624 show = 1;
25625 sqlite3_fprintf(out, ".%s\n", &azHelp[i][1]);
25626 n++;
25627 }else if( show ){
25628 sqlite3_fprintf(out, "%s\n", azHelp[i]);
25629 }
25630 }
25631 return n;
25632 }
25633
25634 /* Seek documented commands for which zPattern is an exact prefix */
25635 zPat = sqlite3_mprintf(".%s*", zPattern);
25636 shell_check_oom(zPat);
25637 for(i=0; i<ArraySize(azHelp); i++){
25638 if( sqlite3_strglob(zPat, azHelp[i])==0 ){
25639 sqlite3_fprintf(out, "%s\n", azHelp[i]);
25640 j = i+1;
25641 n++;
25642 }
25643 }
25644 sqlite3_free(zPat);
25645 if( n ){
25646 if( n==1 ){
25647 /* when zPattern is a prefix of exactly one command, then include
25648 ** the details of that command, which should begin at offset j */
25649 while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){
25650 sqlite3_fprintf(out, "%s\n", azHelp[j]);
25651 j++;
25652 }
25653 }
25654 return n;
25655 }
25656
25657 /* Look for documented commands that contain zPattern anywhere.
25658 ** Show complete text of all documented commands that match. */
25659 zPat = sqlite3_mprintf("%%%s%%", zPattern);
25660 shell_check_oom(zPat);
25661 for(i=0; i<ArraySize(azHelp); i++){
25662 if( azHelp[i][0]==',' ){
25663 while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i;
25664 continue;
25665 }
25666 if( azHelp[i][0]=='.' ) j = i;
25667 if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){
25668 sqlite3_fprintf(out, "%s\n", azHelp[j]);
25669 while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){
25670 j++;
25671 sqlite3_fprintf(out, "%s\n", azHelp[j]);
25672 }
25673 i = j;
25674 n++;
25675 }
25676 }
25677 sqlite3_free(zPat);
static const char * azHelp[]
Definition shell.c:25276

References ArraySize, azHelp, cli_strcmp(), shell_check_oom(), sqlite3_fprintf, sqlite3_free, sqlite3_mprintf, sqlite3_strglob, and sqlite3_strlike.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ skipNonB64()

char * skipNonB64 ( char * s,
int nc )
static
5244 {
5245 char c;
5246 while( nc-- > 0 && (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
5247 return s;
5248}
#define IS_BX_DIGIT(bdp)
Definition shell.c:5197

References BX_DV_PROTO, c, and IS_BX_DIGIT.

Referenced by fromBase64().

Here is the caller graph for this function:

◆ skipNonB85()

char * skipNonB85 ( char * s,
int nc )
static
5537 {
5538 char c;
5539 while( nc-- > 0 && (c = *s) && !IS_B85(c) ) ++s;
5540 return s;
5541}
#define IS_B85(c)
Definition shell.c:5523

References c, and IS_B85.

Referenced by fromBase85().

Here is the caller graph for this function:

◆ sql_trace_callback()

int sql_trace_callback ( unsigned mType,
void * pArg,
void * pP,
void * pX )
static
26392 {
26393 ShellState *p = (ShellState*)pArg;
26394 sqlite3_stmt *pStmt;
26395 const char *zSql;
26396 i64 nSql;
26397 if( p->traceOut==0 ) return 0;
26398 if( mType==SQLITE_TRACE_CLOSE ){
26399 sputz(p->traceOut, "-- closing database connection\n");
26400 return 0;
26401 }
26402 if( mType!=SQLITE_TRACE_ROW && pX!=0 && ((const char*)pX)[0]=='-' ){
26403 zSql = (const char*)pX;
26404 }else{
26405 pStmt = (sqlite3_stmt*)pP;
26406 switch( p->eTraceType ){
26407 case SHELL_TRACE_EXPANDED: {
26408 zSql = sqlite3_expanded_sql(pStmt);
26409 break;
26410 }
26411#ifdef SQLITE_ENABLE_NORMALIZE
26413 zSql = sqlite3_normalized_sql(pStmt);
26414 break;
26415 }
26416#endif
26417 default: {
26418 zSql = sqlite3_sql(pStmt);
26419 break;
26420 }
26421 }
26422 }
26423 if( zSql==0 ) return 0;
26424 nSql = strlen(zSql);
26425 if( nSql>1000000000 ) nSql = 1000000000;
26426 while( nSql>0 && zSql[nSql-1]==';' ){ nSql--; }
26427 switch( mType ){
26428 case SQLITE_TRACE_ROW:
26429 case SQLITE_TRACE_STMT: {
26430 sqlite3_fprintf(p->traceOut, "%.*s;\n", (int)nSql, zSql);
26431 break;
26432 }
26433 case SQLITE_TRACE_PROFILE: {
26434 sqlite3_int64 nNanosec = pX ? *(sqlite3_int64*)pX : 0;
26436 "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec);
26437 break;
26438 }
26439 }
#define sqlite3_expanded_sql
Definition sqlite3ext.h:628
#define sqlite3_normalized_sql
Definition sqlite3ext.h:659

References ShellState::eTraceType, SHELL_TRACE_EXPANDED, SHELL_TRACE_NORMALIZED, sputz, sqlite3_expanded_sql, sqlite3_fprintf, sqlite3_normalized_sql, sqlite3_sql, SQLITE_TRACE_CLOSE, SQLITE_TRACE_PROFILE, SQLITE_TRACE_ROW, SQLITE_TRACE_STMT, and ShellState::traceOut.

Referenced by do_meta_command().

Here is the caller graph for this function:

◆ sqlite3_appendvfs_init()

int sqlite3_appendvfs_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
10181 {
10182 int rc = SQLITE_OK;
10183 sqlite3_vfs *pOrig;
10185 (void)pzErrMsg;
10186 (void)db;
10187 pOrig = sqlite3_vfs_find(0);
10188 if( pOrig==0 ) return SQLITE_ERROR;
10189 apnd_vfs.iVersion = pOrig->iVersion;
10190 apnd_vfs.pAppData = pOrig;
10191 apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
10193#ifdef APPENDVFS_TEST
10194 if( rc==SQLITE_OK ){
10195 rc = sqlite3_auto_extension((void(*)(void))apndvfsRegister);
10196 }
10197#endif
10199 return rc;
10200}
static sqlite3_vfs apnd_vfs
Definition shell.c:9705
#define SQLITE_EXTENSION_INIT2(X)
Definition shell.c:1707
#define sqlite3_auto_extension
Definition sqlite3ext.h:600

References apnd_vfs, sqlite3_vfs::iVersion, sqlite3_auto_extension, sqlite3_vfs_find, sqlite3_vfs_register, SQLITE_ERROR, SQLITE_EXTENSION_INIT2, SQLITE_OK, SQLITE_OK_LOAD_PERMANENTLY, and sqlite3_vfs::szOsFile.

Referenced by main().

Here is the caller graph for this function:

◆ sqlite3_base64_init()

int sqlite3_base64_init ( sqlite3 * db,
char ** pzErr,
const sqlite3_api_routines * pApi )
5373 {
5375 (void)pzErr;
5377 (db, "base64", 1,
5379 0, base64, 0, 0);
5380}
static void base64(sqlite3_context *context, int na, sqlite3_value *av[])
Definition shell.c:5302
#define SQLITE_INNOCUOUS
Definition sqlite3.c:6147

References base64(), sqlite3_base64_init(), sqlite3_base_init, sqlite3_create_function, SQLITE_DETERMINISTIC, SQLITE_DIRECTONLY, SQLITE_EXTENSION_INIT2, SQLITE_INNOCUOUS, and SQLITE_UTF8.

Referenced by open_db(), and sqlite3_base64_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_base85_init()

int sqlite3_base85_init ( sqlite3 * db,
char ** pzErr,
const sqlite3_api_routines * pApi )
5753 {
5755 (void)pzErr;
5756# ifndef OMIT_BASE85_CHECKER
5757 {
5759 (db, "is_base85", 1,
5761 0, is_base85, 0, 0);
5762 if( rc!=SQLITE_OK ) return rc;
5763 }
5764# endif
5766 (db, "base85", 1,
5768 0, base85, 0, 0);
5769}
static void base85(sqlite3_context *context, int na, sqlite3_value *av[])
Definition shell.c:5682

References base85(), sqlite3_base85_init(), sqlite3_base_init, sqlite3_create_function, SQLITE_DETERMINISTIC, SQLITE_DIRECTONLY, SQLITE_EXTENSION_INIT2, SQLITE_INNOCUOUS, SQLITE_OK, and SQLITE_UTF8.

Referenced by open_db(), and sqlite3_base85_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_completion_init()

int sqlite3_completion_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
9517 {
9518 int rc = SQLITE_OK;
9520 (void)(pzErrMsg); /* Unused parameter */
9521#ifndef SQLITE_OMIT_VIRTUALTABLE
9523#endif
9524 return rc;
9525}
int sqlite3CompletionVtabInit(sqlite3 *db)
Definition shell.c:9502

References sqlite3CompletionVtabInit(), SQLITE_EXTENSION_INIT2, and SQLITE_OK.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_decimal_init()

int sqlite3_decimal_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
4545 {
4546 int rc = SQLITE_OK;
4547 static const struct {
4548 const char *zFuncName;
4549 int nArg;
4550 int iArg;
4551 void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
4552 } aFunc[] = {
4553 { "decimal", 1, 0, decimalFunc },
4554 { "decimal_exp", 1, 1, decimalFunc },
4555 { "decimal_cmp", 2, 0, decimalCmpFunc },
4556 { "decimal_add", 2, 0, decimalAddFunc },
4557 { "decimal_sub", 2, 0, decimalSubFunc },
4558 { "decimal_mul", 2, 0, decimalMulFunc },
4559 { "decimal_pow2", 1, 0, decimalPow2Func },
4560 };
4561 unsigned int i;
4562 (void)pzErrMsg; /* Unused parameter */
4563
4565
4566 for(i=0; i<(int)(sizeof(aFunc)/sizeof(aFunc[0])) && rc==SQLITE_OK; i++){
4567 rc = sqlite3_create_function(db, aFunc[i].zFuncName, aFunc[i].nArg,
4569 aFunc[i].iArg ? db : 0, aFunc[i].xFunc, 0, 0);
4570 }
4571 if( rc==SQLITE_OK ){
4572 rc = sqlite3_create_window_function(db, "decimal_sum", 1,
4576 }
4577 if( rc==SQLITE_OK ){
4578 rc = sqlite3_create_collation(db, "decimal", SQLITE_UTF8,
4579 0, decimalCollFunc);
4580 }
4581 return rc;
4582}
static void decimalSumInverse(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:4463
static void decimalSumValue(sqlite3_context *context)
Definition shell.c:4479
static void decimalPow2Func(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:4525
static void decimalSumStep(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:4437
static void decimalAddFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:4402
static void decimalSumFinalize(sqlite3_context *context)
Definition shell.c:4484
static int decimalCollFunc(void *notUsed, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
Definition shell.c:4374
static void decimalSubFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:4415
static void decimalFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:4354
static void decimalCmpFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:4085
static void decimalMulFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:4496
Definition sqlite3.c:23970
#define sqlite3_create_collation
Definition sqlite3ext.h:440

References decimalAddFunc(), decimalCmpFunc(), decimalCollFunc(), decimalFunc(), decimalMulFunc(), decimalPow2Func(), decimalSubFunc(), decimalSumFinalize(), decimalSumInverse(), decimalSumStep(), decimalSumValue(), sqlite3_create_collation, sqlite3_create_function, sqlite3_create_window_function, SQLITE_DETERMINISTIC, SQLITE_EXTENSION_INIT2, SQLITE_INNOCUOUS, SQLITE_OK, and SQLITE_UTF8.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_expert_analyze()

int sqlite3_expert_analyze ( sqlite3expert * p,
char ** pzErr )
14895 {
14896 int rc;
14897 IdxHashEntry *pEntry;
14898
14899 /* Do trigger processing to collect any extra IdxScan structures */
14900 rc = idxProcessTriggers(p, pzErr);
14901
14902 /* Create candidate indexes within the in-memory database file */
14903 if( rc==SQLITE_OK ){
14904 rc = idxCreateCandidates(p);
14905 }else if ( rc==SQLITE_BUSY_TIMEOUT ){
14906 if( pzErr )
14907 *pzErr = sqlite3_mprintf("Cannot find a unique index name to propose.");
14908 return rc;
14909 }
14910
14911 /* Generate the stat1 data */
14912 if( rc==SQLITE_OK ){
14913 rc = idxPopulateStat1(p, pzErr);
14914 }
14915
14916 /* Formulate the EXPERT_REPORT_CANDIDATES text */
14917 for(pEntry=p->hIdx.pFirst; pEntry; pEntry=pEntry->pNext){
14919 "%s;%s%s\n", pEntry->zVal,
14920 pEntry->zVal2 ? " -- stat1: " : "", pEntry->zVal2
14921 );
14922 }
14923
14924 /* Figure out which of the candidate indexes are preferred by the query
14925 ** planner and report the results to the user. */
14926 if( rc==SQLITE_OK ){
14927 rc = idxFindIndexes(p, pzErr);
14928 }
14929
14930 if( rc==SQLITE_OK ){
14931 p->bRun = 1;
14932 }
14933 return rc;
14934}
static int idxFindIndexes(sqlite3expert *p, char **pzErr)
Definition shell.c:13942
static int idxPopulateStat1(sqlite3expert *p, char **pzErr)
Definition shell.c:14556
static int idxCreateCandidates(sqlite3expert *p)
Definition shell.c:13853
int bRun
Definition shell.c:12918
static int idxProcessTriggers(sqlite3expert *p, char **pzErr)
Definition shell.c:14133
char * zCandidates
Definition shell.c:12922

References sqlite3expert::bRun, sqlite3expert::hIdx, idxAppendText(), idxCreateCandidates(), idxFindIndexes(), idxPopulateStat1(), idxProcessTriggers(), IdxHash::pFirst, IdxHashEntry::pNext, sqlite3_mprintf, SQLITE_BUSY_TIMEOUT, SQLITE_OK, sqlite3expert::zCandidates, IdxHashEntry::zVal, and IdxHashEntry::zVal2.

Referenced by expertFinish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_expert_config()

int sqlite3_expert_config ( sqlite3expert * p,
int op,
... )
14822 {
14823 int rc = SQLITE_OK;
14824 va_list ap;
14825 va_start(ap, op);
14826 switch( op ){
14827 case EXPERT_CONFIG_SAMPLE: {
14828 int iVal = va_arg(ap, int);
14829 if( iVal<0 ) iVal = 0;
14830 if( iVal>100 ) iVal = 100;
14831 p->iSample = iVal;
14832 break;
14833 }
14834 default:
14835 rc = SQLITE_NOTFOUND;
14836 break;
14837 }
14838
14839 va_end(ap);
14840 return rc;
14841}

References EXPERT_CONFIG_SAMPLE, sqlite3expert::iSample, SQLITE_NOTFOUND, and SQLITE_OK.

Referenced by expertDotCommand().

Here is the caller graph for this function:

◆ sqlite3_expert_count()

int sqlite3_expert_count ( sqlite3expert * p)
14940 {
14941 int nRet = 0;
14942 if( p->pStatement ) nRet = p->pStatement->iId+1;
14943 return nRet;
14944}
int iId
Definition shell.c:12874

References IdxStatement::iId, and sqlite3expert::pStatement.

Referenced by expertFinish().

Here is the caller graph for this function:

◆ sqlite3_expert_destroy()

void sqlite3_expert_destroy ( sqlite3expert * p)
14975 {
14976 if( p ){
14977 sqlite3_close(p->dbm);
14978 sqlite3_close(p->dbv);
14979 idxScanFree(p->pScan, 0);
14981 idxTableFree(p->pTable);
14982 idxWriteFree(p->pWrite);
14983 idxHashClear(&p->hIdx);
14985 sqlite3_free(p);
14986 }
14987}
static void idxStatementFree(IdxStatement *pStatement, IdxStatement *pLast)
Definition shell.c:13900
static void idxTableFree(IdxTable *pTab)
Definition shell.c:13914
static void idxScanFree(IdxScan *pScan, IdxScan *pLast)
Definition shell.c:13884
static void idxWriteFree(IdxWrite *pTab)
Definition shell.c:13926

References sqlite3expert::dbm, sqlite3expert::dbv, sqlite3expert::hIdx, idxHashClear(), idxScanFree(), idxStatementFree(), idxTableFree(), idxWriteFree(), sqlite3expert::pScan, sqlite3expert::pStatement, sqlite3expert::pTable, sqlite3expert::pWrite, sqlite3_close, sqlite3_free, and sqlite3expert::zCandidates.

Referenced by expertFinish(), and sqlite3_expert_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_expert_new()

sqlite3expert * sqlite3_expert_new ( sqlite3 * db,
char ** pzErr )
14741 {
14742 int rc = SQLITE_OK;
14743 sqlite3expert *pNew;
14744
14745 pNew = (sqlite3expert*)idxMalloc(&rc, sizeof(sqlite3expert));
14746
14747 /* Open two in-memory databases to work with. The "vtab database" (dbv)
14748 ** will contain a virtual table corresponding to each real table in
14749 ** the user database schema, and a copy of each view. It is used to
14750 ** collect information regarding the WHERE, ORDER BY and other clauses
14751 ** of the user's query.
14752 */
14753 if( rc==SQLITE_OK ){
14754 pNew->db = db;
14755 pNew->iSample = 100;
14756 rc = sqlite3_open(":memory:", &pNew->dbv);
14757 }
14758 if( rc==SQLITE_OK ){
14759 rc = sqlite3_open(":memory:", &pNew->dbm);
14760 if( rc==SQLITE_OK ){
14762 }
14763 }
14764
14765 /* Allow custom collations to be dealt with through prepare. */
14766 if( rc==SQLITE_OK ) rc = sqlite3_collation_needed(pNew->dbm,0,useDummyCS);
14767 if( rc==SQLITE_OK ) rc = sqlite3_collation_needed(pNew->dbv,0,useDummyCS);
14768
14769#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) \
14770 && !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS)
14771 /* Register UDFs from database [db] with [dbm] and [dbv]. */
14772 if( rc==SQLITE_OK ){
14773 rc = registerUDFs(pNew->db, pNew->dbm);
14774 }
14775 if( rc==SQLITE_OK ){
14776 rc = registerUDFs(pNew->db, pNew->dbv);
14777 }
14778#endif
14779
14780 /* Copy the entire schema of database [db] into [dbm]. */
14781 if( rc==SQLITE_OK ){
14782 sqlite3_stmt *pSql = 0;
14783 rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
14784 "SELECT sql, name, substr(sql,1,14)=='create virtual' COLLATE nocase"
14785 " FROM sqlite_schema WHERE substr(name,1,7)!='sqlite_' COLLATE nocase"
14786 " ORDER BY 3 DESC, rowid"
14787 );
14788 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
14789 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
14790 const char *zName = (const char*)sqlite3_column_text(pSql, 1);
14791 int bExists = 0;
14792 rc = expertDbContainsObject(pNew->dbm, zName, &bExists);
14793 if( rc==SQLITE_OK && zSql && bExists==0 ){
14794 rc = expertSchemaSql(pNew->dbm, zSql, pzErrmsg);
14795 }
14796 }
14797 idxFinalize(&rc, pSql);
14798 }
14799
14800 /* Create the vtab schema */
14801 if( rc==SQLITE_OK ){
14802 rc = idxCreateVtabSchema(pNew, pzErrmsg);
14803 }
14804
14805 /* Register the auth callback with dbv */
14806 if( rc==SQLITE_OK ){
14807 sqlite3_set_authorizer(pNew->dbv, idxAuthCallback, (void*)pNew);
14808 }
14809
14810 /* If an error has occurred, free the new object and return NULL. Otherwise,
14811 ** return the new sqlite3expert handle. */
14812 if( rc!=SQLITE_OK ){
14814 pNew = 0;
14815 }
14816 return pNew;
14817}
void useDummyCS(void *up1, sqlite3 *db, int etr, const char *zName)
Definition shell.c:14670
static int idxAuthCallback(void *pCtx, int eOp, const char *z3, const char *z4, const char *zDb, const char *zTrigger)
Definition shell.c:14012
int registerUDFs(sqlite3 *dbSrc, sqlite3 *dbDst)
Definition shell.c:14694
static int idxCreateVtabSchema(sqlite3expert *p, char **pzErrmsg)
Definition shell.c:14211
#define sqlite3_collation_needed
Definition sqlite3ext.h:414

References sqlite3expert::db, sqlite3expert::dbm, sqlite3expert::dbv, expertDbContainsObject(), expertSchemaSql(), idxAuthCallback(), idxCreateVtabSchema(), idxFinalize(), idxMalloc(), idxPrintfPrepareStmt(), sqlite3expert::iSample, registerUDFs(), sqlite3_collation_needed, sqlite3_column_text, sqlite3_db_config, sqlite3_expert_destroy(), sqlite3_open, sqlite3_set_authorizer, sqlite3_step, SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_OK, SQLITE_ROW, and useDummyCS().

Referenced by expertDotCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_expert_report()

const char * sqlite3_expert_report ( sqlite3expert * p,
int iStmt,
int eReport )
14949 {
14950 const char *zRet = 0;
14951 IdxStatement *pStmt;
14952
14953 if( p->bRun==0 ) return 0;
14954 for(pStmt=p->pStatement; pStmt && pStmt->iId!=iStmt; pStmt=pStmt->pNext);
14955 switch( eReport ){
14956 case EXPERT_REPORT_SQL:
14957 if( pStmt ) zRet = pStmt->zSql;
14958 break;
14960 if( pStmt ) zRet = pStmt->zIdx;
14961 break;
14962 case EXPERT_REPORT_PLAN:
14963 if( pStmt ) zRet = pStmt->zEQP;
14964 break;
14966 zRet = p->zCandidates;
14967 break;
14968 }
14969 return zRet;
14970}

References sqlite3expert::bRun, EXPERT_REPORT_CANDIDATES, EXPERT_REPORT_INDEXES, EXPERT_REPORT_PLAN, EXPERT_REPORT_SQL, IdxStatement::iId, IdxStatement::pNext, sqlite3expert::pStatement, sqlite3expert::zCandidates, IdxStatement::zEQP, IdxStatement::zIdx, and IdxStatement::zSql.

Referenced by expertFinish().

Here is the caller graph for this function:

◆ sqlite3_expert_sql()

int sqlite3_expert_sql ( sqlite3expert * p,
const char * zSql,
char ** pzErr )
14850 {
14851 IdxScan *pScanOrig = p->pScan;
14852 IdxStatement *pStmtOrig = p->pStatement;
14853 int rc = SQLITE_OK;
14854 const char *zStmt = zSql;
14855
14856 if( p->bRun ) return SQLITE_MISUSE;
14857
14858 while( rc==SQLITE_OK && zStmt && zStmt[0] ){
14859 sqlite3_stmt *pStmt = 0;
14860 /* Ensure that the provided statement compiles against user's DB. */
14861 rc = idxPrepareStmt(p->db, &pStmt, pzErr, zStmt);
14862 if( rc!=SQLITE_OK ) break;
14863 sqlite3_finalize(pStmt);
14864 rc = sqlite3_prepare_v2(p->dbv, zStmt, -1, &pStmt, &zStmt);
14865 if( rc==SQLITE_OK ){
14866 if( pStmt ){
14867 IdxStatement *pNew;
14868 const char *z = sqlite3_sql(pStmt);
14869 int n = STRLEN(z);
14870 pNew = (IdxStatement*)idxMalloc(&rc, sizeof(IdxStatement) + n+1);
14871 if( rc==SQLITE_OK ){
14872 pNew->zSql = (char*)&pNew[1];
14873 memcpy(pNew->zSql, z, n+1);
14874 pNew->pNext = p->pStatement;
14875 if( p->pStatement ) pNew->iId = p->pStatement->iId+1;
14876 p->pStatement = pNew;
14877 }
14878 sqlite3_finalize(pStmt);
14879 }
14880 }else{
14881 idxDatabaseError(p->dbv, pzErr);
14882 }
14883 }
14884
14885 if( rc!=SQLITE_OK ){
14886 idxScanFree(p->pScan, pScanOrig);
14887 idxStatementFree(p->pStatement, pStmtOrig);
14888 p->pScan = pScanOrig;
14889 p->pStatement = pStmtOrig;
14890 }
14891
14892 return rc;
14893}
#define SQLITE_MISUSE
Definition sqlite3.c:787

References sqlite3expert::bRun, sqlite3expert::db, sqlite3expert::dbv, idxDatabaseError(), idxMalloc(), idxPrepareStmt(), idxScanFree(), idxStatementFree(), IdxStatement::iId, IdxStatement::pNext, sqlite3expert::pScan, sqlite3expert::pStatement, sqlite3_finalize, sqlite3_prepare_v2, sqlite3_sql, SQLITE_MISUSE, SQLITE_OK, STRLEN, and IdxStatement::zSql.

Referenced by expertHandleSQL().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_fileio_init()

int sqlite3_fileio_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
8987 {
8988 int rc = SQLITE_OK;
8990 (void)pzErrMsg; /* Unused parameter */
8991 rc = sqlite3_create_function(db, "readfile", 1,
8993 readfileFunc, 0, 0);
8994 if( rc==SQLITE_OK ){
8995 rc = sqlite3_create_function(db, "writefile", -1,
8997 writefileFunc, 0, 0);
8998 }
8999 if( rc==SQLITE_OK ){
9000 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
9001 lsModeFunc, 0, 0);
9002 }
9003 if( rc==SQLITE_OK ){
9004 rc = fsdirRegister(db);
9005 }
9006 return rc;
9007}
static void writefileFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:8463
static int fsdirRegister(sqlite3 *db)
Definition shell.c:8944
static void readfileFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:8152
static void lsModeFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:8513

References fsdirRegister(), lsModeFunc(), readfileFunc(), sqlite3_create_function, SQLITE_DIRECTONLY, SQLITE_EXTENSION_INIT2, SQLITE_OK, SQLITE_UTF8, and writefileFunc().

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_ieee_init()

int sqlite3_ieee_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
6149 {
6150 static const struct {
6151 char *zFName;
6152 int nArg;
6153 int iAux;
6154 void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
6155 } aFunc[] = {
6156 { "ieee754", 1, 0, ieee754func },
6157 { "ieee754", 2, 0, ieee754func },
6158 { "ieee754_mantissa", 1, 1, ieee754func },
6159 { "ieee754_exponent", 1, 2, ieee754func },
6160 { "ieee754_to_blob", 1, 0, ieee754func_to_blob },
6161 { "ieee754_from_blob", 1, 0, ieee754func_from_blob },
6162 { "ieee754_inc", 2, 0, ieee754inc },
6163 };
6164 unsigned int i;
6165 int rc = SQLITE_OK;
6167 (void)pzErrMsg; /* Unused parameter */
6168 for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
6169 rc = sqlite3_create_function(db, aFunc[i].zFName, aFunc[i].nArg,
6171 (void*)&aFunc[i].iAux,
6172 aFunc[i].xFunc, 0, 0);
6173 }
6174 return rc;
6175}
static void ieee754inc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:6123
static void ieee754func_to_blob(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:6088
static void ieee754func_from_blob(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:6068
static void ieee754func(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:5953

References ieee754func(), ieee754func_from_blob(), ieee754func_to_blob(), ieee754inc(), sqlite3_create_function, SQLITE_EXTENSION_INIT2, SQLITE_INNOCUOUS, SQLITE_OK, and SQLITE_UTF8.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_intck_close()

void sqlite3_intck_close ( sqlite3_intck * pCk)
15980 {
15981 if( p ){
15982 sqlite3_finalize(p->pCheck);
15984 p->db, "parse_create_index", 1, SQLITE_UTF8, 0, 0, 0, 0
15985 );
15986 sqlite3_free(p->zObj);
15987 sqlite3_free(p->zKey);
15988 sqlite3_free(p->zTestSql);
15989 sqlite3_free(p->zErr);
15990 sqlite3_free(p->zMessage);
15991 sqlite3_free(p);
15992 }
15993}

References sqlite3_intck::db, sqlite3_intck::pCheck, sqlite3_create_function, sqlite3_finalize, sqlite3_free, SQLITE_UTF8, sqlite3_intck::zErr, sqlite3_intck::zKey, sqlite3_intck::zMessage, sqlite3_intck::zObj, and sqlite3_intck::zTestSql.

Referenced by intckDatabaseCmd(), and sqlite3_intck_open().

Here is the caller graph for this function:

◆ sqlite3_intck_error()

int sqlite3_intck_error ( sqlite3_intck * pCk,
const char ** pzErr )
16070 {
16071 if( pzErr ) *pzErr = p->zErr;
16072 return (p->rc==SQLITE_DONE ? SQLITE_OK : p->rc);
16073}

References sqlite3_intck::rc, SQLITE_DONE, SQLITE_OK, and sqlite3_intck::zErr.

Referenced by intckDatabaseCmd().

Here is the caller graph for this function:

◆ sqlite3_intck_message()

const char * sqlite3_intck_message ( sqlite3_intck * pCk)
16056 {
16057 assert( p->pCheck==0 || p->zMessage==0 );
16058 if( p->zMessage ){
16059 return p->zMessage;
16060 }
16061 if( p->pCheck ){
16062 return (const char*)sqlite3_column_text(p->pCheck, 0);
16063 }
16064 return 0;
16065}

References sqlite3_intck::pCheck, sqlite3_column_text, and sqlite3_intck::zMessage.

Referenced by intckDatabaseCmd().

Here is the caller graph for this function:

◆ sqlite3_intck_open()

int sqlite3_intck_open ( sqlite3 * db,
const char * zDb,
sqlite3_intck ** ppOut )
15950 {
15951 sqlite3_intck *pNew = 0;
15952 int rc = SQLITE_OK;
15953 const char *zDb = zDbArg ? zDbArg : "main";
15954 int nDb = (int)strlen(zDb);
15955
15956 pNew = (sqlite3_intck*)sqlite3_malloc(sizeof(*pNew) + nDb + 1);
15957 if( pNew==0 ){
15958 rc = SQLITE_NOMEM;
15959 }else{
15960 memset(pNew, 0, sizeof(*pNew));
15961 pNew->db = db;
15962 pNew->zDb = (const char*)&pNew[1];
15963 memcpy(&pNew[1], zDb, nDb+1);
15964 rc = sqlite3_create_function(db, "parse_create_index",
15966 );
15967 if( rc!=SQLITE_OK ){
15968 sqlite3_intck_close(pNew);
15969 pNew = 0;
15970 }
15971 }
15972
15973 *ppOut = pNew;
15974 return rc;
15975}
static void intckParseCreateIndexFunc(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal)
Definition shell.c:15614

References sqlite3_intck::db, intckParseCreateIndexFunc(), sqlite3_create_function, sqlite3_intck_close(), sqlite3_malloc, SQLITE_NOMEM, SQLITE_OK, SQLITE_UTF8, and sqlite3_intck::zDb.

Referenced by intckDatabaseCmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_intck_step()

int sqlite3_intck_step ( sqlite3_intck * pCk)
15998 {
15999 if( p->rc==SQLITE_OK ){
16000
16001 if( p->zMessage ){
16002 sqlite3_free(p->zMessage);
16003 p->zMessage = 0;
16004 }
16005
16006 if( p->bCorruptSchema ){
16007 p->rc = SQLITE_DONE;
16008 }else
16009 if( p->pCheck==0 ){
16010 intckFindObject(p);
16011 if( p->rc==SQLITE_OK ){
16012 if( p->zObj ){
16013 char *zSql = 0;
16014 zSql = intckCheckObjectSql(p, p->zObj, p->zKey, &p->nKeyVal);
16015 p->pCheck = intckPrepare(p, zSql);
16016 sqlite3_free(zSql);
16017 sqlite3_free(p->zKey);
16018 p->zKey = 0;
16019 }else{
16020 p->rc = SQLITE_DONE;
16021 }
16022 }else if( p->rc==SQLITE_CORRUPT ){
16023 p->rc = SQLITE_OK;
16024 p->zMessage = intckMprintf(p, "%s",
16025 "corruption found while reading database schema"
16026 );
16027 p->bCorruptSchema = 1;
16028 }
16029 }
16030
16031 if( p->pCheck ){
16032 assert( p->rc==SQLITE_OK );
16033 if( sqlite3_step(p->pCheck)==SQLITE_ROW ){
16034 /* Normal case, do nothing. */
16035 }else{
16036 intckFinalize(p, p->pCheck);
16037 p->pCheck = 0;
16038 p->nKeyVal = 0;
16039 if( p->rc==SQLITE_CORRUPT ){
16040 p->rc = SQLITE_OK;
16041 p->zMessage = intckMprintf(p,
16042 "corruption found while scanning database object %s", p->zObj
16043 );
16044 }
16045 }
16046 }
16047 }
16048
16049 return p->rc;
16050}
static void intckFindObject(sqlite3_intck *p)
Definition shell.c:15437
static char * intckCheckObjectSql(sqlite3_intck *p, const char *zObj, const char *zPrev, int *pnKeyVal)
Definition shell.c:15673

References sqlite3_intck::bCorruptSchema, intckCheckObjectSql(), intckFinalize(), intckFindObject(), intckMprintf(), intckPrepare(), sqlite3_intck::nKeyVal, sqlite3_intck::pCheck, sqlite3_intck::rc, sqlite3_free, sqlite3_step, SQLITE_CORRUPT, SQLITE_DONE, SQLITE_OK, SQLITE_ROW, sqlite3_intck::zKey, sqlite3_intck::zMessage, and sqlite3_intck::zObj.

Referenced by intckDatabaseCmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_intck_test_sql()

const char * sqlite3_intck_test_sql ( sqlite3_intck * pCk,
const char * zObj )
16093 {
16094 sqlite3_free(p->zTestSql);
16095 if( zObj ){
16096 p->zTestSql = intckCheckObjectSql(p, zObj, 0, 0);
16097 }else{
16098 if( p->zObj ){
16099 p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey, 0);
16100 }else{
16101 sqlite3_free(p->zTestSql);
16102 p->zTestSql = 0;
16103 }
16104 }
16105 return p->zTestSql;
16106}

References intckCheckObjectSql(), sqlite3_free, sqlite3_intck::zKey, sqlite3_intck::zObj, and sqlite3_intck::zTestSql.

Here is the call graph for this function:

◆ sqlite3_intck_unlock()

int sqlite3_intck_unlock ( sqlite3_intck * pCk)
16079 {
16080 if( p->rc==SQLITE_OK && p->pCheck ){
16081 assert( p->zKey==0 && p->nKeyVal>0 );
16082 intckSaveKey(p);
16083 intckFinalize(p, p->pCheck);
16084 p->pCheck = 0;
16085 }
16086 return p->rc;
16087}
static void intckSaveKey(sqlite3_intck *p)
Definition shell.c:15337

References intckFinalize(), intckSaveKey(), sqlite3_intck::nKeyVal, sqlite3_intck::pCheck, sqlite3_intck::rc, SQLITE_OK, and sqlite3_intck::zKey.

Referenced by intckDatabaseCmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_percentile_init()

int sqlite3_percentile_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
5069 {
5070 int rc = SQLITE_OK;
5071 unsigned int i;
5072#ifdef SQLITE3EXT_H
5074#else
5075 (void)pApi; /* Unused parameter */
5076#endif
5077 (void)pzErrMsg; /* Unused parameter */
5078 for(i=0; i<sizeof(aPercentFunc)/sizeof(aPercentFunc[0]); i++){
5080 aPercentFunc[i].zName,
5081 aPercentFunc[i].nArg,
5083 (void*)&aPercentFunc[i],
5085 if( rc ) break;
5086 }
5087 return rc;
5088}
static void percentStep(sqlite3_context *pCtx, int argc, sqlite3_value **argv)
Definition shell.c:4816
static const PercentileFunc aPercentFunc[]
Definition shell.c:4736
static void percentFinal(sqlite3_context *pCtx)
Definition shell.c:5055
static void percentValue(sqlite3_context *pCtx)
Definition shell.c:5058
static void percentInverse(sqlite3_context *pCtx, int argc, sqlite3_value **argv)
Definition shell.c:4974
#define SQLITE_SELFORDER1
Definition sqlite3.c:6149

References aPercentFunc, percentFinal(), percentInverse(), percentStep(), percentValue(), sqlite3_create_window_function, SQLITE_EXTENSION_INIT2, SQLITE_INNOCUOUS, SQLITE_OK, SQLITE_SELFORDER1, and SQLITE_UTF8.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_regexp_init()

int sqlite3_regexp_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
7909 {
7910 int rc = SQLITE_OK;
7912 (void)pzErrMsg; /* Unused */
7913 rc = sqlite3_create_function(db, "regexp", 2,
7915 0, re_sql_func, 0, 0);
7916 if( rc==SQLITE_OK ){
7917 /* The regexpi(PATTERN,STRING) function is a case-insensitive version
7918 ** of regexp(PATTERN,STRING). */
7919 rc = sqlite3_create_function(db, "regexpi", 2,
7921 (void*)db, re_sql_func, 0, 0);
7922#if defined(SQLITE_DEBUG)
7923 if( rc==SQLITE_OK ){
7924 rc = sqlite3_create_function(db, "regexp_bytecode", 1,
7926 0, re_bytecode_func, 0, 0);
7927 }
7928#endif /* SQLITE_DEBUG */
7929 }
7930 return rc;
7931}
static void re_sql_func(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:7799

References re_sql_func(), sqlite3_create_function, SQLITE_DETERMINISTIC, SQLITE_EXTENSION_INIT2, SQLITE_INNOCUOUS, SQLITE_OK, and SQLITE_UTF8.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_series_init()

int sqlite3_series_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
7034 {
7035 int rc = SQLITE_OK;
7037#ifndef SQLITE_OMIT_VIRTUALTABLE
7038 if( sqlite3_libversion_number()<3008012 && pzErrMsg!=0 ){
7039 *pzErrMsg = sqlite3_mprintf(
7040 "generate_series() requires SQLite 3.8.12 or later");
7041 return SQLITE_ERROR;
7042 }
7043 rc = sqlite3_create_module(db, "generate_series", &seriesModule, 0);
7044#endif
7045 return rc;
7046}
static sqlite3_module seriesModule
Definition shell.c:6997
#define sqlite3_libversion_number
Definition sqlite3ext.h:469

References seriesModule, sqlite3_create_module, sqlite3_libversion_number, sqlite3_mprintf, SQLITE_ERROR, SQLITE_EXTENSION_INIT2, and SQLITE_OK.

Referenced by open_db().

Here is the caller graph for this function:

◆ sqlite3_sha_init()

int sqlite3_sha_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
3578 {
3579 int rc = SQLITE_OK;
3580 static int one = 1;
3582 (void)pzErrMsg; /* Unused parameter */
3583 rc = sqlite3_create_function(db, "sha1", 1,
3585 0, sha1Func, 0, 0);
3586 if( rc==SQLITE_OK ){
3587 rc = sqlite3_create_function(db, "sha1b", 1,
3589 (void*)&one, sha1Func, 0, 0);
3590 }
3591 if( rc==SQLITE_OK ){
3592 rc = sqlite3_create_function(db, "sha1_query", 1,
3594 sha1QueryFunc, 0, 0);
3595 }
3596 return rc;
3597}
static void sha1Func(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:3429
static void sha1QueryFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:3468

References sha1Func(), sha1QueryFunc(), sqlite3_create_function, SQLITE_DETERMINISTIC, SQLITE_DIRECTONLY, SQLITE_EXTENSION_INIT2, SQLITE_INNOCUOUS, SQLITE_OK, and SQLITE_UTF8.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_shathree_init()

int sqlite3_shathree_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
3152 {
3153 int rc = SQLITE_OK;
3155 (void)pzErrMsg; /* Unused parameter */
3156 rc = sqlite3_create_function(db, "sha3", 1,
3158 0, sha3Func, 0, 0);
3159 if( rc==SQLITE_OK ){
3160 rc = sqlite3_create_function(db, "sha3", 2,
3162 0, sha3Func, 0, 0);
3163 }
3164 if( rc==SQLITE_OK ){
3165 rc = sqlite3_create_function(db, "sha3_agg", 1,
3167 0, 0, sha3AggStep, sha3AggFinal);
3168 }
3169 if( rc==SQLITE_OK ){
3170 rc = sqlite3_create_function(db, "sha3_agg", 2,
3172 0, 0, sha3AggStep, sha3AggFinal);
3173 }
3174 if( rc==SQLITE_OK ){
3175 rc = sqlite3_create_function(db, "sha3_query", 1,
3177 0, sha3QueryFunc, 0, 0);
3178 }
3179 if( rc==SQLITE_OK ){
3180 rc = sqlite3_create_function(db, "sha3_query", 2,
3182 0, sha3QueryFunc, 0, 0);
3183 }
3184 return rc;
3185}
static void sha3AggStep(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:3109
static void sha3AggFinal(sqlite3_context *context)
Definition shell.c:3134
static void sha3QueryFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:3041
static void sha3Func(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:2908

References sha3AggFinal(), sha3AggStep(), sha3Func(), sha3QueryFunc(), sqlite3_create_function, SQLITE_DETERMINISTIC, SQLITE_DIRECTONLY, SQLITE_EXTENSION_INIT2, SQLITE_INNOCUOUS, SQLITE_OK, and SQLITE_UTF8.

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_stmtrand_init()

int sqlite3_stmtrand_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
16195 {
16196 int rc = SQLITE_OK;
16198 (void)pzErrMsg; /* Unused parameter */
16199 rc = sqlite3_create_function(db, "stmtrand", 1, SQLITE_UTF8, 0,
16200 stmtrandFunc, 0, 0);
16201 if( rc==SQLITE_OK ){
16202 rc = sqlite3_create_function(db, "stmtrand", 0, SQLITE_UTF8, 0,
16203 stmtrandFunc, 0, 0);
16204 }
16205 return rc;
16206}
static void stmtrandFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition shell.c:16154

References sqlite3_create_function, SQLITE_EXTENSION_INIT2, SQLITE_OK, SQLITE_UTF8, and stmtrandFunc().

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3_uint_init()

int sqlite3_uint_init ( sqlite3 * db,
char ** pzErrMsg,
const sqlite3_api_routines * pApi )
3688 {
3690 (void)pzErrMsg; /* Unused parameter */
3691 return sqlite3_create_collation(db, "uint", SQLITE_UTF8, 0, uintCollFunc);
3692}
static int uintCollFunc(void *notUsed, int nKey1, const void *pKey1, int nKey2, const void *pKey2)
Definition shell.c:3640

References sqlite3_create_collation, SQLITE_EXTENSION_INIT2, SQLITE_UTF8, and uintCollFunc().

Referenced by open_db().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3CompletionVtabInit()

int sqlite3CompletionVtabInit ( sqlite3 * db)
9502 {
9503 int rc = SQLITE_OK;
9504#ifndef SQLITE_OMIT_VIRTUALTABLE
9505 rc = sqlite3_create_module(db, "completion", &completionModule, 0);
9506#endif
9507 return rc;
9508}
static sqlite3_module completionModule
Definition shell.c:9472

References completionModule, sqlite3_create_module, and SQLITE_OK.

Referenced by sqlite3_completion_init().

Here is the caller graph for this function:

◆ sqlite3MemTraceActivate()

int sqlite3MemTraceActivate ( FILE * out)
2123 {
2124 int rc = SQLITE_OK;
2125 if( memtraceBase.xMalloc==0 ){
2127 if( rc==SQLITE_OK ){
2129 }
2130 }
2131 memtraceOut = out;
2132 return rc;
2133}
static sqlite3_mem_methods ersaztMethods
Definition shell.c:2111
#define SQLITE_CONFIG_GETMALLOC
Definition sqlite3.c:2512
#define SQLITE_CONFIG_MALLOC
Definition sqlite3.c:2511

References ersaztMethods, memtraceBase, memtraceOut, sqlite3_config(), SQLITE_CONFIG_GETMALLOC, SQLITE_CONFIG_MALLOC, and SQLITE_OK.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3MemTraceDeactivate()

int sqlite3MemTraceDeactivate ( void )
2136 {
2137 int rc = SQLITE_OK;
2138 if( memtraceBase.xMalloc!=0 ){
2140 if( rc==SQLITE_OK ){
2141 memset(&memtraceBase, 0, sizeof(memtraceBase));
2142 }
2143 }
2144 memtraceOut = 0;
2145 return rc;
2146}

References memtraceBase, memtraceOut, sqlite3_config(), SQLITE_CONFIG_MALLOC, and SQLITE_OK.

Here is the call graph for this function:

◆ sqlite3PcacheTraceActivate()

int sqlite3PcacheTraceActivate ( FILE * out)
2305 {
2306 int rc = SQLITE_OK;
2307 if( pcacheBase.xFetch==0 ){
2309 if( rc==SQLITE_OK ){
2311 }
2312 }
2313 pcachetraceOut = out;
2314 return rc;
2315}
static sqlite3_pcache_methods2 ersaztPcacheMethods
Definition shell.c:2288
#define SQLITE_CONFIG_PCACHE2
Definition sqlite3.c:2525
#define SQLITE_CONFIG_GETPCACHE2
Definition sqlite3.c:2526

References ersaztPcacheMethods, pcacheBase, pcachetraceOut, sqlite3_config(), SQLITE_CONFIG_GETPCACHE2, SQLITE_CONFIG_PCACHE2, and SQLITE_OK.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqlite3PcacheTraceDeactivate()

int sqlite3PcacheTraceDeactivate ( void )
2318 {
2319 int rc = SQLITE_OK;
2320 if( pcacheBase.xFetch!=0 ){
2322 if( rc==SQLITE_OK ){
2323 memset(&pcacheBase, 0, sizeof(pcacheBase));
2324 }
2325 }
2326 pcachetraceOut = 0;
2327 return rc;
2328}

References pcacheBase, pcachetraceOut, sqlite3_config(), SQLITE_CONFIG_PCACHE2, and SQLITE_OK.

Here is the call graph for this function:

◆ sqlite3re_compile()

const char * sqlite3re_compile ( ReCompiled ** ppRe,
const char * zIn,
int noCase )
static
7723 {
7724 ReCompiled *pRe;
7725 const char *zErr;
7726 int i, j;
7727
7728 *ppRe = 0;
7729 pRe = sqlite3_malloc( sizeof(*pRe) );
7730 if( pRe==0 ){
7731 return "out of memory";
7732 }
7733 memset(pRe, 0, sizeof(*pRe));
7734 pRe->xNextChar = noCase ? re_next_char_nocase : re_next_char;
7735 if( re_resize(pRe, 30) ){
7736 re_free(pRe);
7737 return "out of memory";
7738 }
7739 if( zIn[0]=='^' ){
7740 zIn++;
7741 }else{
7742 re_append(pRe, RE_OP_ANYSTAR, 0);
7743 }
7744 pRe->sIn.z = (unsigned char*)zIn;
7745 pRe->sIn.i = 0;
7746 pRe->sIn.mx = (int)strlen(zIn);
7747 zErr = re_subcompile_re(pRe);
7748 if( zErr ){
7749 re_free(pRe);
7750 return zErr;
7751 }
7752 if( pRe->sIn.i>=pRe->sIn.mx ){
7753 re_append(pRe, RE_OP_ACCEPT, 0);
7754 *ppRe = pRe;
7755 }else{
7756 re_free(pRe);
7757 return "unrecognized character";
7758 }
7759
7760 /* The following is a performance optimization. If the regex begins with
7761 ** ".*" (if the input regex lacks an initial "^") and afterwards there are
7762 ** one or more matching characters, enter those matching characters into
7763 ** zInit[]. The re_match() routine can then search ahead in the input
7764 ** string looking for the initial match without having to run the whole
7765 ** regex engine over the string. Do not worry about trying to match
7766 ** unicode characters beyond plane 0 - those are very rare and this is
7767 ** just an optimization. */
7768 if( pRe->aOp[0]==RE_OP_ANYSTAR && !noCase ){
7769 for(j=0, i=1; j<(int)sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){
7770 unsigned x = pRe->aArg[i];
7771 if( x<=0x7f ){
7772 pRe->zInit[j++] = (unsigned char)x;
7773 }else if( x<=0x7ff ){
7774 pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6));
7775 pRe->zInit[j++] = 0x80 | (x&0x3f);
7776 }else if( x<=0xffff ){
7777 pRe->zInit[j++] = (unsigned char)(0xe0 | (x>>12));
7778 pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f);
7779 pRe->zInit[j++] = 0x80 | (x&0x3f);
7780 }else{
7781 break;
7782 }
7783 }
7784 if( j>0 && pRe->zInit[j-1]==0 ) j--;
7785 pRe->nInit = j;
7786 }
7787 return pRe->zErr;
7788}
unsigned char zInit[12]
Definition shell.c:7206
int nInit
Definition shell.c:7207
#define RE_OP_ACCEPT
Definition shell.c:7134
static unsigned re_next_char_nocase(ReInput *p)
Definition shell.c:7249

References ReCompiled::aArg, ReCompiled::aOp, ReInput::i, ReInput::mx, ReCompiled::nInit, re_append(), re_free, re_next_char(), re_next_char_nocase(), RE_OP_ACCEPT, RE_OP_ANYSTAR, RE_OP_MATCH, re_resize(), re_subcompile_re(), ReCompiled::sIn, sqlite3_malloc, ReCompiled::xNextChar, ReInput::z, ReCompiled::zErr, and ReCompiled::zInit.

Here is the call graph for this function:

◆ sqlite3re_free()

void sqlite3re_free ( void * p)
static
7708 {
7709 ReCompiled *pRe = (ReCompiled*)p;
7710 if( pRe ){
7711 sqlite3_free(pRe->aOp);
7712 sqlite3_free(pRe->aArg);
7713 sqlite3_free(pRe);
7714 }
7715}

References ReCompiled::aArg, ReCompiled::aOp, and sqlite3_free.

◆ sqlite3re_match()

int sqlite3re_match ( ReCompiled * pRe,
const unsigned char * zIn,
int nIn )
static
7274 {
7275 ReStateSet aStateSet[2], *pThis, *pNext;
7276 ReStateNumber aSpace[100];
7277 ReStateNumber *pToFree;
7278 unsigned int i = 0;
7279 unsigned int iSwap = 0;
7280 int c = RE_START;
7281 int cPrev = 0;
7282 int rc = 0;
7283 ReInput in;
7284
7285 in.z = zIn;
7286 in.i = 0;
7287 in.mx = nIn>=0 ? nIn : (int)strlen((char const*)zIn);
7288
7289 /* Look for the initial prefix match, if there is one. */
7290 if( pRe->nInit ){
7291 unsigned char x = pRe->zInit[0];
7292 while( in.i+pRe->nInit<=in.mx
7293 && (zIn[in.i]!=x ||
7294 strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
7295 ){
7296 in.i++;
7297 }
7298 if( in.i+pRe->nInit>in.mx ) return 0;
7299 c = RE_START-1;
7300 }
7301
7302 if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
7303 pToFree = 0;
7304 aStateSet[0].aState = aSpace;
7305 }else{
7306 pToFree = sqlite3_malloc64( sizeof(ReStateNumber)*2*pRe->nState );
7307 if( pToFree==0 ) return -1;
7308 aStateSet[0].aState = pToFree;
7309 }
7310 aStateSet[1].aState = &aStateSet[0].aState[pRe->nState];
7311 pNext = &aStateSet[1];
7312 pNext->nState = 0;
7313 re_add_state(pNext, 0);
7314 while( c!=RE_EOF && pNext->nState>0 ){
7315 cPrev = c;
7316 c = pRe->xNextChar(&in);
7317 pThis = pNext;
7318 pNext = &aStateSet[iSwap];
7319 iSwap = 1 - iSwap;
7320 pNext->nState = 0;
7321 for(i=0; i<pThis->nState; i++){
7322 int x = pThis->aState[i];
7323 switch( pRe->aOp[x] ){
7324 case RE_OP_MATCH: {
7325 if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
7326 break;
7327 }
7328 case RE_OP_ATSTART: {
7329 if( cPrev==RE_START ) re_add_state(pThis, x+1);
7330 break;
7331 }
7332 case RE_OP_ANY: {
7333 if( c!=0 ) re_add_state(pNext, x+1);
7334 break;
7335 }
7336 case RE_OP_WORD: {
7337 if( re_word_char(c) ) re_add_state(pNext, x+1);
7338 break;
7339 }
7340 case RE_OP_NOTWORD: {
7341 if( !re_word_char(c) && c!=0 ) re_add_state(pNext, x+1);
7342 break;
7343 }
7344 case RE_OP_DIGIT: {
7345 if( re_digit_char(c) ) re_add_state(pNext, x+1);
7346 break;
7347 }
7348 case RE_OP_NOTDIGIT: {
7349 if( !re_digit_char(c) && c!=0 ) re_add_state(pNext, x+1);
7350 break;
7351 }
7352 case RE_OP_SPACE: {
7353 if( re_space_char(c) ) re_add_state(pNext, x+1);
7354 break;
7355 }
7356 case RE_OP_NOTSPACE: {
7357 if( !re_space_char(c) && c!=0 ) re_add_state(pNext, x+1);
7358 break;
7359 }
7360 case RE_OP_BOUNDARY: {
7361 if( re_word_char(c)!=re_word_char(cPrev) ) re_add_state(pThis, x+1);
7362 break;
7363 }
7364 case RE_OP_ANYSTAR: {
7365 re_add_state(pNext, x);
7366 re_add_state(pThis, x+1);
7367 break;
7368 }
7369 case RE_OP_FORK: {
7370 re_add_state(pThis, x+pRe->aArg[x]);
7371 re_add_state(pThis, x+1);
7372 break;
7373 }
7374 case RE_OP_GOTO: {
7375 re_add_state(pThis, x+pRe->aArg[x]);
7376 break;
7377 }
7378 case RE_OP_ACCEPT: {
7379 rc = 1;
7380 goto re_match_end;
7381 }
7382 case RE_OP_CC_EXC: {
7383 if( c==0 ) break;
7384 /* fall-through */ goto re_op_cc_inc;
7385 }
7386 case RE_OP_CC_INC: re_op_cc_inc: {
7387 int j = 1;
7388 int n = pRe->aArg[x];
7389 int hit = 0;
7390 for(j=1; j>0 && j<n; j++){
7391 if( pRe->aOp[x+j]==RE_OP_CC_VALUE ){
7392 if( pRe->aArg[x+j]==c ){
7393 hit = 1;
7394 j = -1;
7395 }
7396 }else{
7397 if( pRe->aArg[x+j]<=c && pRe->aArg[x+j+1]>=c ){
7398 hit = 1;
7399 j = -1;
7400 }else{
7401 j++;
7402 }
7403 }
7404 }
7405 if( pRe->aOp[x]==RE_OP_CC_EXC ) hit = !hit;
7406 if( hit ) re_add_state(pNext, x+n);
7407 break;
7408 }
7409 }
7410 }
7411 }
7412 for(i=0; i<pNext->nState; i++){
7413 int x = pNext->aState[i];
7414 while( pRe->aOp[x]==RE_OP_GOTO ) x += pRe->aArg[x];
7415 if( pRe->aOp[x]==RE_OP_ACCEPT ){ rc = 1; break; }
7416 }
7417re_match_end:
7418 sqlite3_free(pToFree);
7419 return rc;
7420}
static int re_word_char(int c)
Definition shell.c:7256
#define RE_START
Definition shell.c:7124
static int re_space_char(int c)
Definition shell.c:7267
static void re_add_state(ReStateSet *pSet, int newState)
Definition shell.c:7213
static int re_digit_char(int c)
Definition shell.c:7262
Definition shell.c:7190
Definition shell.c:7182

References ReCompiled::aArg, ReCompiled::aOp, ReStateSet::aState, c, ReInput::i, ReInput::mx, ReCompiled::nInit, ReCompiled::nState, ReStateSet::nState, re_add_state(), re_digit_char(), RE_EOF, RE_OP_ACCEPT, RE_OP_ANY, RE_OP_ANYSTAR, RE_OP_ATSTART, RE_OP_BOUNDARY, RE_OP_CC_EXC, RE_OP_CC_INC, RE_OP_CC_VALUE, RE_OP_DIGIT, RE_OP_FORK, RE_OP_GOTO, RE_OP_MATCH, RE_OP_NOTDIGIT, RE_OP_NOTSPACE, RE_OP_NOTWORD, RE_OP_SPACE, RE_OP_WORD, re_space_char(), RE_START, re_word_char(), sqlite3_free, sqlite3_malloc64, ReCompiled::xNextChar, ReInput::z, and ReCompiled::zInit.

Here is the call graph for this function:

◆ stmtrandFunc()

void stmtrandFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
16158 {
16159 Stmtrand *p;
16160
16162 if( p==0 ){
16163 unsigned int seed;
16164 p = sqlite3_malloc( sizeof(*p) );
16165 if( p==0 ){
16167 return;
16168 }
16169 if( argc>=1 ){
16170 seed = (unsigned int)sqlite3_value_int(argv[0]);
16171 }else{
16172 seed = 0;
16173 }
16174 p->x = seed | 1;
16175 p->y = seed;
16178 if( p==0 ){
16180 return;
16181 }
16182 }
16183 p->x = (p->x>>1) ^ ((1+~(p->x&1)) & 0xd0000001);
16184 p->y = p->y*1103515245 + 12345;
16185 sqlite3_result_int(context, (int)((p->x ^ p->y)&0x7fffffff));
16186}
#define STMTRAND_KEY
Definition shell.c:16147
unsigned int x
Definition shell.c:16143
unsigned int y
Definition shell.c:16143
Definition shell.c:16142

References sqlite3_free, sqlite3_get_auxdata, sqlite3_malloc, sqlite3_result_error_nomem, sqlite3_result_int, sqlite3_set_auxdata, sqlite3_value_int, STMTRAND_KEY, Stmtrand::x, and Stmtrand::y.

Referenced by sqlite3_stmtrand_init().

Here is the caller graph for this function:

◆ str_in_array()

int str_in_array ( const char * zStr,
const char ** azArray )
static
23869 {
23870 int i;
23871 for(i=0; azArray[i]; i++){
23872 if( 0==cli_strcmp(zStr, azArray[i]) ) return 1;
23873 }

References cli_strcmp().

Referenced by explain_data_prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strappend()

void strappend ( char * z,
int * pI,
const char * zAppend )
static
16564 {
16565 int i = *pI;
16566 while( zAppend[0] ){ z[i++] = *(zAppend++); }
16567 z[i] = 0;
16568 *pI = i;
16569}

Referenced by vfstraceShmLock(), and vfstraceSync().

Here is the caller graph for this function:

◆ strlen30()

int strlen30 ( const char * z)
static
1263 {
1264 const char *z2 = z;
1265 while( *z2 ){ z2++; }
1266 return 0x3fffffff & (int)(z2 - z);
1267}

Referenced by appendText(), do_meta_command(), expertDotCommand(), find_home_dir(), lintDotCommand(), lintFkeyIndexes(), main(), run_schema_dump_query(), set_table_name(), shell_callback(), shellAddSchemaName(), and tryToCloneData().

Here is the caller graph for this function:

◆ strlenChar()

int strlenChar ( const char * z)
static
1273 {
1274 int n = 0;
1275 while( *z ){
1276 if( (0xc0&*(z++))!=0x80 ) n++;
1277 }
1278 return n;
1279}

Referenced by exec_prepared_stmt_columnar(), and shell_callback().

Here is the caller graph for this function:

◆ tableColumnList()

char ** tableColumnList ( ShellState * p,
const char * zTab )
static
25003 {
25004 char **azCol = 0;
25005 sqlite3_stmt *pStmt;
25006 char *zSql;
25007 int nCol = 0;
25008 int nAlloc = 0;
25009 int nPK = 0; /* Number of PRIMARY KEY columns seen */
25010 int isIPK = 0; /* True if one PRIMARY KEY column of type INTEGER */
25011 int preserveRowid = ShellHasFlag(p, SHFLG_PreserveRowid);
25012 int rc;
25013
25014 zSql = sqlite3_mprintf("PRAGMA table_info=%Q", zTab);
25015 shell_check_oom(zSql);
25016 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
25017 sqlite3_free(zSql);
25018 if( rc ) return 0;
25019 while( sqlite3_step(pStmt)==SQLITE_ROW ){
25020 if( nCol>=nAlloc-2 ){
25021 nAlloc = nAlloc*2 + nCol + 10;
25022 azCol = sqlite3_realloc(azCol, nAlloc*sizeof(azCol[0]));
25023 shell_check_oom(azCol);
25024 }
25025 azCol[++nCol] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1));
25026 shell_check_oom(azCol[nCol]);
25027 if( sqlite3_column_int(pStmt, 5) ){
25028 nPK++;
25029 if( nPK==1
25030 && sqlite3_stricmp((const char*)sqlite3_column_text(pStmt,2),
25031 "INTEGER")==0
25032 ){
25033 isIPK = 1;
25034 }else{
25035 isIPK = 0;
25036 }
25037 }
25038 }
25039 sqlite3_finalize(pStmt);
25040 if( azCol==0 ) return 0;
25041 azCol[0] = 0;
25042 azCol[nCol+1] = 0;
25043
25044 /* The decision of whether or not a rowid really needs to be preserved
25045 ** is tricky. We never need to preserve a rowid for a WITHOUT ROWID table
25046 ** or a table with an INTEGER PRIMARY KEY. We are unable to preserve
25047 ** rowids on tables where the rowid is inaccessible because there are other
25048 ** columns in the table named "rowid", "_rowid_", and "oid".
25049 */
25050 if( preserveRowid && isIPK ){
25051 /* If a single PRIMARY KEY column with type INTEGER was seen, then it
25052 ** might be an alias for the ROWID. But it might also be a WITHOUT ROWID
25053 ** table or a INTEGER PRIMARY KEY DESC column, neither of which are
25054 ** ROWID aliases. To distinguish these cases, check to see if
25055 ** there is a "pk" entry in "PRAGMA index_list". There will be
25056 ** no "pk" index if the PRIMARY KEY really is an alias for the ROWID.
25057 */
25058 zSql = sqlite3_mprintf("SELECT 1 FROM pragma_index_list(%Q)"
25059 " WHERE origin='pk'", zTab);
25060 shell_check_oom(zSql);
25061 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
25062 sqlite3_free(zSql);
25063 if( rc ){
25064 freeColumnList(azCol);
25065 return 0;
25066 }
25067 rc = sqlite3_step(pStmt);
25068 sqlite3_finalize(pStmt);
25069 preserveRowid = rc==SQLITE_ROW;
25070 }
25071 if( preserveRowid ){
25072 /* Only preserve the rowid if we can find a name to use for the
25073 ** rowid */
25074 static char *azRowid[] = { "rowid", "_rowid_", "oid" };
25075 int i, j;
25076 for(j=0; j<3; j++){
25077 for(i=1; i<=nCol; i++){
25078 if( sqlite3_stricmp(azRowid[j],azCol[i])==0 ) break;
25079 }
25080 if( i>nCol ){
25081 /* At this point, we know that azRowid[j] is not the name of any
25082 ** ordinary column in the table. Verify that azRowid[j] is a valid
25083 ** name for the rowid before adding it to azCol[0]. WITHOUT ROWID
25084 ** tables will fail this last check */
25085 rc = sqlite3_table_column_metadata(p->db,0,zTab,azRowid[j],0,0,0,0,0);
25086 if( rc==SQLITE_OK ) azCol[0] = azRowid[j];
25087 break;
25088 }
25089 }
25090 }

References ShellState::db, freeColumnList(), shell_check_oom(), ShellHasFlag, SHFLG_PreserveRowid, sqlite3_column_int, sqlite3_column_text, sqlite3_finalize, sqlite3_free, sqlite3_mprintf, sqlite3_prepare_v2, sqlite3_realloc, sqlite3_step, sqlite3_stricmp, sqlite3_table_column_metadata, SQLITE_OK, and SQLITE_ROW.

Referenced by dump_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_breakpoint()

void test_breakpoint ( void )
static
26451 {
26452 static unsigned int nCall = 0;

Referenced by do_meta_command().

Here is the caller graph for this function:

◆ testcase_glob()

int testcase_glob ( const char * zGlob,
const char * z )
static
27170 {
27171 int c, c2;
27172 int invert;
27173 int seen;
27174
27175 while( (c = (*(zGlob++)))!=0 ){
27176 if( IsSpace(c) ){
27177 if( !IsSpace(*z) ) return 0;
27178 while( IsSpace(*zGlob) ) zGlob++;
27179 while( IsSpace(*z) ) z++;
27180 }else if( c=='*' ){
27181 while( (c=(*(zGlob++))) == '*' || c=='?' ){
27182 if( c=='?' && (*(z++))==0 ) return 0;
27183 }
27184 if( c==0 ){
27185 return 1;
27186 }else if( c=='[' ){
27187 while( *z && testcase_glob(zGlob-1,z)==0 ){
27188 z++;
27189 }
27190 return (*z)!=0;
27191 }
27192 while( (c2 = (*(z++)))!=0 ){
27193 while( c2!=c ){
27194 c2 = *(z++);
27195 if( c2==0 ) return 0;
27196 }
27197 if( testcase_glob(zGlob,z) ) return 1;
27198 }
27199 return 0;
27200 }else if( c=='?' ){
27201 if( (*(z++))==0 ) return 0;
27202 }else if( c=='[' ){
27203 int prior_c = 0;
27204 seen = 0;
27205 invert = 0;
27206 c = *(z++);
27207 if( c==0 ) return 0;
27208 c2 = *(zGlob++);
27209 if( c2=='^' ){
27210 invert = 1;
27211 c2 = *(zGlob++);
27212 }
27213 if( c2==']' ){
27214 if( c==']' ) seen = 1;
27215 c2 = *(zGlob++);
27216 }
27217 while( c2 && c2!=']' ){
27218 if( c2=='-' && zGlob[0]!=']' && zGlob[0]!=0 && prior_c>0 ){
27219 c2 = *(zGlob++);
27220 if( c>=prior_c && c<=c2 ) seen = 1;
27221 prior_c = 0;
27222 }else{
27223 if( c==c2 ){
27224 seen = 1;
27225 }
27226 prior_c = c2;
27227 }
27228 c2 = *(zGlob++);
27229 }
27230 if( c2==0 || (seen ^ invert)==0 ) return 0;
27231 }else if( c=='#' ){
27232 if( (z[0]=='-' || z[0]=='+') && IsDigit(z[1]) ) z++;
27233 if( !IsDigit(z[0]) ) return 0;
27234 z++;
27235 while( IsDigit(z[0]) ){ z++; }
27236 }else{
27237 if( c!=(*(z++)) ) return 0;
27238 }
27239 }
27240 while( IsSpace(*z) ){ z++; }

References c, IsDigit, IsSpace, and testcase_glob().

Referenced by do_meta_command(), and testcase_glob().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeDiff()

double timeDiff ( struct timeval * pStart,
struct timeval * pEnd )
static
696 {
697 return (pEnd->tv_usec - pStart->tv_usec)*0.000001 +
698 (double)(pEnd->tv_sec - pStart->tv_sec);
699}

Referenced by endTimer().

Here is the caller graph for this function:

◆ timeOfDay()

sqlite3_int64 timeOfDay ( void )
static
652 {
653 static sqlite3_vfs *clockVfs = 0;
655 if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
656 if( clockVfs==0 ) return 0; /* Never actually happens */
657 if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
658 clockVfs->xCurrentTimeInt64(clockVfs, &t);
659 }else{
660 double r;
661 clockVfs->xCurrentTime(clockVfs, &r);
662 t = (sqlite3_int64)(r*86400000.0);
663 }
664 return t;
665}
int(* xCurrentTimeInt64)(sqlite3_vfs *, sqlite3_int64 *)
Definition sqlite3.c:1832
int(* xCurrentTime)(sqlite3_vfs *, double *)
Definition sqlite3.c:1826

References sqlite3_vfs::iVersion, sqlite3_vfs_find, sqlite3_vfs::xCurrentTime, and sqlite3_vfs::xCurrentTimeInt64.

Referenced by beginTimer(), and endTimer().

Here is the caller graph for this function:

◆ toBase64()

char * toBase64 ( u8 * pIn,
int nbIn,
char * pOut )
static
5207 {
5208 int nCol = 0;
5209 while( nbIn >= 3 ){
5210 /* Do the bit-shuffle, exploiting unsigned input to avoid masking. */
5211 pOut[0] = BX_NUMERAL(pIn[0]>>2);
5212 pOut[1] = BX_NUMERAL(((pIn[0]<<4)|(pIn[1]>>4))&0x3f);
5213 pOut[2] = BX_NUMERAL(((pIn[1]&0xf)<<2)|(pIn[2]>>6));
5214 pOut[3] = BX_NUMERAL(pIn[2]&0x3f);
5215 pOut += 4;
5216 nbIn -= 3;
5217 pIn += 3;
5218 if( (nCol += 4)>=B64_DARK_MAX || nbIn<=0 ){
5219 *pOut++ = '\n';
5220 nCol = 0;
5221 }
5222 }
5223 if( nbIn > 0 ){
5224 signed char nco = nbIn+1;
5225 int nbe;
5226 unsigned long qv = *pIn++;
5227 for( nbe=1; nbe<3; ++nbe ){
5228 qv <<= 8;
5229 if( nbe<nbIn ) qv |= *pIn++;
5230 }
5231 for( nbe=3; nbe>=0; --nbe ){
5232 char ce = (nbe<nco)? BX_NUMERAL((u8)(qv & 0x3f)) : PAD_CHAR;
5233 qv >>= 6;
5234 pOut[nbe] = ce;
5235 }
5236 pOut += 4;
5237 *pOut++ = '\n';
5238 }
5239 *pOut = 0;
5240 return pOut;
5241}
#define BX_NUMERAL(dv)
Definition shell.c:5200

References B64_DARK_MAX, BX_NUMERAL, and PAD_CHAR.

Referenced by base64().

Here is the caller graph for this function:

◆ toBase85()

char * toBase85 ( u8 * pIn,
int nbIn,
char * pOut,
char * pSep )
static
5564 {
5565 int nCol = 0;
5566 while( nbIn >= 4 ){
5567 int nco = 5;
5568 unsigned long qbv = (((unsigned long)pIn[0])<<24) |
5569 (pIn[1]<<16) | (pIn[2]<<8) | pIn[3];
5570 while( nco > 0 ){
5571 unsigned nqv = (unsigned)(qbv/85UL);
5572 unsigned char dv = qbv - 85UL*nqv;
5573 qbv = nqv;
5574 pOut[--nco] = base85Numeral(dv);
5575 }
5576 nbIn -= 4;
5577 pIn += 4;
5578 pOut += 5;
5579 if( pSep && (nCol += 5)>=B85_DARK_MAX ){
5580 pOut = putcs(pOut, pSep);
5581 nCol = 0;
5582 }
5583 }
5584 if( nbIn > 0 ){
5585 int nco = nbIn + 1;
5586 unsigned long qv = *pIn++;
5587 int nbe = 1;
5588 while( nbe++ < nbIn ){
5589 qv = (qv<<8) | *pIn++;
5590 }
5591 nCol += nco;
5592 while( nco > 0 ){
5593 u8 dv = (u8)(qv % 85);
5594 qv /= 85;
5595 pOut[--nco] = base85Numeral(dv);
5596 }
5597 pOut += (nbIn+1);
5598 }
5599 if( pSep && nCol>0 ) pOut = putcs(pOut, pSep);
5600 *pOut = 0;
5601 return pOut;
5602}
#define B85_DARK_MAX
Definition shell.c:5534
static char * putcs(char *pc, char *s)
Definition shell.c:5554
#define base85Numeral(dn)
Definition shell.c:5550

References B85_DARK_MAX, base85Numeral, and putcs().

Referenced by base85().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toggleSelectOrder()

void toggleSelectOrder ( sqlite3 * db)
static
25097 {
25098 sqlite3_stmt *pStmt = 0;
25099 int iSetting = 0;
25100 char zStmt[100];
25101 sqlite3_prepare_v2(db, "PRAGMA reverse_unordered_selects", -1, &pStmt, 0);
25102 if( sqlite3_step(pStmt)==SQLITE_ROW ){
25103 iSetting = sqlite3_column_int(pStmt, 0);
25104 }
25105 sqlite3_finalize(pStmt);
25106 sqlite3_snprintf(sizeof(zStmt), zStmt,
25107 "PRAGMA reverse_unordered_selects(%d)", !iSetting);

References sqlite3_column_int, sqlite3_exec, sqlite3_finalize, sqlite3_prepare_v2, sqlite3_snprintf, sqlite3_step, and SQLITE_ROW.

Referenced by dump_callback().

Here is the caller graph for this function:

◆ trackParenLevel()

void trackParenLevel ( struct DynaPrompt * p,
int ni )
static
920 {
921 p->inParenLevel += ni;
922 if( ni==0 ) p->inParenLevel = 0;
923 p->zScannerAwaits = 0;
924}
int inParenLevel
Definition shell.c:915

References DynaPrompt::inParenLevel, and DynaPrompt::zScannerAwaits.

◆ translateForDisplayAndDup()

char * translateForDisplayAndDup ( ShellState * p,
const unsigned char * z,
const unsigned char ** pzTail,
int mxWidth,
u8 bWordWrap )
static
24195 {
24196 int i; /* Input bytes consumed */
24197 int j; /* Output bytes generated */
24198 int k; /* Input bytes to be displayed */
24199 int n; /* Output column number */
24200 unsigned char *zOut; /* Output text */
24201
24202 if( z==0 ){
24203 *pzTail = 0;
24204 return 0;
24205 }
24206 if( mxWidth<0 ) mxWidth = -mxWidth;
24207 if( mxWidth==0 ) mxWidth = 1000000;
24208 i = j = n = 0;
24209 while( n<mxWidth ){
24210 unsigned char c = z[i];
24211 if( c>=0xc0 ){
24212 int u;
24213 int len = decodeUtf8(&z[i], &u);
24214 i += len;
24215 j += len;
24216 n += cli_wcwidth(u);
24217 continue;
24218 }
24219 if( c>=' ' ){
24220 n++;
24221 i++;
24222 j++;
24223 continue;
24224 }
24225 if( c==0 || c=='\n' || (c=='\r' && z[i+1]=='\n') ) break;
24226 if( c=='\t' ){
24227 do{
24228 n++;
24229 j++;
24230 }while( (n&7)!=0 && n<mxWidth );
24231 i++;
24232 continue;
24233 }
24234 if( c==0x1b && p->eEscMode==SHELL_ESC_OFF && (k = isVt100(&z[i]))>0 ){
24235 i += k;
24236 j += k;
24237 }else{
24238 n++;
24239 j += 3;
24240 i++;
24241 }
24242 }
24243 if( n>=mxWidth && bWordWrap ){
24244 /* Perhaps try to back up to a better place to break the line */
24245 for(k=i; k>i/2; k--){
24246 if( IsSpace(z[k-1]) ) break;
24247 }
24248 if( k<=i/2 ){
24249 for(k=i; k>i/2; k--){
24250 if( IsAlnum(z[k-1])!=IsAlnum(z[k]) && (z[k]&0xc0)!=0x80 ) break;
24251 }
24252 }
24253 if( k<=i/2 ){
24254 k = i;
24255 }else{
24256 i = k;
24257 while( z[i]==' ' ) i++;
24258 }
24259 }else{
24260 k = i;
24261 }
24262 if( n>=mxWidth && z[i]>=' ' ){
24263 *pzTail = &z[i];
24264 }else if( z[i]=='\r' && z[i+1]=='\n' ){
24265 *pzTail = z[i+2] ? &z[i+2] : 0;
24266 }else if( z[i]==0 || z[i+1]==0 ){
24267 *pzTail = 0;
24268 }else{
24269 *pzTail = &z[i+1];
24270 }
24271 zOut = malloc( j+1 );
24272 shell_check_oom(zOut);
24273 i = j = n = 0;
24274 while( i<k ){
24275 unsigned char c = z[i];
24276 if( c>=0xc0 ){
24277 int u;
24278 int len = decodeUtf8(&z[i], &u);
24279 do{ zOut[j++] = z[i++]; }while( (--len)>0 );
24280 n += cli_wcwidth(u);
24281 continue;
24282 }
24283 if( c>=' ' ){
24284 n++;
24285 zOut[j++] = z[i++];
24286 continue;
24287 }
24288 if( c==0 ) break;
24289 if( z[i]=='\t' ){
24290 do{
24291 n++;
24292 zOut[j++] = ' ';
24293 }while( (n&7)!=0 && n<mxWidth );
24294 i++;
24295 continue;
24296 }
24297 switch( p->eEscMode ){
24298 case SHELL_ESC_SYMBOL:
24299 zOut[j++] = 0xe2;
24300 zOut[j++] = 0x90;
24301 zOut[j++] = 0x80 + c;
24302 break;
24303 case SHELL_ESC_ASCII:
24304 zOut[j++] = '^';
24305 zOut[j++] = 0x40 + c;
24306 break;
24307 case SHELL_ESC_OFF: {
24308 int nn;
24309 if( c==0x1b && (nn = isVt100(&z[i]))>0 ){
24310 memcpy(&zOut[j], &z[i], nn);
24311 j += nn;
24312 i += nn - 1;
24313 }else{
24314 zOut[j++] = c;
24315 }
24316 break;
24317 }
24318 }
24319 i++;
24320 }
24321 zOut[j] = 0;
static int decodeUtf8(const unsigned char *z, int *pU)
Definition shell.c:1118
int cli_wcwidth(int c)
Definition shell.c:1088
static int isVt100(const unsigned char *z)
Definition shell.c:1175

References c, cli_wcwidth(), decodeUtf8(), ShellState::eEscMode, IsAlnum, IsSpace, isVt100(), shell_check_oom(), SHELL_ESC_ASCII, SHELL_ESC_OFF, and SHELL_ESC_SYMBOL.

Referenced by exec_prepared_stmt_columnar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryToClone()

void tryToClone ( ShellState * p,
const char * zNewDb )
static
26817 {
26818 int rc;
26819 sqlite3 *newDb = 0;
26820 if( access(zNewDb,0)==0 ){
26821 sqlite3_fprintf(stderr,"File \"%s\" already exists.\n", zNewDb);
26822 return;
26823 }
26824 rc = sqlite3_open(zNewDb, &newDb);
26825 if( rc ){
26826 sqlite3_fprintf(stderr,
26827 "Cannot create output database: %s\n", sqlite3_errmsg(newDb));
26828 }else{
26829 sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0);
26830 sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0);
26831 tryToCloneSchema(p, newDb, "type='table'", tryToCloneData);
26832 tryToCloneSchema(p, newDb, "type!='table'", 0);
26833 sqlite3_exec(newDb, "COMMIT;", 0, 0, 0);
26834 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
26835 }
static void tryToCloneData(ShellState *p, sqlite3 *newDb, const char *zTable)
Definition shell.c:26624
static void tryToCloneSchema(ShellState *p, sqlite3 *newDb, const char *zWhere, void(*xForEach)(ShellState *, sqlite3 *, const char *))
Definition shell.c:26734

References close_db(), ShellState::db, sqlite3_errmsg, sqlite3_exec, sqlite3_fprintf, sqlite3_open, tryToCloneData(), and tryToCloneSchema().

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryToCloneData()

void tryToCloneData ( ShellState * p,
sqlite3 * newDb,
const char * zTable )
static
26630 {
26631 sqlite3_stmt *pQuery = 0;
26632 sqlite3_stmt *pInsert = 0;
26633 char *zQuery = 0;
26634 char *zInsert = 0;
26635 int rc;
26636 int i, j, n;
26637 int nTable = strlen30(zTable);
26638 int k = 0;
26639 int cnt = 0;
26640 const int spinRate = 10000;
26641
26642 zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
26643 shell_check_oom(zQuery);
26644 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
26645 if( rc ){
26646 sqlite3_fprintf(stderr,"Error %d: %s on [%s]\n",
26647 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), zQuery);
26648 goto end_data_xfer;
26649 }
26650 n = sqlite3_column_count(pQuery);
26651 zInsert = sqlite3_malloc64(200 + nTable + n*3);
26652 shell_check_oom(zInsert);
26653 sqlite3_snprintf(200+nTable,zInsert,
26654 "INSERT OR IGNORE INTO \"%s\" VALUES(?", zTable);
26655 i = strlen30(zInsert);
26656 for(j=1; j<n; j++){
26657 memcpy(zInsert+i, ",?", 2);
26658 i += 2;
26659 }
26660 memcpy(zInsert+i, ");", 3);
26661 rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0);
26662 if( rc ){
26663 sqlite3_fprintf(stderr,"Error %d: %s on [%s]\n",
26664 sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb), zInsert);
26665 goto end_data_xfer;
26666 }
26667 for(k=0; k<2; k++){
26668 while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
26669 for(i=0; i<n; i++){
26670 switch( sqlite3_column_type(pQuery, i) ){
26671 case SQLITE_NULL: {
26672 sqlite3_bind_null(pInsert, i+1);
26673 break;
26674 }
26675 case SQLITE_INTEGER: {
26676 sqlite3_bind_int64(pInsert, i+1, sqlite3_column_int64(pQuery,i));
26677 break;
26678 }
26679 case SQLITE_FLOAT: {
26680 sqlite3_bind_double(pInsert, i+1, sqlite3_column_double(pQuery,i));
26681 break;
26682 }
26683 case SQLITE_TEXT: {
26684 sqlite3_bind_text(pInsert, i+1,
26685 (const char*)sqlite3_column_text(pQuery,i),
26686 -1, SQLITE_STATIC);
26687 break;
26688 }
26689 case SQLITE_BLOB: {
26690 sqlite3_bind_blob(pInsert, i+1, sqlite3_column_blob(pQuery,i),
26691 sqlite3_column_bytes(pQuery,i),
26693 break;
26694 }
26695 }
26696 } /* End for */
26697 rc = sqlite3_step(pInsert);
26698 if( rc!=SQLITE_OK && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
26699 sqlite3_fprintf(stderr,"Error %d: %s\n",
26701 }
26702 sqlite3_reset(pInsert);
26703 cnt++;
26704 if( (cnt%spinRate)==0 ){
26705 printf("%c\b", "|/-\\"[(cnt/spinRate)%4]);
26706 fflush(stdout);
26707 }
26708 } /* End while */
26709 if( rc==SQLITE_DONE ) break;
26710 sqlite3_finalize(pQuery);
26711 sqlite3_free(zQuery);
26712 zQuery = sqlite3_mprintf("SELECT * FROM \"%w\" ORDER BY rowid DESC;",
26713 zTable);
26714 shell_check_oom(zQuery);
26715 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
26716 if( rc ){
26717 sqlite3_fprintf(stderr,"Warning: cannot step \"%s\" backwards", zTable);
26718 break;
26719 }
26720 } /* End for(k=0...) */
26721
26722end_data_xfer:
26723 sqlite3_finalize(pQuery);
26724 sqlite3_finalize(pInsert);
26725 sqlite3_free(zQuery);
#define sqlite3_bind_blob
Definition sqlite3ext.h:399
#define sqlite3_bind_int64
Definition sqlite3ext.h:402
#define sqlite3_extended_errcode
Definition sqlite3ext.h:572

References ShellState::db, shell_check_oom(), sqlite3_bind_blob, sqlite3_bind_double, sqlite3_bind_int64, sqlite3_bind_null, sqlite3_bind_text, sqlite3_column_blob, sqlite3_column_bytes, sqlite3_column_count, sqlite3_column_double, sqlite3_column_int64, sqlite3_column_text, sqlite3_column_type, sqlite3_errmsg, sqlite3_extended_errcode, sqlite3_finalize, sqlite3_fprintf, sqlite3_free, sqlite3_malloc64, sqlite3_mprintf, sqlite3_prepare_v2, sqlite3_reset, sqlite3_snprintf, sqlite3_step, SQLITE_BLOB, SQLITE_DONE, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, SQLITE_OK, SQLITE_ROW, SQLITE_STATIC, SQLITE_TEXT, and strlen30().

Referenced by tryToClone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryToCloneSchema()

void tryToCloneSchema ( ShellState * p,
sqlite3 * newDb,
const char * zWhere,
void(* xForEach )(ShellState *, sqlite3 *, const char *) )
static
26741 {
26742 sqlite3_stmt *pQuery = 0;
26743 char *zQuery = 0;
26744 int rc;
26745 const unsigned char *zName;
26746 const unsigned char *zSql;
26747 char *zErrMsg = 0;
26748
26749 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
26750 " WHERE %s ORDER BY rowid ASC", zWhere);
26751 shell_check_oom(zQuery);
26752 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
26753 if( rc ){
26754 sqlite3_fprintf(stderr,
26755 "Error: (%d) %s on [%s]\n", sqlite3_extended_errcode(p->db),
26756 sqlite3_errmsg(p->db), zQuery);
26757 goto end_schema_xfer;
26758 }
26759 while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
26760 zName = sqlite3_column_text(pQuery, 0);
26761 zSql = sqlite3_column_text(pQuery, 1);
26762 if( zName==0 || zSql==0 ) continue;
26763 if( sqlite3_stricmp((char*)zName, "sqlite_sequence")!=0 ){
26764 sqlite3_fprintf(stdout, "%s... ", zName); fflush(stdout);
26765 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
26766 if( zErrMsg ){
26767 sqlite3_fprintf(stderr,"Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
26768 sqlite3_free(zErrMsg);
26769 zErrMsg = 0;
26770 }
26771 }
26772 if( xForEach ){
26773 xForEach(p, newDb, (const char*)zName);
26774 }
26775 sputz(stdout, "done\n");
26776 }
26777 if( rc!=SQLITE_DONE ){
26778 sqlite3_finalize(pQuery);
26779 sqlite3_free(zQuery);
26780 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
26781 " WHERE %s ORDER BY rowid DESC", zWhere);
26782 shell_check_oom(zQuery);
26783 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
26784 if( rc ){
26785 sqlite3_fprintf(stderr,"Error: (%d) %s on [%s]\n",
26786 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), zQuery);
26787 goto end_schema_xfer;
26788 }
26789 while( sqlite3_step(pQuery)==SQLITE_ROW ){
26790 zName = sqlite3_column_text(pQuery, 0);
26791 zSql = sqlite3_column_text(pQuery, 1);
26792 if( zName==0 || zSql==0 ) continue;
26793 if( sqlite3_stricmp((char*)zName, "sqlite_sequence")==0 ) continue;
26794 sqlite3_fprintf(stdout, "%s... ", zName); fflush(stdout);
26795 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
26796 if( zErrMsg ){
26797 sqlite3_fprintf(stderr,"Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
26798 sqlite3_free(zErrMsg);
26799 zErrMsg = 0;
26800 }
26801 if( xForEach ){
26802 xForEach(p, newDb, (const char*)zName);
26803 }
26804 sputz(stdout, "done\n");
26805 }
26806 }
26807end_schema_xfer:
26808 sqlite3_finalize(pQuery);

References ShellState::db, shell_check_oom(), sputz, sqlite3_column_text, sqlite3_errmsg, sqlite3_exec, sqlite3_extended_errcode, sqlite3_finalize, sqlite3_fprintf, sqlite3_free, sqlite3_mprintf, sqlite3_prepare_v2, sqlite3_step, sqlite3_stricmp, SQLITE_DONE, and SQLITE_ROW.

Referenced by tryToClone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uintCollFunc()

int uintCollFunc ( void * notUsed,
int nKey1,
const void * pKey1,
int nKey2,
const void * pKey2 )
static
3644 {
3645 const unsigned char *zA = (const unsigned char*)pKey1;
3646 const unsigned char *zB = (const unsigned char*)pKey2;
3647 int i=0, j=0, x;
3648 (void)notUsed;
3649 while( i<nKey1 && j<nKey2 ){
3650 x = zA[i] - zB[j];
3651 if( isdigit(zA[i]) ){
3652 int k;
3653 if( !isdigit(zB[j]) ) return x;
3654 while( i<nKey1 && zA[i]=='0' ){ i++; }
3655 while( j<nKey2 && zB[j]=='0' ){ j++; }
3656 k = 0;
3657 while( i+k<nKey1 && isdigit(zA[i+k])
3658 && j+k<nKey2 && isdigit(zB[j+k]) ){
3659 k++;
3660 }
3661 if( i+k<nKey1 && isdigit(zA[i+k]) ){
3662 return +1;
3663 }else if( j+k<nKey2 && isdigit(zB[j+k]) ){
3664 return -1;
3665 }else{
3666 x = memcmp(zA+i, zB+j, k);
3667 if( x ) return x;
3668 i += k;
3669 j += k;
3670 }
3671 }else if( x ){
3672 return x;
3673 }else{
3674 i++;
3675 j++;
3676 }
3677 }
3678 return (nKey1 - i) - (nKey2 - j);
3679}

Referenced by sqlite3_uint_init().

Here is the caller graph for this function:

◆ usage()

void usage ( int showDetail)
static
33098 {
33099 sqlite3_fprintf(stderr,"Usage: %s [OPTIONS] [FILENAME [SQL...]]\n"
33100 "FILENAME is the name of an SQLite database. A new database is created\n"
33101 "if the file does not previously exist. Defaults to :memory:.\n", Argv0);
33102 if( showDetail ){
33103 sqlite3_fprintf(stderr,"OPTIONS include:\n%s", zOptions);
33104 }else{
33105 eputz("Use the -help option for additional information\n");
33106 }
static const char zOptions[]
Definition shell.c:33032

References Argv0, eputz, sqlite3_fprintf, and zOptions.

Referenced by lintDotCommand(), and main().

Here is the caller graph for this function:

◆ useDummyCS()

void useDummyCS ( void * up1,
sqlite3 * db,
int etr,
const char * zName )
14670 {
14671 (void)up1;
14672 sqlite3_create_collation_v2(db, zName, etr, 0, dummyCompare, 0);
14673}
int dummyCompare(void *up1, int up2, const void *up3, int up4, const void *up5)
Definition shell.c:14660
#define sqlite3_create_collation_v2
Definition sqlite3ext.h:532

References dummyCompare(), and sqlite3_create_collation_v2.

Referenced by sqlite3_expert_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf8_width_print()

void utf8_width_print ( FILE * out,
int w,
const char * zUtf )
static
1195 {
1196 const unsigned char *a = (const unsigned char*)zUtf;
1197 unsigned char c;
1198 int i = 0;
1199 int n = 0;
1200 int k;
1201 int aw = w<0 ? -w : w;
1202 if( zUtf==0 ) zUtf = "";
1203 while( (c = a[i])!=0 ){
1204 if( (c&0xc0)==0xc0 ){
1205 int u;
1206 int len = decodeUtf8(a+i, &u);
1207 int x = cli_wcwidth(u);
1208 if( x+n>aw ){
1209 break;
1210 }
1211 i += len;
1212 n += x;
1213 }else if( c==0x1b && (k = isVt100(&a[i]))>0 ){
1214 i += k;
1215 }else if( n>=aw ){
1216 break;
1217 }else{
1218 n++;
1219 i++;
1220 }
1221 }
1222 if( n>=aw ){
1223 sqlite3_fprintf(out, "%.*s", i, zUtf);
1224 }else if( w<0 ){
1225 sqlite3_fprintf(out, "%*s%s", aw-n, "", zUtf);
1226 }else{
1227 sqlite3_fprintf(out, "%s%*s", zUtf, aw-n, "");
1228 }
1229}

References a, c, cli_wcwidth(), decodeUtf8(), isVt100(), and sqlite3_fprintf.

Referenced by exec_prepared_stmt_columnar(), and shell_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_uninitialized()

void verify_uninitialized ( void )
static
33114 {
33115 if( sqlite3_config(-1)==SQLITE_MISUSE ){
33116 sputz(stdout, "WARNING: attempt to configure SQLite after"
33117 " initialization.\n");

References sputz, sqlite3_config(), and SQLITE_MISUSE.

Referenced by main(), and main_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstrace_errcode_name()

const char * vfstrace_errcode_name ( int rc)
static
16478 {
16479 const char *zVal = 0;
16480 switch( rc ){
16481 case SQLITE_OK: zVal = "SQLITE_OK"; break;
16482 case SQLITE_INTERNAL: zVal = "SQLITE_INTERNAL"; break;
16483 case SQLITE_ERROR: zVal = "SQLITE_ERROR"; break;
16484 case SQLITE_PERM: zVal = "SQLITE_PERM"; break;
16485 case SQLITE_ABORT: zVal = "SQLITE_ABORT"; break;
16486 case SQLITE_BUSY: zVal = "SQLITE_BUSY"; break;
16487 case SQLITE_LOCKED: zVal = "SQLITE_LOCKED"; break;
16488 case SQLITE_NOMEM: zVal = "SQLITE_NOMEM"; break;
16489 case SQLITE_READONLY: zVal = "SQLITE_READONLY"; break;
16490 case SQLITE_INTERRUPT: zVal = "SQLITE_INTERRUPT"; break;
16491 case SQLITE_IOERR: zVal = "SQLITE_IOERR"; break;
16492 case SQLITE_CORRUPT: zVal = "SQLITE_CORRUPT"; break;
16493 case SQLITE_NOTFOUND: zVal = "SQLITE_NOTFOUND"; break;
16494 case SQLITE_FULL: zVal = "SQLITE_FULL"; break;
16495 case SQLITE_CANTOPEN: zVal = "SQLITE_CANTOPEN"; break;
16496 case SQLITE_PROTOCOL: zVal = "SQLITE_PROTOCOL"; break;
16497 case SQLITE_EMPTY: zVal = "SQLITE_EMPTY"; break;
16498 case SQLITE_SCHEMA: zVal = "SQLITE_SCHEMA"; break;
16499 case SQLITE_TOOBIG: zVal = "SQLITE_TOOBIG"; break;
16500 case SQLITE_CONSTRAINT: zVal = "SQLITE_CONSTRAINT"; break;
16501 case SQLITE_MISMATCH: zVal = "SQLITE_MISMATCH"; break;
16502 case SQLITE_MISUSE: zVal = "SQLITE_MISUSE"; break;
16503 case SQLITE_NOLFS: zVal = "SQLITE_NOLFS"; break;
16504 case SQLITE_IOERR_READ: zVal = "SQLITE_IOERR_READ"; break;
16505 case SQLITE_IOERR_SHORT_READ: zVal = "SQLITE_IOERR_SHORT_READ"; break;
16506 case SQLITE_IOERR_WRITE: zVal = "SQLITE_IOERR_WRITE"; break;
16507 case SQLITE_IOERR_FSYNC: zVal = "SQLITE_IOERR_FSYNC"; break;
16508 case SQLITE_IOERR_DIR_FSYNC: zVal = "SQLITE_IOERR_DIR_FSYNC"; break;
16509 case SQLITE_IOERR_TRUNCATE: zVal = "SQLITE_IOERR_TRUNCATE"; break;
16510 case SQLITE_IOERR_FSTAT: zVal = "SQLITE_IOERR_FSTAT"; break;
16511 case SQLITE_IOERR_UNLOCK: zVal = "SQLITE_IOERR_UNLOCK"; break;
16512 case SQLITE_IOERR_RDLOCK: zVal = "SQLITE_IOERR_RDLOCK"; break;
16513 case SQLITE_IOERR_DELETE: zVal = "SQLITE_IOERR_DELETE"; break;
16514 case SQLITE_IOERR_BLOCKED: zVal = "SQLITE_IOERR_BLOCKED"; break;
16515 case SQLITE_IOERR_NOMEM: zVal = "SQLITE_IOERR_NOMEM"; break;
16516 case SQLITE_IOERR_ACCESS: zVal = "SQLITE_IOERR_ACCESS"; break;
16518 zVal = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
16519 case SQLITE_IOERR_LOCK: zVal = "SQLITE_IOERR_LOCK"; break;
16520 case SQLITE_IOERR_CLOSE: zVal = "SQLITE_IOERR_CLOSE"; break;
16521 case SQLITE_IOERR_DIR_CLOSE: zVal = "SQLITE_IOERR_DIR_CLOSE"; break;
16522 case SQLITE_IOERR_SHMOPEN: zVal = "SQLITE_IOERR_SHMOPEN"; break;
16523 case SQLITE_IOERR_SHMSIZE: zVal = "SQLITE_IOERR_SHMSIZE"; break;
16524 case SQLITE_IOERR_SHMLOCK: zVal = "SQLITE_IOERR_SHMLOCK"; break;
16525 case SQLITE_IOERR_SHMMAP: zVal = "SQLITE_IOERR_SHMMAP"; break;
16526 case SQLITE_IOERR_SEEK: zVal = "SQLITE_IOERR_SEEK"; break;
16527 case SQLITE_IOERR_GETTEMPPATH: zVal = "SQLITE_IOERR_GETTEMPPATH"; break;
16528 case SQLITE_IOERR_CONVPATH: zVal = "SQLITE_IOERR_CONVPATH"; break;
16529 case SQLITE_READONLY_DBMOVED: zVal = "SQLITE_READONLY_DBMOVED"; break;
16530 case SQLITE_LOCKED_SHAREDCACHE: zVal = "SQLITE_LOCKED_SHAREDCACHE"; break;
16531 case SQLITE_BUSY_RECOVERY: zVal = "SQLITE_BUSY_RECOVERY"; break;
16532 case SQLITE_CANTOPEN_NOTEMPDIR: zVal = "SQLITE_CANTOPEN_NOTEMPDIR"; break;
16533 }
16534 return zVal;
16535}
#define SQLITE_IOERR_SHMSIZE
Definition sqlite3.c:837
#define SQLITE_INTERRUPT
Definition sqlite3.c:775
#define SQLITE_IOERR_GETTEMPPATH
Definition sqlite3.c:843
#define SQLITE_SCHEMA
Definition sqlite3.c:783
#define SQLITE_READONLY
Definition sqlite3.c:774
#define SQLITE_IOERR_WRITE
Definition sqlite3.c:821
#define SQLITE_IOERR_CLOSE
Definition sqlite3.c:834
#define SQLITE_IOERR_CONVPATH
Definition sqlite3.c:844
#define SQLITE_IOERR_SHMOPEN
Definition sqlite3.c:836
#define SQLITE_IOERR_TRUNCATE
Definition sqlite3.c:824
#define SQLITE_IOERR_SHORT_READ
Definition sqlite3.c:820
#define SQLITE_IOERR_NOMEM
Definition sqlite3.c:830
#define SQLITE_NOLFS
Definition sqlite3.c:788
#define SQLITE_READONLY_DBMOVED
Definition sqlite3.c:870
#define SQLITE_IOERR_DELETE
Definition sqlite3.c:828
#define SQLITE_INTERNAL
Definition sqlite3.c:768
#define SQLITE_IOERR_SHMMAP
Definition sqlite3.c:839
#define SQLITE_IOERR_LOCK
Definition sqlite3.c:833
#define SQLITE_MISMATCH
Definition sqlite3.c:786
#define SQLITE_IOERR_BLOCKED
Definition sqlite3.c:829
#define SQLITE_LOCKED_SHAREDCACHE
Definition sqlite3.c:853
#define SQLITE_IOERR_UNLOCK
Definition sqlite3.c:826
#define SQLITE_IOERR_DIR_FSYNC
Definition sqlite3.c:823
#define SQLITE_IOERR_DIR_CLOSE
Definition sqlite3.c:835
#define SQLITE_IOERR_FSTAT
Definition sqlite3.c:825
#define SQLITE_PROTOCOL
Definition sqlite3.c:781
#define SQLITE_IOERR_READ
Definition sqlite3.c:819
#define SQLITE_IOERR_SEEK
Definition sqlite3.c:840
#define SQLITE_IOERR_ACCESS
Definition sqlite3.c:831
#define SQLITE_IOERR_RDLOCK
Definition sqlite3.c:827
#define SQLITE_EMPTY
Definition sqlite3.c:782
#define SQLITE_BUSY_RECOVERY
Definition sqlite3.c:855
#define SQLITE_IOERR_FSYNC
Definition sqlite3.c:822
#define SQLITE_IOERR_CHECKRESERVEDLOCK
Definition sqlite3.c:832
#define SQLITE_PERM
Definition sqlite3.c:769
#define SQLITE_CANTOPEN_NOTEMPDIR
Definition sqlite3.c:858
#define SQLITE_IOERR_SHMLOCK
Definition sqlite3.c:838

References SQLITE_ABORT, SQLITE_BUSY, SQLITE_BUSY_RECOVERY, SQLITE_CANTOPEN, SQLITE_CANTOPEN_NOTEMPDIR, SQLITE_CONSTRAINT, SQLITE_CORRUPT, SQLITE_EMPTY, SQLITE_ERROR, SQLITE_FULL, SQLITE_INTERNAL, SQLITE_INTERRUPT, SQLITE_IOERR, SQLITE_IOERR_ACCESS, SQLITE_IOERR_BLOCKED, SQLITE_IOERR_CHECKRESERVEDLOCK, SQLITE_IOERR_CLOSE, SQLITE_IOERR_CONVPATH, SQLITE_IOERR_DELETE, SQLITE_IOERR_DIR_CLOSE, SQLITE_IOERR_DIR_FSYNC, SQLITE_IOERR_FSTAT, SQLITE_IOERR_FSYNC, SQLITE_IOERR_GETTEMPPATH, SQLITE_IOERR_LOCK, SQLITE_IOERR_NOMEM, SQLITE_IOERR_RDLOCK, SQLITE_IOERR_READ, SQLITE_IOERR_SEEK, SQLITE_IOERR_SHMLOCK, SQLITE_IOERR_SHMMAP, SQLITE_IOERR_SHMOPEN, SQLITE_IOERR_SHMSIZE, SQLITE_IOERR_SHORT_READ, SQLITE_IOERR_TRUNCATE, SQLITE_IOERR_UNLOCK, SQLITE_IOERR_WRITE, SQLITE_LOCKED, SQLITE_LOCKED_SHAREDCACHE, SQLITE_MISMATCH, SQLITE_MISUSE, SQLITE_NOLFS, SQLITE_NOMEM, SQLITE_NOTFOUND, SQLITE_OK, SQLITE_PERM, SQLITE_PROTOCOL, SQLITE_READONLY, SQLITE_READONLY_DBMOVED, SQLITE_SCHEMA, and SQLITE_TOOBIG.

Referenced by vfstrace_print_errcode().

Here is the caller graph for this function:

◆ vfstrace_print_errcode()

void vfstrace_print_errcode ( vfstrace_info * pInfo,
const char * zFormat,
int rc )
static
16545 {
16546 const char *zVal;
16547 char zBuf[50];
16548 zVal = vfstrace_errcode_name(rc);
16549 if( zVal==0 ){
16550 zVal = vfstrace_errcode_name(rc&0xff);
16551 if( zVal ){
16552 sqlite3_snprintf(sizeof(zBuf), zBuf, "%s | 0x%x", zVal, rc&0xffff00);
16553 }else{
16554 sqlite3_snprintf(sizeof(zBuf), zBuf, "%d (0x%x)", rc, rc);
16555 }
16556 zVal = zBuf;
16557 }
16558 vfstrace_printf(pInfo, zFormat, zVal);
16559}
static void vfstrace_printf(vfstrace_info *pInfo, const char *zFormat,...)
Definition shell.c:16459
static const char * vfstrace_errcode_name(int rc)
Definition shell.c:16478

References sqlite3_snprintf, vfstrace_errcode_name(), and vfstrace_printf().

Referenced by vfstraceAccess(), vfstraceCheckReservedLock(), vfstraceClose(), vfstraceDelete(), vfstraceFetch(), vfstraceFileControl(), vfstraceFileSize(), vfstraceFullPathname(), vfstraceLock(), vfstraceOpen(), vfstraceRead(), vfstraceShmLock(), vfstraceShmMap(), vfstraceShmUnmap(), vfstraceUnfetch(), vfstraceUnlock(), and vfstraceWrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstrace_printf()

void vfstrace_printf ( vfstrace_info * pInfo,
const char * zFormat,
... )
static

◆ vfstrace_register()

int vfstrace_register ( const char * zTraceName,
const char * zOldVfsName,
int(* xOut )(const char *, void *),
void * pOutArg,
int makeDefault )
17353 {
17354 sqlite3_vfs *pNew;
17355 sqlite3_vfs *pRoot;
17356 vfstrace_info *pInfo;
17357 size_t nName;
17358 size_t nByte;
17359
17360 pRoot = sqlite3_vfs_find(zOldVfsName);
17361 if( pRoot==0 ) return SQLITE_NOTFOUND;
17362 nName = strlen(zTraceName);
17363 nByte = sizeof(*pNew) + sizeof(*pInfo) + nName + 1;
17364 pNew = sqlite3_malloc64( nByte );
17365 if( pNew==0 ) return SQLITE_NOMEM;
17366 memset(pNew, 0, nByte);
17367 pInfo = (vfstrace_info*)&pNew[1];
17368 pNew->iVersion = pRoot->iVersion;
17369 pNew->szOsFile = pRoot->szOsFile + sizeof(vfstrace_file);
17370 pNew->mxPathname = pRoot->mxPathname;
17371 pNew->zName = (char*)&pInfo[1];
17372 memcpy((char*)&pInfo[1], zTraceName, nName+1);
17373 pNew->pAppData = pInfo;
17374 pNew->xOpen = vfstraceOpen;
17375 pNew->xDelete = vfstraceDelete;
17376 pNew->xAccess = vfstraceAccess;
17378 pNew->xDlOpen = pRoot->xDlOpen==0 ? 0 : vfstraceDlOpen;
17379 pNew->xDlError = pRoot->xDlError==0 ? 0 : vfstraceDlError;
17380 pNew->xDlSym = pRoot->xDlSym==0 ? 0 : vfstraceDlSym;
17381 pNew->xDlClose = pRoot->xDlClose==0 ? 0 : vfstraceDlClose;
17383 pNew->xSleep = vfstraceSleep;
17385 pNew->xGetLastError = pRoot->xGetLastError==0 ? 0 : vfstraceGetLastError;
17386 if( pNew->iVersion>=2 ){
17387 pNew->xCurrentTimeInt64 = pRoot->xCurrentTimeInt64==0 ? 0 :
17389 if( pNew->iVersion>=3 ){
17390 pNew->xSetSystemCall = pRoot->xSetSystemCall==0 ? 0 :
17392 pNew->xGetSystemCall = pRoot->xGetSystemCall==0 ? 0 :
17394 pNew->xNextSystemCall = pRoot->xNextSystemCall==0 ? 0 :
17396 }
17397 }
17398 pInfo->pRootVfs = pRoot;
17399 pInfo->xOut = xOut;
17400 pInfo->pOutArg = pOutArg;
17401 pInfo->zVfsName = pNew->zName;
17402 pInfo->pTraceVfs = pNew;
17403 pInfo->mTrace = 0xffffffff;
17404 pInfo->bOn = 1;
17405 vfstrace_printf(pInfo, "%s.enabled_for(\"%s\")\n",
17406 pInfo->zVfsName, pRoot->zName);
17407 return sqlite3_vfs_register(pNew, makeDefault);
17408}
static void vfstraceDlError(sqlite3_vfs *, int nByte, char *zErrMsg)
Definition shell.c:17219
static int vfstraceFullPathname(sqlite3_vfs *, const char *zName, int, char *)
Definition shell.c:17185
static int vfstraceDelete(sqlite3_vfs *, const char *zName, int syncDir)
Definition shell.c:17146
static int vfstraceSetSystemCall(sqlite3_vfs *, const char *, sqlite3_syscall_ptr)
Definition shell.c:17315
static sqlite3_syscall_ptr vfstraceGetSystemCall(sqlite3_vfs *, const char *)
Definition shell.c:17324
static int vfstraceOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int *)
Definition shell.c:17085
sqlite3_vfs * pTraceVfs
Definition shell.c:16355
static const char * vfstraceNextSystemCall(sqlite3_vfs *, const char *zName)
Definition shell.c:17332
static int vfstraceCurrentTime(sqlite3_vfs *, double *)
Definition shell.c:17276
static void * vfstraceDlOpen(sqlite3_vfs *, const char *zFilename)
Definition shell.c:17206
unsigned int mTrace
Definition shell.c:16351
sqlite3_vfs * pRootVfs
Definition shell.c:16349
static int vfstraceAccess(sqlite3_vfs *, const char *zName, int flags, int *)
Definition shell.c:17162
static int vfstraceCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64 *)
Definition shell.c:17286
const char * zVfsName
Definition shell.c:16354
static void vfstraceDlClose(sqlite3_vfs *, void *)
Definition shell.c:17241
static void(*)(void) vfstraceDlSym(sqlite3_vfs *, void *, const char *zSymbol)
Definition shell.c:16431
static int vfstraceSleep(sqlite3_vfs *, int microseconds)
Definition shell.c:17265
static int vfstraceGetLastError(sqlite3_vfs *, int, char *)
Definition shell.c:17300
static int vfstraceRandomness(sqlite3_vfs *, int nByte, char *zOut)
Definition shell.c:17253
Definition shell.c:16362
Definition shell.c:16348
int(* xFullPathname)(sqlite3_vfs *, const char *zName, int nOut, char *zOut)
Definition sqlite3.c:1819
void(*(* xDlSym)(sqlite3_vfs *, void *, const char *zSymbol))(void)
Definition sqlite3.c:1822
void(* xDlError)(sqlite3_vfs *, int nByte, char *zErrMsg)
Definition sqlite3.c:1821
int(* xGetLastError)(sqlite3_vfs *, int, char *)
Definition sqlite3.c:1827
int(* xDelete)(sqlite3_vfs *, const char *zName, int syncDir)
Definition sqlite3.c:1817
sqlite3_syscall_ptr(* xGetSystemCall)(sqlite3_vfs *, const char *zName)
Definition sqlite3.c:1838
int(* xSetSystemCall)(sqlite3_vfs *, const char *zName, sqlite3_syscall_ptr)
Definition sqlite3.c:1837
void * pAppData
Definition sqlite3.c:1814
int(* xSleep)(sqlite3_vfs *, int microseconds)
Definition sqlite3.c:1825
int(* xAccess)(sqlite3_vfs *, const char *zName, int flags, int *pResOut)
Definition sqlite3.c:1818
const char *(* xNextSystemCall)(sqlite3_vfs *, const char *zName)
Definition sqlite3.c:1839
int(* xRandomness)(sqlite3_vfs *, int nByte, char *zOut)
Definition sqlite3.c:1824
void *(* xDlOpen)(sqlite3_vfs *, const char *zFilename)
Definition sqlite3.c:1820
void(* xDlClose)(sqlite3_vfs *, void *)
Definition sqlite3.c:1823

References vfstrace_info::bOn, sqlite3_vfs::iVersion, vfstrace_info::mTrace, sqlite3_vfs::mxPathname, sqlite3_vfs::pAppData, vfstrace_info::pOutArg, vfstrace_info::pRootVfs, vfstrace_info::pTraceVfs, sqlite3_malloc64, sqlite3_vfs_find, sqlite3_vfs_register, SQLITE_NOMEM, SQLITE_NOTFOUND, sqlite3_vfs::szOsFile, vfstrace_printf(), vfstraceAccess(), vfstraceCurrentTime(), vfstraceCurrentTimeInt64(), vfstraceDelete(), vfstraceDlClose(), vfstraceDlError(), vfstraceDlOpen(), vfstraceDlSym, vfstraceFullPathname(), vfstraceGetLastError(), vfstraceGetSystemCall(), vfstraceNextSystemCall(), vfstraceOpen(), vfstraceRandomness(), vfstraceSetSystemCall(), vfstraceSleep(), sqlite3_vfs::xAccess, sqlite3_vfs::xCurrentTime, sqlite3_vfs::xCurrentTimeInt64, sqlite3_vfs::xDelete, sqlite3_vfs::xDlClose, sqlite3_vfs::xDlError, sqlite3_vfs::xDlOpen, sqlite3_vfs::xDlSym, sqlite3_vfs::xFullPathname, sqlite3_vfs::xGetLastError, sqlite3_vfs::xGetSystemCall, sqlite3_vfs::xNextSystemCall, sqlite3_vfs::xOpen, vfstrace_info::xOut, sqlite3_vfs::xRandomness, sqlite3_vfs::xSetSystemCall, sqlite3_vfs::xSleep, sqlite3_vfs::zName, and vfstrace_info::zVfsName.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstrace_unregister()

void vfstrace_unregister ( const char * zTraceName)
17414 {
17415 sqlite3_vfs *pVfs = sqlite3_vfs_find(zTraceName);
17416 if( pVfs==0 ) return;
17417 if( pVfs->xOpen!=vfstraceOpen ) return;
17419 sqlite3_free(pVfs);
17420}
#define sqlite3_vfs_unregister
Definition sqlite3ext.h:549

References sqlite3_free, sqlite3_vfs_find, sqlite3_vfs_unregister, vfstraceOpen(), and sqlite3_vfs::xOpen.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceAccess()

int vfstraceAccess ( sqlite3_vfs * pVfs,
const char * zName,
int flags,
int * pResOut )
static
17167 {
17168 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17169 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17170 int rc;
17171 vfstraceOnOff(pInfo, VTR_ACCESS);
17172 vfstrace_printf(pInfo, "%s.xAccess(\"%s\",%d)",
17173 pInfo->zVfsName, zPath, flags);
17174 rc = pRoot->xAccess(pRoot, zPath, flags, pResOut);
17175 vfstrace_print_errcode(pInfo, " -> %s", rc);
17176 vfstrace_printf(pInfo, ", out=%d\n", *pResOut);
17177 return rc;
17178}
static void vfstrace_print_errcode(vfstrace_info *pInfo, const char *zFormat, int rc)
Definition shell.c:16541
#define VTR_ACCESS
Definition shell.c:16390
static void vfstraceOnOff(vfstrace_info *pInfo, unsigned int mMask)
Definition shell.c:16574

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_ACCESS, sqlite3_vfs::xAccess, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceCheckReservedLock()

int vfstraceCheckReservedLock ( sqlite3_file * pFile,
int * pResOut )
static
16738 {
16739 vfstrace_file *p = (vfstrace_file *)pFile;
16740 vfstrace_info *pInfo = p->pInfo;
16741 int rc;
16742 vfstraceOnOff(pInfo, VTR_CRL);
16743 vfstrace_printf(pInfo, "%s.xCheckReservedLock(%s,%d)",
16744 pInfo->zVfsName, p->zFName);
16745 rc = p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut);
16746 vfstrace_print_errcode(pInfo, " -> %s", rc);
16747 vfstrace_printf(pInfo, ", out=%d\n", *pResOut);
16748 return rc;
16749}
#define VTR_CRL
Definition shell.c:16380
sqlite3_file * pReal
Definition shell.c:16366
vfstrace_info * pInfo
Definition shell.c:16364
const char * zFName
Definition shell.c:16365

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_CRL, sqlite3_io_methods::xCheckReservedLock, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceClose()

int vfstraceClose ( sqlite3_file * pFile)
static
16581 {
16582 vfstrace_file *p = (vfstrace_file *)pFile;
16583 vfstrace_info *pInfo = p->pInfo;
16584 int rc;
16585 vfstraceOnOff(pInfo, VTR_CLOSE);
16586 vfstrace_printf(pInfo, "%s.xClose(%s)", pInfo->zVfsName, p->zFName);
16587 rc = p->pReal->pMethods->xClose(p->pReal);
16588 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
16589 if( rc==SQLITE_OK ){
16590 sqlite3_free((void*)p->base.pMethods);
16591 p->base.pMethods = 0;
16592 }
16593 return rc;
16594}
sqlite3_file base
Definition shell.c:16363
#define VTR_CLOSE
Definition shell.c:16372

References vfstrace_file::base, vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, sqlite3_free, SQLITE_OK, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_CLOSE, sqlite3_io_methods::xClose, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceCurrentTime()

int vfstraceCurrentTime ( sqlite3_vfs * pVfs,
double * pTimeOut )
static
17276 {
17277 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17278 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17279 int rc;
17280 vfstraceOnOff(pInfo, VTR_CURTIME);
17281 vfstrace_printf(pInfo, "%s.xCurrentTime()", pInfo->zVfsName);
17282 rc = pRoot->xCurrentTime(pRoot, pTimeOut);
17283 vfstrace_printf(pInfo, " -> %.17g\n", *pTimeOut);
17284 return rc;
17285}
#define VTR_CURTIME
Definition shell.c:16398

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_printf(), vfstraceOnOff(), VTR_CURTIME, sqlite3_vfs::xCurrentTime, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceCurrentTimeInt64()

int vfstraceCurrentTimeInt64 ( sqlite3_vfs * pVfs,
sqlite3_int64 * pTimeOut )
static
17286 {
17287 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17288 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17289 int rc;
17290 vfstraceOnOff(pInfo, VTR_CURTIME);
17291 vfstrace_printf(pInfo, "%s.xCurrentTimeInt64()", pInfo->zVfsName);
17292 rc = pRoot->xCurrentTimeInt64(pRoot, pTimeOut);
17293 vfstrace_printf(pInfo, " -> %lld\n", *pTimeOut);
17294 return rc;
17295}

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_printf(), vfstraceOnOff(), VTR_CURTIME, sqlite3_vfs::xCurrentTimeInt64, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceDelete()

int vfstraceDelete ( sqlite3_vfs * pVfs,
const char * zName,
int syncDir )
static
17146 {
17147 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17148 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17149 int rc;
17150 vfstraceOnOff(pInfo, VTR_DELETE);
17151 vfstrace_printf(pInfo, "%s.xDelete(\"%s\",%d)",
17152 pInfo->zVfsName, zPath, dirSync);
17153 rc = pRoot->xDelete(pRoot, zPath, dirSync);
17154 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
17155 return rc;
17156}
#define VTR_DELETE
Definition shell.c:16389

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_DELETE, sqlite3_vfs::xDelete, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceDeviceCharacteristics()

int vfstraceDeviceCharacteristics ( sqlite3_file * pFile)
static
16970 {
16971 vfstrace_file *p = (vfstrace_file *)pFile;
16972 vfstrace_info *pInfo = p->pInfo;
16973 int rc;
16974 vfstraceOnOff(pInfo, VTR_DEVCHAR);
16975 vfstrace_printf(pInfo, "%s.xDeviceCharacteristics(%s)",
16976 pInfo->zVfsName, p->zFName);
16978 vfstrace_printf(pInfo, " -> 0x%08x\n", rc);
16979 return rc;
16980}
#define VTR_DEVCHAR
Definition shell.c:16383

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_printf(), vfstraceOnOff(), VTR_DEVCHAR, sqlite3_io_methods::xDeviceCharacteristics, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceDlClose()

void vfstraceDlClose ( sqlite3_vfs * pVfs,
void * pHandle )
static
17241 {
17242 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17243 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17244 vfstraceOnOff(pInfo, VTR_DLCLOSE);
17245 vfstrace_printf(pInfo, "%s.xDlClose()\n", pInfo->zVfsName);
17246 pRoot->xDlClose(pRoot, pHandle);
17247}
#define VTR_DLCLOSE
Definition shell.c:16395

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_printf(), vfstraceOnOff(), VTR_DLCLOSE, sqlite3_vfs::xDlClose, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceDlError()

void vfstraceDlError ( sqlite3_vfs * pVfs,
int nByte,
char * zErrMsg )
static
17219 {
17220 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17221 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17222 vfstraceOnOff(pInfo, VTR_DLERR);
17223 vfstrace_printf(pInfo, "%s.xDlError(%d)", pInfo->zVfsName, nByte);
17224 pRoot->xDlError(pRoot, nByte, zErrMsg);
17225 vfstrace_printf(pInfo, " -> \"%s\"", zErrMsg);
17226}
#define VTR_DLERR
Definition shell.c:16393

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_printf(), vfstraceOnOff(), VTR_DLERR, sqlite3_vfs::xDlError, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceDlOpen()

void * vfstraceDlOpen ( sqlite3_vfs * pVfs,
const char * zFilename )
static
17206 {
17207 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17208 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17209 vfstraceOnOff(pInfo, VTR_DLOPEN);
17210 vfstrace_printf(pInfo, "%s.xDlOpen(\"%s\")\n", pInfo->zVfsName, zPath);
17211 return pRoot->xDlOpen(pRoot, zPath);
17212}
#define VTR_DLOPEN
Definition shell.c:16392

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_printf(), vfstraceOnOff(), VTR_DLOPEN, sqlite3_vfs::xDlOpen, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceFetch()

int vfstraceFetch ( sqlite3_file * pFile,
i64 iOff,
int nAmt,
void ** pptr )
static
17058 {
17059 vfstrace_file *p = (vfstrace_file *)pFile;
17060 vfstrace_info *pInfo = p->pInfo;
17061 int rc;
17062 vfstraceOnOff(pInfo, VTR_FETCH);
17063 vfstrace_printf(pInfo, "%s.xFetch(%s,iOff=%lld,nAmt=%d,p=%p)",
17064 pInfo->zVfsName, p->zFName, iOff, nAmt, *pptr);
17065 rc = p->pReal->pMethods->xFetch(p->pReal, iOff, nAmt, pptr);
17066 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
17067 return rc;
17068}
#define VTR_FETCH
Definition shell.c:16400

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_FETCH, sqlite3_io_methods::xFetch, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceFileControl()

int vfstraceFileControl ( sqlite3_file * pFile,
int op,
void * pArg )
static
16754 {
16755 vfstrace_file *p = (vfstrace_file *)pFile;
16756 vfstrace_info *pInfo = p->pInfo;
16757 int rc;
16758 char zBuf[100];
16759 char zBuf2[100];
16760 char *zOp;
16761 char *zRVal = 0;
16762 vfstraceOnOff(pInfo, VTR_FCTRL);
16763 switch( op ){
16764 case SQLITE_FCNTL_LOCKSTATE: zOp = "LOCKSTATE"; break;
16765 case SQLITE_GET_LOCKPROXYFILE: zOp = "GET_LOCKPROXYFILE"; break;
16766 case SQLITE_SET_LOCKPROXYFILE: zOp = "SET_LOCKPROXYFILE"; break;
16767 case SQLITE_LAST_ERRNO: zOp = "LAST_ERRNO"; break;
16769 sqlite3_snprintf(sizeof(zBuf), zBuf, "SIZE_HINT,%lld",
16770 *(sqlite3_int64*)pArg);
16771 zOp = zBuf;
16772 break;
16773 }
16775 sqlite3_snprintf(sizeof(zBuf), zBuf, "CHUNK_SIZE,%d", *(int*)pArg);
16776 zOp = zBuf;
16777 break;
16778 }
16779 case SQLITE_FCNTL_FILE_POINTER: zOp = "FILE_POINTER"; break;
16780 case SQLITE_FCNTL_WIN32_AV_RETRY: zOp = "WIN32_AV_RETRY"; break;
16782 sqlite3_snprintf(sizeof(zBuf), zBuf, "PERSIST_WAL,%d", *(int*)pArg);
16783 zOp = zBuf;
16784 break;
16785 }
16786 case SQLITE_FCNTL_OVERWRITE: zOp = "OVERWRITE"; break;
16787 case SQLITE_FCNTL_VFSNAME: zOp = "VFSNAME"; break;
16788 case SQLITE_FCNTL_POWERSAFE_OVERWRITE: zOp = "POWERSAFE_OVERWRITE"; break;
16789 case SQLITE_FCNTL_PRAGMA: {
16790 const char *const* a = (const char*const*)pArg;
16791 if( a[1] && strcmp(a[1],"vfstrace")==0 && a[2] ){
16792 const u8 *zArg = (const u8*)a[2];
16793 if( zArg[0]>='0' && zArg[0]<='9' ){
16794 pInfo->mTrace = (sqlite3_uint64)strtoll(a[2], 0, 0);
16795 }else{
16796 static const struct {
16797 const char *z;
16798 unsigned int m;
16799 } aKw[] = {
16800 { "all", 0xffffffff },
16801 { "close", VTR_CLOSE },
16802 { "read", VTR_READ },
16803 { "write", VTR_WRITE },
16804 { "truncate", VTR_TRUNC },
16805 { "sync", VTR_SYNC },
16806 { "filesize", VTR_FSIZE },
16807 { "lock", VTR_LOCK },
16808 { "unlock", VTR_UNLOCK },
16809 { "checkreservedlock", VTR_CRL },
16810 { "filecontrol", VTR_FCTRL },
16811 { "sectorsize", VTR_SECSZ },
16812 { "devicecharacteristics", VTR_DEVCHAR },
16813 { "shmlock", VTR_SHMLOCK },
16814 { "shmmap", VTR_SHMMAP },
16815 { "shmummap", VTR_SHMUNMAP },
16816 { "shmbarrier", VTR_SHMBAR },
16817 { "open", VTR_OPEN },
16818 { "delete", VTR_DELETE },
16819 { "access", VTR_ACCESS },
16820 { "fullpathname", VTR_FULLPATH },
16821 { "dlopen", VTR_DLOPEN },
16822 { "dlerror", VTR_DLERR },
16823 { "dlsym", VTR_DLSYM },
16824 { "dlclose", VTR_DLCLOSE },
16825 { "randomness", VTR_RAND },
16826 { "sleep", VTR_SLEEP },
16827 { "currenttime", VTR_CURTIME },
16828 { "currenttimeint64", VTR_CURTIME },
16829 { "getlasterror", VTR_LASTERR },
16830 { "fetch", VTR_FETCH },
16831 };
16832 int onOff = 1;
16833 while( zArg[0] ){
16834 int jj, n;
16835 while( zArg[0]!=0 && zArg[0]!='-' && zArg[0]!='+'
16836 && !isalpha(zArg[0]) ) zArg++;
16837 if( zArg[0]==0 ) break;
16838 if( zArg[0]=='-' ){
16839 onOff = 0;
16840 zArg++;
16841 }else if( zArg[0]=='+' ){
16842 onOff = 1;
16843 zArg++;
16844 }
16845 while( !isalpha(zArg[0]) ){
16846 if( zArg[0]==0 ) break;
16847 zArg++;
16848 }
16849 if( zArg[0]=='x' && isalpha(zArg[1]) ) zArg++;
16850 for(n=0; isalpha(zArg[n]); n++){}
16851 for(jj=0; jj<(int)(sizeof(aKw)/sizeof(aKw[0])); jj++){
16852 if( sqlite3_strnicmp(aKw[jj].z,(const char*)zArg,n)==0 ){
16853 if( onOff ){
16854 pInfo->mTrace |= aKw[jj].m;
16855 }else{
16856 pInfo->mTrace &= ~aKw[jj].m;
16857 }
16858 break;
16859 }
16860 }
16861 zArg += n;
16862 }
16863 }
16864 }
16865 sqlite3_snprintf(sizeof(zBuf), zBuf, "PRAGMA,[%s,%s]",a[1],a[2]);
16866 zOp = zBuf;
16867 break;
16868 }
16869 case SQLITE_FCNTL_BUSYHANDLER: zOp = "BUSYHANDLER"; break;
16870 case SQLITE_FCNTL_TEMPFILENAME: zOp = "TEMPFILENAME"; break;
16872 sqlite3_int64 iMMap = *(sqlite3_int64*)pArg;
16873 sqlite3_snprintf(sizeof(zBuf), zBuf, "MMAP_SIZE,%lld",iMMap);
16874 zOp = zBuf;
16875 break;
16876 }
16877 case SQLITE_FCNTL_TRACE: zOp = "TRACE"; break;
16878 case SQLITE_FCNTL_HAS_MOVED: zOp = "HAS_MOVED"; break;
16879 case SQLITE_FCNTL_SYNC: zOp = "SYNC"; break;
16880 case SQLITE_FCNTL_COMMIT_PHASETWO: zOp = "COMMIT_PHASETWO"; break;
16881 case SQLITE_FCNTL_WIN32_SET_HANDLE: zOp = "WIN32_SET_HANDLE"; break;
16882 case SQLITE_FCNTL_WAL_BLOCK: zOp = "WAL_BLOCK"; break;
16883 case SQLITE_FCNTL_ZIPVFS: zOp = "ZIPVFS"; break;
16884 case SQLITE_FCNTL_RBU: zOp = "RBU"; break;
16885 case SQLITE_FCNTL_VFS_POINTER: zOp = "VFS_POINTER"; break;
16886 case SQLITE_FCNTL_JOURNAL_POINTER: zOp = "JOURNAL_POINTER"; break;
16887 case SQLITE_FCNTL_WIN32_GET_HANDLE: zOp = "WIN32_GET_HANDLE"; break;
16888 case SQLITE_FCNTL_PDB: zOp = "PDB"; break;
16889 case SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: zOp = "BEGIN_ATOMIC_WRITE"; break;
16890 case SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: zOp = "COMMIT_ATOMIC_WRITE"; break;
16892 zOp = "ROLLBACK_ATOMIC_WRITE";
16893 break;
16894 }
16896 sqlite3_snprintf(sizeof(zBuf), zBuf, "LOCK_TIMEOUT,%d", *(int*)pArg);
16897 zOp = zBuf;
16898 break;
16899 }
16900 case SQLITE_FCNTL_DATA_VERSION: zOp = "DATA_VERSION"; break;
16901 case SQLITE_FCNTL_SIZE_LIMIT: zOp = "SIZE_LIMIT"; break;
16902 case SQLITE_FCNTL_CKPT_DONE: zOp = "CKPT_DONE"; break;
16903 case SQLITE_FCNTL_RESERVE_BYTES: zOp = "RESERVED_BYTES"; break;
16904 case SQLITE_FCNTL_CKPT_START: zOp = "CKPT_START"; break;
16905 case SQLITE_FCNTL_EXTERNAL_READER: zOp = "EXTERNAL_READER"; break;
16906 case SQLITE_FCNTL_CKSM_FILE: zOp = "CKSM_FILE"; break;
16907 case SQLITE_FCNTL_RESET_CACHE: zOp = "RESET_CACHE"; break;
16908 case 0xca093fa0: zOp = "DB_UNCHANGED"; break;
16909 default: {
16910 sqlite3_snprintf(sizeof zBuf, zBuf, "%d", op);
16911 zOp = zBuf;
16912 break;
16913 }
16914 }
16915 vfstrace_printf(pInfo, "%s.xFileControl(%s,%s)",
16916 pInfo->zVfsName, p->zFName, zOp);
16917 rc = p->pReal->pMethods->xFileControl(p->pReal, op, pArg);
16918 if( rc==SQLITE_OK ){
16919 switch( op ){
16920 case SQLITE_FCNTL_VFSNAME: {
16921 *(char**)pArg = sqlite3_mprintf("vfstrace.%s/%z",
16922 pInfo->zVfsName, *(char**)pArg);
16923 zRVal = *(char**)pArg;
16924 break;
16925 }
16927 sqlite3_snprintf(sizeof(zBuf2), zBuf2, "%lld", *(sqlite3_int64*)pArg);
16928 zRVal = zBuf2;
16929 break;
16930 }
16933 sqlite3_snprintf(sizeof(zBuf2), zBuf2, "%d", *(int*)pArg);
16934 zRVal = zBuf2;
16935 break;
16936 }
16939 zRVal = *(char**)pArg;
16940 break;
16941 }
16942 }
16943 }
16944 if( zRVal ){
16945 vfstrace_print_errcode(pInfo, " -> %s", rc);
16946 vfstrace_printf(pInfo, ", %s\n", zRVal);
16947 }else{
16948 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
16949 }
16950 return rc;
16951}
#define VTR_SLEEP
Definition shell.c:16397
#define VTR_OPEN
Definition shell.c:16388
#define VTR_DLSYM
Definition shell.c:16394
#define VTR_SECSZ
Definition shell.c:16382
#define VTR_TRUNC
Definition shell.c:16375
#define VTR_FSIZE
Definition shell.c:16377
#define VTR_SHMLOCK
Definition shell.c:16384
#define VTR_UNLOCK
Definition shell.c:16379
#define VTR_READ
Definition shell.c:16373
#define VTR_SYNC
Definition shell.c:16376
#define VTR_SHMBAR
Definition shell.c:16386
#define VTR_WRITE
Definition shell.c:16374
#define VTR_FCTRL
Definition shell.c:16381
#define VTR_SHMMAP
Definition shell.c:16385
#define VTR_LASTERR
Definition shell.c:16399
#define VTR_RAND
Definition shell.c:16396
#define VTR_SHMUNMAP
Definition shell.c:16387
#define VTR_FULLPATH
Definition shell.c:16391
#define VTR_LOCK
Definition shell.c:16378
#define SQLITE_LAST_ERRNO
Definition sqlite3.c:1592
#define SQLITE_FCNTL_EXTERNAL_READER
Definition sqlite3.c:1583
#define SQLITE_FCNTL_WIN32_GET_HANDLE
Definition sqlite3.c:1572
#define SQLITE_FCNTL_CKPT_START
Definition sqlite3.c:1582
#define SQLITE_SET_LOCKPROXYFILE
Definition sqlite3.c:1591
#define SQLITE_FCNTL_TRACE
Definition sqlite3.c:1562
#define SQLITE_FCNTL_WIN32_SET_HANDLE
Definition sqlite3.c:1566
#define SQLITE_FCNTL_MMAP_SIZE
Definition sqlite3.c:1561
#define SQLITE_FCNTL_FILE_POINTER
Definition sqlite3.c:1551
#define SQLITE_FCNTL_COMMIT_PHASETWO
Definition sqlite3.c:1565
#define SQLITE_FCNTL_RBU
Definition sqlite3.c:1569
#define SQLITE_GET_LOCKPROXYFILE
Definition sqlite3.c:1590
#define SQLITE_FCNTL_SYNC
Definition sqlite3.c:1564
#define SQLITE_FCNTL_CKPT_DONE
Definition sqlite3.c:1580
#define SQLITE_FCNTL_RESET_CACHE
Definition sqlite3.c:1585
#define SQLITE_FCNTL_JOURNAL_POINTER
Definition sqlite3.c:1571
#define SQLITE_FCNTL_OVERWRITE
Definition sqlite3.c:1555
#define SQLITE_FCNTL_WAL_BLOCK
Definition sqlite3.c:1567
#define SQLITE_FCNTL_BUSYHANDLER
Definition sqlite3.c:1559
#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE
Definition sqlite3.c:1574
#define SQLITE_FCNTL_CKSM_FILE
Definition sqlite3.c:1584
#define SQLITE_FCNTL_LOCKSTATE
Definition sqlite3.c:1545
#define SQLITE_FCNTL_WIN32_AV_RETRY
Definition sqlite3.c:1553
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE
Definition sqlite3.c:1576
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE
Definition sqlite3.c:1575
#define SQLITE_FCNTL_ZIPVFS
Definition sqlite3.c:1568
#define SQLITE_FCNTL_PDB
Definition sqlite3.c:1573
#define SQLITE_FCNTL_PRAGMA
Definition sqlite3.c:1558

References a, vfstrace_info::mTrace, vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, sqlite3_mprintf, sqlite3_snprintf, sqlite3_strnicmp, SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, SQLITE_FCNTL_BUSYHANDLER, SQLITE_FCNTL_CHUNK_SIZE, SQLITE_FCNTL_CKPT_DONE, SQLITE_FCNTL_CKPT_START, SQLITE_FCNTL_CKSM_FILE, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, SQLITE_FCNTL_COMMIT_PHASETWO, SQLITE_FCNTL_DATA_VERSION, SQLITE_FCNTL_EXTERNAL_READER, SQLITE_FCNTL_FILE_POINTER, SQLITE_FCNTL_HAS_MOVED, SQLITE_FCNTL_JOURNAL_POINTER, SQLITE_FCNTL_LOCK_TIMEOUT, SQLITE_FCNTL_LOCKSTATE, SQLITE_FCNTL_MMAP_SIZE, SQLITE_FCNTL_OVERWRITE, SQLITE_FCNTL_PDB, SQLITE_FCNTL_PERSIST_WAL, SQLITE_FCNTL_POWERSAFE_OVERWRITE, SQLITE_FCNTL_PRAGMA, SQLITE_FCNTL_RBU, SQLITE_FCNTL_RESERVE_BYTES, SQLITE_FCNTL_RESET_CACHE, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, SQLITE_FCNTL_SIZE_HINT, SQLITE_FCNTL_SIZE_LIMIT, SQLITE_FCNTL_SYNC, SQLITE_FCNTL_TEMPFILENAME, SQLITE_FCNTL_TRACE, SQLITE_FCNTL_VFS_POINTER, SQLITE_FCNTL_VFSNAME, SQLITE_FCNTL_WAL_BLOCK, SQLITE_FCNTL_WIN32_AV_RETRY, SQLITE_FCNTL_WIN32_GET_HANDLE, SQLITE_FCNTL_WIN32_SET_HANDLE, SQLITE_FCNTL_ZIPVFS, SQLITE_GET_LOCKPROXYFILE, SQLITE_LAST_ERRNO, SQLITE_OK, SQLITE_SET_LOCKPROXYFILE, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_ACCESS, VTR_CLOSE, VTR_CRL, VTR_CURTIME, VTR_DELETE, VTR_DEVCHAR, VTR_DLCLOSE, VTR_DLERR, VTR_DLOPEN, VTR_DLSYM, VTR_FCTRL, VTR_FETCH, VTR_FSIZE, VTR_FULLPATH, VTR_LASTERR, VTR_LOCK, VTR_OPEN, VTR_RAND, VTR_READ, VTR_SECSZ, VTR_SHMBAR, VTR_SHMLOCK, VTR_SHMMAP, VTR_SHMUNMAP, VTR_SLEEP, VTR_SYNC, VTR_TRUNC, VTR_UNLOCK, VTR_WRITE, sqlite3_io_methods::xFileControl, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceFileSize()

int vfstraceFileSize ( sqlite3_file * pFile,
sqlite3_int64 * pSize )
static
16679 {
16680 vfstrace_file *p = (vfstrace_file *)pFile;
16681 vfstrace_info *pInfo = p->pInfo;
16682 int rc;
16683 vfstraceOnOff(pInfo, VTR_FSIZE);
16684 vfstrace_printf(pInfo, "%s.xFileSize(%s)", pInfo->zVfsName, p->zFName);
16685 rc = p->pReal->pMethods->xFileSize(p->pReal, pSize);
16686 vfstrace_print_errcode(pInfo, " -> %s,", rc);
16687 vfstrace_printf(pInfo, " size=%lld\n", *pSize);
16688 return rc;
16689}

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_FSIZE, sqlite3_io_methods::xFileSize, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceFullPathname()

int vfstraceFullPathname ( sqlite3_vfs * pVfs,
const char * zName,
int nOut,
char * zOut )
static
17190 {
17191 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17192 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17193 int rc;
17195 vfstrace_printf(pInfo, "%s.xFullPathname(\"%s\")",
17196 pInfo->zVfsName, zPath);
17197 rc = pRoot->xFullPathname(pRoot, zPath, nOut, zOut);
17198 vfstrace_print_errcode(pInfo, " -> %s", rc);
17199 vfstrace_printf(pInfo, ", out=\"%.*s\"\n", nOut, zOut);
17200 return rc;
17201}

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_FULLPATH, sqlite3_vfs::xFullPathname, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceGetLastError()

int vfstraceGetLastError ( sqlite3_vfs * pVfs,
int nErr,
char * zErr )
static
17300 {
17301 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17302 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17303 int rc;
17304 vfstraceOnOff(pInfo, VTR_LASTERR);
17305 vfstrace_printf(pInfo, "%s.xGetLastError(%d,zBuf)", pInfo->zVfsName, nErr);
17306 if( nErr ) zErr[0] = 0;
17307 rc = pRoot->xGetLastError(pRoot, nErr, zErr);
17308 vfstrace_printf(pInfo, " -> zBuf[] = \"%s\", rc = %d\n", nErr?zErr:"", rc);
17309 return rc;
17310}

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_printf(), vfstraceOnOff(), VTR_LASTERR, sqlite3_vfs::xGetLastError, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceGetSystemCall()

sqlite3_syscall_ptr vfstraceGetSystemCall ( sqlite3_vfs * pVfs,
const char * zName )
static
17327 {
17328 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17329 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17330 return pRoot->xGetSystemCall(pRoot, zName);
17331}

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, and sqlite3_vfs::xGetSystemCall.

Referenced by vfstrace_register().

Here is the caller graph for this function:

◆ vfstraceLock()

int vfstraceLock ( sqlite3_file * pFile,
int eLock )
static
16708 {
16709 vfstrace_file *p = (vfstrace_file *)pFile;
16710 vfstrace_info *pInfo = p->pInfo;
16711 int rc;
16712 vfstraceOnOff(pInfo, VTR_LOCK);
16713 vfstrace_printf(pInfo, "%s.xLock(%s,%s)", pInfo->zVfsName, p->zFName,
16714 lockName(eLock));
16715 rc = p->pReal->pMethods->xLock(p->pReal, eLock);
16716 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
16717 return rc;
16718}
static const char * lockName(int eLock)
Definition shell.c:16694

References lockName(), vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_LOCK, sqlite3_io_methods::xLock, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceNextSystemCall()

const char * vfstraceNextSystemCall ( sqlite3_vfs * pVfs,
const char * zName )
static
17332 {
17333 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17334 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17335 return pRoot->xNextSystemCall(pRoot, zName);
17336}

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, and sqlite3_vfs::xNextSystemCall.

Referenced by vfstrace_register().

Here is the caller graph for this function:

◆ vfstraceOnOff()

◆ vfstraceOpen()

int vfstraceOpen ( sqlite3_vfs * pVfs,
const char * zName,
sqlite3_file * pFile,
int flags,
int * pOutFlags )
static
17091 {
17092 int rc;
17093 vfstrace_file *p = (vfstrace_file *)pFile;
17094 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17095 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17096 p->pInfo = pInfo;
17097 p->zFName = zName ? fileTail(zName) : "<temp>";
17098 p->pReal = (sqlite3_file *)&p[1];
17099 rc = pRoot->xOpen(pRoot, zName, p->pReal, flags, pOutFlags);
17100 vfstraceOnOff(pInfo, VTR_OPEN);
17101 vfstrace_printf(pInfo, "%s.xOpen(%s,flags=0x%x)",
17102 pInfo->zVfsName, p->zFName, flags);
17103 if( p->pReal->pMethods ){
17104 sqlite3_io_methods *pNew = sqlite3_malloc( sizeof(*pNew) );
17105 const sqlite3_io_methods *pSub = p->pReal->pMethods;
17106 memset(pNew, 0, sizeof(*pNew));
17107 pNew->iVersion = pSub->iVersion;
17108 pNew->xClose = vfstraceClose;
17109 pNew->xRead = vfstraceRead;
17110 pNew->xWrite = vfstraceWrite;
17112 pNew->xSync = vfstraceSync;
17114 pNew->xLock = vfstraceLock;
17115 pNew->xUnlock = vfstraceUnlock;
17120 if( pNew->iVersion>=2 ){
17121 pNew->xShmMap = pSub->xShmMap ? vfstraceShmMap : 0;
17122 pNew->xShmLock = pSub->xShmLock ? vfstraceShmLock : 0;
17123 pNew->xShmBarrier = pSub->xShmBarrier ? vfstraceShmBarrier : 0;
17124 pNew->xShmUnmap = pSub->xShmUnmap ? vfstraceShmUnmap : 0;
17125 }
17126 if( pNew->iVersion>=3 ){
17127 pNew->xFetch = pSub->xFetch ? vfstraceFetch : 0;
17128 pNew->xUnfetch = pSub->xUnfetch ? vfstraceUnfetch : 0;
17129 }
17130 pFile->pMethods = pNew;
17131 }
17132 vfstrace_print_errcode(pInfo, " -> %s", rc);
17133 if( pOutFlags ){
17134 vfstrace_printf(pInfo, ", outFlags=0x%x\n", *pOutFlags);
17135 }else{
17136 vfstrace_printf(pInfo, "\n");
17137 }
17138 return rc;
17139}
static int vfstraceShmUnmap(sqlite3_file *, int)
Definition shell.c:17047
static int vfstraceDeviceCharacteristics(sqlite3_file *)
Definition shell.c:16970
static int vfstraceFileSize(sqlite3_file *, sqlite3_int64 *pSize)
Definition shell.c:16679
static int vfstraceSectorSize(sqlite3_file *)
Definition shell.c:16956
static int vfstraceUnfetch(sqlite3_file *pFile, i64 iOff, void *ptr)
Definition shell.c:17069
static void vfstraceShmBarrier(sqlite3_file *)
Definition shell.c:17040
static int vfstraceFileControl(sqlite3_file *, int op, void *pArg)
Definition shell.c:16754
static int vfstraceShmLock(sqlite3_file *, int, int, int)
Definition shell.c:16985
static int vfstraceLock(sqlite3_file *, int)
Definition shell.c:16708
static int vfstraceCheckReservedLock(sqlite3_file *, int *)
Definition shell.c:16738
static int vfstraceRead(sqlite3_file *, void *, int iAmt, sqlite3_int64 iOfst)
Definition shell.c:16599
static const char * fileTail(const char *z)
Definition shell.c:16448
static int vfstraceClose(sqlite3_file *)
Definition shell.c:16581
static int vfstraceWrite(sqlite3_file *, const void *, int iAmt, sqlite3_int64)
Definition shell.c:16619
static int vfstraceUnlock(sqlite3_file *, int)
Definition shell.c:16723
static int vfstraceShmMap(sqlite3_file *, int, int, int, void volatile **)
Definition shell.c:17023
static int vfstraceTruncate(sqlite3_file *, sqlite3_int64 size)
Definition shell.c:16639
static int vfstraceSync(sqlite3_file *, int flags)
Definition shell.c:16654
static int vfstraceFetch(sqlite3_file *pFile, i64 iOff, int nAmt, void **pptr)
Definition shell.c:17058
int iVersion
Definition sqlite3.c:1166
Definition sqlite3.c:1165

References fileTail(), sqlite3_io_methods::iVersion, sqlite3_vfs::pAppData, vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_info::pRootVfs, sqlite3_malloc, vfstrace_print_errcode(), vfstrace_printf(), vfstraceCheckReservedLock(), vfstraceClose(), vfstraceDeviceCharacteristics(), vfstraceFetch(), vfstraceFileControl(), vfstraceFileSize(), vfstraceLock(), vfstraceOnOff(), vfstraceRead(), vfstraceSectorSize(), vfstraceShmBarrier(), vfstraceShmLock(), vfstraceShmMap(), vfstraceShmUnmap(), vfstraceSync(), vfstraceTruncate(), vfstraceUnfetch(), vfstraceUnlock(), vfstraceWrite(), VTR_OPEN, sqlite3_io_methods::xCheckReservedLock, sqlite3_io_methods::xClose, sqlite3_io_methods::xDeviceCharacteristics, sqlite3_io_methods::xFetch, sqlite3_io_methods::xFileControl, sqlite3_io_methods::xFileSize, sqlite3_io_methods::xLock, sqlite3_vfs::xOpen, sqlite3_io_methods::xRead, sqlite3_io_methods::xSectorSize, sqlite3_io_methods::xShmBarrier, sqlite3_io_methods::xShmLock, sqlite3_io_methods::xShmMap, sqlite3_io_methods::xShmUnmap, sqlite3_io_methods::xSync, sqlite3_io_methods::xTruncate, sqlite3_io_methods::xUnfetch, sqlite3_io_methods::xUnlock, sqlite3_io_methods::xWrite, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstrace_register(), and vfstrace_unregister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceOut()

int vfstraceOut ( const char * z,
void * pArg )
static
33189 {
33190 ShellState *p = (ShellState*)pArg;
33191 sqlite3_fputs(z, p->out);
33192 fflush(p->out);

References ShellState::out, and sqlite3_fputs.

Referenced by main().

Here is the caller graph for this function:

◆ vfstraceRandomness()

int vfstraceRandomness ( sqlite3_vfs * pVfs,
int nByte,
char * zOut )
static
17253 {
17254 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17255 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17256 vfstraceOnOff(pInfo, VTR_RAND);
17257 vfstrace_printf(pInfo, "%s.xRandomness(%d)\n", pInfo->zVfsName, nByte);
17258 return pRoot->xRandomness(pRoot, nByte, zBufOut);
17259}

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_printf(), vfstraceOnOff(), VTR_RAND, sqlite3_vfs::xRandomness, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceRead()

int vfstraceRead ( sqlite3_file * pFile,
void * zBuf,
int iAmt,
sqlite3_int64 iOfst )
static
16604 {
16605 vfstrace_file *p = (vfstrace_file *)pFile;
16606 vfstrace_info *pInfo = p->pInfo;
16607 int rc;
16608 vfstraceOnOff(pInfo, VTR_READ);
16609 vfstrace_printf(pInfo, "%s.xRead(%s,n=%d,ofst=%lld)",
16610 pInfo->zVfsName, p->zFName, iAmt, iOfst);
16611 rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
16612 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
16613 return rc;
16614}

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_READ, sqlite3_io_methods::xRead, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceSectorSize()

int vfstraceSectorSize ( sqlite3_file * pFile)
static
16956 {
16957 vfstrace_file *p = (vfstrace_file *)pFile;
16958 vfstrace_info *pInfo = p->pInfo;
16959 int rc;
16960 vfstraceOnOff(pInfo, VTR_SECSZ);
16961 vfstrace_printf(pInfo, "%s.xSectorSize(%s)", pInfo->zVfsName, p->zFName);
16962 rc = p->pReal->pMethods->xSectorSize(p->pReal);
16963 vfstrace_printf(pInfo, " -> %d\n", rc);
16964 return rc;
16965}

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_printf(), vfstraceOnOff(), VTR_SECSZ, sqlite3_io_methods::xSectorSize, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceSetSystemCall()

int vfstraceSetSystemCall ( sqlite3_vfs * pVfs,
const char * zName,
sqlite3_syscall_ptr pFunc )
static
17319 {
17320 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17321 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17322 return pRoot->xSetSystemCall(pRoot, zName, pFunc);
17323}

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, and sqlite3_vfs::xSetSystemCall.

Referenced by vfstrace_register().

Here is the caller graph for this function:

◆ vfstraceShmBarrier()

void vfstraceShmBarrier ( sqlite3_file * pFile)
static
17040 {
17041 vfstrace_file *p = (vfstrace_file *)pFile;
17042 vfstrace_info *pInfo = p->pInfo;
17043 vfstraceOnOff(pInfo, VTR_SHMBAR);
17044 vfstrace_printf(pInfo, "%s.xShmBarrier(%s)\n", pInfo->zVfsName, p->zFName);
17046}

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_printf(), vfstraceOnOff(), VTR_SHMBAR, sqlite3_io_methods::xShmBarrier, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceShmLock()

int vfstraceShmLock ( sqlite3_file * pFile,
int ofst,
int n,
int flags )
static
16985 {
16986 static const char *azLockName[] = {
16987 "WRITE",
16988 "CKPT",
16989 "RECOVER",
16990 "READ0",
16991 "READ1",
16992 "READ2",
16993 "READ3",
16994 "READ4",
16995 };
16996 vfstrace_file *p = (vfstrace_file *)pFile;
16997 vfstrace_info *pInfo = p->pInfo;
16998 int rc;
16999 char zLck[100];
17000 int i = 0;
17001 vfstraceOnOff(pInfo, VTR_SHMLOCK);
17002 memcpy(zLck, "|0", 3);
17003 if( flags & SQLITE_SHM_UNLOCK ) strappend(zLck, &i, "|UNLOCK");
17004 if( flags & SQLITE_SHM_LOCK ) strappend(zLck, &i, "|LOCK");
17005 if( flags & SQLITE_SHM_SHARED ) strappend(zLck, &i, "|SHARED");
17006 if( flags & SQLITE_SHM_EXCLUSIVE ) strappend(zLck, &i, "|EXCLUSIVE");
17007 if( flags & ~(0xf) ){
17008 sqlite3_snprintf(sizeof(zLck)-i, &zLck[i], "|0x%x", flags);
17009 }
17010 if( ofst>=0 && ofst<(int)(sizeof(azLockName)/sizeof(azLockName[0])) ){
17011 vfstrace_printf(pInfo, "%s.xShmLock(%s,ofst=%d(%s),n=%d,%s)",
17012 pInfo->zVfsName, p->zFName, ofst, azLockName[ofst],
17013 n, &zLck[1]);
17014 }else{
17015 vfstrace_printf(pInfo, "%s.xShmLock(%s,ofst=5d,n=%d,%s)",
17016 pInfo->zVfsName, p->zFName, ofst,
17017 n, &zLck[1]);
17018 }
17019 rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags);
17020 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
17021 return rc;
17022}
static void strappend(char *z, int *pI, const char *zAppend)
Definition shell.c:16564
#define SQLITE_SHM_LOCK
Definition sqlite3.c:1894
#define SQLITE_SHM_SHARED
Definition sqlite3.c:1895
#define SQLITE_SHM_UNLOCK
Definition sqlite3.c:1893
#define SQLITE_SHM_EXCLUSIVE
Definition sqlite3.c:1896

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, sqlite3_snprintf, SQLITE_SHM_EXCLUSIVE, SQLITE_SHM_LOCK, SQLITE_SHM_SHARED, SQLITE_SHM_UNLOCK, strappend(), vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_SHMLOCK, sqlite3_io_methods::xShmLock, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceShmMap()

int vfstraceShmMap ( sqlite3_file * pFile,
int iRegion,
int szRegion,
int isWrite,
void volatile ** pp )
static
17029 {
17030 vfstrace_file *p = (vfstrace_file *)pFile;
17031 vfstrace_info *pInfo = p->pInfo;
17032 int rc;
17033 vfstraceOnOff(pInfo, VTR_SHMMAP);
17034 vfstrace_printf(pInfo, "%s.xShmMap(%s,iRegion=%d,szRegion=%d,isWrite=%d,*)",
17035 pInfo->zVfsName, p->zFName, iRegion, szRegion, isWrite);
17036 rc = p->pReal->pMethods->xShmMap(p->pReal, iRegion, szRegion, isWrite, pp);
17037 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
17038 return rc;
17039}

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_SHMMAP, sqlite3_io_methods::xShmMap, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceShmUnmap()

int vfstraceShmUnmap ( sqlite3_file * pFile,
int delFlag )
static
17047 {
17048 vfstrace_file *p = (vfstrace_file *)pFile;
17049 vfstrace_info *pInfo = p->pInfo;
17050 int rc;
17052 vfstrace_printf(pInfo, "%s.xShmUnmap(%s,delFlag=%d)",
17053 pInfo->zVfsName, p->zFName, delFlag);
17054 rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag);
17055 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
17056 return rc;
17057}

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_SHMUNMAP, sqlite3_io_methods::xShmUnmap, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceSleep()

int vfstraceSleep ( sqlite3_vfs * pVfs,
int microseconds )
static
17265 {
17266 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17267 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17268 vfstraceOnOff(pInfo, VTR_SLEEP);
17269 vfstrace_printf(pInfo, "%s.xSleep(%d)\n", pInfo->zVfsName, nMicro);
17270 return pRoot->xSleep(pRoot, nMicro);
17271}

References sqlite3_vfs::pAppData, vfstrace_info::pRootVfs, vfstrace_printf(), vfstraceOnOff(), VTR_SLEEP, sqlite3_vfs::xSleep, and vfstrace_info::zVfsName.

Referenced by vfstrace_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceSync()

int vfstraceSync ( sqlite3_file * pFile,
int flags )
static
16654 {
16655 vfstrace_file *p = (vfstrace_file *)pFile;
16656 vfstrace_info *pInfo = p->pInfo;
16657 int rc;
16658 int i;
16659 char zBuf[100];
16660 memcpy(zBuf, "|0", 3);
16661 i = 0;
16662 if( flags & SQLITE_SYNC_FULL ) strappend(zBuf, &i, "|FULL");
16663 else if( flags & SQLITE_SYNC_NORMAL ) strappend(zBuf, &i, "|NORMAL");
16664 if( flags & SQLITE_SYNC_DATAONLY ) strappend(zBuf, &i, "|DATAONLY");
16665 if( flags & ~(SQLITE_SYNC_FULL|SQLITE_SYNC_DATAONLY) ){
16666 sqlite3_snprintf(sizeof(zBuf)-i, &zBuf[i], "|0x%x", flags);
16667 }
16668 vfstraceOnOff(pInfo, VTR_SYNC);
16669 vfstrace_printf(pInfo, "%s.xSync(%s,%s)", pInfo->zVfsName, p->zFName,
16670 &zBuf[1]);
16671 rc = p->pReal->pMethods->xSync(p->pReal, flags);
16672 vfstrace_printf(pInfo, " -> %d\n", rc);
16673 return rc;
16674}
#define SQLITE_SYNC_NORMAL
Definition sqlite3.c:1042
#define SQLITE_SYNC_FULL
Definition sqlite3.c:1043
#define SQLITE_SYNC_DATAONLY
Definition sqlite3.c:1044

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, sqlite3_snprintf, SQLITE_SYNC_DATAONLY, SQLITE_SYNC_FULL, SQLITE_SYNC_NORMAL, strappend(), vfstrace_printf(), vfstraceOnOff(), VTR_SYNC, sqlite3_io_methods::xSync, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceTruncate()

int vfstraceTruncate ( sqlite3_file * pFile,
sqlite3_int64 size )
static
16639 {
16640 vfstrace_file *p = (vfstrace_file *)pFile;
16641 vfstrace_info *pInfo = p->pInfo;
16642 int rc;
16643 vfstraceOnOff(pInfo, VTR_TRUNC);
16644 vfstrace_printf(pInfo, "%s.xTruncate(%s,%lld)", pInfo->zVfsName, p->zFName,
16645 size);
16646 rc = p->pReal->pMethods->xTruncate(p->pReal, size);
16647 vfstrace_printf(pInfo, " -> %d\n", rc);
16648 return rc;
16649}

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_printf(), vfstraceOnOff(), VTR_TRUNC, sqlite3_io_methods::xTruncate, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceUnfetch()

int vfstraceUnfetch ( sqlite3_file * pFile,
i64 iOff,
void * ptr )
static
17069 {
17070 vfstrace_file *p = (vfstrace_file *)pFile;
17071 vfstrace_info *pInfo = p->pInfo;
17072 int rc;
17073 vfstraceOnOff(pInfo, VTR_FETCH);
17074 vfstrace_printf(pInfo, "%s.xUnfetch(%s,iOff=%lld,p=%p)",
17075 pInfo->zVfsName, p->zFName, iOff, ptr);
17076 rc = p->pReal->pMethods->xUnfetch(p->pReal, iOff, ptr);
17077 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
17078 return rc;
17079}

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_FETCH, sqlite3_io_methods::xUnfetch, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceUnlock()

int vfstraceUnlock ( sqlite3_file * pFile,
int eLock )
static
16723 {
16724 vfstrace_file *p = (vfstrace_file *)pFile;
16725 vfstrace_info *pInfo = p->pInfo;
16726 int rc;
16727 vfstraceOnOff(pInfo, VTR_UNLOCK);
16728 vfstrace_printf(pInfo, "%s.xUnlock(%s,%s)", pInfo->zVfsName, p->zFName,
16729 lockName(eLock));
16730 rc = p->pReal->pMethods->xUnlock(p->pReal, eLock);
16731 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
16732 return rc;
16733}

References lockName(), vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_UNLOCK, sqlite3_io_methods::xUnlock, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfstraceWrite()

int vfstraceWrite ( sqlite3_file * pFile,
const void * zBuf,
int iAmt,
sqlite3_int64 iOfst )
static
16624 {
16625 vfstrace_file *p = (vfstrace_file *)pFile;
16626 vfstrace_info *pInfo = p->pInfo;
16627 int rc;
16628 vfstraceOnOff(pInfo, VTR_WRITE);
16629 vfstrace_printf(pInfo, "%s.xWrite(%s,n=%d,ofst=%lld)",
16630 pInfo->zVfsName, p->zFName, iAmt, iOfst);
16631 rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
16632 vfstrace_print_errcode(pInfo, " -> %s\n", rc);
16633 return rc;
16634}

References vfstrace_file::pInfo, sqlite3_file::pMethods, vfstrace_file::pReal, vfstrace_print_errcode(), vfstrace_printf(), vfstraceOnOff(), VTR_WRITE, sqlite3_io_methods::xWrite, vfstrace_file::zFName, and vfstrace_info::zVfsName.

Referenced by vfstraceOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeFile()

int writeFile ( sqlite3_context * pCtx,
const char * zFile,
sqlite3_value * pData,
mode_t mode,
sqlite3_int64 mtime )
static
8346 {
8347 if( zFile==0 ) return 1;
8348#if !defined(_WIN32) && !defined(WIN32)
8349 if( S_ISLNK(mode) ){
8350 const char *zTo = (const char*)sqlite3_value_text(pData);
8351 if( zTo==0 ) return 1;
8352 unlink(zFile);
8353 if( symlink(zTo, zFile)<0 ) return 1;
8354 }else
8355#endif
8356 {
8357 if( S_ISDIR(mode) ){
8358 if( mkdir(zFile, mode) ){
8359 /* The mkdir() call to create the directory failed. This might not
8360 ** be an error though - if there is already a directory at the same
8361 ** path and either the permissions already match or can be changed
8362 ** to do so using chmod(), it is not an error. */
8363 STRUCT_STAT sStat;
8364 if( errno!=EEXIST
8365 || 0!=fileStat(zFile, &sStat)
8366 || !S_ISDIR(sStat.st_mode)
8367 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
8368 ){
8369 return 1;
8370 }
8371 }
8372 }else{
8373 sqlite3_int64 nWrite = 0;
8374 const char *z;
8375 int rc = 0;
8376 FILE *out = sqlite3_fopen(zFile, "wb");
8377 if( out==0 ) return 1;
8378 z = (const char*)sqlite3_value_blob(pData);
8379 if( z ){
8380 sqlite3_int64 n = fwrite(z, 1, sqlite3_value_bytes(pData), out);
8381 nWrite = sqlite3_value_bytes(pData);
8382 if( nWrite!=n ){
8383 rc = 1;
8384 }
8385 }
8386 fclose(out);
8387 if( rc==0 && mode && chmod(zFile, mode & 0777) ){
8388 rc = 1;
8389 }
8390 if( rc ) return 2;
8391 sqlite3_result_int64(pCtx, nWrite);
8392 }
8393 }
8394
8395 if( mtime>=0 ){
8396#if defined(_WIN32)
8397#if !SQLITE_OS_WINRT
8398 /* Windows */
8399 FILETIME lastAccess;
8400 FILETIME lastWrite;
8401 SYSTEMTIME currentTime;
8402 LONGLONG intervals;
8403 HANDLE hFile;
8404 LPWSTR zUnicodeName;
8405 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
8406
8407 GetSystemTime(&currentTime);
8408 SystemTimeToFileTime(&currentTime, &lastAccess);
8409 intervals = (mtime*10000000) + 116444736000000000;
8410 lastWrite.dwLowDateTime = (DWORD)intervals;
8411 lastWrite.dwHighDateTime = intervals >> 32;
8412 zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
8413 if( zUnicodeName==0 ){
8414 return 1;
8415 }
8416 hFile = CreateFileW(
8417 zUnicodeName, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
8418 FILE_FLAG_BACKUP_SEMANTICS, NULL
8419 );
8420 sqlite3_free(zUnicodeName);
8421 if( hFile!=INVALID_HANDLE_VALUE ){
8422 BOOL bResult = SetFileTime(hFile, NULL, &lastAccess, &lastWrite);
8423 CloseHandle(hFile);
8424 return !bResult;
8425 }else{
8426 return 1;
8427 }
8428#endif
8429#elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
8430 /* Recent unix */
8431 struct timespec times[2];
8432 times[0].tv_nsec = times[1].tv_nsec = 0;
8433 times[0].tv_sec = time(0);
8434 times[1].tv_sec = mtime;
8435 if( utimensat(AT_FDCWD, zFile, times, AT_SYMLINK_NOFOLLOW) ){
8436 return 1;
8437 }
8438#else
8439 /* Legacy unix.
8440 **
8441 ** Do not use utimes() on a symbolic link - it sees through the link and
8442 ** modifies the timestamps on the target. Or fails if the target does
8443 ** not exist. */
8444 if( 0==S_ISLNK(mode) ){
8445 struct timeval times[2];
8446 times[0].tv_usec = times[1].tv_usec = 0;
8447 times[0].tv_sec = time(0);
8448 times[1].tv_sec = mtime;
8449 if( utimes(zFile, times) ){
8450 return 1;
8451 }
8452 }
8453#endif
8454 }
8455
8456 return 0;
8457}

References fileStat(), sqlite3_fopen, sqlite3_free, sqlite3_result_int64, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_text, and STRUCT_STAT.

Referenced by writefileFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writefileFunc()

void writefileFunc ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static
8467 {
8468 const char *zFile;
8469 mode_t mode = 0;
8470 int res;
8471 sqlite3_int64 mtime = -1;
8472
8473 if( argc<2 || argc>4 ){
8474 sqlite3_result_error(context,
8475 "wrong number of arguments to function writefile()", -1
8476 );
8477 return;
8478 }
8479
8480 zFile = (const char*)sqlite3_value_text(argv[0]);
8481 if( zFile==0 ) return;
8482 if( argc>=3 ){
8483 mode = (mode_t)sqlite3_value_int(argv[2]);
8484 }
8485 if( argc==4 ){
8486 mtime = sqlite3_value_int64(argv[3]);
8487 }
8488
8489 res = writeFile(context, zFile, argv[1], mode, mtime);
8490 if( res==1 && errno==ENOENT ){
8491 if( makeDirectory(zFile)==SQLITE_OK ){
8492 res = writeFile(context, zFile, argv[1], mode, mtime);
8493 }
8494 }
8495
8496 if( argc>2 && res!=0 ){
8497 if( S_ISLNK(mode) ){
8498 ctxErrorMsg(context, "failed to create symlink: %s", zFile);
8499 }else if( S_ISDIR(mode) ){
8500 ctxErrorMsg(context, "failed to create directory: %s", zFile);
8501 }else{
8502 ctxErrorMsg(context, "failed to write file: %s", zFile);
8503 }
8504 }
8505}
static int writeFile(sqlite3_context *pCtx, const char *zFile, sqlite3_value *pData, mode_t mode, sqlite3_int64 mtime)
Definition shell.c:8340
static int makeDirectory(const char *zFile)
Definition shell.c:8300
static void ctxErrorMsg(sqlite3_context *ctx, const char *zFmt,...)
Definition shell.c:8168

References ctxErrorMsg(), makeDirectory(), sqlite3_result_error, sqlite3_value_int, sqlite3_value_int64, sqlite3_value_text, SQLITE_OK, and writeFile().

Referenced by sqlite3_fileio_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wsToEol()

int wsToEol ( const char * z)
static
22716 {
22717 int i;
22718 for(i=0; z[i]; i++){
22719 if( z[i]=='\n' ) return 1;
22720 if( IsSpace(z[i]) ) continue;
22721 if( z[i]=='-' && z[i+1]=='-' ) return 1;
22722 return 0;
22723 }

References IsSpace.

Referenced by shell_callback().

Here is the caller graph for this function:

◆ zAutoColumn()

char * zAutoColumn ( const char * zColNew,
sqlite3 ** pDb,
char ** pzRenamed )
static
28556 {
28557 /* Queries and D{D,M}L used here */
28558 static const char * const zTabMake = "\
28559CREATE TABLE ColNames(\
28560 cpos INTEGER PRIMARY KEY,\
28561 name TEXT, nlen INT, chop INT, reps INT, suff TEXT);\
28562CREATE VIEW RepeatedNames AS \
28563SELECT DISTINCT t.name FROM ColNames t \
28564WHERE t.name COLLATE NOCASE IN (\
28565 SELECT o.name FROM ColNames o WHERE o.cpos<>t.cpos\
28566);\
28567";
28568 static const char * const zTabFill = "\
28569INSERT INTO ColNames(name,nlen,chop,reps,suff)\
28570 VALUES(iif(length(?1)>0,?1,'?'),max(length(?1),1),0,0,'')\
28571";
28572 static const char * const zHasDupes = "\
28573SELECT count(DISTINCT (substring(name,1,nlen-chop)||suff) COLLATE NOCASE)\
28574 <count(name) FROM ColNames\
28575";
28576#ifdef SHELL_COLUMN_RENAME_CLEAN
28577 static const char * const zDedoctor = "\
28578UPDATE ColNames SET chop=iif(\
28579 (substring(name,nlen,1) BETWEEN '0' AND '9')\
28580 AND (rtrim(name,'0123456790') glob '*"AUTOCOLUMN_SEP"'),\
28581 nlen-length(rtrim(name, '"AUTOCOLUMN_SEP"0123456789')),\
28582 0\
28583)\
28584";
28585#endif
28586 static const char * const zSetReps = "\
28587UPDATE ColNames AS t SET reps=\
28588(SELECT count(*) FROM ColNames d \
28589 WHERE substring(t.name,1,t.nlen-t.chop)=substring(d.name,1,d.nlen-d.chop)\
28590 COLLATE NOCASE\
28591)\
28592";
28593#ifdef SQLITE_ENABLE_MATH_FUNCTIONS
28594 static const char * const zColDigits = "\
28595SELECT CAST(ceil(log(count(*)+0.5)) AS INT) FROM ColNames \
28596";
28597#else
28598 /* Counting on SQLITE_MAX_COLUMN < 100,000 here. (32767 is the hard limit.) */
28599 static const char * const zColDigits = "\
28600SELECT CASE WHEN (nc < 10) THEN 1 WHEN (nc < 100) THEN 2 \
28601 WHEN (nc < 1000) THEN 3 WHEN (nc < 10000) THEN 4 \
28602 ELSE 5 FROM (SELECT count(*) AS nc FROM ColNames) \
28603";
28604#endif
28605 static const char * const zRenameRank =
28606#ifdef SHELL_COLUMN_RENAME_CLEAN
28607 "UPDATE ColNames AS t SET suff="
28608 "iif(reps>1, printf('%c%0*d', '"AUTOCOLUMN_SEP"', $1, cpos), '')"
28609#else /* ...RENAME_MINIMAL_ONE_PASS */
28610"WITH Lzn(nlz) AS (" /* Find minimum extraneous leading 0's for uniqueness */
28611" SELECT 0 AS nlz"
28612" UNION"
28613" SELECT nlz+1 AS nlz FROM Lzn"
28614" WHERE EXISTS("
28615" SELECT 1"
28616" FROM ColNames t, ColNames o"
28617" WHERE"
28618" iif(t.name IN (SELECT * FROM RepeatedNames),"
28619" printf('%s"AUTOCOLUMN_SEP"%s',"
28620" t.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,t.cpos),2)),"
28621" t.name"
28622" )"
28623" ="
28624" iif(o.name IN (SELECT * FROM RepeatedNames),"
28625" printf('%s"AUTOCOLUMN_SEP"%s',"
28626" o.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,o.cpos),2)),"
28627" o.name"
28628" )"
28629" COLLATE NOCASE"
28630" AND o.cpos<>t.cpos"
28631" GROUP BY t.cpos"
28632" )"
28633") UPDATE Colnames AS t SET"
28634" chop = 0," /* No chopping, never touch incoming names. */
28635" suff = iif(name IN (SELECT * FROM RepeatedNames),"
28636" printf('"AUTOCOLUMN_SEP"%s', substring("
28637" printf('%.*c%0.*d',(SELECT max(nlz) FROM Lzn)+1,'0',1,t.cpos),2)),"
28638" ''"
28639" )"
28640#endif
28641 ;
28642 static const char * const zCollectVar = "\
28643SELECT\
28644 '('||x'0a'\
28645 || group_concat(\
28646 cname||' TEXT',\
28647 ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\
28648 ||')' AS ColsSpec \
28649FROM (\
28650 SELECT cpos, printf('\"%w\"',printf('%!.*s%s', nlen-chop,name,suff)) AS cname \
28651 FROM ColNames ORDER BY cpos\
28652)";
28653 static const char * const zRenamesDone =
28654 "SELECT group_concat("
28655 " printf('\"%w\" to \"%w\"',name,printf('%!.*s%s', nlen-chop, name, suff)),"
28656 " ','||x'0a')"
28657 "FROM ColNames WHERE suff<>'' OR chop!=0"
28658 ;
28659 int rc;
28660 sqlite3_stmt *pStmt = 0;
28661 assert(pDb!=0);
28662 if( zColNew ){
28663 /* Add initial or additional column. Init db if necessary. */
28664 if( *pDb==0 ){
28665 if( SQLITE_OK!=sqlite3_open(zCOL_DB, pDb) ) return 0;
28666#ifdef SHELL_COLFIX_DB
28667 if(*zCOL_DB!=':')
28668 sqlite3_exec(*pDb,"drop table if exists ColNames;"
28669 "drop view if exists RepeatedNames;",0,0,0);
28670#endif
28671#undef SHELL_COLFIX_DB
28672 rc = sqlite3_exec(*pDb, zTabMake, 0, 0, 0);
28673 rc_err_oom_die(rc);
28674 }
28675 assert(*pDb!=0);
28676 rc = sqlite3_prepare_v2(*pDb, zTabFill, -1, &pStmt, 0);
28677 rc_err_oom_die(rc);
28678 rc = sqlite3_bind_text(pStmt, 1, zColNew, -1, 0);
28679 rc_err_oom_die(rc);
28680 rc = sqlite3_step(pStmt);
28681 rc_err_oom_die(rc);
28682 sqlite3_finalize(pStmt);
28683 return 0;
28684 }else if( *pDb==0 ){
28685 return 0;
28686 }else{
28687 /* Formulate the columns spec, close the DB, zero *pDb. */
28688 char *zColsSpec = 0;
28689 int hasDupes = db_int(*pDb, "%s", zHasDupes);
28690 int nDigits = (hasDupes)? db_int(*pDb, "%s", zColDigits) : 0;
28691 if( hasDupes ){
28692#ifdef SHELL_COLUMN_RENAME_CLEAN
28693 rc = sqlite3_exec(*pDb, zDedoctor, 0, 0, 0);
28694 rc_err_oom_die(rc);
28695#endif
28696 rc = sqlite3_exec(*pDb, zSetReps, 0, 0, 0);
28697 rc_err_oom_die(rc);
28698 rc = sqlite3_prepare_v2(*pDb, zRenameRank, -1, &pStmt, 0);
28699 rc_err_oom_die(rc);
28700 sqlite3_bind_int(pStmt, 1, nDigits);
28701 rc = sqlite3_step(pStmt);
28702 sqlite3_finalize(pStmt);
28704 }
28705 assert(db_int(*pDb, "%s", zHasDupes)==0); /* Consider: remove this */
28706 rc = sqlite3_prepare_v2(*pDb, zCollectVar, -1, &pStmt, 0);
28707 rc_err_oom_die(rc);
28708 rc = sqlite3_step(pStmt);
28709 if( rc==SQLITE_ROW ){
28710 zColsSpec = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
28711 }else{
28712 zColsSpec = 0;
28713 }
28714 if( pzRenamed!=0 ){
28715 if( !hasDupes ) *pzRenamed = 0;
28716 else{
28717 sqlite3_finalize(pStmt);
28718 if( SQLITE_OK==sqlite3_prepare_v2(*pDb, zRenamesDone, -1, &pStmt, 0)
28719 && SQLITE_ROW==sqlite3_step(pStmt) ){
28720 *pzRenamed = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
28721 }else
28722 *pzRenamed = 0;
28723 }
28724 }
28725 sqlite3_finalize(pStmt);
28726 sqlite3_close(*pDb);
28727 *pDb = 0;
28728 return zColsSpec;
static const char * zCOL_DB
Definition shell.c:28540
#define AUTOCOLUMN_SEP
Definition shell.c:28549
static void rc_err_oom_die(int rc)
Definition shell.c:28531

References AUTOCOLUMN_SEP, db_int(), rc_err_oom_die(), sqlite3_bind_int, sqlite3_bind_text, sqlite3_close, sqlite3_column_text, sqlite3_exec, sqlite3_finalize, sqlite3_mprintf, sqlite3_open, sqlite3_prepare_v2, sqlite3_step, SQLITE_DONE, SQLITE_NOMEM, SQLITE_OK, SQLITE_ROW, and zCOL_DB.

Referenced by do_meta_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zSkipValidUtf8()

const char * zSkipValidUtf8 ( const char * z,
int nAccept,
long ccm )
22248 : nAccept>=0 => char count, nAccept<0 => character
22249 */
22250const char *zSkipValidUtf8(const char *z, int nAccept, long ccm){
22251 int ng = (nAccept<0)? -nAccept : 0;
22252 const char *pcLimit = (nAccept>=0)? z+nAccept : 0;
22253 assert(z!=0);
22254 while( (pcLimit)? (z<pcLimit) : (ng-- != 0) ){
22255 unsigned char c = *(u8*)z;
22256 if( c<0x7f ){
22257 if( ccm != 0L && c < 0x20 && ((1L<<c) & ccm) != 0 ) return z;
22258 ++z; /* ASCII */
22259 }else if( (c & 0xC0) != 0xC0 ) return z; /* not a lead byte */
22260 else{
22261 const char *zt = z+1; /* Got lead byte, look at trail bytes.*/
22262 do{
22263 if( pcLimit && zt >= pcLimit ) return z;
22264 else{
22265 char ct = *zt++;
22266 if( ct==0 || (zt-z)>4 || (ct & 0xC0)!=0x80 ){
22267 /* Trailing bytes are too few, too many, or invalid. */
22268 return z;
22269 }
22270 }
22271 } while( ((c <<= 1) & 0x40) == 0x40 ); /* Eat lead byte's count. */
22272 z = zt;
22273 }
22274 }

References c.

Referenced by output_c_string(), and output_json_string().

Here is the caller graph for this function:

Variable Documentation

◆ aPercentFunc

const PercentileFunc aPercentFunc[]
static
Initial value:
= {
{ "median", 1, 1, 0 },
{ "percentile", 2, 100, 0 },
{ "percentile_cont", 2, 1, 0 },
{ "percentile_disc", 2, 1, 1 },
}
4736 {
4737 { "median", 1, 1, 0 },
4738 { "percentile", 2, 100, 0 },
4739 { "percentile_cont", 2, 1, 0 },
4740 { "percentile_disc", 2, 1, 1 },
4741};

Referenced by sqlite3_percentile_init().

◆ apnd_io_methods

const sqlite3_io_methods apnd_io_methods
static
Initial value:
= {
3,
}
static int apndShmMap(sqlite3_file *, int iPg, int pgsz, int, void volatile **)
Definition shell.c:9909
static int apndSectorSize(sqlite3_file *)
Definition shell.c:9895
static int apndDeviceCharacteristics(sqlite3_file *)
Definition shell.c:9903
static void apndShmBarrier(sqlite3_file *)
Definition shell.c:9927
static int apndSync(sqlite3_file *, int flags)
Definition shell.c:9838
static int apndFileControl(sqlite3_file *, int op, void *pArg)
Definition shell.c:9880
static int apndShmUnmap(sqlite3_file *, int deleteFlag)
Definition shell.c:9933
static int apndShmLock(sqlite3_file *, int offset, int n, int flags)
Definition shell.c:9921
static int apndUnfetch(sqlite3_file *, sqlite3_int64 iOfst, void *p)
Definition shell.c:9954
static int apndLock(sqlite3_file *, int)
Definition shell.c:9856
static int apndRead(sqlite3_file *, void *, int iAmt, sqlite3_int64 iOfst)
Definition shell.c:9763
static int apndWrite(sqlite3_file *, const void *, int iAmt, sqlite3_int64 iOfst)
Definition shell.c:9805
static int apndClose(sqlite3_file *)
Definition shell.c:9755
static int apndTruncate(sqlite3_file *, sqlite3_int64 size)
Definition shell.c:9826
static int apndCheckReservedLock(sqlite3_file *, int *pResOut)
Definition shell.c:9872
static int apndUnlock(sqlite3_file *, int)
Definition shell.c:9864
static int apndFetch(sqlite3_file *, sqlite3_int64 iOfst, int iAmt, void **pp)
Definition shell.c:9939
static int apndFileSize(sqlite3_file *, sqlite3_int64 *pSize)
Definition shell.c:9847
9730 {
9731 3, /* iVersion */
9732 apndClose, /* xClose */
9733 apndRead, /* xRead */
9734 apndWrite, /* xWrite */
9735 apndTruncate, /* xTruncate */
9736 apndSync, /* xSync */
9737 apndFileSize, /* xFileSize */
9738 apndLock, /* xLock */
9739 apndUnlock, /* xUnlock */
9740 apndCheckReservedLock, /* xCheckReservedLock */
9741 apndFileControl, /* xFileControl */
9742 apndSectorSize, /* xSectorSize */
9743 apndDeviceCharacteristics, /* xDeviceCharacteristics */
9744 apndShmMap, /* xShmMap */
9745 apndShmLock, /* xShmLock */
9746 apndShmBarrier, /* xShmBarrier */
9747 apndShmUnmap, /* xShmUnmap */
9748 apndFetch, /* xFetch */
9749 apndUnfetch /* xUnfetch */
9750};

Referenced by apndOpen().

◆ apnd_vfs

sqlite3_vfs apnd_vfs
static
Initial value:
= {
3,
0,
1024,
0,
"apndvfs",
0,
}
static int apndOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int *)
Definition shell.c:10035
static int apndFullPathname(sqlite3_vfs *, const char *zName, int, char *zOut)
Definition shell.c:10117
static int apndCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64 *)
Definition shell.c:10149
static int apndAccess(sqlite3_vfs *, const char *zName, int flags, int *)
Definition shell.c:10109
static int apndDelete(sqlite3_vfs *, const char *zName, int syncDir)
Definition shell.c:10102
static void apndDlError(sqlite3_vfs *, int nByte, char *zErrMsg)
Definition shell.c:10128
static int apndRandomness(sqlite3_vfs *, int nByte, char *zOut)
Definition shell.c:10137
static int apndSleep(sqlite3_vfs *, int microseconds)
Definition shell.c:10140
static int apndSetSystemCall(sqlite3_vfs *, const char *, sqlite3_syscall_ptr)
Definition shell.c:10152
static const char * apndNextSystemCall(sqlite3_vfs *, const char *zName)
Definition shell.c:10165
static void * apndDlOpen(sqlite3_vfs *, const char *zFilename)
Definition shell.c:10125
static void(*)(void) apndDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym)
Definition shell.c:9694
static int apndGetLastError(sqlite3_vfs *, int, char *)
Definition shell.c:10146
static int apndCurrentTime(sqlite3_vfs *, double *)
Definition shell.c:10143
static sqlite3_syscall_ptr apndGetSystemCall(sqlite3_vfs *, const char *z)
Definition shell.c:10159
static void apndDlClose(sqlite3_vfs *, void *)
Definition shell.c:10134
9705 {
9706 3, /* iVersion (set when registered) */
9707 0, /* szOsFile (set when registered) */
9708 1024, /* mxPathname */
9709 0, /* pNext */
9710 "apndvfs", /* zName */
9711 0, /* pAppData (set when registered) */
9712 apndOpen, /* xOpen */
9713 apndDelete, /* xDelete */
9714 apndAccess, /* xAccess */
9715 apndFullPathname, /* xFullPathname */
9716 apndDlOpen, /* xDlOpen */
9717 apndDlError, /* xDlError */
9718 apndDlSym, /* xDlSym */
9719 apndDlClose, /* xDlClose */
9720 apndRandomness, /* xRandomness */
9721 apndSleep, /* xSleep */
9722 apndCurrentTime, /* xCurrentTime */
9723 apndGetLastError, /* xGetLastError */
9724 apndCurrentTimeInt64, /* xCurrentTimeInt64 */
9725 apndSetSystemCall, /* xSetSystemCall */
9726 apndGetSystemCall, /* xGetSystemCall */
9727 apndNextSystemCall /* xNextSystemCall */
9728};

Referenced by sqlite3_appendvfs_init().

◆ apndDlSym

void(*)(void) apndDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym) ( sqlite3_vfs * pVfs,
void * p,
const char * zSym )
static

◆ apvfsSqliteHdr

const char apvfsSqliteHdr[] = "SQLite format 3"
static

◆ Argv0

char* Argv0
static

Referenced by main(), and usage().

◆ [struct]

const struct { ... } aUWidth[]
Initial value:
= {
{0, 0x00300}, {1, 0x00370}, {0, 0x00483}, {1, 0x00487}, {0, 0x00488},
{1, 0x0048a}, {0, 0x00591}, {1, 0x005be}, {0, 0x005bf}, {1, 0x005c0},
{0, 0x005c1}, {1, 0x005c3}, {0, 0x005c4}, {1, 0x005c6}, {0, 0x005c7},
{1, 0x005c8}, {0, 0x00600}, {1, 0x00604}, {0, 0x00610}, {1, 0x00616},
{0, 0x0064b}, {1, 0x0065f}, {0, 0x00670}, {1, 0x00671}, {0, 0x006d6},
{1, 0x006e5}, {0, 0x006e7}, {1, 0x006e9}, {0, 0x006ea}, {1, 0x006ee},
{0, 0x0070f}, {1, 0x00710}, {0, 0x00711}, {1, 0x00712}, {0, 0x00730},
{1, 0x0074b}, {0, 0x007a6}, {1, 0x007b1}, {0, 0x007eb}, {1, 0x007f4},
{0, 0x00901}, {1, 0x00903}, {0, 0x0093c}, {1, 0x0093d}, {0, 0x00941},
{1, 0x00949}, {0, 0x0094d}, {1, 0x0094e}, {0, 0x00951}, {1, 0x00955},
{0, 0x00962}, {1, 0x00964}, {0, 0x00981}, {1, 0x00982}, {0, 0x009bc},
{1, 0x009bd}, {0, 0x009c1}, {1, 0x009c5}, {0, 0x009cd}, {1, 0x009ce},
{0, 0x009e2}, {1, 0x009e4}, {0, 0x00a01}, {1, 0x00a03}, {0, 0x00a3c},
{1, 0x00a3d}, {0, 0x00a41}, {1, 0x00a43}, {0, 0x00a47}, {1, 0x00a49},
{0, 0x00a4b}, {1, 0x00a4e}, {0, 0x00a70}, {1, 0x00a72}, {0, 0x00a81},
{1, 0x00a83}, {0, 0x00abc}, {1, 0x00abd}, {0, 0x00ac1}, {1, 0x00ac6},
{0, 0x00ac7}, {1, 0x00ac9}, {0, 0x00acd}, {1, 0x00ace}, {0, 0x00ae2},
{1, 0x00ae4}, {0, 0x00b01}, {1, 0x00b02}, {0, 0x00b3c}, {1, 0x00b3d},
{0, 0x00b3f}, {1, 0x00b40}, {0, 0x00b41}, {1, 0x00b44}, {0, 0x00b4d},
{1, 0x00b4e}, {0, 0x00b56}, {1, 0x00b57}, {0, 0x00b82}, {1, 0x00b83},
{0, 0x00bc0}, {1, 0x00bc1}, {0, 0x00bcd}, {1, 0x00bce}, {0, 0x00c3e},
{1, 0x00c41}, {0, 0x00c46}, {1, 0x00c49}, {0, 0x00c4a}, {1, 0x00c4e},
{0, 0x00c55}, {1, 0x00c57}, {0, 0x00cbc}, {1, 0x00cbd}, {0, 0x00cbf},
{1, 0x00cc0}, {0, 0x00cc6}, {1, 0x00cc7}, {0, 0x00ccc}, {1, 0x00cce},
{0, 0x00ce2}, {1, 0x00ce4}, {0, 0x00d41}, {1, 0x00d44}, {0, 0x00d4d},
{1, 0x00d4e}, {0, 0x00dca}, {1, 0x00dcb}, {0, 0x00dd2}, {1, 0x00dd5},
{0, 0x00dd6}, {1, 0x00dd7}, {0, 0x00e31}, {1, 0x00e32}, {0, 0x00e34},
{1, 0x00e3b}, {0, 0x00e47}, {1, 0x00e4f}, {0, 0x00eb1}, {1, 0x00eb2},
{0, 0x00eb4}, {1, 0x00eba}, {0, 0x00ebb}, {1, 0x00ebd}, {0, 0x00ec8},
{1, 0x00ece}, {0, 0x00f18}, {1, 0x00f1a}, {0, 0x00f35}, {1, 0x00f36},
{0, 0x00f37}, {1, 0x00f38}, {0, 0x00f39}, {1, 0x00f3a}, {0, 0x00f71},
{1, 0x00f7f}, {0, 0x00f80}, {1, 0x00f85}, {0, 0x00f86}, {1, 0x00f88},
{0, 0x00f90}, {1, 0x00f98}, {0, 0x00f99}, {1, 0x00fbd}, {0, 0x00fc6},
{1, 0x00fc7}, {0, 0x0102d}, {1, 0x01031}, {0, 0x01032}, {1, 0x01033},
{0, 0x01036}, {1, 0x01038}, {0, 0x01039}, {1, 0x0103a}, {0, 0x01058},
{1, 0x0105a}, {2, 0x01100}, {0, 0x01160}, {1, 0x01200}, {0, 0x0135f},
{1, 0x01360}, {0, 0x01712}, {1, 0x01715}, {0, 0x01732}, {1, 0x01735},
{0, 0x01752}, {1, 0x01754}, {0, 0x01772}, {1, 0x01774}, {0, 0x017b4},
{1, 0x017b6}, {0, 0x017b7}, {1, 0x017be}, {0, 0x017c6}, {1, 0x017c7},
{0, 0x017c9}, {1, 0x017d4}, {0, 0x017dd}, {1, 0x017de}, {0, 0x0180b},
{1, 0x0180e}, {0, 0x018a9}, {1, 0x018aa}, {0, 0x01920}, {1, 0x01923},
{0, 0x01927}, {1, 0x01929}, {0, 0x01932}, {1, 0x01933}, {0, 0x01939},
{1, 0x0193c}, {0, 0x01a17}, {1, 0x01a19}, {0, 0x01b00}, {1, 0x01b04},
{0, 0x01b34}, {1, 0x01b35}, {0, 0x01b36}, {1, 0x01b3b}, {0, 0x01b3c},
{1, 0x01b3d}, {0, 0x01b42}, {1, 0x01b43}, {0, 0x01b6b}, {1, 0x01b74},
{0, 0x01dc0}, {1, 0x01dcb}, {0, 0x01dfe}, {1, 0x01e00}, {0, 0x0200b},
{1, 0x02010}, {0, 0x0202a}, {1, 0x0202f}, {0, 0x02060}, {1, 0x02064},
{0, 0x0206a}, {1, 0x02070}, {0, 0x020d0}, {1, 0x020f0}, {2, 0x02329},
{1, 0x0232b}, {2, 0x02e80}, {0, 0x0302a}, {2, 0x03030}, {1, 0x0303f},
{2, 0x03040}, {0, 0x03099}, {2, 0x0309b}, {1, 0x0a4d0}, {0, 0x0a806},
{1, 0x0a807}, {0, 0x0a80b}, {1, 0x0a80c}, {0, 0x0a825}, {1, 0x0a827},
{2, 0x0ac00}, {1, 0x0d7a4}, {2, 0x0f900}, {1, 0x0fb00}, {0, 0x0fb1e},
{1, 0x0fb1f}, {0, 0x0fe00}, {2, 0x0fe10}, {1, 0x0fe1a}, {0, 0x0fe20},
{1, 0x0fe24}, {2, 0x0fe30}, {1, 0x0fe70}, {0, 0x0feff}, {2, 0x0ff00},
{1, 0x0ff61}, {2, 0x0ffe0}, {1, 0x0ffe7}, {0, 0x0fff9}, {1, 0x0fffc},
{0, 0x10a01}, {1, 0x10a04}, {0, 0x10a05}, {1, 0x10a07}, {0, 0x10a0c},
{1, 0x10a10}, {0, 0x10a38}, {1, 0x10a3b}, {0, 0x10a3f}, {1, 0x10a40},
{0, 0x1d167}, {1, 0x1d16a}, {0, 0x1d173}, {1, 0x1d183}, {0, 0x1d185},
{1, 0x1d18c}, {0, 0x1d1aa}, {1, 0x1d1ae}, {0, 0x1d242}, {1, 0x1d245},
{2, 0x20000}, {1, 0x2fffe}, {2, 0x30000}, {1, 0x3fffe}, {0, 0xe0001},
{1, 0xe0002}, {0, 0xe0020}, {1, 0xe0080}, {0, 0xe0100}, {1, 0xe01f0}
}

Referenced by cli_wcwidth().

◆ azHelp

const char* azHelp[]
static
25278 {
25279#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
25280 && !defined(SQLITE_SHELL_FIDDLE)
25281 ".archive ... Manage SQL archives",
25282 " Each command must have exactly one of the following options:",
25283 " -c, --create Create a new archive",
25284 " -u, --update Add or update files with changed mtime",
25285 " -i, --insert Like -u but always add even if unchanged",
25286 " -r, --remove Remove files from archive",
25287 " -t, --list List contents of archive",
25288 " -x, --extract Extract files from archive",
25289 " Optional arguments:",
25290 " -v, --verbose Print each filename as it is processed",
25291 " -f FILE, --file FILE Use archive FILE (default is current db)",
25292 " -a FILE, --append FILE Open FILE using the apndvfs VFS",
25293 " -C DIR, --directory DIR Read/extract files from directory DIR",
25294 " -g, --glob Use glob matching for names in archive",
25295 " -n, --dryrun Show the SQL that would have occurred",
25296 " Examples:",
25297 " .ar -cf ARCHIVE foo bar # Create ARCHIVE from files foo and bar",
25298 " .ar -tf ARCHIVE # List members of ARCHIVE",
25299 " .ar -xvf ARCHIVE # Verbosely extract files from ARCHIVE",
25300 " See also:",
25301 " http://sqlite.org/cli.html#sqlite_archive_support",
25302#endif
25303#ifndef SQLITE_OMIT_AUTHORIZATION
25304 ".auth ON|OFF Show authorizer callbacks",
25305#endif
25306#ifndef SQLITE_SHELL_FIDDLE
25307 ".backup ?DB? FILE Backup DB (default \"main\") to FILE",
25308 " Options:",
25309 " --append Use the appendvfs",
25310 " --async Write to FILE without journal and fsync()",
25311#endif
25312 ".bail on|off Stop after hitting an error. Default OFF",
25313#ifndef SQLITE_SHELL_FIDDLE
25314 ".cd DIRECTORY Change the working directory to DIRECTORY",
25315#endif
25316 ".changes on|off Show number of rows changed by SQL",
25317#ifndef SQLITE_SHELL_FIDDLE
25318 ".check GLOB Fail if output since .testcase does not match",
25319 ".clone NEWDB Clone data into NEWDB from the existing database",
25320#endif
25321 ".connection [close] [#] Open or close an auxiliary database connection",
25322 ".crlf ?on|off? Whether or not to use \\r\\n line endings",
25323 ".databases List names and files of attached databases",
25324 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
25325#if SQLITE_SHELL_HAVE_RECOVER
25326 ".dbinfo ?DB? Show status information about the database",
25327#endif
25328 ".dbtotxt Hex dump of the database file",
25329 ".dump ?OBJECTS? Render database content as SQL",
25330 " Options:",
25331 " --data-only Output only INSERT statements",
25332 " --newlines Allow unescaped newline characters in output",
25333 " --nosys Omit system tables (ex: \"sqlite_stat1\")",
25334 " --preserve-rowids Include ROWID values in the output",
25335 " OBJECTS is a LIKE pattern for tables, indexes, triggers or views to dump",
25336 " Additional LIKE patterns can be given in subsequent arguments",
25337 ".echo on|off Turn command echo on or off",
25338 ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
25339 " Other Modes:",
25340#ifdef SQLITE_DEBUG
25341 " test Show raw EXPLAIN QUERY PLAN output",
25342 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
25343#endif
25344 " trigger Like \"full\" but also show trigger bytecode",
25345#ifndef SQLITE_SHELL_FIDDLE
25346 ".excel Display the output of next command in spreadsheet",
25347 " --bom Put a UTF8 byte-order mark on intermediate file",
25348#endif
25349#ifndef SQLITE_SHELL_FIDDLE
25350 ".exit ?CODE? Exit this program with return-code CODE",
25351#endif
25352 ".expert EXPERIMENTAL. Suggest indexes for queries",
25353 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
25354 ".filectrl CMD ... Run various sqlite3_file_control() operations",
25355 " --schema SCHEMA Use SCHEMA instead of \"main\"",
25356 " --help Show CMD details",
25357 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
25358 ".headers on|off Turn display of headers on or off",
25359 ".help ?-all? ?PATTERN? Show help text for PATTERN",
25360#ifndef SQLITE_SHELL_FIDDLE
25361 ".import FILE TABLE Import data from FILE into TABLE",
25362 " Options:",
25363 " --ascii Use \\037 and \\036 as column and row separators",
25364 " --csv Use , and \\n as column and row separators",
25365 " --skip N Skip the first N rows of input",
25366 " --schema S Target table to be S.TABLE",
25367 " -v \"Verbose\" - increase auxiliary output",
25368 " Notes:",
25369 " * If TABLE does not exist, it is created. The first row of input",
25370 " determines the column names.",
25371 " * If neither --csv or --ascii are used, the input mode is derived",
25372 " from the \".mode\" output mode",
25373 " * If FILE begins with \"|\" then it is a command that generates the",
25374 " input text.",
25375#endif
25376#ifndef SQLITE_OMIT_TEST_CONTROL
25377 ",imposter INDEX TABLE Create imposter table TABLE on index INDEX",
25378#endif
25379 ".indexes ?TABLE? Show names of indexes",
25380 " If TABLE is specified, only show indexes for",
25381 " tables matching TABLE using the LIKE operator.",
25382 ".intck ?STEPS_PER_UNLOCK? Run an incremental integrity check on the db",
25383#ifdef SQLITE_ENABLE_IOTRACE
25384 ",iotrace FILE Enable I/O diagnostic logging to FILE",
25385#endif
25386 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
25387 ".lint OPTIONS Report potential schema issues.",
25388 " Options:",
25389 " fkey-indexes Find missing foreign key indexes",
25390#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
25391 ".load FILE ?ENTRY? Load an extension library",
25392#endif
25393#if !defined(SQLITE_SHELL_FIDDLE)
25394 ".log FILE|on|off Turn logging on or off. FILE can be stderr/stdout",
25395#else
25396 ".log on|off Turn logging on or off.",
25397#endif
25398 ".mode ?MODE? ?OPTIONS? Set output mode",
25399 " MODE is one of:",
25400 " ascii Columns/rows delimited by 0x1F and 0x1E",
25401 " box Tables using unicode box-drawing characters",
25402 " csv Comma-separated values",
25403 " column Output in columns. (See .width)",
25404 " html HTML <table> code",
25405 " insert SQL insert statements for TABLE",
25406 " json Results in a JSON array",
25407 " line One value per line",
25408 " list Values delimited by \"|\"",
25409 " markdown Markdown table format",
25410 " qbox Shorthand for \"box --wrap 60 --quote\"",
25411 " quote Escape answers as for SQL",
25412 " table ASCII-art table",
25413 " tabs Tab-separated values",
25414 " tcl TCL list elements",
25415 " OPTIONS: (for columnar modes or insert mode):",
25416 " --escape T ctrl-char escape; T is one of: symbol, ascii, off",
25417 " --wrap N Wrap output lines to no longer than N characters",
25418 " --wordwrap B Wrap or not at word boundaries per B (on/off)",
25419 " --ww Shorthand for \"--wordwrap 1\"",
25420 " --quote Quote output text as SQL literals",
25421 " --noquote Do not quote output text",
25422 " TABLE The name of SQL table used for \"insert\" mode",
25423#ifndef SQLITE_SHELL_FIDDLE
25424 ".nonce STRING Suspend safe mode for one command if nonce matches",
25425#endif
25426 ".nullvalue STRING Use STRING in place of NULL values",
25427#ifndef SQLITE_SHELL_FIDDLE
25428 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
25429 " If FILE begins with '|' then open as a pipe",
25430 " --bom Put a UTF8 byte-order mark at the beginning",
25431 " -e Send output to the system text editor",
25432 " --plain Use text/plain output instead of HTML for -w option",
25433 " -w Send output as HTML to a web browser (same as \".www\")",
25434 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
25435 /* Note that .open is (partially) available in WASM builds but is
25436 ** currently only intended to be used by the fiddle tool, not
25437 ** end users, so is "undocumented." */
25438 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
25439 " Options:",
25440 " --append Use appendvfs to append database to the end of FILE",
25441#endif
25442#ifndef SQLITE_OMIT_DESERIALIZE
25443 " --deserialize Load into memory using sqlite3_deserialize()",
25444 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
25445 " --maxsize N Maximum size for --hexdb or --deserialized database",
25446#endif
25447 " --new Initialize FILE to an empty database",
25448 " --nofollow Do not follow symbolic links",
25449 " --readonly Open FILE readonly",
25450 " --zip FILE is a ZIP archive",
25451#ifndef SQLITE_SHELL_FIDDLE
25452 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
25453 " If FILE begins with '|' then open it as a pipe.",
25454 " If FILE is 'off' then output is disabled.",
25455 " Options:",
25456 " --bom Prefix output with a UTF8 byte-order mark",
25457 " -e Send output to the system text editor",
25458 " --plain Use text/plain for -w option",
25459 " -w Send output to a web browser",
25460 " -x Send output as CSV to a spreadsheet",
25461#endif
25462 ".parameter CMD ... Manage SQL parameter bindings",
25463 " clear Erase all bindings",
25464 " init Initialize the TEMP table that holds bindings",
25465 " list List the current parameter bindings",
25466 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
25467 " PARAMETER should start with one of: $ : @ ?",
25468 " unset PARAMETER Remove PARAMETER from the binding table",
25469 ".print STRING... Print literal STRING",
25470#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
25471 ".progress N Invoke progress handler after every N opcodes",
25472 " --limit N Interrupt after N progress callbacks",
25473 " --once Do no more than one progress interrupt",
25474 " --quiet|-q No output except at interrupts",
25475 " --reset Reset the count for each input and interrupt",
25476#endif
25477 ".prompt MAIN CONTINUE Replace the standard prompts",
25478#ifndef SQLITE_SHELL_FIDDLE
25479 ".quit Stop interpreting input stream, exit if primary.",
25480 ".read FILE Read input from FILE or command output",
25481 " If FILE begins with \"|\", it is a command that generates the input.",
25482#endif
25483#if SQLITE_SHELL_HAVE_RECOVER
25484 ".recover Recover as much data as possible from corrupt db.",
25485 " --ignore-freelist Ignore pages that appear to be on db freelist",
25486 " --lost-and-found TABLE Alternative name for the lost-and-found table",
25487 " --no-rowids Do not attempt to recover rowid values",
25488 " that are not also INTEGER PRIMARY KEYs",
25489#endif
25490#ifndef SQLITE_SHELL_FIDDLE
25491 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
25492 ".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
25493#endif
25494 ".scanstats on|off|est Turn sqlite3_stmt_scanstatus() metrics on or off",
25495 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
25496 " Options:",
25497 " --indent Try to pretty-print the schema",
25498 " --nosys Omit objects whose names start with \"sqlite_\"",
25499 ",selftest ?OPTIONS? Run tests defined in the SELFTEST table",
25500 " Options:",
25501 " --init Create a new SELFTEST table",
25502 " -v Verbose output",
25503 ".separator COL ?ROW? Change the column and row separators",
25504#if defined(SQLITE_ENABLE_SESSION)
25505 ".session ?NAME? CMD ... Create or control sessions",
25506 " Subcommands:",
25507 " attach TABLE Attach TABLE",
25508 " changeset FILE Write a changeset into FILE",
25509 " close Close one session",
25510 " enable ?BOOLEAN? Set or query the enable bit",
25511 " filter GLOB... Reject tables matching GLOBs",
25512 " indirect ?BOOLEAN? Mark or query the indirect status",
25513 " isempty Query whether the session is empty",
25514 " list List currently open session names",
25515 " open DB NAME Open a new session on DB",
25516 " patchset FILE Write a patchset into FILE",
25517 " If ?NAME? is omitted, the first defined session is used.",
25518#endif
25519 ".sha3sum ... Compute a SHA3 hash of database content",
25520 " Options:",
25521 " --schema Also hash the sqlite_schema table",
25522 " --sha3-224 Use the sha3-224 algorithm",
25523 " --sha3-256 Use the sha3-256 algorithm (default)",
25524 " --sha3-384 Use the sha3-384 algorithm",
25525 " --sha3-512 Use the sha3-512 algorithm",
25526 " Any other argument is a LIKE pattern for tables to hash",
25527#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
25528 ".shell CMD ARGS... Run CMD ARGS... in a system shell",
25529#endif
25530 ".show Show the current values for various settings",
25531 ".stats ?ARG? Show stats or turn stats on or off",
25532 " off Turn off automatic stat display",
25533 " on Turn on automatic stat display",
25534 " stmt Show statement stats",
25535 " vmstep Show the virtual machine step count only",
25536#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
25537 ".system CMD ARGS... Run CMD ARGS... in a system shell",
25538#endif
25539 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
25540#ifndef SQLITE_SHELL_FIDDLE
25541 ",testcase NAME Begin redirecting output to 'testcase-out.txt'",
25542#endif
25543 ",testctrl CMD ... Run various sqlite3_test_control() operations",
25544 " Run \".testctrl\" with no arguments for details",
25545 ".timeout MS Try opening locked tables for MS milliseconds",
25546 ".timer on|off Turn SQL timer on or off",
25547#ifndef SQLITE_OMIT_TRACE
25548 ".trace ?OPTIONS? Output each SQL statement as it is run",
25549 " FILE Send output to FILE",
25550 " stdout Send output to stdout",
25551 " stderr Send output to stderr",
25552 " off Disable tracing",
25553 " --expanded Expand query parameters",
25554#ifdef SQLITE_ENABLE_NORMALIZE
25555 " --normalized Normal the SQL statements",
25556#endif
25557 " --plain Show SQL as it is input",
25558 " --stmt Trace statement execution (SQLITE_TRACE_STMT)",
25559 " --profile Profile statements (SQLITE_TRACE_PROFILE)",
25560 " --row Trace each row (SQLITE_TRACE_ROW)",
25561 " --close Trace connection close (SQLITE_TRACE_CLOSE)",
25562#endif /* SQLITE_OMIT_TRACE */
25563#ifdef SQLITE_DEBUG
25564 ".unmodule NAME ... Unregister virtual table modules",
25565 " --allexcept Unregister everything except those named",
25566#endif
25567 ".version Show source, library and compiler versions",
25568 ".vfsinfo ?AUX? Information about the top-level VFS",
25569 ".vfslist List all available VFSes",
25570 ".vfsname ?AUX? Print the name of the VFS stack",
25571 ".width NUM1 NUM2 ... Set minimum column widths for columnar output",
25572 " Negative values right-justify",
25573#ifndef SQLITE_SHELL_FIDDLE
25574 ".www Display output of the next command in web browser",
25575 " --plain Show results as text/plain, not as HTML",

Referenced by showHelp().

◆ b64DigitValues

const u8 b64DigitValues[128]
static
Initial value:
= {
0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x81 , 0x81 , 0x81 , 0x81 , 0x81 , 0x82 , 0x82 ,
0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 ,
0x81 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 , 0x82 ,62, 0x82 , 0x82 , 0x82 ,63,
52,53,54,55, 56,57,58,59, 60,61, 0x82 , 0x82 , 0x82 , 0x80 , 0x82 , 0x82 ,
0x82 , 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
15,16,17,18, 19,20,21,22, 23,24,25, 0x82 , 0x82 , 0x82 , 0x82 , 0x82 ,
0x82 ,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41,42,43,44, 45,46,47,48, 49,50,51, 0x82 , 0x82 , 0x82 , 0x82 , 0x82
}
5173 {
5174 /* HT LF VT FF CR */
5175 ND,ND,ND,ND, ND,ND,ND,ND, ND,WS,WS,WS, WS,WS,ND,ND,
5176 /* US */
5177 ND,ND,ND,ND, ND,ND,ND,ND, ND,ND,ND,ND, ND,ND,ND,ND,
5178 /*sp + / */
5179 WS,ND,ND,ND, ND,ND,ND,ND, ND,ND,ND,62, ND,ND,ND,63,
5180 /* 0 1 5 9 = */
5181 52,53,54,55, 56,57,58,59, 60,61,ND,ND, ND,PC,ND,ND,
5182 /* A O */
5183 ND, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
5184 /* P Z */
5185 15,16,17,18, 19,20,21,22, 23,24,25,ND, ND,ND,ND,ND,
5186 /* a o */
5187 ND,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
5188 /* p z */
5189 41,42,43,44, 45,46,47,48, 49,50,51,ND, ND,ND,ND,ND
5190};

◆ b64Numerals

const char b64Numerals[64+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
static

Referenced by fromBase64().

◆ b85_cOffset

u8 b85_cOffset[] = { 0, '#', 0, '*'-4, 0 }
static
5519{ 0, '#', 0, '*'-4, 0 };

◆ bail_on_error

int bail_on_error = 0
static

◆ completionModule

sqlite3_module completionModule
static
Initial value:
= {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}
static int completionClose(sqlite3_vtab_cursor *cur)
Definition shell.c:9196
static int completionFilter(sqlite3_vtab_cursor *pVtabCursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
Definition shell.c:9376
static int completionRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid)
Definition shell.c:9355
static int completionColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
Definition shell.c:9324
static int completionDisconnect(sqlite3_vtab *pVtab)
Definition shell.c:9165
static int completionConnect(sqlite3 *db, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVtab, char **pzErr)
Definition shell.c:9123
static int completionEof(sqlite3_vtab_cursor *cur)
Definition shell.c:9365
static int completionOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor)
Definition shell.c:9173
static int completionBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo)
Definition shell.c:9427
9472 {
9473 0, /* iVersion */
9474 0, /* xCreate */
9475 completionConnect, /* xConnect */
9476 completionBestIndex, /* xBestIndex */
9477 completionDisconnect, /* xDisconnect */
9478 0, /* xDestroy */
9479 completionOpen, /* xOpen - open a cursor */
9480 completionClose, /* xClose - close a cursor */
9481 completionFilter, /* xFilter - configure scan constraints */
9482 completionNext, /* xNext - advance a cursor */
9483 completionEof, /* xEof - check for end of scan */
9484 completionColumn, /* xColumn - read data */
9485 completionRowid, /* xRowid - read data */
9486 0, /* xUpdate */
9487 0, /* xBegin */
9488 0, /* xSync */
9489 0, /* xCommit */
9490 0, /* xRollback */
9491 0, /* xFindMethod */
9492 0, /* xRename */
9493 0, /* xSavepoint */
9494 0, /* xRelease */
9495 0, /* xRollbackTo */
9496 0, /* xShadowName */
9497 0 /* xIntegrity */
9498};

Referenced by sqlite3CompletionVtabInit().

◆ continuePrompt

char continuePrompt[128]
static

◆ dynPrompt

struct DynaPrompt dynPrompt = { {0}, {0}, 0, 0 }
static

Referenced by dynamicContinuePrompt().

◆ enableTimer

int enableTimer = 0
static

◆ ersaztMethods

sqlite3_mem_methods ersaztMethods
static
Initial value:
= {
0
}
static void * memtraceRealloc(void *p, int n)
Definition shell.c:2085
static int memtraceInit(void *p)
Definition shell.c:2103
static int memtraceSize(void *p)
Definition shell.c:2097
static int memtraceRoundup(int n)
Definition shell.c:2100
static void memtraceShutdown(void *p)
Definition shell.c:2106
2111 {
2119 0
2120};

Referenced by sqlite3MemTraceActivate().

◆ ersaztPcacheMethods

sqlite3_pcache_methods2 ersaztPcacheMethods
static
Initial value:
= {
0,
0,
}
static void pcachetraceUnpin(sqlite3_pcache *p, sqlite3_pcache_page *pPg, int bDiscard)
Definition shell.c:2245
static int pcachetraceInit(void *pArg)
Definition shell.c:2182
static void pcachetraceShutdown(void *pArg)
Definition shell.c:2193
static void pcachetraceDestroy(sqlite3_pcache *p)
Definition shell.c:2274
static void pcachetraceCachesize(sqlite3_pcache *p, int nCachesize)
Definition shell.c:2212
static sqlite3_pcache_page * pcachetraceFetch(sqlite3_pcache *p, unsigned key, int crFg)
Definition shell.c:2229
static void pcachetraceRekey(sqlite3_pcache *p, sqlite3_pcache_page *pPg, unsigned oldKey, unsigned newKey)
Definition shell.c:2256
static void pcachetraceTruncate(sqlite3_pcache *p, unsigned n)
Definition shell.c:2268
static int pcachetracePagecount(sqlite3_pcache *p)
Definition shell.c:2218
static sqlite3_pcache * pcachetraceCreate(int szPage, int szExtra, int bPurge)
Definition shell.c:2199
static void pcachetraceShrink(sqlite3_pcache *p)
Definition shell.c:2280

Referenced by sqlite3PcacheTraceActivate().

◆ [struct]

struct { ... } faultsim_state

◆ globalDb

sqlite3* globalDb = 0
static

◆ iBegin

sqlite3_int64 iBegin
static

Referenced by beginTimer(), and endTimer().

◆ mainPrompt

char mainPrompt[128]
static

◆ memtraceBase

◆ memtraceOut

◆ modeDescr

const char* modeDescr[]
static
Initial value:
= {
"line",
"column",
"list",
"semi",
"html",
"insert",
"quote",
"tcl",
"csv",
"explain",
"ascii",
"prettyprint",
"eqp",
"json",
"markdown",
"table",
"box",
"count",
"off",
"scanexp",
"www",
}
21841 {
21842 "line",
21843 "column",
21844 "list",
21845 "semi",
21846 "html",
21847 "insert",
21848 "quote",
21849 "tcl",
21850 "csv",
21851 "explain",
21852 "ascii",
21853 "prettyprint",
21854 "eqp",
21855 "json",
21856 "markdown",
21857 "table",
21858 "box",
21859 "count",
21860 "off",
21861 "scanexp",

Referenced by do_meta_command().

◆ needCsvQuote

const char needCsvQuote[]
static
Initial value:
= {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
}
22498 {
22499 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22500 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22501 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
22502 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22503 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22504 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22505 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22506 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
22507 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22508 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22509 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22510 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22511 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22512 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22513 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,

Referenced by output_csv().

◆ pcacheBase

◆ pcachetraceOut

◆ savedSelectTrace

unsigned int savedSelectTrace
static

◆ savedWhereTrace

unsigned int savedWhereTrace
static

◆ sBegin

struct rusage sBegin
static

Referenced by beginTimer(), and endTimer().

◆ seenInterrupt

◆ seriesModule

sqlite3_module seriesModule
static
Initial value:
= {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}
static int seriesClose(sqlite3_vtab_cursor *cur)
Definition shell.c:6502
static int seriesNext(sqlite3_vtab_cursor *cur)
Definition shell.c:6511
static int seriesConnect(sqlite3 *db, void *pUnused, int argcUnused, const char *const *argvUnused, sqlite3_vtab **ppVtab, char **pzErrUnused)
Definition shell.c:6446
static int seriesOpen(sqlite3_vtab *pUnused, sqlite3_vtab_cursor **ppCursor)
Definition shell.c:6489
static int seriesColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
Definition shell.c:6521
static int seriesBestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pIdxInfo)
Definition shell.c:6821
static int seriesEof(sqlite3_vtab_cursor *cur)
Definition shell.c:6557
static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid)
Definition shell.c:6547
static int seriesFilter(sqlite3_vtab_cursor *pVtabCursor, int idxNum, const char *idxStrUnused, int argc, sqlite3_value **argv)
Definition shell.c:6597
static int seriesDisconnect(sqlite3_vtab *pVtab)
Definition shell.c:6481
6997 {
6998 0, /* iVersion */
6999 0, /* xCreate */
7000 seriesConnect, /* xConnect */
7001 seriesBestIndex, /* xBestIndex */
7002 seriesDisconnect, /* xDisconnect */
7003 0, /* xDestroy */
7004 seriesOpen, /* xOpen - open a cursor */
7005 seriesClose, /* xClose - close a cursor */
7006 seriesFilter, /* xFilter - configure scan constraints */
7007 seriesNext, /* xNext - advance a cursor */
7008 seriesEof, /* xEof - check for end of scan */
7009 seriesColumn, /* xColumn - read data */
7010 seriesRowid, /* xRowid - read data */
7011 0, /* xUpdate */
7012 0, /* xBegin */
7013 0, /* xSync */
7014 0, /* xCommit */
7015 0, /* xRollback */
7016 0, /* xFindMethod */
7017 0, /* xRename */
7018 0, /* xSavepoint */
7019 0, /* xRelease */
7020 0, /* xRollbackTo */
7021 0, /* xShadowName */
7022 0 /* xIntegrity */
7023};

Referenced by sqlite3_series_init().

◆ shell_EscModeNames

const char* shell_EscModeNames[] = { "ascii", "symbol", "off" }
static

Referenced by do_meta_command(), and main().

◆ stdin_is_interactive

int stdin_is_interactive = 1
static

◆ stdout_is_console

int stdout_is_console = 1
static

Referenced by main().

◆ vfstraceDlSym

void(*)(void) vfstraceDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym) ( sqlite3_vfs * pVfs,
void * p,
const char * zSymbol )
static

Referenced by vfstrace_register().

◆ zCOL_DB

const char* zCOL_DB = ":memory:"
static

Referenced by zAutoColumn().

◆ zOptions

const char zOptions[]
static
Initial value:
=
" -- treat no subsequent arguments as options\n"
" -append append the database to the end of the file\n"
" -ascii set output mode to 'ascii'\n"
" -bail stop after hitting an error\n"
" -batch force batch I/O\n"
" -box set output mode to 'box'\n"
" -column set output mode to 'column'\n"
" -cmd COMMAND run \"COMMAND\" before reading stdin\n"
" -csv set output mode to 'csv'\n"
" -deserialize open the database using sqlite3_deserialize()\n"
" -echo print inputs before execution\n"
" -escape T ctrl-char escape; T is one of: symbol, ascii, off\n"
" -init FILENAME read/process named file\n"
" -[no]header turn headers on or off\n"
" -help show this message\n"
" -html set output mode to HTML\n"
" -interactive force interactive I/O\n"
" -json set output mode to 'json'\n"
" -line set output mode to 'line'\n"
" -list set output mode to 'list'\n"
" -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
" -markdown set output mode to 'markdown'\n"
" -maxsize N maximum size for a --deserialize database\n"
" -memtrace trace all memory allocations and deallocations\n"
" -mmap N default mmap size set to N\n"
" -newline SEP set output row separator. Default: '\\n'\n"
" -nofollow refuse to open symbolic links to database files\n"
" -nonce STRING set the safe-mode escape nonce\n"
" -no-rowid-in-view Disable rowid-in-view using sqlite3_config()\n"
" -nullvalue TEXT set text string for NULL values. Default ''\n"
" -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
" -pcachetrace trace all page cache operations\n"
" -quote set output mode to 'quote'\n"
" -readonly open the database read-only\n"
" -safe enable safe-mode\n"
" -separator SEP set output column separator. Default: '|'\n"
" -stats print memory stats before each finalize\n"
" -table set output mode to 'table'\n"
" -tabs set output mode to 'tabs'\n"
" -unsafe-testing allow unsafe commands and modes for testing\n"
" -version show SQLite version\n"
" -vfs NAME use NAME as the default VFS\n"
" -vfstrace enable tracing of all VFS calls\n"

Referenced by usage().