Implement locking in SQLite

This commit is contained in:
Zwelf 2020-07-12 12:21:41 +02:00
parent 1677e1fed5
commit 17de42a947
2 changed files with 11 additions and 0 deletions

View file

@ -11,6 +11,7 @@ CSqliteConnection::CSqliteConnection(const char *pFilename, bool Setup) :
m_pDb(nullptr),
m_pStmt(nullptr),
m_Done(true),
m_Locked(false),
m_InUse(false)
{
str_copy(m_aFilename, pFilename, sizeof(m_aFilename));
@ -67,6 +68,7 @@ IDbConnection::Status CSqliteConnection::Connect()
return Status::ERROR;
m_Setup = false;
}
m_Locked = false;
return Status::SUCCESS;
}
@ -80,10 +82,18 @@ void CSqliteConnection::Disconnect()
void CSqliteConnection::Lock(const char *pTable)
{
// locks the whole database read/write
Execute("BEGIN EXCLUSIVE TRANSACTION;");
m_Locked = true;
}
void CSqliteConnection::Unlock()
{
if(m_Locked)
{
Execute("COMMIT TRANSACTION;");
m_Locked = false;
}
}
void CSqliteConnection::PrepareStatement(const char *pStmt)

View file

@ -45,6 +45,7 @@ private:
sqlite3 *m_pDb;
sqlite3_stmt *m_pStmt;
bool m_Done; // no more rows available for Step
bool m_Locked;
// returns true, if the query succeded
bool Execute(const char *pQuery);