-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_ps.cc
More file actions
50 lines (39 loc) · 1.18 KB
/
binary_ps.cc
File metadata and controls
50 lines (39 loc) · 1.18 KB
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
#include <mysql.h>
#include <string>
#include <iostream>
#include "common.hh"
int main(int argc, char** argv)
{
Config cnf = parse(argc, argv);
MYSQL* c = cnf.connect();
if (c)
{
if (mysql_query(c, "CREATE OR REPLACE PROCEDURE sp() SELECT 1"))
{
std::cout << "CREATE: " << mysql_error(c) << std::endl;
}
MYSQL_STMT* stmt = mysql_stmt_init(c);
std::string query = "CALL sp()";
if (mysql_stmt_prepare(stmt, query.c_str(), query.length()))
{
std::cout << "Prepare: " << mysql_error(c) << std::endl;
}
unsigned long cursor_type = CURSOR_TYPE_READ_ONLY;
unsigned long rows = 1;
if (mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor_type))
{
std::cout << "Attr set: " << mysql_error(c) << std::endl;
}
if (mysql_stmt_execute(stmt))
{
std::cout << "Prepare: " << mysql_error(c) << std::endl;
}
mysql_stmt_close(stmt);
if (mysql_query(c, "DROP PROCEDURE sp"))
{
std::cout << "DROP: " << mysql_error(c) << std::endl;
}
}
mysql_close(c);
return 0;
}