fix: stabilize runtime follow-up regressions
This commit is contained in:
@@ -70,15 +70,21 @@ bool SQLite::connect(String path)
|
||||
{
|
||||
disconnect();
|
||||
this->path = path;
|
||||
// Register regardless of outcome: tracking is about the wrapper's
|
||||
// lifetime, not the connection's. disconnect()/~SQLite() unregister.
|
||||
sqlite_register_request_connection(this);
|
||||
s32 rc = sqlite3_open_v2(path.c_str(), (sqlite3**)&connection, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, 0);
|
||||
if(rc != SQLITE_OK)
|
||||
{
|
||||
set_error(rc, "sqlite open failed for " + path);
|
||||
disconnect();
|
||||
if(connection)
|
||||
{
|
||||
sqlite3_close((sqlite3*)connection);
|
||||
connection = 0;
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
sqlite3_busy_timeout((sqlite3*)connection, 5000);
|
||||
sqlite_register_request_connection(this);
|
||||
if(!apply_default_pragmas())
|
||||
return(false);
|
||||
statement_info = "connected";
|
||||
@@ -278,9 +284,11 @@ SQLite* sqlite_connect(String path)
|
||||
}
|
||||
|
||||
SQLite* db = new SQLite();
|
||||
db->worker_cache = true;
|
||||
if(db->connect(path) && db->connection)
|
||||
{
|
||||
db->worker_cache = true;
|
||||
sqlite_worker_connection_cache[path] = db;
|
||||
}
|
||||
else
|
||||
db->request_cleanup_delete = true;
|
||||
return(db);
|
||||
@@ -339,6 +347,10 @@ void cleanup_sqlite_connections()
|
||||
context->resources.sqlite_connections.pop_back();
|
||||
if(db->worker_cache)
|
||||
{
|
||||
// A page that ran BEGIN and faulted must not leak its transaction
|
||||
// (and the WAL write lock) into the next request on this worker.
|
||||
if(db->connection && !sqlite3_get_autocommit((sqlite3*)db->connection))
|
||||
sqlite3_exec((sqlite3*)db->connection, "ROLLBACK", 0, 0, 0);
|
||||
db->affected_rows = 0;
|
||||
db->insert_id = 0;
|
||||
db->error_code = SQLITE_OK;
|
||||
|
||||
Reference in New Issue
Block a user