Enhance the shell to provide more flexibility when entering numeric arguments

on dot-commands.  In particular, allow hex arguments to .wheretrace.

FossilOrigin-Name: b9578c371ee569dca6a0964019959a93407c8ef9
This commit is contained in:
drh 2013-05-31 14:31:11 +00:00
parent 0afb423fd3
commit 84f1414b1a
3 changed files with 73 additions and 29 deletions

View File

@ -1,5 +1,5 @@
C Futher\senhancements\sto\sthe\sORDER\sBY\soptimizer.
D 2013-05-31T13:36:32.993
C Enhance\sthe\sshell\sto\sprovide\smore\sflexibility\swhen\sentering\snumeric\sarguments\non\sdot-commands.\s\sIn\sparticular,\sallow\shex\sarguments\sto\s.wheretrace.
D 2013-05-31T14:31:11.784
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -216,7 +216,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
F src/resolve.c 89f9003e8316ee3a172795459efc2a0274e1d5a8
F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
F src/select.c 22ee971346a736ddefdc4497d07c92f2e9978afc
F src/shell.c 9a18124ff209ca308d786c99a466e8e270193ff3
F src/shell.c ab6eea968c8745be3aa74e45fedb37d057b4cd0d
F src/sqlite.h.in 5b390ca5d94e09e56e7fee6a51ddde4721b89f8e
F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
F src/sqlite3ext.h d936f797812c28b81b26ed18345baf8db28a21a5
@ -1093,7 +1093,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P 58805eb36b9975706e2c4e382689519454e9a504
R d753e9381f16048231d3d54f23e54ee3
P d8efa5f8b60bc4c8df8bfad077f87f76f7ee9bf6
R cab66f9edd3249c76db6815f19ee5773
U drh
Z 2bef9deff008e88de89f5b60b513bb1c
Z 93073f371b16237bef628d122f206ede

View File

@ -1 +1 @@
d8efa5f8b60bc4c8df8bfad077f87f76f7ee9bf6
b9578c371ee569dca6a0964019959a93407c8ef9

View File

@ -1523,21 +1523,14 @@ static void resolve_backslashes(char *z){
}
/*
** Interpret zArg as a boolean value. Return either 0 or 1.
** Return the value of a hexadecimal digit. Return -1 if the input
** is not a hex digit.
*/
static int booleanValue(char *zArg){
int i;
for(i=0; zArg[i]>='0' && zArg[i]<='9'; i++){}
if( i>0 && zArg[i]==0 ) return atoi(zArg);
if( sqlite3_stricmp(zArg, "on")==0 || sqlite3_stricmp(zArg,"yes")==0 ){
return 1;
}
if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){
return 0;
}
fprintf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
zArg);
return 0;
static int hexDigitValue(char c){
if( c>='0' && c<='9' ) return c - '0';
if( c>='a' && c<='f' ) return c - 'a' + 10;
if( c>='A' && c<='F' ) return c - 'A' + 10;
return -1;
}
/*
@ -1564,9 +1557,18 @@ static sqlite3_int64 integerValue(const char *zArg){
}else if( zArg[0]=='+' ){
zArg++;
}
while( IsDigit(zArg[0]) ){
v = v*10 + zArg[0] - '0';
zArg++;
if( zArg[0]=='0' && zArg[1]=='x' ){
int x;
zArg += 2;
while( (x = hexDigitValue(zArg[0]))>=0 ){
v = (v<<4) + x;
zArg++;
}
}else{
while( IsDigit(zArg[0]) ){
v = v*10 + zArg[0] - '0';
zArg++;
}
}
for(i=0; i<ArraySize(aMult); i++){
if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
@ -1577,6 +1579,29 @@ static sqlite3_int64 integerValue(const char *zArg){
return isNeg? -v : v;
}
/*
** Interpret zArg as either an integer or a boolean value. Return 1 or 0
** for TRUE and FALSE. Return the integer value if appropriate.
*/
static int booleanValue(char *zArg){
int i;
if( zArg[0]=='0' && zArg[1]=='x' ){
for(i=2; hexDigitValue(zArg[i])>=0; i++){}
}else{
for(i=0; zArg[i]>='0' && zArg[i]<='9'; i++){}
}
if( i>0 && zArg[i]==0 ) return (int)(integerValue(zArg) & 0xffffffff);
if( sqlite3_stricmp(zArg, "on")==0 || sqlite3_stricmp(zArg,"yes")==0 ){
return 1;
}
if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){
return 0;
}
fprintf(stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n",
zArg);
return 0;
}
/*
** Close an output file, assuming it is not stderr or stdout
*/
@ -1808,7 +1833,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
}else
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
if( nArg>1 && (rc = atoi(azArg[1]))!=0 ) exit(rc);
if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
rc = 2;
}else
@ -2305,6 +2330,25 @@ static int do_meta_command(char *zLine, struct callback_data *p){
}
}else
/* Undocumented commands for internal testing. Subject to change
** without notice. */
if( c=='s' && n>=10 && strncmp(azArg[0], "selftest-", 9)==0 ){
if( strncmp(azArg[0]+9, "boolean", n-9)==0 ){
int i, v;
for(i=1; i<nArg; i++){
v = booleanValue(azArg[i]);
fprintf(p->out, "%s: %d 0x%x\n", azArg[i], v, v);
}
}
if( strncmp(azArg[0]+9, "integer", n-9)==0 ){
int i; sqlite3_int64 v;
for(i=1; i<nArg; i++){
v = integerValue(azArg[i]);
fprintf(p->out, "%s: %lld 0x%llx\n", azArg[i], v, v);
}
}
}else
if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
sqlite3_snprintf(sizeof(p->separator), p->separator,
"%.*s", (int)sizeof(p->separator)-1, azArg[1]);
@ -2458,7 +2502,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
}
}
}
if( testctrl<0 ) testctrl = atoi(azArg[1]);
if( testctrl<0 ) testctrl = (int)integerValue(azArg[1]);
if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
}else{
@ -2505,7 +2549,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
case SQLITE_TESTCTRL_ASSERT:
case SQLITE_TESTCTRL_ALWAYS:
if( nArg==3 ){
int opt = atoi(azArg[2]);
int opt = booleanValue(azArg[2]);
rc = sqlite3_test_control(testctrl, opt);
fprintf(p->out, "%d (0x%08x)\n", rc, rc);
} else {
@ -2542,7 +2586,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
open_db(p);
sqlite3_busy_timeout(p->db, atoi(azArg[1]));
sqlite3_busy_timeout(p->db, (int)integerValue(azArg[1]));
}else
if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
@ -2592,7 +2636,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
int j;
assert( nArg<=ArraySize(azArg) );
for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){
p->colWidth[j-1] = atoi(azArg[j]);
p->colWidth[j-1] = (int)integerValue(azArg[j]);
}
}else