UniSet  2.6.0
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  // ----------------------------------------------------------------------------
33  public DBNetInterface
34  {
35  public:
36 
39 
40  virtual bool nconnect( const std::string& host, const std::string& user,
41  const std::string& pswd, const std::string& dbname,
42  unsigned int port = 5432) override;
43  virtual bool close() override;
44  virtual bool isConnection() const override;
45  virtual bool ping() const override;
46 
47  virtual DBResult query( const std::string& q ) override;
48  virtual const std::string lastQuery() override;
49 
50  virtual bool insert( const std::string& q ) override;
51  bool insertAndSaveRowid( const std::string& q );
52  virtual double insert_id() override;
53  void save_inserted_id( const pqxx::result& res );
54 
55  typedef std::list<std::string> Record;
56  typedef std::vector<Record> Data;
57 
58  // fast insert: Use COPY..from SDTIN..
59  bool copy( const std::string& tblname, const std::list<std::string>& cols, const Data& data );
60 
61  virtual const std::string error() override;
62 
63  protected:
64 
65  private:
66 
67  void makeResult(DBResult& dbres, const pqxx::result& res );
68  std::shared_ptr<pqxx::connection> db;
69  std::string lastQ;
70  std::string lastE;
71  double last_inserted_id;
72  };
73  // ----------------------------------------------------------------------------------
74 } // end of namespace uniset
75 // ----------------------------------------------------------------------------
76 #endif
77 // ----------------------------------------------------------------------------------