I'm developing an app in Visual C++ that uses an SQLite3 DB for storing data. Usually it sits in the tray most of the time.
I also would like to enable putting my app in a DropBox folder to share it across several PCs.
It worked really well up until DropBox has recently updated itself.
And now it says that it "can't sync the file in use". The SQLite file is open in my app, but the lock is shared. There are some prepared statements, but all are reset immediately after using step.
Is there any way to enable synchronizing of an open SQLite database file? Thanks!
Here is the simple wrapper that I use just for testing (no error handling), in case this helps:
class Statement
{
private:
Statement(sqlite3* db, const std::wstring& sql) : db(db)
{
sqlite3_prepare16_v2(db, sql.c_str(), sql.length() * sizeof(wchar_t), &stmt, NULL);
}
public:
~Statement() { sqlite3_finalize(stmt); }
public:
void reset() { sqlite3_reset(stmt); }
int step() { return sqlite3_step(stmt); }
int getInt(int i) const { return sqlite3_column_int(stmt, i); }
tstring getText(int i) const
{
const wchar_t* v = (const wchar_t*)sqlite3_column_text16(stmt, i);
int sz = sqlite3_column_bytes16(stmt, i) / sizeof(wchar_t);
return std::wstring(v, v + sz);
}
private:
friend class Database;
sqlite3* db;
sqlite3_stmt* stmt;
};
class Database
{
public:
Database(const std::wstring& filename = L"")) : db(NULL)
{
sqlite3_open16(filename.c_str(), &db);
}
~Database() { sqlite3_close(db); }
void exec(const std::wstring& sql)
{
auto_ptr<Statement> st(prepare(sql));
st->step();
}
auto_ptr<Statement> prepare(const tstring& sql) const
{
return auto_ptr<Statement>(new Statement(db, sql));
}
private:
sqlite3* db;
};