mysql_query
host callCapy
function mysql_query(handle : u64, query : string) any function mysql_query(handle : u64, query : string, params : any) any
Description
mysql_query() runs a query and returns its rows as an any.
Use named :name placeholders with an any map. Each value uses normal any string conversion without changing the caller's map. Signed and unsigned integers keep their exact decimal text. Booleans become true or false. Floating-point values use their normal string form. none becomes an empty string, not SQL NULL.
The API rejects positional ? placeholders. Add ! to a placeholder only for an unquoted non-negative integer.
Capture mysql_info(handle, "error") immediately after each query. An empty result does not indicate failure. Reading the error does not consume it.
Each selected field remains present. SQL NULL becomes none. Use has(row, key) to distinguish a selected NULL from a missing field. Non-null fields remain byte-preserving text, including numeric fields and embedded NUL bytes. Convert a field only when an operation needs a numeric type.
A failed statement or COMMIT is never replayed. After connection loss, retain the failed operation's error. A later explicit mysql_connect() can open a fresh connection. A lost COMMIT response does not establish whether the server committed the transaction.
Same-target leases share their transaction within a request or SERVICE workspace. mysql_disconnect() releases a lease. It does not commit or roll back. After a statement or row-lock timeout, explicitly roll back the transaction.
Parameters
handle : the MySQL connection handle
query : the SQL query text
params : an any map of named parameter values
Return Values
the query result rows
Example
Capy
var database := mysql_connect("localhost", "root", "", "").value ?? u64(0)
if mysql_info(database, "connection") { var rows := mysql_query(database, "select :name as name", {"name": "Ada"}); print(rows[0]["name"], "\n") }
if database { mysql_disconnect(database) }
Output
Ada