DbGetConnectionState

From Wiki G1R-MP G1 Remake Multiplayer
Revision as of 10:51, 19 September 2026 by QCherry (talk | contribs) (Document upcoming 0.1.4 database recovery; organize wiki navigation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

dbGetConnectionState

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

Syntax

table|false dbGetConnectionState(DatabaseConnection connection)

Returns false for an unknown or foreign handle; otherwise returns a snapshot:

Field Meaning
state connected, reconnecting, disconnected, transaction_lost, or closing while shutdown is pending.
generation Starts at 1 after initial connection; increments after each successful replacement session.
errorCode Last state error code, or 0 after successful connection.
errorMessage Last state error description, or an empty string after successful connection.
autoreconnect Whether automatic recovery was enabled in dbConnect.

This is a cached worker-observed state, not a blocking ping. It may still say connected until the next query or idle health check observes a failure. transaction_lost also covers conservative session-loss fencing after a failed control/unknown statement; do not infer that COMMIT rolled back.

local status = dbGetConnectionState(db)
if status then
    outputDebugString(status.state .. " / generation " .. status.generation)
end

See MySQL connection recovery, dbReconnect and onDatabaseConnectionStateChange.