-
Notifications
You must be signed in to change notification settings - Fork 35
/
MySqlPreparedStatement.hpp
55 lines (43 loc) · 1.69 KB
/
MySqlPreparedStatement.hpp
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
#ifndef MYSQL_PREPARED_STATEMENT_HPP_
#define MYSQL_PREPARED_STATEMENT_HPP_
#include <cstddef>
// MYSQL and MYSQL_STMT are typedefs so we have to include mysql.h.
// Otherwise, I would just forward declare them.
#include <mysql/mysql.h>
#include <vector>
namespace OutputBinderPrivate {
// Used in the friend class declaration below
class Friend;
}
class MySqlPreparedStatement {
public:
MySqlPreparedStatement(MySqlPreparedStatement&& rhs) = default;
~MySqlPreparedStatement();
size_t getParameterCount() const {
return parameterCount_;
}
size_t getFieldCount() const {
return fieldCount_;
}
private:
// I don't want external uses to mess with this class, but these
// friends need to access the raw MYSQL_STMT* to fetch rows and other
// stuff.
friend class MySql;
friend class OutputBinderPrivate::Friend;
friend class MySqlException;
// External users should call MySQL::prepareStatement
MySqlPreparedStatement(const char* query, MYSQL* connection);
MySqlPreparedStatement() = delete;
MySqlPreparedStatement(const MySqlPreparedStatement&) = delete;
const MySqlPreparedStatement& operator=(
const MySqlPreparedStatement&) = delete;
MySqlPreparedStatement& operator=(MySqlPreparedStatement&&) = default;
// This should be const, but the MySQL C interface doesn't use const
// anywhere, so I'd have to typecast the constness whenever I'd want
// to use it
MYSQL_STMT* statementHandle_;
size_t parameterCount_;
size_t fieldCount_;
};
#endif // MYSQL_PREPARED_STATEMENT_HPP_