I am developing an application in Visual C ++ that uses SQLite3 DB to store data. He usually sits in a tray most of the time.
I would also like to enable the transfer of my application to the DropBox folder in order to share it on several PCs. It worked very well until DropBox updated itself. And now he says that he "cannot sync the file used." The SQLite file is open in my application, but the lock is shared. There are several prepared statements, but they are all reset immediately after use step.
Is there a way to enable synchronization of an open SQLite database file? Thank!
Here is a simple shell that I use only for testing (without error handling), if that 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); }
std::wstring 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 std::wstring& sql) const
{
return auto_ptr<Statement>(new Statement(db, sql));
}
private:
sqlite3* db;
};
UPD: LockFile LockFileEx sqlite3.c - .
UPD2: sqlite3_close ( ) - ! Filemon , , .
UPD3: . BEGIN COMMIT ( Transaction RAII ). SQliteManager .