File: mariadb_stmt_execute_direct.3

package info (click to toggle)
mariadb 1%3A10.11.14-0%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 614,128 kB
  • sloc: ansic: 2,421,226; cpp: 1,765,048; asm: 381,336; perl: 62,256; java: 39,363; pascal: 38,841; sh: 38,242; sql: 19,830; yacc: 19,731; xml: 10,414; python: 10,125; ruby: 8,544; cs: 6,542; makefile: 6,155; ada: 1,879; lex: 1,207; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (73 lines) | stat: -rw-r--r-- 2,591 bytes parent folder | download
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
.\" Automatically generated by Pandoc 3.5
.\"
.TH "mariadb_stmt_execute_direct" "3" "" "Version 3.3" "MariaDB Connector/C"
.SS Name
mariadb_stmt_execute_direct \- prepares and executes a prepared
statement
.SS Synopsis
.IP
.EX
#include <mysql.h>

int mariadb_stmt_execute_direct(MYSQL_STMT * stmt,
                                const char *query,
                                size_t length);
.EE
.SS Description
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[CR]stmt\f[R] \- A statement handle, which was previously allocated by
\f[B]mysql_stmt_init(3)\f[R].
.IP \[bu] 2
\f[CR]query\f[R] SQL statement
.IP \[bu] 2
\f[CR]length\f[R] Length of SQL statement
.SS Return value
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[CR]\-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
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
\[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; }