Skip to content

Commit e4d8814

Browse files
committed
Remove code for support of older SQLite versions
Only SQLite version 3.32.0 and higher will be supported. Therefore code relevant only to older versions could be removed. Additionally, fixed an issue with attached databases implicitly using the encryption key of the main database.
1 parent c9aeba0 commit e4d8814

File tree

3 files changed

+4
-70
lines changed

3 files changed

+4
-70
lines changed

src/codecext.c

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ static int
158158
sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey, int nKey)
159159
{
160160
/* Attach a key to a database. */
161+
const char* zDbName = db->aDb[nDb].zDbSName;
162+
const char* dbFileName = sqlite3_db_filename(db, zDbName);
161163
Codec* codec = (Codec*) sqlite3_malloc(sizeof(Codec));
162164
int rc = (codec != NULL) ? sqlite3mcCodecInit(codec) : SQLITE_NOMEM;
163165
if (rc != SQLITE_OK)
@@ -188,7 +190,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
188190
sqlite3mcSetBtree(codec, db->aDb[nDb].pBt);
189191
mcAdjustBtree(db->aDb[nDb].pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec));
190192
sqlite3mcCodecSizeChange(codec, pageSize, reserved);
191-
sqlite3mcSetCodec(db, zPath, codec);
193+
sqlite3mcSetCodec(db, dbFileName, codec);
192194
}
193195
else
194196
{
@@ -210,12 +212,6 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
210212
}
211213
else
212214
{
213-
#if (SQLITE_VERSION_NUMBER >= 3015000)
214-
const char* zDbName = db->aDb[nDb].zDbSName;
215-
#else
216-
const char* zDbName = db->aDb[nDb].zName;
217-
#endif
218-
const char* dbFileName = sqlite3_db_filename(db, zDbName);
219215
if (dbFileName != NULL)
220216
{
221217
/* Check whether key salt is provided in URI */
@@ -245,9 +241,6 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
245241
int reserved = sqlite3mcGetReservedWriteCipher(codec);
246242
mcAdjustBtree(db->aDb[nDb].pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec));
247243
sqlite3mcCodecSizeChange(codec, pageSize, reserved);
248-
#if 0
249-
const char* dbFileName = sqlite3_db_filename(db, zDbName);
250-
#endif
251244
sqlite3mcSetCodec(db, dbFileName, codec);
252245
}
253246
else
@@ -395,11 +388,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
395388
char* err = NULL;
396389
sqlite3mcSetReadReserved(codec, nReserved);
397390
sqlite3mcSetWriteReserved(codec, nReservedWriteCipher);
398-
#if (SQLITE_VERSION_NUMBER >= 3027000)
399391
rc = sqlite3mcRunVacuumForRekey(&err, db, dbIndex, NULL, nReservedWriteCipher);
400-
#else
401-
rc = sqlite3mcRunVacuumForRekey(&err, db, dbIndex, nReservedWriteCipher);
402-
#endif
403392
goto leave_rekey;
404393
}
405394
}
@@ -426,11 +415,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
426415
char* err = NULL;
427416
sqlite3mcSetReadReserved(codec, nReserved);
428417
sqlite3mcSetWriteReserved(codec, 0);
429-
#if (SQLITE_VERSION_NUMBER >= 3027000)
430418
rc = sqlite3mcRunVacuumForRekey(&err, db, dbIndex, NULL, 0);
431-
#else
432-
rc = sqlite3mcRunVacuumForRekey(&err, db, dbIndex, 0);
433-
#endif
434419
goto leave_rekey;
435420
}
436421
}
@@ -451,11 +436,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
451436
char* err = NULL;
452437
sqlite3mcSetReadReserved(codec, nReserved);
453438
sqlite3mcSetWriteReserved(codec, nReservedWriteCipher);
454-
#if (SQLITE_VERSION_NUMBER >= 3027000)
455439
rc = sqlite3mcRunVacuumForRekey(&err, db, dbIndex, NULL, nReservedWriteCipher);
456-
#else
457-
rc = sqlite3mcRunVacuumForRekey(&err, db, dbIndex, nReservedWriteCipher);
458-
#endif
459440
goto leave_rekey;
460441
}
461442
}
@@ -474,56 +455,27 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
474455
}
475456

