DbReconnect

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search

dbReconnect

Available since 0.1.4 (in development; not present in public 0.1.3). Server-side only.

Explicitly requests a fresh session for a disconnected resource-owned MySQL handle, including one fenced after transaction/session loss.

Syntax

boolean dbReconnect(DatabaseConnection connection)

Returns true if a recovery request was accepted, not if a connection has already been established. Returns false for foreign/unknown/closed handles, an already connected or reconnecting connection, or one still busy. Observe dbGetConnectionState or onDatabaseConnectionStateChange for completion.

With autoreconnect=false this requests one connection attempt. With autoreconnect=true failed attempts continue with bounded backoff. The original handle is retained and generation increases on success. No failed queries or session SQL are replayed. Calling it for transaction_lost acknowledges session replacement; it cannot resume the transaction or determine whether a lost COMMIT succeeded.

local status = dbGetConnectionState(db)
if status and status.state == "disconnected" then
    dbReconnect(db) -- asynchronous; check state before submitting more work
end

See MySQL connection recovery for safe transaction handling.