FreeBSD manual
download PDF document: mariadb_stmt_execute_direct.3.pdf
mariadb_stmt_execute_direct(3) MariaDB Connector/C
Name
mariadb_stmt_execute_direct - prepares and executes a prepared
statement
Synopsis
#include <mysql.h>
int mariadb_stmt_execute_direct(MYSQL_STMT * stmt,
const char *query,
size_t length);
Description
Prepares and executes a statement which was previously allocated by
mysql_stmt_init(3), using the current values of the parameter variables
if any parameters exist in the statement.
Parameters
o stmt - A statement handle, which was previously allocated by
mysql_stmt_init(3).
o query SQL statement
o length Length of SQL statement
Return value
Returns zero on success, non-zero on failure.
Notes
o Since the number of parameter of the statement is unknown before
execution it is mandatory to set the number of parameters via the
mysql_stmt_attr_set(3) function.
o If the SQL statement is a zero-terminated string, you can also pass
-1 as length.
o The statement handle is intended for one-time execution. Reusing the
statement handle might lead to unexpected behavior.
History
This function was added in Connector/C 3.0 and requires MariaDB 10.2 or
later versions.
See Also
o mysql_stmt_attr_set(3)
o mysql_stmt_bind_param(3)
Example
```C static int execute_direct_example(MYSQL mysql) { MYSQL_STMT stmt=
mysql_stmt_init(mysql); MYSQL_BIND bind[2]; int intval= 1; int
param_count= 2; char *strval= "execute_direct_example";
/* Direct execution without parameters */ if
(mariadb_stmt_execute_direct(stmt, "CREATE TABLE execute_direct (a int,
b varchar(30))", -1)) goto error;
STMT_ATTR_PREBIND_PARAMS, ¶m_count)) goto error;
/* bind parameters */ if (mysql_stmt_bind_param(stmt, bind)) goto
error;
if (mariadb_stmt_execute_direct(stmt, "INSERT INTO execute_direct
VALUES (?,?)", -1)) goto error;
mysql_stmt_close(stmt); return 0; error: printf("Error: %s",
mysql_stmt_error(stmt)); mysql_stmt_close(stmt); return 1; }
Version 3.3.1 mariadb_stmt_execute_direct(3)