Function rorm::rorm_db_raw_sql
source · #[no_mangle]
pub extern "C" fn rorm_db_raw_sql(
db: &'static Database,
transaction: Option<&'static mut Transaction>,
query_string: FFIString<'static>,
bind_params: FFISlice<'static, FFIValue<'static>>,
callback: Option<unsafe extern "C" fn(_: usize, _: FFISlice<'_, Row>, _: Error<'_>)>,
context: usize
)
Expand description
This function executes a raw SQL statement.
Statements are executed as prepared statements, if possible.
To define placeholders, use ?
in SQLite and MySQL and $1, $n in Postgres.
The corresponding parameters are bound in order to the query.
The number of placeholder must match with the number of provided bind parameters.
To include the statement in a transaction specify transaction
as a valid
Transaction. As the Transaction needs to be mutable, it is important to not
use the Transaction anywhere else until the callback is finished.
If the statement should be executed not in a Transaction, specify a null pointer.
Parameter:
db
: Reference to the Database, provided by rorm_db_connect.transaction
: Mutable pointer to a Transaction. Can be a null pointer to ignore this parameter.query_string
: SQL statement to execute.bind_params
: Slice of FFIValues to bind to the query.callback
: callback function. Takes thecontext
, a pointer to a slice of rows and an Error.context
: Pass through void pointer.
Important:
- Make sure
db
,query_string
andbind_params
are allocated until the callback was executed. - The FFISlice returned in the callback is freed after the callback has ended.
This function is called from an asynchronous context.