I configured SQLCipher as the tutorial in their site... I can compile & Run the project. But sqlite3_exec returns SQLITE_NOTADB when trying to execute a statement.
Please find code snippet below:
=================
NSString *dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:dbPath];
if(success) {
int sql_results = sqlite3_open([dbPath UTF8String], &SQLDB);
const char* key = [@"BIGSecret" UTF8String];
sqlite3_key(SQLDB, key, strlen(key));
if (sql_results == SQLITE_OK) {
NSString *sql;
const char *update_sql;
sql = [NSString stringWithFormat:@"DROP table %@",tablename];
update_sql = [sql cStringUsingEncoding:NSUTF8StringEncoding];
if(sqlite3_exec(SQLDB, update_sql, nil, nil, nil) == SQLITE_OK) {
NSLog(@"Good to go %@ dropped",tablename);
}
else {
NSLog(@"Bad Delete Cat SQL: %s -- %d", update_sql,sql_results);
NSLog(@"error code %i", sql_results);
}
Am not able to get the issue, where I went wrong....
Thanks,
Ben
Cross posting from Mailing list:
I noticed in your code that you are only entering the block to sqlite3_open if the database file exists. Are you by chance trying to encrypt an existing standard SQLite database using SQLCipher using this code? If so, calling sqlite3_key will not work that way. You'd instead want to open the standard SQLite database, attach a new encrypted database, and then export the data between the two. There are some more details on this procedure here:
http://sqlcipher.net/sqlcipher-api/#sqlcipher_export
Once you're dealing with an encrypted database you can call sqlite3_key as the first operation before using it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With