I have found that the following command in my opinion returns an
incorrect exit code:
eric@sirius:~/src/sqlite-amalgamation-3071602$ ./sqlite3 appl.db .quit
eric@sirius:~/src/sqlite-amalgamation-3071602$ echo $?
2
This should (in my opinion) return 0 for success instead of 2. In
interactive mode the correct value is returned:
eric@sirius:~/src/sqlite-amalgamation-3071602$ ./sqlite3 appl.db
SQLite version 3.7.16.2 2013-04-12 11:52:43
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .quit
eric@sirius:~/src/sqlite-amalgamation-3071602$ echo $?
0
The cause is that do_meta_command() returns 2 if an exit is requested.
In non-interactive mode this value is not filtered and passed directly
back to the shell.
I do not know if this is intentional or not. If so, please ignore this
message.
Below is a patch which will fix the issue and have the shell return 0
even if an exit is requested non-interactively. The fix is rather crude,
it will set rc to 0 if do_meta_command() returned 2. As far as I can
tell the return code 2 is used exclusively for exit/quit requests so
this should be safe to do.
===============================
--- shell.c.org 2013-04-12 14:21:39.000000000 +0200
+++ shell.c 2013-04-16 20:04:12.000000000 +0200
@@ -3128,6 +3128,7 @@
z = cmdline_option_value(argc,argv,++i);
if( z[0]=='.' ){
rc = do_meta_command(z, &data);
+ rc = rc == 2 ? 0 : rc;
if( rc && bail_on_error ) return rc;
}else{
open_db(&data);
@@ -3152,6 +3153,7 @@
*/
if( zFirstCmd[0]=='.' ){
rc = do_meta_command(zFirstCmd, &data);
+ rc = rc == 2 ? 0 : rc;
}else{
open_db(&data);
rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
===============================
Of course the above snippet is hereby donated to the Public Domain.
Thanks for all the hard work, I appreciate it immensely.
Regards,
Eric.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users