简体   繁体   中英

sqlite3 command line inconsistent return codes

I cannot find documentation anywhere on the internet for return codes from the sqlite3 command line program.

Trying to use it programmatically, I've found that some errors will print to the screen but still return zero. For example, anything that returns the error message "Error: incomplete SQL" will not cause the command line application to return nonzero:

$ echo 'foo' > /tmp/foo.sql
$ sqlite3 /tmp/foo.db < /tmp/foo.sql
Error: incomplete SQL: foo
$ echo $?
0

Is this a bug? I would think so, particularly given this equivalent line:

$ sqlite3 /tmp/foo.db "foo"
-- Loading resources from /home/yomomma/.sqliterc

Error: near "foo": syntax error
$ echo $?
1

Can anyone point me to documentation on the expected return values for sqlite3?

(The problem is not my .sqliterc, reproduced in full here:

.mode column
.headers on
.nullvalue '<NULL!>'

)

Edit:

$ sqlite3 --version
-- Loading resources from /home/yomomma/.sqliterc

3.7.13 2012-06-11 02:05:22 f5b5a13f7394dc143aa136f1d4faba6839eaa6dc

This could be a bug in SQLite (v3.8.6). I am looking at shell.c:3644

if( nSql ){
  if( !_all_whitespace(zSql) ){
    fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
  }
  free(zSql);
}
free(zLine);
return errCnt>0;

I think there should be a errCnt++; after the fprintf statement. This increment operation is used earlier in the code after detecting another type of error. I will report this to the author.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM