any dbQuery(element connection, string sql, any ... [, function callback = nil])
Parameters
| Name | Type | Description |
|---|---|---|
| callback | function | If given, it is called with the query handle when the answer arrives; call dbPoll(query, 0) inside it.default nil |
| connection | element | A connection from dbConnect. |
| sql | string | The SQL statement, with ? and ?? as placeholders. |
| ... | any | The placeholders' values: strings, numbers, booleans or nil. |
Returns
A query handle for dbPoll and dbFree. Without callback, inside a coroutine, it waits for the answer and returns the same as dbPoll.
Placeholders and handle lifetime
?takes the next value, escaped:nilbecomesNULL, booleans become1or0and strings are quoted.??takes a string as an escaped table or column identifier.- The number of values must match the number of placeholders.
- A handle without
callbackthat nothing references any more is freed automatically by the garbage collector.
Example
dbQuery(function(query)
local rows = dbPoll(query, 0)
if rows then
print(#rows .. " players saved")
end
end, db, "SELECT * FROM players WHERE money > ?", 100)