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