From: mistachkin Date: Thu, 31 Dec 2015 19:06:24 +0000 (+0000) Subject: In the shell, use utf8_printf() when any string formatting is present and raw_printf... X-Git-Tag: version-3.10.0~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aae280ef8b69b38a56aabdd322d59fc8686c7b82;p=thirdparty%2Fsqlite.git In the shell, use utf8_printf() when any string formatting is present and raw_printf() otherwise. FossilOrigin-Name: 8cf01fff232d15d3c7b7b62b2d890d983e1945f2 --- diff --git a/manifest b/manifest index 3b002abdc1..3c7f5db48d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarning\sseen\swith\sMSVC. -D 2015-12-31T19:04:42.799 +C In\sthe\sshell,\suse\sutf8_printf()\swhen\sany\sstring\sformatting\sis\spresent\sand\sraw_printf()\sotherwise. +D 2015-12-31T19:06:24.721 F Makefile.in 28bcd6149e050dff35d4dcfd97e890cd387a499d F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 5fff077fcc46de7714ed6eebb6159a4c00eab751 @@ -334,7 +334,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c a83b41104e6ff69855d03cd0aaa09e93927ec39f F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c f8fded11fc443a9f5a73cc5db069d06b34460e2f -F src/shell.c ace08b69cd9702143cf87b5bd20b744a56f832fd +F src/shell.c 8d152e833c3b79825978deb83175234749c5cdf3 F src/sqlite.h.in 7d87d71b9a4689c51fa092f48f16590ff71558e3 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d @@ -1406,7 +1406,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9c392c1019ee15f27c8e05b41246d2844f91f6c0 -R 55161c92d22f1816c3b9c126a24128f9 +P 98ec778daac835d9ae103f6460b7d897981a5dd6 +R cd1e993dc14f9af3b107557468145aaf U mistachkin -Z b7a8bb994d81380f55ad5f17330fd4b6 +Z 770ade254ba97d3649a2f5b30f5d6fd8 diff --git a/manifest.uuid b/manifest.uuid index 60606fbdfc..4302de3a4a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -98ec778daac835d9ae103f6460b7d897981a5dd6 \ No newline at end of file +8cf01fff232d15d3c7b7b62b2d890d983e1945f2 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index a6d75176c2..ecb591a32a 100644 --- a/src/shell.c +++ b/src/shell.c @@ -382,7 +382,7 @@ static void SQLITE_CDECL iotracePrintf(const char *zFormat, ...){ va_start(ap, zFormat); z = sqlite3_vmprintf(zFormat, ap); va_end(ap); - fprintf(iotrace, "%s", z); + utf8_printf(iotrace, "%s", z); sqlite3_free(z); } #endif @@ -548,7 +548,7 @@ static char *one_input_line(FILE *in, char *zPrior, int isContinuation){ void utf8_printf(FILE *out, const char *zFormat, ...){ va_list ap; va_start(ap, zFormat); - if( stdout_is_console && out==stdout ){ + 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); @@ -560,10 +560,18 @@ void utf8_printf(FILE *out, const char *zFormat, ...){ } va_end(ap); } -#else +#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" @@ -675,7 +683,7 @@ static const char *modeDescr[] = { 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); } @@ -685,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' ){ - fprintf(out,">"); + raw_printf(out,">"); }else if( z[i]=='\"' ){ - fprintf(out,"""); + raw_printf(out,"""); }else if( z[i]=='\'' ){ - fprintf(out,"'"); + raw_printf(out,"'"); }else{ break; } @@ -927,7 +935,7 @@ 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 : " "); @@ -947,7 +955,7 @@ static int shell_callback( } if( i==1 && p->aiIndent && p->pStmt ){ if( p->iIndentnIndent ){ - fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], ""); + utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], ""); } p->iIndent++; } @@ -988,22 +996,22 @@ static int shell_callback( } case MODE_Html: { if( p->cnt++==0 && p->showHeader ){ - fprintf(p->out,""); + raw_printf(p->out,""); for(i=0; iout,""); + raw_printf(p->out,""); output_html_string(p->out, azCol[i]); - fprintf(p->out,"\n"); + raw_printf(p->out,"\n"); } - fprintf(p->out,"\n"); + raw_printf(p->out,"\n"); } if( azArg==0 ) break; - fprintf(p->out,""); + raw_printf(p->out,""); for(i=0; iout,""); + raw_printf(p->out,""); output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue); - fprintf(p->out,"\n"); + raw_printf(p->out,"\n"); } - fprintf(p->out,"\n"); + raw_printf(p->out,"\n"); break; } case MODE_Tcl: { @@ -1044,20 +1052,20 @@ static int shell_callback( if( azArg==0 ) break; utf8_printf(p->out,"INSERT INTO %s",p->zDestTable); if( p->showHeader ){ - fprintf(p->out,"("); + raw_printf(p->out,"("); for(i=0; i0 ? ",": ""; 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; i0 ? ",": ""; 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) ){ @@ -1065,16 +1073,16 @@ static int shell_callback( }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) ){ 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: { @@ -1131,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; @@ -1212,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; } @@ -1231,15 +1240,16 @@ static int run_table_dump_query( 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; @@ -1274,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 } @@ -1329,48 +1340,55 @@ 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 */ @@ -1390,7 +1408,7 @@ static void display_scanstats( 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; @@ -1408,7 +1426,7 @@ 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); @@ -1416,13 +1434,13 @@ static void display_scanstats( sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&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 } @@ -1586,9 +1604,9 @@ 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)); + 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)); } } @@ -1717,13 +1735,13 @@ 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( @@ -1811,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; } @@ -1822,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; } @@ -1987,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); @@ -2137,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; } @@ -2165,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; @@ -2214,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); } } @@ -2268,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; @@ -2354,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; @@ -2362,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, @@ -2375,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; @@ -2412,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); @@ -2429,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...) */ @@ -2465,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; @@ -2476,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; } @@ -2492,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; @@ -2503,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; } @@ -2527,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); @@ -2629,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]); + 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; iout, "%-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"); @@ -2673,7 +2691,7 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){ */ static int shellDatabaseError(sqlite3 *db){ const char *zErr = sqlite3_errmsg(db); - fprintf(stderr, "Error: %s\n", zErr); + utf8_printf(stderr, "Error: %s\n", zErr); return 1; } @@ -2681,7 +2699,7 @@ static int shellDatabaseError(sqlite3 *db){ ** Print an out-of-memory message to stderr and return 1. */ static int shellNomemError(void){ - fprintf(stderr, "Error: out of memory\n"); + raw_printf(stderr, "Error: out of memory\n"); return 1; } @@ -2741,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 ){ @@ -2750,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; } @@ -2777,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); @@ -2787,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 @@ -2800,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 @@ -2816,7 +2834,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( nArg==2 ){ p->countChanges = booleanValue(azArg[1]); }else{ - fprintf(stderr, "Usage: .changes on|off\n"); + raw_printf(stderr, "Usage: .changes on|off\n"); rc = 1; } }else @@ -2825,7 +2843,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( nArg==2 ){ tryToClone(p, azArg[1]); }else{ - fprintf(stderr, "Usage: .clone FILENAME\n"); + raw_printf(stderr, "Usage: .clone FILENAME\n"); rc = 1; } }else @@ -2843,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; } @@ -2859,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; @@ -2899,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 @@ -2920,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 @@ -2970,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; } @@ -2997,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; @@ -3012,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 @@ -3020,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 ){ @@ -3044,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]; @@ -3054,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 ){ @@ -3076,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; } @@ -3084,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"); @@ -3101,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; } @@ -3127,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); @@ -3145,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; } @@ -3155,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; } @@ -3170,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; @@ -3194,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( idb)); + utf8_printf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, + startLine, sqlite3_errmsg(p->db)); } } }while( sCtx.cTerm!=EOF ); @@ -3257,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 @@ -3284,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{ @@ -3319,7 +3339,7 @@ static int do_meta_command(char *zLine, ShellState *p){ 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{ @@ -3330,14 +3350,14 @@ static int do_meta_command(char *zLine, ShellState *p){ 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; @@ -3357,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; } @@ -3366,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; } @@ -3375,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]; @@ -3414,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; } @@ -3425,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 @@ -3454,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; } @@ -3471,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{ @@ -3488,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; @@ -3501,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; i1 ) fprintf(p->out, " "); + 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 ){ @@ -3523,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); @@ -3551,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; } @@ -3579,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); @@ -3593,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 @@ -3663,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; @@ -3713,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 ){ @@ -3732,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; } @@ -3743,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 @@ -3882,7 +3902,7 @@ static int do_meta_command(char *zLine, ShellState *p){ utf8_printf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:""); } - fprintf(p->out, "\n"); + raw_printf(p->out, "\n"); } } @@ -3925,7 +3945,7 @@ static int do_meta_command(char *zLine, ShellState *p){ 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; } @@ -3933,7 +3953,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } if( testctrl<0 ) testctrl = (int)integerValue(azArg[1]); if( (testctrlSQLITE_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){ @@ -3943,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; @@ -3957,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; @@ -3968,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; @@ -3982,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; @@ -3995,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 @@ -4009,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; @@ -4020,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; } } @@ -4036,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 @@ -4048,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; } @@ -4066,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; } @@ -4093,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; } @@ -4106,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; } @@ -4129,7 +4152,7 @@ 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 @@ -4139,10 +4162,10 @@ static int do_meta_command(char *zLine, ShellState *p){ if( p->db ){ sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs); if( pVfs ){ - fprintf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName); - fprintf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion); - fprintf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile); - fprintf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname); + 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 @@ -4153,7 +4176,7 @@ static int do_meta_command(char *zLine, ShellState *p){ 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); } } @@ -4175,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; } @@ -4310,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); } } @@ -4344,15 +4367,15 @@ 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 ){ - fprintf(p->out, "changes: %3d total_changes: %d\n", + raw_printf(p->out, "changes: %3d total_changes: %d\n", sqlite3_changes(p->db), sqlite3_total_changes(p->db)); } nSql = 0; @@ -4367,7 +4390,7 @@ 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++; } } @@ -4458,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; } @@ -4469,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); @@ -4516,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); } @@ -4571,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); } @@ -4591,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); } @@ -4640,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; @@ -4722,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); } } @@ -4732,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 } @@ -4854,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; } } @@ -4881,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; } }