-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.cpp
44 lines (37 loc) · 955 Bytes
/
connection.cpp
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
#include <vector>
#include <string>
#include <boost/thread/tss.hpp>
#include "cot/connection.h"
#include "cot/exception.h"
namespace cot {
boost::thread_specific_ptr<Connection::Resource> Connection::resource;
void Connection::connect(
const char * host,
const char * user,
const char * password,
const char * name)
{
if (resource.get() == NULL) {
resource.reset(new Resource());
}
if (!mysql_init(&resource->connect))
throw Exception(
std::string("mysql_init(): ") +
mysql_error(&resource->connect)
);
if (!mysql_real_connect(
&resource->connect,
host, user, password, name,
0,
NULL,
0))
throw Exception(
std::string("mysql_real_connect()") +
mysql_error(&resource->connect)
);
}
MYSQL * Connection::connection()
{
return &resource->connect;
}
} // namespace cot