Skip to content

Commit c9c5bef

Browse files
committed
Update compatibility with sqlite3 version 3.16.0 and higher (highest currently 3.34.0)
1 parent 281c6a8 commit c9c5bef

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ SQLITE_API void SQLITE_STDCALL sqlite3_activate_cerod(const char *zPassPhrase);
117117
If you are using CEVFS, chances are that you are _not_ currently making use of this API hook. You can use the `const char *` param to pass something other than the intended activation key, such as the encryption key. This `sqlite3_activate_cerod` function has been implemented in `cevfs_build/cevfs_mod.c` as an example. Alternatively, you can roll out your own [Run-Time Loadable Extension](http://www.sqlite.org/loadext.html).
118118

119119
## Limitations
120-
1. Currently tested with SQLite version 3.10.2 only.
120+
121121
- WAL mode is not (yet) supported.
122122
- Free nodes are not managed which could result in wasted space. Not an issue if the database you create with `cevfs_build()` is intended to be used as a read-only database.
123123
- VACUUM not yet implemented to recover lost space.
@@ -126,10 +126,10 @@ If you are using CEVFS, chances are that you are _not_ currently making use of t
126126

127127
|Version|Combatibility|
128128
|-|-|
129-
|3.10.2|Most development was originally on this version|
130-
|3.11.x|OK|
131-
|3.12.0 - 3.15.2|CEVFS recently fixed for these versions|
132-
|3.16.0 and higher|Not compatible yet due to API changes|
129+
|3.10.2|Most development was originally with this version.|
130+
|3.11.x|Testing OK. No changes were required.|
131+
|3.12.0 - 3.15.2|Default pager page size changed. CEVFS updated for these versions.|
132+
|3.16.0 - 3.34.0|`sqlite3PagerClose` API signature changed: CEVFS updated for these versions.|
133133

134134
## Contributing to the project
135135
If you would like to contribute back to the project, please fork the repo and submit pull requests. For more information, please read this [wiki page](https://github.com/ryanhomer/sqlite3-compression-encryption-vfs/wiki/Developing-in-Xcode)

cevfs/cevfs.c

+19-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ SOFTWARE.
6363
#define CEVFS_PRINTF(a,b,...)
6464
#endif
6565

66+
SQLITE_PRIVATE int sqlite3PagerCloseShim(Pager *pPager, sqlite3* db){
67+
#if SQLITE_VERSION_NUMBER < 3016000
68+
return sqlite3PagerClose(pPager);
69+
#else
70+
return sqlite3PagerClose(pPager, db);
71+
#endif
72+
}
73+
74+
#ifndef EXTRA_SIZE
75+
#define EXTRA_SIZE sizeof(MemPage)
76+
#endif
77+
6678
// Compression size and offset types
6779
typedef u16 CevfsCmpSize;
6880
typedef u16 CevfsCmpOfst;
@@ -140,6 +152,7 @@ struct cevfs_info {
140152
const char *zVfsName; // Name of this VFS
141153
sqlite3_vfs *pCevfsVfs; // Pointer back to the cevfs VFS
142154
cevfs_file *pFile; // Pointer back to the cevfs_file representing the dest. db.
155+
sqlite3 *pDb; // Pointer to sqlite3 instance
143156
int cerod_activated; // if extension is enabled, make sure read only
144157

145158
// Pointers to custom compress/encryption functions implemented by the user
@@ -914,7 +927,7 @@ static int cevfsClose(sqlite3_file *pFile){
914927

915928
if( rc==SQLITE_OK ){
916929
cevfsReleasePage1(p);
917-
if( (rc = sqlite3PagerClose(p->pPager))==SQLITE_OK ){
930+
if( (rc = sqlite3PagerCloseShim(p->pPager, pInfo->pDb))==SQLITE_OK ){
918931
p->pPager = NULL;
919932
if( p->zUppJournalPath ){
920933
sqlite3_free(p->zUppJournalPath);
@@ -1123,7 +1136,7 @@ static int cevfsWrite(
11231136
cevfsPageMapSet(p, iOfst, nSrcAmt, &uppPgno, &mappedPgno, &cmprPgOfst);
11241137

11251138
// write
1126-
if( (rc = sqlite3PagerGet(p->pPager, mappedPgno, &pPage, 0))==SQLITE_OK ){
1139+
if( rc==SQLITE_OK && (rc = sqlite3PagerGet(p->pPager, mappedPgno, &pPage, 0))==SQLITE_OK ){
11271140
CevfsMemPage *pMemPage = memPageFromDbPage(pPage, mappedPgno);
11281141
if( rc==SQLITE_OK && (rc = cevfsPagerWrite(p, pPage))==SQLITE_OK ){
11291142
CEVFS_PRINTF(
@@ -1871,6 +1884,9 @@ int cevfs_build(
18711884
pInfo->upperPgSize = pageSize;
18721885

18731886
if( (rc = sqlite3_open_v2(zDestFilename, &pDb, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, vfsName))==SQLITE_OK ){
1887+
// Needed for sqlite3 API shims
1888+
pInfo->pDb = pDb;
1889+
18741890
DbPage *pPage1 = NULL;
18751891
// import all pages
18761892
for(Pgno pgno=0; pgno<pageCount; pgno++){
@@ -1894,7 +1910,7 @@ int cevfs_build(
18941910
}
18951911
}
18961912
if (pPage1) sqlite3PagerUnref(pPage1);
1897-
sqlite3PagerClose(pPager);
1913+
sqlite3PagerCloseShim(pPager, pDb);
18981914
rc = sqlite3_close(pDb);
18991915
}
19001916
}

0 commit comments

Comments
 (0)