.\" Automatically generated by Pandoc 2.5 .\" .TH "mariadb_stmt_execute_direct" "3" "" "Version 3.3.1" "MariaDB Connector/C" .hy .SS Name .PP mariadb_stmt_execute_direct \- prepares and executes a prepared statement .SS Synopsis .IP .nf \f[C] #include int mariadb_stmt_execute_direct(MYSQL_STMT * stmt, const char *query, size_t length); \f[R] .fi .SS Description .PP Prepares and executes a statement which was previously allocated by \f[B]mysql_stmt_init(3)\f[R], using the current values of the parameter variables if any parameters exist in the statement. .SS Parameters .IP \[bu] 2 \f[C]stmt\f[R] \- A statement handle, which was previously allocated by \f[B]mysql_stmt_init(3)\f[R]. .IP \[bu] 2 \f[C]query\f[R] SQL statement .IP \[bu] 2 \f[C]length\f[R] Length of SQL statement .SS Return value .PP Returns zero on success, non\-zero on failure. .SS Notes .IP \[bu] 2 Since the number of parameter of the statement is unknown before execution it is mandatory to set the number of parameters via the \f[B]mysql_stmt_attr_set(3)\f[R] function. .IP \[bu] 2 If the SQL statement is a zero\-terminated string, you can also pass \f[C]\-1\f[R] as length. .IP \[bu] 2 The statement handle is intended for one\-time execution. Reusing the statement handle might lead to unexpected behavior. .SS History .PP This function was added in Connector/C 3.0 and requires MariaDB 10.2 or later versions. .SS See Also .IP \[bu] 2 \f[B]mysql_stmt_attr_set(3)\f[R] .IP \[bu] 2 \f[B]mysql_stmt_bind_param(3)\f[R] .SS Example .PP \[ga]\[ga]\[ga]C static int execute_direct_example(MYSQL \f[I]mysql) { MYSQL_STMT \f[R]stmt= mysql_stmt_init(mysql); MYSQL_BIND bind[2]; int intval= 1; int param_count= 2; char *strval= \[lq]execute_direct_example\[rq]; .PP /* Direct execution without parameters */ if (mariadb_stmt_execute_direct(stmt, \[lq]CREATE TABLE execute_direct (a int, b varchar(30))\[rq], \-1)) goto error; .PP memset(&bind, 0, sizeof(MYSQL_BIND) * 2); bind[0].buffer_type= MYSQL_TYPE_SHORT; bind[0].buffer= &intval; bind[1].buffer_type= MYSQL_TYPE_STRING; bind[1].buffer= strval; bind[1].buffer_length= strlen(strval); .PP /* set number of parameters */ if (mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count)) goto error; .PP /* bind parameters */ if (mysql_stmt_bind_param(stmt, bind)) goto error; .PP if (mariadb_stmt_execute_direct(stmt, \[lq]INSERT INTO execute_direct VALUES (?,?)\[rq], \-1)) goto error; .PP mysql_stmt_close(stmt); return 0; error: printf(\[lq]Error: %s\[rq], mysql_stmt_error(stmt)); mysql_stmt_close(stmt); return 1; }