|
|
|
@ -117,6 +117,7 @@ SQLite_Connector::SQLite_Connector() |
|
|
|
m_bIsConnected = false; |
|
|
|
m_bPersistentConnection = false; |
|
|
|
m_pDBLink = NULL; |
|
|
|
m_nBusyTimeoutMs = SQLITE_BUSY_TIMEOUT_MS; |
|
|
|
if (! sqlite_global_config_is_set) |
|
|
|
{ |
|
|
|
// if( SQLITE_OK != sqlite3_config(int, ...) ){ SQLITE_MISUSE
|
|
|
|
@ -166,8 +167,7 @@ bool SQLite_Connector::Connect(CSTR FileName, int AUX_FLAGS, bool Persistent) |
|
|
|
#endif
|
|
|
|
if (SQLITE_OK == sqlite3_open_v2(m_pDBName, &m_pDBLink, m_nFLAGS, NULL)) |
|
|
|
{ |
|
|
|
// Wait for locks held by other connections instead of failing immediately
|
|
|
|
sqlite3_busy_timeout(m_pDBLink, SQLITE_BUSY_TIMEOUT_MS); |
|
|
|
applyBusyTimeout(); |
|
|
|
m_bIsConnected = true; |
|
|
|
} |
|
|
|
else if (m_pDBLink != NULL) |
|
|
|
@ -188,6 +188,23 @@ bool SQLite_Connector::Connect(CSTR FileName, int AUX_FLAGS, bool Persistent) |
|
|
|
return m_bIsConnected; |
|
|
|
} |
|
|
|
|
|
|
|
void SQLite_Connector::applyBusyTimeout(void) |
|
|
|
{ |
|
|
|
if (m_pDBLink != NULL) |
|
|
|
{ |
|
|
|
// <= 0 removes the busy handler: a locked database fails with SQLITE_BUSY at once
|
|
|
|
sqlite3_busy_timeout(m_pDBLink, m_nBusyTimeoutMs > 0 ? m_nBusyTimeoutMs : 0); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
void SQLite_Connector::setBusyTimeout(int ms) |
|
|
|
{ |
|
|
|
m_mAccessMutex.lock(); |
|
|
|
m_nBusyTimeoutMs = ms > 0 ? ms : 0; |
|
|
|
applyBusyTimeout(); // a persistent link is open already; non-persistent ones get it on ReConnect()
|
|
|
|
m_mAccessMutex.unlock(); |
|
|
|
} |
|
|
|
|
|
|
|
bool SQLite_Connector::ReConnect(void) |
|
|
|
{ |
|
|
|
if (m_pDBLink != NULL) |
|
|
|
@ -200,8 +217,7 @@ bool SQLite_Connector::ReConnect(void) |
|
|
|
} |
|
|
|
if (SQLITE_OK == sqlite3_open_v2(m_pDBName, &m_pDBLink, m_nFLAGS, NULL)) |
|
|
|
{ |
|
|
|
// Wait for locks held by other connections instead of failing immediately
|
|
|
|
sqlite3_busy_timeout(m_pDBLink, SQLITE_BUSY_TIMEOUT_MS); |
|
|
|
applyBusyTimeout(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (m_pDBLink != NULL) |
|
|
|
@ -252,8 +268,15 @@ bool SQLite_Connector::SilentQuery(CSTR QS) |
|
|
|
LOG(sqlite3_expanded_sql(query)); |
|
|
|
#endif
|
|
|
|
|
|
|
|
if (SQLITE_DONE != sqlite3_step(query)) |
|
|
|
int stepRC = sqlite3_step(query); |
|
|
|
if (SQLITE_DONE != stepRC) |
|
|
|
{ |
|
|
|
if (SQLITE_ROW != stepRC) |
|
|
|
{ |
|
|
|
char tB[256]; |
|
|
|
snprintf(tB, sizeof(tB), "SilentQuery step failed (%d): %.200s", stepRC, sqlite3_errmsg(m_pDBLink)); |
|
|
|
LOG_ERROR(tB); |
|
|
|
}; |
|
|
|
sqlite3_finalize(query); |
|
|
|
m_mAccessMutex.unlock(); |
|
|
|
return false; |
|
|
|
@ -338,7 +361,7 @@ AAssoc * SQLite_Connector::Query(CSTR QS, bool useCache) |
|
|
|
if (stepRC != SQLITE_DONE) |
|
|
|
{ |
|
|
|
char tB[256]; |
|
|
|
snprintf(tB, sizeof(tB), "Query step failed (%d): %s", stepRC, sqlite3_errmsg(m_pDBLink)); |
|
|
|
snprintf(tB, sizeof(tB), "Query step failed (%d): %.200s", stepRC, sqlite3_errmsg(m_pDBLink)); |
|
|
|
LOG_ERROR(tB); |
|
|
|
}; |
|
|
|
|
|
|
|
|