@@ -158,6 +158,8 @@ static int
158158sqlite3mcCodecAttach (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
550494leave_rekey :
0 commit comments