Fix the CLI to keep proper track of input line numbers for use in error

messages, even after processing in-line hex database inputs using
".open --hexdb".

FossilOrigin-Name: 7ffa9858162774cba03a565a7b65135d9e8bfea726af1a29de6898f66c4b1261
This commit is contained in:
drh 2018-12-13 18:59:30 +00:00
parent 60379d4243
commit 2c8ee026ba
3 changed files with 28 additions and 14 deletions

View File

@ -1,5 +1,5 @@
C Fix\sthe\sCLI\sso\sthat\sthe\s".open\s--hexdb"\scommand\sworks\seven\sif\sit\sis\scontained\nin\sa\ssubscript\sthat\sis\sread\susing\s".read".
D 2018-12-13T18:30:01.890
C Fix\sthe\sCLI\sto\skeep\sproper\strack\sof\sinput\sline\snumbers\sfor\suse\sin\serror\nmessages,\seven\safter\sprocessing\sin-line\shex\sdatabase\sinputs\susing\n".open\s--hexdb".
D 2018-12-13T18:59:30.657
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 2f1b61ac62689ca4e9cbff9fdb359578ea37ddd9252355ec0b7b9700ad56fe90
@ -508,7 +508,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c abd65c518c198400193c6319a70c0d722fa30a35be89dc898917ff6489edf017
F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
F src/select.c 8c7317d5ee920516a56b8b4ca79fbfca70a1f8b52d67e884c808ea3a016c04e3
F src/shell.c.in b998c6d78bc886e900780abf8ef89fc33c0884058ee6583ff466e52a273872e6
F src/shell.c.in a9b26ab3925e179f4f1a3a910ffe634195bc6becab8aa3e02bbb0dc652d30543
F src/sqlite.h.in 92fd656c26cc76de9fa8c5bf1a473066e3b5c6da345a447679f0f44de1aa4edd
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 960f1b86c3610fa23cb6a267572a97dcf286e77aa0dd3b9b23292ffaa1ea8683
@ -1786,7 +1786,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P e3bf1d3ea5f748c5142c2403813fdace5aedc1fc68f0dcd5eae40a2fe763fedb
R a7af747c108542ed7a9f41235cf0fca7
P 67a87399b8ad8f1ce3052ee3159906f5c6df3d7b5691b3acac856bd2f1c82088
R f859719ab1a18f7f99e4d481a8b5bfc0
U drh
Z c11351b3fcf7b9c9d8ba68269cb05836
Z 99cc51545a333a02cea3f7ae2232a64b

View File

@ -1 +1 @@
67a87399b8ad8f1ce3052ee3159906f5c6df3d7b5691b3acac856bd2f1c82088
7ffa9858162774cba03a565a7b65135d9e8bfea726af1a29de6898f66c4b1261

View File

@ -1011,6 +1011,7 @@ struct ShellState {
unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
int outCount; /* Revert to stdout when reaching zero */
int cnt; /* Number of records displayed so far */
int lineno; /* Line number of last line read from in */
FILE *in; /* Read commands from this stream */
FILE *out; /* Write results here */
FILE *traceOut; /* Output for sqlite3_trace() */
@ -3734,7 +3735,7 @@ int deduceDatabaseType(const char *zName, int dfltZip){
*/
static unsigned char *readHexDb(ShellState *p, int *pnData){
unsigned char *a = 0;
int nLine = 1;
int nLine;
int n = 0;
int pgsz = 0;
int iOffset = 0;
@ -3742,17 +3743,20 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){
int rc;
FILE *in;
unsigned char x[16];
char zLine[100];
char zLine[1000];
if( p->zDbFilename ){
in = fopen(p->zDbFilename, "r");
if( in==0 ){
utf8_printf(stderr, "cannot open \"%s\" for reading\n", p->zDbFilename);
return 0;
}
nLine = 0;
}else{
in = p->in;
nLine = p->lineno;
}
*pnData = 0;
nLine++;
if( fgets(zLine, sizeof(zLine), in)==0 ) goto readHexDb_error;
rc = sscanf(zLine, "| size %d pagesize %d", &n, &pgsz);
if( rc!=2 ) goto readHexDb_error;
@ -3767,7 +3771,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){
utf8_printf(stderr, "invalid pagesize\n");
goto readHexDb_error;
}
for(nLine=2; fgets(zLine, sizeof(zLine), in)!=0; nLine++){
for(nLine++; fgets(zLine, sizeof(zLine), in)!=0; nLine++){
rc = sscanf(zLine, "| page %d offset %d", &j, &k);
if( rc==2 ){
iOffset = k;
@ -3790,7 +3794,11 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){
}
}
*pnData = n;
if( in!=p->in ) fclose(in);
if( in!=p->in ){
fclose(in);
}else{
p->lineno = nLine;
}
return a;
readHexDb_error:
@ -3798,8 +3806,10 @@ readHexDb_error:
fclose(in);
}else{
while( fgets(zLine, sizeof(zLine), p->in)!=0 ){
nLine++;
if(strncmp(zLine, "| end ", 6)==0 ) break;
}
p->lineno = nLine;
}
sqlite3_free(a);
utf8_printf(stderr,"Error on line %d of --hexdb input\n", nLine);
@ -6972,6 +6982,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
FILE *inSaved = p->in;
int savedLineno = p->lineno;
if( nArg!=2 ){
raw_printf(stderr, "Usage: .read FILE\n");
rc = 1;
@ -6986,6 +6997,7 @@ static int do_meta_command(char *zLine, ShellState *p){
fclose(p->in);
}
p->in = inSaved;
p->lineno = savedLineno;
}else
if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
@ -8335,9 +8347,9 @@ static int process_input(ShellState *p){
int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
int rc; /* Error code */
int errCnt = 0; /* Number of errors seen */
int lineno = 0; /* Current line number */
int startline = 0; /* Line number for start of current input */
p->lineno = 0;
while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
fflush(p->out);
zLine = one_input_line(p->in, zLine, nSql>0);
@ -8350,7 +8362,7 @@ static int process_input(ShellState *p){
if( p->in!=0 ) break;
seenInterrupt = 0;
}
lineno++;
p->lineno++;
if( nSql==0 && _all_whitespace(zLine) ){
if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
continue;
@ -8382,7 +8394,7 @@ static int process_input(ShellState *p){
for(i=0; zLine[i] && IsSpace(zLine[i]); i++){}
assert( nAlloc>0 && zSql!=0 );
memcpy(zSql, zLine+i, nLine+1-i);
startline = lineno;
startline = p->lineno;
nSql = nLine-i;
}else{
zSql[nSql++] = '\n';
@ -8495,6 +8507,7 @@ static void process_sqliterc(
const char *sqliterc = sqliterc_override;
char *zBuf = 0;
FILE *inSaved = p->in;
int savedLineno = p->lineno;
if (sqliterc == NULL) {
home_dir = find_home_dir(0);
@ -8515,6 +8528,7 @@ static void process_sqliterc(
fclose(p->in);
}
p->in = inSaved;
p->lineno = savedLineno;
sqlite3_free(zBuf);
}