UniSet 2.32.1
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 <string_view>
22#include <list>
23#include <vector>
24#include <queue>
25#include <iostream>
26#include <pqxx/pqxx>
27#include <PassiveTimer.h>
28#include <DBInterface.h>
29// -------------------------------------------------------------------------
30namespace uniset
31{
32 // ----------------------------------------------------------------------------
33 // No thread safety!
35 public DBNetInterface
36 {
37 public:
38
41
42 virtual bool nconnect( const std::string& host, const std::string& user,
43 const std::string& pswd, const std::string& dbname,
44 unsigned int port = 5432) override;
45 virtual bool close() override;
46 virtual bool isConnection() const override;
47 virtual bool ping() const override;
48
49 virtual DBResult query( const std::string& q ) override;
50 virtual void cancel_query() override;
51 virtual const std::string lastQuery() override;
52
53 virtual bool insert( const std::string& q ) override;
54 bool insertAndSaveRowid( const std::string& q );
55 virtual double insert_id() override;
56 void save_inserted_id( const pqxx::result& res );
57
58 typedef std::list<std::string> Record;
59 typedef std::vector<Record> Data;
60
61 // fast insert: Use COPY..from SDTIN..
62 bool copy( const std::string& tblname, std::string_view cols, const Data& data );
63
64 virtual const std::string error() override;
65
66 bool reconnect(const std::string& host, const std::string& user,
67 const std::string& pswd, const std::string& dbname,
68 unsigned int port = 5432);
69
70 protected:
71
72 private:
73
74 DBResult makeResult( const pqxx::result& res );
75 std::unique_ptr<pqxx::connection> db;
76 std::string lastQ;
77 std::string lastE;
78 double last_inserted_id;
79 };
80 // ----------------------------------------------------------------------------------
81} // end of namespace uniset
82// ----------------------------------------------------------------------------
83#endif
84// ----------------------------------------------------------------------------------
Definition DBInterface.h:37
Definition DBInterface.h:52
Definition PostgreSQLInterface.h:36
Definition Calibration.h:27