OnDatabaseConnectionStateChange
onDatabaseConnectionStateChange
Available since 0.1.4 (in development; not present in public 0.1.3). Server-side event.
Callback
function(connection, state, generation, errorCode, errorMessage)
Delivered on the owning resource's Lua tick, including the initial connected transition. connection compares equal to the handle returned by dbConnect. State transitions include connected, reconnecting, disconnected and transaction_lost. The event is not broadcast to other resources or clients. Source is the owning resource root. Explicit close/shutdown does not promise a final event.
Each generation identifies a different native database session. Error details describe the transition; repeated retries in the same state need not produce additional events. Up to 256 state notifications are retained per resource, dropping oldest entries on overflow. Events describe history; dbGetConnectionState returns the latest snapshot.
addEventHandler("onDatabaseConnectionStateChange", resourceRoot,
function(connection, state, generation, errorCode, errorMessage)
if connection ~= db then return end
outputDebugString("DB " .. state .. ", generation=" .. generation)
end)
Do not infer that a lost COMMIT failed. Do not blindly replay failed writes. See MySQL connection recovery.