forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnector.cpp
76 lines (54 loc) · 1.37 KB
/
Connector.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
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
74
75
//
// MySQLException.cpp
//
// $Id: //poco/1.4/Data/MySQL/src/Connector.cpp#1 $
//
// Library: Data
// Package: MySQL
// Module: Connector
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Data/MySQL/Connector.h"
#include "Poco/Data/MySQL/SessionImpl.h"
#include "Poco/Data/SessionFactory.h"
#include "Poco/Exception.h"
#include <mysql.h>
const MySQLConnectorRegistrator pocoMySQLConnectorRegistrator;
namespace Poco {
namespace Data {
namespace MySQL {
std::string Connector::KEY(POCO_DATA_MYSQL_CONNECTOR_NAME);
Connector::Connector()
{
}
Connector::~Connector()
{
}
const std::string& Connector::name() const
{
static const std::string n(POCO_DATA_MYSQL_CONNECTOR_NAME);
return n;
}
Poco::AutoPtr<Poco::Data::SessionImpl> Connector::createSession(const std::string& connectionString,
std::size_t timeout)
{
return Poco::AutoPtr<Poco::Data::SessionImpl>(new SessionImpl(connectionString, timeout));
}
void Connector::registerConnector()
{
if (mysql_library_init(0, 0, 0) != 0)
{
throw Exception("mysql_library_init error");
}
Poco::Data::SessionFactory::instance().add(new Connector());
}
void Connector::unregisterConnector()
{
Poco::Data::SessionFactory::instance().remove(POCO_DATA_MYSQL_CONNECTOR_NAME);
mysql_library_end();
}
} } } // namespace Poco::Data::MySQL