typedef sqlite3_int64 i64;
typedef sqlite3_uint64 u64;
typedef unsigned char u8;
+typedef unsigned short u16;
#if SQLITE_USER_AUTHENTICATION
# include "sqlite3userauth.h"
#endif
#if defined(_WIN32) || defined(WIN32)
/* For interactive input on Windows systems, translate the
** multi-byte characterset characters into UTF-8. */
- if( stdin_is_interactive && pInSrc==&stdInSource) ){
+ if( stdin_is_interactive && pInSrc==&stdInSource ){
char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
if( zTrans ){
int nTrans = strlen30(zTrans)+1;
/* Runtime test for shell extended parsing, given ShellState pointer */
#if SHELL_EXTENDED_PARSING
-# define SHEXT_PARSING(pSS) (pSS->bExtendedDotCmds & (1<<SHEXT_PARSING_BIT) !=0)
+# define SHEXT_PARSING(pSS) ((pSS->bExtendedDotCmds&(1<<SHEXT_PARSING_BIT))!=0)
#else
# define SHEXT_PARSING(pSS) 0
#endif
/* Runtime test for shell variable expansion, given ShellState pointer */
#if SHELL_EXTENDED_PARSING
-# define SHEXT_VAREXP(pSS) (pSS->bExtendedDotCmds & (1<<SHEXT_VAREXP_BIT) !=0)
+# define SHEXT_VAREXP(pSS) ((pSS->bExtendedDotCmds&(1<<SHEXT_VAREXP_BIT))!=0)
#else
# define SHEXT_VAREXP(pSS) 0
#endif
#define ColModeOpts_default { 60, 0, 0 }
#define ColModeOpts_default_qbox { 60, 1, 0 }
+typedef struct OutModeState {
+ u8 showHeader; /* True to show column names in List or Column mode */
+ u8 mode; /* An output mode setting */
+ u16 shellFlgs; /* Various flags */
+ ColModeOpts cmOpts; /* Option values affecting columnar mode output */
+ char colSeparator[20]; /* Column separator character for several modes */
+ char rowSeparator[20]; /* Row separator character for MODE_Ascii */
+} OutModeState;
+
/*
** State information about the database connection is contained in an
** instance of the following structure.
u8 autoEQPtrace; /* autoEQP is in trace mode */
u8 scanstatsOn; /* True to display scan stats before each finalize */
u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
+ int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
u8 nEqpLevel; /* Depth of the EQP output graph */
u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
u8 bSafeModePersist; /* The long-term value of bSafeMode */
u8 bAllowSysDump; /* Allow .dump use for sqlite_* tables. */
u8 bExtendedDotCmds; /* Bits set to enable various shell extensions */
+
+ u8 showHeader; /* True to show column names in List or Column mode */
+ u16 shellFlgs; /* Various flags */
+ u16 priorShFlgs; /* Saved copy of flags */
+ u8 mode; /* An output mode setting */
+ u8 modePrior; /* Saved mode */
+ u8 cMode; /* temporary output mode for the current query */
+ u8 normalMode; /* Output mode before ".explain on" */
ColModeOpts cmOpts; /* Option values affecting columnar mode output */
+ char colSeparator[20]; /* Column separator character for several modes */
+ char colSepPrior[20]; /* Saved column separator */
+ char rowSeparator[20]; /* Row separator character for MODE_Ascii */
+ char rowSepPrior[20]; /* Saved row separator */
+
+ int *colWidth; /* Requested width of each column in columnar modes */
+ int *actualWidth; /* Actual width of each column */
+ int nWidth; /* Number of slots in colWidth[] and actualWidth[] */
+ char nullValue[20]; /* Text to print for NULL retrieved from database */
+
unsigned statsOn; /* True to display memory stats before each finalize */
- u8 bQuote; /* Quote results for .mode box and table */
- int iWrap; /* In columnar modes, wrap lines reaching this limit */
unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
int inputNesting; /* Track nesting level of .read and other redirects */
int outCount; /* Revert to stdout when reaching zero */
int cnt; /* Number of records displayed so far */
- int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
InSource *pInSource; /* Read commands and SQL from this stream source */
FILE *out; /* Write results here */
FILE *traceOut; /* Output for sqlite3_trace() */
int nErr; /* Number of errors seen */
- int mode; /* An output mode setting */
- int modePrior; /* Saved mode */
- int cMode; /* temporary output mode for the current query */
- int normalMode; /* Output mode before ".explain on" */
int writableSchema; /* True if PRAGMA writable_schema=ON */
- int showHeader; /* True to show column names in List or Column mode */
int nCheck; /* Number of ".check" commands run */
unsigned nProgress; /* Number of progress callbacks encountered */
unsigned mxProgress; /* Maximum progress callbacks before failing */
unsigned flgProgress; /* Flags for the progress callback */
- unsigned shellFlgs; /* Various flags */
- unsigned priorShFlgs; /* Saved copy of flags */
sqlite3_int64 szMax; /* --maxsize argument to .open */
char *zDestTable; /* Name of destination table when MODE_Insert */
char *zTempFile; /* Temporary file that might need deleting */
char *zEditor; /* Name of editor if non-zero, then deletable */
char zTestcase[30]; /* Name of current test case */
- char colSeparator[20]; /* Column separator character for several modes */
- char rowSeparator[20]; /* Row separator character for MODE_Ascii */
- char colSepPrior[20]; /* Saved column separator */
- char rowSepPrior[20]; /* Saved row separator */
- int *colWidth; /* Requested width of each column in columnar modes */
- int *actualWidth; /* Actual width of each column */
- int nWidth; /* Number of slots in colWidth[] and actualWidth[] */
- char nullValue[20]; /* Text to print for NULL retrieved from database */
char outfile[FILENAME_MAX]; /* Filename for *out */
sqlite3_stmt *pStmt; /* Current statement if any. */
FILE *pLog; /* Write log output here */
" --bom Prefix output with a UTF8 byte-order mark",
" -e Send output to the system text editor",
" -x Send output as CSV to a spreadsheet",
- ".parameter CMD ... Manage SQL parameter bindings",
- " clear ?NAMES? Erase some or all parameter bindings",
+ ".parameter CMD ... Manage SQL parameter bindings and scripts table",
+ " clear ?NAMES? Erase some or all named parameters",
#ifndef SQLITE_NOHAVE_SYSTEM
" edit NAME Use edit() to create or alter parameter NAME",
#endif
- " init Initialize the TEMP table that holds bindings",
- " list List the current parameter bindings",
- " load FILE ?NAMES? Load some or all parameter bindings from FILE",
- " save FILE ?NAMES? Save some or all parameter bindings into FILE",
+ " init Initialize TEMP table for bindings and scripts",
+ " list List parameters table binding and script values",
+ " load ?FILE? ?NAMES? Load some or all named parameters from FILE",
+ " If FILE missing, empty or '~', it defaults to ~/sqlite_params.sdb",
+ " save ?FILE? ?NAMES? Save some or all named parameters into FILE",
+ " If FILE missing, empty or '~', it defaults to ~/sqlite_params.sdb",
" set ?TOPT? NAME VALUE Give SQL parameter NAME a value of VALUE",
- " NAME must begin with $,:,@, or ? for bindings, or a letter to be",
- " executable; the value is following argument list, space-joined.",
+ " NAME must begin with one of $,:,@,? for bindings, or with a letter",
+ " to be executable; the value is following argument list, space-joined.",
" Option TOPT may be one of {-b -i -n -r -t} to cast effective value",
" to BLOB, INT, NUMERIC, REAL or TEXT respectively.",
- " unset ?NAMES? Remove named parameter(s) from the binding table",
+ " unset ?NAMES? Remove named parameter(s) from parameters table",
".print STRING... Print literal STRING, then a newline",
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
".progress N Invoke progress handler after every N opcodes",
** Otherwise, assume an ordinary database regardless of the filename if
** the type cannot be determined from content.
*/
-int deduceDatabaseType(const char *zName, int dfltZip){
+u8 deduceDatabaseType(const char *zName, int dfltZip){
FILE *f = fopen(zName, "rb");
size_t n;
- int rc = SHELL_OPEN_UNSPEC;
+ u8 rc = SHELL_OPEN_UNSPEC;
char zBuf[100];
if( f==0 ){
if( dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){
if( zDbFilename==0 || zDbFilename[0]==0 ){
p->openMode = SHELL_OPEN_NORMAL;
}else{
- p->openMode = (u8)deduceDatabaseType(zDbFilename,
- (openFlags & OPEN_DB_ZIPFILE)!=0);
+ p->openMode = deduceDatabaseType(zDbFilename,
+ (openFlags & OPEN_DB_ZIPFILE)!=0);
}
}
switch( p->openMode ){
char *zNewFilename = 0; /* Name of the database file to open */
int iName = 1; /* Index in azArg[] of the filename */
int newFlag = 0; /* True to delete file before opening */
- int openMode = SHELL_OPEN_UNSPEC;
+ u8 openMode = SHELL_OPEN_UNSPEC;
/* Check for command-line arguments */
for(iName=1; iName<nArg; iName++){
** Returns are: 0 => not open (aka complete), 1 => is open (incomplete)
** The following macros may be applied to the scan state:
*/
-#define DCSS_InDarkArg(dcss) ((dcss)&argPosMask==inDqArg)
+#define DCSS_InDarkArg(dcss) (((dcss)&argPosMask)==inDqArg)
#define DCSS_EndEscaped(dcss) (((dcss)&endEscaped)!=0)
-#define DCSS_IsOpen(dcss) (((dcss) & isOpenMask)!=0)
+#define DCSS_IsOpen(dcss) (((dcss)&isOpenMask)!=0)
typedef enum {
DCSS_Start = 0,
twixtArgs = 0, inSqArg = 1, inDarkArg = 2, inDqArg = 3, /* ordered */
char c = (ss&isOpenMask)? 1 : *zCmd++;
while( c!=0 ){
switch( ss ){
- twixt:
case twixtArgs:
while( IsSpace(c) ){
if( (c=*zCmd++)==0 ) goto atEnd;