- Documentation
- Server functions
- dbExecAwait
Function
dbExecAwait
Runs a write query and waits for the database to confirm it. Inside an async task the server keeps running in the meantime. Returns the number of affected rows and the id of the new row.
Syntax
bool, int, int dbExecAwait(element connection, string query [, mixed ...])Arguments
connectionelement- A connection from
dbConnect. querystring- An SQL query with
?placeholders. ...mixed, optional- Values for the
?placeholders.
Returns
true, affected rows, insertId; false and an error message if the write failed.
Example
async(function()
local ok, rows, id = dbExecAwait(db, "INSERT INTO cars (owner, model) VALUES (?, ?)", "Jan", 411)
if ok then print("nowe auto nr " .. id) else print("błąd: " .. tostring(rows)) end
end)
See also
dbExecRuns a query that returns no result (INSERT, UPDATE, CREATE). Arguments replace the?placeholders.dbTransactionRuns several queries as one transaction. The function receives atxobject with thetx:query,tx:queryOneandtx:execmethods. An SQL error,error()orreturn falseinside the function rolls back every change.dbQuerySends a query that returns a result. Collect it withdbPollor in a callback that receives the query handle.