/ Check-in [46b341e3]
Login

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

Overview
Comment:Fix the appendvfs so that it leaves sqlite3_file->pMethods as NULL if it fails to open.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | appendvfs
Files: files | file ages | folders
SHA3-256: 46b341e3ad11b807ae50f001b970299de7ea0d523dbb639ee10f1d5aca5d958b
User & Date: drh 2018-01-06 13:33:21
Context
2018-01-06
13:42
Add the appendvfs extension and code for the sqltclsh.exe executable. check-in: b0a43e32 user: drh tags: trunk
13:33
Fix the appendvfs so that it leaves sqlite3_file->pMethods as NULL if it fails to open. Closed-Leaf check-in: 46b341e3 user: drh tags: appendvfs
04:34
Add sqltclsh.exe to the windows makefile. check-in: a6d5c7c2 user: drh tags: appendvfs
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/appendvfs.c.

   436    436     sqlite3_int64 sz;
   437    437     pSubVfs = ORIGVFS(pVfs);
   438    438     if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
   439    439       return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
   440    440     }
   441    441     p = (ApndFile*)pFile;
   442    442     memset(p, 0, sizeof(*p));
   443         -  p->base.pMethods = &apnd_io_methods;
   444    443     pSubFile = ORIGFILE(pFile);
          444  +  p->base.pMethods = &apnd_io_methods;
   445    445     rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
   446         -  if( rc ) return rc;
          446  +  if( rc ) goto apnd_open_done;
   447    447     rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
   448    448     if( rc ){
   449    449       pSubFile->pMethods->xClose(pSubFile);
   450         -    return rc;
          450  +    goto apnd_open_done;
   451    451     }
   452    452     if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
   453    453       memmove(pFile, pSubFile, pSubVfs->szOsFile);
   454    454       return SQLITE_OK;
   455    455     }
   456    456     p->iMark = 0;
   457    457     p->iPgOne = apndReadMark(sz, pFile);
   458    458     if( p->iPgOne>0 ){
   459    459       return SQLITE_OK;
   460    460     }
   461    461     if( (flags & SQLITE_OPEN_CREATE)==0 ){
   462    462       pSubFile->pMethods->xClose(pSubFile);
   463         -    pFile->pMethods = 0;
   464         -    return SQLITE_CANTOPEN;
          463  +    rc = SQLITE_CANTOPEN;
   465    464     }
   466    465     p->iPgOne = (sz+0xfff) & ~(sqlite3_int64)0xfff;
   467         -  return SQLITE_OK;
          466  +apnd_open_done:
          467  +  if( rc ) pFile->pMethods = 0;
          468  +  return rc;
   468    469   }
   469    470   
   470    471   /*
   471    472   ** All other VFS methods are pass-thrus.
   472    473   */
   473    474   static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
   474    475     return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);

Changes to tool/sqltclsh.tcl.

     1      1   # Try to open the executable as a database and read the "scripts.data"
     2      2   # field where "scripts.name" is 'main.tcl'
     3      3   #
     4      4   catch {
            5  +  if {![file exists $argv0] && [file exists $argv0.exe]} {
            6  +    append argv0 .exe
            7  +  }
     5      8     sqlite3 db $argv0 -vfs apndvfs -create 0
     6      9     set mainscript [db one {SELECT data FROM scripts WHERE name='main.tcl'}]
     7     10   }
     8     11   if {[info exists mainscript]} {
     9     12     eval $mainscript
    10     13     return
    11     14   } else {