1mariadb_stmt_execute_direct(3)MariaDB Connector/Cmariadb_stmt_execute_direct(3)
2
3
4
5 Name
6 mariadb_stmt_execute_direct - prepares and executes a prepared state‐
7 ment
8
9 Synopsis
10 #include <mysql.h>
11
12 int mariadb_stmt_execute_direct(MYSQL_STMT * stmt,
13 const char *query,
14 size_t length);
15
16 Description
17 Prepares and executes a statement which was previously allocated by
18 mysql_stmt_init(3), using the current values of the parameter variables
19 if any parameters exist in the statement.
20
21 Parameters
22 • stmt - A statement handle, which was previously allocated by
23 mysql_stmt_init(3).
24
25 • query SQL statement
26
27 • length Length of SQL statement
28
29 Return value
30 Returns zero on success, non-zero on failure.
31
32 Notes
33 • Since the number of parameter of the statement is unknown before exe‐
34 cution it is mandatory to set the number of parameters via the
35 mysql_stmt_attr_set(3) function.
36
37 • If the SQL statement is a zero-terminated string, you can also pass
38 -1 as length.
39
40 • The statement handle is intended for one-time execution. Reusing the
41 statement handle might lead to unexpected behavior.
42
43 History
44 This function was added in Connector/C 3.0 and requires MariaDB 10.2 or
45 later versions.
46
47 See Also
48 • mysql_stmt_attr_set(3)
49
50 • mysql_stmt_bind_param(3)
51
52 Example
53 ```C static int execute_direct_example(MYSQL mysql) { MYSQL_STMT stmt=
54 mysql_stmt_init(mysql); MYSQL_BIND bind[2]; int intval= 1; int
55 param_count= 2; char *strval= “execute_direct_example”;
56
57 /* Direct execution without parameters */ if (mariadb_stmt_execute_di‐
58 rect(stmt, “CREATE TABLE execute_direct (a int, b varchar(30))”, -1))
59 goto error;
60
61 memset(&bind, 0, sizeof(MYSQL_BIND) * 2); bind[0].buffer_type=
62 MYSQL_TYPE_SHORT; bind[0].buffer= &intval; bind[1].buffer_type=
63 MYSQL_TYPE_STRING; bind[1].buffer= strval; bind[1].buffer_length=
64 strlen(strval);
65
66 /* set number of parameters */ if (mysql_stmt_attr_set(stmt, STMT_AT‐
67 TR_PREBIND_PARAMS, ¶m_count)) goto error;
68
69 /* bind parameters */ if (mysql_stmt_bind_param(stmt, bind)) goto er‐
70 ror;
71
72 if (mariadb_stmt_execute_direct(stmt, “INSERT INTO execute_direct VAL‐
73 UES (?,?)”, -1)) goto error;
74
75 mysql_stmt_close(stmt); return 0; error: printf(“Error: %s”,
76 mysql_stmt_error(stmt)); mysql_stmt_close(stmt); return 1; }
77
78
79
80Version 3.3.1 mariadb_stmt_execute_direct(3)