summaryrefslogtreecommitdiffstats
path: root/libmariadb/man/mariadb_stmt_execute_direct.3
blob: b441a9e9fec6a6a89ff82c59782b87cb2e9c12c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
.\" 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 <mysql.h>

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, &param_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; }