# Insert failed with error message "no such table"

**URL:** <https://discuss.zetetic.net/t/insert-failed-with-error-message-no-such-table/5619>\
**Category:** SQLCipher\
**Created:** [October 29, 2022, 1:22pm UTC](https://discuss.zetetic.net/t/insert-failed-with-error-message-no-such-table/5619 "2022-10-29T13:22:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![exia\_guo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/exia_guo/32/1891_2.png) [@exia\_guo](https://discuss.zetetic.net/u/exia_guo)\
**Post date:** [October 29, 2022, 1:22pm UTC](https://discuss.zetetic.net/t/insert-failed-with-error-message-no-such-table/5619/1 "2022-10-29T13:22:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [October 31, 2022, 2:38pm UTC](https://discuss.zetetic.net/t/insert-failed-with-error-message-no-such-table/5619/2 "2022-10-31T14:38:59Z")

</div>

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](https://www.zetetic.net/sqlcipher/sqlcipher-api/#sqlcipher_export)

---

<div class="post-metadata">

**Author:** ![exia\_guo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/exia_guo/32/1891_2.png) [@exia\_guo](https://discuss.zetetic.net/u/exia_guo)\
**Post date:** [October 31, 2022, 3:13pm UTC](https://discuss.zetetic.net/t/insert-failed-with-error-message-no-such-table/5619/3 "2022-10-31T15:13:52Z")

</div>

Thanks for reply!

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