Hello
I’m having an issue that I’m sure is related to how I am using the API and I thought that this might be a good way for anyone who is using the community edition can get a headstart on a simple howto.
I downloaded the git code on to my Linux box and it compiles properly (including the extra options during configure as instructed) and so I’ve decided to test it.
I’ve got a piece of code that creates an encrypted database like so:
//open database
rc = sqlite3_open(outfile,&component_db);
if (rc != SQLITE_OK)
{
printf(“Could not open the sqlite database\n”);
exit(4);
}
sqlite3_key(component_db, “testkey”, strlen(“testkey”));
//printf(“creating version table\n”);
rc = sqlite3_exec(component_db, “CREATE TABLE ‘version’ (‘version_id’ INTEGER PRIMARY KEY)”, NULL, 0, &zErrMsg);
if( rc!=SQLITE_OK )
{
fprintf(stderr, “SQL error: %s\n”, zErrMsg);
sqlite3_free(zErrMsg);
}
and another piece of code that opens and reads it like so:
*rc = sqlite3_open(component_database_file_from_keyfile,&(component_db));*
if (rc != SQLITE_OK)
*{*
*g_print("failed to open in component database: %s\n", *sqlite3_errmsg(component_db));*
*sqlite3_close(component_db);*
*}*
*else*
*{*
*g_print("Component database let's try to make it faster\n");*
*sqlite3_key(component_db, "test", strlen("test"));*
*rc = sqlite3_exec((component_db), "PRAGMA synchronous = OFF", 0, 0, &zErrMsg);*
*rc = sqlite3_exec((component_db), "PRAGMA journal_mode = MEMORY", 0, 0, &zErrMsg);*
*if (sqlite3_exec(component_db, "SELECT count(\*) FROM version", NULL, NULL, NULL) == SQLITE_OK)*
*{*
*g_print("key is correct\n");*
*}*
else
*{*
*g_print("key is wrong\n");*
*}*
}
Problem is that I always get a fail on the read. It seems to create a database that is encrypted but I cannot seem to open it with the sqlcipher command line application either. Obviously I’m creating the DB wrong but I cannot see how. It seems pretty straightforward.
Can anyone see anything I’m forgetting or misunderstanding.
Mark