UniSet  2.6.0
MySQLInterface.h
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 // --------------------------------------------------------------------------
00020 //----------------------------------------------------------------------------
00021 #ifndef MySQLInterface_H_
00022 #define MySQLInterface_H_
00023 // ---------------------------------------------------------------------------
00024 #include <string>
00025 #include <vector>
00026 #include <deque>
00027 #include <iostream>
00028 //#warning Для использования mysql_create нужен define USE_OLD_FUNCTIONS
00029 //#define USE_OLD_FUNCTIONS
00030 #include <mysql/mysql.h>
00031 #include <DBInterface.h>
00032 // -------------------------------------------------------------------------
00033 namespace uniset
00034 {
00035 // ----------------------------------------------------------------------------
00036 class MySQLInterface:
00037     public DBNetInterface
00038 {
00039     public:
00040 
00041         MySQLInterface();
00042         ~MySQLInterface();
00043 
00044         //            DBResult listFields( const std::string& table, const std::string& wild );
00045 
00046         virtual bool nconnect( const std::string& host, const std::string& user, const std::string& pswd,
00047                                const std::string& dbname, unsigned int port = 0 ) override;
00048         virtual bool close() override;
00049 
00050         bool query_ok( const std::string& q );
00051 
00052         // \param finalize - освободить буфер после запроса
00053         virtual DBResult query( const std::string& q ) override;
00054 
00055         virtual const std::string lastQuery() override;
00056         virtual bool insert( const std::string& q ) override;
00057 
00058         std::string addslashes(const std::string& str);
00059 
00064         virtual bool ping() const override;
00065 
00067         virtual bool isConnection() const override;
00068 
00069         virtual double insert_id() override;
00070 
00071         virtual const std::string error() override;
00072 
00073         // *******************
00074         const char* gethostinfo() const;
00075     protected:
00076 
00077     private:
00078 
00079         void makeResult(DBResult& dbres, MYSQL_RES* r, bool finalize = true );
00080         MYSQL* mysql;
00081         std::string lastQ;
00082         bool connected;
00083 };
00084 // ----------------------------------------------------------------------------------
00085 } // end of namespace uniset
00086 // ----------------------------------------------------------------------------------
00087 #endif