开发者

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

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 appr开发者_运维技巧opriate method to achieve this as it might be common to load a DB from a stream or from decrypted data...

Thanks.


I believe that the proper way to do this is to create an SQLite VFS layer around your buffer, as mentioned in this thread. A possible/partial solution, spmemvfs, is mentioned here, although I have never tried it.

If you don't need concurrency for your DB, creating your own VFS implementation should be quite simple.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