UnQLite Users Forum

Can't save data

append delete Roger

I insert a record to a new db file every 1s, and excute unqlite_commit after unqlite_kv_store. The db file is saved on a SD card. I find the db file is empty when I remove the SD or power down the embedded device. How can I save data when I remove SD or power down.

Reply RSS

Replies

append delete #1. devel

This is a known problem related to cheap SD/Drives that do not honor sync requests. As the SQLite authors stated:

USB flash memory sticks seem to be especially pernicious liars regarding sync requests. One can easily see this by committing a large transaction to an SQLite database on a USB memory stick. The COMMIT command will return relatively quickly, indicating that the memory stick has told the operating system and the operating system has told SQLite that all content is safely in persistent storage, and yet the LED on the end of the memory stick will continue flashing for several more seconds. Pulling out the memory stick while the LED is still flashing will frequently result in database corruption...

Your best defense here is to manually commit your DB as you did (unqlite_commit()), close the database handle (unqlite_close()) and wait a little bit hoping that everything gets **really** flushed to the target surface.

Reply

(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: chm_at_symisc, devel_at_symisc