@@ -871,6 +871,7 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
871871 u32 meta ;
872872 int rc = 0 ;
873873 int command_idx = 0 ;
874+ int password_sz ;
874875 int saved_flags ;
875876 int saved_nChange ;
876877 int saved_nTotalChange ;
@@ -879,7 +880,7 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
879880 sqlite3 * db = ctx -> pBt -> db ;
880881 const char * db_filename = sqlite3_db_filename (db , "main" );
881882 const char * migrated_db_filename = sqlite3_mprintf ("%s-migrated" , db_filename );
882- const char * key = ctx -> read_ctx -> pass ;
883+ char * key = ctx -> read_ctx -> pass ;
883884 static const unsigned char aCopy [] = {
884885 BTREE_SCHEMA_VERSION , 1 , /* Add one to the old schema cookie */
885886 BTREE_DEFAULT_CACHE_SIZE , 0 , /* Preserve the default page cache size */
@@ -932,18 +933,22 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
932933
933934 rc = sqlite3_exec (db , "BEGIN;" , NULL , NULL , NULL );
934935 rc = sqlite3BtreeBeginTrans (pSrc , 2 );
935- // rc = sqlite3BtreeBeginTrans(pDest, 2);
936+ rc = sqlite3BtreeBeginTrans (pDest , 2 );
936937
937938 assert ( 1 == sqlite3BtreeIsInTrans (pDest ) );
938939 assert ( 1 == sqlite3BtreeIsInTrans (pSrc ) );
940+
941+ sqlite3CodecGetKey (db , db -> nDb - 1 , & key , & password_sz );
942+ sqlcipher_codec_ctx_set_pass (ctx , key , password_sz , 2 );
939943
940944 int i = 0 ;
941945 for (i = 0 ; i < ArraySize (aCopy ); i += 2 ){
942946 sqlite3BtreeGetMeta (pSrc , aCopy [i ], & meta );
943947 rc = sqlite3BtreeUpdateMeta (pDest , aCopy [i ], meta + aCopy [i + 1 ]);
944948 if ( NEVER (rc != SQLITE_OK ) ) goto handle_error ;
945949 }
946- rc = sqlite3BtreeCopyFile (pSrc , pDest );
950+
951+ rc = sqlite3BtreeCopyFile (pDest , pSrc );
947952 if ( rc != SQLITE_OK ) goto handle_error ;
948953 rc = sqlite3BtreeCommit (pDest );
949954
0 commit comments