476457
/* Start transaction */
477-
#if (SQLITE_VERSION_NUMBER >= 3025000)
478458
rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
479-
#else
480-
rc = sqlite3BtreeBeginTrans(pBt, 1);
481-
#endif
482459
if (!rc)
483460
{
484461
int pageSize = sqlite3BtreeGetPageSize(pBt);
485462
Pgno nSkip = WX_PAGER_MJ_PGNO(pageSize);
486-
#if (SQLITE_VERSION_NUMBER >= 3003014)
487463
DbPage *pPage;
488-
#else
489-
void *pPage;
490-
#endif
491464
Pgno n;
492465
/* Rewrite all pages using the new encryption key (if specified) */
493-
#if (SQLITE_VERSION_NUMBER >= 3007001)
494466
Pgno nPage;
495467
int nPageCount = -1;
496468
sqlite3PagerPagecount(pPager, &nPageCount);
497469
nPage = nPageCount;
498-
#elif (SQLITE_VERSION_NUMBER >= 3006000)
499-
int nPageCount = -1;
500-
int rc = sqlite3PagerPagecount(pPager, &nPageCount);
501-
Pgno nPage = (Pgno) nPageCount;
502-
#elif (SQLITE_VERSION_NUMBER >= 3003014)
503-
Pgno nPage = sqlite3PagerPagecount(pPager);
504-
#else
505-
Pgno nPage = sqlite3pager_pagecount(pPager);
506-
#endif
507470

508471
for (n = 1; rc == SQLITE_OK && n <= nPage; n++)
509472
{
510473
if (n == nSkip) continue;
511-
#if (SQLITE_VERSION_NUMBER >= 3010000)
512474
rc = sqlite3PagerGet(pPager, n, &pPage, 0);
513-
#elif (SQLITE_VERSION_NUMBER >= 3003014)
514-
rc = sqlite3PagerGet(pPager, n, &pPage);
515-
#else
516-
rc = sqlite3pager_get(pPager, n, &pPage);
517-
#endif
518475
if (!rc)
519476
{
520-
#if (SQLITE_VERSION_NUMBER >= 3003014)
521477
rc = sqlite3PagerWrite(pPage);
522478
sqlite3PagerUnref(pPage);
523-
#else
524-
rc = sqlite3pager_write(pPage);
525-
sqlite3pager_unref(pPage);
526-
#endif
527479
}
528480
}
529481
}
@@ -536,15 +488,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
536488
if (rc != SQLITE_OK)
537489
{
538490
/* Rollback in case of error */
539-
#if (SQLITE_VERSION_NUMBER >= 3008007)
540-
/* Unfortunately this change was introduced in version 3.8.7.2 which cannot be detected using the SQLITE_VERSION_NUMBER */
541-
/* That is, compilation will fail for version 3.8.7 or 3.8.7.1 ==> Please change manually ... or upgrade to 3.8.7.2 or higher */
542491
sqlite3BtreeRollback(pBt, SQLITE_OK, 0);
543-
#elif (SQLITE_VERSION_NUMBER >= 3007011)
544-
sqlite3BtreeRollback(pbt, SQLITE_OK);
545-
#else
546-
sqlite3BtreeRollback(pbt);
547-
#endif
548492
}
549493

550494
leave_rekey:

src/sqlite3mc.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include "sqlite3.h"
1414

15-
#ifdef SQLITE_USER_AUHENTICATION
15+
#ifdef SQLITE_USER_AUTHENTICATION
1616
#include "sqlite3userauth.h"
1717
#endif
1818

@@ -95,24 +95,18 @@
9595
/*
9696
** Define Windows specific SQLite API functions (not defined in sqlite3.h)
9797
*/
98-
#if SQLITE_VERSION_NUMBER >= 3007014
9998
#if SQLITE_OS_WIN == 1
10099

101100
#ifdef __cplusplus
102101
extern "C" {
103102
#endif
104103

105-
#if SQLITE_VERSION_NUMBER >= 3024000
106104
SQLITE_API int sqlite3_win32_set_directory(unsigned long type, void* zValue);
107-
#else
108-
SQLITE_API int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue);
109-
#endif
110105

111106
#ifdef __cplusplus
112107
}
113108
#endif
114109

115-
#endif
116110
#endif
117111

118112
#ifdef __cplusplus

src/userauth.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,7 @@ int sqlite3_user_authenticate(
214214
db->auth.nAuthPW = nPW;
215215
rc = sqlite3UserAuthCheckLogin(db, "main", &authLevel);
216216
db->auth.authLevel = authLevel;
217-
#if (SQLITE_VERSION_NUMBER >= 3025000)
218217
sqlite3ExpirePreparedStatements(db, 0);
219-
#else
220-
sqlite3ExpirePreparedStatements(db);
221-
#endif
222218
if( rc ){
223219
return rc; /* OOM error, I/O error, etc. */
224220
}

0 commit comments

Comments
 (0)