@@ -336,6 +336,11 @@ sqlite3_key_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
336336 {
337337 int dbIndex ;
338338 const char * dbFileName = sqlite3_db_filename (db , zDbName );
339+ if (dbFileName == NULL || dbFileName [0 ] == 0 )
340+ {
341+ sqlite3ErrorWithMsg (db , rc , "Setting key not supported for in-memory or temporary databases." );
342+ return rc ;
343+ }
339344 /* Configure cipher from URI parameters if requested */
340345 if (sqlite3FindFunction (db , "sqlite3mc_config_table" , 0 , SQLITE_UTF8 , 0 ) == NULL )
341346 {
@@ -356,7 +361,7 @@ sqlite3_key_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
356361 else
357362 {
358363 rc = SQLITE_ERROR ;
359- sqlite3ErrorWithMsg (db , rc , "Key failed. Database '%s' not found." , zDbName );
364+ sqlite3ErrorWithMsg (db , rc , "Setting key failed. Database '%s' not found." , zDbName );
360365 }
361366 }
362367 return rc ;
@@ -383,7 +388,12 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
383388 dbIndex = (zDbName ) ? sqlite3FindDbName (db , zDbName ) : 0 ;
384389 if (dbIndex < 0 )
385390 {
386- sqlite3ErrorWithMsg (db , rc , "Rekey failed. Database '%s' not found." , zDbName );
391+ sqlite3ErrorWithMsg (db , rc , "Rekeying failed. Database '%s' not found." , zDbName );
392+ return rc ;
393+ }
394+ if (dbFileName == NULL || dbFileName [0 ] == 0 )
395+ {
396+ sqlite3ErrorWithMsg (db , rc , "Rekeying not supported for in-memory or temporary databases." );
387397 return rc ;
388398 }
389399 pBt = db -> aDb [dbIndex ].pBt ;
@@ -398,7 +408,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
398408
399409 if (pagerUseWal (pPager ))
400410 {
401- sqlite3ErrorWithMsg (db , rc , "Rekey is not supported in WAL journal mode." );
411+ sqlite3ErrorWithMsg (db , rc , "Rekeying is not supported in WAL journal mode." );
402412 return rc ;
403413 }
404414
@@ -449,7 +459,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
449459 {
450460 /* Pagesize cannot be changed for an encrypted database */
451461 rc = SQLITE_ERROR ;
452- sqlite3ErrorWithMsg (db , rc , "Rekey failed. Pagesize cannot be changed for an encrypted database." );
462+ sqlite3ErrorWithMsg (db , rc , "Rekeying failed. Pagesize cannot be changed for an encrypted database." );
453463 goto leave_rekey ;
454464 }
455465 }
@@ -498,14 +508,14 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
498508 {
499509 /* Pagesize cannot be changed for an encrypted database */
500510 rc = SQLITE_ERROR ;
501- sqlite3ErrorWithMsg (db , rc , "Rekey failed. Pagesize cannot be changed for an encrypted database." );
511+ sqlite3ErrorWithMsg (db , rc , "Rekeying failed. Pagesize cannot be changed for an encrypted database." );
502512 goto leave_rekey ;
503513 }
504514 }
505515 else
506516 {
507517 /* Setup of write cipher failed */
508- sqlite3ErrorWithMsg (db , rc , "Rekey failed. Setup of write cipher failed." );
518+ sqlite3ErrorWithMsg (db , rc , "Rekeying failed. Setup of write cipher failed." );
509519 goto leave_rekey ;
510520 }
511521 }
0 commit comments