aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2018-01-10 14:00:00 +0000
committerdrh <drh@noemail.net>2018-01-10 14:00:00 +0000
commita82c95b47d17c172077bdc9c1b225a577498efdd (patch)
tree098bc9e3b8781c07522a4a2aad93ec45909c0171 /src
parentb376b3d6aa5648e1ffe9ca5ff09b2d29003834c7 (diff)
downloadsqlite-a82c95b47d17c172077bdc9c1b225a577498efdd.tar.gz
sqlite-a82c95b47d17c172077bdc9c1b225a577498efdd.zip
Allow the use of ".ar -t" without specifying an archive file or the "-z"
option when the command-line shell is opened on a ZIP archive. FossilOrigin-Name: 9340a2c145bcb4b38d19276a16264a37341c617f0554d66e1da653f1d9f85163
Diffstat (limited to 'src')
-rw-r--r--src/shell.c.in14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/shell.c.in b/src/shell.c.in
index 4bfc1c85c..ad5300336 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -5118,11 +5118,16 @@ static int arDotCommand(
cmd.p = pState;
cmd.db = pState->db;
cmd.zSrcTable = "sqlar";
- if( cmd.bZip ){
- if( pState->openMode==SHELL_OPEN_ZIPFILE ){
+ if( cmd.bZip || pState->openMode==SHELL_OPEN_ZIPFILE ){
+ if( cmd.zFile==0
+ && sqlite3_table_column_metadata(cmd.db,0,"zip","name",0,0,0,0,0)==SQLITE_OK
+ ){
cmd.zSrcTable = "zip";
- }else{
+ }else if( cmd.zFile!=0 ){
cmd.zSrcTable = "zipfile($archiveFile)";
+ }else{
+ utf8_printf(stderr, "no zip archive file specified\n");
+ return SQLITE_ERROR;
}
if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
utf8_printf(stderr, "zip archives are read-only\n");
@@ -5135,6 +5140,7 @@ static int arDotCommand(
}else{
flags = SQLITE_OPEN_READONLY;
}
+ cmd.db = 0;
rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags, 0);
if( rc!=SQLITE_OK ){
utf8_printf(stderr, "cannot open file: %s (%s)\n",
@@ -5172,7 +5178,7 @@ static int arDotCommand(
break;
}
- if( cmd.zFile ){
+ if( cmd.db!=pState->db ){
sqlite3_close(cmd.db);
}
}