Fossil SCM

Cherry-pick [http://www.sqlite.org/src/info/03b725a768290e3c|03b725a768]: Fix harmless compiler warnings seen with MSVC 2015.

jan.nijtmans 2015-04-28 08:11 trunk
Commit eda622cefc8c90f697d81a731aad8af844625b7a
1 file changed +52 -52
+52 -52
--- src/shell.c
+++ src/shell.c
@@ -334,11 +334,11 @@
334334
/*
335335
** The following is the open SQLite database. We make a pointer
336336
** to this database a static variable so that it can be accessed
337337
** by the SIGINT handler to interrupt database processing.
338338
*/
339
-static sqlite3 *db = 0;
339
+static sqlite3 *globalDb = 0;
340340
341341
/*
342342
** True if an interrupt (Control-C) has been received.
343343
*/
344344
static volatile int seenInterrupt = 0;
@@ -803,11 +803,11 @@
803803
*/
804804
static void interrupt_handler(int NotUsed){
805805
UNUSED_PARAMETER(NotUsed);
806806
seenInterrupt++;
807807
if( seenInterrupt>2 ) exit(1);
808
- if( db ) sqlite3_interrupt(db);
808
+ if( globalDb ) sqlite3_interrupt(globalDb);
809809
}
810810
#endif
811811
812812
/*
813813
** This is the callback routine that the shell
@@ -1907,27 +1907,27 @@
19071907
*/
19081908
static void open_db(ShellState *p, int keepAlive){
19091909
if( p->db==0 ){
19101910
sqlite3_initialize();
19111911
sqlite3_open(p->zDbFilename, &p->db);
1912
- db = p->db;
1913
- if( db && sqlite3_errcode(db)==SQLITE_OK ){
1914
- sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
1912
+ globalDb = p->db;
1913
+ if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
1914
+ sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
19151915
shellstaticFunc, 0, 0);
19161916
}
1917
- if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
1917
+ if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
19181918
fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
1919
- p->zDbFilename, sqlite3_errmsg(db));
1919
+ p->zDbFilename, sqlite3_errmsg(p->db));
19201920
if( keepAlive ) return;
19211921
exit(1);
19221922
}
19231923
#ifndef SQLITE_OMIT_LOAD_EXTENSION
19241924
sqlite3_enable_load_extension(p->db, 1);
19251925
#endif
1926
- sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
1926
+ sqlite3_create_function(p->db, "readfile", 1, SQLITE_UTF8, 0,
19271927
readfileFunc, 0, 0);
1928
- sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0,
1928
+ sqlite3_create_function(p->db, "writefile", 2, SQLITE_UTF8, 0,
19291929
writefileFunc, 0, 0);
19301930
}
19311931
}
19321932
19331933
/*
@@ -2584,36 +2584,36 @@
25842584
** process that line.
25852585
**
25862586
** Return 1 on error, 2 to exit, and 0 otherwise.
25872587
*/
25882588
static int do_meta_command(char *zLine, ShellState *p){
2589
- int i = 1;
2589
+ int h = 1;
25902590
int nArg = 0;
25912591
int n, c;
25922592
int rc = 0;
25932593
char *azArg[50];
25942594
25952595
/* Parse the input line into tokens.
25962596
*/
2597
- while( zLine[i] && nArg<ArraySize(azArg) ){
2598
- while( IsSpace(zLine[i]) ){ i++; }
2599
- if( zLine[i]==0 ) break;
2600
- if( zLine[i]=='\'' || zLine[i]=='"' ){
2601
- int delim = zLine[i++];
2602
- azArg[nArg++] = &zLine[i];
2603
- while( zLine[i] && zLine[i]!=delim ){
2604
- if( zLine[i]=='\\' && delim=='"' && zLine[i+1]!=0 ) i++;
2605
- i++;
2606
- }
2607
- if( zLine[i]==delim ){
2608
- zLine[i++] = 0;
2597
+ while( zLine[h] && nArg<ArraySize(azArg) ){
2598
+ while( IsSpace(zLine[h]) ){ h++; }
2599
+ if( zLine[h]==0 ) break;
2600
+ if( zLine[h]=='\'' || zLine[h]=='"' ){
2601
+ int delim = zLine[h++];
2602
+ azArg[nArg++] = &zLine[h];
2603
+ while( zLine[h] && zLine[h]!=delim ){
2604
+ if( zLine[h]=='\\' && delim=='"' && zLine[h+1]!=0 ) h++;
2605
+ h++;
2606
+ }
2607
+ if( zLine[h]==delim ){
2608
+ zLine[h++] = 0;
26092609
}
26102610
if( delim=='"' ) resolve_backslashes(azArg[nArg-1]);
26112611
}else{
2612
- azArg[nArg++] = &zLine[i];
2613
- while( zLine[i] && !IsSpace(zLine[i]) ){ i++; }
2614
- if( zLine[i] ) zLine[i++] = 0;
2612
+ azArg[nArg++] = &zLine[h];
2613
+ while( zLine[h] && !IsSpace(zLine[h]) ){ h++; }
2614
+ if( zLine[h] ) zLine[h++] = 0;
26152615
resolve_backslashes(azArg[nArg-1]);
26162616
}
26172617
}
26182618
26192619
/* Process the input line.
@@ -2985,11 +2985,11 @@
29852985
return 1;
29862986
}
29872987
nByte = strlen30(zSql);
29882988
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
29892989
import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
2990
- if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2990
+ if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
29912991
char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
29922992
char cSep = '(';
29932993
while( xRead(&sCtx) ){
29942994
zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCtx.z);
29952995
cSep = ',';
@@ -3005,21 +3005,21 @@
30053005
zCreate = sqlite3_mprintf("%z\n)", zCreate);
30063006
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
30073007
sqlite3_free(zCreate);
30083008
if( rc ){
30093009
fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
3010
- sqlite3_errmsg(db));
3010
+ sqlite3_errmsg(p->db));
30113011
sqlite3_free(sCtx.z);
30123012
xCloser(sCtx.in);
30133013
return 1;
30143014
}
30153015
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
30163016
}
30173017
sqlite3_free(zSql);
30183018
if( rc ){
30193019
if (pStmt) sqlite3_finalize(pStmt);
3020
- fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
3020
+ fprintf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
30213021
xCloser(sCtx.in);
30223022
return 1;
30233023
}
30243024
nCol = sqlite3_column_count(pStmt);
30253025
sqlite3_finalize(pStmt);
@@ -3040,17 +3040,17 @@
30403040
zSql[j++] = ')';
30413041
zSql[j] = 0;
30423042
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
30433043
sqlite3_free(zSql);
30443044
if( rc ){
3045
- fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
3045
+ fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
30463046
if (pStmt) sqlite3_finalize(pStmt);
30473047
xCloser(sCtx.in);
30483048
return 1;
30493049
}
3050
- needCommit = sqlite3_get_autocommit(db);
3051
- if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
3050
+ needCommit = sqlite3_get_autocommit(p->db);
3051
+ if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
30523052
do{
30533053
int startLine = sCtx.nLine;
30543054
for(i=0; i<nCol; i++){
30553055
char *z = xRead(&sCtx);
30563056
/*
@@ -3085,19 +3085,19 @@
30853085
if( i>=nCol ){
30863086
sqlite3_step(pStmt);
30873087
rc = sqlite3_reset(pStmt);
30883088
if( rc!=SQLITE_OK ){
30893089
fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
3090
- sqlite3_errmsg(db));
3090
+ sqlite3_errmsg(p->db));
30913091
}
30923092
}
30933093
}while( sCtx.cTerm!=EOF );
30943094
30953095
xCloser(sCtx.in);
30963096
sqlite3_free(sCtx.z);
30973097
sqlite3_finalize(pStmt);
3098
- if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
3098
+ if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
30993099
}else
31003100
31013101
if( c=='i' && (strncmp(azArg[0], "indices", n)==0
31023102
|| strncmp(azArg[0], "indexes", n)==0) ){
31033103
ShellState data;
@@ -3647,17 +3647,17 @@
36473647
sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC);
36483648
}
36493649
while( sqlite3_step(pStmt)==SQLITE_ROW ){
36503650
if( nRow>=nAlloc ){
36513651
char **azNew;
3652
- int n = nAlloc*2 + 10;
3653
- azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n);
3652
+ int n2 = nAlloc*2 + 10;
3653
+ azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n2);
36543654
if( azNew==0 ){
36553655
fprintf(stderr, "Error: out of memory\n");
36563656
break;
36573657
}
3658
- nAlloc = n;
3658
+ nAlloc = n2;
36593659
azResult = azNew;
36603660
}
36613661
azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
36623662
if( azResult[nRow] ) nRow++;
36633663
}
@@ -3706,19 +3706,19 @@
37063706
{ "byteorder", SQLITE_TESTCTRL_BYTEORDER },
37073707
{ "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
37083708
{ "imposter", SQLITE_TESTCTRL_IMPOSTER },
37093709
};
37103710
int testctrl = -1;
3711
- int rc = 0;
3712
- int i, n;
3711
+ int rc2 = 0;
3712
+ int i, n2;
37133713
open_db(p, 0);
37143714
37153715
/* convert testctrl text option to value. allow any unique prefix
37163716
** of the option name, or a numerical value. */
3717
- n = strlen30(azArg[1]);
3717
+ n2 = strlen30(azArg[1]);
37183718
for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
3719
- if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
3719
+ if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){
37203720
if( testctrl<0 ){
37213721
testctrl = aCtrl[i].ctrlCode;
37223722
}else{
37233723
fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
37243724
testctrl = -1;
@@ -3735,12 +3735,12 @@
37353735
/* sqlite3_test_control(int, db, int) */
37363736
case SQLITE_TESTCTRL_OPTIMIZATIONS:
37373737
case SQLITE_TESTCTRL_RESERVE:
37383738
if( nArg==3 ){
37393739
int opt = (int)strtol(azArg[2], 0, 0);
3740
- rc = sqlite3_test_control(testctrl, p->db, opt);
3741
- fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3740
+ rc2 = sqlite3_test_control(testctrl, p->db, opt);
3741
+ fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
37423742
} else {
37433743
fprintf(stderr,"Error: testctrl %s takes a single int option\n",
37443744
azArg[1]);
37453745
}
37463746
break;
@@ -3749,23 +3749,23 @@
37493749
case SQLITE_TESTCTRL_PRNG_SAVE:
37503750
case SQLITE_TESTCTRL_PRNG_RESTORE:
37513751
case SQLITE_TESTCTRL_PRNG_RESET:
37523752
case SQLITE_TESTCTRL_BYTEORDER:
37533753
if( nArg==2 ){
3754
- rc = sqlite3_test_control(testctrl);
3755
- fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3754
+ rc2 = sqlite3_test_control(testctrl);
3755
+ fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
37563756
} else {
37573757
fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
37583758
}
37593759
break;
37603760
37613761
/* sqlite3_test_control(int, uint) */
37623762
case SQLITE_TESTCTRL_PENDING_BYTE:
37633763
if( nArg==3 ){
37643764
unsigned int opt = (unsigned int)integerValue(azArg[2]);
3765
- rc = sqlite3_test_control(testctrl, opt);
3766
- fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3765
+ rc2 = sqlite3_test_control(testctrl, opt);
3766
+ fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
37673767
} else {
37683768
fprintf(stderr,"Error: testctrl %s takes a single unsigned"
37693769
" int option\n", azArg[1]);
37703770
}
37713771
break;
@@ -3774,12 +3774,12 @@
37743774
case SQLITE_TESTCTRL_ASSERT:
37753775
case SQLITE_TESTCTRL_ALWAYS:
37763776
case SQLITE_TESTCTRL_NEVER_CORRUPT:
37773777
if( nArg==3 ){
37783778
int opt = booleanValue(azArg[2]);
3779
- rc = sqlite3_test_control(testctrl, opt);
3780
- fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3779
+ rc2 = sqlite3_test_control(testctrl, opt);
3780
+ fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
37813781
} else {
37823782
fprintf(stderr,"Error: testctrl %s takes a single int option\n",
37833783
azArg[1]);
37843784
}
37853785
break;
@@ -3787,26 +3787,26 @@
37873787
/* sqlite3_test_control(int, char *) */
37883788
#ifdef SQLITE_N_KEYWORD
37893789
case SQLITE_TESTCTRL_ISKEYWORD:
37903790
if( nArg==3 ){
37913791
const char *opt = azArg[2];
3792
- rc = sqlite3_test_control(testctrl, opt);
3793
- fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3792
+ rc2 = sqlite3_test_control(testctrl, opt);
3793
+ fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
37943794
} else {
37953795
fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
37963796
azArg[1]);
37973797
}
37983798
break;
37993799
#endif
38003800
38013801
case SQLITE_TESTCTRL_IMPOSTER:
38023802
if( nArg==5 ){
3803
- rc = sqlite3_test_control(testctrl, p->db,
3803
+ rc2 = sqlite3_test_control(testctrl, p->db,
38043804
azArg[2],
38053805
integerValue(azArg[3]),
38063806
integerValue(azArg[4]));
3807
- fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3807
+ fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
38083808
}else{
38093809
fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
38103810
}
38113811
break;
38123812
38133813
--- src/shell.c
+++ src/shell.c
@@ -334,11 +334,11 @@
334 /*
335 ** The following is the open SQLite database. We make a pointer
336 ** to this database a static variable so that it can be accessed
337 ** by the SIGINT handler to interrupt database processing.
338 */
339 static sqlite3 *db = 0;
340
341 /*
342 ** True if an interrupt (Control-C) has been received.
343 */
344 static volatile int seenInterrupt = 0;
@@ -803,11 +803,11 @@
803 */
804 static void interrupt_handler(int NotUsed){
805 UNUSED_PARAMETER(NotUsed);
806 seenInterrupt++;
807 if( seenInterrupt>2 ) exit(1);
808 if( db ) sqlite3_interrupt(db);
809 }
810 #endif
811
812 /*
813 ** This is the callback routine that the shell
@@ -1907,27 +1907,27 @@
1907 */
1908 static void open_db(ShellState *p, int keepAlive){
1909 if( p->db==0 ){
1910 sqlite3_initialize();
1911 sqlite3_open(p->zDbFilename, &p->db);
1912 db = p->db;
1913 if( db && sqlite3_errcode(db)==SQLITE_OK ){
1914 sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
1915 shellstaticFunc, 0, 0);
1916 }
1917 if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
1918 fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
1919 p->zDbFilename, sqlite3_errmsg(db));
1920 if( keepAlive ) return;
1921 exit(1);
1922 }
1923 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1924 sqlite3_enable_load_extension(p->db, 1);
1925 #endif
1926 sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
1927 readfileFunc, 0, 0);
1928 sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0,
1929 writefileFunc, 0, 0);
1930 }
1931 }
1932
1933 /*
@@ -2584,36 +2584,36 @@
2584 ** process that line.
2585 **
2586 ** Return 1 on error, 2 to exit, and 0 otherwise.
2587 */
2588 static int do_meta_command(char *zLine, ShellState *p){
2589 int i = 1;
2590 int nArg = 0;
2591 int n, c;
2592 int rc = 0;
2593 char *azArg[50];
2594
2595 /* Parse the input line into tokens.
2596 */
2597 while( zLine[i] && nArg<ArraySize(azArg) ){
2598 while( IsSpace(zLine[i]) ){ i++; }
2599 if( zLine[i]==0 ) break;
2600 if( zLine[i]=='\'' || zLine[i]=='"' ){
2601 int delim = zLine[i++];
2602 azArg[nArg++] = &zLine[i];
2603 while( zLine[i] && zLine[i]!=delim ){
2604 if( zLine[i]=='\\' && delim=='"' && zLine[i+1]!=0 ) i++;
2605 i++;
2606 }
2607 if( zLine[i]==delim ){
2608 zLine[i++] = 0;
2609 }
2610 if( delim=='"' ) resolve_backslashes(azArg[nArg-1]);
2611 }else{
2612 azArg[nArg++] = &zLine[i];
2613 while( zLine[i] && !IsSpace(zLine[i]) ){ i++; }
2614 if( zLine[i] ) zLine[i++] = 0;
2615 resolve_backslashes(azArg[nArg-1]);
2616 }
2617 }
2618
2619 /* Process the input line.
@@ -2985,11 +2985,11 @@
2985 return 1;
2986 }
2987 nByte = strlen30(zSql);
2988 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2989 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
2990 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2991 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2992 char cSep = '(';
2993 while( xRead(&sCtx) ){
2994 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCtx.z);
2995 cSep = ',';
@@ -3005,21 +3005,21 @@
3005 zCreate = sqlite3_mprintf("%z\n)", zCreate);
3006 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
3007 sqlite3_free(zCreate);
3008 if( rc ){
3009 fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
3010 sqlite3_errmsg(db));
3011 sqlite3_free(sCtx.z);
3012 xCloser(sCtx.in);
3013 return 1;
3014 }
3015 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3016 }
3017 sqlite3_free(zSql);
3018 if( rc ){
3019 if (pStmt) sqlite3_finalize(pStmt);
3020 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
3021 xCloser(sCtx.in);
3022 return 1;
3023 }
3024 nCol = sqlite3_column_count(pStmt);
3025 sqlite3_finalize(pStmt);
@@ -3040,17 +3040,17 @@
3040 zSql[j++] = ')';
3041 zSql[j] = 0;
3042 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3043 sqlite3_free(zSql);
3044 if( rc ){
3045 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
3046 if (pStmt) sqlite3_finalize(pStmt);
3047 xCloser(sCtx.in);
3048 return 1;
3049 }
3050 needCommit = sqlite3_get_autocommit(db);
3051 if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
3052 do{
3053 int startLine = sCtx.nLine;
3054 for(i=0; i<nCol; i++){
3055 char *z = xRead(&sCtx);
3056 /*
@@ -3085,19 +3085,19 @@
3085 if( i>=nCol ){
3086 sqlite3_step(pStmt);
3087 rc = sqlite3_reset(pStmt);
3088 if( rc!=SQLITE_OK ){
3089 fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
3090 sqlite3_errmsg(db));
3091 }
3092 }
3093 }while( sCtx.cTerm!=EOF );
3094
3095 xCloser(sCtx.in);
3096 sqlite3_free(sCtx.z);
3097 sqlite3_finalize(pStmt);
3098 if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
3099 }else
3100
3101 if( c=='i' && (strncmp(azArg[0], "indices", n)==0
3102 || strncmp(azArg[0], "indexes", n)==0) ){
3103 ShellState data;
@@ -3647,17 +3647,17 @@
3647 sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC);
3648 }
3649 while( sqlite3_step(pStmt)==SQLITE_ROW ){
3650 if( nRow>=nAlloc ){
3651 char **azNew;
3652 int n = nAlloc*2 + 10;
3653 azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n);
3654 if( azNew==0 ){
3655 fprintf(stderr, "Error: out of memory\n");
3656 break;
3657 }
3658 nAlloc = n;
3659 azResult = azNew;
3660 }
3661 azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
3662 if( azResult[nRow] ) nRow++;
3663 }
@@ -3706,19 +3706,19 @@
3706 { "byteorder", SQLITE_TESTCTRL_BYTEORDER },
3707 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
3708 { "imposter", SQLITE_TESTCTRL_IMPOSTER },
3709 };
3710 int testctrl = -1;
3711 int rc = 0;
3712 int i, n;
3713 open_db(p, 0);
3714
3715 /* convert testctrl text option to value. allow any unique prefix
3716 ** of the option name, or a numerical value. */
3717 n = strlen30(azArg[1]);
3718 for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
3719 if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
3720 if( testctrl<0 ){
3721 testctrl = aCtrl[i].ctrlCode;
3722 }else{
3723 fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
3724 testctrl = -1;
@@ -3735,12 +3735,12 @@
3735 /* sqlite3_test_control(int, db, int) */
3736 case SQLITE_TESTCTRL_OPTIMIZATIONS:
3737 case SQLITE_TESTCTRL_RESERVE:
3738 if( nArg==3 ){
3739 int opt = (int)strtol(azArg[2], 0, 0);
3740 rc = sqlite3_test_control(testctrl, p->db, opt);
3741 fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3742 } else {
3743 fprintf(stderr,"Error: testctrl %s takes a single int option\n",
3744 azArg[1]);
3745 }
3746 break;
@@ -3749,23 +3749,23 @@
3749 case SQLITE_TESTCTRL_PRNG_SAVE:
3750 case SQLITE_TESTCTRL_PRNG_RESTORE:
3751 case SQLITE_TESTCTRL_PRNG_RESET:
3752 case SQLITE_TESTCTRL_BYTEORDER:
3753 if( nArg==2 ){
3754 rc = sqlite3_test_control(testctrl);
3755 fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3756 } else {
3757 fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
3758 }
3759 break;
3760
3761 /* sqlite3_test_control(int, uint) */
3762 case SQLITE_TESTCTRL_PENDING_BYTE:
3763 if( nArg==3 ){
3764 unsigned int opt = (unsigned int)integerValue(azArg[2]);
3765 rc = sqlite3_test_control(testctrl, opt);
3766 fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3767 } else {
3768 fprintf(stderr,"Error: testctrl %s takes a single unsigned"
3769 " int option\n", azArg[1]);
3770 }
3771 break;
@@ -3774,12 +3774,12 @@
3774 case SQLITE_TESTCTRL_ASSERT:
3775 case SQLITE_TESTCTRL_ALWAYS:
3776 case SQLITE_TESTCTRL_NEVER_CORRUPT:
3777 if( nArg==3 ){
3778 int opt = booleanValue(azArg[2]);
3779 rc = sqlite3_test_control(testctrl, opt);
3780 fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3781 } else {
3782 fprintf(stderr,"Error: testctrl %s takes a single int option\n",
3783 azArg[1]);
3784 }
3785 break;
@@ -3787,26 +3787,26 @@
3787 /* sqlite3_test_control(int, char *) */
3788 #ifdef SQLITE_N_KEYWORD
3789 case SQLITE_TESTCTRL_ISKEYWORD:
3790 if( nArg==3 ){
3791 const char *opt = azArg[2];
3792 rc = sqlite3_test_control(testctrl, opt);
3793 fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3794 } else {
3795 fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
3796 azArg[1]);
3797 }
3798 break;
3799 #endif
3800
3801 case SQLITE_TESTCTRL_IMPOSTER:
3802 if( nArg==5 ){
3803 rc = sqlite3_test_control(testctrl, p->db,
3804 azArg[2],
3805 integerValue(azArg[3]),
3806 integerValue(azArg[4]));
3807 fprintf(p->out, "%d (0x%08x)\n", rc, rc);
3808 }else{
3809 fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
3810 }
3811 break;
3812
3813
--- src/shell.c
+++ src/shell.c
@@ -334,11 +334,11 @@
334 /*
335 ** The following is the open SQLite database. We make a pointer
336 ** to this database a static variable so that it can be accessed
337 ** by the SIGINT handler to interrupt database processing.
338 */
339 static sqlite3 *globalDb = 0;
340
341 /*
342 ** True if an interrupt (Control-C) has been received.
343 */
344 static volatile int seenInterrupt = 0;
@@ -803,11 +803,11 @@
803 */
804 static void interrupt_handler(int NotUsed){
805 UNUSED_PARAMETER(NotUsed);
806 seenInterrupt++;
807 if( seenInterrupt>2 ) exit(1);
808 if( globalDb ) sqlite3_interrupt(globalDb);
809 }
810 #endif
811
812 /*
813 ** This is the callback routine that the shell
@@ -1907,27 +1907,27 @@
1907 */
1908 static void open_db(ShellState *p, int keepAlive){
1909 if( p->db==0 ){
1910 sqlite3_initialize();
1911 sqlite3_open(p->zDbFilename, &p->db);
1912 globalDb = p->db;
1913 if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
1914 sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0,
1915 shellstaticFunc, 0, 0);
1916 }
1917 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
1918 fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
1919 p->zDbFilename, sqlite3_errmsg(p->db));
1920 if( keepAlive ) return;
1921 exit(1);
1922 }
1923 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1924 sqlite3_enable_load_extension(p->db, 1);
1925 #endif
1926 sqlite3_create_function(p->db, "readfile", 1, SQLITE_UTF8, 0,
1927 readfileFunc, 0, 0);
1928 sqlite3_create_function(p->db, "writefile", 2, SQLITE_UTF8, 0,
1929 writefileFunc, 0, 0);
1930 }
1931 }
1932
1933 /*
@@ -2584,36 +2584,36 @@
2584 ** process that line.
2585 **
2586 ** Return 1 on error, 2 to exit, and 0 otherwise.
2587 */
2588 static int do_meta_command(char *zLine, ShellState *p){
2589 int h = 1;
2590 int nArg = 0;
2591 int n, c;
2592 int rc = 0;
2593 char *azArg[50];
2594
2595 /* Parse the input line into tokens.
2596 */
2597 while( zLine[h] && nArg<ArraySize(azArg) ){
2598 while( IsSpace(zLine[h]) ){ h++; }
2599 if( zLine[h]==0 ) break;
2600 if( zLine[h]=='\'' || zLine[h]=='"' ){
2601 int delim = zLine[h++];
2602 azArg[nArg++] = &zLine[h];
2603 while( zLine[h] && zLine[h]!=delim ){
2604 if( zLine[h]=='\\' && delim=='"' && zLine[h+1]!=0 ) h++;
2605 h++;
2606 }
2607 if( zLine[h]==delim ){
2608 zLine[h++] = 0;
2609 }
2610 if( delim=='"' ) resolve_backslashes(azArg[nArg-1]);
2611 }else{
2612 azArg[nArg++] = &zLine[h];
2613 while( zLine[h] && !IsSpace(zLine[h]) ){ h++; }
2614 if( zLine[h] ) zLine[h++] = 0;
2615 resolve_backslashes(azArg[nArg-1]);
2616 }
2617 }
2618
2619 /* Process the input line.
@@ -2985,11 +2985,11 @@
2985 return 1;
2986 }
2987 nByte = strlen30(zSql);
2988 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2989 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
2990 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
2991 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2992 char cSep = '(';
2993 while( xRead(&sCtx) ){
2994 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCtx.z);
2995 cSep = ',';
@@ -3005,21 +3005,21 @@
3005 zCreate = sqlite3_mprintf("%z\n)", zCreate);
3006 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
3007 sqlite3_free(zCreate);
3008 if( rc ){
3009 fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
3010 sqlite3_errmsg(p->db));
3011 sqlite3_free(sCtx.z);
3012 xCloser(sCtx.in);
3013 return 1;
3014 }
3015 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3016 }
3017 sqlite3_free(zSql);
3018 if( rc ){
3019 if (pStmt) sqlite3_finalize(pStmt);
3020 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
3021 xCloser(sCtx.in);
3022 return 1;
3023 }
3024 nCol = sqlite3_column_count(pStmt);
3025 sqlite3_finalize(pStmt);
@@ -3040,17 +3040,17 @@
3040 zSql[j++] = ')';
3041 zSql[j] = 0;
3042 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3043 sqlite3_free(zSql);
3044 if( rc ){
3045 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
3046 if (pStmt) sqlite3_finalize(pStmt);
3047 xCloser(sCtx.in);
3048 return 1;
3049 }
3050 needCommit = sqlite3_get_autocommit(p->db);
3051 if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
3052 do{
3053 int startLine = sCtx.nLine;
3054 for(i=0; i<nCol; i++){
3055 char *z = xRead(&sCtx);
3056 /*
@@ -3085,19 +3085,19 @@
3085 if( i>=nCol ){
3086 sqlite3_step(pStmt);
3087 rc = sqlite3_reset(pStmt);
3088 if( rc!=SQLITE_OK ){
3089 fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine,
3090 sqlite3_errmsg(p->db));
3091 }
3092 }
3093 }while( sCtx.cTerm!=EOF );
3094
3095 xCloser(sCtx.in);
3096 sqlite3_free(sCtx.z);
3097 sqlite3_finalize(pStmt);
3098 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
3099 }else
3100
3101 if( c=='i' && (strncmp(azArg[0], "indices", n)==0
3102 || strncmp(azArg[0], "indexes", n)==0) ){
3103 ShellState data;
@@ -3647,17 +3647,17 @@
3647 sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC);
3648 }
3649 while( sqlite3_step(pStmt)==SQLITE_ROW ){
3650 if( nRow>=nAlloc ){
3651 char **azNew;
3652 int n2 = nAlloc*2 + 10;
3653 azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n2);
3654 if( azNew==0 ){
3655 fprintf(stderr, "Error: out of memory\n");
3656 break;
3657 }
3658 nAlloc = n2;
3659 azResult = azNew;
3660 }
3661 azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
3662 if( azResult[nRow] ) nRow++;
3663 }
@@ -3706,19 +3706,19 @@
3706 { "byteorder", SQLITE_TESTCTRL_BYTEORDER },
3707 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
3708 { "imposter", SQLITE_TESTCTRL_IMPOSTER },
3709 };
3710 int testctrl = -1;
3711 int rc2 = 0;
3712 int i, n2;
3713 open_db(p, 0);
3714
3715 /* convert testctrl text option to value. allow any unique prefix
3716 ** of the option name, or a numerical value. */
3717 n2 = strlen30(azArg[1]);
3718 for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
3719 if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){
3720 if( testctrl<0 ){
3721 testctrl = aCtrl[i].ctrlCode;
3722 }else{
3723 fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
3724 testctrl = -1;
@@ -3735,12 +3735,12 @@
3735 /* sqlite3_test_control(int, db, int) */
3736 case SQLITE_TESTCTRL_OPTIMIZATIONS:
3737 case SQLITE_TESTCTRL_RESERVE:
3738 if( nArg==3 ){
3739 int opt = (int)strtol(azArg[2], 0, 0);
3740 rc2 = sqlite3_test_control(testctrl, p->db, opt);
3741 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3742 } else {
3743 fprintf(stderr,"Error: testctrl %s takes a single int option\n",
3744 azArg[1]);
3745 }
3746 break;
@@ -3749,23 +3749,23 @@
3749 case SQLITE_TESTCTRL_PRNG_SAVE:
3750 case SQLITE_TESTCTRL_PRNG_RESTORE:
3751 case SQLITE_TESTCTRL_PRNG_RESET:
3752 case SQLITE_TESTCTRL_BYTEORDER:
3753 if( nArg==2 ){
3754 rc2 = sqlite3_test_control(testctrl);
3755 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3756 } else {
3757 fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
3758 }
3759 break;
3760
3761 /* sqlite3_test_control(int, uint) */
3762 case SQLITE_TESTCTRL_PENDING_BYTE:
3763 if( nArg==3 ){
3764 unsigned int opt = (unsigned int)integerValue(azArg[2]);
3765 rc2 = sqlite3_test_control(testctrl, opt);
3766 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3767 } else {
3768 fprintf(stderr,"Error: testctrl %s takes a single unsigned"
3769 " int option\n", azArg[1]);
3770 }
3771 break;
@@ -3774,12 +3774,12 @@
3774 case SQLITE_TESTCTRL_ASSERT:
3775 case SQLITE_TESTCTRL_ALWAYS:
3776 case SQLITE_TESTCTRL_NEVER_CORRUPT:
3777 if( nArg==3 ){
3778 int opt = booleanValue(azArg[2]);
3779 rc2 = sqlite3_test_control(testctrl, opt);
3780 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3781 } else {
3782 fprintf(stderr,"Error: testctrl %s takes a single int option\n",
3783 azArg[1]);
3784 }
3785 break;
@@ -3787,26 +3787,26 @@
3787 /* sqlite3_test_control(int, char *) */
3788 #ifdef SQLITE_N_KEYWORD
3789 case SQLITE_TESTCTRL_ISKEYWORD:
3790 if( nArg==3 ){
3791 const char *opt = azArg[2];
3792 rc2 = sqlite3_test_control(testctrl, opt);
3793 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3794 } else {
3795 fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
3796 azArg[1]);
3797 }
3798 break;
3799 #endif
3800
3801 case SQLITE_TESTCTRL_IMPOSTER:
3802 if( nArg==5 ){
3803 rc2 = sqlite3_test_control(testctrl, p->db,
3804 azArg[2],
3805 integerValue(azArg[3]),
3806 integerValue(azArg[4]));
3807 fprintf(p->out, "%d (0x%08x)\n", rc2, rc2);
3808 }else{
3809 fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
3810 }
3811 break;
3812
3813

Keyboard Shortcuts

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