|
UniSet
2.6.0
|
00001 /* 00002 * Copyright (c) 2015 Pavel Vainerman. 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as 00006 * published by the Free Software Foundation, version 2.1. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Lesser Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 */ 00016 //---------------------------------------------------------------------------- 00017 #ifndef PostgreSQLInterface_H_ 00018 #define PostgreSQLInterface_H_ 00019 // --------------------------------------------------------------------------- 00020 #include <string> 00021 #include <list> 00022 #include <vector> 00023 #include <queue> 00024 #include <iostream> 00025 #include <pqxx/pqxx> 00026 #include <PassiveTimer.h> 00027 #include <DBInterface.h> 00028 // ------------------------------------------------------------------------- 00029 namespace uniset 00030 { 00031 // ---------------------------------------------------------------------------- 00032 class PostgreSQLInterface: 00033 public DBNetInterface 00034 { 00035 public: 00036 00037 PostgreSQLInterface(); 00038 ~PostgreSQLInterface(); 00039 00040 virtual bool nconnect( const std::string& host, const std::string& user, 00041 const std::string& pswd, const std::string& dbname, 00042 unsigned int port = 5432) override; 00043 virtual bool close() override; 00044 virtual bool isConnection() const override; 00045 virtual bool ping() const override; 00046 00047 virtual DBResult query( const std::string& q ) override; 00048 virtual const std::string lastQuery() override; 00049 00050 virtual bool insert( const std::string& q ) override; 00051 bool insertAndSaveRowid( const std::string& q ); 00052 virtual double insert_id() override; 00053 void save_inserted_id( const pqxx::result& res ); 00054 00055 typedef std::list<std::string> Record; 00056 typedef std::vector<Record> Data; 00057 00058 // fast insert: Use COPY..from SDTIN.. 00059 bool copy( const std::string& tblname, const std::list<std::string>& cols, const Data& data ); 00060 00061 virtual const std::string error() override; 00062 00063 protected: 00064 00065 private: 00066 00067 void makeResult(DBResult& dbres, const pqxx::result& res ); 00068 std::shared_ptr<pqxx::connection> db; 00069 std::string lastQ; 00070 std::string lastE; 00071 double last_inserted_id; 00072 }; 00073 // ---------------------------------------------------------------------------------- 00074 } // end of namespace uniset 00075 // ---------------------------------------------------------------------------- 00076 #endif 00077 // ----------------------------------------------------------------------------------
1.7.6.1