Insert failed with error message "no such table"

Hi,
I am new to SQLCipher. I am using the Community Edition, version 4.5.2. My Platform is Windows 10.
I followed the instructions to create the encrypted db from scratch as following steps:
1, .\sqlcipher.exe test
2, PRAGMA key = ‘test123’;
3, create table XX

Then I want to insert data into the db using C++ with the APIs. My program is like the following:
int init()
{
int ret = sqlite3_open_v2(“test.db”, &db_, SQLITE_OPEN_READWRITE, NULL);

const char* db_key = “test123”;
ret = sqlite3_key(db_, db_key, strlen(db_key));

return 0;
}

After opened the db, I try the code to insert data in another function.
int store()
{
sqlite3_stmt *stmt = NULL;
int rc = sqlite3_prepare_v2(db_, “insert into XX”, -1, &stmt, NULL);

}
But sqlite3_prepare_v2 return 1, and the sqlite3_errmsg is “no such table”.

The shown codes work on a normal db without encryption.

Could you give me some instructions about my problem?

Thanks.

Hi @exia_guo

Does the database already exist? If so, is it a plaintext SQLite database? Existing plaintext SQLite databases may be exported to SQLCipher using the sqlcipher_export(...) [1] convenience function, then would the database be encrypted. Alternatively, you can create the database directly using SQLCipher, however, you would need to create the table prior to inserting data.


  1. SQLCipher API - Zetetic ↩︎

Thanks for reply!

I try again from scratch following my steps, and insert success! There may be something wrong in my previous work. :slight_smile: