SQLite

Check-in [9340a2c145]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | archive-improvements
Files: files | file ages | folders
SHA3-256: 9340a2c145bcb4b38d19276a16264a37341c617f0554d66e1da653f1d9f85163
User & Date: drh 2018-01-10 14:00:00.949
Context
2018-01-10
15:17
The ".ar" command deduces whether or not the target file is a ZIP or SQLAR and does the appropropriate thing. The "-z" option is omitted. The "--append" option is added to open auxiliary databases using apndvfs. (check-in: 430d1a7daa user: drh tags: archive-improvements)
14:00
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. (check-in: 9340a2c145 user: drh tags: archive-improvements)
13:11
Work on the ".archive" command. (1) Add the --dryrun option. (2) Do not require --file when open on a ZIP archive. (3) Miscellaneous code simplifications. This is an incremental check-in of work in progress. (check-in: a2baada429 user: drh tags: archive-improvements)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/shell.c.in.
5114
5115
5116
5117
5118
5119
5120

5121
5122


5123
5124
5125



5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137

5138
5139
5140
5141
5142
5143
5144
  ArCommand cmd;
  int rc;
  rc = arParseCommand(azArg, nArg, &cmd);
  if( rc==SQLITE_OK ){
    cmd.p = pState;
    cmd.db = pState->db;
    cmd.zSrcTable = "sqlar";

    if( cmd.bZip ){
      if( pState->openMode==SHELL_OPEN_ZIPFILE ){


        cmd.zSrcTable = "zip";
      }else{
        cmd.zSrcTable = "zipfile($archiveFile)";



      }
      if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
        utf8_printf(stderr, "zip archives are read-only\n");
        return SQLITE_ERROR;
      }
    }else if( cmd.zFile ){
      int flags;
      if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
        flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
      }else{
        flags = SQLITE_OPEN_READONLY;
      }

      rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags, 0);
      if( rc!=SQLITE_OK ){
        utf8_printf(stderr, "cannot open file: %s (%s)\n", 
            cmd.zFile, sqlite3_errmsg(cmd.db)
        );
        sqlite3_close(cmd.db);
        return rc;







>
|
<
>
>

|

>
>
>












>







5114
5115
5116
5117
5118
5119
5120
5121
5122

5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
  ArCommand cmd;
  int rc;
  rc = arParseCommand(azArg, nArg, &cmd);
  if( rc==SQLITE_OK ){
    cmd.p = pState;
    cmd.db = pState->db;
    cmd.zSrcTable = "sqlar";
    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 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");
        return SQLITE_ERROR;
      }
    }else if( cmd.zFile ){
      int flags;
      if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
        flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
      }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", 
            cmd.zFile, sqlite3_errmsg(cmd.db)
        );
        sqlite3_close(cmd.db);
        return rc;
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182

      default:
        assert( cmd.eCmd==AR_CMD_UPDATE );
        rc = arCreateOrUpdateCommand(&cmd, 1);
        break;
    }

    if( cmd.zFile ){
      sqlite3_close(cmd.db);
    }
  }

  return rc;
}
/* End of the ".archive" or ".ar" command logic







|







5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188

      default:
        assert( cmd.eCmd==AR_CMD_UPDATE );
        rc = arCreateOrUpdateCommand(&cmd, 1);
        break;
    }

    if( cmd.db!=pState->db ){
      sqlite3_close(cmd.db);
    }
  }

  return rc;
}
/* End of the ".archive" or ".ar" command logic