UniSet
2.8.0
extensions
DBServer-PostgreSQL
PostgreSQLInterface.h
1
/*
2
* Copyright (c) 2015 Pavel Vainerman.
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as
6
* published by the Free Software Foundation, version 2.1.
7
*
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Lesser Public License for more details.
12
*
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*/
16
//----------------------------------------------------------------------------
17
#ifndef PostgreSQLInterface_H_
18
#define PostgreSQLInterface_H_
19
// ---------------------------------------------------------------------------
20
#include <string>
21
#include <list>
22
#include <vector>
23
#include <queue>
24
#include <iostream>
25
#include <pqxx/pqxx>
26
#include <PassiveTimer.h>
27
#include <DBInterface.h>
28
// -------------------------------------------------------------------------
29
namespace
uniset
30
{
31
// ----------------------------------------------------------------------------
32
// No thread safety!
33
class
PostgreSQLInterface
:
34
public
DBNetInterface
35
{
36
public
:
37
38
PostgreSQLInterface
();
39
~
PostgreSQLInterface
();
40
41
virtual
bool
nconnect(
const
std::string& host,
const
std::string& user,
42
const
std::string& pswd,
const
std::string& dbname,
43
unsigned
int
port = 5432)
override
;
44
virtual
bool
close()
override
;
45
virtual
bool
isConnection()
const override
;
46
virtual
bool
ping()
const override
;
47
48
virtual
DBResult
query(
const
std::string& q )
override
;
49
virtual
void
cancel_query()
override
;
50
virtual
const
std::string lastQuery()
override
;
51
52
virtual
bool
insert(
const
std::string& q )
override
;
53
bool
insertAndSaveRowid(
const
std::string& q );
54
virtual
double
insert_id()
override
;
55
void
save_inserted_id(
const
pqxx::result& res );
56
57
typedef
std::list<std::string> Record;
58
typedef
std::vector<Record> Data;
59
60
// fast insert: Use COPY..from SDTIN..
61
bool
copy(
const
std::string& tblname,
const
std::vector<std::string>& cols,
const
Data& data );
62
63
virtual
const
std::string error()
override
;
64
65
bool
reconnect(
const
std::string& host,
const
std::string& user,
66
const
std::string& pswd,
const
std::string& dbname,
67
unsigned
int
port = 5432);
68
69
protected
:
70
71
private
:
72
73
DBResult
makeResult(
const
pqxx::result& res );
74
std::unique_ptr<pqxx::connection> db;
75
std::string lastQ;
76
std::string lastE;
77
double
last_inserted_id;
78
};
79
// ----------------------------------------------------------------------------------
80
}
// end of namespace uniset
81
// ----------------------------------------------------------------------------
82
#endif
83
// ----------------------------------------------------------------------------------
uniset
Definition:
CommonEventLoop.h:14
uniset::PostgreSQLInterface
Definition:
PostgreSQLInterface.h:33
uniset::DBNetInterface
Definition:
DBInterface.h:36
uniset::DBResult
Definition:
DBInterface.h:51
Документация по UniSet. Последние изменения: Вс 25 Окт 2020 00:06:48. Создано системой
1.8.15