sqlite3 *unencrypted_DB;
NSString *path_u = local_databasePath;
if (sqlite3_open([path_u UTF8String], &unencrypted_DB) == SQLITE_OK) {
NSLog(@"Database Opened");
int res = -1;
NSString *enc_databasePath = [libsDir stringByAppendingPathComponent:@"encrypted.sqlite"];
if (sqlite3_open([enc_databasePath UTF8String], &unencrypted_DB) == SQLITE_OK) {
NSString* de_query = [NSString stringWithFormat:@"ATTACH DATABASE '%@' AS encrypted KEY '123';",enc_databasePath];
NSLog(@"deq: %@",de_query);
const char* sqlstmt = [de_query UTF8String];
res = sqlite3_exec(unencrypted_DB, sqlstmt, NULL, NULL, NULL);
}
NSString* de_export =
[NSString stringWithFormat:@"SELECT sqlcipher_export('%@');",enc_databasePath];// SUSPECTING ISSUE HERE
const char* sqlstmt1 = [de_export UTF8String];
// export database
res = sqlite3_exec(unencrypted_DB,sqlstmt1, NULL, NULL, NULL); // ISSUE I AM FACING AS MENTIONED ABOVE
// Detach encrypted database
res = sqlite3_exec(unencrypted_DB, "DETACH DATABASE encrypted;", NULL, NULL, NULL);
NSLog (@"End database copying");
sqlite3_close(unencrypted_DB);
NSLog(@"Database Opened");
int res = -1;
NSString *enc_databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent: @"encrypted.sqlite"];
NSMutableString* str = [[NSMutableString alloc]initWithString:@"encrypted"];
NSMutableString* queryStr = [[NSMutableString alloc]initWithString:@"ATTACH DATABASE '%@' AS "];
[queryStr appendString:str];
if (sqlite3_open([enc_databasePath UTF8String], &unencrypted_DB) == SQLITE_OK) {
NSString* de_query = [NSString stringWithFormat:queryStr,path_u];
NSLog(@"deq: %@",de_query);
const char* sqlstmt = [de_query UTF8String];
res = sqlite3_exec(unencrypted_DB, sqlstmt, NULL, NULL, NULL);
}
NSString* de_export = [NSString stringWithFormat:@"SELECT sqlcipher_export ('%@')",str];
const char* sqlstmt1 = [de_export UTF8String];
// export database
res = sqlite3_exec(unencrypted_DB,sqlstmt1, NULL, NULL, NULL); ====>>>SQLCIPHER_EXPORT command is failing with error code 1 (missing DB).
i think xcode is not recognizing SQLCIPHER_EXPORT command
NSString* de_export = [NSString stringWithFormat:@"SELECT sqlcipher_export('%@')",str];
const char* sqlstmt1 = [de_export UTF8String];
// export database
res = sqlite3_exec(unencrypted_DB,sqlstmt1, NULL, NULL, NULL);
res returned me error code 1 ( /* SQL error or missing database */)
it menace my sqlcipher_export is not working .
can you please tell me why ?
Regards,
Vinay Hegde