SQLite Forum

how to insert a structure data into blob?
Login
> It can not work, why?

Yes, it can work. `sqlite3_bind_blob()` doesn't accepts raw memory as-is, and that's what you've passed to it. You haven't shown us any error messages, nor any code where you test the result of the insert, so we can only speculate about what might have gone wrong in your case. You have failed to check any of the result codes for your various calls to sqlite3 functions, especially `sqlite3_step()`.

Your `CREATE TABLE` has `CapTime DOUBLE NOT NULL` and your `INSERT` does not provide a value for that field. Perhaps that is where your problem is. Checking the result of the call to `sqlite3_step()`, and calling `sqlite3_errmsg()` if it fails, will probably tell you exactly what went wrong.

In any case: storing a binary image of a struct this way is completely non-portable and not generally a good idea. You may think that it's a quick and easy way to save and restore binary data, but it's a dark path which will cause you grief if you try to load that data on a machine with a different architecture. Such data will load in an incompatible environment, but may have a different binary signature there and thus effectively be corrupted.