mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
Implement locking in SQLite
This commit is contained in:
parent
1677e1fed5
commit
17de42a947
|
@ -11,6 +11,7 @@ CSqliteConnection::CSqliteConnection(const char *pFilename, bool Setup) :
|
||||||
m_pDb(nullptr),
|
m_pDb(nullptr),
|
||||||
m_pStmt(nullptr),
|
m_pStmt(nullptr),
|
||||||
m_Done(true),
|
m_Done(true),
|
||||||
|
m_Locked(false),
|
||||||
m_InUse(false)
|
m_InUse(false)
|
||||||
{
|
{
|
||||||
str_copy(m_aFilename, pFilename, sizeof(m_aFilename));
|
str_copy(m_aFilename, pFilename, sizeof(m_aFilename));
|
||||||
|
@ -67,6 +68,7 @@ IDbConnection::Status CSqliteConnection::Connect()
|
||||||
return Status::ERROR;
|
return Status::ERROR;
|
||||||
m_Setup = false;
|
m_Setup = false;
|
||||||
}
|
}
|
||||||
|
m_Locked = false;
|
||||||
return Status::SUCCESS;
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,10 +82,18 @@ void CSqliteConnection::Disconnect()
|
||||||
|
|
||||||
void CSqliteConnection::Lock(const char *pTable)
|
void CSqliteConnection::Lock(const char *pTable)
|
||||||
{
|
{
|
||||||
|
// locks the whole database read/write
|
||||||
|
Execute("BEGIN EXCLUSIVE TRANSACTION;");
|
||||||
|
m_Locked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSqliteConnection::Unlock()
|
void CSqliteConnection::Unlock()
|
||||||
{
|
{
|
||||||
|
if(m_Locked)
|
||||||
|
{
|
||||||
|
Execute("COMMIT TRANSACTION;");
|
||||||
|
m_Locked = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSqliteConnection::PrepareStatement(const char *pStmt)
|
void CSqliteConnection::PrepareStatement(const char *pStmt)
|
||||||
|
|
|
@ -45,6 +45,7 @@ private:
|
||||||
sqlite3 *m_pDb;
|
sqlite3 *m_pDb;
|
||||||
sqlite3_stmt *m_pStmt;
|
sqlite3_stmt *m_pStmt;
|
||||||
bool m_Done; // no more rows available for Step
|
bool m_Done; // no more rows available for Step
|
||||||
|
bool m_Locked;
|
||||||
// returns true, if the query succeded
|
// returns true, if the query succeded
|
||||||
bool Execute(const char *pQuery);
|
bool Execute(const char *pQuery);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue