Fossil SCM

Merge trunk.

jan 2016-01-07 10:02 jan-manifest-tags merge
Commit 99f7662b5ef83817150ecfee6ea731e1e78d07ca
+2 -2
--- src/manifest.c
+++ src/manifest.c
@@ -380,13 +380,13 @@
380380
** if that is not the case for this artifact.
381381
*/
382382
if( !isRepeat ) g.parseCnt[0]++;
383383
z = blob_materialize(pContent);
384384
n = blob_size(pContent);
385
- if( pErr && (n<=0 || z[n-1]!='\n') ){
385
+ if( n<=0 || z[n-1]!='\n' ){
386386
blob_reset(pContent);
387
- blob_append(pErr, n ? "not terminated with \\n" : "zero-length", -1);
387
+ blob_appendf(pErr, "%s", n ? "not terminated with \\n" : "zero-length");
388388
return 0;
389389
}
390390
391391
/* Strip off the PGP signature if there is one.
392392
*/
393393
--- src/manifest.c
+++ src/manifest.c
@@ -380,13 +380,13 @@
380 ** if that is not the case for this artifact.
381 */
382 if( !isRepeat ) g.parseCnt[0]++;
383 z = blob_materialize(pContent);
384 n = blob_size(pContent);
385 if( pErr && (n<=0 || z[n-1]!='\n') ){
386 blob_reset(pContent);
387 blob_append(pErr, n ? "not terminated with \\n" : "zero-length", -1);
388 return 0;
389 }
390
391 /* Strip off the PGP signature if there is one.
392 */
393
--- src/manifest.c
+++ src/manifest.c
@@ -380,13 +380,13 @@
380 ** if that is not the case for this artifact.
381 */
382 if( !isRepeat ) g.parseCnt[0]++;
383 z = blob_materialize(pContent);
384 n = blob_size(pContent);
385 if( n<=0 || z[n-1]!='\n' ){
386 blob_reset(pContent);
387 blob_appendf(pErr, "%s", n ? "not terminated with \\n" : "zero-length");
388 return 0;
389 }
390
391 /* Strip off the PGP signature if there is one.
392 */
393
+278 -255
--- src/shell.c
+++ src/shell.c
@@ -546,11 +546,11 @@
546546
*/
547547
#if defined(_WIN32) || defined(WIN32)
548548
void utf8_printf(FILE *out, const char *zFormat, ...){
549549
va_list ap;
550550
va_start(ap, zFormat);
551
- if( stdout_is_console && out==stdout ){
551
+ if( stdout_is_console && (out==stdout || out==stderr) ){
552552
extern char *sqlite3_win32_utf8_to_mbcs(const char*);
553553
char *z1 = sqlite3_vmprintf(zFormat, ap);
554554
char *z2 = sqlite3_win32_utf8_to_mbcs(z1);
555555
sqlite3_free(z1);
556556
fputs(z2, out);
@@ -558,14 +558,22 @@
558558
}else{
559559
vfprintf(out, zFormat, ap);
560560
}
561561
va_end(ap);
562562
}
563
-#else
563
+#elif !defined(utf8_printf)
564564
# define utf8_printf fprintf
565565
#endif
566566
567
+/*
568
+** Render output like fprintf(). This should not be used on anything that
569
+** includes string formatting (e.g. "%s").
570
+*/
571
+#if !defined(raw_printf)
572
+# define raw_printf fprintf
573
+#endif
574
+
567575
/*
568576
** Shell output mode information from before ".explain on",
569577
** saved so that it can be restored by ".explain off"
570578
*/
571579
typedef struct SavedModeInfo SavedModeInfo;
@@ -673,23 +681,23 @@
673681
** A callback for the sqlite3_log() interface.
674682
*/
675683
static void shellLog(void *pArg, int iErrCode, const char *zMsg){
676684
ShellState *p = (ShellState*)pArg;
677685
if( p->pLog==0 ) return;
678
- fprintf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
686
+ utf8_printf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
679687
fflush(p->pLog);
680688
}
681689
682690
/*
683691
** Output the given string as a hex-encoded blob (eg. X'1234' )
684692
*/
685693
static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
686694
int i;
687695
char *zBlob = (char *)pBlob;
688
- fprintf(out,"X'");
689
- for(i=0; i<nBlob; i++){ fprintf(out,"%02x",zBlob[i]&0xff); }
690
- fprintf(out,"'");
696
+ raw_printf(out,"X'");
697
+ for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
698
+ raw_printf(out,"'");
691699
}
692700
693701
/*
694702
** Output the given string as a quoted string using SQL quoting conventions.
695703
*/
@@ -701,25 +709,25 @@
701709
if( z[i]=='\'' ) nSingle++;
702710
}
703711
if( nSingle==0 ){
704712
utf8_printf(out,"'%s'",z);
705713
}else{
706
- fprintf(out,"'");
714
+ raw_printf(out,"'");
707715
while( *z ){
708716
for(i=0; z[i] && z[i]!='\''; i++){}
709717
if( i==0 ){
710
- fprintf(out,"''");
718
+ raw_printf(out,"''");
711719
z++;
712720
}else if( z[i]=='\'' ){
713721
utf8_printf(out,"%.*s''",i,z);
714722
z += i+1;
715723
}else{
716724
utf8_printf(out,"%s",z);
717725
break;
718726
}
719727
}
720
- fprintf(out,"'");
728
+ raw_printf(out,"'");
721729
}
722730
setTextMode(out);
723731
}
724732
725733
/*
@@ -743,11 +751,11 @@
743751
fputc('n', out);
744752
}else if( c=='\r' ){
745753
fputc('\\', out);
746754
fputc('r', out);
747755
}else if( !isprint(c&0xff) ){
748
- fprintf(out, "\\%03o", c&0xff);
756
+ raw_printf(out, "\\%03o", c&0xff);
749757
}else{
750758
fputc(c, out);
751759
}
752760
}
753761
fputc('"', out);
@@ -770,19 +778,19 @@
770778
i++){}
771779
if( i>0 ){
772780
utf8_printf(out,"%.*s",i,z);
773781
}
774782
if( z[i]=='<' ){
775
- fprintf(out,"&lt;");
783
+ raw_printf(out,"&lt;");
776784
}else if( z[i]=='&' ){
777
- fprintf(out,"&amp;");
785
+ raw_printf(out,"&amp;");
778786
}else if( z[i]=='>' ){
779
- fprintf(out,"&gt;");
787
+ raw_printf(out,"&gt;");
780788
}else if( z[i]=='\"' ){
781
- fprintf(out,"&quot;");
789
+ raw_printf(out,"&quot;");
782790
}else if( z[i]=='\'' ){
783
- fprintf(out,"&#39;");
791
+ raw_printf(out,"&#39;");
784792
}else{
785793
break;
786794
}
787795
z += i + 1;
788796
}
@@ -925,11 +933,11 @@
925933
w = p->actualWidth[i];
926934
if( w<0 ) w = -w;
927935
}else{
928936
w = 10;
929937
}
930
- fprintf(p->out,"%-*.*s%s",w,w,
938
+ utf8_printf(p->out,"%-*.*s%s",w,w,
931939
"----------------------------------------------------------"
932940
"----------------------------------------------------------",
933941
i==nArg-1 ? p->rowSeparator : " ");
934942
}
935943
}
@@ -945,11 +953,11 @@
945953
if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
946954
w = strlen30(azArg[i]);
947955
}
948956
if( i==1 && p->aiIndent && p->pStmt ){
949957
if( p->iIndent<p->nIndent ){
950
- fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
958
+ utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
951959
}
952960
p->iIndent++;
953961
}
954962
if( w<0 ){
955963
utf8_printf(p->out,"%*.*s%s",-w,-w,
@@ -986,26 +994,26 @@
986994
}
987995
break;
988996
}
989997
case MODE_Html: {
990998
if( p->cnt++==0 && p->showHeader ){
991
- fprintf(p->out,"<TR>");
999
+ raw_printf(p->out,"<TR>");
9921000
for(i=0; i<nArg; i++){
993
- fprintf(p->out,"<TH>");
1001
+ raw_printf(p->out,"<TH>");
9941002
output_html_string(p->out, azCol[i]);
995
- fprintf(p->out,"</TH>\n");
1003
+ raw_printf(p->out,"</TH>\n");
9961004
}
997
- fprintf(p->out,"</TR>\n");
1005
+ raw_printf(p->out,"</TR>\n");
9981006
}
9991007
if( azArg==0 ) break;
1000
- fprintf(p->out,"<TR>");
1008
+ raw_printf(p->out,"<TR>");
10011009
for(i=0; i<nArg; i++){
1002
- fprintf(p->out,"<TD>");
1010
+ raw_printf(p->out,"<TD>");
10031011
output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
1004
- fprintf(p->out,"</TD>\n");
1012
+ raw_printf(p->out,"</TD>\n");
10051013
}
1006
- fprintf(p->out,"</TR>\n");
1014
+ raw_printf(p->out,"</TR>\n");
10071015
break;
10081016
}
10091017
case MODE_Tcl: {
10101018
if( p->cnt++==0 && p->showHeader ){
10111019
for(i=0; i<nArg; i++){
@@ -1042,41 +1050,41 @@
10421050
case MODE_Insert: {
10431051
p->cnt++;
10441052
if( azArg==0 ) break;
10451053
utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
10461054
if( p->showHeader ){
1047
- fprintf(p->out,"(");
1055
+ raw_printf(p->out,"(");
10481056
for(i=0; i<nArg; i++){
10491057
char *zSep = i>0 ? ",": "";
10501058
utf8_printf(p->out, "%s%s", zSep, azCol[i]);
10511059
}
1052
- fprintf(p->out,")");
1060
+ raw_printf(p->out,")");
10531061
}
1054
- fprintf(p->out," VALUES(");
1062
+ raw_printf(p->out," VALUES(");
10551063
for(i=0; i<nArg; i++){
10561064
char *zSep = i>0 ? ",": "";
10571065
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
1058
- fprintf(p->out,"%sNULL",zSep);
1066
+ utf8_printf(p->out,"%sNULL",zSep);
10591067
}else if( aiType && aiType[i]==SQLITE_TEXT ){
1060
- if( zSep[0] ) fprintf(p->out,"%s",zSep);
1068
+ if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
10611069
output_quoted_string(p->out, azArg[i]);
10621070
}else if( aiType && (aiType[i]==SQLITE_INTEGER
10631071
|| aiType[i]==SQLITE_FLOAT) ){
10641072
utf8_printf(p->out,"%s%s",zSep, azArg[i]);
10651073
}else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
10661074
const void *pBlob = sqlite3_column_blob(p->pStmt, i);
10671075
int nBlob = sqlite3_column_bytes(p->pStmt, i);
1068
- if( zSep[0] ) fprintf(p->out,"%s",zSep);
1076
+ if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
10691077
output_hex_blob(p->out, pBlob, nBlob);
10701078
}else if( isNumber(azArg[i], 0) ){
10711079
utf8_printf(p->out,"%s%s",zSep, azArg[i]);
10721080
}else{
1073
- if( zSep[0] ) fprintf(p->out,"%s",zSep);
1081
+ if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
10741082
output_quoted_string(p->out, azArg[i]);
10751083
}
10761084
}
1077
- fprintf(p->out,");\n");
1085
+ raw_printf(p->out,");\n");
10781086
break;
10791087
}
10801088
case MODE_Ascii: {
10811089
if( p->cnt++==0 && p->showHeader ){
10821090
for(i=0; i<nArg; i++){
@@ -1129,11 +1137,11 @@
11291137
}
11301138
}
11311139
if( needQuote ) n += 2;
11321140
z = p->zDestTable = malloc( n+1 );
11331141
if( z==0 ){
1134
- fprintf(stderr,"Error: out of memory\n");
1142
+ raw_printf(stderr,"Error: out of memory\n");
11351143
exit(1);
11361144
}
11371145
n = 0;
11381146
if( needQuote ) z[n++] = '\'';
11391147
for(i=0; zName[i]; i++){
@@ -1210,11 +1218,12 @@
12101218
int nResult;
12111219
int i;
12121220
const char *z;
12131221
rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
12141222
if( rc!=SQLITE_OK || !pSelect ){
1215
- fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
1223
+ utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc,
1224
+ sqlite3_errmsg(p->db));
12161225
if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
12171226
return rc;
12181227
}
12191228
rc = sqlite3_step(pSelect);
12201229
nResult = sqlite3_column_count(pSelect);
@@ -1229,19 +1238,20 @@
12291238
utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
12301239
}
12311240
if( z==0 ) z = "";
12321241
while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
12331242
if( z[0] ){
1234
- fprintf(p->out, "\n;\n");
1243
+ raw_printf(p->out, "\n;\n");
12351244
}else{
1236
- fprintf(p->out, ";\n");
1245
+ raw_printf(p->out, ";\n");
12371246
}
12381247
rc = sqlite3_step(pSelect);
12391248
}
12401249
rc = sqlite3_finalize(pSelect);
12411250
if( rc!=SQLITE_OK ){
1242
- fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
1251
+ utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc,
1252
+ sqlite3_errmsg(p->db));
12431253
if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
12441254
}
12451255
return rc;
12461256
}
12471257
@@ -1272,107 +1282,115 @@
12721282
12731283
if( pArg && pArg->out ){
12741284
12751285
iHiwtr = iCur = -1;
12761286
sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
1277
- fprintf(pArg->out,
1287
+ raw_printf(pArg->out,
12781288
"Memory Used: %d (max %d) bytes\n",
12791289
iCur, iHiwtr);
12801290
iHiwtr = iCur = -1;
12811291
sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
1282
- fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
1292
+ raw_printf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
12831293
iCur, iHiwtr);
12841294
if( pArg->shellFlgs & SHFLG_Pagecache ){
12851295
iHiwtr = iCur = -1;
12861296
sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
1287
- fprintf(pArg->out,
1297
+ raw_printf(pArg->out,
12881298
"Number of Pcache Pages Used: %d (max %d) pages\n",
12891299
iCur, iHiwtr);
12901300
}
12911301
iHiwtr = iCur = -1;
12921302
sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
1293
- fprintf(pArg->out,
1303
+ raw_printf(pArg->out,
12941304
"Number of Pcache Overflow Bytes: %d (max %d) bytes\n",
12951305
iCur, iHiwtr);
12961306
if( pArg->shellFlgs & SHFLG_Scratch ){
12971307
iHiwtr = iCur = -1;
12981308
sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
1299
- fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n",
1309
+ raw_printf(pArg->out,
1310
+ "Number of Scratch Allocations Used: %d (max %d)\n",
13001311
iCur, iHiwtr);
13011312
}
13021313
iHiwtr = iCur = -1;
13031314
sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
1304
- fprintf(pArg->out,
1315
+ raw_printf(pArg->out,
13051316
"Number of Scratch Overflow Bytes: %d (max %d) bytes\n",
13061317
iCur, iHiwtr);
13071318
iHiwtr = iCur = -1;
13081319
sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
1309
- fprintf(pArg->out, "Largest Allocation: %d bytes\n",
1320
+ raw_printf(pArg->out, "Largest Allocation: %d bytes\n",
13101321
iHiwtr);
13111322
iHiwtr = iCur = -1;
13121323
sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
1313
- fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
1324
+ raw_printf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
13141325
iHiwtr);
13151326
iHiwtr = iCur = -1;
13161327
sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
1317
- fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
1328
+ raw_printf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
13181329
iHiwtr);
13191330
#ifdef YYTRACKMAXSTACKDEPTH
13201331
iHiwtr = iCur = -1;
13211332
sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
1322
- fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
1333
+ raw_printf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
13231334
iCur, iHiwtr);
13241335
#endif
13251336
}
13261337
13271338
if( pArg && pArg->out && db ){
13281339
if( pArg->shellFlgs & SHFLG_Lookaside ){
13291340
iHiwtr = iCur = -1;
13301341
sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED,
13311342
&iCur, &iHiwtr, bReset);
1332
- fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n",
1343
+ raw_printf(pArg->out,
1344
+ "Lookaside Slots Used: %d (max %d)\n",
13331345
iCur, iHiwtr);
13341346
sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT,
13351347
&iCur, &iHiwtr, bReset);
1336
- fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr);
1348
+ raw_printf(pArg->out, "Successful lookaside attempts: %d\n",
1349
+ iHiwtr);
13371350
sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE,
13381351
&iCur, &iHiwtr, bReset);
1339
- fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr);
1352
+ raw_printf(pArg->out, "Lookaside failures due to size: %d\n",
1353
+ iHiwtr);
13401354
sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL,
13411355
&iCur, &iHiwtr, bReset);
1342
- fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr);
1356
+ raw_printf(pArg->out, "Lookaside failures due to OOM: %d\n",
1357
+ iHiwtr);
13431358
}
13441359
iHiwtr = iCur = -1;
13451360
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
1346
- fprintf(pArg->out, "Pager Heap Usage: %d bytes\n",iCur);
1361
+ raw_printf(pArg->out, "Pager Heap Usage: %d bytes\n",
1362
+ iCur);
13471363
iHiwtr = iCur = -1;
13481364
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
1349
- fprintf(pArg->out, "Page cache hits: %d\n", iCur);
1365
+ raw_printf(pArg->out, "Page cache hits: %d\n", iCur);
13501366
iHiwtr = iCur = -1;
13511367
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
1352
- fprintf(pArg->out, "Page cache misses: %d\n", iCur);
1368
+ raw_printf(pArg->out, "Page cache misses: %d\n", iCur);
13531369
iHiwtr = iCur = -1;
13541370
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
1355
- fprintf(pArg->out, "Page cache writes: %d\n", iCur);
1371
+ raw_printf(pArg->out, "Page cache writes: %d\n", iCur);
13561372
iHiwtr = iCur = -1;
13571373
sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1358
- fprintf(pArg->out, "Schema Heap Usage: %d bytes\n",iCur);
1374
+ raw_printf(pArg->out, "Schema Heap Usage: %d bytes\n",
1375
+ iCur);
13591376
iHiwtr = iCur = -1;
13601377
sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
1361
- fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",iCur);
1378
+ raw_printf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",
1379
+ iCur);
13621380
}
13631381
13641382
if( pArg && pArg->out && db && pArg->pStmt ){
13651383
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP,
13661384
bReset);
1367
- fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1385
+ raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur);
13681386
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1369
- fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1387
+ raw_printf(pArg->out, "Sort Operations: %d\n", iCur);
13701388
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
1371
- fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1389
+ raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur);
13721390
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1373
- fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1391
+ raw_printf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
13741392
}
13751393
13761394
/* Do not remove this machine readable comment: extra-stats-output-here */
13771395
13781396
return 0;
@@ -1388,11 +1406,11 @@
13881406
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
13891407
UNUSED_PARAMETER(db);
13901408
UNUSED_PARAMETER(pArg);
13911409
#else
13921410
int i, k, n, mx;
1393
- fprintf(pArg->out, "-------- scanstats --------\n");
1411
+ raw_printf(pArg->out, "-------- scanstats --------\n");
13941412
mx = 0;
13951413
for(k=0; k<=mx; k++){
13961414
double rEstLoop = 1.0;
13971415
for(i=n=0; 1; i++){
13981416
sqlite3_stmt *p = pArg->pStmt;
@@ -1406,25 +1424,25 @@
14061424
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_SELECTID, (void*)&iSid);
14071425
if( iSid>mx ) mx = iSid;
14081426
if( iSid!=k ) continue;
14091427
if( n==0 ){
14101428
rEstLoop = (double)nLoop;
1411
- if( k>0 ) fprintf(pArg->out, "-------- subquery %d -------\n", k);
1429
+ if( k>0 ) raw_printf(pArg->out, "-------- subquery %d -------\n", k);
14121430
}
14131431
n++;
14141432
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
14151433
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
14161434
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
14171435
utf8_printf(pArg->out, "Loop %2d: %s\n", n, zExplain);
14181436
rEstLoop *= rEst;
1419
- fprintf(pArg->out,
1437
+ raw_printf(pArg->out,
14201438
" nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
14211439
nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
14221440
);
14231441
}
14241442
}
1425
- fprintf(pArg->out, "---------------------------\n");
1443
+ raw_printf(pArg->out, "---------------------------\n");
14261444
#endif
14271445
}
14281446
14291447
/*
14301448
** Parameter azArray points to a zero-terminated array of strings. zStr
@@ -1584,13 +1602,13 @@
15841602
char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
15851603
sqlite3_sql(pStmt));
15861604
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
15871605
if( rc==SQLITE_OK ){
15881606
while( sqlite3_step(pExplain)==SQLITE_ROW ){
1589
- fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1590
- fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
1591
- fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
1607
+ raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
1608
+ raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
1609
+ raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
15921610
utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
15931611
}
15941612
}
15951613
sqlite3_finalize(pExplain);
15961614
sqlite3_free(zEQP);
@@ -1715,17 +1733,17 @@
17151733
zSql = azArg[2];
17161734
17171735
if( strcmp(zTable, "sqlite_sequence")==0 ){
17181736
zPrepStmt = "DELETE FROM sqlite_sequence;\n";
17191737
}else if( sqlite3_strglob("sqlite_stat?", zTable)==0 ){
1720
- fprintf(p->out, "ANALYZE sqlite_master;\n");
1738
+ raw_printf(p->out, "ANALYZE sqlite_master;\n");
17211739
}else if( strncmp(zTable, "sqlite_", 7)==0 ){
17221740
return 0;
17231741
}else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
17241742
char *zIns;
17251743
if( !p->writableSchema ){
1726
- fprintf(p->out, "PRAGMA writable_schema=ON;\n");
1744
+ raw_printf(p->out, "PRAGMA writable_schema=ON;\n");
17271745
p->writableSchema = 1;
17281746
}
17291747
zIns = sqlite3_mprintf(
17301748
"INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
17311749
"VALUES('table','%q','%q',0,'%q');",
@@ -1809,22 +1827,22 @@
18091827
char *zErr = 0;
18101828
rc = sqlite3_exec(p->db, zQuery, dump_callback, p, &zErr);
18111829
if( rc==SQLITE_CORRUPT ){
18121830
char *zQ2;
18131831
int len = strlen30(zQuery);
1814
- fprintf(p->out, "/****** CORRUPTION ERROR *******/\n");
1832
+ raw_printf(p->out, "/****** CORRUPTION ERROR *******/\n");
18151833
if( zErr ){
1816
- fprintf(p->out, "/****** %s ******/\n", zErr);
1834
+ utf8_printf(p->out, "/****** %s ******/\n", zErr);
18171835
sqlite3_free(zErr);
18181836
zErr = 0;
18191837
}
18201838
zQ2 = malloc( len+100 );
18211839
if( zQ2==0 ) return rc;
18221840
sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery);
18231841
rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr);
18241842
if( rc ){
1825
- fprintf(p->out, "/****** ERROR: %s ******/\n", zErr);
1843
+ utf8_printf(p->out, "/****** ERROR: %s ******/\n", zErr);
18261844
}else{
18271845
rc = SQLITE_CORRUPT;
18281846
}
18291847
sqlite3_free(zErr);
18301848
free(zQ2);
@@ -1985,11 +2003,11 @@
19852003
if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
19862004
sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
19872005
shellstaticFunc, 0, 0);
19882006
}
19892007
if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
1990
- fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
2008
+ utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
19912009
p->zDbFilename, sqlite3_errmsg(p->db));
19922010
if( keepAlive ) return;
19932011
exit(1);
19942012
}
19952013
#ifndef SQLITE_OMIT_LOAD_EXTENSION
@@ -2135,11 +2153,11 @@
21352153
return 1;
21362154
}
21372155
if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){
21382156
return 0;
21392157
}
2140
- fprintf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
2158
+ utf8_printf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
21412159
zArg);
21422160
return 0;
21432161
}
21442162
21452163
/*
@@ -2163,11 +2181,11 @@
21632181
}else if( strcmp(zFile, "off")==0 ){
21642182
f = 0;
21652183
}else{
21662184
f = fopen(zFile, "wb");
21672185
if( f==0 ){
2168
- fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
2186
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
21692187
}
21702188
}
21712189
return f;
21722190
}
21732191
@@ -2212,11 +2230,11 @@
22122230
static void import_append_char(ImportCtx *p, int c){
22132231
if( p->n+1>=p->nAlloc ){
22142232
p->nAlloc += p->nAlloc + 100;
22152233
p->z = sqlite3_realloc64(p->z, p->nAlloc);
22162234
if( p->z==0 ){
2217
- fprintf(stderr, "out of memory\n");
2235
+ raw_printf(stderr, "out of memory\n");
22182236
exit(1);
22192237
}
22202238
}
22212239
p->z[p->n++] = (char)c;
22222240
}
@@ -2266,15 +2284,15 @@
22662284
do{ p->n--; }while( p->z[p->n]!=cQuote );
22672285
p->cTerm = c;
22682286
break;
22692287
}
22702288
if( pc==cQuote && c!='\r' ){
2271
- fprintf(stderr, "%s:%d: unescaped %c character\n",
2289
+ utf8_printf(stderr, "%s:%d: unescaped %c character\n",
22722290
p->zFile, p->nLine, cQuote);
22732291
}
22742292
if( c==EOF ){
2275
- fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
2293
+ utf8_printf(stderr, "%s:%d: unterminated %c-quoted field\n",
22762294
p->zFile, startLine, cQuote);
22772295
p->cTerm = c;
22782296
break;
22792297
}
22802298
import_append_char(p, c);
@@ -2352,19 +2370,19 @@
23522370
const int spinRate = 10000;
23532371
23542372
zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
23552373
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
23562374
if( rc ){
2357
- fprintf(stderr, "Error %d: %s on [%s]\n",
2375
+ utf8_printf(stderr, "Error %d: %s on [%s]\n",
23582376
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
23592377
zQuery);
23602378
goto end_data_xfer;
23612379
}
23622380
n = sqlite3_column_count(pQuery);
23632381
zInsert = sqlite3_malloc64(200 + nTable + n*3);
23642382
if( zInsert==0 ){
2365
- fprintf(stderr, "out of memory\n");
2383
+ raw_printf(stderr, "out of memory\n");
23662384
goto end_data_xfer;
23672385
}
23682386
sqlite3_snprintf(200+nTable,zInsert,
23692387
"INSERT OR IGNORE INTO \"%s\" VALUES(?", zTable);
23702388
i = (int)strlen(zInsert);
@@ -2373,11 +2391,11 @@
23732391
i += 2;
23742392
}
23752393
memcpy(zInsert+i, ");", 3);
23762394
rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0);
23772395
if( rc ){
2378
- fprintf(stderr, "Error %d: %s on [%s]\n",
2396
+ utf8_printf(stderr, "Error %d: %s on [%s]\n",
23792397
sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb),
23802398
zQuery);
23812399
goto end_data_xfer;
23822400
}
23832401
for(k=0; k<2; k++){
@@ -2410,11 +2428,11 @@
24102428
}
24112429
}
24122430
} /* End for */
24132431
rc = sqlite3_step(pInsert);
24142432
if( rc!=SQLITE_OK && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
2415
- fprintf(stderr, "Error %d: %s\n", sqlite3_extended_errcode(newDb),
2433
+ utf8_printf(stderr, "Error %d: %s\n", sqlite3_extended_errcode(newDb),
24162434
sqlite3_errmsg(newDb));
24172435
}
24182436
sqlite3_reset(pInsert);
24192437
cnt++;
24202438
if( (cnt%spinRate)==0 ){
@@ -2427,11 +2445,11 @@
24272445
sqlite3_free(zQuery);
24282446
zQuery = sqlite3_mprintf("SELECT * FROM \"%w\" ORDER BY rowid DESC;",
24292447
zTable);
24302448
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
24312449
if( rc ){
2432
- fprintf(stderr, "Warning: cannot step \"%s\" backwards", zTable);
2450
+ utf8_printf(stderr, "Warning: cannot step \"%s\" backwards", zTable);
24332451
break;
24342452
}
24352453
} /* End for(k=0...) */
24362454
24372455
end_data_xfer:
@@ -2463,11 +2481,11 @@
24632481
24642482
zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
24652483
" WHERE %s", zWhere);
24662484
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
24672485
if( rc ){
2468
- fprintf(stderr, "Error: (%d) %s on [%s]\n",
2486
+ utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
24692487
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
24702488
zQuery);
24712489
goto end_schema_xfer;
24722490
}
24732491
while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
@@ -2474,11 +2492,11 @@
24742492
zName = sqlite3_column_text(pQuery, 0);
24752493
zSql = sqlite3_column_text(pQuery, 1);
24762494
printf("%s... ", zName); fflush(stdout);
24772495
sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
24782496
if( zErrMsg ){
2479
- fprintf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
2497
+ utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
24802498
sqlite3_free(zErrMsg);
24812499
zErrMsg = 0;
24822500
}
24832501
if( xForEach ){
24842502
xForEach(p, newDb, (const char*)zName);
@@ -2490,11 +2508,11 @@
24902508
sqlite3_free(zQuery);
24912509
zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
24922510
" WHERE %s ORDER BY rowid DESC", zWhere);
24932511
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
24942512
if( rc ){
2495
- fprintf(stderr, "Error: (%d) %s on [%s]\n",
2513
+ utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
24962514
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
24972515
zQuery);
24982516
goto end_schema_xfer;
24992517
}
25002518
while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
@@ -2501,11 +2519,11 @@
25012519
zName = sqlite3_column_text(pQuery, 0);
25022520
zSql = sqlite3_column_text(pQuery, 1);
25032521
printf("%s... ", zName); fflush(stdout);
25042522
sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
25052523
if( zErrMsg ){
2506
- fprintf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
2524
+ utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
25072525
sqlite3_free(zErrMsg);
25082526
zErrMsg = 0;
25092527
}
25102528
if( xForEach ){
25112529
xForEach(p, newDb, (const char*)zName);
@@ -2525,16 +2543,16 @@
25252543
*/
25262544
static void tryToClone(ShellState *p, const char *zNewDb){
25272545
int rc;
25282546
sqlite3 *newDb = 0;
25292547
if( access(zNewDb,0)==0 ){
2530
- fprintf(stderr, "File \"%s\" already exists.\n", zNewDb);
2548
+ utf8_printf(stderr, "File \"%s\" already exists.\n", zNewDb);
25312549
return;
25322550
}
25332551
rc = sqlite3_open(zNewDb, &newDb);
25342552
if( rc ){
2535
- fprintf(stderr, "Cannot create output database: %s\n",
2553
+ utf8_printf(stderr, "Cannot create output database: %s\n",
25362554
sqlite3_errmsg(newDb));
25372555
}else{
25382556
sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0);
25392557
sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0);
25402558
tryToCloneSchema(p, newDb, "type='table'", tryToCloneData);
@@ -2627,31 +2645,31 @@
26272645
if( pFile==0 || pFile->pMethods==0 || pFile->pMethods->xRead==0 ){
26282646
return 1;
26292647
}
26302648
i = pFile->pMethods->xRead(pFile, aHdr, 100, 0);
26312649
if( i!=SQLITE_OK ){
2632
- fprintf(stderr, "unable to read database header\n");
2650
+ raw_printf(stderr, "unable to read database header\n");
26332651
return 1;
26342652
}
26352653
i = get2byteInt(aHdr+16);
26362654
if( i==1 ) i = 65536;
2637
- fprintf(p->out, "%-20s %d\n", "database page size:", i);
2638
- fprintf(p->out, "%-20s %d\n", "write format:", aHdr[18]);
2639
- fprintf(p->out, "%-20s %d\n", "read format:", aHdr[19]);
2640
- fprintf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]);
2655
+ utf8_printf(p->out, "%-20s %d\n", "database page size:", i);
2656
+ utf8_printf(p->out, "%-20s %d\n", "write format:", aHdr[18]);
2657
+ utf8_printf(p->out, "%-20s %d\n", "read format:", aHdr[19]);
2658
+ utf8_printf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]);
26412659
for(i=0; i<ArraySize(aField); i++){
26422660
int ofst = aField[i].ofst;
26432661
unsigned int val = get4byteInt(aHdr + ofst);
2644
- fprintf(p->out, "%-20s %u", aField[i].zName, val);
2662
+ utf8_printf(p->out, "%-20s %u", aField[i].zName, val);
26452663
switch( ofst ){
26462664
case 56: {
2647
- if( val==1 ) fprintf(p->out, " (utf8)");
2648
- if( val==2 ) fprintf(p->out, " (utf16le)");
2649
- if( val==3 ) fprintf(p->out, " (utf16be)");
2665
+ if( val==1 ) raw_printf(p->out, " (utf8)");
2666
+ if( val==2 ) raw_printf(p->out, " (utf16le)");
2667
+ if( val==3 ) raw_printf(p->out, " (utf16be)");
26502668
}
26512669
}
2652
- fprintf(p->out, "\n");
2670
+ raw_printf(p->out, "\n");
26532671
}
26542672
if( zDb==0 ){
26552673
zSchemaTab = sqlite3_mprintf("main.sqlite_master");
26562674
}else if( strcmp(zDb,"temp")==0 ){
26572675
zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_master");
@@ -2671,19 +2689,19 @@
26712689
/*
26722690
** Print the current sqlite3_errmsg() value to stderr and return 1.
26732691
*/
26742692
static int shellDatabaseError(sqlite3 *db){
26752693
const char *zErr = sqlite3_errmsg(db);
2676
- fprintf(stderr, "Error: %s\n", zErr);
2694
+ utf8_printf(stderr, "Error: %s\n", zErr);
26772695
return 1;
26782696
}
26792697
26802698
/*
26812699
** Print an out-of-memory message to stderr and return 1.
26822700
*/
26832701
static int shellNomemError(void){
2684
- fprintf(stderr, "Error: out of memory\n");
2702
+ raw_printf(stderr, "Error: out of memory\n");
26852703
return 1;
26862704
}
26872705
26882706
/*
26892707
** If an input line begins with "." then invoke this routine to
@@ -2739,57 +2757,57 @@
27392757
const char *z = azArg[j];
27402758
if( z[0]=='-' ){
27412759
while( z[0]=='-' ) z++;
27422760
/* No options to process at this time */
27432761
{
2744
- fprintf(stderr, "unknown option: %s\n", azArg[j]);
2762
+ utf8_printf(stderr, "unknown option: %s\n", azArg[j]);
27452763
return 1;
27462764
}
27472765
}else if( zDestFile==0 ){
27482766
zDestFile = azArg[j];
27492767
}else if( zDb==0 ){
27502768
zDb = zDestFile;
27512769
zDestFile = azArg[j];
27522770
}else{
2753
- fprintf(stderr, "too many arguments to .backup\n");
2771
+ raw_printf(stderr, "too many arguments to .backup\n");
27542772
return 1;
27552773
}
27562774
}
27572775
if( zDestFile==0 ){
2758
- fprintf(stderr, "missing FILENAME argument on .backup\n");
2776
+ raw_printf(stderr, "missing FILENAME argument on .backup\n");
27592777
return 1;
27602778
}
27612779
if( zDb==0 ) zDb = "main";
27622780
rc = sqlite3_open(zDestFile, &pDest);
27632781
if( rc!=SQLITE_OK ){
2764
- fprintf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
2782
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
27652783
sqlite3_close(pDest);
27662784
return 1;
27672785
}
27682786
open_db(p, 0);
27692787
pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
27702788
if( pBackup==0 ){
2771
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
2789
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
27722790
sqlite3_close(pDest);
27732791
return 1;
27742792
}
27752793
while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){}
27762794
sqlite3_backup_finish(pBackup);
27772795
if( rc==SQLITE_DONE ){
27782796
rc = 0;
27792797
}else{
2780
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
2798
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
27812799
rc = 1;
27822800
}
27832801
sqlite3_close(pDest);
27842802
}else
27852803
27862804
if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
27872805
if( nArg==2 ){
27882806
bail_on_error = booleanValue(azArg[1]);
27892807
}else{
2790
- fprintf(stderr, "Usage: .bail on|off\n");
2808
+ raw_printf(stderr, "Usage: .bail on|off\n");
27912809
rc = 1;
27922810
}
27932811
}else
27942812
27952813
if( c=='b' && n>=3 && strncmp(azArg[0], "binary", n)==0 ){
@@ -2798,11 +2816,11 @@
27982816
setBinaryMode(p->out);
27992817
}else{
28002818
setTextMode(p->out);
28012819
}
28022820
}else{
2803
- fprintf(stderr, "Usage: .binary on|off\n");
2821
+ raw_printf(stderr, "Usage: .binary on|off\n");
28042822
rc = 1;
28052823
}
28062824
}else
28072825
28082826
/* The undocumented ".breakpoint" command causes a call to the no-op
@@ -2814,20 +2832,20 @@
28142832
28152833
if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
28162834
if( nArg==2 ){
28172835
p->countChanges = booleanValue(azArg[1]);
28182836
}else{
2819
- fprintf(stderr, "Usage: .changes on|off\n");
2837
+ raw_printf(stderr, "Usage: .changes on|off\n");
28202838
rc = 1;
28212839
}
28222840
}else
28232841
28242842
if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
28252843
if( nArg==2 ){
28262844
tryToClone(p, azArg[1]);
28272845
}else{
2828
- fprintf(stderr, "Usage: .clone FILENAME\n");
2846
+ raw_printf(stderr, "Usage: .clone FILENAME\n");
28292847
rc = 1;
28302848
}
28312849
}else
28322850
28332851
if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
@@ -2841,11 +2859,11 @@
28412859
data.colWidth[1] = 15;
28422860
data.colWidth[2] = 58;
28432861
data.cnt = 0;
28442862
sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
28452863
if( zErrMsg ){
2846
- fprintf(stderr,"Error: %s\n", zErrMsg);
2864
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
28472865
sqlite3_free(zErrMsg);
28482866
rc = 1;
28492867
}
28502868
}else
28512869
@@ -2857,16 +2875,16 @@
28572875
open_db(p, 0);
28582876
/* When playing back a "dump", the content might appear in an order
28592877
** which causes immediate foreign key constraints to be violated.
28602878
** So disable foreign-key constraint enforcement to prevent problems. */
28612879
if( nArg!=1 && nArg!=2 ){
2862
- fprintf(stderr, "Usage: .dump ?LIKE-PATTERN?\n");
2880
+ raw_printf(stderr, "Usage: .dump ?LIKE-PATTERN?\n");
28632881
rc = 1;
28642882
goto meta_command_exit;
28652883
}
2866
- fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
2867
- fprintf(p->out, "BEGIN TRANSACTION;\n");
2884
+ raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
2885
+ raw_printf(p->out, "BEGIN TRANSACTION;\n");
28682886
p->writableSchema = 0;
28692887
sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
28702888
p->nErr = 0;
28712889
if( nArg==1 ){
28722890
run_schema_dump_query(p,
@@ -2897,32 +2915,32 @@
28972915
);
28982916
zShellStatic = 0;
28992917
}
29002918
}
29012919
if( p->writableSchema ){
2902
- fprintf(p->out, "PRAGMA writable_schema=OFF;\n");
2920
+ raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
29032921
p->writableSchema = 0;
29042922
}
29052923
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
29062924
sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
2907
- fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
2925
+ raw_printf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
29082926
}else
29092927
29102928
if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
29112929
if( nArg==2 ){
29122930
p->echoOn = booleanValue(azArg[1]);
29132931
}else{
2914
- fprintf(stderr, "Usage: .echo on|off\n");
2932
+ raw_printf(stderr, "Usage: .echo on|off\n");
29152933
rc = 1;
29162934
}
29172935
}else
29182936
29192937
if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
29202938
if( nArg==2 ){
29212939
p->autoEQP = booleanValue(azArg[1]);
29222940
}else{
2923
- fprintf(stderr, "Usage: .eqp on|off\n");
2941
+ raw_printf(stderr, "Usage: .eqp on|off\n");
29242942
rc = 1;
29252943
}
29262944
}else
29272945
29282946
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -2968,11 +2986,11 @@
29682986
if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
29692987
ShellState data;
29702988
char *zErrMsg = 0;
29712989
int doStats = 0;
29722990
if( nArg!=1 ){
2973
- fprintf(stderr, "Usage: .fullschema\n");
2991
+ raw_printf(stderr, "Usage: .fullschema\n");
29742992
rc = 1;
29752993
goto meta_command_exit;
29762994
}
29772995
open_db(p, 0);
29782996
memcpy(&data, p, sizeof(data));
@@ -2995,13 +3013,13 @@
29953013
-1, &pStmt, 0);
29963014
doStats = sqlite3_step(pStmt)==SQLITE_ROW;
29973015
sqlite3_finalize(pStmt);
29983016
}
29993017
if( doStats==0 ){
3000
- fprintf(p->out, "/* No STAT tables available */\n");
3018
+ raw_printf(p->out, "/* No STAT tables available */\n");
30013019
}else{
3002
- fprintf(p->out, "ANALYZE sqlite_master;\n");
3020
+ raw_printf(p->out, "ANALYZE sqlite_master;\n");
30033021
sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
30043022
callback, &data, &zErrMsg);
30053023
data.mode = MODE_Insert;
30063024
data.zDestTable = "sqlite_stat1";
30073025
shell_exec(p->db, "SELECT * FROM sqlite_stat1",
@@ -3010,25 +3028,25 @@
30103028
shell_exec(p->db, "SELECT * FROM sqlite_stat3",
30113029
shell_callback, &data,&zErrMsg);
30123030
data.zDestTable = "sqlite_stat4";
30133031
shell_exec(p->db, "SELECT * FROM sqlite_stat4",
30143032
shell_callback, &data, &zErrMsg);
3015
- fprintf(p->out, "ANALYZE sqlite_master;\n");
3033
+ raw_printf(p->out, "ANALYZE sqlite_master;\n");
30163034
}
30173035
}else
30183036
30193037
if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
30203038
if( nArg==2 ){
30213039
p->showHeader = booleanValue(azArg[1]);
30223040
}else{
3023
- fprintf(stderr, "Usage: .headers on|off\n");
3041
+ raw_printf(stderr, "Usage: .headers on|off\n");
30243042
rc = 1;
30253043
}
30263044
}else
30273045
30283046
if( c=='h' && strncmp(azArg[0], "help", n)==0 ){
3029
- fprintf(p->out, "%s", zHelp);
3047
+ utf8_printf(p->out, "%s", zHelp);
30303048
}else
30313049
30323050
if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
30333051
char *zTable; /* Insert data into this table */
30343052
char *zFile; /* Name of file to extra content from */
@@ -3042,31 +3060,32 @@
30423060
ImportCtx sCtx; /* Reader context */
30433061
char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
30443062
int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close file */
30453063
30463064
if( nArg!=3 ){
3047
- fprintf(stderr, "Usage: .import FILE TABLE\n");
3065
+ raw_printf(stderr, "Usage: .import FILE TABLE\n");
30483066
goto meta_command_exit;
30493067
}
30503068
zFile = azArg[1];
30513069
zTable = azArg[2];
30523070
seenInterrupt = 0;
30533071
memset(&sCtx, 0, sizeof(sCtx));
30543072
open_db(p, 0);
30553073
nSep = strlen30(p->colSeparator);
30563074
if( nSep==0 ){
3057
- fprintf(stderr, "Error: non-null column separator required for import\n");
3075
+ raw_printf(stderr,
3076
+ "Error: non-null column separator required for import\n");
30583077
return 1;
30593078
}
30603079
if( nSep>1 ){
3061
- fprintf(stderr, "Error: multi-character column separators not allowed"
3080
+ raw_printf(stderr, "Error: multi-character column separators not allowed"
30623081
" for import\n");
30633082
return 1;
30643083
}
30653084
nSep = strlen30(p->rowSeparator);
30663085
if( nSep==0 ){
3067
- fprintf(stderr, "Error: non-null row separator required for import\n");
3086
+ raw_printf(stderr, "Error: non-null row separator required for import\n");
30683087
return 1;
30693088
}
30703089
if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
30713090
/* When importing CSV (only), if the row separator is set to the
30723091
** default output row separator, change it to the default input
@@ -3074,19 +3093,19 @@
30743093
** and output row separators. */
30753094
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
30763095
nSep = strlen30(p->rowSeparator);
30773096
}
30783097
if( nSep>1 ){
3079
- fprintf(stderr, "Error: multi-character row separators not allowed"
3098
+ raw_printf(stderr, "Error: multi-character row separators not allowed"
30803099
" for import\n");
30813100
return 1;
30823101
}
30833102
sCtx.zFile = zFile;
30843103
sCtx.nLine = 1;
30853104
if( sCtx.zFile[0]=='|' ){
30863105
#ifdef SQLITE_OMIT_POPEN
3087
- fprintf(stderr, "Error: pipes are not supported in this OS\n");
3106
+ raw_printf(stderr, "Error: pipes are not supported in this OS\n");
30883107
return 1;
30893108
#else
30903109
sCtx.in = popen(sCtx.zFile+1, "r");
30913110
sCtx.zFile = "<pipe>";
30923111
xCloser = pclose;
@@ -3099,18 +3118,18 @@
30993118
xRead = ascii_read_one_field;
31003119
}else{
31013120
xRead = csv_read_one_field;
31023121
}
31033122
if( sCtx.in==0 ){
3104
- fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
3123
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
31053124
return 1;
31063125
}
31073126
sCtx.cColSep = p->colSeparator[0];
31083127
sCtx.cRowSep = p->rowSeparator[0];
31093128
zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
31103129
if( zSql==0 ){
3111
- fprintf(stderr, "Error: out of memory\n");
3130
+ raw_printf(stderr, "Error: out of memory\n");
31123131
xCloser(sCtx.in);
31133132
return 1;
31143133
}
31153134
nByte = strlen30(zSql);
31163135
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -3125,18 +3144,18 @@
31253144
}
31263145
if( cSep=='(' ){
31273146
sqlite3_free(zCreate);
31283147
sqlite3_free(sCtx.z);
31293148
xCloser(sCtx.in);
3130
- fprintf(stderr,"%s: empty file\n", sCtx.zFile);
3149
+ utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
31313150
return 1;
31323151
}
31333152
zCreate = sqlite3_mprintf("%z\n)", zCreate);
31343153
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
31353154
sqlite3_free(zCreate);
31363155
if( rc ){
3137
- fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
3156
+ utf8_printf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
31383157
sqlite3_errmsg(p->db));
31393158
sqlite3_free(sCtx.z);
31403159
xCloser(sCtx.in);
31413160
return 1;
31423161
}
@@ -3143,21 +3162,21 @@
31433162
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
31443163
}
31453164
sqlite3_free(zSql);
31463165
if( rc ){
31473166
if (pStmt) sqlite3_finalize(pStmt);
3148
- fprintf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
3167
+ utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
31493168
xCloser(sCtx.in);
31503169
return 1;
31513170
}
31523171
nCol = sqlite3_column_count(pStmt);
31533172
sqlite3_finalize(pStmt);
31543173
pStmt = 0;
31553174
if( nCol==0 ) return 0; /* no columns, no error */
31563175
zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
31573176
if( zSql==0 ){
3158
- fprintf(stderr, "Error: out of memory\n");
3177
+ raw_printf(stderr, "Error: out of memory\n");
31593178
xCloser(sCtx.in);
31603179
return 1;
31613180
}
31623181
sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
31633182
j = strlen30(zSql);
@@ -3168,11 +3187,11 @@
31683187
zSql[j++] = ')';
31693188
zSql[j] = 0;
31703189
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
31713190
sqlite3_free(zSql);
31723191
if( rc ){
3173
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3192
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
31743193
if (pStmt) sqlite3_finalize(pStmt);
31753194
xCloser(sCtx.in);
31763195
return 1;
31773196
}
31783197
needCommit = sqlite3_get_autocommit(p->db);
@@ -3192,11 +3211,11 @@
31923211
** the remaining columns.
31933212
*/
31943213
if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
31953214
sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
31963215
if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
3197
- fprintf(stderr, "%s:%d: expected %d columns but found %d - "
3216
+ utf8_printf(stderr, "%s:%d: expected %d columns but found %d - "
31983217
"filling the rest with NULL\n",
31993218
sCtx.zFile, startLine, nCol, i+1);
32003219
i += 2;
32013220
while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
32023221
}
@@ -3204,20 +3223,20 @@
32043223
if( sCtx.cTerm==sCtx.cColSep ){
32053224
do{
32063225
xRead(&sCtx);
32073226
i++;
32083227
}while( sCtx.cTerm==sCtx.cColSep );
3209
- fprintf(stderr, "%s:%d: expected %d columns but found %d - "
3228
+ utf8_printf(stderr, "%s:%d: expected %d columns but found %d - "
32103229
"extras ignored\n",
32113230
sCtx.zFile, startLine, nCol, i);
32123231
}
32133232
if( i>=nCol ){
32143233
sqlite3_step(pStmt);
32153234
rc = sqlite3_reset(pStmt);
32163235
if( rc!=SQLITE_OK ){
3217
- fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
3218
- sqlite3_errmsg(p->db));
3236
+ utf8_printf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile,
3237
+ startLine, sqlite3_errmsg(p->db));
32193238
}
32203239
}
32213240
}while( sCtx.cTerm!=EOF );
32223241
32233242
xCloser(sCtx.in);
@@ -3255,20 +3274,21 @@
32553274
"ORDER BY 1",
32563275
callback, &data, &zErrMsg
32573276
);
32583277
zShellStatic = 0;
32593278
}else{
3260
- fprintf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
3279
+ raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
32613280
rc = 1;
32623281
goto meta_command_exit;
32633282
}
32643283
if( zErrMsg ){
3265
- fprintf(stderr,"Error: %s\n", zErrMsg);
3284
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
32663285
sqlite3_free(zErrMsg);
32673286
rc = 1;
32683287
}else if( rc != SQLITE_OK ){
3269
- fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n");
3288
+ raw_printf(stderr,
3289
+ "Error: querying sqlite_master and sqlite_temp_master\n");
32703290
rc = 1;
32713291
}
32723292
}else
32733293
32743294
#ifdef SQLITE_ENABLE_IOTRACE
@@ -3282,11 +3302,11 @@
32823302
sqlite3IoTrace = iotracePrintf;
32833303
iotrace = stdout;
32843304
}else{
32853305
iotrace = fopen(azArg[1], "w");
32863306
if( iotrace==0 ){
3287
- fprintf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
3307
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
32883308
sqlite3IoTrace = 0;
32893309
rc = 1;
32903310
}else{
32913311
sqlite3IoTrace = iotracePrintf;
32923312
}
@@ -3317,11 +3337,11 @@
33173337
for(i=0; i<ArraySize(aLimit); i++){
33183338
printf("%20s %d\n", aLimit[i].zLimitName,
33193339
sqlite3_limit(p->db, aLimit[i].limitCode, -1));
33203340
}
33213341
}else if( nArg>3 ){
3322
- fprintf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n");
3342
+ raw_printf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n");
33233343
rc = 1;
33243344
goto meta_command_exit;
33253345
}else{
33263346
int iLimit = -1;
33273347
n2 = strlen30(azArg[1]);
@@ -3328,18 +3348,18 @@
33283348
for(i=0; i<ArraySize(aLimit); i++){
33293349
if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){
33303350
if( iLimit<0 ){
33313351
iLimit = i;
33323352
}else{
3333
- fprintf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]);
3353
+ utf8_printf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]);
33343354
rc = 1;
33353355
goto meta_command_exit;
33363356
}
33373357
}
33383358
}
33393359
if( iLimit<0 ){
3340
- fprintf(stderr, "unknown limit: \"%s\"\n"
3360
+ utf8_printf(stderr, "unknown limit: \"%s\"\n"
33413361
"enter \".limits\" with no arguments for a list.\n",
33423362
azArg[1]);
33433363
rc = 1;
33443364
goto meta_command_exit;
33453365
}
@@ -3355,29 +3375,29 @@
33553375
#ifndef SQLITE_OMIT_LOAD_EXTENSION
33563376
if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
33573377
const char *zFile, *zProc;
33583378
char *zErrMsg = 0;
33593379
if( nArg<2 ){
3360
- fprintf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
3380
+ raw_printf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
33613381
rc = 1;
33623382
goto meta_command_exit;
33633383
}
33643384
zFile = azArg[1];
33653385
zProc = nArg>=3 ? azArg[2] : 0;
33663386
open_db(p, 0);
33673387
rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
33683388
if( rc!=SQLITE_OK ){
3369
- fprintf(stderr, "Error: %s\n", zErrMsg);
3389
+ utf8_printf(stderr, "Error: %s\n", zErrMsg);
33703390
sqlite3_free(zErrMsg);
33713391
rc = 1;
33723392
}
33733393
}else
33743394
#endif
33753395
33763396
if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
33773397
if( nArg!=2 ){
3378
- fprintf(stderr, "Usage: .log FILENAME\n");
3398
+ raw_printf(stderr, "Usage: .log FILENAME\n");
33793399
rc = 1;
33803400
}else{
33813401
const char *zFile = azArg[1];
33823402
output_file_close(p->pLog);
33833403
p->pLog = output_file_open(zFile);
@@ -3412,11 +3432,11 @@
34123432
}else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
34133433
p->mode = MODE_Ascii;
34143434
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
34153435
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
34163436
}else {
3417
- fprintf(stderr,"Error: mode should be one of: "
3437
+ raw_printf(stderr, "Error: mode should be one of: "
34183438
"ascii column csv html insert line list tabs tcl\n");
34193439
rc = 1;
34203440
}
34213441
}else
34223442
@@ -3423,11 +3443,11 @@
34233443
if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
34243444
if( nArg==2 ){
34253445
sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
34263446
"%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
34273447
}else{
3428
- fprintf(stderr, "Usage: .nullvalue STRING\n");
3448
+ raw_printf(stderr, "Usage: .nullvalue STRING\n");
34293449
rc = 1;
34303450
}
34313451
}else
34323452
34333453
if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
@@ -3452,17 +3472,17 @@
34523472
if( c=='o'
34533473
&& (strncmp(azArg[0], "output", n)==0 || strncmp(azArg[0], "once", n)==0)
34543474
){
34553475
const char *zFile = nArg>=2 ? azArg[1] : "stdout";
34563476
if( nArg>2 ){
3457
- fprintf(stderr, "Usage: .%s FILE\n", azArg[0]);
3477
+ utf8_printf(stderr, "Usage: .%s FILE\n", azArg[0]);
34583478
rc = 1;
34593479
goto meta_command_exit;
34603480
}
34613481
if( n>1 && strncmp(azArg[0], "once", n)==0 ){
34623482
if( nArg<2 ){
3463
- fprintf(stderr, "Usage: .once FILE\n");
3483
+ raw_printf(stderr, "Usage: .once FILE\n");
34643484
rc = 1;
34653485
goto meta_command_exit;
34663486
}
34673487
p->outCount = 2;
34683488
}else{
@@ -3469,17 +3489,17 @@
34693489
p->outCount = 0;
34703490
}
34713491
output_reset(p);
34723492
if( zFile[0]=='|' ){
34733493
#ifdef SQLITE_OMIT_POPEN
3474
- fprintf(stderr,"Error: pipes are not supported in this OS\n");
3494
+ raw_printf(stderr, "Error: pipes are not supported in this OS\n");
34753495
rc = 1;
34763496
p->out = stdout;
34773497
#else
34783498
p->out = popen(zFile + 1, "w");
34793499
if( p->out==0 ){
3480
- fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
3500
+ utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
34813501
p->out = stdout;
34823502
rc = 1;
34833503
}else{
34843504
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
34853505
}
@@ -3486,11 +3506,11 @@
34863506
#endif
34873507
}else{
34883508
p->out = output_file_open(zFile);
34893509
if( p->out==0 ){
34903510
if( strcmp(zFile,"off")!=0 ){
3491
- fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
3511
+ utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
34923512
}
34933513
p->out = stdout;
34943514
rc = 1;
34953515
} else {
34963516
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
@@ -3499,14 +3519,14 @@
34993519
}else
35003520
35013521
if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
35023522
int i;
35033523
for(i=1; i<nArg; i++){
3504
- if( i>1 ) fprintf(p->out, " ");
3524
+ if( i>1 ) raw_printf(p->out, " ");
35053525
utf8_printf(p->out, "%s", azArg[i]);
35063526
}
3507
- fprintf(p->out, "\n");
3527
+ raw_printf(p->out, "\n");
35083528
}else
35093529
35103530
if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){
35113531
if( nArg >= 2) {
35123532
strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
@@ -3521,17 +3541,17 @@
35213541
}else
35223542
35233543
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
35243544
FILE *alt;
35253545
if( nArg!=2 ){
3526
- fprintf(stderr, "Usage: .read FILE\n");
3546
+ raw_printf(stderr, "Usage: .read FILE\n");
35273547
rc = 1;
35283548
goto meta_command_exit;
35293549
}
35303550
alt = fopen(azArg[1], "rb");
35313551
if( alt==0 ){
3532
- fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
3552
+ utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
35333553
rc = 1;
35343554
}else{
35353555
rc = process_input(p, alt);
35363556
fclose(alt);
35373557
}
@@ -3549,24 +3569,24 @@
35493569
zDb = "main";
35503570
}else if( nArg==3 ){
35513571
zSrcFile = azArg[2];
35523572
zDb = azArg[1];
35533573
}else{
3554
- fprintf(stderr, "Usage: .restore ?DB? FILE\n");
3574
+ raw_printf(stderr, "Usage: .restore ?DB? FILE\n");
35553575
rc = 1;
35563576
goto meta_command_exit;
35573577
}
35583578
rc = sqlite3_open(zSrcFile, &pSrc);
35593579
if( rc!=SQLITE_OK ){
3560
- fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
3580
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
35613581
sqlite3_close(pSrc);
35623582
return 1;
35633583
}
35643584
open_db(p, 0);
35653585
pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
35663586
if( pBackup==0 ){
3567
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3587
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
35683588
sqlite3_close(pSrc);
35693589
return 1;
35703590
}
35713591
while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK
35723592
|| rc==SQLITE_BUSY ){
@@ -3577,14 +3597,14 @@
35773597
}
35783598
sqlite3_backup_finish(pBackup);
35793599
if( rc==SQLITE_DONE ){
35803600
rc = 0;
35813601
}else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){
3582
- fprintf(stderr, "Error: source database is busy\n");
3602
+ raw_printf(stderr, "Error: source database is busy\n");
35833603
rc = 1;
35843604
}else{
3585
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3605
+ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
35863606
rc = 1;
35873607
}
35883608
sqlite3_close(pSrc);
35893609
}else
35903610
@@ -3591,14 +3611,14 @@
35913611
35923612
if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
35933613
if( nArg==2 ){
35943614
p->scanstatsOn = booleanValue(azArg[1]);
35953615
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
3596
- fprintf(stderr, "Warning: .scanstats not available in this build.\n");
3616
+ raw_printf(stderr, "Warning: .scanstats not available in this build.\n");
35973617
#endif
35983618
}else{
3599
- fprintf(stderr, "Usage: .scanstats on|off\n");
3619
+ raw_printf(stderr, "Usage: .scanstats on|off\n");
36003620
rc = 1;
36013621
}
36023622
}else
36033623
36043624
if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
@@ -3661,20 +3681,20 @@
36613681
"WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
36623682
"ORDER BY rowid",
36633683
callback, &data, &zErrMsg
36643684
);
36653685
}else{
3666
- fprintf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
3686
+ raw_printf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
36673687
rc = 1;
36683688
goto meta_command_exit;
36693689
}
36703690
if( zErrMsg ){
3671
- fprintf(stderr,"Error: %s\n", zErrMsg);
3691
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
36723692
sqlite3_free(zErrMsg);
36733693
rc = 1;
36743694
}else if( rc != SQLITE_OK ){
3675
- fprintf(stderr,"Error: querying schema information\n");
3695
+ raw_printf(stderr,"Error: querying schema information\n");
36763696
rc = 1;
36773697
}else{
36783698
rc = 0;
36793699
}
36803700
}else
@@ -3711,11 +3731,11 @@
37113731
}else
37123732
#endif
37133733
37143734
if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
37153735
if( nArg<2 || nArg>3 ){
3716
- fprintf(stderr, "Usage: .separator COL ?ROW?\n");
3736
+ raw_printf(stderr, "Usage: .separator COL ?ROW?\n");
37173737
rc = 1;
37183738
}
37193739
if( nArg>=2 ){
37203740
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator,
37213741
"%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]);
@@ -3730,11 +3750,11 @@
37303750
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
37313751
){
37323752
char *zCmd;
37333753
int i, x;
37343754
if( nArg<2 ){
3735
- fprintf(stderr, "Usage: .system COMMAND\n");
3755
+ raw_printf(stderr, "Usage: .system COMMAND\n");
37363756
rc = 1;
37373757
goto meta_command_exit;
37383758
}
37393759
zCmd = sqlite3_mprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]);
37403760
for(i=2; i<nArg; i++){
@@ -3741,49 +3761,49 @@
37413761
zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"",
37423762
zCmd, azArg[i]);
37433763
}
37443764
x = system(zCmd);
37453765
sqlite3_free(zCmd);
3746
- if( x ) fprintf(stderr, "System command returns %d\n", x);
3766
+ if( x ) raw_printf(stderr, "System command returns %d\n", x);
37473767
}else
37483768
37493769
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
37503770
int i;
37513771
if( nArg!=1 ){
3752
- fprintf(stderr, "Usage: .show\n");
3772
+ raw_printf(stderr, "Usage: .show\n");
37533773
rc = 1;
37543774
goto meta_command_exit;
37553775
}
3756
- fprintf(p->out,"%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3757
- fprintf(p->out,"%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
3758
- fprintf(p->out,"%9.9s: %s\n","explain", p->normalMode.valid ? "on" :"off");
3759
- fprintf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3760
- fprintf(p->out,"%12.12s: %s\n","mode", modeDescr[p->mode]);
3761
- fprintf(p->out,"%12.12s: ", "nullvalue");
3776
+ utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3777
+ utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
3778
+ utf8_printf(p->out,"%9.9s: %s\n","explain",p->normalMode.valid?"on":"off");
3779
+ utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3780
+ utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
3781
+ utf8_printf(p->out, "%12.12s: ", "nullvalue");
37623782
output_c_string(p->out, p->nullValue);
3763
- fprintf(p->out, "\n");
3764
- fprintf(p->out,"%12.12s: %s\n","output",
3783
+ raw_printf(p->out, "\n");
3784
+ utf8_printf(p->out,"%12.12s: %s\n","output",
37653785
strlen30(p->outfile) ? p->outfile : "stdout");
3766
- fprintf(p->out,"%12.12s: ", "colseparator");
3786
+ utf8_printf(p->out,"%12.12s: ", "colseparator");
37673787
output_c_string(p->out, p->colSeparator);
3768
- fprintf(p->out, "\n");
3769
- fprintf(p->out,"%12.12s: ", "rowseparator");
3788
+ raw_printf(p->out, "\n");
3789
+ utf8_printf(p->out,"%12.12s: ", "rowseparator");
37703790
output_c_string(p->out, p->rowSeparator);
3771
- fprintf(p->out, "\n");
3772
- fprintf(p->out,"%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
3773
- fprintf(p->out,"%12.12s: ","width");
3791
+ raw_printf(p->out, "\n");
3792
+ utf8_printf(p->out, "%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
3793
+ utf8_printf(p->out, "%12.12s: ", "width");
37743794
for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
3775
- fprintf(p->out,"%d ",p->colWidth[i]);
3795
+ raw_printf(p->out, "%d ", p->colWidth[i]);
37763796
}
3777
- fprintf(p->out,"\n");
3797
+ raw_printf(p->out, "\n");
37783798
}else
37793799
37803800
if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
37813801
if( nArg==2 ){
37823802
p->statsOn = booleanValue(azArg[1]);
37833803
}else{
3784
- fprintf(stderr, "Usage: .stats on|off\n");
3804
+ raw_printf(stderr, "Usage: .stats on|off\n");
37853805
rc = 1;
37863806
}
37873807
}else
37883808
37893809
if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
@@ -3880,11 +3900,11 @@
38803900
for(j=i; j<nRow; j+=nPrintRow){
38813901
char *zSp = j<nPrintRow ? "" : " ";
38823902
utf8_printf(p->out, "%s%-*s", zSp, maxlen,
38833903
azResult[j] ? azResult[j]:"");
38843904
}
3885
- fprintf(p->out, "\n");
3905
+ raw_printf(p->out, "\n");
38863906
}
38873907
}
38883908
38893909
for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
38903910
sqlite3_free(azResult);
@@ -3923,31 +3943,31 @@
39233943
for(i=0; i<ArraySize(aCtrl); i++){
39243944
if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){
39253945
if( testctrl<0 ){
39263946
testctrl = aCtrl[i].ctrlCode;
39273947
}else{
3928
- fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
3948
+ utf8_printf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
39293949
testctrl = -1;
39303950
break;
39313951
}
39323952
}
39333953
}
39343954
if( testctrl<0 ) testctrl = (int)integerValue(azArg[1]);
39353955
if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
3936
- fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
3956
+ utf8_printf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
39373957
}else{
39383958
switch(testctrl){
39393959
39403960
/* sqlite3_test_control(int, db, int) */
39413961
case SQLITE_TESTCTRL_OPTIMIZATIONS:
39423962
case SQLITE_TESTCTRL_RESERVE:
39433963
if( nArg==3 ){
39443964
int opt = (int)strtol(azArg[2], 0, 0);
39453965
rc2 = sqlite3_test_control(testctrl, p->db, opt);
3946
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3966
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
39473967
} else {
3948
- fprintf(stderr,"Error: testctrl %s takes a single int option\n",
3968
+ utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
39493969
azArg[1]);
39503970
}
39513971
break;
39523972
39533973
/* sqlite3_test_control(int) */
@@ -3955,24 +3975,25 @@
39553975
case SQLITE_TESTCTRL_PRNG_RESTORE:
39563976
case SQLITE_TESTCTRL_PRNG_RESET:
39573977
case SQLITE_TESTCTRL_BYTEORDER:
39583978
if( nArg==2 ){
39593979
rc2 = sqlite3_test_control(testctrl);
3960
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3980
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
39613981
} else {
3962
- fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
3982
+ utf8_printf(stderr,"Error: testctrl %s takes no options\n",
3983
+ azArg[1]);
39633984
}
39643985
break;
39653986
39663987
/* sqlite3_test_control(int, uint) */
39673988
case SQLITE_TESTCTRL_PENDING_BYTE:
39683989
if( nArg==3 ){
39693990
unsigned int opt = (unsigned int)integerValue(azArg[2]);
39703991
rc2 = sqlite3_test_control(testctrl, opt);
3971
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3992
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
39723993
} else {
3973
- fprintf(stderr,"Error: testctrl %s takes a single unsigned"
3994
+ utf8_printf(stderr,"Error: testctrl %s takes a single unsigned"
39743995
" int option\n", azArg[1]);
39753996
}
39763997
break;
39773998
39783999
/* sqlite3_test_control(int, int) */
@@ -3980,13 +4001,13 @@
39804001
case SQLITE_TESTCTRL_ALWAYS:
39814002
case SQLITE_TESTCTRL_NEVER_CORRUPT:
39824003
if( nArg==3 ){
39834004
int opt = booleanValue(azArg[2]);
39844005
rc2 = sqlite3_test_control(testctrl, opt);
3985
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
4006
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
39864007
} else {
3987
- fprintf(stderr,"Error: testctrl %s takes a single int option\n",
4008
+ utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
39884009
azArg[1]);
39894010
}
39904011
break;
39914012
39924013
/* sqlite3_test_control(int, char *) */
@@ -3993,14 +4014,15 @@
39934014
#ifdef SQLITE_N_KEYWORD
39944015
case SQLITE_TESTCTRL_ISKEYWORD:
39954016
if( nArg==3 ){
39964017
const char *opt = azArg[2];
39974018
rc2 = sqlite3_test_control(testctrl, opt);
3998
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
4019
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
39994020
} else {
4000
- fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
4001
- azArg[1]);
4021
+ utf8_printf(stderr,
4022
+ "Error: testctrl %s takes a single char * option\n",
4023
+ azArg[1]);
40024024
}
40034025
break;
40044026
#endif
40054027
40064028
case SQLITE_TESTCTRL_IMPOSTER:
@@ -4007,23 +4029,24 @@
40074029
if( nArg==5 ){
40084030
rc2 = sqlite3_test_control(testctrl, p->db,
40094031
azArg[2],
40104032
integerValue(azArg[3]),
40114033
integerValue(azArg[4]));
4012
- fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
4034
+ raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
40134035
}else{
4014
- fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
4036
+ raw_printf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
40154037
}
40164038
break;
40174039
40184040
case SQLITE_TESTCTRL_BITVEC_TEST:
40194041
case SQLITE_TESTCTRL_FAULT_INSTALL:
40204042
case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
40214043
case SQLITE_TESTCTRL_SCRATCHMALLOC:
40224044
default:
4023
- fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n",
4024
- azArg[1]);
4045
+ utf8_printf(stderr,
4046
+ "Error: CLI support for testctrl %s not implemented\n",
4047
+ azArg[1]);
40254048
break;
40264049
}
40274050
}
40284051
}else
40294052
@@ -4034,23 +4057,23 @@
40344057
40354058
if( c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 ){
40364059
if( nArg==2 ){
40374060
enableTimer = booleanValue(azArg[1]);
40384061
if( enableTimer && !HAS_TIMER ){
4039
- fprintf(stderr, "Error: timer not available on this system.\n");
4062
+ raw_printf(stderr, "Error: timer not available on this system.\n");
40404063
enableTimer = 0;
40414064
}
40424065
}else{
4043
- fprintf(stderr, "Usage: .timer on|off\n");
4066
+ raw_printf(stderr, "Usage: .timer on|off\n");
40444067
rc = 1;
40454068
}
40464069
}else
40474070
40484071
if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
40494072
open_db(p, 0);
40504073
if( nArg!=2 ){
4051
- fprintf(stderr, "Usage: .trace FILE|off\n");
4074
+ raw_printf(stderr, "Usage: .trace FILE|off\n");
40524075
rc = 1;
40534076
goto meta_command_exit;
40544077
}
40554078
output_file_close(p->traceOut);
40564079
p->traceOut = output_file_open(azArg[1]);
@@ -4064,87 +4087,87 @@
40644087
}else
40654088
40664089
#if SQLITE_USER_AUTHENTICATION
40674090
if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
40684091
if( nArg<2 ){
4069
- fprintf(stderr, "Usage: .user SUBCOMMAND ...\n");
4092
+ raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n");
40704093
rc = 1;
40714094
goto meta_command_exit;
40724095
}
40734096
open_db(p, 0);
40744097
if( strcmp(azArg[1],"login")==0 ){
40754098
if( nArg!=4 ){
4076
- fprintf(stderr, "Usage: .user login USER PASSWORD\n");
4099
+ raw_printf(stderr, "Usage: .user login USER PASSWORD\n");
40774100
rc = 1;
40784101
goto meta_command_exit;
40794102
}
40804103
rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3],
40814104
(int)strlen(azArg[3]));
40824105
if( rc ){
4083
- fprintf(stderr, "Authentication failed for user %s\n", azArg[2]);
4106
+ utf8_printf(stderr, "Authentication failed for user %s\n", azArg[2]);
40844107
rc = 1;
40854108
}
40864109
}else if( strcmp(azArg[1],"add")==0 ){
40874110
if( nArg!=5 ){
4088
- fprintf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
4111
+ raw_printf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
40894112
rc = 1;
40904113
goto meta_command_exit;
40914114
}
40924115
rc = sqlite3_user_add(p->db, azArg[2],
40934116
azArg[3], (int)strlen(azArg[3]),
40944117
booleanValue(azArg[4]));
40954118
if( rc ){
4096
- fprintf(stderr, "User-Add failed: %d\n", rc);
4119
+ raw_printf(stderr, "User-Add failed: %d\n", rc);
40974120
rc = 1;
40984121
}
40994122
}else if( strcmp(azArg[1],"edit")==0 ){
41004123
if( nArg!=5 ){
4101
- fprintf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
4124
+ raw_printf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
41024125
rc = 1;
41034126
goto meta_command_exit;
41044127
}
41054128
rc = sqlite3_user_change(p->db, azArg[2],
41064129
azArg[3], (int)strlen(azArg[3]),
41074130
booleanValue(azArg[4]));
41084131
if( rc ){
4109
- fprintf(stderr, "User-Edit failed: %d\n", rc);
4132
+ raw_printf(stderr, "User-Edit failed: %d\n", rc);
41104133
rc = 1;
41114134
}
41124135
}else if( strcmp(azArg[1],"delete")==0 ){
41134136
if( nArg!=3 ){
4114
- fprintf(stderr, "Usage: .user delete USER\n");
4137
+ raw_printf(stderr, "Usage: .user delete USER\n");
41154138
rc = 1;
41164139
goto meta_command_exit;
41174140
}
41184141
rc = sqlite3_user_delete(p->db, azArg[2]);
41194142
if( rc ){
4120
- fprintf(stderr, "User-Delete failed: %d\n", rc);
4143
+ raw_printf(stderr, "User-Delete failed: %d\n", rc);
41214144
rc = 1;
41224145
}
41234146
}else{
4124
- fprintf(stderr, "Usage: .user login|add|edit|delete ...\n");
4147
+ raw_printf(stderr, "Usage: .user login|add|edit|delete ...\n");
41254148
rc = 1;
41264149
goto meta_command_exit;
41274150
}
41284151
}else
41294152
#endif /* SQLITE_USER_AUTHENTICATION */
41304153
41314154
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
4132
- fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
4155
+ utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
41334156
sqlite3_libversion(), sqlite3_sourceid());
41344157
}else
41354158
41364159
if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
41374160
const char *zDbName = nArg==2 ? azArg[1] : "main";
41384161
sqlite3_vfs *pVfs;
41394162
if( p->db ){
41404163
sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs);
41414164
if( pVfs ){
4142
- fprintf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName);
4143
- fprintf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
4144
- fprintf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile);
4145
- fprintf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname);
4165
+ utf8_printf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName);
4166
+ raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
4167
+ raw_printf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile);
4168
+ raw_printf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname);
41464169
}
41474170
}
41484171
}else
41494172
41504173
if( c=='v' && strncmp(azArg[0], "vfsname", n)==0 ){
@@ -4151,11 +4174,11 @@
41514174
const char *zDbName = nArg==2 ? azArg[1] : "main";
41524175
char *zVfsName = 0;
41534176
if( p->db ){
41544177
sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName);
41554178
if( zVfsName ){
4156
- fprintf(p->out, "%s\n", zVfsName);
4179
+ utf8_printf(p->out, "%s\n", zVfsName);
41574180
sqlite3_free(zVfsName);
41584181
}
41594182
}
41604183
}else
41614184
@@ -4173,11 +4196,11 @@
41734196
p->colWidth[j-1] = (int)integerValue(azArg[j]);
41744197
}
41754198
}else
41764199
41774200
{
4178
- fprintf(stderr, "Error: unknown command or invalid arguments: "
4201
+ utf8_printf(stderr, "Error: unknown command or invalid arguments: "
41794202
" \"%s\". Enter \".help\" for help\n", azArg[0]);
41804203
rc = 1;
41814204
}
41824205
41834206
meta_command_exit:
@@ -4308,11 +4331,11 @@
43084331
nLine = strlen30(zLine);
43094332
if( nSql+nLine+2>=nAlloc ){
43104333
nAlloc = nSql+nLine+100;
43114334
zSql = realloc(zSql, nAlloc);
43124335
if( zSql==0 ){
4313
- fprintf(stderr, "Error: out of memory\n");
4336
+ raw_printf(stderr, "Error: out of memory\n");
43144337
exit(1);
43154338
}
43164339
}
43174340
nSqlPrior = nSql;
43184341
if( nSql==0 ){
@@ -4342,19 +4365,19 @@
43424365
"Error: near line %d:", startline);
43434366
}else{
43444367
sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
43454368
}
43464369
if( zErrMsg!=0 ){
4347
- fprintf(stderr, "%s %s\n", zPrefix, zErrMsg);
4370
+ utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
43484371
sqlite3_free(zErrMsg);
43494372
zErrMsg = 0;
43504373
}else{
4351
- fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
4374
+ utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
43524375
}
43534376
errCnt++;
43544377
}else if( p->countChanges ){
4355
- fprintf(p->out, "changes: %3d total_changes: %d\n",
4378
+ raw_printf(p->out, "changes: %3d total_changes: %d\n",
43564379
sqlite3_changes(p->db), sqlite3_total_changes(p->db));
43574380
}
43584381
nSql = 0;
43594382
if( p->outCount ){
43604383
output_reset(p);
@@ -4365,11 +4388,11 @@
43654388
nSql = 0;
43664389
}
43674390
}
43684391
if( nSql ){
43694392
if( !_all_whitespace(zSql) ){
4370
- fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
4393
+ utf8_printf(stderr, "Error: incomplete SQL: %s\n", zSql);
43714394
errCnt++;
43724395
}
43734396
}
43744397
free(zSql);
43754398
free(zLine);
@@ -4456,11 +4479,11 @@
44564479
FILE *in = NULL;
44574480
44584481
if (sqliterc == NULL) {
44594482
home_dir = find_home_dir();
44604483
if( home_dir==0 ){
4461
- fprintf(stderr, "-- warning: cannot find home directory;"
4484
+ raw_printf(stderr, "-- warning: cannot find home directory;"
44624485
" cannot read ~/.sqliterc\n");
44634486
return;
44644487
}
44654488
sqlite3_initialize();
44664489
zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
@@ -4467,11 +4490,11 @@
44674490
sqliterc = zBuf;
44684491
}
44694492
in = fopen(sqliterc,"rb");
44704493
if( in ){
44714494
if( stdin_is_interactive ){
4472
- fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
4495
+ utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc);
44734496
}
44744497
process_input(p,in);
44754498
fclose(in);
44764499
}
44774500
sqlite3_free(zBuf);
@@ -4514,18 +4537,18 @@
45144537
#ifdef SQLITE_ENABLE_VFSTRACE
45154538
" -vfstrace enable tracing of all VFS calls\n"
45164539
#endif
45174540
;
45184541
static void usage(int showDetail){
4519
- fprintf(stderr,
4542
+ utf8_printf(stderr,
45204543
"Usage: %s [OPTIONS] FILENAME [SQL]\n"
45214544
"FILENAME is the name of an SQLite database. A new database is created\n"
45224545
"if the file does not previously exist.\n", Argv0);
45234546
if( showDetail ){
4524
- fprintf(stderr, "OPTIONS include:\n%s", zOptions);
4547
+ utf8_printf(stderr, "OPTIONS include:\n%s", zOptions);
45254548
}else{
4526
- fprintf(stderr, "Use the -help option for additional information\n");
4549
+ raw_printf(stderr, "Use the -help option for additional information\n");
45274550
}
45284551
exit(1);
45294552
}
45304553
45314554
/*
@@ -4569,11 +4592,11 @@
45694592
** Get the argument to an --option. Throw an error and die if no argument
45704593
** is available.
45714594
*/
45724595
static char *cmdline_option_value(int argc, char **argv, int i){
45734596
if( i==argc ){
4574
- fprintf(stderr, "%s: Error: missing argument to %s\n",
4597
+ utf8_printf(stderr, "%s: Error: missing argument to %s\n",
45754598
argv[0], argv[argc-1]);
45764599
exit(1);
45774600
}
45784601
return argv[i];
45794602
}
@@ -4589,11 +4612,11 @@
45894612
int nCmd = 0;
45904613
char **azCmd = 0;
45914614
45924615
#if USE_SYSTEM_SQLITE+0!=1
45934616
if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
4594
- fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
4617
+ utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
45954618
sqlite3_sourceid(), SQLITE_SOURCE_ID);
45964619
exit(1);
45974620
}
45984621
#endif
45994622
setBinaryMode(stdin);
@@ -4638,11 +4661,11 @@
46384661
** mean that nothing is read from stdin */
46394662
readStdin = 0;
46404663
nCmd++;
46414664
azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
46424665
if( azCmd==0 ){
4643
- fprintf(stderr, "out of memory\n");
4666
+ raw_printf(stderr, "out of memory\n");
46444667
exit(1);
46454668
}
46464669
azCmd[nCmd-1] = z;
46474670
}
46484671
}
@@ -4720,21 +4743,21 @@
47204743
}else if( strcmp(z,"-vfs")==0 ){
47214744
sqlite3_vfs *pVfs = sqlite3_vfs_find(cmdline_option_value(argc,argv,++i));
47224745
if( pVfs ){
47234746
sqlite3_vfs_register(pVfs, 1);
47244747
}else{
4725
- fprintf(stderr, "no such VFS: \"%s\"\n", argv[i]);
4748
+ utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
47264749
exit(1);
47274750
}
47284751
}
47294752
}
47304753
if( data.zDbFilename==0 ){
47314754
#ifndef SQLITE_OMIT_MEMORYDB
47324755
data.zDbFilename = ":memory:";
47334756
warnInmemoryDb = argc==1;
47344757
#else
4735
- fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
4758
+ utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
47364759
return 1;
47374760
#endif
47384761
}
47394762
data.out = stdout;
47404763
@@ -4852,20 +4875,20 @@
48524875
if( rc && bail_on_error ) return rc==2 ? 0 : rc;
48534876
}else{
48544877
open_db(&data, 0);
48554878
rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
48564879
if( zErrMsg!=0 ){
4857
- fprintf(stderr,"Error: %s\n", zErrMsg);
4880
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
48584881
if( bail_on_error ) return rc!=0 ? rc : 1;
48594882
}else if( rc!=0 ){
4860
- fprintf(stderr,"Error: unable to process SQL \"%s\"\n", z);
4883
+ utf8_printf(stderr,"Error: unable to process SQL \"%s\"\n", z);
48614884
if( bail_on_error ) return rc;
48624885
}
48634886
}
48644887
}else{
4865
- fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
4866
- fprintf(stderr,"Use -help for a list of options.\n");
4888
+ utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
4889
+ raw_printf(stderr,"Use -help for a list of options.\n");
48674890
return 1;
48684891
}
48694892
}
48704893
48714894
if( !readStdin ){
@@ -4879,14 +4902,14 @@
48794902
if( rc ) return rc==2 ? 0 : rc;
48804903
}else{
48814904
open_db(&data, 0);
48824905
rc = shell_exec(data.db, azCmd[i], shell_callback, &data, &zErrMsg);
48834906
if( zErrMsg!=0 ){
4884
- fprintf(stderr,"Error: %s\n", zErrMsg);
4907
+ utf8_printf(stderr,"Error: %s\n", zErrMsg);
48854908
return rc!=0 ? rc : 1;
48864909
}else if( rc!=0 ){
4887
- fprintf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
4910
+ utf8_printf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
48884911
return rc;
48894912
}
48904913
}
48914914
}
48924915
free(azCmd);
48934916
--- src/shell.c
+++ src/shell.c
@@ -546,11 +546,11 @@
546 */
547 #if defined(_WIN32) || defined(WIN32)
548 void utf8_printf(FILE *out, const char *zFormat, ...){
549 va_list ap;
550 va_start(ap, zFormat);
551 if( stdout_is_console && out==stdout ){
552 extern char *sqlite3_win32_utf8_to_mbcs(const char*);
553 char *z1 = sqlite3_vmprintf(zFormat, ap);
554 char *z2 = sqlite3_win32_utf8_to_mbcs(z1);
555 sqlite3_free(z1);
556 fputs(z2, out);
@@ -558,14 +558,22 @@
558 }else{
559 vfprintf(out, zFormat, ap);
560 }
561 va_end(ap);
562 }
563 #else
564 # define utf8_printf fprintf
565 #endif
566
 
 
 
 
 
 
 
 
567 /*
568 ** Shell output mode information from before ".explain on",
569 ** saved so that it can be restored by ".explain off"
570 */
571 typedef struct SavedModeInfo SavedModeInfo;
@@ -673,23 +681,23 @@
673 ** A callback for the sqlite3_log() interface.
674 */
675 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
676 ShellState *p = (ShellState*)pArg;
677 if( p->pLog==0 ) return;
678 fprintf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
679 fflush(p->pLog);
680 }
681
682 /*
683 ** Output the given string as a hex-encoded blob (eg. X'1234' )
684 */
685 static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
686 int i;
687 char *zBlob = (char *)pBlob;
688 fprintf(out,"X'");
689 for(i=0; i<nBlob; i++){ fprintf(out,"%02x",zBlob[i]&0xff); }
690 fprintf(out,"'");
691 }
692
693 /*
694 ** Output the given string as a quoted string using SQL quoting conventions.
695 */
@@ -701,25 +709,25 @@
701 if( z[i]=='\'' ) nSingle++;
702 }
703 if( nSingle==0 ){
704 utf8_printf(out,"'%s'",z);
705 }else{
706 fprintf(out,"'");
707 while( *z ){
708 for(i=0; z[i] && z[i]!='\''; i++){}
709 if( i==0 ){
710 fprintf(out,"''");
711 z++;
712 }else if( z[i]=='\'' ){
713 utf8_printf(out,"%.*s''",i,z);
714 z += i+1;
715 }else{
716 utf8_printf(out,"%s",z);
717 break;
718 }
719 }
720 fprintf(out,"'");
721 }
722 setTextMode(out);
723 }
724
725 /*
@@ -743,11 +751,11 @@
743 fputc('n', out);
744 }else if( c=='\r' ){
745 fputc('\\', out);
746 fputc('r', out);
747 }else if( !isprint(c&0xff) ){
748 fprintf(out, "\\%03o", c&0xff);
749 }else{
750 fputc(c, out);
751 }
752 }
753 fputc('"', out);
@@ -770,19 +778,19 @@
770 i++){}
771 if( i>0 ){
772 utf8_printf(out,"%.*s",i,z);
773 }
774 if( z[i]=='<' ){
775 fprintf(out,"&lt;");
776 }else if( z[i]=='&' ){
777 fprintf(out,"&amp;");
778 }else if( z[i]=='>' ){
779 fprintf(out,"&gt;");
780 }else if( z[i]=='\"' ){
781 fprintf(out,"&quot;");
782 }else if( z[i]=='\'' ){
783 fprintf(out,"&#39;");
784 }else{
785 break;
786 }
787 z += i + 1;
788 }
@@ -925,11 +933,11 @@
925 w = p->actualWidth[i];
926 if( w<0 ) w = -w;
927 }else{
928 w = 10;
929 }
930 fprintf(p->out,"%-*.*s%s",w,w,
931 "----------------------------------------------------------"
932 "----------------------------------------------------------",
933 i==nArg-1 ? p->rowSeparator : " ");
934 }
935 }
@@ -945,11 +953,11 @@
945 if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
946 w = strlen30(azArg[i]);
947 }
948 if( i==1 && p->aiIndent && p->pStmt ){
949 if( p->iIndent<p->nIndent ){
950 fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
951 }
952 p->iIndent++;
953 }
954 if( w<0 ){
955 utf8_printf(p->out,"%*.*s%s",-w,-w,
@@ -986,26 +994,26 @@
986 }
987 break;
988 }
989 case MODE_Html: {
990 if( p->cnt++==0 && p->showHeader ){
991 fprintf(p->out,"<TR>");
992 for(i=0; i<nArg; i++){
993 fprintf(p->out,"<TH>");
994 output_html_string(p->out, azCol[i]);
995 fprintf(p->out,"</TH>\n");
996 }
997 fprintf(p->out,"</TR>\n");
998 }
999 if( azArg==0 ) break;
1000 fprintf(p->out,"<TR>");
1001 for(i=0; i<nArg; i++){
1002 fprintf(p->out,"<TD>");
1003 output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
1004 fprintf(p->out,"</TD>\n");
1005 }
1006 fprintf(p->out,"</TR>\n");
1007 break;
1008 }
1009 case MODE_Tcl: {
1010 if( p->cnt++==0 && p->showHeader ){
1011 for(i=0; i<nArg; i++){
@@ -1042,41 +1050,41 @@
1042 case MODE_Insert: {
1043 p->cnt++;
1044 if( azArg==0 ) break;
1045 utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
1046 if( p->showHeader ){
1047 fprintf(p->out,"(");
1048 for(i=0; i<nArg; i++){
1049 char *zSep = i>0 ? ",": "";
1050 utf8_printf(p->out, "%s%s", zSep, azCol[i]);
1051 }
1052 fprintf(p->out,")");
1053 }
1054 fprintf(p->out," VALUES(");
1055 for(i=0; i<nArg; i++){
1056 char *zSep = i>0 ? ",": "";
1057 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
1058 fprintf(p->out,"%sNULL",zSep);
1059 }else if( aiType && aiType[i]==SQLITE_TEXT ){
1060 if( zSep[0] ) fprintf(p->out,"%s",zSep);
1061 output_quoted_string(p->out, azArg[i]);
1062 }else if( aiType && (aiType[i]==SQLITE_INTEGER
1063 || aiType[i]==SQLITE_FLOAT) ){
1064 utf8_printf(p->out,"%s%s",zSep, azArg[i]);
1065 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
1066 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
1067 int nBlob = sqlite3_column_bytes(p->pStmt, i);
1068 if( zSep[0] ) fprintf(p->out,"%s",zSep);
1069 output_hex_blob(p->out, pBlob, nBlob);
1070 }else if( isNumber(azArg[i], 0) ){
1071 utf8_printf(p->out,"%s%s",zSep, azArg[i]);
1072 }else{
1073 if( zSep[0] ) fprintf(p->out,"%s",zSep);
1074 output_quoted_string(p->out, azArg[i]);
1075 }
1076 }
1077 fprintf(p->out,");\n");
1078 break;
1079 }
1080 case MODE_Ascii: {
1081 if( p->cnt++==0 && p->showHeader ){
1082 for(i=0; i<nArg; i++){
@@ -1129,11 +1137,11 @@
1129 }
1130 }
1131 if( needQuote ) n += 2;
1132 z = p->zDestTable = malloc( n+1 );
1133 if( z==0 ){
1134 fprintf(stderr,"Error: out of memory\n");
1135 exit(1);
1136 }
1137 n = 0;
1138 if( needQuote ) z[n++] = '\'';
1139 for(i=0; zName[i]; i++){
@@ -1210,11 +1218,12 @@
1210 int nResult;
1211 int i;
1212 const char *z;
1213 rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
1214 if( rc!=SQLITE_OK || !pSelect ){
1215 fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
 
1216 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
1217 return rc;
1218 }
1219 rc = sqlite3_step(pSelect);
1220 nResult = sqlite3_column_count(pSelect);
@@ -1229,19 +1238,20 @@
1229 utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
1230 }
1231 if( z==0 ) z = "";
1232 while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
1233 if( z[0] ){
1234 fprintf(p->out, "\n;\n");
1235 }else{
1236 fprintf(p->out, ";\n");
1237 }
1238 rc = sqlite3_step(pSelect);
1239 }
1240 rc = sqlite3_finalize(pSelect);
1241 if( rc!=SQLITE_OK ){
1242 fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
 
1243 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
1244 }
1245 return rc;
1246 }
1247
@@ -1272,107 +1282,115 @@
1272
1273 if( pArg && pArg->out ){
1274
1275 iHiwtr = iCur = -1;
1276 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
1277 fprintf(pArg->out,
1278 "Memory Used: %d (max %d) bytes\n",
1279 iCur, iHiwtr);
1280 iHiwtr = iCur = -1;
1281 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
1282 fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
1283 iCur, iHiwtr);
1284 if( pArg->shellFlgs & SHFLG_Pagecache ){
1285 iHiwtr = iCur = -1;
1286 sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
1287 fprintf(pArg->out,
1288 "Number of Pcache Pages Used: %d (max %d) pages\n",
1289 iCur, iHiwtr);
1290 }
1291 iHiwtr = iCur = -1;
1292 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
1293 fprintf(pArg->out,
1294 "Number of Pcache Overflow Bytes: %d (max %d) bytes\n",
1295 iCur, iHiwtr);
1296 if( pArg->shellFlgs & SHFLG_Scratch ){
1297 iHiwtr = iCur = -1;
1298 sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
1299 fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n",
 
1300 iCur, iHiwtr);
1301 }
1302 iHiwtr = iCur = -1;
1303 sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
1304 fprintf(pArg->out,
1305 "Number of Scratch Overflow Bytes: %d (max %d) bytes\n",
1306 iCur, iHiwtr);
1307 iHiwtr = iCur = -1;
1308 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
1309 fprintf(pArg->out, "Largest Allocation: %d bytes\n",
1310 iHiwtr);
1311 iHiwtr = iCur = -1;
1312 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
1313 fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
1314 iHiwtr);
1315 iHiwtr = iCur = -1;
1316 sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
1317 fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
1318 iHiwtr);
1319 #ifdef YYTRACKMAXSTACKDEPTH
1320 iHiwtr = iCur = -1;
1321 sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
1322 fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
1323 iCur, iHiwtr);
1324 #endif
1325 }
1326
1327 if( pArg && pArg->out && db ){
1328 if( pArg->shellFlgs & SHFLG_Lookaside ){
1329 iHiwtr = iCur = -1;
1330 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED,
1331 &iCur, &iHiwtr, bReset);
1332 fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n",
 
1333 iCur, iHiwtr);
1334 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT,
1335 &iCur, &iHiwtr, bReset);
1336 fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr);
 
1337 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE,
1338 &iCur, &iHiwtr, bReset);
1339 fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr);
 
1340 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL,
1341 &iCur, &iHiwtr, bReset);
1342 fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr);
 
1343 }
1344 iHiwtr = iCur = -1;
1345 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
1346 fprintf(pArg->out, "Pager Heap Usage: %d bytes\n",iCur);
 
1347 iHiwtr = iCur = -1;
1348 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
1349 fprintf(pArg->out, "Page cache hits: %d\n", iCur);
1350 iHiwtr = iCur = -1;
1351 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
1352 fprintf(pArg->out, "Page cache misses: %d\n", iCur);
1353 iHiwtr = iCur = -1;
1354 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
1355 fprintf(pArg->out, "Page cache writes: %d\n", iCur);
1356 iHiwtr = iCur = -1;
1357 sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1358 fprintf(pArg->out, "Schema Heap Usage: %d bytes\n",iCur);
 
1359 iHiwtr = iCur = -1;
1360 sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
1361 fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",iCur);
 
1362 }
1363
1364 if( pArg && pArg->out && db && pArg->pStmt ){
1365 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP,
1366 bReset);
1367 fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1368 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1369 fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1370 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
1371 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1372 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1373 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1374 }
1375
1376 /* Do not remove this machine readable comment: extra-stats-output-here */
1377
1378 return 0;
@@ -1388,11 +1406,11 @@
1388 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
1389 UNUSED_PARAMETER(db);
1390 UNUSED_PARAMETER(pArg);
1391 #else
1392 int i, k, n, mx;
1393 fprintf(pArg->out, "-------- scanstats --------\n");
1394 mx = 0;
1395 for(k=0; k<=mx; k++){
1396 double rEstLoop = 1.0;
1397 for(i=n=0; 1; i++){
1398 sqlite3_stmt *p = pArg->pStmt;
@@ -1406,25 +1424,25 @@
1406 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_SELECTID, (void*)&iSid);
1407 if( iSid>mx ) mx = iSid;
1408 if( iSid!=k ) continue;
1409 if( n==0 ){
1410 rEstLoop = (double)nLoop;
1411 if( k>0 ) fprintf(pArg->out, "-------- subquery %d -------\n", k);
1412 }
1413 n++;
1414 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
1415 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
1416 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
1417 utf8_printf(pArg->out, "Loop %2d: %s\n", n, zExplain);
1418 rEstLoop *= rEst;
1419 fprintf(pArg->out,
1420 " nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
1421 nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
1422 );
1423 }
1424 }
1425 fprintf(pArg->out, "---------------------------\n");
1426 #endif
1427 }
1428
1429 /*
1430 ** Parameter azArray points to a zero-terminated array of strings. zStr
@@ -1584,13 +1602,13 @@
1584 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1585 sqlite3_sql(pStmt));
1586 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1587 if( rc==SQLITE_OK ){
1588 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1589 fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1590 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
1591 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
1592 utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1593 }
1594 }
1595 sqlite3_finalize(pExplain);
1596 sqlite3_free(zEQP);
@@ -1715,17 +1733,17 @@
1715 zSql = azArg[2];
1716
1717 if( strcmp(zTable, "sqlite_sequence")==0 ){
1718 zPrepStmt = "DELETE FROM sqlite_sequence;\n";
1719 }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 ){
1720 fprintf(p->out, "ANALYZE sqlite_master;\n");
1721 }else if( strncmp(zTable, "sqlite_", 7)==0 ){
1722 return 0;
1723 }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
1724 char *zIns;
1725 if( !p->writableSchema ){
1726 fprintf(p->out, "PRAGMA writable_schema=ON;\n");
1727 p->writableSchema = 1;
1728 }
1729 zIns = sqlite3_mprintf(
1730 "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
1731 "VALUES('table','%q','%q',0,'%q');",
@@ -1809,22 +1827,22 @@
1809 char *zErr = 0;
1810 rc = sqlite3_exec(p->db, zQuery, dump_callback, p, &zErr);
1811 if( rc==SQLITE_CORRUPT ){
1812 char *zQ2;
1813 int len = strlen30(zQuery);
1814 fprintf(p->out, "/****** CORRUPTION ERROR *******/\n");
1815 if( zErr ){
1816 fprintf(p->out, "/****** %s ******/\n", zErr);
1817 sqlite3_free(zErr);
1818 zErr = 0;
1819 }
1820 zQ2 = malloc( len+100 );
1821 if( zQ2==0 ) return rc;
1822 sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery);
1823 rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr);
1824 if( rc ){
1825 fprintf(p->out, "/****** ERROR: %s ******/\n", zErr);
1826 }else{
1827 rc = SQLITE_CORRUPT;
1828 }
1829 sqlite3_free(zErr);
1830 free(zQ2);
@@ -1985,11 +2003,11 @@
1985 if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
1986 sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
1987 shellstaticFunc, 0, 0);
1988 }
1989 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
1990 fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
1991 p->zDbFilename, sqlite3_errmsg(p->db));
1992 if( keepAlive ) return;
1993 exit(1);
1994 }
1995 #ifndef SQLITE_OMIT_LOAD_EXTENSION
@@ -2135,11 +2153,11 @@
2135 return 1;
2136 }
2137 if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){
2138 return 0;
2139 }
2140 fprintf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
2141 zArg);
2142 return 0;
2143 }
2144
2145 /*
@@ -2163,11 +2181,11 @@
2163 }else if( strcmp(zFile, "off")==0 ){
2164 f = 0;
2165 }else{
2166 f = fopen(zFile, "wb");
2167 if( f==0 ){
2168 fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
2169 }
2170 }
2171 return f;
2172 }
2173
@@ -2212,11 +2230,11 @@
2212 static void import_append_char(ImportCtx *p, int c){
2213 if( p->n+1>=p->nAlloc ){
2214 p->nAlloc += p->nAlloc + 100;
2215 p->z = sqlite3_realloc64(p->z, p->nAlloc);
2216 if( p->z==0 ){
2217 fprintf(stderr, "out of memory\n");
2218 exit(1);
2219 }
2220 }
2221 p->z[p->n++] = (char)c;
2222 }
@@ -2266,15 +2284,15 @@
2266 do{ p->n--; }while( p->z[p->n]!=cQuote );
2267 p->cTerm = c;
2268 break;
2269 }
2270 if( pc==cQuote && c!='\r' ){
2271 fprintf(stderr, "%s:%d: unescaped %c character\n",
2272 p->zFile, p->nLine, cQuote);
2273 }
2274 if( c==EOF ){
2275 fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
2276 p->zFile, startLine, cQuote);
2277 p->cTerm = c;
2278 break;
2279 }
2280 import_append_char(p, c);
@@ -2352,19 +2370,19 @@
2352 const int spinRate = 10000;
2353
2354 zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
2355 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
2356 if( rc ){
2357 fprintf(stderr, "Error %d: %s on [%s]\n",
2358 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2359 zQuery);
2360 goto end_data_xfer;
2361 }
2362 n = sqlite3_column_count(pQuery);
2363 zInsert = sqlite3_malloc64(200 + nTable + n*3);
2364 if( zInsert==0 ){
2365 fprintf(stderr, "out of memory\n");
2366 goto end_data_xfer;
2367 }
2368 sqlite3_snprintf(200+nTable,zInsert,
2369 "INSERT OR IGNORE INTO \"%s\" VALUES(?", zTable);
2370 i = (int)strlen(zInsert);
@@ -2373,11 +2391,11 @@
2373 i += 2;
2374 }
2375 memcpy(zInsert+i, ");", 3);
2376 rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0);
2377 if( rc ){
2378 fprintf(stderr, "Error %d: %s on [%s]\n",
2379 sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb),
2380 zQuery);
2381 goto end_data_xfer;
2382 }
2383 for(k=0; k<2; k++){
@@ -2410,11 +2428,11 @@
2410 }
2411 }
2412 } /* End for */
2413 rc = sqlite3_step(pInsert);
2414 if( rc!=SQLITE_OK && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
2415 fprintf(stderr, "Error %d: %s\n", sqlite3_extended_errcode(newDb),
2416 sqlite3_errmsg(newDb));
2417 }
2418 sqlite3_reset(pInsert);
2419 cnt++;
2420 if( (cnt%spinRate)==0 ){
@@ -2427,11 +2445,11 @@
2427 sqlite3_free(zQuery);
2428 zQuery = sqlite3_mprintf("SELECT * FROM \"%w\" ORDER BY rowid DESC;",
2429 zTable);
2430 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
2431 if( rc ){
2432 fprintf(stderr, "Warning: cannot step \"%s\" backwards", zTable);
2433 break;
2434 }
2435 } /* End for(k=0...) */
2436
2437 end_data_xfer:
@@ -2463,11 +2481,11 @@
2463
2464 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
2465 " WHERE %s", zWhere);
2466 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
2467 if( rc ){
2468 fprintf(stderr, "Error: (%d) %s on [%s]\n",
2469 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2470 zQuery);
2471 goto end_schema_xfer;
2472 }
2473 while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
@@ -2474,11 +2492,11 @@
2474 zName = sqlite3_column_text(pQuery, 0);
2475 zSql = sqlite3_column_text(pQuery, 1);
2476 printf("%s... ", zName); fflush(stdout);
2477 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
2478 if( zErrMsg ){
2479 fprintf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
2480 sqlite3_free(zErrMsg);
2481 zErrMsg = 0;
2482 }
2483 if( xForEach ){
2484 xForEach(p, newDb, (const char*)zName);
@@ -2490,11 +2508,11 @@
2490 sqlite3_free(zQuery);
2491 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
2492 " WHERE %s ORDER BY rowid DESC", zWhere);
2493 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
2494 if( rc ){
2495 fprintf(stderr, "Error: (%d) %s on [%s]\n",
2496 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2497 zQuery);
2498 goto end_schema_xfer;
2499 }
2500 while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
@@ -2501,11 +2519,11 @@
2501 zName = sqlite3_column_text(pQuery, 0);
2502 zSql = sqlite3_column_text(pQuery, 1);
2503 printf("%s... ", zName); fflush(stdout);
2504 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
2505 if( zErrMsg ){
2506 fprintf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
2507 sqlite3_free(zErrMsg);
2508 zErrMsg = 0;
2509 }
2510 if( xForEach ){
2511 xForEach(p, newDb, (const char*)zName);
@@ -2525,16 +2543,16 @@
2525 */
2526 static void tryToClone(ShellState *p, const char *zNewDb){
2527 int rc;
2528 sqlite3 *newDb = 0;
2529 if( access(zNewDb,0)==0 ){
2530 fprintf(stderr, "File \"%s\" already exists.\n", zNewDb);
2531 return;
2532 }
2533 rc = sqlite3_open(zNewDb, &newDb);
2534 if( rc ){
2535 fprintf(stderr, "Cannot create output database: %s\n",
2536 sqlite3_errmsg(newDb));
2537 }else{
2538 sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0);
2539 sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0);
2540 tryToCloneSchema(p, newDb, "type='table'", tryToCloneData);
@@ -2627,31 +2645,31 @@
2627 if( pFile==0 || pFile->pMethods==0 || pFile->pMethods->xRead==0 ){
2628 return 1;
2629 }
2630 i = pFile->pMethods->xRead(pFile, aHdr, 100, 0);
2631 if( i!=SQLITE_OK ){
2632 fprintf(stderr, "unable to read database header\n");
2633 return 1;
2634 }
2635 i = get2byteInt(aHdr+16);
2636 if( i==1 ) i = 65536;
2637 fprintf(p->out, "%-20s %d\n", "database page size:", i);
2638 fprintf(p->out, "%-20s %d\n", "write format:", aHdr[18]);
2639 fprintf(p->out, "%-20s %d\n", "read format:", aHdr[19]);
2640 fprintf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]);
2641 for(i=0; i<ArraySize(aField); i++){
2642 int ofst = aField[i].ofst;
2643 unsigned int val = get4byteInt(aHdr + ofst);
2644 fprintf(p->out, "%-20s %u", aField[i].zName, val);
2645 switch( ofst ){
2646 case 56: {
2647 if( val==1 ) fprintf(p->out, " (utf8)");
2648 if( val==2 ) fprintf(p->out, " (utf16le)");
2649 if( val==3 ) fprintf(p->out, " (utf16be)");
2650 }
2651 }
2652 fprintf(p->out, "\n");
2653 }
2654 if( zDb==0 ){
2655 zSchemaTab = sqlite3_mprintf("main.sqlite_master");
2656 }else if( strcmp(zDb,"temp")==0 ){
2657 zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_master");
@@ -2671,19 +2689,19 @@
2671 /*
2672 ** Print the current sqlite3_errmsg() value to stderr and return 1.
2673 */
2674 static int shellDatabaseError(sqlite3 *db){
2675 const char *zErr = sqlite3_errmsg(db);
2676 fprintf(stderr, "Error: %s\n", zErr);
2677 return 1;
2678 }
2679
2680 /*
2681 ** Print an out-of-memory message to stderr and return 1.
2682 */
2683 static int shellNomemError(void){
2684 fprintf(stderr, "Error: out of memory\n");
2685 return 1;
2686 }
2687
2688 /*
2689 ** If an input line begins with "." then invoke this routine to
@@ -2739,57 +2757,57 @@
2739 const char *z = azArg[j];
2740 if( z[0]=='-' ){
2741 while( z[0]=='-' ) z++;
2742 /* No options to process at this time */
2743 {
2744 fprintf(stderr, "unknown option: %s\n", azArg[j]);
2745 return 1;
2746 }
2747 }else if( zDestFile==0 ){
2748 zDestFile = azArg[j];
2749 }else if( zDb==0 ){
2750 zDb = zDestFile;
2751 zDestFile = azArg[j];
2752 }else{
2753 fprintf(stderr, "too many arguments to .backup\n");
2754 return 1;
2755 }
2756 }
2757 if( zDestFile==0 ){
2758 fprintf(stderr, "missing FILENAME argument on .backup\n");
2759 return 1;
2760 }
2761 if( zDb==0 ) zDb = "main";
2762 rc = sqlite3_open(zDestFile, &pDest);
2763 if( rc!=SQLITE_OK ){
2764 fprintf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
2765 sqlite3_close(pDest);
2766 return 1;
2767 }
2768 open_db(p, 0);
2769 pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
2770 if( pBackup==0 ){
2771 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
2772 sqlite3_close(pDest);
2773 return 1;
2774 }
2775 while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){}
2776 sqlite3_backup_finish(pBackup);
2777 if( rc==SQLITE_DONE ){
2778 rc = 0;
2779 }else{
2780 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
2781 rc = 1;
2782 }
2783 sqlite3_close(pDest);
2784 }else
2785
2786 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
2787 if( nArg==2 ){
2788 bail_on_error = booleanValue(azArg[1]);
2789 }else{
2790 fprintf(stderr, "Usage: .bail on|off\n");
2791 rc = 1;
2792 }
2793 }else
2794
2795 if( c=='b' && n>=3 && strncmp(azArg[0], "binary", n)==0 ){
@@ -2798,11 +2816,11 @@
2798 setBinaryMode(p->out);
2799 }else{
2800 setTextMode(p->out);
2801 }
2802 }else{
2803 fprintf(stderr, "Usage: .binary on|off\n");
2804 rc = 1;
2805 }
2806 }else
2807
2808 /* The undocumented ".breakpoint" command causes a call to the no-op
@@ -2814,20 +2832,20 @@
2814
2815 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
2816 if( nArg==2 ){
2817 p->countChanges = booleanValue(azArg[1]);
2818 }else{
2819 fprintf(stderr, "Usage: .changes on|off\n");
2820 rc = 1;
2821 }
2822 }else
2823
2824 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
2825 if( nArg==2 ){
2826 tryToClone(p, azArg[1]);
2827 }else{
2828 fprintf(stderr, "Usage: .clone FILENAME\n");
2829 rc = 1;
2830 }
2831 }else
2832
2833 if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
@@ -2841,11 +2859,11 @@
2841 data.colWidth[1] = 15;
2842 data.colWidth[2] = 58;
2843 data.cnt = 0;
2844 sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
2845 if( zErrMsg ){
2846 fprintf(stderr,"Error: %s\n", zErrMsg);
2847 sqlite3_free(zErrMsg);
2848 rc = 1;
2849 }
2850 }else
2851
@@ -2857,16 +2875,16 @@
2857 open_db(p, 0);
2858 /* When playing back a "dump", the content might appear in an order
2859 ** which causes immediate foreign key constraints to be violated.
2860 ** So disable foreign-key constraint enforcement to prevent problems. */
2861 if( nArg!=1 && nArg!=2 ){
2862 fprintf(stderr, "Usage: .dump ?LIKE-PATTERN?\n");
2863 rc = 1;
2864 goto meta_command_exit;
2865 }
2866 fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
2867 fprintf(p->out, "BEGIN TRANSACTION;\n");
2868 p->writableSchema = 0;
2869 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
2870 p->nErr = 0;
2871 if( nArg==1 ){
2872 run_schema_dump_query(p,
@@ -2897,32 +2915,32 @@
2897 );
2898 zShellStatic = 0;
2899 }
2900 }
2901 if( p->writableSchema ){
2902 fprintf(p->out, "PRAGMA writable_schema=OFF;\n");
2903 p->writableSchema = 0;
2904 }
2905 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
2906 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
2907 fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
2908 }else
2909
2910 if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
2911 if( nArg==2 ){
2912 p->echoOn = booleanValue(azArg[1]);
2913 }else{
2914 fprintf(stderr, "Usage: .echo on|off\n");
2915 rc = 1;
2916 }
2917 }else
2918
2919 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
2920 if( nArg==2 ){
2921 p->autoEQP = booleanValue(azArg[1]);
2922 }else{
2923 fprintf(stderr, "Usage: .eqp on|off\n");
2924 rc = 1;
2925 }
2926 }else
2927
2928 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -2968,11 +2986,11 @@
2968 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
2969 ShellState data;
2970 char *zErrMsg = 0;
2971 int doStats = 0;
2972 if( nArg!=1 ){
2973 fprintf(stderr, "Usage: .fullschema\n");
2974 rc = 1;
2975 goto meta_command_exit;
2976 }
2977 open_db(p, 0);
2978 memcpy(&data, p, sizeof(data));
@@ -2995,13 +3013,13 @@
2995 -1, &pStmt, 0);
2996 doStats = sqlite3_step(pStmt)==SQLITE_ROW;
2997 sqlite3_finalize(pStmt);
2998 }
2999 if( doStats==0 ){
3000 fprintf(p->out, "/* No STAT tables available */\n");
3001 }else{
3002 fprintf(p->out, "ANALYZE sqlite_master;\n");
3003 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
3004 callback, &data, &zErrMsg);
3005 data.mode = MODE_Insert;
3006 data.zDestTable = "sqlite_stat1";
3007 shell_exec(p->db, "SELECT * FROM sqlite_stat1",
@@ -3010,25 +3028,25 @@
3010 shell_exec(p->db, "SELECT * FROM sqlite_stat3",
3011 shell_callback, &data,&zErrMsg);
3012 data.zDestTable = "sqlite_stat4";
3013 shell_exec(p->db, "SELECT * FROM sqlite_stat4",
3014 shell_callback, &data, &zErrMsg);
3015 fprintf(p->out, "ANALYZE sqlite_master;\n");
3016 }
3017 }else
3018
3019 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
3020 if( nArg==2 ){
3021 p->showHeader = booleanValue(azArg[1]);
3022 }else{
3023 fprintf(stderr, "Usage: .headers on|off\n");
3024 rc = 1;
3025 }
3026 }else
3027
3028 if( c=='h' && strncmp(azArg[0], "help", n)==0 ){
3029 fprintf(p->out, "%s", zHelp);
3030 }else
3031
3032 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
3033 char *zTable; /* Insert data into this table */
3034 char *zFile; /* Name of file to extra content from */
@@ -3042,31 +3060,32 @@
3042 ImportCtx sCtx; /* Reader context */
3043 char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
3044 int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close file */
3045
3046 if( nArg!=3 ){
3047 fprintf(stderr, "Usage: .import FILE TABLE\n");
3048 goto meta_command_exit;
3049 }
3050 zFile = azArg[1];
3051 zTable = azArg[2];
3052 seenInterrupt = 0;
3053 memset(&sCtx, 0, sizeof(sCtx));
3054 open_db(p, 0);
3055 nSep = strlen30(p->colSeparator);
3056 if( nSep==0 ){
3057 fprintf(stderr, "Error: non-null column separator required for import\n");
 
3058 return 1;
3059 }
3060 if( nSep>1 ){
3061 fprintf(stderr, "Error: multi-character column separators not allowed"
3062 " for import\n");
3063 return 1;
3064 }
3065 nSep = strlen30(p->rowSeparator);
3066 if( nSep==0 ){
3067 fprintf(stderr, "Error: non-null row separator required for import\n");
3068 return 1;
3069 }
3070 if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
3071 /* When importing CSV (only), if the row separator is set to the
3072 ** default output row separator, change it to the default input
@@ -3074,19 +3093,19 @@
3074 ** and output row separators. */
3075 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
3076 nSep = strlen30(p->rowSeparator);
3077 }
3078 if( nSep>1 ){
3079 fprintf(stderr, "Error: multi-character row separators not allowed"
3080 " for import\n");
3081 return 1;
3082 }
3083 sCtx.zFile = zFile;
3084 sCtx.nLine = 1;
3085 if( sCtx.zFile[0]=='|' ){
3086 #ifdef SQLITE_OMIT_POPEN
3087 fprintf(stderr, "Error: pipes are not supported in this OS\n");
3088 return 1;
3089 #else
3090 sCtx.in = popen(sCtx.zFile+1, "r");
3091 sCtx.zFile = "<pipe>";
3092 xCloser = pclose;
@@ -3099,18 +3118,18 @@
3099 xRead = ascii_read_one_field;
3100 }else{
3101 xRead = csv_read_one_field;
3102 }
3103 if( sCtx.in==0 ){
3104 fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
3105 return 1;
3106 }
3107 sCtx.cColSep = p->colSeparator[0];
3108 sCtx.cRowSep = p->rowSeparator[0];
3109 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
3110 if( zSql==0 ){
3111 fprintf(stderr, "Error: out of memory\n");
3112 xCloser(sCtx.in);
3113 return 1;
3114 }
3115 nByte = strlen30(zSql);
3116 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -3125,18 +3144,18 @@
3125 }
3126 if( cSep=='(' ){
3127 sqlite3_free(zCreate);
3128 sqlite3_free(sCtx.z);
3129 xCloser(sCtx.in);
3130 fprintf(stderr,"%s: empty file\n", sCtx.zFile);
3131 return 1;
3132 }
3133 zCreate = sqlite3_mprintf("%z\n)", zCreate);
3134 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
3135 sqlite3_free(zCreate);
3136 if( rc ){
3137 fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
3138 sqlite3_errmsg(p->db));
3139 sqlite3_free(sCtx.z);
3140 xCloser(sCtx.in);
3141 return 1;
3142 }
@@ -3143,21 +3162,21 @@
3143 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3144 }
3145 sqlite3_free(zSql);
3146 if( rc ){
3147 if (pStmt) sqlite3_finalize(pStmt);
3148 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
3149 xCloser(sCtx.in);
3150 return 1;
3151 }
3152 nCol = sqlite3_column_count(pStmt);
3153 sqlite3_finalize(pStmt);
3154 pStmt = 0;
3155 if( nCol==0 ) return 0; /* no columns, no error */
3156 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
3157 if( zSql==0 ){
3158 fprintf(stderr, "Error: out of memory\n");
3159 xCloser(sCtx.in);
3160 return 1;
3161 }
3162 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
3163 j = strlen30(zSql);
@@ -3168,11 +3187,11 @@
3168 zSql[j++] = ')';
3169 zSql[j] = 0;
3170 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3171 sqlite3_free(zSql);
3172 if( rc ){
3173 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3174 if (pStmt) sqlite3_finalize(pStmt);
3175 xCloser(sCtx.in);
3176 return 1;
3177 }
3178 needCommit = sqlite3_get_autocommit(p->db);
@@ -3192,11 +3211,11 @@
3192 ** the remaining columns.
3193 */
3194 if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
3195 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
3196 if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
3197 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
3198 "filling the rest with NULL\n",
3199 sCtx.zFile, startLine, nCol, i+1);
3200 i += 2;
3201 while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
3202 }
@@ -3204,20 +3223,20 @@
3204 if( sCtx.cTerm==sCtx.cColSep ){
3205 do{
3206 xRead(&sCtx);
3207 i++;
3208 }while( sCtx.cTerm==sCtx.cColSep );
3209 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
3210 "extras ignored\n",
3211 sCtx.zFile, startLine, nCol, i);
3212 }
3213 if( i>=nCol ){
3214 sqlite3_step(pStmt);
3215 rc = sqlite3_reset(pStmt);
3216 if( rc!=SQLITE_OK ){
3217 fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
3218 sqlite3_errmsg(p->db));
3219 }
3220 }
3221 }while( sCtx.cTerm!=EOF );
3222
3223 xCloser(sCtx.in);
@@ -3255,20 +3274,21 @@
3255 "ORDER BY 1",
3256 callback, &data, &zErrMsg
3257 );
3258 zShellStatic = 0;
3259 }else{
3260 fprintf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
3261 rc = 1;
3262 goto meta_command_exit;
3263 }
3264 if( zErrMsg ){
3265 fprintf(stderr,"Error: %s\n", zErrMsg);
3266 sqlite3_free(zErrMsg);
3267 rc = 1;
3268 }else if( rc != SQLITE_OK ){
3269 fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n");
 
3270 rc = 1;
3271 }
3272 }else
3273
3274 #ifdef SQLITE_ENABLE_IOTRACE
@@ -3282,11 +3302,11 @@
3282 sqlite3IoTrace = iotracePrintf;
3283 iotrace = stdout;
3284 }else{
3285 iotrace = fopen(azArg[1], "w");
3286 if( iotrace==0 ){
3287 fprintf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
3288 sqlite3IoTrace = 0;
3289 rc = 1;
3290 }else{
3291 sqlite3IoTrace = iotracePrintf;
3292 }
@@ -3317,11 +3337,11 @@
3317 for(i=0; i<ArraySize(aLimit); i++){
3318 printf("%20s %d\n", aLimit[i].zLimitName,
3319 sqlite3_limit(p->db, aLimit[i].limitCode, -1));
3320 }
3321 }else if( nArg>3 ){
3322 fprintf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n");
3323 rc = 1;
3324 goto meta_command_exit;
3325 }else{
3326 int iLimit = -1;
3327 n2 = strlen30(azArg[1]);
@@ -3328,18 +3348,18 @@
3328 for(i=0; i<ArraySize(aLimit); i++){
3329 if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){
3330 if( iLimit<0 ){
3331 iLimit = i;
3332 }else{
3333 fprintf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]);
3334 rc = 1;
3335 goto meta_command_exit;
3336 }
3337 }
3338 }
3339 if( iLimit<0 ){
3340 fprintf(stderr, "unknown limit: \"%s\"\n"
3341 "enter \".limits\" with no arguments for a list.\n",
3342 azArg[1]);
3343 rc = 1;
3344 goto meta_command_exit;
3345 }
@@ -3355,29 +3375,29 @@
3355 #ifndef SQLITE_OMIT_LOAD_EXTENSION
3356 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
3357 const char *zFile, *zProc;
3358 char *zErrMsg = 0;
3359 if( nArg<2 ){
3360 fprintf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
3361 rc = 1;
3362 goto meta_command_exit;
3363 }
3364 zFile = azArg[1];
3365 zProc = nArg>=3 ? azArg[2] : 0;
3366 open_db(p, 0);
3367 rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
3368 if( rc!=SQLITE_OK ){
3369 fprintf(stderr, "Error: %s\n", zErrMsg);
3370 sqlite3_free(zErrMsg);
3371 rc = 1;
3372 }
3373 }else
3374 #endif
3375
3376 if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
3377 if( nArg!=2 ){
3378 fprintf(stderr, "Usage: .log FILENAME\n");
3379 rc = 1;
3380 }else{
3381 const char *zFile = azArg[1];
3382 output_file_close(p->pLog);
3383 p->pLog = output_file_open(zFile);
@@ -3412,11 +3432,11 @@
3412 }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
3413 p->mode = MODE_Ascii;
3414 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
3415 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
3416 }else {
3417 fprintf(stderr,"Error: mode should be one of: "
3418 "ascii column csv html insert line list tabs tcl\n");
3419 rc = 1;
3420 }
3421 }else
3422
@@ -3423,11 +3443,11 @@
3423 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
3424 if( nArg==2 ){
3425 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
3426 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
3427 }else{
3428 fprintf(stderr, "Usage: .nullvalue STRING\n");
3429 rc = 1;
3430 }
3431 }else
3432
3433 if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
@@ -3452,17 +3472,17 @@
3452 if( c=='o'
3453 && (strncmp(azArg[0], "output", n)==0 || strncmp(azArg[0], "once", n)==0)
3454 ){
3455 const char *zFile = nArg>=2 ? azArg[1] : "stdout";
3456 if( nArg>2 ){
3457 fprintf(stderr, "Usage: .%s FILE\n", azArg[0]);
3458 rc = 1;
3459 goto meta_command_exit;
3460 }
3461 if( n>1 && strncmp(azArg[0], "once", n)==0 ){
3462 if( nArg<2 ){
3463 fprintf(stderr, "Usage: .once FILE\n");
3464 rc = 1;
3465 goto meta_command_exit;
3466 }
3467 p->outCount = 2;
3468 }else{
@@ -3469,17 +3489,17 @@
3469 p->outCount = 0;
3470 }
3471 output_reset(p);
3472 if( zFile[0]=='|' ){
3473 #ifdef SQLITE_OMIT_POPEN
3474 fprintf(stderr,"Error: pipes are not supported in this OS\n");
3475 rc = 1;
3476 p->out = stdout;
3477 #else
3478 p->out = popen(zFile + 1, "w");
3479 if( p->out==0 ){
3480 fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
3481 p->out = stdout;
3482 rc = 1;
3483 }else{
3484 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
3485 }
@@ -3486,11 +3506,11 @@
3486 #endif
3487 }else{
3488 p->out = output_file_open(zFile);
3489 if( p->out==0 ){
3490 if( strcmp(zFile,"off")!=0 ){
3491 fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
3492 }
3493 p->out = stdout;
3494 rc = 1;
3495 } else {
3496 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
@@ -3499,14 +3519,14 @@
3499 }else
3500
3501 if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
3502 int i;
3503 for(i=1; i<nArg; i++){
3504 if( i>1 ) fprintf(p->out, " ");
3505 utf8_printf(p->out, "%s", azArg[i]);
3506 }
3507 fprintf(p->out, "\n");
3508 }else
3509
3510 if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){
3511 if( nArg >= 2) {
3512 strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
@@ -3521,17 +3541,17 @@
3521 }else
3522
3523 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
3524 FILE *alt;
3525 if( nArg!=2 ){
3526 fprintf(stderr, "Usage: .read FILE\n");
3527 rc = 1;
3528 goto meta_command_exit;
3529 }
3530 alt = fopen(azArg[1], "rb");
3531 if( alt==0 ){
3532 fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
3533 rc = 1;
3534 }else{
3535 rc = process_input(p, alt);
3536 fclose(alt);
3537 }
@@ -3549,24 +3569,24 @@
3549 zDb = "main";
3550 }else if( nArg==3 ){
3551 zSrcFile = azArg[2];
3552 zDb = azArg[1];
3553 }else{
3554 fprintf(stderr, "Usage: .restore ?DB? FILE\n");
3555 rc = 1;
3556 goto meta_command_exit;
3557 }
3558 rc = sqlite3_open(zSrcFile, &pSrc);
3559 if( rc!=SQLITE_OK ){
3560 fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
3561 sqlite3_close(pSrc);
3562 return 1;
3563 }
3564 open_db(p, 0);
3565 pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
3566 if( pBackup==0 ){
3567 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3568 sqlite3_close(pSrc);
3569 return 1;
3570 }
3571 while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK
3572 || rc==SQLITE_BUSY ){
@@ -3577,14 +3597,14 @@
3577 }
3578 sqlite3_backup_finish(pBackup);
3579 if( rc==SQLITE_DONE ){
3580 rc = 0;
3581 }else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){
3582 fprintf(stderr, "Error: source database is busy\n");
3583 rc = 1;
3584 }else{
3585 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3586 rc = 1;
3587 }
3588 sqlite3_close(pSrc);
3589 }else
3590
@@ -3591,14 +3611,14 @@
3591
3592 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
3593 if( nArg==2 ){
3594 p->scanstatsOn = booleanValue(azArg[1]);
3595 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
3596 fprintf(stderr, "Warning: .scanstats not available in this build.\n");
3597 #endif
3598 }else{
3599 fprintf(stderr, "Usage: .scanstats on|off\n");
3600 rc = 1;
3601 }
3602 }else
3603
3604 if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
@@ -3661,20 +3681,20 @@
3661 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
3662 "ORDER BY rowid",
3663 callback, &data, &zErrMsg
3664 );
3665 }else{
3666 fprintf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
3667 rc = 1;
3668 goto meta_command_exit;
3669 }
3670 if( zErrMsg ){
3671 fprintf(stderr,"Error: %s\n", zErrMsg);
3672 sqlite3_free(zErrMsg);
3673 rc = 1;
3674 }else if( rc != SQLITE_OK ){
3675 fprintf(stderr,"Error: querying schema information\n");
3676 rc = 1;
3677 }else{
3678 rc = 0;
3679 }
3680 }else
@@ -3711,11 +3731,11 @@
3711 }else
3712 #endif
3713
3714 if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
3715 if( nArg<2 || nArg>3 ){
3716 fprintf(stderr, "Usage: .separator COL ?ROW?\n");
3717 rc = 1;
3718 }
3719 if( nArg>=2 ){
3720 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator,
3721 "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]);
@@ -3730,11 +3750,11 @@
3730 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
3731 ){
3732 char *zCmd;
3733 int i, x;
3734 if( nArg<2 ){
3735 fprintf(stderr, "Usage: .system COMMAND\n");
3736 rc = 1;
3737 goto meta_command_exit;
3738 }
3739 zCmd = sqlite3_mprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]);
3740 for(i=2; i<nArg; i++){
@@ -3741,49 +3761,49 @@
3741 zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"",
3742 zCmd, azArg[i]);
3743 }
3744 x = system(zCmd);
3745 sqlite3_free(zCmd);
3746 if( x ) fprintf(stderr, "System command returns %d\n", x);
3747 }else
3748
3749 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
3750 int i;
3751 if( nArg!=1 ){
3752 fprintf(stderr, "Usage: .show\n");
3753 rc = 1;
3754 goto meta_command_exit;
3755 }
3756 fprintf(p->out,"%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3757 fprintf(p->out,"%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
3758 fprintf(p->out,"%9.9s: %s\n","explain", p->normalMode.valid ? "on" :"off");
3759 fprintf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3760 fprintf(p->out,"%12.12s: %s\n","mode", modeDescr[p->mode]);
3761 fprintf(p->out,"%12.12s: ", "nullvalue");
3762 output_c_string(p->out, p->nullValue);
3763 fprintf(p->out, "\n");
3764 fprintf(p->out,"%12.12s: %s\n","output",
3765 strlen30(p->outfile) ? p->outfile : "stdout");
3766 fprintf(p->out,"%12.12s: ", "colseparator");
3767 output_c_string(p->out, p->colSeparator);
3768 fprintf(p->out, "\n");
3769 fprintf(p->out,"%12.12s: ", "rowseparator");
3770 output_c_string(p->out, p->rowSeparator);
3771 fprintf(p->out, "\n");
3772 fprintf(p->out,"%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
3773 fprintf(p->out,"%12.12s: ","width");
3774 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
3775 fprintf(p->out,"%d ",p->colWidth[i]);
3776 }
3777 fprintf(p->out,"\n");
3778 }else
3779
3780 if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
3781 if( nArg==2 ){
3782 p->statsOn = booleanValue(azArg[1]);
3783 }else{
3784 fprintf(stderr, "Usage: .stats on|off\n");
3785 rc = 1;
3786 }
3787 }else
3788
3789 if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
@@ -3880,11 +3900,11 @@
3880 for(j=i; j<nRow; j+=nPrintRow){
3881 char *zSp = j<nPrintRow ? "" : " ";
3882 utf8_printf(p->out, "%s%-*s", zSp, maxlen,
3883 azResult[j] ? azResult[j]:"");
3884 }
3885 fprintf(p->out, "\n");
3886 }
3887 }
3888
3889 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
3890 sqlite3_free(azResult);
@@ -3923,31 +3943,31 @@
3923 for(i=0; i<ArraySize(aCtrl); i++){
3924 if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){
3925 if( testctrl<0 ){
3926 testctrl = aCtrl[i].ctrlCode;
3927 }else{
3928 fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
3929 testctrl = -1;
3930 break;
3931 }
3932 }
3933 }
3934 if( testctrl<0 ) testctrl = (int)integerValue(azArg[1]);
3935 if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
3936 fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
3937 }else{
3938 switch(testctrl){
3939
3940 /* sqlite3_test_control(int, db, int) */
3941 case SQLITE_TESTCTRL_OPTIMIZATIONS:
3942 case SQLITE_TESTCTRL_RESERVE:
3943 if( nArg==3 ){
3944 int opt = (int)strtol(azArg[2], 0, 0);
3945 rc2 = sqlite3_test_control(testctrl, p->db, opt);
3946 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3947 } else {
3948 fprintf(stderr,"Error: testctrl %s takes a single int option\n",
3949 azArg[1]);
3950 }
3951 break;
3952
3953 /* sqlite3_test_control(int) */
@@ -3955,24 +3975,25 @@
3955 case SQLITE_TESTCTRL_PRNG_RESTORE:
3956 case SQLITE_TESTCTRL_PRNG_RESET:
3957 case SQLITE_TESTCTRL_BYTEORDER:
3958 if( nArg==2 ){
3959 rc2 = sqlite3_test_control(testctrl);
3960 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3961 } else {
3962 fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
 
3963 }
3964 break;
3965
3966 /* sqlite3_test_control(int, uint) */
3967 case SQLITE_TESTCTRL_PENDING_BYTE:
3968 if( nArg==3 ){
3969 unsigned int opt = (unsigned int)integerValue(azArg[2]);
3970 rc2 = sqlite3_test_control(testctrl, opt);
3971 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3972 } else {
3973 fprintf(stderr,"Error: testctrl %s takes a single unsigned"
3974 " int option\n", azArg[1]);
3975 }
3976 break;
3977
3978 /* sqlite3_test_control(int, int) */
@@ -3980,13 +4001,13 @@
3980 case SQLITE_TESTCTRL_ALWAYS:
3981 case SQLITE_TESTCTRL_NEVER_CORRUPT:
3982 if( nArg==3 ){
3983 int opt = booleanValue(azArg[2]);
3984 rc2 = sqlite3_test_control(testctrl, opt);
3985 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3986 } else {
3987 fprintf(stderr,"Error: testctrl %s takes a single int option\n",
3988 azArg[1]);
3989 }
3990 break;
3991
3992 /* sqlite3_test_control(int, char *) */
@@ -3993,14 +4014,15 @@
3993 #ifdef SQLITE_N_KEYWORD
3994 case SQLITE_TESTCTRL_ISKEYWORD:
3995 if( nArg==3 ){
3996 const char *opt = azArg[2];
3997 rc2 = sqlite3_test_control(testctrl, opt);
3998 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3999 } else {
4000 fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
4001 azArg[1]);
 
4002 }
4003 break;
4004 #endif
4005
4006 case SQLITE_TESTCTRL_IMPOSTER:
@@ -4007,23 +4029,24 @@
4007 if( nArg==5 ){
4008 rc2 = sqlite3_test_control(testctrl, p->db,
4009 azArg[2],
4010 integerValue(azArg[3]),
4011 integerValue(azArg[4]));
4012 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
4013 }else{
4014 fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
4015 }
4016 break;
4017
4018 case SQLITE_TESTCTRL_BITVEC_TEST:
4019 case SQLITE_TESTCTRL_FAULT_INSTALL:
4020 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
4021 case SQLITE_TESTCTRL_SCRATCHMALLOC:
4022 default:
4023 fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n",
4024 azArg[1]);
 
