/ 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 Unified Diffs Ignore Whitespace Patch

Changes to ext/misc/appendvfs.c.

436
437
438
439
440
441
442
443
444

445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466


467
468
469
470
471
472
473
474
  sqlite3_int64 sz;
  pSubVfs = ORIGVFS(pVfs);
  if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
    return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
  }
  p = (ApndFile*)pFile;
  memset(p, 0, sizeof(*p));
  p->base.pMethods = &apnd_io_methods;
  pSubFile = ORIGFILE(pFile);

  rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
  if( rc ) return rc;
  rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
  if( rc ){
    pSubFile->pMethods->xClose(pSubFile);
    return rc;
  }
  if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
    memmove(pFile, pSubFile, pSubVfs->szOsFile);
    return SQLITE_OK;
  }
  p->iMark = 0;
  p->iPgOne = apndReadMark(sz, pFile);
  if( p->iPgOne>0 ){
    return SQLITE_OK;
  }
  if( (flags & SQLITE_OPEN_CREATE)==0 ){
    pSubFile->pMethods->xClose(pSubFile);
    pFile->pMethods = 0;
    return SQLITE_CANTOPEN;
  }
  p->iPgOne = (sz+0xfff) & ~(sqlite3_int64)0xfff;


  return SQLITE_OK;
}

/*
** All other VFS methods are pass-thrus.
*/
static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
  return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);







<

>

|



|












<
|


>
>
|







436
437
438
439
440
441
442

443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462

463
464
465
466
467
468
469
470
471
472
473
474
475
  sqlite3_int64 sz;
  pSubVfs = ORIGVFS(pVfs);
  if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
    return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
  }
  p = (ApndFile*)pFile;
  memset(p, 0, sizeof(*p));

  pSubFile = ORIGFILE(pFile);
  p->base.pMethods = &apnd_io_methods;
  rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
  if( rc ) goto apnd_open_done;
  rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
  if( rc ){
    pSubFile->pMethods->xClose(pSubFile);
    goto apnd_open_done;
  }
  if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
    memmove(pFile, pSubFile, pSubVfs->szOsFile);
    return SQLITE_OK;
  }
  p->iMark = 0;
  p->iPgOne = apndReadMark(sz, pFile);
  if( p->iPgOne>0 ){
    return SQLITE_OK;
  }
  if( (flags & SQLITE_OPEN_CREATE)==0 ){
    pSubFile->pMethods->xClose(pSubFile);

    rc = SQLITE_CANTOPEN;
  }
  p->iPgOne = (sz+0xfff) & ~(sqlite3_int64)0xfff;
apnd_open_done:
  if( rc ) pFile->pMethods = 0;
  return rc;
}

/*
** All other VFS methods are pass-thrus.
*/
static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
  return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);

Changes to tool/sqltclsh.tcl.

1
2
3
4



5
6
7
8
9
10
11
# Try to open the executable as a database and read the "scripts.data"
# field where "scripts.name" is 'main.tcl'
#
catch {



  sqlite3 db $argv0 -vfs apndvfs -create 0
  set mainscript [db one {SELECT data FROM scripts WHERE name='main.tcl'}]
}
if {[info exists mainscript]} {
  eval $mainscript
  return
} else {




>
>
>







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