UniSet  2.7.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 void cancel_query() override;
49  virtual const std::string lastQuery() override;
50 
51  virtual bool insert( const std::string& q ) override;
52  bool insertAndSaveRowid( const std::string& q );
53  virtual double insert_id() override;
54  void save_inserted_id( const pqxx::result& res );
55 
56  typedef std::list<std::string> Record;
57  typedef std::vector<Record> Data;
58 
59  // fast insert: Use COPY..from SDTIN..
60  bool copy( const std::string& tblname, const std::vector<std::string>& cols, const Data& data );
61 
62  virtual const std::string error() override;
63 
64  protected:
65 
66  private:
67 
68  DBResult makeResult( const pqxx::result& res );
69  std::shared_ptr<pqxx::connection> db;
70  std::string lastQ;
71  std::string lastE;
72  double last_inserted_id;
73  };
74  // ----------------------------------------------------------------------------------
75 } // end of namespace uniset
76 // ----------------------------------------------------------------------------
77 #endif
78 // ----------------------------------------------------------------------------------
Definition: CallbackTimer.h:29
Definition: PostgreSQLInterface.h:32
Definition: DBInterface.h:36
Definition: DBInterface.h:51