/ Check-in [300038be]
Login

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

Overview
Comment:Fix bugs in temp database handling introduced by the prevous check-in. (CVS 4288)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 300038be9368556a29efce7cf3657fabfe54d8f9
User & Date: drh 2007-08-24 16:29:24
Context
2007-08-24
17:52
Rework the win32 OS driver to use malloc()/free() directly rather than going through the SQLite memory allocation layer. With this change, the complete quick.test script now runs on windows. There are a few errors, but no segfaults. Progress. (CVS 4289) check-in: 75aad316 user: drh tags: trunk
16:29
Fix bugs in temp database handling introduced by the prevous check-in. (CVS 4288) check-in: 300038be user: drh tags: trunk
16:08
Remove nRef and vfsMutex from the sqlite3_vfs structure. Omit the sqlite3_vfs_release() interface. Less memory allocated for a pager in the common case where the size of the pathname is less than MAX_PATH. (CVS 4287) check-in: b8451da3 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.375 2007/08/24 16:08:29 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.376 2007/08/24 16:29:24 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include <assert.h>
    26     26   #include <string.h>
    27     27   
    28     28   /*
................................................................................
  1804   1804   /*
  1805   1805   ** Open a temporary file. 
  1806   1806   **
  1807   1807   ** Write the file descriptor into *fd.  Return SQLITE_OK on success or some
  1808   1808   ** other error code if we fail. The OS will automatically delete the temporary
  1809   1809   ** file when it is closed.
  1810   1810   **
  1811         -** If zNameOut is 0, then SQLITE_OPEN_SUBJOURNAL is passed to the OS layer.
  1812         -** If zNameOut is not 0, SQLITE_OPEN_TEMP_DB is passed.
         1811  +** If zFilename is 0, then an appropriate temporary filename is
         1812  +** generated automatically and  SQLITE_OPEN_SUBJOURNAL is passed to
         1813  +** the OS layer as the file type.
         1814  +**
         1815  +** If zFilename is not 0, SQLITE_OPEN_TEMP_DB is passed as the file type.
  1813   1816   */
  1814   1817   static int sqlite3PagerOpentemp(
  1815   1818     sqlite3_vfs *pVfs, 
  1816   1819     sqlite3_file *pFile, 
  1817         -  char *zNameOut
         1820  +  char *zFilename
  1818   1821   ){
  1819         -  int cnt = 8;
  1820   1822     int rc;
  1821   1823     int flags = (
  1822   1824        SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
  1823   1825        SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_DELETEONCLOSE
  1824   1826     );
  1825   1827   
  1826   1828     char *zFree = 0;
  1827         -  if( zNameOut==0 ){
         1829  +  if( zFilename==0 ){
  1828   1830       zFree = (char *)sqlite3_malloc(pVfs->mxPathname);
  1829   1831       if( !zFree ){
  1830   1832         return SQLITE_NOMEM;
  1831   1833       }
  1832         -    zNameOut = zFree;
         1834  +    zFilename = zFree;
  1833   1835       flags |= SQLITE_OPEN_SUBJOURNAL;
         1836  +    rc = sqlite3OsGetTempName(pVfs, zFilename);
         1837  +    if( rc!=SQLITE_OK ){
         1838  +      sqlite3_free(zFree);
         1839  +      return rc;
         1840  +    }
  1834   1841     }else{
  1835   1842       flags |= SQLITE_OPEN_TEMP_DB;
  1836   1843     }
  1837   1844   
  1838   1845   #ifdef SQLITE_TEST
  1839   1846     sqlite3_opentemp_count++;  /* Used for testing and analysis only */
  1840   1847   #endif
  1841   1848   
  1842         -  do{
  1843         -    cnt--;
  1844         -    sqlite3OsGetTempName(pVfs, zNameOut);
  1845         -    rc = sqlite3OsOpen(pVfs, zNameOut, pFile, flags, 0);
  1846         -    assert( rc!=SQLITE_OK || pFile->pMethods );
  1847         -  }while( cnt>0 && rc!=SQLITE_OK && rc!=SQLITE_NOMEM );
  1848         -
         1849  +  rc = sqlite3OsOpen(pVfs, zFilename, pFile, flags, 0);
         1850  +  assert( rc!=SQLITE_OK || pFile->pMethods );
  1849   1851     sqlite3_free(zFree);
  1850   1852     return rc;
  1851   1853   }
  1852   1854   
  1853   1855   /*
  1854   1856   ** Create a new page cache and put a pointer to the page cache in *ppPager.
  1855   1857   ** The file to be cached need not exist.  The file is not locked until
................................................................................
  1898   1900       if( strcmp(zFilename,":memory:")==0 ){
  1899   1901         memDb = 1;
  1900   1902         zPathname[0] = 0;
  1901   1903       }else
  1902   1904   #endif
  1903   1905       {
  1904   1906         rc = sqlite3OsFullPathname(pVfs, zFilename, zPathname);
  1905         -      if( rc!=SQLITE_OK ){
  1906         -        sqlite3_free(zPathname);
  1907         -        return rc;
  1908         -      }
  1909   1907       }
  1910   1908     }else{
  1911         -    zPathname[0] = 0;
         1909  +    rc = sqlite3OsGetTempName(pVfs, zPathname);
         1910  +  }
         1911  +  if( rc!=SQLITE_OK ){
         1912  +    sqlite3_free(zPathname);
         1913  +    return rc;
  1912   1914     }
  1913   1915     nPathname = strlen(zPathname);
  1914   1916   
  1915   1917     /* Allocate memory for the pager structure */
  1916   1918     pPager = sqlite3MallocZero(
  1917   1919       sizeof(*pPager) +           /* Pager structure */
  1918   1920       journalFileSize +           /* The journal file structure */ 
................................................................................
  1932   1934     pPager->zJournal = &pPager->zDirectory[nPathname+1];
  1933   1935     pPager->pVfs = pVfs;
  1934   1936     memcpy(pPager->zFilename, zPathname, nPathname+1);
  1935   1937     sqlite3_free(zPathname);
  1936   1938   
  1937   1939     /* Open the pager file.
  1938   1940     */
  1939         -  if( pPager->zFilename[0] ){
         1941  +  if( zFilename && zFilename[0] && !memDb ){
  1940   1942       if( nPathname>(pVfs->mxPathname - sizeof("-journal")) ){
  1941   1943         rc = SQLITE_CANTOPEN;
  1942   1944       }else{
  1943   1945   /***  FIXME:  Might need to be SQLITE_OPEN_TEMP_DB.  Need to pass in
  1944   1946   **** a flag from higher up.
  1945   1947   ****/
  1946   1948         int oflag = 

Changes to test/pager.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is page cache subsystem.
    13     13   #
    14         -# $Id: pager.test,v 1.29 2007/08/24 16:08:29 drh Exp $
           14  +# $Id: pager.test,v 1.30 2007/08/24 16:29:24 drh Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   if {[info commands pager_open]!=""} {
    21     21   db close
................................................................................
   405    405   do_test pager-4.6.1 {
   406    406     pager_close [pager_open ptf2.db -15]
   407    407   } {}
   408    408   
   409    409   # Test truncate on an in-memory database is Ok.
   410    410   ifcapable memorydb {
   411    411     do_test pager-4.6.2 {
   412         -btree_breakpoint
   413    412       set ::p2 [pager_open :memory: 10]
   414    413       pager_truncate $::p2 5
   415    414     } {}
   416    415     do_test pager-4.6.3 {
   417    416       for {set i 1} {$i<5} {incr i} {
   418    417         set p [page_get $::p2 $i]
   419    418         page_write $p "Page $i"