blob: e0f4cbc1b604e06a3a4ccf80c691e907d7d57a0d (
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
|
#include "mysqlStmt.h"
#include "mysqlBindings.h"
#include "mysqlConn.h"
#include "mysqlRecordSet.h"
#include <cstring>
#include <helpers.h>
#include <stdexcept>
#include <utility>
#include <vector>
namespace MyGrate::Input {
MySQLPrepStmt::MySQLPrepStmt(const char * const q, MYSQL * c) : stmt {mysql_stmt_init(c), &mysql_stmt_close}
{
verify<MySQLErr>(!mysql_stmt_prepare(stmt.get(), q, strlen(q)), q, c);
}
void
MySQLPrepStmt::execute(const std::initializer_list<DbValue> & vs)
{
Bindings b {vs};
verify<std::logic_error>(!mysql_stmt_bind_param(stmt.get(), b.binds.data()), "Param count mismatch");
verify<MySQLErr>(!mysql_stmt_execute(stmt.get()), "Prepared statement execute", stmt->mysql);
}
std::size_t
MySQLPrepStmt::rows() const
{
return mysql_stmt_affected_rows(stmt.get());
}
RecordSetPtr
MySQLPrepStmt::recordSet()
{
return std::make_unique<MySQLRecordSet>(std::move(stmt));
}
CursorPtr
MySQLPrepStmt::cursor()
{
return std::make_unique<MySQLCursor>(std::move(stmt));
}
}
|