/ Check-in [80d925b8]
Login

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

Overview
Comment::-) (CVS 1696)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 80d925b82b176df7f73a1747a6ed711ac3d9a0d3
User & Date: drh 2000-06-02 02:09:23
Context
2000-06-02
13:27
:-) (CVS 37) check-in: 2b55f9b7 user: drh tags: trunk
02:09
:-) (CVS 1696) check-in: 80d925b8 user: drh tags: trunk
01:51
:-) (CVS 36) check-in: d3c31def user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/dbbe.c.

    26     26   ** sqlite and the code that does the actually reading and writing
    27     27   ** of information to the disk.
    28     28   **
    29     29   ** This file uses GDBM as the database backend.  It should be
    30     30   ** relatively simple to convert to a different database such
    31     31   ** as NDBM, SDBM, or BerkeleyDB.
    32     32   **
    33         -** $Id: dbbe.c,v 1.9 2000/06/02 01:51:20 drh Exp $
           33  +** $Id: dbbe.c,v 1.10 2000/06/02 02:09:23 drh Exp $
    34     34   */
    35     35   #include "sqliteInt.h"
    36     36   #include <gdbm.h>
    37     37   #include <sys/stat.h>
    38     38   #include <unistd.h>
    39     39   #include <ctype.h>
    40     40   #include <time.h>
................................................................................
    67     67   */
    68     68   struct Dbbe {
    69     69     char *zDir;        /* The directory containing the database */
    70     70     int write;         /* True for write permission */
    71     71     BeFile *pOpen;     /* List of open files */
    72     72     int nTemp;         /* Number of temporary files created */
    73     73     FILE **apTemp;     /* Space to hold temporary file pointers */
           74  +  char **azTemp;     /* Names of the temporary files */
    74     75     struct rc4 rc4;    /* The random number generator */
    75     76   };
    76     77   
    77     78   /*
    78     79   ** Each file within the database is an instance of this
    79     80   ** structure.
    80     81   */
................................................................................
   178    179   }
   179    180   
   180    181   /*
   181    182   ** Completely shutdown the given database.  Close all files.  Free all memory.
   182    183   */
   183    184   void sqliteDbbeClose(Dbbe *pBe){
   184    185     BeFile *pFile, *pNext;
          186  +  int i;
   185    187     for(pFile=pBe->pOpen; pFile; pFile=pNext){
   186    188       pNext = pFile->pNext;
   187    189       gdbm_close(pFile->dbf);
   188    190       memset(pFile, 0, sizeof(*pFile));   
   189    191       sqliteFree(pFile);
   190    192     }
          193  +  for(i=0; i<pBe->nTemp; i++){
          194  +    if( pBe->apTemp[i]!=0 ){
          195  +      unlink(pBe->azTemp[i]);
          196  +      fclose(pBe->apTemp[i]);
          197  +      sqliteFree(pBe->azTemp[i]);
          198  +      pBe->apTemp[i] = 0;
          199  +      pBe->azTemp[i] = 0;
          200  +      break;
          201  +    }
          202  +  }
          203  +  sqliteFree(pBe->azTemp);
          204  +  sqliteFree(pBe->apTemp);
   191    205     memset(pBe, 0, sizeof(*pBe));
   192    206     sqliteFree(pBe);
   193    207   }
   194    208   
   195    209   /*
   196    210   ** Translate the name of a table into the name of a file that holds
   197    211   ** that table.  Space to hold the filename is obtained from
................................................................................
   600    614   
   601    615     for(i=0; i<pBe->nTemp; i++){
   602    616       if( pBe->apTemp[i]==0 ) break;
   603    617     }
   604    618     if( i>=pBe->nTemp ){
   605    619       pBe->nTemp++;
   606    620       pBe->apTemp = sqliteRealloc(pBe->apTemp, pBe->nTemp*sizeof(FILE*) );
          621  +    pBe->azTemp = sqliteRealloc(pBe->azTemp, pBe->nTemp*sizeof(char*) );
   607    622     }
   608    623     if( pBe->apTemp==0 ){
   609    624       *ppFile = 0;
   610    625       return SQLITE_NOMEM;
   611    626     }
   612    627     limit = 4;
   613    628     zFile = 0;
................................................................................
   616    631       sqliteFree(zFile);
   617    632       zFile = 0;
   618    633       sqliteSetString(&zFile, pBe->zDir, zBuf, 0);
   619    634     }while( access(zFile,0)==0 && limit-- >= 0 );
   620    635     *ppFile = pBe->apTemp[i] = fopen(zFile, "w+");
   621    636     if( pBe->apTemp[i]==0 ){
   622    637       rc = SQLITE_ERROR;
          638  +    sqliteFree(zFile);
          639  +    pBe->azTemp[i] = 0;
          640  +  }else{
          641  +    pBe->azTemp[i] = zFile;
   623    642     }
   624         -  sqliteFree(zFile);
   625    643     return rc;
   626    644   }
   627    645   
   628    646   /*
   629    647   ** Close a temporary file opened using sqliteDbbeOpenTempFile()
   630    648   */
   631    649   void sqliteDbbeCloseTempFile(Dbbe *pBe, FILE *f){
   632    650     int i;
   633    651     for(i=0; i<pBe->nTemp; i++){
   634    652       if( pBe->apTemp[i]==f ){
   635         -      char *zFile;
   636         -      char zBuf[30];
   637         -      sprintf(zBuf, "/_temp_%d~", i);
   638         -      zFile = 0;
   639         -      sqliteSetString(&zFile, pBe->zDir, zBuf, 0);
   640         -      unlink(zFile);
   641         -      sqliteFree(zFile);
          653  +      unlink(pBe->azTemp[i]);
          654  +      sqliteFree(pBe->azTemp[i]);
   642    655         pBe->apTemp[i] = 0;
          656  +      pBe->azTemp[i] = 0;
   643    657         break;
   644    658       }
   645    659     }
   646    660     fclose(f);
   647    661   }