Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Simplify the BTree interface by shortening names. Added two new methods for accessing the current filename and for changing the name of the database file. (CVS 900) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
185d8dc8d0c26cef36aeba6992823e51 |
User & Date: | drh 2003-04-06 20:44:45.000 |
Context
2003-04-06
| ||
20:52 | Move the implementation of VACUUM into a separate source file. (CVS 901) (check-in: b123c165fd user: drh tags: trunk) | |
20:44 | Simplify the BTree interface by shortening names. Added two new methods for accessing the current filename and for changing the name of the database file. (CVS 900) (check-in: 185d8dc8d0 user: drh tags: trunk) | |
2003-04-05
| ||
16:56 | More testing of ATTACH and DETACH. (CVS 899) (check-in: 51f515f28c user: drh tags: trunk) | |
Changes
Changes to src/btree.c.
1 2 3 4 5 6 7 8 9 10 11 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** $Id: btree.c,v 1.87 2003/04/06 20:44:45 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to ** ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3: ** "Sorting And Searching", pages 473-480. Addison-Wesley ** Publishing Company, Reading, Massachusetts. |
︙ | ︙ | |||
3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 | /* Clean up and report errors. */ sqliteFree(sCheck.anRef); return sCheck.zErrMsg; } static BtOps sqliteBtreeOps = { sqliteBtreeClose, sqliteBtreeSetCacheSize, sqliteBtreeSetSafetyLevel, sqliteBtreeBeginTrans, sqliteBtreeCommit, sqliteBtreeRollback, sqliteBtreeBeginCkpt, sqliteBtreeCommitCkpt, sqliteBtreeRollbackCkpt, sqliteBtreeCreateTable, sqliteBtreeCreateIndex, sqliteBtreeDropTable, sqliteBtreeClearTable, sqliteBtreeCursor, sqliteBtreeGetMeta, sqliteBtreeUpdateMeta, sqliteBtreeIntegrityCheck, | > > > > > > > > > > > > > > > > > > > > > | > < | 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 | /* Clean up and report errors. */ sqliteFree(sCheck.anRef); return sCheck.zErrMsg; } /* ** Return the full pathname of the underlying database file. */ static const char *sqliteBtreeGetFilename(Btree *pBt){ assert( pBt->pPager!=0 ); return sqlitepager_filename(pBt->pPager); } /* ** Change the name of the underlying database file. */ static int sqliteBtreeChangeFilename(Btree *pBt, const char *zNew){ return sqlitepager_rename(pBt->pPager, zNew); } /* ** The following tables contain pointers to all of the interface ** routines for this implementation of the B*Tree backend. To ** substitute a different implemention of the backend, one has merely ** to provide pointers to alternative functions in similar tables. */ static BtOps sqliteBtreeOps = { sqliteBtreeClose, sqliteBtreeSetCacheSize, sqliteBtreeSetSafetyLevel, sqliteBtreeBeginTrans, sqliteBtreeCommit, sqliteBtreeRollback, sqliteBtreeBeginCkpt, sqliteBtreeCommitCkpt, sqliteBtreeRollbackCkpt, sqliteBtreeCreateTable, sqliteBtreeCreateIndex, sqliteBtreeDropTable, sqliteBtreeClearTable, sqliteBtreeCursor, sqliteBtreeGetMeta, sqliteBtreeUpdateMeta, sqliteBtreeIntegrityCheck, sqliteBtreeGetFilename, sqliteBtreeChangeFilename, #ifdef SQLITE_TEST sqliteBtreePageDump, sqliteBtreePager #endif }; static BtCursorOps sqliteBtreeCursorOps = { sqliteBtreeMoveto, sqliteBtreeDelete, sqliteBtreeInsert, sqliteBtreeFirst, sqliteBtreeLast, sqliteBtreeNext, |
︙ | ︙ |
Changes to src/btree.h.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite B-Tree file ** subsystem. See comments in the source code for a detailed description ** of what each interface routine does. ** | | > > > > > > > > > > > > > > > > | | | < | | | | | | < | | | | < | < | | < | | > | | < | > > > | | | | | | | | | | | | | | | < | > > > | < | < | < | < | < | < | < | < | < | | | | < | | | | < | | < | < | < | < | < | | | < | | < | < | < | > > > | | | < | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite B-Tree file ** subsystem. See comments in the source code for a detailed description ** of what each interface routine does. ** ** @(#) $Id: btree.h,v 1.30 2003/04/06 20:44:45 drh Exp $ */ #ifndef _BTREE_H_ #define _BTREE_H_ /* ** Forward declarations of structure */ typedef struct Btree Btree; typedef struct BtCursor BtCursor; typedef struct BtOps BtOps; typedef struct BtCursorOps BtCursorOps; /* ** An instance of the following structure contains pointers to all ** methods against an open BTree. Alternative BTree implementations ** (examples: file based versus in-memory) can be created by substituting ** different methods. Users of the BTree cannot tell the difference. ** ** In C++ we could do this by defining a virtual base class and then ** creating subclasses for each different implementation. But this is ** C not C++ so we have to be a little more explicit. */ struct BtOps { int (*Close)(Btree*); int (*SetCacheSize)(Btree*, int); int (*SetSafetyLevel)(Btree*, int); int (*BeginTrans)(Btree*); int (*Commit)(Btree*); int (*Rollback)(Btree*); int (*BeginCkpt)(Btree*); int (*CommitCkpt)(Btree*); int (*RollbackCkpt)(Btree*); int (*CreateTable)(Btree*, int*); int (*CreateIndex)(Btree*, int*); int (*DropTable)(Btree*, int); int (*ClearTable)(Btree*, int); int (*Cursor)(Btree*, int iTable, int wrFlag, BtCursor **ppCur); int (*GetMeta)(Btree*, int*); int (*UpdateMeta)(Btree*, int*); char *(*IntegrityCheck)(Btree*, int*, int); const char *(*GetFilename)(Btree*); int (*ChangeFilename)(Btree*, const char *zNew); #ifdef SQLITE_TEST int (*PageDump)(Btree*, int, int); struct Pager *(*Pager)(Btree*); #endif }; /* ** An instance of this structure defines all of the methods that can ** be executed against a cursor. */ struct BtCursorOps { int (*Moveto)(BtCursor*, const void *pKey, int nKey, int *pRes); int (*Delete)(BtCursor*); int (*Insert)(BtCursor*, const void *pKey, int nKey, const void *pData, int nData); int (*First)(BtCursor*, int *pRes); int (*Last)(BtCursor*, int *pRes); int (*Next)(BtCursor*, int *pRes); int (*Previous)(BtCursor*, int *pRes); int (*KeySize)(BtCursor*, int *pSize); int (*Key)(BtCursor*, int offset, int amt, char *zBuf); int (*KeyCompare)(BtCursor*, const void *pKey, int nKey, int nIgnore, int *pRes); int (*DataSize)(BtCursor*, int *pSize); int (*Data)(BtCursor*, int offset, int amt, char *zBuf); int (*CloseCursor)(BtCursor*); #ifdef SQLITE_TEST int (*CursorDump)(BtCursor*, int*); #endif }; /* ** The number of 4-byte "meta" values contained on the first page of each ** database file. */ #define SQLITE_N_BTREE_META 10 int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree); #if !defined(SQLITE_NO_BTREE_DEFS) #define btOps(pBt) (*((BtOps **)(pBt))) #define btCOps(pCur) (*((BtCursorOps **)(pCur))) #define sqliteBtreeClose(pBt) (btOps(pBt)->Close(pBt)) #define sqliteBtreeSetCacheSize(pBt, sz) (btOps(pBt)->SetCacheSize(pBt, sz)) #define sqliteBtreeSetSafetyLevel(pBt, sl) (btOps(pBt)->SetSafetyLevel(pBt, sl)) #define sqliteBtreeBeginTrans(pBt) (btOps(pBt)->BeginTrans(pBt)) #define sqliteBtreeCommit(pBt) (btOps(pBt)->Commit(pBt)) #define sqliteBtreeRollback(pBt) (btOps(pBt)->Rollback(pBt)) #define sqliteBtreeBeginCkpt(pBt) (btOps(pBt)->BeginCkpt(pBt)) #define sqliteBtreeCommitCkpt(pBt) (btOps(pBt)->CommitCkpt(pBt)) #define sqliteBtreeRollbackCkpt(pBt) (btOps(pBt)->RollbackCkpt(pBt)) #define sqliteBtreeCreateTable(pBt,piTable)\ (btOps(pBt)->CreateTable(pBt,piTable)) #define sqliteBtreeCreateIndex(pBt, piIndex)\ (btOps(pBt)->CreateIndex(pBt, piIndex)) #define sqliteBtreeDropTable(pBt, iTable) (btOps(pBt)->DropTable(pBt, iTable)) #define sqliteBtreeClearTable(pBt, iTable)\ (btOps(pBt)->ClearTable(pBt, iTable)) #define sqliteBtreeCursor(pBt, iTable, wrFlag, ppCur)\ (btOps(pBt)->Cursor(pBt, iTable, wrFlag, ppCur)) #define sqliteBtreeMoveto(pCur, pKey, nKey, pRes)\ (btCOps(pCur)->Moveto(pCur, pKey, nKey, pRes)) #define sqliteBtreeDelete(pCur) (btCOps(pCur)->Delete(pCur)) #define sqliteBtreeInsert(pCur, pKey, nKey, pData, nData) \ (btCOps(pCur)->Insert(pCur, pKey, nKey, pData, nData)) #define sqliteBtreeFirst(pCur, pRes) (btCOps(pCur)->First(pCur, pRes)) #define sqliteBtreeLast(pCur, pRes) (btCOps(pCur)->Last(pCur, pRes)) #define sqliteBtreeNext(pCur, pRes) (btCOps(pCur)->Next(pCur, pRes)) #define sqliteBtreePrevious(pCur, pRes) (btCOps(pCur)->Previous(pCur, pRes)) #define sqliteBtreeKeySize(pCur, pSize) (btCOps(pCur)->KeySize(pCur, pSize) ) #define sqliteBtreeKey(pCur, offset, amt, zBuf)\ (btCOps(pCur)->Key(pCur, offset, amt, zBuf)) #define sqliteBtreeKeyCompare(pCur, pKey, nKey, nIgnore, pRes)\ (btCOps(pCur)->KeyCompare(pCur, pKey, nKey, nIgnore, pRes)) #define sqliteBtreeDataSize(pCur, pSize) (btCOps(pCur)->DataSize(pCur, pSize)) #define sqliteBtreeData(pCur, offset, amt, zBuf)\ (btCOps(pCur)->Data(pCur, offset, amt, zBuf)) #define sqliteBtreeCloseCursor(pCur) (btCOps(pCur)->CloseCursor(pCur)) #define sqliteBtreeGetMeta(pBt, aMeta) (btOps(pBt)->GetMeta(pBt, aMeta)) #define sqliteBtreeUpdateMeta(pBt, aMeta) (btOps(pBt)->UpdateMeta(pBt, aMeta)) #define sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot)\ (btOps(pBt)->IntegrityCheck(pBt, aRoot, nRoot)) #define sqliteBtreeGetFilename(pBt) (btOps(pBt)->GetFilename(pBt)) #define sqliteBtreeChangeFilename(pBt, zNew)\ (btOps(pBt)->ChangeFilename(pBt, zNew)) #endif #ifdef SQLITE_TEST #if !defined(SQLITE_NO_BTREE_DEFS) #define sqliteBtreePageDump(pBt, pgno, recursive)\ (btOps(pBt)->PageDump(pBt, pgno, recursive)) #define sqliteBtreeCursorDump(pCur, aResult)\ (btCOps(pCur)->CursorDump(pCur, aResult)) #define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt)) #endif int btree_native_byte_order; #endif #endif /* _BTREE_H_ */ |
Changes to src/os.c.
︙ | ︙ | |||
267 268 269 270 271 272 273 | #endif } /* ** Change the name of an existing file. */ | | | 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | #endif } /* ** Change the name of an existing file. */ int sqliteOsFileRename(const char *zOldName, const char *zNewName){ #if OS_UNIX if( link(zOldName, zNewName) ){ return SQLITE_ERROR; } unlink(zOldName); return SQLITE_OK; #endif |
︙ | ︙ |
Changes to src/pager.c.
︙ | ︙ | |||
14 15 16 17 18 19 20 | ** The pager is used to access a database disk file. It implements ** atomic commit and rollback through the use of a journal file that ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ** The pager is used to access a database disk file. It implements ** atomic commit and rollback through the use of a journal file that ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** ** @(#) $Id: pager.c,v 1.80 2003/04/06 20:44:45 drh Exp $ */ #include "os.h" /* Must be first to enable large file support */ #include "sqliteInt.h" #include "pager.h" #include <assert.h> #include <string.h> |
︙ | ︙ | |||
962 963 964 965 966 967 968 969 970 971 972 973 974 975 | assert( pPager->journalOpen==0 ); /* Temp files are automatically deleted by the OS ** if( pPager->tempFile ){ ** sqliteOsDelete(pPager->zFilename); ** } */ CLR_PAGER(pPager); sqliteFree(pPager); return SQLITE_OK; } /* ** Return the page number for the given page data. */ | > > > > | 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 | assert( pPager->journalOpen==0 ); /* Temp files are automatically deleted by the OS ** if( pPager->tempFile ){ ** sqliteOsDelete(pPager->zFilename); ** } */ CLR_PAGER(pPager); if( pPager->zFilename!=(char*)&pPager[1] ){ sqliteFree(pPager->zFilename); sqliteFree(pPager->zJournal); } sqliteFree(pPager); return SQLITE_OK; } /* ** Return the page number for the given page data. */ |
︙ | ︙ | |||
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 | sqlitepager_ckpt_commit(pPager); }else{ rc = SQLITE_OK; } pPager->ckptAutoopen = 0; return rc; } #ifdef SQLITE_TEST /* ** Print a listing of all referenced pages and their ref count. */ void sqlitepager_refdump(Pager *pPager){ PgHdr *pPg; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 | sqlitepager_ckpt_commit(pPager); }else{ rc = SQLITE_OK; } pPager->ckptAutoopen = 0; return rc; } /* ** Return the full pathname of the database file. */ const char *sqlitepager_filename(Pager *pPager){ return pPager->zFilename; } /* ** Rename the database file */ int sqlitepager_rename(Pager *pPager, const char *zNewName){ char *zNew; char *zJournal; int nName; int rc; nName = strlen(zNewName); zNew = sqliteMalloc( nName*2 + 30 ); if( zNew==0 ){ return SQLITE_NOMEM; } memcpy(zNew, zNewName, nName+1); zJournal = &zNew[nName+1]; memcpy(zJournal, zNew, nName); strcpy(&zJournal[nName], "-journal"); if( pPager->journalOpen ){ rc = sqliteOsRename(pPager->zJournal, zJournal); if( rc ){ sqliteFree(zNew); return rc; } } rc = sqliteOsRename(pPager->zFilename, zNew); if( rc ){ sqliteFree(zNew); return rc; } if( pPager->zFilename!=(char*)&pPager[1] ){ sqliteFree(pPager->zFilename); } pPager->zFilename = zNew; return SQLITE_OK; } #ifdef SQLITE_TEST /* ** Print a listing of all referenced pages and their ref count. */ void sqlitepager_refdump(Pager *pPager){ PgHdr *pPg; |
︙ | ︙ |
Changes to src/pager.h.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite page cache ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite page cache ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** ** @(#) $Id: pager.h,v 1.22 2003/04/06 20:44:45 drh Exp $ */ /* ** The size of one page ** ** You can change this value to another (reasonable) power of two ** such as 512, 2048, 4096, or 8192 and things will still work. But |
︙ | ︙ | |||
68 69 70 71 72 73 74 75 76 77 78 79 80 | int sqlitepager_ckpt_begin(Pager*); int sqlitepager_ckpt_commit(Pager*); int sqlitepager_ckpt_rollback(Pager*); void sqlitepager_dont_rollback(void*); void sqlitepager_dont_write(Pager*, Pgno); int *sqlitepager_stats(Pager*); void sqlitepager_set_safety_level(Pager*,int); #ifdef SQLITE_TEST void sqlitepager_refdump(Pager*); int pager_refinfo_enable; int journal_format; #endif | > > | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | int sqlitepager_ckpt_begin(Pager*); int sqlitepager_ckpt_commit(Pager*); int sqlitepager_ckpt_rollback(Pager*); void sqlitepager_dont_rollback(void*); void sqlitepager_dont_write(Pager*, Pgno); int *sqlitepager_stats(Pager*); void sqlitepager_set_safety_level(Pager*,int); const char *sqlitepager_filename(Pager*); int sqlitepager_rename(Pager*, const char *zNewName); #ifdef SQLITE_TEST void sqlitepager_refdump(Pager*); int pager_refinfo_enable; int journal_format; #endif |