summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/sqlite/shell.c
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2016-01-22 10:48:03 +0100
committerMark Brand <mabrand@mabrand.nl>2016-01-29 00:13:12 +0000
commitdae6445e2659c5e8ea797fc48b0fc2dedf70d7c5 (patch)
treeadf642d6941e77888c73c699600c835d6c223a0e /src/3rdparty/sqlite/shell.c
parentd9229d849f44cf94e4ee19fac390811b474127d2 (diff)
update bundled sqlite to 3.10.0.2
Thanks to gunnar.roth@gmx.net for updating the WinCE patch. Change-Id: I131e0ee9141efdbd377e096aae0959311a601830 Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'src/3rdparty/sqlite/shell.c')
-rw-r--r--src/3rdparty/sqlite/shell.c844
1 files changed, 495 insertions, 349 deletions
diff --git a/src/3rdparty/sqlite/shell.c b/src/3rdparty/sqlite/shell.c
index 7db8dbda0a..b7a7abcd33 100644
--- a/src/3rdparty/sqlite/shell.c
+++ b/src/3rdparty/sqlite/shell.c
@@ -101,28 +101,26 @@
#if defined(_WIN32) || defined(WIN32)
# include <io.h>
# include <fcntl.h>
-#define isatty(h) _isatty(h)
-#ifndef access
-# define access(f,m) _access((f),(m))
-#endif
-#undef popen
-#define popen _popen
-#undef pclose
-#define pclose _pclose
-#else
-/* Make sure isatty() has a prototype.
-*/
-extern int isatty(int);
-
-#if !defined(__RTP__) && !defined(_WRS_KERNEL)
- /* popen and pclose are not C89 functions and so are sometimes omitted from
- ** the <stdio.h> header */
- extern FILE *popen(const char*,const char*);
- extern int pclose(FILE*);
+# define isatty(h) _isatty(h)
+# ifndef access
+# define access(f,m) _access((f),(m))
+# endif
+# undef popen
+# define popen _popen
+# undef pclose
+# define pclose _pclose
#else
-# define SQLITE_OMIT_POPEN 1
-#endif
+ /* Make sure isatty() has a prototype. */
+ extern int isatty(int);
+# if !defined(__RTP__) && !defined(_WRS_KERNEL)
+ /* popen and pclose are not C89 functions and so are
+ ** sometimes omitted from the <stdio.h> header */
+ extern FILE *popen(const char*,const char*);
+ extern int pclose(FILE*);
+# else
+# define SQLITE_OMIT_POPEN 1
+# endif
#endif
#if defined(_WIN32_WCE)
@@ -167,7 +165,7 @@ static sqlite3_int64 timeOfDay(void){
static sqlite3_vfs *clockVfs = 0;
sqlite3_int64 t;
if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
- if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){
+ if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
clockVfs->xCurrentTimeInt64(clockVfs, &t);
}else{
double r;
@@ -332,6 +330,13 @@ static int bail_on_error = 0;
static int stdin_is_interactive = 1;
/*
+** On Windows systems we have to know if standard output is a console
+** in order to translate UTF-8 into MBCS. The following variable is
+** true if translation is required.
+*/
+static int stdout_is_console = 1;
+
+/*
** The following is the open SQLite database. We make a pointer
** to this database a static variable so that it can be accessed
** by the SIGINT handler to interrupt database processing.
@@ -433,6 +438,16 @@ static void shellstaticFunc(
/*
+** Compute a string length that is limited to what can be stored in
+** lower 30 bits of a 32-bit signed integer.
+*/
+static int strlen30(const char *z){
+ const char *z2 = z;
+ while( *z2 ){ z2++; }
+ return 0x3fffffff & (int)(z2 - z);
+}
+
+/*
** This routine reads a line of text from FILE in, stores
** the text in memory obtained from malloc() and returns a pointer
** to the text. NULL is returned at end of file, or if malloc()
@@ -467,6 +482,26 @@ static char *local_getline(char *zLine, FILE *in){
break;
}
}
+#if defined(_WIN32) || defined(WIN32)
+ /* For interactive input on Windows systems, translate the
+ ** multi-byte characterset characters into UTF-8. */
+ if( stdin_is_interactive ){
+ extern char *sqlite3_win32_mbcs_to_utf8(const char*);
+ char *zTrans = sqlite3_win32_mbcs_to_utf8(zLine);
+ if( zTrans ){
+ int nTrans = strlen30(zTrans)+1;
+ if( nTrans>nLine ){
+ zLine = realloc(zLine, nTrans);
+ if( zLine==0 ){
+ sqlite3_free(zTrans);
+ return 0;
+ }
+ }
+ memcpy(zLine, zTrans, nTrans);
+ sqlite3_free(zTrans);
+ }
+ }
+#endif /* defined(_WIN32) || defined(WIN32) */
return zLine;
}
@@ -505,6 +540,39 @@ static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
}
/*
+** Render output like fprintf(). Except, if the output is going to the
+** console and if this is running on a Windows machine, translate the
+** output from UTF-8 into MBCS.
+*/
+#if defined(_WIN32) || defined(WIN32)
+void utf8_printf(FILE *out, const char *zFormat, ...){
+ va_list ap;
+ va_start(ap, zFormat);
+ if( stdout_is_console && (out==stdout || out==stderr) ){
+ extern char *sqlite3_win32_utf8_to_mbcs(const char*);
+ char *z1 = sqlite3_vmprintf(zFormat, ap);
+ char *z2 = sqlite3_win32_utf8_to_mbcs(z1);
+ sqlite3_free(z1);
+ fputs(z2, out);
+ sqlite3_free(z2);
+ }else{
+ vfprintf(out, zFormat, ap);
+ }
+ va_end(ap);
+}
+#elif !defined(utf8_printf)
+# define utf8_printf fprintf
+#endif
+
+/*
+** Render output like fprintf(). This should not be used on anything that
+** includes string formatting (e.g. "%s").
+*/
+#if !defined(raw_printf)
+# define raw_printf fprintf
+#endif
+
+/*
** Shell output mode information from before ".explain on",
** saved so that it can be restored by ".explain off"
*/
@@ -527,6 +595,7 @@ struct ShellState {
int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
int statsOn; /* True to display memory stats before each finalize */
int scanstatsOn; /* True to display scan stats before each finalize */
+ int countChanges; /* True to display change counts */
int backslashOn; /* Resolve C-style \x escapes in SQL input text */
int outCount; /* Revert to stdout when reaching zero */
int cnt; /* Number of records displayed so far */
@@ -609,22 +678,12 @@ static const char *modeDescr[] = {
#define ArraySize(X) (int)(sizeof(X)/sizeof(X[0]))
/*
-** Compute a string length that is limited to what can be stored in
-** lower 30 bits of a 32-bit signed integer.
-*/
-static int strlen30(const char *z){
- const char *z2 = z;
- while( *z2 ){ z2++; }
- return 0x3fffffff & (int)(z2 - z);
-}
-
-/*
** A callback for the sqlite3_log() interface.
*/
static void shellLog(void *pArg, int iErrCode, const char *zMsg){
ShellState *p = (ShellState*)pArg;
if( p->pLog==0 ) return;
- fprintf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
+ utf8_printf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
fflush(p->pLog);
}
@@ -634,9 +693,9 @@ static void shellLog(void *pArg, int iErrCode, const char *zMsg){
static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
int i;
char *zBlob = (char *)pBlob;
- fprintf(out,"X'");
- for(i=0; i<nBlob; i++){ fprintf(out,"%02x",zBlob[i]&0xff); }
- fprintf(out,"'");
+ raw_printf(out,"X'");
+ for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
+ raw_printf(out,"'");
}
/*
@@ -650,23 +709,23 @@ static void output_quoted_string(FILE *out, const char *z){
if( z[i]=='\'' ) nSingle++;
}
if( nSingle==0 ){
- fprintf(out,"'%s'",z);
+ utf8_printf(out,"'%s'",z);
}else{
- fprintf(out,"'");
+ raw_printf(out,"'");
while( *z ){
for(i=0; z[i] && z[i]!='\''; i++){}
if( i==0 ){
- fprintf(out,"''");
+ raw_printf(out,"''");
z++;
}else if( z[i]=='\'' ){
- fprintf(out,"%.*s''",i,z);
+ utf8_printf(out,"%.*s''",i,z);
z += i+1;
}else{
- fprintf(out,"%s",z);
+ utf8_printf(out,"%s",z);
break;
}
}
- fprintf(out,"'");
+ raw_printf(out,"'");
}
setTextMode(out);
}
@@ -694,7 +753,7 @@ static void output_c_string(FILE *out, const char *z){
fputc('\\', out);
fputc('r', out);
}else if( !isprint(c&0xff) ){
- fprintf(out, "\\%03o", c&0xff);
+ raw_printf(out, "\\%03o", c&0xff);
}else{
fputc(c, out);
}
@@ -718,18 +777,18 @@ static void output_html_string(FILE *out, const char *z){
&& z[i]!='\'';
i++){}
if( i>0 ){
- fprintf(out,"%.*s",i,z);
+ utf8_printf(out,"%.*s",i,z);
}
if( z[i]=='<' ){
- fprintf(out,"&lt;");
+ raw_printf(out,"&lt;");
}else if( z[i]=='&' ){
- fprintf(out,"&amp;");
+ raw_printf(out,"&amp;");
}else if( z[i]=='>' ){
- fprintf(out,"&gt;");
+ raw_printf(out,"&gt;");
}else if( z[i]=='\"' ){
- fprintf(out,"&quot;");
+ raw_printf(out,"&quot;");
}else if( z[i]=='\'' ){
- fprintf(out,"&#39;");
+ raw_printf(out,"&#39;");
}else{
break;
}
@@ -769,7 +828,7 @@ static const char needCsvQuote[] = {
static void output_csv(ShellState *p, const char *z, int bSep){
FILE *out = p->out;
if( z==0 ){
- fprintf(out,"%s",p->nullValue);
+ utf8_printf(out,"%s",p->nullValue);
}else{
int i;
int nSep = strlen30(p->colSeparator);
@@ -789,11 +848,11 @@ static void output_csv(ShellState *p, const char *z, int bSep){
}
putc('"', out);
}else{
- fprintf(out, "%s", z);
+ utf8_printf(out, "%s", z);
}
}
if( bSep ){
- fprintf(p->out, "%s", p->colSeparator);
+ utf8_printf(p->out, "%s", p->colSeparator);
}
}
@@ -831,9 +890,9 @@ static int shell_callback(
int len = strlen30(azCol[i] ? azCol[i] : "");
if( len>w ) w = len;
}
- if( p->cnt++>0 ) fprintf(p->out, "%s", p->rowSeparator);
+ if( p->cnt++>0 ) utf8_printf(p->out, "%s", p->rowSeparator);
for(i=0; i<nArg; i++){
- fprintf(p->out,"%*s = %s%s", w, azCol[i],
+ utf8_printf(p->out,"%*s = %s%s", w, azCol[i],
azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator);
}
break;
@@ -859,10 +918,10 @@ static int shell_callback(
}
if( p->showHeader ){
if( w<0 ){
- fprintf(p->out,"%*.*s%s",-w,-w,azCol[i],
+ utf8_printf(p->out,"%*.*s%s",-w,-w,azCol[i],
i==nArg-1 ? p->rowSeparator : " ");
}else{
- fprintf(p->out,"%-*.*s%s",w,w,azCol[i],
+ utf8_printf(p->out,"%-*.*s%s",w,w,azCol[i],
i==nArg-1 ? p->rowSeparator : " ");
}
}
@@ -876,7 +935,8 @@ static int shell_callback(
}else{
w = 10;
}
- fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
+ utf8_printf(p->out,"%-*.*s%s",w,w,
+ "----------------------------------------------------------"
"----------------------------------------------------------",
i==nArg-1 ? p->rowSeparator : " ");
}
@@ -895,16 +955,16 @@ static int shell_callback(
}
if( i==1 && p->aiIndent && p->pStmt ){
if( p->iIndent<p->nIndent ){
- fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
+ utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
}
p->iIndent++;
}
if( w<0 ){
- fprintf(p->out,"%*.*s%s",-w,-w,
+ utf8_printf(p->out,"%*.*s%s",-w,-w,
azArg[i] ? azArg[i] : p->nullValue,
i==nArg-1 ? p->rowSeparator : " ");
}else{
- fprintf(p->out,"%-*.*s%s",w,w,
+ utf8_printf(p->out,"%-*.*s%s",w,w,
azArg[i] ? azArg[i] : p->nullValue,
i==nArg-1 ? p->rowSeparator : " ");
}
@@ -915,7 +975,7 @@ static int shell_callback(
case MODE_List: {
if( p->cnt++==0 && p->showHeader ){
for(i=0; i<nArg; i++){
- fprintf(p->out,"%s%s",azCol[i],
+ utf8_printf(p->out,"%s%s",azCol[i],
i==nArg-1 ? p->rowSeparator : p->colSeparator);
}
}
@@ -923,51 +983,51 @@ static int shell_callback(
for(i=0; i<nArg; i++){
char *z = azArg[i];
if( z==0 ) z = p->nullValue;
- fprintf(p->out, "%s", z);
+ utf8_printf(p->out, "%s", z);
if( i<nArg-1 ){
- fprintf(p->out, "%s", p->colSeparator);
+ utf8_printf(p->out, "%s", p->colSeparator);
}else if( p->mode==MODE_Semi ){
- fprintf(p->out, ";%s", p->rowSeparator);
+ utf8_printf(p->out, ";%s", p->rowSeparator);
}else{
- fprintf(p->out, "%s", p->rowSeparator);
+ utf8_printf(p->out, "%s", p->rowSeparator);
}
}
break;
}
case MODE_Html: {
if( p->cnt++==0 && p->showHeader ){
- fprintf(p->out,"<TR>");
+ raw_printf(p->out,"<TR>");
for(i=0; i<nArg; i++){
- fprintf(p->out,"<TH>");
+ raw_printf(p->out,"<TH>");
output_html_string(p->out, azCol[i]);
- fprintf(p->out,"</TH>\n");
+ raw_printf(p->out,"</TH>\n");
}
- fprintf(p->out,"</TR>\n");
+ raw_printf(p->out,"</TR>\n");
}
if( azArg==0 ) break;
- fprintf(p->out,"<TR>");
+ raw_printf(p->out,"<TR>");
for(i=0; i<nArg; i++){
- fprintf(p->out,"<TD>");
+ raw_printf(p->out,"<TD>");
output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
- fprintf(p->out,"</TD>\n");
+ raw_printf(p->out,"</TD>\n");
}
- fprintf(p->out,"</TR>\n");
+ raw_printf(p->out,"</TR>\n");
break;
}
case MODE_Tcl: {
if( p->cnt++==0 && p->showHeader ){
for(i=0; i<nArg; i++){
output_c_string(p->out,azCol[i] ? azCol[i] : "");
- if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
+ if(i<nArg-1) utf8_printf(p->out, "%s", p->colSeparator);
}
- fprintf(p->out, "%s", p->rowSeparator);
+ utf8_printf(p->out, "%s", p->rowSeparator);
}
if( azArg==0 ) break;
for(i=0; i<nArg; i++){
output_c_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
- if(i<nArg-1) fprintf(p->out, "%s", p->colSeparator);
+ if(i<nArg-1) utf8_printf(p->out, "%s", p->colSeparator);
}
- fprintf(p->out, "%s", p->rowSeparator);
+ utf8_printf(p->out, "%s", p->rowSeparator);
break;
}
case MODE_Csv: {
@@ -976,13 +1036,13 @@ static int shell_callback(
for(i=0; i<nArg; i++){
output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
}
- fprintf(p->out, "%s", p->rowSeparator);
+ utf8_printf(p->out, "%s", p->rowSeparator);
}
if( nArg>0 ){
for(i=0; i<nArg; i++){
output_csv(p, azArg[i], i<nArg-1);
}
- fprintf(p->out, "%s", p->rowSeparator);
+ utf8_printf(p->out, "%s", p->rowSeparator);
}
setTextMode(p->out);
break;
@@ -990,55 +1050,55 @@ static int shell_callback(
case MODE_Insert: {
p->cnt++;
if( azArg==0 ) break;
- fprintf(p->out,"INSERT INTO %s",p->zDestTable);
+ utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
if( p->showHeader ){
- fprintf(p->out,"(");
+ raw_printf(p->out,"(");
for(i=0; i<nArg; i++){
char *zSep = i>0 ? ",": "";
- fprintf(p->out, "%s%s", zSep, azCol[i]);
+ utf8_printf(p->out, "%s%s", zSep, azCol[i]);
}
- fprintf(p->out,")");
+ raw_printf(p->out,")");
}
- fprintf(p->out," VALUES(");
+ raw_printf(p->out," VALUES(");
for(i=0; i<nArg; i++){
char *zSep = i>0 ? ",": "";
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
- fprintf(p->out,"%sNULL",zSep);
+ utf8_printf(p->out,"%sNULL",zSep);
}else if( aiType && aiType[i]==SQLITE_TEXT ){
- if( zSep[0] ) fprintf(p->out,"%s",zSep);
+ if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
output_quoted_string(p->out, azArg[i]);
}else if( aiType && (aiType[i]==SQLITE_INTEGER
|| aiType[i]==SQLITE_FLOAT) ){
- fprintf(p->out,"%s%s",zSep, azArg[i]);
+ utf8_printf(p->out,"%s%s",zSep, azArg[i]);
}else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
const void *pBlob = sqlite3_column_blob(p->pStmt, i);
int nBlob = sqlite3_column_bytes(p->pStmt, i);
- if( zSep[0] ) fprintf(p->out,"%s",zSep);
+ if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
output_hex_blob(p->out, pBlob, nBlob);
}else if( isNumber(azArg[i], 0) ){
- fprintf(p->out,"%s%s",zSep, azArg[i]);
+ utf8_printf(p->out,"%s%s",zSep, azArg[i]);
}else{
- if( zSep[0] ) fprintf(p->out,"%s",zSep);
+ if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
output_quoted_string(p->out, azArg[i]);
}
}
- fprintf(p->out,");\n");
+ raw_printf(p->out,");\n");
break;
}
case MODE_Ascii: {
if( p->cnt++==0 && p->showHeader ){
for(i=0; i<nArg; i++){
- if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
- fprintf(p->out,"%s",azCol[i] ? azCol[i] : "");
+ if( i>0 ) utf8_printf(p->out, "%s", p->colSeparator);
+ utf8_printf(p->out,"%s",azCol[i] ? azCol[i] : "");
}
- fprintf(p->out, "%s", p->rowSeparator);
+ utf8_printf(p->out, "%s", p->rowSeparator);
}
if( azArg==0 ) break;
for(i=0; i<nArg; i++){
- if( i>0 ) fprintf(p->out, "%s", p->colSeparator);
- fprintf(p->out,"%s",azArg[i] ? azArg[i] : p->nullValue);
+ if( i>0 ) utf8_printf(p->out, "%s", p->colSeparator);
+ utf8_printf(p->out,"%s",azArg[i] ? azArg[i] : p->nullValue);
}
- fprintf(p->out, "%s", p->rowSeparator);
+ utf8_printf(p->out, "%s", p->rowSeparator);
break;
}
}
@@ -1079,7 +1139,7 @@ static void set_table_name(ShellState *p, const char *zName){
if( needQuote ) n += 2;
z = p->zDestTable = malloc( n+1 );
if( z==0 ){
- fprintf(stderr,"Error: out of memory\n");
+ raw_printf(stderr,"Error: out of memory\n");
exit(1);
}
n = 0;
@@ -1160,7 +1220,8 @@ static int run_table_dump_query(
const char *z;
rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
if( rc!=SQLITE_OK || !pSelect ){
- fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
+ utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc,
+ sqlite3_errmsg(p->db));
if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
return rc;
}
@@ -1168,26 +1229,27 @@ static int run_table_dump_query(
nResult = sqlite3_column_count(pSelect);
while( rc==SQLITE_ROW ){
if( zFirstRow ){
- fprintf(p->out, "%s", zFirstRow);
+ utf8_printf(p->out, "%s", zFirstRow);
zFirstRow = 0;
}
z = (const char*)sqlite3_column_text(pSelect, 0);
- fprintf(p->out, "%s", z);
+ utf8_printf(p->out, "%s", z);
for(i=1; i<nResult; i++){
- fprintf(p->out, ",%s", sqlite3_column_text(pSelect, i));
+ utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
}
if( z==0 ) z = "";
while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
if( z[0] ){
- fprintf(p->out, "\n;\n");
+ raw_printf(p->out, "\n;\n");
}else{
- fprintf(p->out, ";\n");
+ raw_printf(p->out, ";\n");
}
rc = sqlite3_step(pSelect);
}
rc = sqlite3_finalize(pSelect);
if( rc!=SQLITE_OK ){
- fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
+ utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc,
+ sqlite3_errmsg(p->db));
if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
}
return rc;
@@ -1222,52 +1284,53 @@ static int display_stats(
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out,
+ raw_printf(pArg->out,
"Memory Used: %d (max %d) bytes\n",
iCur, iHiwtr);
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
+ raw_printf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
iCur, iHiwtr);
if( pArg->shellFlgs & SHFLG_Pagecache ){
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out,
+ raw_printf(pArg->out,
"Number of Pcache Pages Used: %d (max %d) pages\n",
iCur, iHiwtr);
}
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out,
+ raw_printf(pArg->out,
"Number of Pcache Overflow Bytes: %d (max %d) bytes\n",
iCur, iHiwtr);
if( pArg->shellFlgs & SHFLG_Scratch ){
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n",
+ raw_printf(pArg->out,
+ "Number of Scratch Allocations Used: %d (max %d)\n",
iCur, iHiwtr);
}
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out,
+ raw_printf(pArg->out,
"Number of Scratch Overflow Bytes: %d (max %d) bytes\n",
iCur, iHiwtr);
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Largest Allocation: %d bytes\n",
+ raw_printf(pArg->out, "Largest Allocation: %d bytes\n",
iHiwtr);
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
+ raw_printf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
iHiwtr);
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
+ raw_printf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
iHiwtr);
#ifdef YYTRACKMAXSTACKDEPTH
iHiwtr = iCur = -1;
sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
+ raw_printf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
iCur, iHiwtr);
#endif
}
@@ -1277,50 +1340,59 @@ static int display_stats(
iHiwtr = iCur = -1;
sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED,
&iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n",
+ raw_printf(pArg->out,
+ "Lookaside Slots Used: %d (max %d)\n",
iCur, iHiwtr);
sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT,
&iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr);
+ raw_printf(pArg->out, "Successful lookaside attempts: %d\n",
+ iHiwtr);
sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE,
&iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr);
+ raw_printf(pArg->out, "Lookaside failures due to size: %d\n",
+ iHiwtr);
sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL,
&iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr);
+ raw_printf(pArg->out, "Lookaside failures due to OOM: %d\n",
+ iHiwtr);
}
iHiwtr = iCur = -1;
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Pager Heap Usage: %d bytes\n",iCur);
+ raw_printf(pArg->out, "Pager Heap Usage: %d bytes\n",
+ iCur);
iHiwtr = iCur = -1;
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
- fprintf(pArg->out, "Page cache hits: %d\n", iCur);
+ raw_printf(pArg->out, "Page cache hits: %d\n", iCur);
iHiwtr = iCur = -1;
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
- fprintf(pArg->out, "Page cache misses: %d\n", iCur);
+ raw_printf(pArg->out, "Page cache misses: %d\n", iCur);
iHiwtr = iCur = -1;
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
- fprintf(pArg->out, "Page cache writes: %d\n", iCur);
+ raw_printf(pArg->out, "Page cache writes: %d\n", iCur);
iHiwtr = iCur = -1;
sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Schema Heap Usage: %d bytes\n",iCur);
+ raw_printf(pArg->out, "Schema Heap Usage: %d bytes\n",
+ iCur);
iHiwtr = iCur = -1;
sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
- fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",iCur);
+ raw_printf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",
+ iCur);
}
if( pArg && pArg->out && db && pArg->pStmt ){
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP,
bReset);
- fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
+ raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur);
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
- fprintf(pArg->out, "Sort Operations: %d\n", iCur);
+ raw_printf(pArg->out, "Sort Operations: %d\n", iCur);
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
- fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
+ raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur);
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
- fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
+ raw_printf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
}
+ /* Do not remove this machine readable comment: extra-stats-output-here */
+
return 0;
}
@@ -1331,9 +1403,12 @@ static void display_scanstats(
sqlite3 *db, /* Database to query */
ShellState *pArg /* Pointer to ShellState */
){
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
+#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
+ UNUSED_PARAMETER(db);
+ UNUSED_PARAMETER(pArg);
+#else
int i, k, n, mx;
- fprintf(pArg->out, "-------- scanstats --------\n");
+ raw_printf(pArg->out, "-------- scanstats --------\n");
mx = 0;
for(k=0; k<=mx; k++){
double rEstLoop = 1.0;
@@ -1351,21 +1426,21 @@ static void display_scanstats(
if( iSid!=k ) continue;
if( n==0 ){
rEstLoop = (double)nLoop;
- if( k>0 ) fprintf(pArg->out, "-------- subquery %d -------\n", k);
+ if( k>0 ) raw_printf(pArg->out, "-------- subquery %d -------\n", k);
}
n++;
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
- fprintf(pArg->out, "Loop %2d: %s\n", n, zExplain);
+ utf8_printf(pArg->out, "Loop %2d: %s\n", n, zExplain);
rEstLoop *= rEst;
- fprintf(pArg->out,
+ raw_printf(pArg->out,
" nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
);
}
}
- fprintf(pArg->out, "---------------------------\n");
+ raw_printf(pArg->out, "---------------------------\n");
#endif
}
@@ -1518,7 +1593,7 @@ static int shell_exec(
/* echo the sql statement if echo on */
if( pArg && pArg->echoOn ){
const char *zStmtSql = sqlite3_sql(pStmt);
- fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
+ utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
}
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
@@ -1529,10 +1604,10 @@ static int shell_exec(
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
if( rc==SQLITE_OK ){
while( sqlite3_step(pExplain)==SQLITE_ROW ){
- fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
- fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
- fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
- fprintf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
+ raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
+ raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
+ raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
+ utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
}
}
sqlite3_finalize(pExplain);
@@ -1660,24 +1735,24 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
if( strcmp(zTable, "sqlite_sequence")==0 ){
zPrepStmt = "DELETE FROM sqlite_sequence;\n";
}else if( sqlite3_strglob("sqlite_stat?", zTable)==0 ){
- fprintf(p->out, "ANALYZE sqlite_master;\n");
+ raw_printf(p->out, "ANALYZE sqlite_master;\n");
}else if( strncmp(zTable, "sqlite_", 7)==0 ){
return 0;
}else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
char *zIns;
if( !p->writableSchema ){
- fprintf(p->out, "PRAGMA writable_schema=ON;\n");
+ raw_printf(p->out, "PRAGMA writable_schema=ON;\n");
p->writableSchema = 1;
}
zIns = sqlite3_mprintf(
"INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
"VALUES('table','%q','%q',0,'%q');",
zTable, zTable, zSql);
- fprintf(p->out, "%s\n", zIns);
+ utf8_printf(p->out, "%s\n", zIns);
sqlite3_free(zIns);
return 0;
}else{
- fprintf(p->out, "%s;\n", zSql);
+ utf8_printf(p->out, "%s;\n", zSql);
}
if( strcmp(zType, "table")==0 ){
@@ -1754,9 +1829,9 @@ static int run_schema_dump_query(
if( rc==SQLITE_CORRUPT ){
char *zQ2;
int len = strlen30(zQuery);
- fprintf(p->out, "/****** CORRUPTION ERROR *******/\n");
+ raw_printf(p->out, "/****** CORRUPTION ERROR *******/\n");
if( zErr ){
- fprintf(p->out, "/****** %s ******/\n", zErr);
+ utf8_printf(p->out, "/****** %s ******/\n", zErr);
sqlite3_free(zErr);
zErr = 0;
}
@@ -1765,7 +1840,7 @@ static int run_schema_dump_query(
sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery);
rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr);
if( rc ){
- fprintf(p->out, "/****** ERROR: %s ******/\n", zErr);
+ utf8_printf(p->out, "/****** ERROR: %s ******/\n", zErr);
}else{
rc = SQLITE_CORRUPT;
}
@@ -1782,6 +1857,7 @@ static char zHelp[] =
".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
".bail on|off Stop after hitting an error. Default OFF\n"
".binary on|off Turn binary output on or off. Default OFF\n"
+ ".changes on|off Show number of rows changed by SQL\n"
".clone NEWDB Clone data into NEWDB from the existing database\n"
".databases List names and files of attached databases\n"
".dbinfo ?DB? Show status information about the database\n"
@@ -1844,6 +1920,7 @@ static char zHelp[] =
".timeout MS Try opening locked tables for MS milliseconds\n"
".timer on|off Turn SQL timer on or off\n"
".trace FILE|off Output each SQL statement as it is run\n"
+ ".vfsinfo ?AUX? Information about the top-level VFS\n"
".vfsname ?AUX? Print the name of the VFS stack\n"
".width NUM1 NUM2 ... Set column widths for \"column\" mode\n"
" Negative values right-justify\n"
@@ -1866,6 +1943,7 @@ static void readfileFunc(
long nIn;
void *pBuf;
+ UNUSED_PARAMETER(argc);
zName = (const char*)sqlite3_value_text(argv[0]);
if( zName==0 ) return;
in = fopen(zName, "rb");
@@ -1898,6 +1976,7 @@ static void writefileFunc(
sqlite3_int64 rc;
const char *zFile;
+ UNUSED_PARAMETER(argc);
zFile = (const char*)sqlite3_value_text(argv[0]);
if( zFile==0 ) return;
out = fopen(zFile, "wb");
@@ -1926,7 +2005,7 @@ static void open_db(ShellState *p, int keepAlive){
shellstaticFunc, 0, 0);
}
if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
- fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
+ utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
p->zDbFilename, sqlite3_errmsg(p->db));
if( keepAlive ) return;
exit(1);
@@ -2076,7 +2155,7 @@ static int booleanValue(char *zArg){
if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){
return 0;
}
- fprintf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
+ utf8_printf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
zArg);
return 0;
}
@@ -2104,7 +2183,7 @@ static FILE *output_file_open(const char *zFile){
}else{
f = fopen(zFile, "wb");
if( f==0 ){
- fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
}
}
return f;
@@ -2118,7 +2197,7 @@ static void sql_trace_callback(void *pArg, const char *z){
if( f ){
int i = (int)strlen(z);
while( i>0 && z[i-1]==';' ){ i--; }
- fprintf(f, "%.*s;\n", i, z);
+ utf8_printf(f, "%.*s;\n", i, z);
}
}
@@ -2153,7 +2232,7 @@ static void import_append_char(ImportCtx *p, int c){
p->nAlloc += p->nAlloc + 100;
p->z = sqlite3_realloc64(p->z, p->nAlloc);
if( p->z==0 ){
- fprintf(stderr, "out of memory\n");
+ raw_printf(stderr, "out of memory\n");
exit(1);
}
}
@@ -2207,11 +2286,11 @@ static char *SQLITE_CDECL csv_read_one_field(ImportCtx *p){
break;
}
if( pc==cQuote && c!='\r' ){
- fprintf(stderr, "%s:%d: unescaped %c character\n",
+ utf8_printf(stderr, "%s:%d: unescaped %c character\n",
p->zFile, p->nLine, cQuote);
}
if( c==EOF ){
- fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
+ utf8_printf(stderr, "%s:%d: unterminated %c-quoted field\n",
p->zFile, startLine, cQuote);
p->cTerm = c;
break;
@@ -2293,7 +2372,7 @@ static void tryToCloneData(
zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
if( rc ){
- fprintf(stderr, "Error %d: %s on [%s]\n",
+ utf8_printf(stderr, "Error %d: %s on [%s]\n",
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
zQuery);
goto end_data_xfer;
@@ -2301,7 +2380,7 @@ static void tryToCloneData(
n = sqlite3_column_count(pQuery);
zInsert = sqlite3_malloc64(200 + nTable + n*3);
if( zInsert==0 ){
- fprintf(stderr, "out of memory\n");
+ raw_printf(stderr, "out of memory\n");
goto end_data_xfer;
}
sqlite3_snprintf(200+nTable,zInsert,
@@ -2314,7 +2393,7 @@ static void tryToCloneData(
memcpy(zInsert+i, ");", 3);
rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0);
if( rc ){
- fprintf(stderr, "Error %d: %s on [%s]\n",
+ utf8_printf(stderr, "Error %d: %s on [%s]\n",
sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb),
zQuery);
goto end_data_xfer;
@@ -2351,7 +2430,7 @@ static void tryToCloneData(
} /* End for */
rc = sqlite3_step(pInsert);
if( rc!=SQLITE_OK && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
- fprintf(stderr, "Error %d: %s\n", sqlite3_extended_errcode(newDb),
+ utf8_printf(stderr, "Error %d: %s\n", sqlite3_extended_errcode(newDb),
sqlite3_errmsg(newDb));
}
sqlite3_reset(pInsert);
@@ -2368,7 +2447,7 @@ static void tryToCloneData(
zTable);
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
if( rc ){
- fprintf(stderr, "Warning: cannot step \"%s\" backwards", zTable);
+ utf8_printf(stderr, "Warning: cannot step \"%s\" backwards", zTable);
break;
}
} /* End for(k=0...) */
@@ -2404,7 +2483,7 @@ static void tryToCloneSchema(
" WHERE %s", zWhere);
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
if( rc ){
- fprintf(stderr, "Error: (%d) %s on [%s]\n",
+ utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
zQuery);
goto end_schema_xfer;
@@ -2415,7 +2494,7 @@ static void tryToCloneSchema(
printf("%s... ", zName); fflush(stdout);
sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
if( zErrMsg ){
- fprintf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
+ utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
sqlite3_free(zErrMsg);
zErrMsg = 0;
}
@@ -2431,7 +2510,7 @@ static void tryToCloneSchema(
" WHERE %s ORDER BY rowid DESC", zWhere);
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
if( rc ){
- fprintf(stderr, "Error: (%d) %s on [%s]\n",
+ utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
zQuery);
goto end_schema_xfer;
@@ -2442,7 +2521,7 @@ static void tryToCloneSchema(
printf("%s... ", zName); fflush(stdout);
sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
if( zErrMsg ){
- fprintf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
+ utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
sqlite3_free(zErrMsg);
zErrMsg = 0;
}
@@ -2466,12 +2545,12 @@ static void tryToClone(ShellState *p, const char *zNewDb){
int rc;
sqlite3 *newDb = 0;
if( access(zNewDb,0)==0 ){
- fprintf(stderr, "File \"%s\" already exists.\n", zNewDb);
+ utf8_printf(stderr, "File \"%s\" already exists.\n", zNewDb);
return;
}
rc = sqlite3_open(zNewDb, &newDb);
if( rc ){
- fprintf(stderr, "Cannot create output database: %s\n",
+ utf8_printf(stderr, "Cannot create output database: %s\n",
sqlite3_errmsg(newDb));
}else{
sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0);
@@ -2555,7 +2634,7 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
{ "schema size:",
"SELECT total(length(sql)) FROM %s" },
};
- sqlite3_file *pFile;
+ sqlite3_file *pFile = 0;
int i;
char *zSchemaTab;
char *zDb = nArg>=2 ? azArg[1] : "main";
@@ -2568,27 +2647,27 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
}
i = pFile->pMethods->xRead(pFile, aHdr, 100, 0);
if( i!=SQLITE_OK ){
- fprintf(stderr, "unable to read database header\n");
+ raw_printf(stderr, "unable to read database header\n");
return 1;
}
i = get2byteInt(aHdr+16);
if( i==1 ) i = 65536;
- fprintf(p->out, "%-20s %d\n", "database page size:", i);
- fprintf(p->out, "%-20s %d\n", "write format:", aHdr[18]);
- fprintf(p->out, "%-20s %d\n", "read format:", aHdr[19]);
- fprintf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]);
- for(i=0; i<sizeof(aField)/sizeof(aField[0]); i++){
+ utf8_printf(p->out, "%-20s %d\n", "database page size:", i);
+ utf8_printf(p->out, "%-20s %d\n", "write format:", aHdr[18]);
+ utf8_printf(p->out, "%-20s %d\n", "read format:", aHdr[19]);
+ utf8_printf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]);
+ for(i=0; i<ArraySize(aField); i++){
int ofst = aField[i].ofst;
unsigned int val = get4byteInt(aHdr + ofst);
- fprintf(p->out, "%-20s %u", aField[i].zName, val);
+ utf8_printf(p->out, "%-20s %u", aField[i].zName, val);
switch( ofst ){
case 56: {
- if( val==1 ) fprintf(p->out, " (utf8)");
- if( val==2 ) fprintf(p->out, " (utf16le)");
- if( val==3 ) fprintf(p->out, " (utf16be)");
+ if( val==1 ) raw_printf(p->out, " (utf8)");
+ if( val==2 ) raw_printf(p->out, " (utf16le)");
+ if( val==3 ) raw_printf(p->out, " (utf16be)");
}
}
- fprintf(p->out, "\n");
+ raw_printf(p->out, "\n");
}
if( zDb==0 ){
zSchemaTab = sqlite3_mprintf("main.sqlite_master");
@@ -2597,16 +2676,32 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
}else{
zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_master", zDb);
}
- for(i=0; i<sizeof(aQuery)/sizeof(aQuery[0]); i++){
+ for(i=0; i<ArraySize(aQuery); i++){
char *zSql = sqlite3_mprintf(aQuery[i].zSql, zSchemaTab);
int val = db_int(p, zSql);
sqlite3_free(zSql);
- fprintf(p->out, "%-20s %d\n", aQuery[i].zName, val);
+ utf8_printf(p->out, "%-20s %d\n", aQuery[i].zName, val);
}
sqlite3_free(zSchemaTab);
return 0;
}
+/*
+** Print the current sqlite3_errmsg() value to stderr and return 1.
+*/
+static int shellDatabaseError(sqlite3 *db){
+ const char *zErr = sqlite3_errmsg(db);
+ utf8_printf(stderr, "Error: %s\n", zErr);
+ return 1;
+}
+
+/*
+** Print an out-of-memory message to stderr and return 1.
+*/
+static int shellNomemError(void){
+ raw_printf(stderr, "Error: out of memory\n");
+ return 1;
+}
/*
** If an input line begins with "." then invoke this routine to
@@ -2664,7 +2759,7 @@ static int do_meta_command(char *zLine, ShellState *p){
while( z[0]=='-' ) z++;
/* No options to process at this time */
{
- fprintf(stderr, "unknown option: %s\n", azArg[j]);
+ utf8_printf(stderr, "unknown option: %s\n", azArg[j]);
return 1;
}
}else if( zDestFile==0 ){
@@ -2673,25 +2768,25 @@ static int do_meta_command(char *zLine, ShellState *p){
zDb = zDestFile;
zDestFile = azArg[j];
}else{
- fprintf(stderr, "too many arguments to .backup\n");
+ raw_printf(stderr, "too many arguments to .backup\n");
return 1;
}
}
if( zDestFile==0 ){
- fprintf(stderr, "missing FILENAME argument on .backup\n");
+ raw_printf(stderr, "missing FILENAME argument on .backup\n");
return 1;
}
if( zDb==0 ) zDb = "main";
rc = sqlite3_open(zDestFile, &pDest);
if( rc!=SQLITE_OK ){
- fprintf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
sqlite3_close(pDest);
return 1;
}
open_db(p, 0);
pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
if( pBackup==0 ){
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
sqlite3_close(pDest);
return 1;
}
@@ -2700,7 +2795,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( rc==SQLITE_DONE ){
rc = 0;
}else{
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
rc = 1;
}
sqlite3_close(pDest);
@@ -2710,7 +2805,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nArg==2 ){
bail_on_error = booleanValue(azArg[1]);
}else{
- fprintf(stderr, "Usage: .bail on|off\n");
+ raw_printf(stderr, "Usage: .bail on|off\n");
rc = 1;
}
}else
@@ -2723,7 +2818,7 @@ static int do_meta_command(char *zLine, ShellState *p){
setTextMode(p->out);
}
}else{
- fprintf(stderr, "Usage: .binary on|off\n");
+ raw_printf(stderr, "Usage: .binary on|off\n");
rc = 1;
}
}else
@@ -2735,11 +2830,20 @@ static int do_meta_command(char *zLine, ShellState *p){
test_breakpoint();
}else
+ if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
+ if( nArg==2 ){
+ p->countChanges = booleanValue(azArg[1]);
+ }else{
+ raw_printf(stderr, "Usage: .changes on|off\n");
+ rc = 1;
+ }
+ }else
+
if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
if( nArg==2 ){
tryToClone(p, azArg[1]);
}else{
- fprintf(stderr, "Usage: .clone FILENAME\n");
+ raw_printf(stderr, "Usage: .clone FILENAME\n");
rc = 1;
}
}else
@@ -2757,7 +2861,7 @@ static int do_meta_command(char *zLine, ShellState *p){
data.cnt = 0;
sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
if( zErrMsg ){
- fprintf(stderr,"Error: %s\n", zErrMsg);
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
rc = 1;
}
@@ -2773,12 +2877,12 @@ static int do_meta_command(char *zLine, ShellState *p){
** which causes immediate foreign key constraints to be violated.
** So disable foreign-key constraint enforcement to prevent problems. */
if( nArg!=1 && nArg!=2 ){
- fprintf(stderr, "Usage: .dump ?LIKE-PATTERN?\n");
+ raw_printf(stderr, "Usage: .dump ?LIKE-PATTERN?\n");
rc = 1;
goto meta_command_exit;
}
- fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
- fprintf(p->out, "BEGIN TRANSACTION;\n");
+ raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
+ raw_printf(p->out, "BEGIN TRANSACTION;\n");
p->writableSchema = 0;
sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
p->nErr = 0;
@@ -2813,19 +2917,19 @@ static int do_meta_command(char *zLine, ShellState *p){
}
}
if( p->writableSchema ){
- fprintf(p->out, "PRAGMA writable_schema=OFF;\n");
+ raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
p->writableSchema = 0;
}
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
- fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
+ raw_printf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
}else
if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
if( nArg==2 ){
p->echoOn = booleanValue(azArg[1]);
}else{
- fprintf(stderr, "Usage: .echo on|off\n");
+ raw_printf(stderr, "Usage: .echo on|off\n");
rc = 1;
}
}else
@@ -2834,7 +2938,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nArg==2 ){
p->autoEQP = booleanValue(azArg[1]);
}else{
- fprintf(stderr, "Usage: .eqp on|off\n");
+ raw_printf(stderr, "Usage: .eqp on|off\n");
rc = 1;
}
}else
@@ -2884,7 +2988,7 @@ static int do_meta_command(char *zLine, ShellState *p){
char *zErrMsg = 0;
int doStats = 0;
if( nArg!=1 ){
- fprintf(stderr, "Usage: .fullschema\n");
+ raw_printf(stderr, "Usage: .fullschema\n");
rc = 1;
goto meta_command_exit;
}
@@ -2911,9 +3015,9 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_finalize(pStmt);
}
if( doStats==0 ){
- fprintf(p->out, "/* No STAT tables available */\n");
+ raw_printf(p->out, "/* No STAT tables available */\n");
}else{
- fprintf(p->out, "ANALYZE sqlite_master;\n");
+ raw_printf(p->out, "ANALYZE sqlite_master;\n");
sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
callback, &data, &zErrMsg);
data.mode = MODE_Insert;
@@ -2926,7 +3030,7 @@ static int do_meta_command(char *zLine, ShellState *p){
data.zDestTable = "sqlite_stat4";
shell_exec(p->db, "SELECT * FROM sqlite_stat4",
shell_callback, &data, &zErrMsg);
- fprintf(p->out, "ANALYZE sqlite_master;\n");
+ raw_printf(p->out, "ANALYZE sqlite_master;\n");
}
}else
@@ -2934,13 +3038,13 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nArg==2 ){
p->showHeader = booleanValue(azArg[1]);
}else{
- fprintf(stderr, "Usage: .headers on|off\n");
+ raw_printf(stderr, "Usage: .headers on|off\n");
rc = 1;
}
}else
if( c=='h' && strncmp(azArg[0], "help", n)==0 ){
- fprintf(p->out, "%s", zHelp);
+ utf8_printf(p->out, "%s", zHelp);
}else
if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
@@ -2958,7 +3062,7 @@ static int do_meta_command(char *zLine, ShellState *p){
int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close file */
if( nArg!=3 ){
- fprintf(stderr, "Usage: .import FILE TABLE\n");
+ raw_printf(stderr, "Usage: .import FILE TABLE\n");
goto meta_command_exit;
}
zFile = azArg[1];
@@ -2968,17 +3072,18 @@ static int do_meta_command(char *zLine, ShellState *p){
open_db(p, 0);
nSep = strlen30(p->colSeparator);
if( nSep==0 ){
- fprintf(stderr, "Error: non-null column separator required for import\n");
+ raw_printf(stderr,
+ "Error: non-null column separator required for import\n");
return 1;
}
if( nSep>1 ){
- fprintf(stderr, "Error: multi-character column separators not allowed"
+ raw_printf(stderr, "Error: multi-character column separators not allowed"
" for import\n");
return 1;
}
nSep = strlen30(p->rowSeparator);
if( nSep==0 ){
- fprintf(stderr, "Error: non-null row separator required for import\n");
+ raw_printf(stderr, "Error: non-null row separator required for import\n");
return 1;
}
if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
@@ -2990,7 +3095,7 @@ static int do_meta_command(char *zLine, ShellState *p){
nSep = strlen30(p->rowSeparator);
}
if( nSep>1 ){
- fprintf(stderr, "Error: multi-character row separators not allowed"
+ raw_printf(stderr, "Error: multi-character row separators not allowed"
" for import\n");
return 1;
}
@@ -2998,7 +3103,7 @@ static int do_meta_command(char *zLine, ShellState *p){
sCtx.nLine = 1;
if( sCtx.zFile[0]=='|' ){
#ifdef SQLITE_OMIT_POPEN
- fprintf(stderr, "Error: pipes are not supported in this OS\n");
+ raw_printf(stderr, "Error: pipes are not supported in this OS\n");
return 1;
#else
sCtx.in = popen(sCtx.zFile+1, "r");
@@ -3015,14 +3120,14 @@ static int do_meta_command(char *zLine, ShellState *p){
xRead = csv_read_one_field;
}
if( sCtx.in==0 ){
- fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
return 1;
}
sCtx.cColSep = p->colSeparator[0];
sCtx.cRowSep = p->rowSeparator[0];
zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
if( zSql==0 ){
- fprintf(stderr, "Error: out of memory\n");
+ raw_printf(stderr, "Error: out of memory\n");
xCloser(sCtx.in);
return 1;
}
@@ -3041,14 +3146,14 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_free(zCreate);
sqlite3_free(sCtx.z);
xCloser(sCtx.in);
- fprintf(stderr,"%s: empty file\n", sCtx.zFile);
+ utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
return 1;
}
zCreate = sqlite3_mprintf("%z\n)", zCreate);
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
sqlite3_free(zCreate);
if( rc ){
- fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
+ utf8_printf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
sqlite3_errmsg(p->db));
sqlite3_free(sCtx.z);
xCloser(sCtx.in);
@@ -3059,7 +3164,7 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_free(zSql);
if( rc ){
if (pStmt) sqlite3_finalize(pStmt);
- fprintf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
xCloser(sCtx.in);
return 1;
}
@@ -3069,7 +3174,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nCol==0 ) return 0; /* no columns, no error */
zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
if( zSql==0 ){
- fprintf(stderr, "Error: out of memory\n");
+ raw_printf(stderr, "Error: out of memory\n");
xCloser(sCtx.in);
return 1;
}
@@ -3084,7 +3189,7 @@ static int do_meta_command(char *zLine, ShellState *p){
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
sqlite3_free(zSql);
if( rc ){
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
if (pStmt) sqlite3_finalize(pStmt);
xCloser(sCtx.in);
return 1;
@@ -3108,7 +3213,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
- fprintf(stderr, "%s:%d: expected %d columns but found %d - "
+ utf8_printf(stderr, "%s:%d: expected %d columns but found %d - "
"filling the rest with NULL\n",
sCtx.zFile, startLine, nCol, i+1);
i += 2;
@@ -3120,7 +3225,7 @@ static int do_meta_command(char *zLine, ShellState *p){
xRead(&sCtx);
i++;
}while( sCtx.cTerm==sCtx.cColSep );
- fprintf(stderr, "%s:%d: expected %d columns but found %d - "
+ utf8_printf(stderr, "%s:%d: expected %d columns but found %d - "
"extras ignored\n",
sCtx.zFile, startLine, nCol, i);
}
@@ -3128,8 +3233,8 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_step(pStmt);
rc = sqlite3_reset(pStmt);
if( rc!=SQLITE_OK ){
- fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
- sqlite3_errmsg(p->db));
+ utf8_printf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile,
+ startLine, sqlite3_errmsg(p->db));
}
}
}while( sCtx.cTerm!=EOF );
@@ -3171,16 +3276,17 @@ static int do_meta_command(char *zLine, ShellState *p){
);
zShellStatic = 0;
}else{
- fprintf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
+ raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
rc = 1;
goto meta_command_exit;
}
if( zErrMsg ){
- fprintf(stderr,"Error: %s\n", zErrMsg);
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
rc = 1;
}else if( rc != SQLITE_OK ){
- fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n");
+ raw_printf(stderr,
+ "Error: querying sqlite_master and sqlite_temp_master\n");
rc = 1;
}
}else
@@ -3198,7 +3304,7 @@ static int do_meta_command(char *zLine, ShellState *p){
}else{
iotrace = fopen(azArg[1], "w");
if( iotrace==0 ){
- fprintf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
sqlite3IoTrace = 0;
rc = 1;
}else{
@@ -3228,30 +3334,30 @@ static int do_meta_command(char *zLine, ShellState *p){
int i, n2;
open_db(p, 0);
if( nArg==1 ){
- for(i=0; i<sizeof(aLimit)/sizeof(aLimit[0]); i++){
+ for(i=0; i<ArraySize(aLimit); i++){
printf("%20s %d\n", aLimit[i].zLimitName,
sqlite3_limit(p->db, aLimit[i].limitCode, -1));
}
}else if( nArg>3 ){
- fprintf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n");
+ raw_printf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n");
rc = 1;
goto meta_command_exit;
}else{
int iLimit = -1;
n2 = strlen30(azArg[1]);
- for(i=0; i<sizeof(aLimit)/sizeof(aLimit[0]); i++){
+ for(i=0; i<ArraySize(aLimit); i++){
if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){
if( iLimit<0 ){
iLimit = i;
}else{
- fprintf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]);
+ utf8_printf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]);
rc = 1;
goto meta_command_exit;
}
}
}
if( iLimit<0 ){
- fprintf(stderr, "unknown limit: \"%s\"\n"
+ utf8_printf(stderr, "unknown limit: \"%s\"\n"
"enter \".limits\" with no arguments for a list.\n",
azArg[1]);
rc = 1;
@@ -3271,7 +3377,7 @@ static int do_meta_command(char *zLine, ShellState *p){
const char *zFile, *zProc;
char *zErrMsg = 0;
if( nArg<2 ){
- fprintf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
+ raw_printf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
rc = 1;
goto meta_command_exit;
}
@@ -3280,7 +3386,7 @@ static int do_meta_command(char *zLine, ShellState *p){
open_db(p, 0);
rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
if( rc!=SQLITE_OK ){
- fprintf(stderr, "Error: %s\n", zErrMsg);
+ utf8_printf(stderr, "Error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
rc = 1;
}
@@ -3289,7 +3395,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
if( nArg!=2 ){
- fprintf(stderr, "Usage: .log FILENAME\n");
+ raw_printf(stderr, "Usage: .log FILENAME\n");
rc = 1;
}else{
const char *zFile = azArg[1];
@@ -3328,7 +3434,7 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
}else {
- fprintf(stderr,"Error: mode should be one of: "
+ raw_printf(stderr, "Error: mode should be one of: "
"ascii column csv html insert line list tabs tcl\n");
rc = 1;
}
@@ -3339,7 +3445,7 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
"%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
}else{
- fprintf(stderr, "Usage: .nullvalue STRING\n");
+ raw_printf(stderr, "Usage: .nullvalue STRING\n");
rc = 1;
}
}else
@@ -3349,9 +3455,8 @@ static int do_meta_command(char *zLine, ShellState *p){
const char *zSavedFilename = p->zDbFilename;
char *zNewFilename = 0;
p->db = 0;
- if( nArg>=2 ){
- p->zDbFilename = zNewFilename = sqlite3_mprintf("%s", azArg[1]);
- }
+ if( nArg>=2 ) zNewFilename = sqlite3_mprintf("%s", azArg[1]);
+ p->zDbFilename = zNewFilename;
open_db(p, 1);
if( p->db!=0 ){
sqlite3_close(savedDb);
@@ -3369,13 +3474,13 @@ static int do_meta_command(char *zLine, ShellState *p){
){
const char *zFile = nArg>=2 ? azArg[1] : "stdout";
if( nArg>2 ){
- fprintf(stderr, "Usage: .%s FILE\n", azArg[0]);
+ utf8_printf(stderr, "Usage: .%s FILE\n", azArg[0]);
rc = 1;
goto meta_command_exit;
}
if( n>1 && strncmp(azArg[0], "once", n)==0 ){
if( nArg<2 ){
- fprintf(stderr, "Usage: .once FILE\n");
+ raw_printf(stderr, "Usage: .once FILE\n");
rc = 1;
goto meta_command_exit;
}
@@ -3386,13 +3491,13 @@ static int do_meta_command(char *zLine, ShellState *p){
output_reset(p);
if( zFile[0]=='|' ){
#ifdef SQLITE_OMIT_POPEN
- fprintf(stderr,"Error: pipes are not supported in this OS\n");
+ raw_printf(stderr, "Error: pipes are not supported in this OS\n");
rc = 1;
p->out = stdout;
#else
p->out = popen(zFile + 1, "w");
if( p->out==0 ){
- fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
+ utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
p->out = stdout;
rc = 1;
}else{
@@ -3403,7 +3508,7 @@ static int do_meta_command(char *zLine, ShellState *p){
p->out = output_file_open(zFile);
if( p->out==0 ){
if( strcmp(zFile,"off")!=0 ){
- fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
+ utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
}
p->out = stdout;
rc = 1;
@@ -3416,10 +3521,10 @@ static int do_meta_command(char *zLine, ShellState *p){
if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
int i;
for(i=1; i<nArg; i++){
- if( i>1 ) fprintf(p->out, " ");
- fprintf(p->out, "%s", azArg[i]);
+ if( i>1 ) raw_printf(p->out, " ");
+ utf8_printf(p->out, "%s", azArg[i]);
}
- fprintf(p->out, "\n");
+ raw_printf(p->out, "\n");
}else
if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){
@@ -3438,13 +3543,13 @@ static int do_meta_command(char *zLine, ShellState *p){
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
FILE *alt;
if( nArg!=2 ){
- fprintf(stderr, "Usage: .read FILE\n");
+ raw_printf(stderr, "Usage: .read FILE\n");
rc = 1;
goto meta_command_exit;
}
alt = fopen(azArg[1], "rb");
if( alt==0 ){
- fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
+ utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
rc = 1;
}else{
rc = process_input(p, alt);
@@ -3466,20 +3571,20 @@ static int do_meta_command(char *zLine, ShellState *p){
zSrcFile = azArg[2];
zDb = azArg[1];
}else{
- fprintf(stderr, "Usage: .restore ?DB? FILE\n");
+ raw_printf(stderr, "Usage: .restore ?DB? FILE\n");
rc = 1;
goto meta_command_exit;
}
rc = sqlite3_open(zSrcFile, &pSrc);
if( rc!=SQLITE_OK ){
- fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
sqlite3_close(pSrc);
return 1;
}
open_db(p, 0);
pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
if( pBackup==0 ){
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
sqlite3_close(pSrc);
return 1;
}
@@ -3494,10 +3599,10 @@ static int do_meta_command(char *zLine, ShellState *p){
if( rc==SQLITE_DONE ){
rc = 0;
}else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){
- fprintf(stderr, "Error: source database is busy\n");
+ raw_printf(stderr, "Error: source database is busy\n");
rc = 1;
}else{
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
rc = 1;
}
sqlite3_close(pSrc);
@@ -3508,10 +3613,10 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nArg==2 ){
p->scanstatsOn = booleanValue(azArg[1]);
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
- fprintf(stderr, "Warning: .scanstats not available in this build.\n");
+ raw_printf(stderr, "Warning: .scanstats not available in this build.\n");
#endif
}else{
- fprintf(stderr, "Usage: .scanstats on|off\n");
+ raw_printf(stderr, "Usage: .scanstats on|off\n");
rc = 1;
}
}else
@@ -3578,16 +3683,16 @@ static int do_meta_command(char *zLine, ShellState *p){
callback, &data, &zErrMsg
);
}else{
- fprintf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
+ raw_printf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
rc = 1;
goto meta_command_exit;
}
if( zErrMsg ){
- fprintf(stderr,"Error: %s\n", zErrMsg);
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
rc = 1;
}else if( rc != SQLITE_OK ){
- fprintf(stderr,"Error: querying schema information\n");
+ raw_printf(stderr,"Error: querying schema information\n");
rc = 1;
}else{
rc = 0;
@@ -3611,7 +3716,7 @@ static int do_meta_command(char *zLine, ShellState *p){
int i, v;
for(i=1; i<nArg; i++){
v = booleanValue(azArg[i]);
- fprintf(p->out, "%s: %d 0x%x\n", azArg[i], v, v);
+ utf8_printf(p->out, "%s: %d 0x%x\n", azArg[i], v, v);
}
}
if( strncmp(azArg[0]+9, "integer", n-9)==0 ){
@@ -3620,7 +3725,7 @@ static int do_meta_command(char *zLine, ShellState *p){
char zBuf[200];
v = integerValue(azArg[i]);
sqlite3_snprintf(sizeof(zBuf),zBuf,"%s: %lld 0x%llx\n", azArg[i],v,v);
- fprintf(p->out, "%s", zBuf);
+ utf8_printf(p->out, "%s", zBuf);
}
}
}else
@@ -3628,7 +3733,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
if( nArg<2 || nArg>3 ){
- fprintf(stderr, "Usage: .separator COL ?ROW?\n");
+ raw_printf(stderr, "Usage: .separator COL ?ROW?\n");
rc = 1;
}
if( nArg>=2 ){
@@ -3647,7 +3752,7 @@ static int do_meta_command(char *zLine, ShellState *p){
char *zCmd;
int i, x;
if( nArg<2 ){
- fprintf(stderr, "Usage: .system COMMAND\n");
+ raw_printf(stderr, "Usage: .system COMMAND\n");
rc = 1;
goto meta_command_exit;
}
@@ -3658,45 +3763,45 @@ static int do_meta_command(char *zLine, ShellState *p){
}
x = system(zCmd);
sqlite3_free(zCmd);
- if( x ) fprintf(stderr, "System command returns %d\n", x);
+ if( x ) raw_printf(stderr, "System command returns %d\n", x);
}else
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
int i;
if( nArg!=1 ){
- fprintf(stderr, "Usage: .show\n");
+ raw_printf(stderr, "Usage: .show\n");
rc = 1;
goto meta_command_exit;
}
- fprintf(p->out,"%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
- fprintf(p->out,"%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
- fprintf(p->out,"%9.9s: %s\n","explain", p->normalMode.valid ? "on" :"off");
- fprintf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
- fprintf(p->out,"%12.12s: %s\n","mode", modeDescr[p->mode]);
- fprintf(p->out,"%12.12s: ", "nullvalue");
+ utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
+ utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
+ utf8_printf(p->out,"%9.9s: %s\n","explain",p->normalMode.valid?"on":"off");
+ utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
+ utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
+ utf8_printf(p->out, "%12.12s: ", "nullvalue");
output_c_string(p->out, p->nullValue);
- fprintf(p->out, "\n");
- fprintf(p->out,"%12.12s: %s\n","output",
+ raw_printf(p->out, "\n");
+ utf8_printf(p->out,"%12.12s: %s\n","output",
strlen30(p->outfile) ? p->outfile : "stdout");
- fprintf(p->out,"%12.12s: ", "colseparator");
+ utf8_printf(p->out,"%12.12s: ", "colseparator");
output_c_string(p->out, p->colSeparator);
- fprintf(p->out, "\n");
- fprintf(p->out,"%12.12s: ", "rowseparator");
+ raw_printf(p->out, "\n");
+ utf8_printf(p->out,"%12.12s: ", "rowseparator");
output_c_string(p->out, p->rowSeparator);
- fprintf(p->out, "\n");
- fprintf(p->out,"%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
- fprintf(p->out,"%12.12s: ","width");
+ raw_printf(p->out, "\n");
+ utf8_printf(p->out, "%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
+ utf8_printf(p->out, "%12.12s: ", "width");
for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
- fprintf(p->out,"%d ",p->colWidth[i]);
+ raw_printf(p->out, "%d ", p->colWidth[i]);
}
- fprintf(p->out,"\n");
+ raw_printf(p->out, "\n");
}else
if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
if( nArg==2 ){
p->statsOn = booleanValue(azArg[1]);
}else{
- fprintf(stderr, "Usage: .stats on|off\n");
+ raw_printf(stderr, "Usage: .stats on|off\n");
rc = 1;
}
}else
@@ -3709,13 +3814,17 @@ static int do_meta_command(char *zLine, ShellState *p){
int ii;
open_db(p, 0);
rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
- if( rc ) return rc;
+ if( rc ) return shellDatabaseError(p->db);
+
+ /* Create an SQL statement to query for the list of tables in the
+ ** main and all attached databases where the table name matches the
+ ** LIKE pattern bound to variable "?1". */
zSql = sqlite3_mprintf(
"SELECT name FROM sqlite_master"
" WHERE type IN ('table','view')"
" AND name NOT LIKE 'sqlite_%%'"
" AND name LIKE ?1");
- while( sqlite3_step(pStmt)==SQLITE_ROW ){
+ while( zSql && sqlite3_step(pStmt)==SQLITE_ROW ){
const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
if( zDbName==0 || strcmp(zDbName,"main")==0 ) continue;
if( strcmp(zDbName,"temp")==0 ){
@@ -3734,11 +3843,17 @@ static int do_meta_command(char *zLine, ShellState *p){
" AND name LIKE ?1", zSql, zDbName, zDbName);
}
}
- sqlite3_finalize(pStmt);
- zSql = sqlite3_mprintf("%z ORDER BY 1", zSql);
- rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
+ rc = sqlite3_finalize(pStmt);
+ if( zSql && rc==SQLITE_OK ){
+ zSql = sqlite3_mprintf("%z ORDER BY 1", zSql);
+ if( zSql ) rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
+ }
sqlite3_free(zSql);
- if( rc ) return rc;
+ if( !zSql ) return shellNomemError();
+ if( rc ) return shellDatabaseError(p->db);
+
+ /* Run the SQL statement prepared by the above block. Store the results
+ ** as an array of nul-terminated strings in azResult[]. */
nRow = nAlloc = 0;
azResult = 0;
if( nArg>1 ){
@@ -3752,17 +3867,25 @@ static int do_meta_command(char *zLine, ShellState *p){
int n2 = nAlloc*2 + 10;
azNew = sqlite3_realloc64(azResult, sizeof(azResult[0])*n2);
if( azNew==0 ){
- fprintf(stderr, "Error: out of memory\n");
+ rc = shellNomemError();
break;
}
nAlloc = n2;
azResult = azNew;
}
azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
- if( azResult[nRow] ) nRow++;
+ if( 0==azResult[nRow] ){
+ rc = shellNomemError();
+ break;
+ }
+ nRow++;
}
- sqlite3_finalize(pStmt);
- if( nRow>0 ){
+ if( sqlite3_finalize(pStmt)!=SQLITE_OK ){
+ rc = shellDatabaseError(p->db);
+ }
+
+ /* Pretty-print the contents of array azResult[] to the output */
+ if( rc==0 && nRow>0 ){
int len, maxlen = 0;
int i, j;
int nPrintCol, nPrintRow;
@@ -3776,11 +3899,13 @@ static int do_meta_command(char *zLine, ShellState *p){
for(i=0; i<nPrintRow; i++){
for(j=i; j<nRow; j+=nPrintRow){
char *zSp = j<nPrintRow ? "" : " ";
- fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:"");
+ utf8_printf(p->out, "%s%-*s", zSp, maxlen,
+ azResult[j] ? azResult[j]:"");
}
- fprintf(p->out, "\n");
+ raw_printf(p->out, "\n");
}
}
+
for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
sqlite3_free(azResult);
}else
@@ -3815,12 +3940,12 @@ static int do_meta_command(char *zLine, ShellState *p){
/* convert testctrl text option to value. allow any unique prefix
** of the option name, or a numerical value. */
n2 = strlen30(azArg[1]);
- for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
+ for(i=0; i<ArraySize(aCtrl); i++){
if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){
if( testctrl<0 ){
testctrl = aCtrl[i].ctrlCode;
}else{
- fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
+ utf8_printf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
testctrl = -1;
break;
}
@@ -3828,7 +3953,7 @@ static int do_meta_command(char *zLine, ShellState *p){
}
if( testctrl<0 ) testctrl = (int)integerValue(azArg[1]);
if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
- fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
+ utf8_printf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
}else{
switch(testctrl){
@@ -3838,9 +3963,9 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nArg==3 ){
int opt = (int)strtol(azArg[2], 0, 0);
rc2 = sqlite3_test_control(testctrl, p->db, opt);
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
} else {
- fprintf(stderr,"Error: testctrl %s takes a single int option\n",
+ utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
azArg[1]);
}
break;
@@ -3852,9 +3977,10 @@ static int do_meta_command(char *zLine, ShellState *p){
case SQLITE_TESTCTRL_BYTEORDER:
if( nArg==2 ){
rc2 = sqlite3_test_control(testctrl);
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
} else {
- fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
+ utf8_printf(stderr,"Error: testctrl %s takes no options\n",
+ azArg[1]);
}
break;
@@ -3863,9 +3989,9 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nArg==3 ){
unsigned int opt = (unsigned int)integerValue(azArg[2]);
rc2 = sqlite3_test_control(testctrl, opt);
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
} else {
- fprintf(stderr,"Error: testctrl %s takes a single unsigned"
+ utf8_printf(stderr,"Error: testctrl %s takes a single unsigned"
" int option\n", azArg[1]);
}
break;
@@ -3877,9 +4003,9 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nArg==3 ){
int opt = booleanValue(azArg[2]);
rc2 = sqlite3_test_control(testctrl, opt);
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
} else {
- fprintf(stderr,"Error: testctrl %s takes a single int option\n",
+ utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
azArg[1]);
}
break;
@@ -3890,10 +4016,11 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nArg==3 ){
const char *opt = azArg[2];
rc2 = sqlite3_test_control(testctrl, opt);
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
} else {
- fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
- azArg[1]);
+ utf8_printf(stderr,
+ "Error: testctrl %s takes a single char * option\n",
+ azArg[1]);
}
break;
#endif
@@ -3904,9 +4031,9 @@ static int do_meta_command(char *zLine, ShellState *p){
azArg[2],
integerValue(azArg[3]),
integerValue(azArg[4]));
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
}else{
- fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
+ raw_printf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
}
break;
@@ -3915,8 +4042,9 @@ static int do_meta_command(char *zLine, ShellState *p){
case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
case SQLITE_TESTCTRL_SCRATCHMALLOC:
default:
- fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n",
- azArg[1]);
+ utf8_printf(stderr,
+ "Error: CLI support for testctrl %s not implemented\n",
+ azArg[1]);
break;
}
}
@@ -3931,11 +4059,11 @@ static int do_meta_command(char *zLine, ShellState *p){
if( nArg==2 ){
enableTimer = booleanValue(azArg[1]);
if( enableTimer && !HAS_TIMER ){
- fprintf(stderr, "Error: timer not available on this system.\n");
+ raw_printf(stderr, "Error: timer not available on this system.\n");
enableTimer = 0;
}
}else{
- fprintf(stderr, "Usage: .timer on|off\n");
+ raw_printf(stderr, "Usage: .timer on|off\n");
rc = 1;
}
}else
@@ -3943,7 +4071,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
open_db(p, 0);
if( nArg!=2 ){
- fprintf(stderr, "Usage: .trace FILE|off\n");
+ raw_printf(stderr, "Usage: .trace FILE|off\n");
rc = 1;
goto meta_command_exit;
}
@@ -3961,26 +4089,26 @@ static int do_meta_command(char *zLine, ShellState *p){
#if SQLITE_USER_AUTHENTICATION
if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
if( nArg<2 ){
- fprintf(stderr, "Usage: .user SUBCOMMAND ...\n");
+ raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n");
rc = 1;
goto meta_command_exit;
}
open_db(p, 0);
if( strcmp(azArg[1],"login")==0 ){
if( nArg!=4 ){
- fprintf(stderr, "Usage: .user login USER PASSWORD\n");
+ raw_printf(stderr, "Usage: .user login USER PASSWORD\n");
rc = 1;
goto meta_command_exit;
}
rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3],
(int)strlen(azArg[3]));
if( rc ){
- fprintf(stderr, "Authentication failed for user %s\n", azArg[2]);
+ utf8_printf(stderr, "Authentication failed for user %s\n", azArg[2]);
rc = 1;
}
}else if( strcmp(azArg[1],"add")==0 ){
if( nArg!=5 ){
- fprintf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
+ raw_printf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
rc = 1;
goto meta_command_exit;
}
@@ -3988,12 +4116,12 @@ static int do_meta_command(char *zLine, ShellState *p){
azArg[3], (int)strlen(azArg[3]),
booleanValue(azArg[4]));
if( rc ){
- fprintf(stderr, "User-Add failed: %d\n", rc);
+ raw_printf(stderr, "User-Add failed: %d\n", rc);
rc = 1;
}
}else if( strcmp(azArg[1],"edit")==0 ){
if( nArg!=5 ){
- fprintf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
+ raw_printf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
rc = 1;
goto meta_command_exit;
}
@@ -4001,22 +4129,22 @@ static int do_meta_command(char *zLine, ShellState *p){
azArg[3], (int)strlen(azArg[3]),
booleanValue(azArg[4]));
if( rc ){
- fprintf(stderr, "User-Edit failed: %d\n", rc);
+ raw_printf(stderr, "User-Edit failed: %d\n", rc);
rc = 1;
}
}else if( strcmp(azArg[1],"delete")==0 ){
if( nArg!=3 ){
- fprintf(stderr, "Usage: .user delete USER\n");
+ raw_printf(stderr, "Usage: .user delete USER\n");
rc = 1;
goto meta_command_exit;
}
rc = sqlite3_user_delete(p->db, azArg[2]);
if( rc ){
- fprintf(stderr, "User-Delete failed: %d\n", rc);
+ raw_printf(stderr, "User-Delete failed: %d\n", rc);
rc = 1;
}
}else{
- fprintf(stderr, "Usage: .user login|add|edit|delete ...\n");
+ raw_printf(stderr, "Usage: .user login|add|edit|delete ...\n");
rc = 1;
goto meta_command_exit;
}
@@ -4024,17 +4152,31 @@ static int do_meta_command(char *zLine, ShellState *p){
#endif /* SQLITE_USER_AUTHENTICATION */
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
- fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
+ utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
sqlite3_libversion(), sqlite3_sourceid());
}else
+ if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
+ const char *zDbName = nArg==2 ? azArg[1] : "main";
+ sqlite3_vfs *pVfs;
+ if( p->db ){
+ sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs);
+ if( pVfs ){
+ utf8_printf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName);
+ raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
+ raw_printf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile);
+ raw_printf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname);
+ }
+ }
+ }else
+
if( c=='v' && strncmp(azArg[0], "vfsname", n)==0 ){
const char *zDbName = nArg==2 ? azArg[1] : "main";
char *zVfsName = 0;
if( p->db ){
sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName);
if( zVfsName ){
- fprintf(p->out, "%s\n", zVfsName);
+ utf8_printf(p->out, "%s\n", zVfsName);
sqlite3_free(zVfsName);
}
}
@@ -4056,7 +4198,7 @@ static int do_meta_command(char *zLine, ShellState *p){
}else
{
- fprintf(stderr, "Error: unknown command or invalid arguments: "
+ utf8_printf(stderr, "Error: unknown command or invalid arguments: "
" \"%s\". Enter \".help\" for help\n", azArg[0]);
rc = 1;
}
@@ -4191,7 +4333,7 @@ static int process_input(ShellState *p, FILE *in){
nAlloc = nSql+nLine+100;
zSql = realloc(zSql, nAlloc);
if( zSql==0 ){
- fprintf(stderr, "Error: out of memory\n");
+ raw_printf(stderr, "Error: out of memory\n");
exit(1);
}
}
@@ -4225,13 +4367,16 @@ static int process_input(ShellState *p, FILE *in){
sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
}
if( zErrMsg!=0 ){
- fprintf(stderr, "%s %s\n", zPrefix, zErrMsg);
+ utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
sqlite3_free(zErrMsg);
zErrMsg = 0;
}else{
- fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
+ utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
}
errCnt++;
+ }else if( p->countChanges ){
+ raw_printf(p->out, "changes: %3d total_changes: %d\n",
+ sqlite3_changes(p->db), sqlite3_total_changes(p->db));
}
nSql = 0;
if( p->outCount ){
@@ -4245,11 +4390,11 @@ static int process_input(ShellState *p, FILE *in){
}
if( nSql ){
if( !_all_whitespace(zSql) ){
- fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
+ utf8_printf(stderr, "Error: incomplete SQL: %s\n", zSql);
errCnt++;
}
- free(zSql);
}
+ free(zSql);
free(zLine);
return errCnt>0;
}
@@ -4336,7 +4481,7 @@ static void process_sqliterc(
if (sqliterc == NULL) {
home_dir = find_home_dir();
if( home_dir==0 ){
- fprintf(stderr, "-- warning: cannot find home directory;"
+ raw_printf(stderr, "-- warning: cannot find home directory;"
" cannot read ~/.sqliterc\n");
return;
}
@@ -4347,7 +4492,7 @@ static void process_sqliterc(
in = fopen(sqliterc,"rb");
if( in ){
if( stdin_is_interactive ){
- fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
+ utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc);
}
process_input(p,in);
fclose(in);
@@ -4394,14 +4539,14 @@ static const char zOptions[] =
#endif
;
static void usage(int showDetail){
- fprintf(stderr,
+ utf8_printf(stderr,
"Usage: %s [OPTIONS] FILENAME [SQL]\n"
"FILENAME is the name of an SQLite database. A new database is created\n"
"if the file does not previously exist.\n", Argv0);
if( showDetail ){
- fprintf(stderr, "OPTIONS include:\n%s", zOptions);
+ utf8_printf(stderr, "OPTIONS include:\n%s", zOptions);
}else{
- fprintf(stderr, "Use the -help option for additional information\n");
+ raw_printf(stderr, "Use the -help option for additional information\n");
}
exit(1);
}
@@ -4449,7 +4594,7 @@ static void printBold(const char *zText){
*/
static char *cmdline_option_value(int argc, char **argv, int i){
if( i==argc ){
- fprintf(stderr, "%s: Error: missing argument to %s\n",
+ utf8_printf(stderr, "%s: Error: missing argument to %s\n",
argv[0], argv[argc-1]);
exit(1);
}
@@ -4469,7 +4614,7 @@ int SQLITE_CDECL main(int argc, char **argv){
#if USE_SYSTEM_SQLITE+0!=1
if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
- fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
+ utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
sqlite3_sourceid(), SQLITE_SOURCE_ID);
exit(1);
}
@@ -4479,6 +4624,7 @@ int SQLITE_CDECL main(int argc, char **argv){
Argv0 = argv[0];
main_init(&data);
stdin_is_interactive = isatty(0);
+ stdout_is_console = isatty(1);
/* Make sure we have a valid signal handler early, before anything
** else is done.
@@ -4517,7 +4663,7 @@ int SQLITE_CDECL main(int argc, char **argv){
nCmd++;
azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
if( azCmd==0 ){
- fprintf(stderr, "out of memory\n");
+ raw_printf(stderr, "out of memory\n");
exit(1);
}
azCmd[nCmd-1] = z;
@@ -4562,10 +4708,10 @@ int SQLITE_CDECL main(int argc, char **argv){
int n, sz;
sz = (int)integerValue(cmdline_option_value(argc,argv,++i));
if( sz>70000 ) sz = 70000;
- if( sz<800 ) sz = 800;
+ if( sz<0 ) sz = 0;
n = (int)integerValue(cmdline_option_value(argc,argv,++i));
- if( n<10 ) n = 10;
- sqlite3_config(SQLITE_CONFIG_PAGECACHE, malloc(n*sz+1), sz, n);
+ sqlite3_config(SQLITE_CONFIG_PAGECACHE,
+ (n>0 && sz>0) ? malloc(n*sz) : 0, sz, n);
data.shellFlgs |= SHFLG_Pagecache;
}else if( strcmp(z,"-lookaside")==0 ){
int n, sz;
@@ -4599,7 +4745,7 @@ int SQLITE_CDECL main(int argc, char **argv){
if( pVfs ){
sqlite3_vfs_register(pVfs, 1);
}else{
- fprintf(stderr, "no such VFS: \"%s\"\n", argv[i]);
+ utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
exit(1);
}
}
@@ -4609,7 +4755,7 @@ int SQLITE_CDECL main(int argc, char **argv){
data.zDbFilename = ":memory:";
warnInmemoryDb = argc==1;
#else
- fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
+ utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
return 1;
#endif
}
@@ -4731,16 +4877,16 @@ int SQLITE_CDECL main(int argc, char **argv){
open_db(&data, 0);
rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
if( zErrMsg!=0 ){
- fprintf(stderr,"Error: %s\n", zErrMsg);
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
if( bail_on_error ) return rc!=0 ? rc : 1;
}else if( rc!=0 ){
- fprintf(stderr,"Error: unable to process SQL \"%s\"\n", z);
+ utf8_printf(stderr,"Error: unable to process SQL \"%s\"\n", z);
if( bail_on_error ) return rc;
}
}
}else{
- fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
- fprintf(stderr,"Use -help for a list of options.\n");
+ utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
+ raw_printf(stderr,"Use -help for a list of options.\n");
return 1;
}
}
@@ -4758,10 +4904,10 @@ int SQLITE_CDECL main(int argc, char **argv){
open_db(&data, 0);
rc = shell_exec(data.db, azCmd[i], shell_callback, &data, &zErrMsg);
if( zErrMsg!=0 ){
- fprintf(stderr,"Error: %s\n", zErrMsg);
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
return rc!=0 ? rc : 1;
}else if( rc!=0 ){
- fprintf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
+ utf8_printf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
return rc;
}
}
@@ -4792,7 +4938,7 @@ int SQLITE_CDECL main(int argc, char **argv){
sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
}
}
- if( zHistory ) shell_read_history(zHistory);
+ if( zHistory ){ shell_read_history(zHistory); }
rc = process_input(&data, 0);
if( zHistory ){
shell_stifle_history(100);