33** Purpose: Implementation of SQLite codec API
44** Author: Ulrich Telle
55** Created: 2006-12-06
6- ** Copyright: (c) 2006-2020 Ulrich Telle
6+ ** Copyright: (c) 2006-2021 Ulrich Telle
77** License: MIT
88*/
99
@@ -346,6 +346,7 @@ sqlite3_key_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
346346 else
347347 {
348348 rc = SQLITE_ERROR ;
349+ sqlite3ErrorWithMsg (db , rc , "Key failed. Database '%s' not found." , zDbName );
349350 }
350351 }
351352 return rc ;
@@ -372,6 +373,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
372373 dbIndex = (zDbName ) ? sqlite3FindDbName (db , zDbName ) : 0 ;
373374 if (dbIndex < 0 )
374375 {
376+ sqlite3ErrorWithMsg (db , rc , "Rekey failed. Database '%s' not found." , zDbName );
375377 return rc ;
376378 }
377379 pBt = db -> aDb [dbIndex ].pBt ;
@@ -384,6 +386,12 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
384386 pPager = sqlite3BtreePager (pBt );
385387 codec = sqlite3mcGetCodec (db , zDbName );
386388
389+ if (pagerUseWal (pPager ))
390+ {
391+ sqlite3ErrorWithMsg (db , rc , "Rekey is not supported in WAL journal mode." );
392+ return rc ;
393+ }
394+
387395 if ((zKey == NULL || nKey == 0 ) && (codec == NULL || !sqlite3mcIsEncrypted (codec )))
388396 {
389397 /* Database not encrypted and key not specified, therefore do nothing */
@@ -431,6 +439,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
431439 {
432440 /* Pagesize cannot be changed for an encrypted database */
433441 rc = SQLITE_ERROR ;
442+ sqlite3ErrorWithMsg (db , rc , "Rekey failed. Pagesize cannot be changed for an encrypted database." );
434443 goto leave_rekey ;
435444 }
436445 }
@@ -479,12 +488,14 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
479488 {
480489 /* Pagesize cannot be changed for an encrypted database */
481490 rc = SQLITE_ERROR ;
491+ sqlite3ErrorWithMsg (db , rc , "Rekey failed. Pagesize cannot be changed for an encrypted database." );
482492 goto leave_rekey ;
483493 }
484494 }
485495 else
486496 {
487497 /* Setup of write cipher failed */
498+ sqlite3ErrorWithMsg (db , rc , "Rekey failed. Setup of write cipher failed." );
488499 goto leave_rekey ;
489500 }
490501 }
0 commit comments