How can I load a SQLITE database from a buffer with the C API ?

Posted by rockeye on Stack Overflow See other posts from Stack Overflow or by rockeye
Published on 2010-12-23T16:49:17Z Indexed on 2010/12/23 16:54 UTC
Read the original article Hit count: 189

Filed under:
|
|
|
|

Hello,

I am trying to load a database from the memory instead of opening a .sqlite file. I have read the C/C++ API reference but I can not find the proper method.

The buffer I am trying to load is simply an sqlite file loaded in memory. I just want to use this buffer (a const char* array) without using the filesystem (I could have saved this buffer in a file, then load the file, but no).

First, I create a memory DB : mErrorCode = sqlite3_open_v2(":memory:", &mSqlDatabase, lMode, NULL);

This returns SQLITE_OK, then I tried to use the buffer as a statement and call preparev2(MyDB, MyBufferData, MyBufferLength, MyStatement, NULL) but it's not really a statement, and it returns an error. Same result if I call directly exec(MyDB, MyBufferData, NULL, NULL, NULL);

I guess there is an appropriate method to achieve this as it might be common to load a DB from a stream or from decrypted data...

Thanks.

© Stack Overflow or respective owner

Related posts about c++

Related posts about database