4025 break;
4026 }
4027 }
4028 }else
4029
@@ -4034,23 +4057,23 @@
4034
4035 if( c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 ){
4036 if( nArg==2 ){
4037 enableTimer = booleanValue(azArg[1]);
4038 if( enableTimer && !HAS_TIMER ){
4039 fprintf(stderr, "Error: timer not available on this system.\n");
4040 enableTimer = 0;
4041 }
4042 }else{
4043 fprintf(stderr, "Usage: .timer on|off\n");
4044 rc = 1;
4045 }
4046 }else
4047
4048 if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
4049 open_db(p, 0);
4050 if( nArg!=2 ){
4051 fprintf(stderr, "Usage: .trace FILE|off\n");
4052 rc = 1;
4053 goto meta_command_exit;
4054 }
4055 output_file_close(p->traceOut);
4056 p->traceOut = output_file_open(azArg[1]);
@@ -4064,87 +4087,87 @@
4064 }else
4065
4066 #if SQLITE_USER_AUTHENTICATION
4067 if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
4068 if( nArg<2 ){
4069 fprintf(stderr, "Usage: .user SUBCOMMAND ...\n");
4070 rc = 1;
4071 goto meta_command_exit;
4072 }
4073 open_db(p, 0);
4074 if( strcmp(azArg[1],"login")==0 ){
4075 if( nArg!=4 ){
4076 fprintf(stderr, "Usage: .user login USER PASSWORD\n");
4077 rc = 1;
4078 goto meta_command_exit;
4079 }
4080 rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3],
4081 (int)strlen(azArg[3]));
4082 if( rc ){
4083 fprintf(stderr, "Authentication failed for user %s\n", azArg[2]);
4084 rc = 1;
4085 }
4086 }else if( strcmp(azArg[1],"add")==0 ){
4087 if( nArg!=5 ){
4088 fprintf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
4089 rc = 1;
4090 goto meta_command_exit;
4091 }
4092 rc = sqlite3_user_add(p->db, azArg[2],
4093 azArg[3], (int)strlen(azArg[3]),
4094 booleanValue(azArg[4]));
4095 if( rc ){
4096 fprintf(stderr, "User-Add failed: %d\n", rc);
4097 rc = 1;
4098 }
4099 }else if( strcmp(azArg[1],"edit")==0 ){
4100 if( nArg!=5 ){
4101 fprintf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
4102 rc = 1;
4103 goto meta_command_exit;
4104 }
4105 rc = sqlite3_user_change(p->db, azArg[2],
4106 azArg[3], (int)strlen(azArg[3]),
4107 booleanValue(azArg[4]));
4108 if( rc ){
4109 fprintf(stderr, "User-Edit failed: %d\n", rc);
4110 rc = 1;
4111 }
4112 }else if( strcmp(azArg[1],"delete")==0 ){
4113 if( nArg!=3 ){
4114 fprintf(stderr, "Usage: .user delete USER\n");
4115 rc = 1;
4116 goto meta_command_exit;
4117 }
4118 rc = sqlite3_user_delete(p->db, azArg[2]);
4119 if( rc ){
4120 fprintf(stderr, "User-Delete failed: %d\n", rc);
4121 rc = 1;
4122 }
4123 }else{
4124 fprintf(stderr, "Usage: .user login|add|edit|delete ...\n");
4125 rc = 1;
4126 goto meta_command_exit;
4127 }
4128 }else
4129 #endif /* SQLITE_USER_AUTHENTICATION */
4130
4131 if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
4132 fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
4133 sqlite3_libversion(), sqlite3_sourceid());
4134 }else
4135
4136 if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
4137 const char *zDbName = nArg==2 ? azArg[1] : "main";
4138 sqlite3_vfs *pVfs;
4139 if( p->db ){
4140 sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs);
4141 if( pVfs ){
4142 fprintf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName);
4143 fprintf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
4144 fprintf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile);
4145 fprintf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname);
4146 }
4147 }
4148 }else
4149
4150 if( c=='v' && strncmp(azArg[0], "vfsname", n)==0 ){
@@ -4151,11 +4174,11 @@
4151 const char *zDbName = nArg==2 ? azArg[1] : "main";
4152 char *zVfsName = 0;
4153 if( p->db ){
4154 sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName);
4155 if( zVfsName ){
4156 fprintf(p->out, "%s\n", zVfsName);
4157 sqlite3_free(zVfsName);
4158 }
4159 }
4160 }else
4161
@@ -4173,11 +4196,11 @@
4173 p->colWidth[j-1] = (int)integerValue(azArg[j]);
4174 }
4175 }else
4176
4177 {
4178 fprintf(stderr, "Error: unknown command or invalid arguments: "
4179 " \"%s\". Enter \".help\" for help\n", azArg[0]);
4180 rc = 1;
4181 }
4182
4183 meta_command_exit:
@@ -4308,11 +4331,11 @@
4308 nLine = strlen30(zLine);
4309 if( nSql+nLine+2>=nAlloc ){
4310 nAlloc = nSql+nLine+100;
4311 zSql = realloc(zSql, nAlloc);
4312 if( zSql==0 ){
4313 fprintf(stderr, "Error: out of memory\n");
4314 exit(1);
4315 }
4316 }
4317 nSqlPrior = nSql;
4318 if( nSql==0 ){
@@ -4342,19 +4365,19 @@
4342 "Error: near line %d:", startline);
4343 }else{
4344 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
4345 }
4346 if( zErrMsg!=0 ){
4347 fprintf(stderr, "%s %s\n", zPrefix, zErrMsg);
4348 sqlite3_free(zErrMsg);
4349 zErrMsg = 0;
4350 }else{
4351 fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
4352 }
4353 errCnt++;
4354 }else if( p->countChanges ){
4355 fprintf(p->out, "changes: %3d total_changes: %d\n",
4356 sqlite3_changes(p->db), sqlite3_total_changes(p->db));
4357 }
4358 nSql = 0;
4359 if( p->outCount ){
4360 output_reset(p);
@@ -4365,11 +4388,11 @@
4365 nSql = 0;
4366 }
4367 }
4368 if( nSql ){
4369 if( !_all_whitespace(zSql) ){
4370 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
4371 errCnt++;
4372 }
4373 }
4374 free(zSql);
4375 free(zLine);
@@ -4456,11 +4479,11 @@
4456 FILE *in = NULL;
4457
4458 if (sqliterc == NULL) {
4459 home_dir = find_home_dir();
4460 if( home_dir==0 ){
4461 fprintf(stderr, "-- warning: cannot find home directory;"
4462 " cannot read ~/.sqliterc\n");
4463 return;
4464 }
4465 sqlite3_initialize();
4466 zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
@@ -4467,11 +4490,11 @@
4467 sqliterc = zBuf;
4468 }
4469 in = fopen(sqliterc,"rb");
4470 if( in ){
4471 if( stdin_is_interactive ){
4472 fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
4473 }
4474 process_input(p,in);
4475 fclose(in);
4476 }
4477 sqlite3_free(zBuf);
@@ -4514,18 +4537,18 @@
4514 #ifdef SQLITE_ENABLE_VFSTRACE
4515 " -vfstrace enable tracing of all VFS calls\n"
4516 #endif
4517 ;
4518 static void usage(int showDetail){
4519 fprintf(stderr,
4520 "Usage: %s [OPTIONS] FILENAME [SQL]\n"
4521 "FILENAME is the name of an SQLite database. A new database is created\n"
4522 "if the file does not previously exist.\n", Argv0);
4523 if( showDetail ){
4524 fprintf(stderr, "OPTIONS include:\n%s", zOptions);
4525 }else{
4526 fprintf(stderr, "Use the -help option for additional information\n");
4527 }
4528 exit(1);
4529 }
4530
4531 /*
@@ -4569,11 +4592,11 @@
4569 ** Get the argument to an --option. Throw an error and die if no argument
4570 ** is available.
4571 */
4572 static char *cmdline_option_value(int argc, char **argv, int i){
4573 if( i==argc ){
4574 fprintf(stderr, "%s: Error: missing argument to %s\n",
4575 argv[0], argv[argc-1]);
4576 exit(1);
4577 }
4578 return argv[i];
4579 }
@@ -4589,11 +4612,11 @@
4589 int nCmd = 0;
4590 char **azCmd = 0;
4591
4592 #if USE_SYSTEM_SQLITE+0!=1
4593 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
4594 fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
4595 sqlite3_sourceid(), SQLITE_SOURCE_ID);
4596 exit(1);
4597 }
4598 #endif
4599 setBinaryMode(stdin);
@@ -4638,11 +4661,11 @@
4638 ** mean that nothing is read from stdin */
4639 readStdin = 0;
4640 nCmd++;
4641 azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
4642 if( azCmd==0 ){
4643 fprintf(stderr, "out of memory\n");
4644 exit(1);
4645 }
4646 azCmd[nCmd-1] = z;
4647 }
4648 }
@@ -4720,21 +4743,21 @@
4720 }else if( strcmp(z,"-vfs")==0 ){
4721 sqlite3_vfs *pVfs = sqlite3_vfs_find(cmdline_option_value(argc,argv,++i));
4722 if( pVfs ){
4723 sqlite3_vfs_register(pVfs, 1);
4724 }else{
4725 fprintf(stderr, "no such VFS: \"%s\"\n", argv[i]);
4726 exit(1);
4727 }
4728 }
4729 }
4730 if( data.zDbFilename==0 ){
4731 #ifndef SQLITE_OMIT_MEMORYDB
4732 data.zDbFilename = ":memory:";
4733 warnInmemoryDb = argc==1;
4734 #else
4735 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
4736 return 1;
4737 #endif
4738 }
4739 data.out = stdout;
4740
@@ -4852,20 +4875,20 @@
4852 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
4853 }else{
4854 open_db(&data, 0);
4855 rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
4856 if( zErrMsg!=0 ){
4857 fprintf(stderr,"Error: %s\n", zErrMsg);
4858 if( bail_on_error ) return rc!=0 ? rc : 1;
4859 }else if( rc!=0 ){
4860 fprintf(stderr,"Error: unable to process SQL \"%s\"\n", z);
4861 if( bail_on_error ) return rc;
4862 }
4863 }
4864 }else{
4865 fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
4866 fprintf(stderr,"Use -help for a list of options.\n");
4867 return 1;
4868 }
4869 }
4870
4871 if( !readStdin ){
@@ -4879,14 +4902,14 @@
4879 if( rc ) return rc==2 ? 0 : rc;
4880 }else{
4881 open_db(&data, 0);
4882 rc = shell_exec(data.db, azCmd[i], shell_callback, &data, &zErrMsg);
4883 if( zErrMsg!=0 ){
4884 fprintf(stderr,"Error: %s\n", zErrMsg);
4885 return rc!=0 ? rc : 1;
4886 }else if( rc!=0 ){
4887 fprintf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
4888 return rc;
4889 }
4890 }
4891 }
4892 free(azCmd);
4893
--- src/shell.c
+++ src/shell.c
@@ -546,11 +546,11 @@
546 */
547 #if defined(_WIN32) || defined(WIN32)
548 void utf8_printf(FILE *out, const char *zFormat, ...){
549 va_list ap;
550 va_start(ap, zFormat);
551 if( stdout_is_console && (out==stdout || out==stderr) ){
552 extern char *sqlite3_win32_utf8_to_mbcs(const char*);
553 char *z1 = sqlite3_vmprintf(zFormat, ap);
554 char *z2 = sqlite3_win32_utf8_to_mbcs(z1);
555 sqlite3_free(z1);
556 fputs(z2, out);
@@ -558,14 +558,22 @@
558 }else{
559 vfprintf(out, zFormat, ap);
560 }
561 va_end(ap);
562 }
563 #elif !defined(utf8_printf)
564 # define utf8_printf fprintf
565 #endif
566
567 /*
568 ** Render output like fprintf(). This should not be used on anything that
569 ** includes string formatting (e.g. "%s").
570 */
571 #if !defined(raw_printf)
572 # define raw_printf fprintf
573 #endif
574
575 /*
576 ** Shell output mode information from before ".explain on",
577 ** saved so that it can be restored by ".explain off"
578 */
579 typedef struct SavedModeInfo SavedModeInfo;
@@ -673,23 +681,23 @@
681 ** A callback for the sqlite3_log() interface.
682 */
683 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
684 ShellState *p = (ShellState*)pArg;
685 if( p->pLog==0 ) return;
686 utf8_printf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
687 fflush(p->pLog);
688 }
689
690 /*
691 ** Output the given string as a hex-encoded blob (eg. X'1234' )
692 */
693 static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
694 int i;
695 char *zBlob = (char *)pBlob;
696 raw_printf(out,"X'");
697 for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
698 raw_printf(out,"'");
699 }
700
701 /*
702 ** Output the given string as a quoted string using SQL quoting conventions.
703 */
@@ -701,25 +709,25 @@
709 if( z[i]=='\'' ) nSingle++;
710 }
711 if( nSingle==0 ){
712 utf8_printf(out,"'%s'",z);
713 }else{
714 raw_printf(out,"'");
715 while( *z ){
716 for(i=0; z[i] && z[i]!='\''; i++){}
717 if( i==0 ){
718 raw_printf(out,"''");
719 z++;
720 }else if( z[i]=='\'' ){
721 utf8_printf(out,"%.*s''",i,z);
722 z += i+1;
723 }else{
724 utf8_printf(out,"%s",z);
725 break;
726 }
727 }
728 raw_printf(out,"'");
729 }
730 setTextMode(out);
731 }
732
733 /*
@@ -743,11 +751,11 @@
751 fputc('n', out);
752 }else if( c=='\r' ){
753 fputc('\\', out);
754 fputc('r', out);
755 }else if( !isprint(c&0xff) ){
756 raw_printf(out, "\\%03o", c&0xff);
757 }else{
758 fputc(c, out);
759 }
760 }
761 fputc('"', out);
@@ -770,19 +778,19 @@
778 i++){}
779 if( i>0 ){
780 utf8_printf(out,"%.*s",i,z);
781 }
782 if( z[i]=='<' ){
783 raw_printf(out,"&lt;");
784 }else if( z[i]=='&' ){
785 raw_printf(out,"&amp;");
786 }else if( z[i]=='>' ){
787 raw_printf(out,"&gt;");
788 }else if( z[i]=='\"' ){
789 raw_printf(out,"&quot;");
790 }else if( z[i]=='\'' ){
791 raw_printf(out,"&#39;");
792 }else{
793 break;
794 }
795 z += i + 1;
796 }
@@ -925,11 +933,11 @@
933 w = p->actualWidth[i];
934 if( w<0 ) w = -w;
935 }else{
936 w = 10;
937 }
938 utf8_printf(p->out,"%-*.*s%s",w,w,
939 "----------------------------------------------------------"
940 "----------------------------------------------------------",
941 i==nArg-1 ? p->rowSeparator : " ");
942 }
943 }
@@ -945,11 +953,11 @@
953 if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
954 w = strlen30(azArg[i]);
955 }
956 if( i==1 && p->aiIndent && p->pStmt ){
957 if( p->iIndent<p->nIndent ){
958 utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
959 }
960 p->iIndent++;
961 }
962 if( w<0 ){
963 utf8_printf(p->out,"%*.*s%s",-w,-w,
@@ -986,26 +994,26 @@
994 }
995 break;
996 }
997 case MODE_Html: {
998 if( p->cnt++==0 && p->showHeader ){
999 raw_printf(p->out,"<TR>");
1000 for(i=0; i<nArg; i++){
1001 raw_printf(p->out,"<TH>");
1002 output_html_string(p->out, azCol[i]);
1003 raw_printf(p->out,"</TH>\n");
1004 }
1005 raw_printf(p->out,"</TR>\n");
1006 }
1007 if( azArg==0 ) break;
1008 raw_printf(p->out,"<TR>");
1009 for(i=0; i<nArg; i++){
1010 raw_printf(p->out,"<TD>");
1011 output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue);
1012 raw_printf(p->out,"</TD>\n");
1013 }
1014 raw_printf(p->out,"</TR>\n");
1015 break;
1016 }
1017 case MODE_Tcl: {
1018 if( p->cnt++==0 && p->showHeader ){
1019 for(i=0; i<nArg; i++){
@@ -1042,41 +1050,41 @@
1050 case MODE_Insert: {
1051 p->cnt++;
1052 if( azArg==0 ) break;
1053 utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
1054 if( p->showHeader ){
1055 raw_printf(p->out,"(");
1056 for(i=0; i<nArg; i++){
1057 char *zSep = i>0 ? ",": "";
1058 utf8_printf(p->out, "%s%s", zSep, azCol[i]);
1059 }
1060 raw_printf(p->out,")");
1061 }
1062 raw_printf(p->out," VALUES(");
1063 for(i=0; i<nArg; i++){
1064 char *zSep = i>0 ? ",": "";
1065 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
1066 utf8_printf(p->out,"%sNULL",zSep);
1067 }else if( aiType && aiType[i]==SQLITE_TEXT ){
1068 if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
1069 output_quoted_string(p->out, azArg[i]);
1070 }else if( aiType && (aiType[i]==SQLITE_INTEGER
1071 || aiType[i]==SQLITE_FLOAT) ){
1072 utf8_printf(p->out,"%s%s",zSep, azArg[i]);
1073 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
1074 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
1075 int nBlob = sqlite3_column_bytes(p->pStmt, i);
1076 if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
1077 output_hex_blob(p->out, pBlob, nBlob);
1078 }else if( isNumber(azArg[i], 0) ){
1079 utf8_printf(p->out,"%s%s",zSep, azArg[i]);
1080 }else{
1081 if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
1082 output_quoted_string(p->out, azArg[i]);
1083 }
1084 }
1085 raw_printf(p->out,");\n");
1086 break;
1087 }
1088 case MODE_Ascii: {
1089 if( p->cnt++==0 && p->showHeader ){
1090 for(i=0; i<nArg; i++){
@@ -1129,11 +1137,11 @@
1137 }
1138 }
1139 if( needQuote ) n += 2;
1140 z = p->zDestTable = malloc( n+1 );
1141 if( z==0 ){
1142 raw_printf(stderr,"Error: out of memory\n");
1143 exit(1);
1144 }
1145 n = 0;
1146 if( needQuote ) z[n++] = '\'';
1147 for(i=0; zName[i]; i++){
@@ -1210,11 +1218,12 @@
1218 int nResult;
1219 int i;
1220 const char *z;
1221 rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
1222 if( rc!=SQLITE_OK || !pSelect ){
1223 utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc,
1224 sqlite3_errmsg(p->db));
1225 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
1226 return rc;
1227 }
1228 rc = sqlite3_step(pSelect);
1229 nResult = sqlite3_column_count(pSelect);
@@ -1229,19 +1238,20 @@
1238 utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
1239 }
1240 if( z==0 ) z = "";
1241 while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
1242 if( z[0] ){
1243 raw_printf(p->out, "\n;\n");
1244 }else{
1245 raw_printf(p->out, ";\n");
1246 }
1247 rc = sqlite3_step(pSelect);
1248 }
1249 rc = sqlite3_finalize(pSelect);
1250 if( rc!=SQLITE_OK ){
1251 utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc,
1252 sqlite3_errmsg(p->db));
1253 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
1254 }
1255 return rc;
1256 }
1257
@@ -1272,107 +1282,115 @@
1282
1283 if( pArg && pArg->out ){
1284
1285 iHiwtr = iCur = -1;
1286 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
1287 raw_printf(pArg->out,
1288 "Memory Used: %d (max %d) bytes\n",
1289 iCur, iHiwtr);
1290 iHiwtr = iCur = -1;
1291 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
1292 raw_printf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
1293 iCur, iHiwtr);
1294 if( pArg->shellFlgs & SHFLG_Pagecache ){
1295 iHiwtr = iCur = -1;
1296 sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
1297 raw_printf(pArg->out,
1298 "Number of Pcache Pages Used: %d (max %d) pages\n",
1299 iCur, iHiwtr);
1300 }
1301 iHiwtr = iCur = -1;
1302 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
1303 raw_printf(pArg->out,
1304 "Number of Pcache Overflow Bytes: %d (max %d) bytes\n",
1305 iCur, iHiwtr);
1306 if( pArg->shellFlgs & SHFLG_Scratch ){
1307 iHiwtr = iCur = -1;
1308 sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
1309 raw_printf(pArg->out,
1310 "Number of Scratch Allocations Used: %d (max %d)\n",
1311 iCur, iHiwtr);
1312 }
1313 iHiwtr = iCur = -1;
1314 sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
1315 raw_printf(pArg->out,
1316 "Number of Scratch Overflow Bytes: %d (max %d) bytes\n",
1317 iCur, iHiwtr);
1318 iHiwtr = iCur = -1;
1319 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
1320 raw_printf(pArg->out, "Largest Allocation: %d bytes\n",
1321 iHiwtr);
1322 iHiwtr = iCur = -1;
1323 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
1324 raw_printf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
1325 iHiwtr);
1326 iHiwtr = iCur = -1;
1327 sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
1328 raw_printf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
1329 iHiwtr);
1330 #ifdef YYTRACKMAXSTACKDEPTH
1331 iHiwtr = iCur = -1;
1332 sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
1333 raw_printf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
1334 iCur, iHiwtr);
1335 #endif
1336 }
1337
1338 if( pArg && pArg->out && db ){
1339 if( pArg->shellFlgs & SHFLG_Lookaside ){
1340 iHiwtr = iCur = -1;
1341 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED,
1342 &iCur, &iHiwtr, bReset);
1343 raw_printf(pArg->out,
1344 "Lookaside Slots Used: %d (max %d)\n",
1345 iCur, iHiwtr);
1346 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT,
1347 &iCur, &iHiwtr, bReset);
1348 raw_printf(pArg->out, "Successful lookaside attempts: %d\n",
1349 iHiwtr);
1350 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE,
1351 &iCur, &iHiwtr, bReset);
1352 raw_printf(pArg->out, "Lookaside failures due to size: %d\n",
1353 iHiwtr);
1354 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL,
1355 &iCur, &iHiwtr, bReset);
1356 raw_printf(pArg->out, "Lookaside failures due to OOM: %d\n",
1357 iHiwtr);
1358 }
1359 iHiwtr = iCur = -1;
1360 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
1361 raw_printf(pArg->out, "Pager Heap Usage: %d bytes\n",
1362 iCur);
1363 iHiwtr = iCur = -1;
1364 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
1365 raw_printf(pArg->out, "Page cache hits: %d\n", iCur);
1366 iHiwtr = iCur = -1;
1367 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
1368 raw_printf(pArg->out, "Page cache misses: %d\n", iCur);
1369 iHiwtr = iCur = -1;
1370 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
1371 raw_printf(pArg->out, "Page cache writes: %d\n", iCur);
1372 iHiwtr = iCur = -1;
1373 sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1374 raw_printf(pArg->out, "Schema Heap Usage: %d bytes\n",
1375 iCur);
1376 iHiwtr = iCur = -1;
1377 sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
1378 raw_printf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",
1379 iCur);
1380 }
1381
1382 if( pArg && pArg->out && db && pArg->pStmt ){
1383 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP,
1384 bReset);
1385 raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur);
1386 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1387 raw_printf(pArg->out, "Sort Operations: %d\n", iCur);
1388 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
1389 raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1390 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1391 raw_printf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1392 }
1393
1394 /* Do not remove this machine readable comment: extra-stats-output-here */
1395
1396 return 0;
@@ -1388,11 +1406,11 @@
1406 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
1407 UNUSED_PARAMETER(db);
1408 UNUSED_PARAMETER(pArg);
1409 #else
1410 int i, k, n, mx;
1411 raw_printf(pArg->out, "-------- scanstats --------\n");
1412 mx = 0;
1413 for(k=0; k<=mx; k++){
1414 double rEstLoop = 1.0;
1415 for(i=n=0; 1; i++){
1416 sqlite3_stmt *p = pArg->pStmt;
@@ -1406,25 +1424,25 @@
1424 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_SELECTID, (void*)&iSid);
1425 if( iSid>mx ) mx = iSid;
1426 if( iSid!=k ) continue;
1427 if( n==0 ){
1428 rEstLoop = (double)nLoop;
1429 if( k>0 ) raw_printf(pArg->out, "-------- subquery %d -------\n", k);
1430 }
1431 n++;
1432 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
1433 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
1434 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
1435 utf8_printf(pArg->out, "Loop %2d: %s\n", n, zExplain);
1436 rEstLoop *= rEst;
1437 raw_printf(pArg->out,
1438 " nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
1439 nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
1440 );
1441 }
1442 }
1443 raw_printf(pArg->out, "---------------------------\n");
1444 #endif
1445 }
1446
1447 /*
1448 ** Parameter azArray points to a zero-terminated array of strings. zStr
@@ -1584,13 +1602,13 @@
1602 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1603 sqlite3_sql(pStmt));
1604 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1605 if( rc==SQLITE_OK ){
1606 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1607 raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
1608 raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
1609 raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
1610 utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1611 }
1612 }
1613 sqlite3_finalize(pExplain);
1614 sqlite3_free(zEQP);
@@ -1715,17 +1733,17 @@
1733 zSql = azArg[2];
1734
1735 if( strcmp(zTable, "sqlite_sequence")==0 ){
1736 zPrepStmt = "DELETE FROM sqlite_sequence;\n";
1737 }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 ){
1738 raw_printf(p->out, "ANALYZE sqlite_master;\n");
1739 }else if( strncmp(zTable, "sqlite_", 7)==0 ){
1740 return 0;
1741 }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
1742 char *zIns;
1743 if( !p->writableSchema ){
1744 raw_printf(p->out, "PRAGMA writable_schema=ON;\n");
1745 p->writableSchema = 1;
1746 }
1747 zIns = sqlite3_mprintf(
1748 "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
1749 "VALUES('table','%q','%q',0,'%q');",
@@ -1809,22 +1827,22 @@
1827 char *zErr = 0;
1828 rc = sqlite3_exec(p->db, zQuery, dump_callback, p, &zErr);
1829 if( rc==SQLITE_CORRUPT ){
1830 char *zQ2;
1831 int len = strlen30(zQuery);
1832 raw_printf(p->out, "/****** CORRUPTION ERROR *******/\n");
1833 if( zErr ){
1834 utf8_printf(p->out, "/****** %s ******/\n", zErr);
1835 sqlite3_free(zErr);
1836 zErr = 0;
1837 }
1838 zQ2 = malloc( len+100 );
1839 if( zQ2==0 ) return rc;
1840 sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery);
1841 rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr);
1842 if( rc ){
1843 utf8_printf(p->out, "/****** ERROR: %s ******/\n", zErr);
1844 }else{
1845 rc = SQLITE_CORRUPT;
1846 }
1847 sqlite3_free(zErr);
1848 free(zQ2);
@@ -1985,11 +2003,11 @@
2003 if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
2004 sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
2005 shellstaticFunc, 0, 0);
2006 }
2007 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
2008 utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
2009 p->zDbFilename, sqlite3_errmsg(p->db));
2010 if( keepAlive ) return;
2011 exit(1);
2012 }
2013 #ifndef SQLITE_OMIT_LOAD_EXTENSION
@@ -2135,11 +2153,11 @@
2153 return 1;
2154 }
2155 if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){
2156 return 0;
2157 }
2158 utf8_printf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
2159 zArg);
2160 return 0;
2161 }
2162
2163 /*
@@ -2163,11 +2181,11 @@
2181 }else if( strcmp(zFile, "off")==0 ){
2182 f = 0;
2183 }else{
2184 f = fopen(zFile, "wb");
2185 if( f==0 ){
2186 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
2187 }
2188 }
2189 return f;
2190 }
2191
@@ -2212,11 +2230,11 @@
2230 static void import_append_char(ImportCtx *p, int c){
2231 if( p->n+1>=p->nAlloc ){
2232 p->nAlloc += p->nAlloc + 100;
2233 p->z = sqlite3_realloc64(p->z, p->nAlloc);
2234 if( p->z==0 ){
2235 raw_printf(stderr, "out of memory\n");
2236 exit(1);
2237 }
2238 }
2239 p->z[p->n++] = (char)c;
2240 }
@@ -2266,15 +2284,15 @@
2284 do{ p->n--; }while( p->z[p->n]!=cQuote );
2285 p->cTerm = c;
2286 break;
2287 }
2288 if( pc==cQuote && c!='\r' ){
2289 utf8_printf(stderr, "%s:%d: unescaped %c character\n",
2290 p->zFile, p->nLine, cQuote);
2291 }
2292 if( c==EOF ){
2293 utf8_printf(stderr, "%s:%d: unterminated %c-quoted field\n",
2294 p->zFile, startLine, cQuote);
2295 p->cTerm = c;
2296 break;
2297 }
2298 import_append_char(p, c);
@@ -2352,19 +2370,19 @@
2370 const int spinRate = 10000;
2371
2372 zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
2373 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
2374 if( rc ){
2375 utf8_printf(stderr, "Error %d: %s on [%s]\n",
2376 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2377 zQuery);
2378 goto end_data_xfer;
2379 }
2380 n = sqlite3_column_count(pQuery);
2381 zInsert = sqlite3_malloc64(200 + nTable + n*3);
2382 if( zInsert==0 ){
2383 raw_printf(stderr, "out of memory\n");
2384 goto end_data_xfer;
2385 }
2386 sqlite3_snprintf(200+nTable,zInsert,
2387 "INSERT OR IGNORE INTO \"%s\" VALUES(?", zTable);
2388 i = (int)strlen(zInsert);
@@ -2373,11 +2391,11 @@
2391 i += 2;
2392 }
2393 memcpy(zInsert+i, ");", 3);
2394 rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0);
2395 if( rc ){
2396 utf8_printf(stderr, "Error %d: %s on [%s]\n",
2397 sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb),
2398 zQuery);
2399 goto end_data_xfer;
2400 }
2401 for(k=0; k<2; k++){
@@ -2410,11 +2428,11 @@
2428 }
2429 }
2430 } /* End for */
2431 rc = sqlite3_step(pInsert);
2432 if( rc!=SQLITE_OK && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
2433 utf8_printf(stderr, "Error %d: %s\n", sqlite3_extended_errcode(newDb),
2434 sqlite3_errmsg(newDb));
2435 }
2436 sqlite3_reset(pInsert);
2437 cnt++;
2438 if( (cnt%spinRate)==0 ){
@@ -2427,11 +2445,11 @@
2445 sqlite3_free(zQuery);
2446 zQuery = sqlite3_mprintf("SELECT * FROM \"%w\" ORDER BY rowid DESC;",
2447 zTable);
2448 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
2449 if( rc ){
2450 utf8_printf(stderr, "Warning: cannot step \"%s\" backwards", zTable);
2451 break;
2452 }
2453 } /* End for(k=0...) */
2454
2455 end_data_xfer:
@@ -2463,11 +2481,11 @@
2481
2482 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
2483 " WHERE %s", zWhere);
2484 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
2485 if( rc ){
2486 utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
2487 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2488 zQuery);
2489 goto end_schema_xfer;
2490 }
2491 while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
@@ -2474,11 +2492,11 @@
2492 zName = sqlite3_column_text(pQuery, 0);
2493 zSql = sqlite3_column_text(pQuery, 1);
2494 printf("%s... ", zName); fflush(stdout);
2495 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
2496 if( zErrMsg ){
2497 utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
2498 sqlite3_free(zErrMsg);
2499 zErrMsg = 0;
2500 }
2501 if( xForEach ){
2502 xForEach(p, newDb, (const char*)zName);
@@ -2490,11 +2508,11 @@
2508 sqlite3_free(zQuery);
2509 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
2510 " WHERE %s ORDER BY rowid DESC", zWhere);
2511 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
2512 if( rc ){
2513 utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
2514 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
2515 zQuery);
2516 goto end_schema_xfer;
2517 }
2518 while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
@@ -2501,11 +2519,11 @@
2519 zName = sqlite3_column_text(pQuery, 0);
2520 zSql = sqlite3_column_text(pQuery, 1);
2521 printf("%s... ", zName); fflush(stdout);
2522 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
2523 if( zErrMsg ){
2524 utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
2525 sqlite3_free(zErrMsg);
2526 zErrMsg = 0;
2527 }
2528 if( xForEach ){
2529 xForEach(p, newDb, (const char*)zName);
@@ -2525,16 +2543,16 @@
2543 */
2544 static void tryToClone(ShellState *p, const char *zNewDb){
2545 int rc;
2546 sqlite3 *newDb = 0;
2547 if( access(zNewDb,0)==0 ){
2548 utf8_printf(stderr, "File \"%s\" already exists.\n", zNewDb);
2549 return;
2550 }
2551 rc = sqlite3_open(zNewDb, &newDb);
2552 if( rc ){
2553 utf8_printf(stderr, "Cannot create output database: %s\n",
2554 sqlite3_errmsg(newDb));
2555 }else{
2556 sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0);
2557 sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0);
2558 tryToCloneSchema(p, newDb, "type='table'", tryToCloneData);
@@ -2627,31 +2645,31 @@
2645 if( pFile==0 || pFile->pMethods==0 || pFile->pMethods->xRead==0 ){
2646 return 1;
2647 }
2648 i = pFile->pMethods->xRead(pFile, aHdr, 100, 0);
2649 if( i!=SQLITE_OK ){
2650 raw_printf(stderr, "unable to read database header\n");
2651 return 1;
2652 }
2653 i = get2byteInt(aHdr+16);
2654 if( i==1 ) i = 65536;
2655 utf8_printf(p->out, "%-20s %d\n", "database page size:", i);
2656 utf8_printf(p->out, "%-20s %d\n", "write format:", aHdr[18]);
2657 utf8_printf(p->out, "%-20s %d\n", "read format:", aHdr[19]);
2658 utf8_printf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]);
2659 for(i=0; i<ArraySize(aField); i++){
2660 int ofst = aField[i].ofst;
2661 unsigned int val = get4byteInt(aHdr + ofst);
2662 utf8_printf(p->out, "%-20s %u", aField[i].zName, val);
2663 switch( ofst ){
2664 case 56: {
2665 if( val==1 ) raw_printf(p->out, " (utf8)");
2666 if( val==2 ) raw_printf(p->out, " (utf16le)");
2667 if( val==3 ) raw_printf(p->out, " (utf16be)");
2668 }
2669 }
2670 raw_printf(p->out, "\n");
2671 }
2672 if( zDb==0 ){
2673 zSchemaTab = sqlite3_mprintf("main.sqlite_master");
2674 }else if( strcmp(zDb,"temp")==0 ){
2675 zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_master");
@@ -2671,19 +2689,19 @@
2689 /*
2690 ** Print the current sqlite3_errmsg() value to stderr and return 1.
2691 */
2692 static int shellDatabaseError(sqlite3 *db){
2693 const char *zErr = sqlite3_errmsg(db);
2694 utf8_printf(stderr, "Error: %s\n", zErr);
2695 return 1;
2696 }
2697
2698 /*
2699 ** Print an out-of-memory message to stderr and return 1.
2700 */
2701 static int shellNomemError(void){
2702 raw_printf(stderr, "Error: out of memory\n");
2703 return 1;
2704 }
2705
2706 /*
2707 ** If an input line begins with "." then invoke this routine to
@@ -2739,57 +2757,57 @@
2757 const char *z = azArg[j];
2758 if( z[0]=='-' ){
2759 while( z[0]=='-' ) z++;
2760 /* No options to process at this time */
2761 {
2762 utf8_printf(stderr, "unknown option: %s\n", azArg[j]);
2763 return 1;
2764 }
2765 }else if( zDestFile==0 ){
2766 zDestFile = azArg[j];
2767 }else if( zDb==0 ){
2768 zDb = zDestFile;
2769 zDestFile = azArg[j];
2770 }else{
2771 raw_printf(stderr, "too many arguments to .backup\n");
2772 return 1;
2773 }
2774 }
2775 if( zDestFile==0 ){
2776 raw_printf(stderr, "missing FILENAME argument on .backup\n");
2777 return 1;
2778 }
2779 if( zDb==0 ) zDb = "main";
2780 rc = sqlite3_open(zDestFile, &pDest);
2781 if( rc!=SQLITE_OK ){
2782 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
2783 sqlite3_close(pDest);
2784 return 1;
2785 }
2786 open_db(p, 0);
2787 pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
2788 if( pBackup==0 ){
2789 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
2790 sqlite3_close(pDest);
2791 return 1;
2792 }
2793 while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){}
2794 sqlite3_backup_finish(pBackup);
2795 if( rc==SQLITE_DONE ){
2796 rc = 0;
2797 }else{
2798 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
2799 rc = 1;
2800 }
2801 sqlite3_close(pDest);
2802 }else
2803
2804 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
2805 if( nArg==2 ){
2806 bail_on_error = booleanValue(azArg[1]);
2807 }else{
2808 raw_printf(stderr, "Usage: .bail on|off\n");
2809 rc = 1;
2810 }
2811 }else
2812
2813 if( c=='b' && n>=3 && strncmp(azArg[0], "binary", n)==0 ){
@@ -2798,11 +2816,11 @@
2816 setBinaryMode(p->out);
2817 }else{
2818 setTextMode(p->out);
2819 }
2820 }else{
2821 raw_printf(stderr, "Usage: .binary on|off\n");
2822 rc = 1;
2823 }
2824 }else
2825
2826 /* The undocumented ".breakpoint" command causes a call to the no-op
@@ -2814,20 +2832,20 @@
2832
2833 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
2834 if( nArg==2 ){
2835 p->countChanges = booleanValue(azArg[1]);
2836 }else{
2837 raw_printf(stderr, "Usage: .changes on|off\n");
2838 rc = 1;
2839 }
2840 }else
2841
2842 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
2843 if( nArg==2 ){
2844 tryToClone(p, azArg[1]);
2845 }else{
2846 raw_printf(stderr, "Usage: .clone FILENAME\n");
2847 rc = 1;
2848 }
2849 }else
2850
2851 if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
@@ -2841,11 +2859,11 @@
2859 data.colWidth[1] = 15;
2860 data.colWidth[2] = 58;
2861 data.cnt = 0;
2862 sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
2863 if( zErrMsg ){
2864 utf8_printf(stderr,"Error: %s\n", zErrMsg);
2865 sqlite3_free(zErrMsg);
2866 rc = 1;
2867 }
2868 }else
2869
@@ -2857,16 +2875,16 @@
2875 open_db(p, 0);
2876 /* When playing back a "dump", the content might appear in an order
2877 ** which causes immediate foreign key constraints to be violated.
2878 ** So disable foreign-key constraint enforcement to prevent problems. */
2879 if( nArg!=1 && nArg!=2 ){
2880 raw_printf(stderr, "Usage: .dump ?LIKE-PATTERN?\n");
2881 rc = 1;
2882 goto meta_command_exit;
2883 }
2884 raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
2885 raw_printf(p->out, "BEGIN TRANSACTION;\n");
2886 p->writableSchema = 0;
2887 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
2888 p->nErr = 0;
2889 if( nArg==1 ){
2890 run_schema_dump_query(p,
@@ -2897,32 +2915,32 @@
2915 );
2916 zShellStatic = 0;
2917 }
2918 }
2919 if( p->writableSchema ){
2920 raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
2921 p->writableSchema = 0;
2922 }
2923 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
2924 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
2925 raw_printf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
2926 }else
2927
2928 if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
2929 if( nArg==2 ){
2930 p->echoOn = booleanValue(azArg[1]);
2931 }else{
2932 raw_printf(stderr, "Usage: .echo on|off\n");
2933 rc = 1;
2934 }
2935 }else
2936
2937 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
2938 if( nArg==2 ){
2939 p->autoEQP = booleanValue(azArg[1]);
2940 }else{
2941 raw_printf(stderr, "Usage: .eqp on|off\n");
2942 rc = 1;
2943 }
2944 }else
2945
2946 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -2968,11 +2986,11 @@
2986 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
2987 ShellState data;
2988 char *zErrMsg = 0;
2989 int doStats = 0;
2990 if( nArg!=1 ){
2991 raw_printf(stderr, "Usage: .fullschema\n");
2992 rc = 1;
2993 goto meta_command_exit;
2994 }
2995 open_db(p, 0);
2996 memcpy(&data, p, sizeof(data));
@@ -2995,13 +3013,13 @@
3013 -1, &pStmt, 0);
3014 doStats = sqlite3_step(pStmt)==SQLITE_ROW;
3015 sqlite3_finalize(pStmt);
3016 }
3017 if( doStats==0 ){
3018 raw_printf(p->out, "/* No STAT tables available */\n");
3019 }else{
3020 raw_printf(p->out, "ANALYZE sqlite_master;\n");
3021 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
3022 callback, &data, &zErrMsg);
3023 data.mode = MODE_Insert;
3024 data.zDestTable = "sqlite_stat1";
3025 shell_exec(p->db, "SELECT * FROM sqlite_stat1",
@@ -3010,25 +3028,25 @@
3028 shell_exec(p->db, "SELECT * FROM sqlite_stat3",
3029 shell_callback, &data,&zErrMsg);
3030 data.zDestTable = "sqlite_stat4";
3031 shell_exec(p->db, "SELECT * FROM sqlite_stat4",
3032 shell_callback, &data, &zErrMsg);
3033 raw_printf(p->out, "ANALYZE sqlite_master;\n");
3034 }
3035 }else
3036
3037 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
3038 if( nArg==2 ){
3039 p->showHeader = booleanValue(azArg[1]);
3040 }else{
3041 raw_printf(stderr, "Usage: .headers on|off\n");
3042 rc = 1;
3043 }
3044 }else
3045
3046 if( c=='h' && strncmp(azArg[0], "help", n)==0 ){
3047 utf8_printf(p->out, "%s", zHelp);
3048 }else
3049
3050 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
3051 char *zTable; /* Insert data into this table */
3052 char *zFile; /* Name of file to extra content from */
@@ -3042,31 +3060,32 @@
3060 ImportCtx sCtx; /* Reader context */
3061 char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
3062 int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close file */
3063
3064 if( nArg!=3 ){
3065 raw_printf(stderr, "Usage: .import FILE TABLE\n");
3066 goto meta_command_exit;
3067 }
3068 zFile = azArg[1];
3069 zTable = azArg[2];
3070 seenInterrupt = 0;
3071 memset(&sCtx, 0, sizeof(sCtx));
3072 open_db(p, 0);
3073 nSep = strlen30(p->colSeparator);
3074 if( nSep==0 ){
3075 raw_printf(stderr,
3076 "Error: non-null column separator required for import\n");
3077 return 1;
3078 }
3079 if( nSep>1 ){
3080 raw_printf(stderr, "Error: multi-character column separators not allowed"
3081 " for import\n");
3082 return 1;
3083 }
3084 nSep = strlen30(p->rowSeparator);
3085 if( nSep==0 ){
3086 raw_printf(stderr, "Error: non-null row separator required for import\n");
3087 return 1;
3088 }
3089 if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
3090 /* When importing CSV (only), if the row separator is set to the
3091 ** default output row separator, change it to the default input
@@ -3074,19 +3093,19 @@
3093 ** and output row separators. */
3094 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
3095 nSep = strlen30(p->rowSeparator);
3096 }
3097 if( nSep>1 ){
3098 raw_printf(stderr, "Error: multi-character row separators not allowed"
3099 " for import\n");
3100 return 1;
3101 }
3102 sCtx.zFile = zFile;
3103 sCtx.nLine = 1;
3104 if( sCtx.zFile[0]=='|' ){
3105 #ifdef SQLITE_OMIT_POPEN
3106 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
3107 return 1;
3108 #else
3109 sCtx.in = popen(sCtx.zFile+1, "r");
3110 sCtx.zFile = "<pipe>";
3111 xCloser = pclose;
@@ -3099,18 +3118,18 @@
3118 xRead = ascii_read_one_field;
3119 }else{
3120 xRead = csv_read_one_field;
3121 }
3122 if( sCtx.in==0 ){
3123 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
3124 return 1;
3125 }
3126 sCtx.cColSep = p->colSeparator[0];
3127 sCtx.cRowSep = p->rowSeparator[0];
3128 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
3129 if( zSql==0 ){
3130 raw_printf(stderr, "Error: out of memory\n");
3131 xCloser(sCtx.in);
3132 return 1;
3133 }
3134 nByte = strlen30(zSql);
3135 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -3125,18 +3144,18 @@
3144 }
3145 if( cSep=='(' ){
3146 sqlite3_free(zCreate);
3147 sqlite3_free(sCtx.z);
3148 xCloser(sCtx.in);
3149 utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
3150 return 1;
3151 }
3152 zCreate = sqlite3_mprintf("%z\n)", zCreate);
3153 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
3154 sqlite3_free(zCreate);
3155 if( rc ){
3156 utf8_printf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
3157 sqlite3_errmsg(p->db));
3158 sqlite3_free(sCtx.z);
3159 xCloser(sCtx.in);
3160 return 1;
3161 }
@@ -3143,21 +3162,21 @@
3162 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3163 }
3164 sqlite3_free(zSql);
3165 if( rc ){
3166 if (pStmt) sqlite3_finalize(pStmt);
3167 utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
3168 xCloser(sCtx.in);
3169 return 1;
3170 }
3171 nCol = sqlite3_column_count(pStmt);
3172 sqlite3_finalize(pStmt);
3173 pStmt = 0;
3174 if( nCol==0 ) return 0; /* no columns, no error */
3175 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
3176 if( zSql==0 ){
3177 raw_printf(stderr, "Error: out of memory\n");
3178 xCloser(sCtx.in);
3179 return 1;
3180 }
3181 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
3182 j = strlen30(zSql);
@@ -3168,11 +3187,11 @@
3187 zSql[j++] = ')';
3188 zSql[j] = 0;
3189 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3190 sqlite3_free(zSql);
3191 if( rc ){
3192 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3193 if (pStmt) sqlite3_finalize(pStmt);
3194 xCloser(sCtx.in);
3195 return 1;
3196 }
3197 needCommit = sqlite3_get_autocommit(p->db);
@@ -3192,11 +3211,11 @@
3211 ** the remaining columns.
3212 */
3213 if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
3214 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
3215 if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
3216 utf8_printf(stderr, "%s:%d: expected %d columns but found %d - "
3217 "filling the rest with NULL\n",
3218 sCtx.zFile, startLine, nCol, i+1);
3219 i += 2;
3220 while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
3221 }
@@ -3204,20 +3223,20 @@
3223 if( sCtx.cTerm==sCtx.cColSep ){
3224 do{
3225 xRead(&sCtx);
3226 i++;
3227 }while( sCtx.cTerm==sCtx.cColSep );
3228 utf8_printf(stderr, "%s:%d: expected %d columns but found %d - "
3229 "extras ignored\n",
3230 sCtx.zFile, startLine, nCol, i);
3231 }
3232 if( i>=nCol ){
3233 sqlite3_step(pStmt);
3234 rc = sqlite3_reset(pStmt);
3235 if( rc!=SQLITE_OK ){
3236 utf8_printf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile,
3237 startLine, sqlite3_errmsg(p->db));
3238 }
3239 }
3240 }while( sCtx.cTerm!=EOF );
3241
3242 xCloser(sCtx.in);
@@ -3255,20 +3274,21 @@
3274 "ORDER BY 1",
3275 callback, &data, &zErrMsg
3276 );
3277 zShellStatic = 0;
3278 }else{
3279 raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
3280 rc = 1;
3281 goto meta_command_exit;
3282 }
3283 if( zErrMsg ){
3284 utf8_printf(stderr,"Error: %s\n", zErrMsg);
3285 sqlite3_free(zErrMsg);
3286 rc = 1;
3287 }else if( rc != SQLITE_OK ){
3288 raw_printf(stderr,
3289 "Error: querying sqlite_master and sqlite_temp_master\n");
3290 rc = 1;
3291 }
3292 }else
3293
3294 #ifdef SQLITE_ENABLE_IOTRACE
@@ -3282,11 +3302,11 @@
3302 sqlite3IoTrace = iotracePrintf;
3303 iotrace = stdout;
3304 }else{
3305 iotrace = fopen(azArg[1], "w");
3306 if( iotrace==0 ){
3307 utf8_printf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
3308 sqlite3IoTrace = 0;
3309 rc = 1;
3310 }else{
3311 sqlite3IoTrace = iotracePrintf;
3312 }
@@ -3317,11 +3337,11 @@
3337 for(i=0; i<ArraySize(aLimit); i++){
3338 printf("%20s %d\n", aLimit[i].zLimitName,
3339 sqlite3_limit(p->db, aLimit[i].limitCode, -1));
3340 }
3341 }else if( nArg>3 ){
3342 raw_printf(stderr, "Usage: .limit NAME ?NEW-VALUE?\n");
3343 rc = 1;
3344 goto meta_command_exit;
3345 }else{
3346 int iLimit = -1;
3347 n2 = strlen30(azArg[1]);
@@ -3328,18 +3348,18 @@
3348 for(i=0; i<ArraySize(aLimit); i++){
3349 if( sqlite3_strnicmp(aLimit[i].zLimitName, azArg[1], n2)==0 ){
3350 if( iLimit<0 ){
3351 iLimit = i;
3352 }else{
3353 utf8_printf(stderr, "ambiguous limit: \"%s\"\n", azArg[1]);
3354 rc = 1;
3355 goto meta_command_exit;
3356 }
3357 }
3358 }
3359 if( iLimit<0 ){
3360 utf8_printf(stderr, "unknown limit: \"%s\"\n"
3361 "enter \".limits\" with no arguments for a list.\n",
3362 azArg[1]);
3363 rc = 1;
3364 goto meta_command_exit;
3365 }
@@ -3355,29 +3375,29 @@
3375 #ifndef SQLITE_OMIT_LOAD_EXTENSION
3376 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
3377 const char *zFile, *zProc;
3378 char *zErrMsg = 0;
3379 if( nArg<2 ){
3380 raw_printf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
3381 rc = 1;
3382 goto meta_command_exit;
3383 }
3384 zFile = azArg[1];
3385 zProc = nArg>=3 ? azArg[2] : 0;
3386 open_db(p, 0);
3387 rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
3388 if( rc!=SQLITE_OK ){
3389 utf8_printf(stderr, "Error: %s\n", zErrMsg);
3390 sqlite3_free(zErrMsg);
3391 rc = 1;
3392 }
3393 }else
3394 #endif
3395
3396 if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
3397 if( nArg!=2 ){
3398 raw_printf(stderr, "Usage: .log FILENAME\n");
3399 rc = 1;
3400 }else{
3401 const char *zFile = azArg[1];
3402 output_file_close(p->pLog);
3403 p->pLog = output_file_open(zFile);
@@ -3412,11 +3432,11 @@
3432 }else if( c2=='a' && strncmp(azArg[1],"ascii",n2)==0 ){
3433 p->mode = MODE_Ascii;
3434 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
3435 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
3436 }else {
3437 raw_printf(stderr, "Error: mode should be one of: "
3438 "ascii column csv html insert line list tabs tcl\n");
3439 rc = 1;
3440 }
3441 }else
3442
@@ -3423,11 +3443,11 @@
3443 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
3444 if( nArg==2 ){
3445 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
3446 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
3447 }else{
3448 raw_printf(stderr, "Usage: .nullvalue STRING\n");
3449 rc = 1;
3450 }
3451 }else
3452
3453 if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
@@ -3452,17 +3472,17 @@
3472 if( c=='o'
3473 && (strncmp(azArg[0], "output", n)==0 || strncmp(azArg[0], "once", n)==0)
3474 ){
3475 const char *zFile = nArg>=2 ? azArg[1] : "stdout";
3476 if( nArg>2 ){
3477 utf8_printf(stderr, "Usage: .%s FILE\n", azArg[0]);
3478 rc = 1;
3479 goto meta_command_exit;
3480 }
3481 if( n>1 && strncmp(azArg[0], "once", n)==0 ){
3482 if( nArg<2 ){
3483 raw_printf(stderr, "Usage: .once FILE\n");
3484 rc = 1;
3485 goto meta_command_exit;
3486 }
3487 p->outCount = 2;
3488 }else{
@@ -3469,17 +3489,17 @@
3489 p->outCount = 0;
3490 }
3491 output_reset(p);
3492 if( zFile[0]=='|' ){
3493 #ifdef SQLITE_OMIT_POPEN
3494 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
3495 rc = 1;
3496 p->out = stdout;
3497 #else
3498 p->out = popen(zFile + 1, "w");
3499 if( p->out==0 ){
3500 utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
3501 p->out = stdout;
3502 rc = 1;
3503 }else{
3504 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
3505 }
@@ -3486,11 +3506,11 @@
3506 #endif
3507 }else{
3508 p->out = output_file_open(zFile);
3509 if( p->out==0 ){
3510 if( strcmp(zFile,"off")!=0 ){
3511 utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
3512 }
3513 p->out = stdout;
3514 rc = 1;
3515 } else {
3516 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
@@ -3499,14 +3519,14 @@
3519 }else
3520
3521 if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
3522 int i;
3523 for(i=1; i<nArg; i++){
3524 if( i>1 ) raw_printf(p->out, " ");
3525 utf8_printf(p->out, "%s", azArg[i]);
3526 }
3527 raw_printf(p->out, "\n");
3528 }else
3529
3530 if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){
3531 if( nArg >= 2) {
3532 strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
@@ -3521,17 +3541,17 @@
3541 }else
3542
3543 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
3544 FILE *alt;
3545 if( nArg!=2 ){
3546 raw_printf(stderr, "Usage: .read FILE\n");
3547 rc = 1;
3548 goto meta_command_exit;
3549 }
3550 alt = fopen(azArg[1], "rb");
3551 if( alt==0 ){
3552 utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
3553 rc = 1;
3554 }else{
3555 rc = process_input(p, alt);
3556 fclose(alt);
3557 }
@@ -3549,24 +3569,24 @@
3569 zDb = "main";
3570 }else if( nArg==3 ){
3571 zSrcFile = azArg[2];
3572 zDb = azArg[1];
3573 }else{
3574 raw_printf(stderr, "Usage: .restore ?DB? FILE\n");
3575 rc = 1;
3576 goto meta_command_exit;
3577 }
3578 rc = sqlite3_open(zSrcFile, &pSrc);
3579 if( rc!=SQLITE_OK ){
3580 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
3581 sqlite3_close(pSrc);
3582 return 1;
3583 }
3584 open_db(p, 0);
3585 pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
3586 if( pBackup==0 ){
3587 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3588 sqlite3_close(pSrc);
3589 return 1;
3590 }
3591 while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK
3592 || rc==SQLITE_BUSY ){
@@ -3577,14 +3597,14 @@
3597 }
3598 sqlite3_backup_finish(pBackup);
3599 if( rc==SQLITE_DONE ){
3600 rc = 0;
3601 }else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){
3602 raw_printf(stderr, "Error: source database is busy\n");
3603 rc = 1;
3604 }else{
3605 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3606 rc = 1;
3607 }
3608 sqlite3_close(pSrc);
3609 }else
3610
@@ -3591,14 +3611,14 @@
3611
3612 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
3613 if( nArg==2 ){
3614 p->scanstatsOn = booleanValue(azArg[1]);
3615 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
3616 raw_printf(stderr, "Warning: .scanstats not available in this build.\n");
3617 #endif
3618 }else{
3619 raw_printf(stderr, "Usage: .scanstats on|off\n");
3620 rc = 1;
3621 }
3622 }else
3623
3624 if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
@@ -3661,20 +3681,20 @@
3681 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
3682 "ORDER BY rowid",
3683 callback, &data, &zErrMsg
3684 );
3685 }else{
3686 raw_printf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
3687 rc = 1;
3688 goto meta_command_exit;
3689 }
3690 if( zErrMsg ){
3691 utf8_printf(stderr,"Error: %s\n", zErrMsg);
3692 sqlite3_free(zErrMsg);
3693 rc = 1;
3694 }else if( rc != SQLITE_OK ){
3695 raw_printf(stderr,"Error: querying schema information\n");
3696 rc = 1;
3697 }else{
3698 rc = 0;
3699 }
3700 }else
@@ -3711,11 +3731,11 @@
3731 }else
3732 #endif
3733
3734 if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){
3735 if( nArg<2 || nArg>3 ){
3736 raw_printf(stderr, "Usage: .separator COL ?ROW?\n");
3737 rc = 1;
3738 }
3739 if( nArg>=2 ){
3740 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator,
3741 "%.*s", (int)ArraySize(p->colSeparator)-1, azArg[1]);
@@ -3730,11 +3750,11 @@
3750 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
3751 ){
3752 char *zCmd;
3753 int i, x;
3754 if( nArg<2 ){
3755 raw_printf(stderr, "Usage: .system COMMAND\n");
3756 rc = 1;
3757 goto meta_command_exit;
3758 }
3759 zCmd = sqlite3_mprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]);
3760 for(i=2; i<nArg; i++){
@@ -3741,49 +3761,49 @@
3761 zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"",
3762 zCmd, azArg[i]);
3763 }
3764 x = system(zCmd);
3765 sqlite3_free(zCmd);
3766 if( x ) raw_printf(stderr, "System command returns %d\n", x);
3767 }else
3768
3769 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
3770 int i;
3771 if( nArg!=1 ){
3772 raw_printf(stderr, "Usage: .show\n");
3773 rc = 1;
3774 goto meta_command_exit;
3775 }
3776 utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
3777 utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
3778 utf8_printf(p->out,"%9.9s: %s\n","explain",p->normalMode.valid?"on":"off");
3779 utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
3780 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
3781 utf8_printf(p->out, "%12.12s: ", "nullvalue");
3782 output_c_string(p->out, p->nullValue);
3783 raw_printf(p->out, "\n");
3784 utf8_printf(p->out,"%12.12s: %s\n","output",
3785 strlen30(p->outfile) ? p->outfile : "stdout");
3786 utf8_printf(p->out,"%12.12s: ", "colseparator");
3787 output_c_string(p->out, p->colSeparator);
3788 raw_printf(p->out, "\n");
3789 utf8_printf(p->out,"%12.12s: ", "rowseparator");
3790 output_c_string(p->out, p->rowSeparator);
3791 raw_printf(p->out, "\n");
3792 utf8_printf(p->out, "%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
3793 utf8_printf(p->out, "%12.12s: ", "width");
3794 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
3795 raw_printf(p->out, "%d ", p->colWidth[i]);
3796 }
3797 raw_printf(p->out, "\n");
3798 }else
3799
3800 if( c=='s' && strncmp(azArg[0], "stats", n)==0 ){
3801 if( nArg==2 ){
3802 p->statsOn = booleanValue(azArg[1]);
3803 }else{
3804 raw_printf(stderr, "Usage: .stats on|off\n");
3805 rc = 1;
3806 }
3807 }else
3808
3809 if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
@@ -3880,11 +3900,11 @@
3900 for(j=i; j<nRow; j+=nPrintRow){
3901 char *zSp = j<nPrintRow ? "" : " ";
3902 utf8_printf(p->out, "%s%-*s", zSp, maxlen,
3903 azResult[j] ? azResult[j]:"");
3904 }
3905 raw_printf(p->out, "\n");
3906 }
3907 }
3908
3909 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
3910 sqlite3_free(azResult);
@@ -3923,31 +3943,31 @@
3943 for(i=0; i<ArraySize(aCtrl); i++){
3944 if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){
3945 if( testctrl<0 ){
3946 testctrl = aCtrl[i].ctrlCode;
3947 }else{
3948 utf8_printf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
3949 testctrl = -1;
3950 break;
3951 }
3952 }
3953 }
3954 if( testctrl<0 ) testctrl = (int)integerValue(azArg[1]);
3955 if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
3956 utf8_printf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
3957 }else{
3958 switch(testctrl){
3959
3960 /* sqlite3_test_control(int, db, int) */
3961 case SQLITE_TESTCTRL_OPTIMIZATIONS:
3962 case SQLITE_TESTCTRL_RESERVE:
3963 if( nArg==3 ){
3964 int opt = (int)strtol(azArg[2], 0, 0);
3965 rc2 = sqlite3_test_control(testctrl, p->db, opt);
3966 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
3967 } else {
3968 utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
3969 azArg[1]);
3970 }
3971 break;
3972
3973 /* sqlite3_test_control(int) */
@@ -3955,24 +3975,25 @@
3975 case SQLITE_TESTCTRL_PRNG_RESTORE:
3976 case SQLITE_TESTCTRL_PRNG_RESET:
3977 case SQLITE_TESTCTRL_BYTEORDER:
3978 if( nArg==2 ){
3979 rc2 = sqlite3_test_control(testctrl);
3980 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
3981 } else {
3982 utf8_printf(stderr,"Error: testctrl %s takes no options\n",
3983 azArg[1]);
3984 }
3985 break;
3986
3987 /* sqlite3_test_control(int, uint) */
3988 case SQLITE_TESTCTRL_PENDING_BYTE:
3989 if( nArg==3 ){
3990 unsigned int opt = (unsigned int)integerValue(azArg[2]);
3991 rc2 = sqlite3_test_control(testctrl, opt);
3992 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
3993 } else {
3994 utf8_printf(stderr,"Error: testctrl %s takes a single unsigned"
3995 " int option\n", azArg[1]);
3996 }
3997 break;
3998
3999 /* sqlite3_test_control(int, int) */
@@ -3980,13 +4001,13 @@
4001 case SQLITE_TESTCTRL_ALWAYS:
4002 case SQLITE_TESTCTRL_NEVER_CORRUPT:
4003 if( nArg==3 ){
4004 int opt = booleanValue(azArg[2]);
4005 rc2 = sqlite3_test_control(testctrl, opt);
4006 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
4007 } else {
4008 utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
4009 azArg[1]);
4010 }
4011 break;
4012
4013 /* sqlite3_test_control(int, char *) */
@@ -3993,14 +4014,15 @@
4014 #ifdef SQLITE_N_KEYWORD
4015 case SQLITE_TESTCTRL_ISKEYWORD:
4016 if( nArg==3 ){
4017 const char *opt = azArg[2];
4018 rc2 = sqlite3_test_control(testctrl, opt);
4019 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
4020 } else {
4021 utf8_printf(stderr,
4022 "Error: testctrl %s takes a single char * option\n",
4023 azArg[1]);
4024 }
4025 break;
4026 #endif
4027
4028 case SQLITE_TESTCTRL_IMPOSTER:
@@ -4007,23 +4029,24 @@
4029 if( nArg==5 ){
4030 rc2 = sqlite3_test_control(testctrl, p->db,
4031 azArg[2],
4032 integerValue(azArg[3]),
4033 integerValue(azArg[4]));
4034 raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
4035 }else{
4036 raw_printf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
4037 }
4038 break;
4039
4040 case SQLITE_TESTCTRL_BITVEC_TEST:
4041 case SQLITE_TESTCTRL_FAULT_INSTALL:
4042 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
4043 case SQLITE_TESTCTRL_SCRATCHMALLOC:
4044 default:
4045 utf8_printf(stderr,
4046 "Error: CLI support for testctrl %s not implemented\n",
4047 azArg[1]);
4048 break;
4049 }
4050 }
4051 }else
4052
@@ -4034,23 +4057,23 @@
4057
4058 if( c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 ){
4059 if( nArg==2 ){
4060 enableTimer = booleanValue(azArg[1]);
4061 if( enableTimer && !HAS_TIMER ){
4062 raw_printf(stderr, "Error: timer not available on this system.\n");
4063 enableTimer = 0;
4064 }
4065 }else{
4066 raw_printf(stderr, "Usage: .timer on|off\n");
4067 rc = 1;
4068 }
4069 }else
4070
4071 if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
4072 open_db(p, 0);
4073 if( nArg!=2 ){
4074 raw_printf(stderr, "Usage: .trace FILE|off\n");
4075 rc = 1;
4076 goto meta_command_exit;
4077 }
4078 output_file_close(p->traceOut);
4079 p->traceOut = output_file_open(azArg[1]);
@@ -4064,87 +4087,87 @@
4087 }else
4088
4089 #if SQLITE_USER_AUTHENTICATION
4090 if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
4091 if( nArg<2 ){
4092 raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n");
4093 rc = 1;
4094 goto meta_command_exit;
4095 }
4096 open_db(p, 0);
4097 if( strcmp(azArg[1],"login")==0 ){
4098 if( nArg!=4 ){
4099 raw_printf(stderr, "Usage: .user login USER PASSWORD\n");
4100 rc = 1;
4101 goto meta_command_exit;
4102 }
4103 rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3],
4104 (int)strlen(azArg[3]));
4105 if( rc ){
4106 utf8_printf(stderr, "Authentication failed for user %s\n", azArg[2]);
4107 rc = 1;
4108 }
4109 }else if( strcmp(azArg[1],"add")==0 ){
4110 if( nArg!=5 ){
4111 raw_printf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
4112 rc = 1;
4113 goto meta_command_exit;
4114 }
4115 rc = sqlite3_user_add(p->db, azArg[2],
4116 azArg[3], (int)strlen(azArg[3]),
4117 booleanValue(azArg[4]));
4118 if( rc ){
4119 raw_printf(stderr, "User-Add failed: %d\n", rc);
4120 rc = 1;
4121 }
4122 }else if( strcmp(azArg[1],"edit")==0 ){
4123 if( nArg!=5 ){
4124 raw_printf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
4125 rc = 1;
4126 goto meta_command_exit;
4127 }
4128 rc = sqlite3_user_change(p->db, azArg[2],
4129 azArg[3], (int)strlen(azArg[3]),
4130 booleanValue(azArg[4]));
4131 if( rc ){
4132 raw_printf(stderr, "User-Edit failed: %d\n", rc);
4133 rc = 1;
4134 }
4135 }else if( strcmp(azArg[1],"delete")==0 ){
4136 if( nArg!=3 ){
4137 raw_printf(stderr, "Usage: .user delete USER\n");
4138 rc = 1;
4139 goto meta_command_exit;
4140 }
4141 rc = sqlite3_user_delete(p->db, azArg[2]);
4142 if( rc ){
4143 raw_printf(stderr, "User-Delete failed: %d\n", rc);
4144 rc = 1;
4145 }
4146 }else{
4147 raw_printf(stderr, "Usage: .user login|add|edit|delete ...\n");
4148 rc = 1;
4149 goto meta_command_exit;
4150 }
4151 }else
4152 #endif /* SQLITE_USER_AUTHENTICATION */
4153
4154 if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
4155 utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
4156 sqlite3_libversion(), sqlite3_sourceid());
4157 }else
4158
4159 if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
4160 const char *zDbName = nArg==2 ? azArg[1] : "main";
4161 sqlite3_vfs *pVfs;
4162 if( p->db ){
4163 sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs);
4164 if( pVfs ){
4165 utf8_printf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName);
4166 raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
4167 raw_printf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile);
4168 raw_printf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname);
4169 }
4170 }
4171 }else
4172
4173 if( c=='v' && strncmp(azArg[0], "vfsname", n)==0 ){
@@ -4151,11 +4174,11 @@
4174 const char *zDbName = nArg==2 ? azArg[1] : "main";
4175 char *zVfsName = 0;
4176 if( p->db ){
4177 sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName);
4178 if( zVfsName ){
4179 utf8_printf(p->out, "%s\n", zVfsName);
4180 sqlite3_free(zVfsName);
4181 }
4182 }
4183 }else
4184
@@ -4173,11 +4196,11 @@
4196 p->colWidth[j-1] = (int)integerValue(azArg[j]);
4197 }
4198 }else
4199
4200 {
4201 utf8_printf(stderr, "Error: unknown command or invalid arguments: "
4202 " \"%s\". Enter \".help\" for help\n", azArg[0]);
4203 rc = 1;
4204 }
4205
4206 meta_command_exit:
@@ -4308,11 +4331,11 @@
4331 nLine = strlen30(zLine);
4332 if( nSql+nLine+2>=nAlloc ){
4333 nAlloc = nSql+nLine+100;
4334 zSql = realloc(zSql, nAlloc);
4335 if( zSql==0 ){
4336 raw_printf(stderr, "Error: out of memory\n");
4337 exit(1);
4338 }
4339 }
4340 nSqlPrior = nSql;
4341 if( nSql==0 ){
@@ -4342,19 +4365,19 @@
4365 "Error: near line %d:", startline);
4366 }else{
4367 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
4368 }
4369 if( zErrMsg!=0 ){
4370 utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
4371 sqlite3_free(zErrMsg);
4372 zErrMsg = 0;
4373 }else{
4374 utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
4375 }
4376 errCnt++;
4377 }else if( p->countChanges ){
4378 raw_printf(p->out, "changes: %3d total_changes: %d\n",
4379 sqlite3_changes(p->db), sqlite3_total_changes(p->db));
4380 }
4381 nSql = 0;
4382 if( p->outCount ){
4383 output_reset(p);
@@ -4365,11 +4388,11 @@
4388 nSql = 0;
4389 }
4390 }
4391 if( nSql ){
4392 if( !_all_whitespace(zSql) ){
4393 utf8_printf(stderr, "Error: incomplete SQL: %s\n", zSql);
4394 errCnt++;
4395 }
4396 }
4397 free(zSql);
4398 free(zLine);
@@ -4456,11 +4479,11 @@
4479 FILE *in = NULL;
4480
4481 if (sqliterc == NULL) {
4482 home_dir = find_home_dir();
4483 if( home_dir==0 ){
4484 raw_printf(stderr, "-- warning: cannot find home directory;"
4485 " cannot read ~/.sqliterc\n");
4486 return;
4487 }
4488 sqlite3_initialize();
4489 zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
@@ -4467,11 +4490,11 @@
4490 sqliterc = zBuf;
4491 }
4492 in = fopen(sqliterc,"rb");
4493 if( in ){
4494 if( stdin_is_interactive ){
4495 utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc);
4496 }
4497 process_input(p,in);
4498 fclose(in);
4499 }
4500 sqlite3_free(zBuf);
@@ -4514,18 +4537,18 @@
4537 #ifdef SQLITE_ENABLE_VFSTRACE
4538 " -vfstrace enable tracing of all VFS calls\n"
4539 #endif
4540 ;
4541 static void usage(int showDetail){
4542 utf8_printf(stderr,
4543 "Usage: %s [OPTIONS] FILENAME [SQL]\n"
4544 "FILENAME is the name of an SQLite database. A new database is created\n"
4545 "if the file does not previously exist.\n", Argv0);
4546 if( showDetail ){
4547 utf8_printf(stderr, "OPTIONS include:\n%s", zOptions);
4548 }else{
4549 raw_printf(stderr, "Use the -help option for additional information\n");
4550 }
4551 exit(1);
4552 }
4553
4554 /*
@@ -4569,11 +4592,11 @@
4592 ** Get the argument to an --option. Throw an error and die if no argument
4593 ** is available.
4594 */
4595 static char *cmdline_option_value(int argc, char **argv, int i){
4596 if( i==argc ){
4597 utf8_printf(stderr, "%s: Error: missing argument to %s\n",
4598 argv[0], argv[argc-1]);
4599 exit(1);
4600 }
4601 return argv[i];
4602 }
@@ -4589,11 +4612,11 @@
4612 int nCmd = 0;
4613 char **azCmd = 0;
4614
4615 #if USE_SYSTEM_SQLITE+0!=1
4616 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
4617 utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
4618 sqlite3_sourceid(), SQLITE_SOURCE_ID);
4619 exit(1);
4620 }
4621 #endif
4622 setBinaryMode(stdin);
@@ -4638,11 +4661,11 @@
4661 ** mean that nothing is read from stdin */
4662 readStdin = 0;
4663 nCmd++;
4664 azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
4665 if( azCmd==0 ){
4666 raw_printf(stderr, "out of memory\n");
4667 exit(1);
4668 }
4669 azCmd[nCmd-1] = z;
4670 }
4671 }
@@ -4720,21 +4743,21 @@
4743 }else if( strcmp(z,"-vfs")==0 ){
4744 sqlite3_vfs *pVfs = sqlite3_vfs_find(cmdline_option_value(argc,argv,++i));
4745 if( pVfs ){
4746 sqlite3_vfs_register(pVfs, 1);
4747 }else{
4748 utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
4749 exit(1);
4750 }
4751 }
4752 }
4753 if( data.zDbFilename==0 ){
4754 #ifndef SQLITE_OMIT_MEMORYDB
4755 data.zDbFilename = ":memory:";
4756 warnInmemoryDb = argc==1;
4757 #else
4758 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
4759 return 1;
4760 #endif
4761 }
4762 data.out = stdout;
4763
@@ -4852,20 +4875,20 @@
4875 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
4876 }else{
4877 open_db(&data, 0);
4878 rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
4879 if( zErrMsg!=0 ){
4880 utf8_printf(stderr,"Error: %s\n", zErrMsg);
4881 if( bail_on_error ) return rc!=0 ? rc : 1;
4882 }else if( rc!=0 ){
4883 utf8_printf(stderr,"Error: unable to process SQL \"%s\"\n", z);
4884 if( bail_on_error ) return rc;
4885 }
4886 }
4887 }else{
4888 utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
4889 raw_printf(stderr,"Use -help for a list of options.\n");
4890 return 1;
4891 }
4892 }
4893
4894 if( !readStdin ){
@@ -4879,14 +4902,14 @@
4902 if( rc ) return rc==2 ? 0 : rc;
4903 }else{
4904 open_db(&data, 0);
4905 rc = shell_exec(data.db, azCmd[i], shell_callback, &data, &zErrMsg);
4906 if( zErrMsg!=0 ){
4907 utf8_printf(stderr,"Error: %s\n", zErrMsg);
4908 return rc!=0 ? rc : 1;
4909 }else if( rc!=0 ){
4910 utf8_printf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
4911 return rc;
4912 }
4913 }
4914 }
4915 free(azCmd);
4916
+22 -14
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325325
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326326
** [sqlite_version()] and [sqlite_source_id()].
327327
*/
328328
#define SQLITE_VERSION "3.10.0"
329329
#define SQLITE_VERSION_NUMBER 3010000
330
-#define SQLITE_SOURCE_ID "2016-01-01 16:42:09 3e852804c85a5c9f4c4ffafd55d03af6d19fe5cc"
330
+#define SQLITE_SOURCE_ID "2016-01-06 11:01:07 fd0a50f0797d154fefff724624f00548b5320566"
331331
332332
/*
333333
** CAPI3REF: Run-Time Library Version Numbers
334334
** KEYWORDS: sqlite3_version, sqlite3_sourceid
335335
**
@@ -13759,13 +13759,13 @@
1375913759
*/
1376013760
struct StrAccum {
1376113761
sqlite3 *db; /* Optional database for lookaside. Can be NULL */
1376213762
char *zBase; /* A base allocation. Not from malloc. */
1376313763
char *zText; /* The string collected so far */
13764
- int nChar; /* Length of the string so far */
13765
- int nAlloc; /* Amount of space allocated in zText */
13766
- int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
13764
+ u32 nChar; /* Length of the string so far */
13765
+ u32 nAlloc; /* Amount of space allocated in zText */
13766
+ u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
1376713767
u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
1376813768
u8 bMalloced; /* zText points to allocated space */
1376913769
};
1377013770
#define STRACCUM_NOMEM 1
1377113771
#define STRACCUM_TOOBIG 2
@@ -69136,23 +69136,31 @@
6913669136
**
6913769137
** See also: allocateCursor().
6913869138
*/
6913969139
nMem += nCursor;
6914069140
69141
- /* Allocate space for memory registers, SQL variables, VDBE cursors and
69142
- ** an array to marshal SQL function arguments in.
69141
+ /* zCsr will initially point to nFree bytes of unused space at the
69142
+ ** end of the opcode array, p->aOp. The computation of nFree is
69143
+ ** conservative - it might be smaller than the true number of free
69144
+ ** bytes, but never larger. nFree must be a multiple of 8 - it is
69145
+ ** rounded down if is not.
6914369146
*/
69144
- zCsr = ((u8*)p->aOp) + ROUND8(sizeof(Op)*p->nOp); /* Available space */
69145
- nFree = pParse->szOpAlloc - ROUND8(sizeof(Op)*p->nOp); /* Size of zCsr */
69147
+ n = ROUND8(sizeof(Op)*p->nOp); /* Bytes of opcode space used */
69148
+ zCsr = &((u8*)p->aOp)[n]; /* Unused opcode space */
69149
+ assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
69150
+ nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused space */
69151
+ assert( nFree>=0 );
69152
+ if( nFree>0 ){
69153
+ memset(zCsr, 0, nFree);
69154
+ assert( EIGHT_BYTE_ALIGNMENT(&zCsr[nFree]) );
69155
+ }
6914669156
6914769157
resolveP2Values(p, &nArg);
6914869158
p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
6914969159
if( pParse->explain && nMem<10 ){
6915069160
nMem = 10;
6915169161
}
69152
- memset(zCsr, 0, nFree);
69153
- assert( EIGHT_BYTE_ALIGNMENT(&zCsr[nFree]) );
6915469162
p->expired = 0;
6915569163
6915669164
/* Memory for registers, parameters, cursor, etc, is allocated in two
6915769165
** passes. On the first pass, we try to reuse unused space at the
6915869166
** end of the opcode array. If we are unable to satisfy all memory
@@ -76201,11 +76209,11 @@
7620176209
){
7620276210
rc = SQLITE_CORRUPT_BKPT;
7620376211
goto op_column_error;
7620476212
}
7620576213
}else{
76206
- VVA_ONLY( t = 0; ) /* Only needed by assert() statements */
76214
+ t = 0;
7620776215
}
7620876216
7620976217
/* If after trying to extract new entries from the header, nHdrParsed is
7621076218
** still not up to p2, that means that the record has fewer than p2
7621176219
** columns. So the result will be either the default value or a NULL.
@@ -77079,11 +77087,11 @@
7707977087
7708077088
open_cursor_set_hints:
7708177089
assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
7708277090
assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ );
7708377091
testcase( pOp->p5 & OPFLAG_BULKCSR );
77084
-#ifdef SQLITE_ENABLE_CURSOR_HINT
77092
+#ifdef SQLITE_ENABLE_CURSOR_HINTS
7708577093
testcase( pOp->p2 & OPFLAG_SEEKEQ );
7708677094
#endif
7708777095
sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
7708877096
(pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
7708977097
break;
@@ -95465,11 +95473,11 @@
9546595473
9546695474
/* Make sure every column of the PRIMARY KEY is NOT NULL. (Except,
9546795475
** do not enforce this for imposter tables.) */
9546895476
if( !db->init.imposterTable ){
9546995477
for(i=0; i<nPk; i++){
95470
- pTab->aCol[pPk->aiColumn[i]].notNull = 1;
95478
+ pTab->aCol[pPk->aiColumn[i]].notNull = OE_Abort;
9547195479
}
9547295480
pPk->uniqNotNull = 1;
9547395481
}
9547495482
9547595483
/* The root page of the PRIMARY KEY is the table root page */
@@ -182239,11 +182247,11 @@
182239182247
sqlite3_context *pCtx, /* Function call context */
182240182248
int nArg, /* Number of args */
182241182249
sqlite3_value **apVal /* Function arguments */
182242182250
){
182243182251
assert( nArg==0 );
182244
- sqlite3_result_text(pCtx, "fts5: 2015-12-16 19:55:57 cb22efaf50d83d9a73fdf8d986e6ea2fc6500cfb", -1, SQLITE_TRANSIENT);
182252
+ sqlite3_result_text(pCtx, "fts5: 2016-01-06 11:01:07 fd0a50f0797d154fefff724624f00548b5320566", -1, SQLITE_TRANSIENT);
182245182253
}
182246182254
182247182255
static int fts5Init(sqlite3 *db){
182248182256
static const sqlite3_module fts5Mod = {
182249182257
/* iVersion */ 2,
182250182258
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.10.0"
329 #define SQLITE_VERSION_NUMBER 3010000
330 #define SQLITE_SOURCE_ID "2016-01-01 16:42:09 3e852804c85a5c9f4c4ffafd55d03af6d19fe5cc"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -13759,13 +13759,13 @@
13759 */
13760 struct StrAccum {
13761 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
13762 char *zBase; /* A base allocation. Not from malloc. */
13763 char *zText; /* The string collected so far */
13764 int nChar; /* Length of the string so far */
13765 int nAlloc; /* Amount of space allocated in zText */
13766 int mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
13767 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
13768 u8 bMalloced; /* zText points to allocated space */
13769 };
13770 #define STRACCUM_NOMEM 1
13771 #define STRACCUM_TOOBIG 2
@@ -69136,23 +69136,31 @@
69136 **
69137 ** See also: allocateCursor().
69138 */
69139 nMem += nCursor;
69140
69141 /* Allocate space for memory registers, SQL variables, VDBE cursors and
69142 ** an array to marshal SQL function arguments in.
 
 
 
69143 */
69144 zCsr = ((u8*)p->aOp) + ROUND8(sizeof(Op)*p->nOp); /* Available space */
69145 nFree = pParse->szOpAlloc - ROUND8(sizeof(Op)*p->nOp); /* Size of zCsr */
 
 
 
 
 
 
 
69146
69147 resolveP2Values(p, &nArg);
69148 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
69149 if( pParse->explain && nMem<10 ){
69150 nMem = 10;
69151 }
69152 memset(zCsr, 0, nFree);
69153 assert( EIGHT_BYTE_ALIGNMENT(&zCsr[nFree]) );
69154 p->expired = 0;
69155
69156 /* Memory for registers, parameters, cursor, etc, is allocated in two
69157 ** passes. On the first pass, we try to reuse unused space at the
69158 ** end of the opcode array. If we are unable to satisfy all memory
@@ -76201,11 +76209,11 @@
76201 ){
76202 rc = SQLITE_CORRUPT_BKPT;
76203 goto op_column_error;
76204 }
76205 }else{
76206 VVA_ONLY( t = 0; ) /* Only needed by assert() statements */
76207 }
76208
76209 /* If after trying to extract new entries from the header, nHdrParsed is
76210 ** still not up to p2, that means that the record has fewer than p2
76211 ** columns. So the result will be either the default value or a NULL.
@@ -77079,11 +77087,11 @@
77079
77080 open_cursor_set_hints:
77081 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
77082 assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ );
77083 testcase( pOp->p5 & OPFLAG_BULKCSR );
77084 #ifdef SQLITE_ENABLE_CURSOR_HINT
77085 testcase( pOp->p2 & OPFLAG_SEEKEQ );
77086 #endif
77087 sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
77088 (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
77089 break;
@@ -95465,11 +95473,11 @@
95465
95466 /* Make sure every column of the PRIMARY KEY is NOT NULL. (Except,
95467 ** do not enforce this for imposter tables.) */
95468 if( !db->init.imposterTable ){
95469 for(i=0; i<nPk; i++){
95470 pTab->aCol[pPk->aiColumn[i]].notNull = 1;
95471 }
95472 pPk->uniqNotNull = 1;
95473 }
95474
95475 /* The root page of the PRIMARY KEY is the table root page */
@@ -182239,11 +182247,11 @@
182239 sqlite3_context *pCtx, /* Function call context */
182240 int nArg, /* Number of args */
182241 sqlite3_value **apVal /* Function arguments */
182242 ){
182243 assert( nArg==0 );
182244 sqlite3_result_text(pCtx, "fts5: 2015-12-16 19:55:57 cb22efaf50d83d9a73fdf8d986e6ea2fc6500cfb", -1, SQLITE_TRANSIENT);
182245 }
182246
182247 static int fts5Init(sqlite3 *db){
182248 static const sqlite3_module fts5Mod = {
182249 /* iVersion */ 2,
182250
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.10.0"
329 #define SQLITE_VERSION_NUMBER 3010000
330 #define SQLITE_SOURCE_ID "2016-01-06 11:01:07 fd0a50f0797d154fefff724624f00548b5320566"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -13759,13 +13759,13 @@
13759 */
13760 struct StrAccum {
13761 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
13762 char *zBase; /* A base allocation. Not from malloc. */
13763 char *zText; /* The string collected so far */
13764 u32 nChar; /* Length of the string so far */
13765 u32 nAlloc; /* Amount of space allocated in zText */
13766 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
13767 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
13768 u8 bMalloced; /* zText points to allocated space */
13769 };
13770 #define STRACCUM_NOMEM 1
13771 #define STRACCUM_TOOBIG 2
@@ -69136,23 +69136,31 @@
69136 **
69137 ** See also: allocateCursor().
69138 */
69139 nMem += nCursor;
69140
69141 /* zCsr will initially point to nFree bytes of unused space at the
69142 ** end of the opcode array, p->aOp. The computation of nFree is
69143 ** conservative - it might be smaller than the true number of free
69144 ** bytes, but never larger. nFree must be a multiple of 8 - it is
69145 ** rounded down if is not.
69146 */
69147 n = ROUND8(sizeof(Op)*p->nOp); /* Bytes of opcode space used */
69148 zCsr = &((u8*)p->aOp)[n]; /* Unused opcode space */
69149 assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
69150 nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused space */
69151 assert( nFree>=0 );
69152 if( nFree>0 ){
69153 memset(zCsr, 0, nFree);
69154 assert( EIGHT_BYTE_ALIGNMENT(&zCsr[nFree]) );
69155 }
69156
69157 resolveP2Values(p, &nArg);
69158 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
69159 if( pParse->explain && nMem<10 ){
69160 nMem = 10;
69161 }
 
 
69162 p->expired = 0;
69163
69164 /* Memory for registers, parameters, cursor, etc, is allocated in two
69165 ** passes. On the first pass, we try to reuse unused space at the
69166 ** end of the opcode array. If we are unable to satisfy all memory
@@ -76201,11 +76209,11 @@
76209 ){
76210 rc = SQLITE_CORRUPT_BKPT;
76211 goto op_column_error;
76212 }
76213 }else{
76214 t = 0;
76215 }
76216
76217 /* If after trying to extract new entries from the header, nHdrParsed is
76218 ** still not up to p2, that means that the record has fewer than p2
76219 ** columns. So the result will be either the default value or a NULL.
@@ -77079,11 +77087,11 @@
77087
77088 open_cursor_set_hints:
77089 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
77090 assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ );
77091 testcase( pOp->p5 & OPFLAG_BULKCSR );
77092 #ifdef SQLITE_ENABLE_CURSOR_HINTS
77093 testcase( pOp->p2 & OPFLAG_SEEKEQ );
77094 #endif
77095 sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
77096 (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
77097 break;
@@ -95465,11 +95473,11 @@
95473
95474 /* Make sure every column of the PRIMARY KEY is NOT NULL. (Except,
95475 ** do not enforce this for imposter tables.) */
95476 if( !db->init.imposterTable ){
95477 for(i=0; i<nPk; i++){
95478 pTab->aCol[pPk->aiColumn[i]].notNull = OE_Abort;
95479 }
95480 pPk->uniqNotNull = 1;
95481 }
95482
95483 /* The root page of the PRIMARY KEY is the table root page */
@@ -182239,11 +182247,11 @@
182247 sqlite3_context *pCtx, /* Function call context */
182248 int nArg, /* Number of args */
182249 sqlite3_value **apVal /* Function arguments */
182250 ){
182251 assert( nArg==0 );
182252 sqlite3_result_text(pCtx, "fts5: 2016-01-06 11:01:07 fd0a50f0797d154fefff724624f00548b5320566", -1, SQLITE_TRANSIENT);
182253 }
182254
182255 static int fts5Init(sqlite3 *db){
182256 static const sqlite3_module fts5Mod = {
182257 /* iVersion */ 2,
182258
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114114
#define SQLITE_VERSION "3.10.0"
115115
#define SQLITE_VERSION_NUMBER 3010000
116
-#define SQLITE_SOURCE_ID "2016-01-01 16:42:09 3e852804c85a5c9f4c4ffafd55d03af6d19fe5cc"
116
+#define SQLITE_SOURCE_ID "2016-01-06 11:01:07 fd0a50f0797d154fefff724624f00548b5320566"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
122122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.10.0"
115 #define SQLITE_VERSION_NUMBER 3010000
116 #define SQLITE_SOURCE_ID "2016-01-01 16:42:09 3e852804c85a5c9f4c4ffafd55d03af6d19fe5cc"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.10.0"
115 #define SQLITE_VERSION_NUMBER 3010000
116 #define SQLITE_SOURCE_ID "2016-01-06 11:01:07 fd0a50f0797d154fefff724624f00548b5320566"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122
+2 -2
--- src/zip.c
+++ src/zip.c
@@ -142,18 +142,18 @@
142142
char zOutBuf[100000];
143143
144144
/* Fill in as much of the header as we know.
145145
*/
146146
nBlob = pFile ? blob_size(pFile) : 0;
147
- if( nBlob>0 ){
147
+ if( pFile ){ /* This is a file, possibly empty... */
148148
iMethod = 8;
149149
switch( mPerm ){
150150
case PERM_LNK: iMode = 0120755; break;
151151
case PERM_EXE: iMode = 0100755; break;
152152
default: iMode = 0100644; break;
153153
}
154
- }else{
154
+ }else{ /* This is a directory, no blob... */
155155
iMethod = 0;
156156
iMode = 040755;
157157
}
158158
nameLen = strlen(zName);
159159
memset(zHdr, 0, sizeof(zHdr));
160160
--- src/zip.c
+++ src/zip.c
@@ -142,18 +142,18 @@
142 char zOutBuf[100000];
143
144 /* Fill in as much of the header as we know.
145 */
146 nBlob = pFile ? blob_size(pFile) : 0;
147 if( nBlob>0 ){
148 iMethod = 8;
149 switch( mPerm ){
150 case PERM_LNK: iMode = 0120755; break;
151 case PERM_EXE: iMode = 0100755; break;
152 default: iMode = 0100644; break;
153 }
154 }else{
155 iMethod = 0;
156 iMode = 040755;
157 }
158 nameLen = strlen(zName);
159 memset(zHdr, 0, sizeof(zHdr));
160
--- src/zip.c
+++ src/zip.c
@@ -142,18 +142,18 @@
142 char zOutBuf[100000];
143
144 /* Fill in as much of the header as we know.
145 */
146 nBlob = pFile ? blob_size(pFile) : 0;
147 if( pFile ){ /* This is a file, possibly empty... */
148 iMethod = 8;
149 switch( mPerm ){
150 case PERM_LNK: iMode = 0120755; break;
151 case PERM_EXE: iMode = 0100755; break;
152 default: iMode = 0100644; break;
153 }
154 }else{ /* This is a directory, no blob... */
155 iMethod = 0;
156 iMode = 040755;
157 }
158 nameLen = strlen(zName);
159 memset(zHdr, 0, sizeof(zHdr));
160
+2 -2
--- src/zip.c
+++ src/zip.c
@@ -142,18 +142,18 @@
142142
char zOutBuf[100000];
143143
144144
/* Fill in as much of the header as we know.
145145
*/
146146
nBlob = pFile ? blob_size(pFile) : 0;
147
- if( nBlob>0 ){
147
+ if( pFile ){ /* This is a file, possibly empty... */
148148
iMethod = 8;
149149
switch( mPerm ){
150150
case PERM_LNK: iMode = 0120755; break;
151151
case PERM_EXE: iMode = 0100755; break;
152152
default: iMode = 0100644; break;
153153
}
154
- }else{
154
+ }else{ /* This is a directory, no blob... */
155155
iMethod = 0;
156156
iMode = 040755;
157157
}
158158
nameLen = strlen(zName);
159159
memset(zHdr, 0, sizeof(zHdr));
160160
--- src/zip.c
+++ src/zip.c
@@ -142,18 +142,18 @@
142 char zOutBuf[100000];
143
144 /* Fill in as much of the header as we know.
145 */
146 nBlob = pFile ? blob_size(pFile) : 0;
147 if( nBlob>0 ){
148 iMethod = 8;
149 switch( mPerm ){
150 case PERM_LNK: iMode = 0120755; break;
151 case PERM_EXE: iMode = 0100755; break;
152 default: iMode = 0100644; break;
153 }
154 }else{
155 iMethod = 0;
156 iMode = 040755;
157 }
158 nameLen = strlen(zName);
159 memset(zHdr, 0, sizeof(zHdr));
160
--- src/zip.c
+++ src/zip.c
@@ -142,18 +142,18 @@
142 char zOutBuf[100000];
143
144 /* Fill in as much of the header as we know.
145 */
146 nBlob = pFile ? blob_size(pFile) : 0;
147 if( pFile ){ /* This is a file, possibly empty... */
148 iMethod = 8;
149 switch( mPerm ){
150 case PERM_LNK: iMode = 0120755; break;
151 case PERM_EXE: iMode = 0100755; break;
152 default: iMode = 0100644; break;
153 }
154 }else{ /* This is a directory, no blob... */
155 iMethod = 0;
156 iMode = 040755;
157 }
158 nameLen = strlen(zName);
159 memset(zHdr, 0, sizeof(zHdr));
160
+3 -3
--- test/clean.test
+++ test/clean.test
@@ -57,11 +57,11 @@
5757
test clean-5 {[normalize_result] eq {}}
5858
5959
###############################################################################
6060
6161
fossil undo
62
-test clean-6 {[normalize_result] eq {NEW f2}}
62
+test clean-6 {[normalize_result] eq {NEW f2}}
6363
test clean-7 {[read_file f2] eq "f2 line"}
6464
6565
###############################################################################
6666
6767
fossil extra
@@ -87,11 +87,11 @@
8787
test clean-11 {[normalize_result] eq {f3}}
8888
8989
###############################################################################
9090
9191
fossil undo
92
-test clean-12 {[normalize_result] eq {NEW f2}}
92
+test clean-12 {[normalize_result] eq {NEW f2}}
9393
test clean-13 {[read_file f2] eq "f2 line"}
9494
test clean-14 {[read_file f3] eq [string repeat ABCDEFGHIJK 1048576]}
9595
9696
###############################################################################
9797
@@ -112,11 +112,11 @@
112112
test clean-17 {[normalize_result] eq {}}
113113
114114
###############################################################################
115115
116116
fossil undo
117
-test clean-18 {[normalize_result] eq {NEW f2}}
117
+test clean-18 {[normalize_result] eq {NEW f2}}
118118
test clean-19 {[read_file f2] eq "f2 line"}
119119
120120
###############################################################################
121121
122122
write_file f4 [string repeat KJIHGFEDCBA 1048576]
123123
--- test/clean.test
+++ test/clean.test
@@ -57,11 +57,11 @@
57 test clean-5 {[normalize_result] eq {}}
58
59 ###############################################################################
60
61 fossil undo
62 test clean-6 {[normalize_result] eq {NEW f2}}
63 test clean-7 {[read_file f2] eq "f2 line"}
64
65 ###############################################################################
66
67 fossil extra
@@ -87,11 +87,11 @@
87 test clean-11 {[normalize_result] eq {f3}}
88
89 ###############################################################################
90
91 fossil undo
92 test clean-12 {[normalize_result] eq {NEW f2}}
93 test clean-13 {[read_file f2] eq "f2 line"}
94 test clean-14 {[read_file f3] eq [string repeat ABCDEFGHIJK 1048576]}
95
96 ###############################################################################
97
@@ -112,11 +112,11 @@
112 test clean-17 {[normalize_result] eq {}}
113
114 ###############################################################################
115
116 fossil undo
117 test clean-18 {[normalize_result] eq {NEW f2}}
118 test clean-19 {[read_file f2] eq "f2 line"}
119
120 ###############################################################################
121
122 write_file f4 [string repeat KJIHGFEDCBA 1048576]
123
--- test/clean.test
+++ test/clean.test
@@ -57,11 +57,11 @@
57 test clean-5 {[normalize_result] eq {}}
58
59 ###############################################################################
60
61 fossil undo
62 test clean-6 {[normalize_result] eq {NEW f2}}
63 test clean-7 {[read_file f2] eq "f2 line"}
64
65 ###############################################################################
66
67 fossil extra
@@ -87,11 +87,11 @@
87 test clean-11 {[normalize_result] eq {f3}}
88
89 ###############################################################################
90
91 fossil undo
92 test clean-12 {[normalize_result] eq {NEW f2}}
93 test clean-13 {[read_file f2] eq "f2 line"}
94 test clean-14 {[read_file f3] eq [string repeat ABCDEFGHIJK 1048576]}
95
96 ###############################################################################
97
@@ -112,11 +112,11 @@
112 test clean-17 {[normalize_result] eq {}}
113
114 ###############################################################################
115
116 fossil undo
117 test clean-18 {[normalize_result] eq {NEW f2}}
118 test clean-19 {[read_file f2] eq "f2 line"}
119
120 ###############################################################################
121
122 write_file f4 [string repeat KJIHGFEDCBA 1048576]
123
+16 -16
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -68,11 +68,11 @@
6868
fossil mv ../f1 .
6969
test mv-soft-relative-1 {$RESULT eq "RENAME f1 subdir1/f1"}
7070
7171
fossil revert
7272
test mv-soft-relative-2 {
73
- [normalize_result] eq "DELETE: subdir1/f1\nREVERTED: f1${undoMsg}"
73
+ [normalize_result] eq "DELETE subdir1/f1\nREVERT f1${undoMsg}"
7474
}
7575
7676
cd $rootDir
7777
7878
###################################
@@ -85,11 +85,11 @@
8585
fossil mv ../f2 ./f2
8686
test mv-soft-relative-3 {$RESULT eq "RENAME f2 subdir2/f2"}
8787
8888
fossil revert
8989
test mv-soft-relative-4 {
90
- [normalize_result] eq "DELETE: subdir2/f2\nREVERTED: f2${undoMsg}"
90
+ [normalize_result] eq "DELETE subdir2/f2\nREVERT f2${undoMsg}"
9191
}
9292
9393
cd $rootDir
9494
9595
########################################
@@ -104,11 +104,11 @@
104104
[normalize_result] eq "RENAME f3 subdir3/f3\nMOVED_FILE ${rootDir}/f3"
105105
}
106106
107107
fossil revert
108108
test mv-hard-relative-2 {
109
- [normalize_result] eq "DELETE: subdir3/f3\nREVERTED: f3${undoMsg}"
109
+ [normalize_result] eq "DELETE subdir3/f3\nREVERT f3${undoMsg}"
110110
}
111111
112112
cd $rootDir
113113
114114
###################################
@@ -123,11 +123,11 @@
123123
[normalize_result] eq "RENAME f4 subdir4/f4\nMOVED_FILE ${rootDir}/f4"
124124
}
125125
126126
fossil revert
127127
test mv-hard-relative-4 {
128
- [normalize_result] eq "DELETE: subdir4/f4\nREVERTED: f4${undoMsg}"
128
+ [normalize_result] eq "DELETE subdir4/f4\nREVERT f4${undoMsg}"
129129
}
130130
131131
cd $rootDir
132132
133133
########################################
@@ -140,11 +140,11 @@
140140
fossil mv [file join $rootDir f5] [file join $rootDir subdir5]
141141
test mv-soft-absolute-1 {$RESULT eq "RENAME f5 subdir5/f5"}
142142
143143
fossil revert
144144
test mv-soft-absolute-2 {
145
- [normalize_result] eq "DELETE: subdir5/f5\nREVERTED: f5${undoMsg}"
145
+ [normalize_result] eq "DELETE subdir5/f5\nREVERT f5${undoMsg}"
146146
}
147147
148148
cd $rootDir
149149
150150
###################################
@@ -157,11 +157,11 @@
157157
fossil mv [file join $rootDir f6] [file join $rootDir subdir6 f6]
158158
test mv-soft-absolute-3 {$RESULT eq "RENAME f6 subdir6/f6"}
159159
160160
fossil revert
161161
test mv-soft-absolute-4 {
162
- [normalize_result] eq "DELETE: subdir6/f6\nREVERTED: f6${undoMsg}"
162
+ [normalize_result] eq "DELETE subdir6/f6\nREVERT f6${undoMsg}"
163163
}
164164
165165
cd $rootDir
166166
167167
########################################
@@ -176,11 +176,11 @@
176176
[normalize_result] eq "RENAME f7 subdir7/f7\nMOVED_FILE ${rootDir}/f7"
177177
}
178178
179179
fossil revert
180180
test mv-hard-absolute-2 {
181
- [normalize_result] eq "DELETE: subdir7/f7\nREVERTED: f7${undoMsg}"
181
+ [normalize_result] eq "DELETE subdir7/f7\nREVERT f7${undoMsg}"
182182
}
183183
184184
cd $rootDir
185185
186186
###################################
@@ -195,11 +195,11 @@
195195
[normalize_result] eq "RENAME f8 subdir8/f8\nMOVED_FILE ${rootDir}/f8"
196196
}
197197
198198
fossil revert
199199
test mv-hard-absolute-4 {
200
- [normalize_result] eq "DELETE: subdir8/f8\nREVERTED: f8${undoMsg}"
200
+ [normalize_result] eq "DELETE subdir8/f8\nREVERT f8${undoMsg}"
201201
}
202202
203203
cd $rootDir
204204
205205
##########################################
@@ -221,11 +221,11 @@
221221
}
222222
223223
fossil revert
224224
test rm-soft-relative-4 {
225225
[normalize_result] eq \
226
- "REVERTED: subdirB/f9\nREVERTED: subdirC/f10\nREVERTED: subdirC/f11${undoMsg}"
226
+ "REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
227227
}
228228
229229
cd $rootDir
230230
231231
######################################
@@ -238,11 +238,11 @@
238238
fossil rm ../f2
239239
test rm-soft-relative-5 {$RESULT eq "DELETED f2"}
240240
241241
fossil revert
242242
test rm-soft-relative-6 {
243
- [normalize_result] eq "REVERTED: f2${undoMsg}"
243
+ [normalize_result] eq "REVERT f2${undoMsg}"
244244
}
245245
246246
cd $rootDir
247247
248248
###########################################
@@ -271,11 +271,11 @@
271271
}
272272
273273
fossil revert
274274
test rm-hard-relative-4 {
275275
[normalize_result] eq \
276
- "REVERTED: subdirB/f9\nREVERTED: subdirC/f10\nREVERTED: subdirC/f11${undoMsg}"
276
+ "REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
277277
}
278278
279279
cd $rootDir
280280
281281
######################################
@@ -290,11 +290,11 @@
290290
[normalize_result] eq "DELETED f4\nDELETED_FILE ${rootDir}/f4"
291291
}
292292
293293
fossil revert
294294
test rm-hard-relative-6 {
295
- [normalize_result] eq "REVERTED: f4${undoMsg}"
295
+ [normalize_result] eq "REVERT f4${undoMsg}"
296296
}
297297
298298
cd $rootDir
299299
300300
###########################################
@@ -316,11 +316,11 @@
316316
}
317317
318318
fossil revert
319319
test rm-soft-absolute-4 {
320320
[normalize_result] eq \
321
- "REVERTED: subdirB/f9\nREVERTED: subdirC/f10\nREVERTED: subdirC/f11${undoMsg}"
321
+ "REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
322322
}
323323
324324
cd $rootDir
325325
326326
######################################
@@ -333,11 +333,11 @@
333333
fossil rm [file join $rootDir f6]
334334
test rm-soft-absolute-5 {$RESULT eq "DELETED f6"}
335335
336336
fossil revert
337337
test rm-soft-absolute-6 {
338
- [normalize_result] eq "REVERTED: f6${undoMsg}"
338
+ [normalize_result] eq "REVERT f6${undoMsg}"
339339
}
340340
341341
cd $rootDir
342342
343343
###########################################
@@ -364,11 +364,11 @@
364364
}
365365
366366
fossil revert
367367
test rm-hard-absolute-4 {
368368
[normalize_result] eq \
369
- "REVERTED: subdirB/f9\nREVERTED: subdirC/f10\nREVERTED: subdirC/f11${undoMsg}"
369
+ "REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
370370
}
371371
372372
cd $rootDir
373373
374374
######################################
@@ -383,9 +383,9 @@
383383
[normalize_result] eq "DELETED f8\nDELETED_FILE ${rootDir}/f8"
384384
}
385385
386386
fossil revert
387387
test rm-hard-absolute-6 {
388
- [normalize_result] eq "REVERTED: f8${undoMsg}"
388
+ [normalize_result] eq "REVERT f8${undoMsg}"
389389
}
390390
391391
cd $rootDir
392392
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -68,11 +68,11 @@
68 fossil mv ../f1 .
69 test mv-soft-relative-1 {$RESULT eq "RENAME f1 subdir1/f1"}
70
71 fossil revert
72 test mv-soft-relative-2 {
73 [normalize_result] eq "DELETE: subdir1/f1\nREVERTED: f1${undoMsg}"
74 }
75
76 cd $rootDir
77
78 ###################################
@@ -85,11 +85,11 @@
85 fossil mv ../f2 ./f2
86 test mv-soft-relative-3 {$RESULT eq "RENAME f2 subdir2/f2"}
87
88 fossil revert
89 test mv-soft-relative-4 {
90 [normalize_result] eq "DELETE: subdir2/f2\nREVERTED: f2${undoMsg}"
91 }
92
93 cd $rootDir
94
95 ########################################
@@ -104,11 +104,11 @@
104 [normalize_result] eq "RENAME f3 subdir3/f3\nMOVED_FILE ${rootDir}/f3"
105 }
106
107 fossil revert
108 test mv-hard-relative-2 {
109 [normalize_result] eq "DELETE: subdir3/f3\nREVERTED: f3${undoMsg}"
110 }
111
112 cd $rootDir
113
114 ###################################
@@ -123,11 +123,11 @@
123 [normalize_result] eq "RENAME f4 subdir4/f4\nMOVED_FILE ${rootDir}/f4"
124 }
125
126 fossil revert
127 test mv-hard-relative-4 {
128 [normalize_result] eq "DELETE: subdir4/f4\nREVERTED: f4${undoMsg}"
129 }
130
131 cd $rootDir
132
133 ########################################
@@ -140,11 +140,11 @@
140 fossil mv [file join $rootDir f5] [file join $rootDir subdir5]
141 test mv-soft-absolute-1 {$RESULT eq "RENAME f5 subdir5/f5"}
142
143 fossil revert
144 test mv-soft-absolute-2 {
145 [normalize_result] eq "DELETE: subdir5/f5\nREVERTED: f5${undoMsg}"
146 }
147
148 cd $rootDir
149
150 ###################################
@@ -157,11 +157,11 @@
157 fossil mv [file join $rootDir f6] [file join $rootDir subdir6 f6]
158 test mv-soft-absolute-3 {$RESULT eq "RENAME f6 subdir6/f6"}
159
160 fossil revert
161 test mv-soft-absolute-4 {
162 [normalize_result] eq "DELETE: subdir6/f6\nREVERTED: f6${undoMsg}"
163 }
164
165 cd $rootDir
166
167 ########################################
@@ -176,11 +176,11 @@
176 [normalize_result] eq "RENAME f7 subdir7/f7\nMOVED_FILE ${rootDir}/f7"
177 }
178
179 fossil revert
180 test mv-hard-absolute-2 {
181 [normalize_result] eq "DELETE: subdir7/f7\nREVERTED: f7${undoMsg}"
182 }
183
184 cd $rootDir
185
186 ###################################
@@ -195,11 +195,11 @@
195 [normalize_result] eq "RENAME f8 subdir8/f8\nMOVED_FILE ${rootDir}/f8"
196 }
197
198 fossil revert
199 test mv-hard-absolute-4 {
200 [normalize_result] eq "DELETE: subdir8/f8\nREVERTED: f8${undoMsg}"
201 }
202
203 cd $rootDir
204
205 ##########################################
@@ -221,11 +221,11 @@
221 }
222
223 fossil revert
224 test rm-soft-relative-4 {
225 [normalize_result] eq \
226 "REVERTED: subdirB/f9\nREVERTED: subdirC/f10\nREVERTED: subdirC/f11${undoMsg}"
227 }
228
229 cd $rootDir
230
231 ######################################
@@ -238,11 +238,11 @@
238 fossil rm ../f2
239 test rm-soft-relative-5 {$RESULT eq "DELETED f2"}
240
241 fossil revert
242 test rm-soft-relative-6 {
243 [normalize_result] eq "REVERTED: f2${undoMsg}"
244 }
245
246 cd $rootDir
247
248 ###########################################
@@ -271,11 +271,11 @@
271 }
272
273 fossil revert
274 test rm-hard-relative-4 {
275 [normalize_result] eq \
276 "REVERTED: subdirB/f9\nREVERTED: subdirC/f10\nREVERTED: subdirC/f11${undoMsg}"
277 }
278
279 cd $rootDir
280
281 ######################################
@@ -290,11 +290,11 @@
290 [normalize_result] eq "DELETED f4\nDELETED_FILE ${rootDir}/f4"
291 }
292
293 fossil revert
294 test rm-hard-relative-6 {
295 [normalize_result] eq "REVERTED: f4${undoMsg}"
296 }
297
298 cd $rootDir
299
300 ###########################################
@@ -316,11 +316,11 @@
316 }
317
318 fossil revert
319 test rm-soft-absolute-4 {
320 [normalize_result] eq \
321 "REVERTED: subdirB/f9\nREVERTED: subdirC/f10\nREVERTED: subdirC/f11${undoMsg}"
322 }
323
324 cd $rootDir
325
326 ######################################
@@ -333,11 +333,11 @@
333 fossil rm [file join $rootDir f6]
334 test rm-soft-absolute-5 {$RESULT eq "DELETED f6"}
335
336 fossil revert
337 test rm-soft-absolute-6 {
338 [normalize_result] eq "REVERTED: f6${undoMsg}"
339 }
340
341 cd $rootDir
342
343 ###########################################
@@ -364,11 +364,11 @@
364 }
365
366 fossil revert
367 test rm-hard-absolute-4 {
368 [normalize_result] eq \
369 "REVERTED: subdirB/f9\nREVERTED: subdirC/f10\nREVERTED: subdirC/f11${undoMsg}"
370 }
371
372 cd $rootDir
373
374 ######################################
@@ -383,9 +383,9 @@
383 [normalize_result] eq "DELETED f8\nDELETED_FILE ${rootDir}/f8"
384 }
385
386 fossil revert
387 test rm-hard-absolute-6 {
388 [normalize_result] eq "REVERTED: f8${undoMsg}"
389 }
390
391 cd $rootDir
392
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -68,11 +68,11 @@
68 fossil mv ../f1 .
69 test mv-soft-relative-1 {$RESULT eq "RENAME f1 subdir1/f1"}
70
71 fossil revert
72 test mv-soft-relative-2 {
73 [normalize_result] eq "DELETE subdir1/f1\nREVERT f1${undoMsg}"
74 }
75
76 cd $rootDir
77
78 ###################################
@@ -85,11 +85,11 @@
85 fossil mv ../f2 ./f2
86 test mv-soft-relative-3 {$RESULT eq "RENAME f2 subdir2/f2"}
87
88 fossil revert
89 test mv-soft-relative-4 {
90 [normalize_result] eq "DELETE subdir2/f2\nREVERT f2${undoMsg}"
91 }
92
93 cd $rootDir
94
95 ########################################
@@ -104,11 +104,11 @@
104 [normalize_result] eq "RENAME f3 subdir3/f3\nMOVED_FILE ${rootDir}/f3"
105 }
106
107 fossil revert
108 test mv-hard-relative-2 {
109 [normalize_result] eq "DELETE subdir3/f3\nREVERT f3${undoMsg}"
110 }
111
112 cd $rootDir
113
114 ###################################
@@ -123,11 +123,11 @@
123 [normalize_result] eq "RENAME f4 subdir4/f4\nMOVED_FILE ${rootDir}/f4"
124 }
125
126 fossil revert
127 test mv-hard-relative-4 {
128 [normalize_result] eq "DELETE subdir4/f4\nREVERT f4${undoMsg}"
129 }
130
131 cd $rootDir
132
133 ########################################
@@ -140,11 +140,11 @@
140 fossil mv [file join $rootDir f5] [file join $rootDir subdir5]
141 test mv-soft-absolute-1 {$RESULT eq "RENAME f5 subdir5/f5"}
142
143 fossil revert
144 test mv-soft-absolute-2 {
145 [normalize_result] eq "DELETE subdir5/f5\nREVERT f5${undoMsg}"
146 }
147
148 cd $rootDir
149
150 ###################################
@@ -157,11 +157,11 @@
157 fossil mv [file join $rootDir f6] [file join $rootDir subdir6 f6]
158 test mv-soft-absolute-3 {$RESULT eq "RENAME f6 subdir6/f6"}
159
160 fossil revert
161 test mv-soft-absolute-4 {
162 [normalize_result] eq "DELETE subdir6/f6\nREVERT f6${undoMsg}"
163 }
164
165 cd $rootDir
166
167 ########################################
@@ -176,11 +176,11 @@
176 [normalize_result] eq "RENAME f7 subdir7/f7\nMOVED_FILE ${rootDir}/f7"
177 }
178
179 fossil revert
180 test mv-hard-absolute-2 {
181 [normalize_result] eq "DELETE subdir7/f7\nREVERT f7${undoMsg}"
182 }
183
184 cd $rootDir
185
186 ###################################
@@ -195,11 +195,11 @@
195 [normalize_result] eq "RENAME f8 subdir8/f8\nMOVED_FILE ${rootDir}/f8"
196 }
197
198 fossil revert
199 test mv-hard-absolute-4 {
200 [normalize_result] eq "DELETE subdir8/f8\nREVERT f8${undoMsg}"
201 }
202
203 cd $rootDir
204
205 ##########################################
@@ -221,11 +221,11 @@
221 }
222
223 fossil revert
224 test rm-soft-relative-4 {
225 [normalize_result] eq \
226 "REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
227 }
228
229 cd $rootDir
230
231 ######################################
@@ -238,11 +238,11 @@
238 fossil rm ../f2
239 test rm-soft-relative-5 {$RESULT eq "DELETED f2"}
240
241 fossil revert
242 test rm-soft-relative-6 {
243 [normalize_result] eq "REVERT f2${undoMsg}"
244 }
245
246 cd $rootDir
247
248 ###########################################
@@ -271,11 +271,11 @@
271 }
272
273 fossil revert
274 test rm-hard-relative-4 {
275 [normalize_result] eq \
276 "REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
277 }
278
279 cd $rootDir
280
281 ######################################
@@ -290,11 +290,11 @@
290 [normalize_result] eq "DELETED f4\nDELETED_FILE ${rootDir}/f4"
291 }
292
293 fossil revert
294 test rm-hard-relative-6 {
295 [normalize_result] eq "REVERT f4${undoMsg}"
296 }
297
298 cd $rootDir
299
300 ###########################################
@@ -316,11 +316,11 @@
316 }
317
318 fossil revert
319 test rm-soft-absolute-4 {
320 [normalize_result] eq \
321 "REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
322 }
323
324 cd $rootDir
325
326 ######################################
@@ -333,11 +333,11 @@
333 fossil rm [file join $rootDir f6]
334 test rm-soft-absolute-5 {$RESULT eq "DELETED f6"}
335
336 fossil revert
337 test rm-soft-absolute-6 {
338 [normalize_result] eq "REVERT f6${undoMsg}"
339 }
340
341 cd $rootDir
342
343 ###########################################
@@ -364,11 +364,11 @@
364 }
365
366 fossil revert
367 test rm-hard-absolute-4 {
368 [normalize_result] eq \
369 "REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
370 }
371
372 cd $rootDir
373
374 ######################################
@@ -383,9 +383,9 @@
383 [normalize_result] eq "DELETED f8\nDELETED_FILE ${rootDir}/f8"
384 }
385
386 fossil revert
387 test rm-hard-absolute-6 {
388 [normalize_result] eq "REVERT f8${undoMsg}"
389 }
390
391 cd $rootDir
392
+18 -18
--- test/revert.test
+++ test/revert.test
@@ -70,41 +70,41 @@
7070
fossil mv f3 f3n
7171
7272
# Test 'fossil revert' with no arguments
7373
#
7474
revert-test 1-1 {} {
75
- UNMANAGE: f0
76
- REVERTED: f1
77
- REVERTED: f2
78
- REVERTED: f3
79
- DELETE: f3n
75
+ UNMANAGE f0
76
+ REVERT f1
77
+ REVERT f2
78
+ REVERT f3
79
+ DELETE f3n
8080
} -addremove {
8181
ADDED f0
8282
} -exists {f0 f1 f2 f3} -notexists f3n
8383
8484
# Test with a single filename argument
8585
#
8686
revert-test 1-2 f0 {
87
- UNMANAGE: f0
87
+ UNMANAGE f0
8888
} -changes {
8989
DELETED f1
9090
EDITED f2
9191
RENAMED f3n
9292
} -addremove {
9393
ADDED f0
9494
} -exists {f0 f2 f3n} -notexists f3
9595
9696
revert-test 1-3 f1 {
97
- REVERTED: f1
97
+ REVERT f1
9898
} -changes {
9999
ADDED f0
100100
EDITED f2
101101
RENAMED f3n
102102
} -exists {f0 f1 f2 f3n} -notexists f3
103103
104104
revert-test 1-4 f2 {
105
- REVERTED: f2
105
+ REVERT f2
106106
} -changes {
107107
ADDED f0
108108
DELETED f1
109109
RENAMED f3n
110110
} -exists {f0 f2 f3n} -notexists {f1 f3}
@@ -111,34 +111,34 @@
111111
112112
# Both files involved in a rename are reverted regardless of which filename
113113
# is used as an argument to 'fossil revert'
114114
#
115115
revert-test 1-5 f3 {
116
- REVERTED: f3
117
- DELETE: f3n
116
+ REVERT f3
117
+ DELETE f3n
118118
} -changes {
119119
ADDED f0
120120
DELETED f1
121121
EDITED f2
122122
} -exists {f0 f2 f3} -notexists {f1 f3n}
123123
124124
revert-test 1-6 f3n {
125
- REVERTED: f3
126
- DELETE: f3n
125
+ REVERT f3
126
+ DELETE f3n
127127
} -changes {
128128
ADDED f0
129129
DELETED f1
130130
EDITED f2
131131
} -exists {f0 f2 f3} -notexists {f1 f3n}
132132
133133
# Test with multiple filename arguments
134134
#
135135
revert-test 1-7 {f0 f2 f3n} {
136
- UNMANAGE: f0
137
- REVERTED: f2
138
- REVERTED: f3
139
- DELETE: f3n
136
+ UNMANAGE f0
137
+ REVERT f2
138
+ REVERT f3
139
+ DELETE f3n
140140
} -changes {
141141
DELETED f1
142142
} -addremove {
143143
ADDED f0
144144
} -exists {f0 f2 f3} -notexists {f1 f3n}
@@ -156,8 +156,8 @@
156156
fossil mv f1 f1n
157157
write_file f1 "f1b"
158158
fossil add f1
159159
160160
revert-test 2-1 {} {
161
- REVERTED: f1
162
- DELETE: f1n
161
+ REVERT f1
162
+ DELETE f1n
163163
} -exists {f1} -notexists {f1n}
164164
--- test/revert.test
+++ test/revert.test
@@ -70,41 +70,41 @@
70 fossil mv f3 f3n
71
72 # Test 'fossil revert' with no arguments
73 #
74 revert-test 1-1 {} {
75 UNMANAGE: f0
76 REVERTED: f1
77 REVERTED: f2
78 REVERTED: f3
79 DELETE: f3n
80 } -addremove {
81 ADDED f0
82 } -exists {f0 f1 f2 f3} -notexists f3n
83
84 # Test with a single filename argument
85 #
86 revert-test 1-2 f0 {
87 UNMANAGE: f0
88 } -changes {
89 DELETED f1
90 EDITED f2
91 RENAMED f3n
92 } -addremove {
93 ADDED f0
94 } -exists {f0 f2 f3n} -notexists f3
95
96 revert-test 1-3 f1 {
97 REVERTED: f1
98 } -changes {
99 ADDED f0
100 EDITED f2
101 RENAMED f3n
102 } -exists {f0 f1 f2 f3n} -notexists f3
103
104 revert-test 1-4 f2 {
105 REVERTED: f2
106 } -changes {
107 ADDED f0
108 DELETED f1
109 RENAMED f3n
110 } -exists {f0 f2 f3n} -notexists {f1 f3}
@@ -111,34 +111,34 @@
111
112 # Both files involved in a rename are reverted regardless of which filename
113 # is used as an argument to 'fossil revert'
114 #
115 revert-test 1-5 f3 {
116 REVERTED: f3
117 DELETE: f3n
118 } -changes {
119 ADDED f0
120 DELETED f1
121 EDITED f2
122 } -exists {f0 f2 f3} -notexists {f1 f3n}
123
124 revert-test 1-6 f3n {
125 REVERTED: f3
126 DELETE: f3n
127 } -changes {
128 ADDED f0
129 DELETED f1
130 EDITED f2
131 } -exists {f0 f2 f3} -notexists {f1 f3n}
132
133 # Test with multiple filename arguments
134 #
135 revert-test 1-7 {f0 f2 f3n} {
136 UNMANAGE: f0
137 REVERTED: f2
138 REVERTED: f3
139 DELETE: f3n
140 } -changes {
141 DELETED f1
142 } -addremove {
143 ADDED f0
144 } -exists {f0 f2 f3} -notexists {f1 f3n}
@@ -156,8 +156,8 @@
156 fossil mv f1 f1n
157 write_file f1 "f1b"
158 fossil add f1
159
160 revert-test 2-1 {} {
161 REVERTED: f1
162 DELETE: f1n
163 } -exists {f1} -notexists {f1n}
164
--- test/revert.test
+++ test/revert.test
@@ -70,41 +70,41 @@
70 fossil mv f3 f3n
71
72 # Test 'fossil revert' with no arguments
73 #
74 revert-test 1-1 {} {
75 UNMANAGE f0
76 REVERT f1
77 REVERT f2
78 REVERT f3
79 DELETE f3n
80 } -addremove {
81 ADDED f0
82 } -exists {f0 f1 f2 f3} -notexists f3n
83
84 # Test with a single filename argument
85 #
86 revert-test 1-2 f0 {
87 UNMANAGE f0
88 } -changes {
89 DELETED f1
90 EDITED f2
91 RENAMED f3n
92 } -addremove {
93 ADDED f0
94 } -exists {f0 f2 f3n} -notexists f3
95
96 revert-test 1-3 f1 {
97 REVERT f1
98 } -changes {
99 ADDED f0
100 EDITED f2
101 RENAMED f3n
102 } -exists {f0 f1 f2 f3n} -notexists f3
103
104 revert-test 1-4 f2 {
105 REVERT f2
106 } -changes {
107 ADDED f0
108 DELETED f1
109 RENAMED f3n
110 } -exists {f0 f2 f3n} -notexists {f1 f3}
@@ -111,34 +111,34 @@
111
112 # Both files involved in a rename are reverted regardless of which filename
113 # is used as an argument to 'fossil revert'
114 #
115 revert-test 1-5 f3 {
116 REVERT f3
117 DELETE f3n
118 } -changes {
119 ADDED f0
120 DELETED f1
121 EDITED f2
122 } -exists {f0 f2 f3} -notexists {f1 f3n}
123
124 revert-test 1-6 f3n {
125 REVERT f3
126 DELETE f3n
127 } -changes {
128 ADDED f0
129 DELETED f1
130 EDITED f2
131 } -exists {f0 f2 f3} -notexists {f1 f3n}
132
133 # Test with multiple filename arguments
134 #
135 revert-test 1-7 {f0 f2 f3n} {
136 UNMANAGE f0
137 REVERT f2
138 REVERT f3
139 DELETE f3n
140 } -changes {
141 DELETED f1
142 } -addremove {
143 ADDED f0
144 } -exists {f0 f2 f3} -notexists {f1 f3n}
@@ -156,8 +156,8 @@
156 fossil mv f1 f1n
157 write_file f1 "f1b"
158 fossil add f1
159
160 revert-test 2-1 {} {
161 REVERT f1
162 DELETE f1n
163 } -exists {f1} -notexists {f1n}
164
+39 -19
--- test/tester.tcl
+++ test/tester.tcl
@@ -49,25 +49,26 @@
4949
set VERBOSE 1
5050
set argv [lreplace $argv $i $i]
5151
} else {
5252
set VERBOSE 0
5353
}
54
+
55
+set i [lsearch $argv -quiet]
56
+if {$i>=0} {
57
+ set QUIET 1
58
+ set argv [lreplace $argv $i $i]
59
+} else {
60
+ set QUIET 0
61
+}
5462
5563
if {[llength $argv]==0} {
5664
foreach f [lsort [glob $testdir/*.test]] {
5765
set base [file root [file tail $f]]
5866
lappend argv $base
5967
}
6068
}
6169
62
-set tempPath [expr {[info exists env(TEMP)] ? \
63
- $env(TEMP) : [file dirname [info script]]}]
64
-
65
-if {$tcl_platform(platform) eq "windows"} then {
66
- set tempPath [string map [list \\ /] $tempPath]
67
-}
68
-
6970
# start protocol
7071
#
7172
proc protInit {cmd} {
7273
if {$::PROT} {
7374
set out [open [file join $::testrundir prot] w]
@@ -77,12 +78,14 @@
7778
}
7879
}
7980
8081
# write protocol
8182
#
82
-proc protOut {msg} {
83
- puts stdout $msg
83
+proc protOut {msg {noQuiet 0}} {
84
+ if {$noQuiet || !$::QUIET} {
85
+ puts stdout $msg
86
+ }
8487
if {$::PROT} {
8588
set out [open [file join $::testrundir prot] a]
8689
fconfigure $out -translation platform
8790
puts $out $msg
8891
close $out
@@ -126,11 +129,11 @@
126129
set rc [catch {eval exec $cmd} result]
127130
}
128131
global RESULT CODE
129132
set CODE $rc
130133
if {$rc} {
131
- protOut "ERROR: $result"
134
+ protOut "ERROR: $result" 1
132135
} elseif {$::VERBOSE} {
133136
protOut "RESULT: $result"
134137
}
135138
set RESULT $result
136139
}
@@ -207,12 +210,12 @@
207210
set expected [normalize_status_list $expected]
208211
set result [normalize_status_list $result]
209212
if {$result eq $expected} {
210213
test $name 1
211214
} else {
212
- protOut " Expected:\n [join $expected "\n "]"
213
- protOut " Got:\n [join $result "\n "]"
215
+ protOut " Expected:\n [join $expected "\n "]" 1
216
+ protOut " Got:\n [join $result "\n "]" 1
214217
test $name 0
215218
}
216219
}
217220
218221
# Append all arguments into a single value and then returns it.
@@ -254,11 +257,11 @@
254257
# Saves the TH1 setup script file by renaming it, based on the current
255258
# process ID.
256259
#
257260
proc saveTh1SetupFile {} {
258261
set oldFileName [getTh1SetupFileName]
259
- if {[file exists $oldFileName]} then {
262
+ if {[file exists $oldFileName]} {
260263
set newFileName [getSavedTh1SetupFileName]
261264
catch {file delete $newFileName}
262265
file rename $oldFileName $newFileName
263266
}
264267
}
@@ -267,11 +270,11 @@
267270
# on the current process ID.
268271
#
269272
proc restoreTh1SetupFile {} {
270273
set oldFileName [getSavedTh1SetupFileName]
271274
set newFileName [getTh1SetupFileName]
272
- if {[file exists $oldFileName]} then {
275
+ if {[file exists $oldFileName]} {
273276
catch {file delete $newFileName}
274277
file rename $oldFileName $newFileName
275278
} else {
276279
#
277280
# NOTE: There was no TH1 setup script file, delete the test one.
@@ -282,17 +285,18 @@
282285
283286
# Perform a test
284287
#
285288
set test_count 0
286289
proc test {name expr} {
287
- global bad_test test_count
290
+ global bad_test test_count RESULT
288291
incr test_count
289292
set r [uplevel 1 [list expr $expr]]
290293
if {$r} {
291294
protOut "test $name OK"
292295
} else {
293
- protOut "test $name FAILED!"
296
+ protOut "test $name FAILED!" 1
297
+ if {$::QUIET} {protOut "RESULT: $RESULT" 1}
294298
lappend bad_test $name
295299
if {$::HALT} exit
296300
}
297301
}
298302
set bad_test {}
@@ -367,11 +371,11 @@
367371
368372
write_file $inFileName $data
369373
fossil http $inFileName $outFileName 127.0.0.1 $repository --localauth
370374
set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}]
371375
372
- if {1} then {
376
+ if {1} {
373377
catch {file delete $inFileName}
374378
catch {file delete $outFileName}
375379
}
376380
377381
return $result
@@ -418,10 +422,24 @@
418422
419423
# returns the third to last line of the normalized result.
420424
proc third_to_last_data_line {} {
421425
return [lindex [split [normalize_result] \n] end-2]
422426
}
427
+
428
+set tempPath [expr {[info exists env(TEMP)] ? \
429
+ $env(TEMP) : [file dirname [info script]]}]
430
+
431
+if {$tcl_platform(platform) eq "windows"} {
432
+ set tempPath [string map [list \\ /] $tempPath]
433
+}
434
+
435
+if {[catch {
436
+ write_file [file join $tempPath temporary.txt] [clock seconds]
437
+} error] != 0} {
438
+ error "could not write file to directory \"$tempPath\",\
439
+please set TEMP variable in environment: $error"
440
+}
423441
424442
protInit $fossilexe
425443
foreach testfile $argv {
426444
set dir [file root [file tail $testfile]]
427445
file delete -force $dir
@@ -432,9 +450,11 @@
432450
source $testdir/$testfile.test
433451
protOut "***** End of $testfile: [llength $bad_test] errors so far ******"
434452
cd $origwd
435453
}
436454
set nErr [llength $bad_test]
437
-protOut "***** Final result: $nErr errors out of $test_count tests"
455
+if {$nErr>0 || !$::QUIET} {
456
+ protOut "***** Final result: $nErr errors out of $test_count tests" 1
457
+}
438458
if {$nErr>0} {
439
- protOut "***** Failures: $bad_test"
459
+ protOut "***** Failures: $bad_test" 1
440460
}
441461
--- test/tester.tcl
+++ test/tester.tcl
@@ -49,25 +49,26 @@
49 set VERBOSE 1
50 set argv [lreplace $argv $i $i]
51 } else {
52 set VERBOSE 0
53 }
 
 
 
 
 
 
 
 
54
55 if {[llength $argv]==0} {
56 foreach f [lsort [glob $testdir/*.test]] {
57 set base [file root [file tail $f]]
58 lappend argv $base
59 }
60 }
61
62 set tempPath [expr {[info exists env(TEMP)] ? \
63 $env(TEMP) : [file dirname [info script]]}]
64
65 if {$tcl_platform(platform) eq "windows"} then {
66 set tempPath [string map [list \\ /] $tempPath]
67 }
68
69 # start protocol
70 #
71 proc protInit {cmd} {
72 if {$::PROT} {
73 set out [open [file join $::testrundir prot] w]
@@ -77,12 +78,14 @@
77 }
78 }
79
80 # write protocol
81 #
82 proc protOut {msg} {
83 puts stdout $msg
 
 
84 if {$::PROT} {
85 set out [open [file join $::testrundir prot] a]
86 fconfigure $out -translation platform
87 puts $out $msg
88 close $out
@@ -126,11 +129,11 @@
126 set rc [catch {eval exec $cmd} result]
127 }
128 global RESULT CODE
129 set CODE $rc
130 if {$rc} {
131 protOut "ERROR: $result"
132 } elseif {$::VERBOSE} {
133 protOut "RESULT: $result"
134 }
135 set RESULT $result
136 }
@@ -207,12 +210,12 @@
207 set expected [normalize_status_list $expected]
208 set result [normalize_status_list $result]
209 if {$result eq $expected} {
210 test $name 1
211 } else {
212 protOut " Expected:\n [join $expected "\n "]"
213 protOut " Got:\n [join $result "\n "]"
214 test $name 0
215 }
216 }
217
218 # Append all arguments into a single value and then returns it.
@@ -254,11 +257,11 @@
254 # Saves the TH1 setup script file by renaming it, based on the current
255 # process ID.
256 #
257 proc saveTh1SetupFile {} {
258 set oldFileName [getTh1SetupFileName]
259 if {[file exists $oldFileName]} then {
260 set newFileName [getSavedTh1SetupFileName]
261 catch {file delete $newFileName}
262 file rename $oldFileName $newFileName
263 }
264 }
@@ -267,11 +270,11 @@
267 # on the current process ID.
268 #
269 proc restoreTh1SetupFile {} {
270 set oldFileName [getSavedTh1SetupFileName]
271 set newFileName [getTh1SetupFileName]
272 if {[file exists $oldFileName]} then {
273 catch {file delete $newFileName}
274 file rename $oldFileName $newFileName
275 } else {
276 #
277 # NOTE: There was no TH1 setup script file, delete the test one.
@@ -282,17 +285,18 @@
282
283 # Perform a test
284 #
285 set test_count 0
286 proc test {name expr} {
287 global bad_test test_count
288 incr test_count
289 set r [uplevel 1 [list expr $expr]]
290 if {$r} {
291 protOut "test $name OK"
292 } else {
293 protOut "test $name FAILED!"
 
294 lappend bad_test $name
295 if {$::HALT} exit
296 }
297 }
298 set bad_test {}
@@ -367,11 +371,11 @@
367
368 write_file $inFileName $data
369 fossil http $inFileName $outFileName 127.0.0.1 $repository --localauth
370 set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}]
371
372 if {1} then {
373 catch {file delete $inFileName}
374 catch {file delete $outFileName}
375 }
376
377 return $result
@@ -418,10 +422,24 @@
418
419 # returns the third to last line of the normalized result.
420 proc third_to_last_data_line {} {
421 return [lindex [split [normalize_result] \n] end-2]
422 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
424 protInit $fossilexe
425 foreach testfile $argv {
426 set dir [file root [file tail $testfile]]
427 file delete -force $dir
@@ -432,9 +450,11 @@
432 source $testdir/$testfile.test
433 protOut "***** End of $testfile: [llength $bad_test] errors so far ******"
434 cd $origwd
435 }
436 set nErr [llength $bad_test]
437 protOut "***** Final result: $nErr errors out of $test_count tests"
 
 
438 if {$nErr>0} {
439 protOut "***** Failures: $bad_test"
440 }
441
--- test/tester.tcl
+++ test/tester.tcl
@@ -49,25 +49,26 @@
49 set VERBOSE 1
50 set argv [lreplace $argv $i $i]
51 } else {
52 set VERBOSE 0
53 }
54
55 set i [lsearch $argv -quiet]
56 if {$i>=0} {
57 set QUIET 1
58 set argv [lreplace $argv $i $i]
59 } else {
60 set QUIET 0
61 }
62
63 if {[llength $argv]==0} {
64 foreach f [lsort [glob $testdir/*.test]] {
65 set base [file root [file tail $f]]
66 lappend argv $base
67 }
68 }
69
 
 
 
 
 
 
 
70 # start protocol
71 #
72 proc protInit {cmd} {
73 if {$::PROT} {
74 set out [open [file join $::testrundir prot] w]
@@ -77,12 +78,14 @@
78 }
79 }
80
81 # write protocol
82 #
83 proc protOut {msg {noQuiet 0}} {
84 if {$noQuiet || !$::QUIET} {
85 puts stdout $msg
86 }
87 if {$::PROT} {
88 set out [open [file join $::testrundir prot] a]
89 fconfigure $out -translation platform
90 puts $out $msg
91 close $out
@@ -126,11 +129,11 @@
129 set rc [catch {eval exec $cmd} result]
130 }
131 global RESULT CODE
132 set CODE $rc
133 if {$rc} {
134 protOut "ERROR: $result" 1
135 } elseif {$::VERBOSE} {
136 protOut "RESULT: $result"
137 }
138 set RESULT $result
139 }
@@ -207,12 +210,12 @@
210 set expected [normalize_status_list $expected]
211 set result [normalize_status_list $result]
212 if {$result eq $expected} {
213 test $name 1
214 } else {
215 protOut " Expected:\n [join $expected "\n "]" 1
216 protOut " Got:\n [join $result "\n "]" 1
217 test $name 0
218 }
219 }
220
221 # Append all arguments into a single value and then returns it.
@@ -254,11 +257,11 @@
257 # Saves the TH1 setup script file by renaming it, based on the current
258 # process ID.
259 #
260 proc saveTh1SetupFile {} {
261 set oldFileName [getTh1SetupFileName]
262 if {[file exists $oldFileName]} {
263 set newFileName [getSavedTh1SetupFileName]
264 catch {file delete $newFileName}
265 file rename $oldFileName $newFileName
266 }
267 }
@@ -267,11 +270,11 @@
270 # on the current process ID.
271 #
272 proc restoreTh1SetupFile {} {
273 set oldFileName [getSavedTh1SetupFileName]
274 set newFileName [getTh1SetupFileName]
275 if {[file exists $oldFileName]} {
276 catch {file delete $newFileName}
277 file rename $oldFileName $newFileName
278 } else {
279 #
280 # NOTE: There was no TH1 setup script file, delete the test one.
@@ -282,17 +285,18 @@
285
286 # Perform a test
287 #
288 set test_count 0
289 proc test {name expr} {
290 global bad_test test_count RESULT
291 incr test_count
292 set r [uplevel 1 [list expr $expr]]
293 if {$r} {
294 protOut "test $name OK"
295 } else {
296 protOut "test $name FAILED!" 1
297 if {$::QUIET} {protOut "RESULT: $RESULT" 1}
298 lappend bad_test $name
299 if {$::HALT} exit
300 }
301 }
302 set bad_test {}
@@ -367,11 +371,11 @@
371
372 write_file $inFileName $data
373 fossil http $inFileName $outFileName 127.0.0.1 $repository --localauth
374 set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}]
375
376 if {1} {
377 catch {file delete $inFileName}
378 catch {file delete $outFileName}
379 }
380
381 return $result
@@ -418,10 +422,24 @@
422
423 # returns the third to last line of the normalized result.
424 proc third_to_last_data_line {} {
425 return [lindex [split [normalize_result] \n] end-2]
426 }
427
428 set tempPath [expr {[info exists env(TEMP)] ? \
429 $env(TEMP) : [file dirname [info script]]}]
430
431 if {$tcl_platform(platform) eq "windows"} {
432 set tempPath [string map [list \\ /] $tempPath]
433 }
434
435 if {[catch {
436 write_file [file join $tempPath temporary.txt] [clock seconds]
437 } error] != 0} {
438 error "could not write file to directory \"$tempPath\",\
439 please set TEMP variable in environment: $error"
440 }
441
442 protInit $fossilexe
443 foreach testfile $argv {
444 set dir [file root [file tail $testfile]]
445 file delete -force $dir
@@ -432,9 +450,11 @@
450 source $testdir/$testfile.test
451 protOut "***** End of $testfile: [llength $bad_test] errors so far ******"
452 cd $origwd
453 }
454 set nErr [llength $bad_test]
455 if {$nErr>0 || !$::QUIET} {
456 protOut "***** Final result: $nErr errors out of $test_count tests" 1
457 }
458 if {$nErr>0} {
459 protOut "***** Failures: $bad_test" 1
460 }
461
--- test/th1.test
+++ test/th1.test
@@ -1203,11 +1203,10 @@
12031203
###############################################################################
12041204
12051205
fossil test-th-eval {markdown "Test1\n=====\n*This is a test.*"}
12061206
test th1-markdown-4 {[normalize_result] eq {Test1 {<div class="markdown">
12071207
1208
-<h1>Test1</h1>
12091208
<p><em>This is a test.</em></p>
12101209
12111210
</div>
12121211
}}}
12131212
@@ -1217,11 +1216,10 @@
12171216
fossil test-th-eval [string map \
12181217
[list %markdown% $markdown] {markdown {%markdown%}}]
12191218
test th1-markdown-5 {[normalize_result] eq \
12201219
{{Markdown Formatter Test Document} {<div class="markdown">
12211220
1222
-<h1>Markdown Formatter Test Document</h1>
12231221
<p>This document is designed to test the markdown formatter.</p>
12241222
12251223
<ul>
12261224
<li>A bullet item.
12271225
12281226
--- test/th1.test
+++ test/th1.test
@@ -1203,11 +1203,10 @@
1203 ###############################################################################
1204
1205 fossil test-th-eval {markdown "Test1\n=====\n*This is a test.*"}
1206 test th1-markdown-4 {[normalize_result] eq {Test1 {<div class="markdown">
1207
1208 <h1>Test1</h1>
1209 <p><em>This is a test.</em></p>
1210
1211 </div>
1212 }}}
1213
@@ -1217,11 +1216,10 @@
1217 fossil test-th-eval [string map \
1218 [list %markdown% $markdown] {markdown {%markdown%}}]
1219 test th1-markdown-5 {[normalize_result] eq \
1220 {{Markdown Formatter Test Document} {<div class="markdown">
1221
1222 <h1>Markdown Formatter Test Document</h1>
1223 <p>This document is designed to test the markdown formatter.</p>
1224
1225 <ul>
1226 <li>A bullet item.
1227
1228
--- test/th1.test
+++ test/th1.test
@@ -1203,11 +1203,10 @@
1203 ###############################################################################
1204
1205 fossil test-th-eval {markdown "Test1\n=====\n*This is a test.*"}
1206 test th1-markdown-4 {[normalize_result] eq {Test1 {<div class="markdown">
1207
 
1208 <p><em>This is a test.</em></p>
1209
1210 </div>
1211 }}}
1212
@@ -1217,11 +1216,10 @@
1216 fossil test-th-eval [string map \
1217 [list %markdown% $markdown] {markdown {%markdown%}}]
1218 test th1-markdown-5 {[normalize_result] eq \
1219 {{Markdown Formatter Test Document} {<div class="markdown">
1220
 
1221 <p>This document is designed to test the markdown formatter.</p>
1222
1223 <ul>
1224 <li>A bullet item.
1225
1226

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button