UniSet  2.24.2
MySQLInterface.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 // --------------------------------------------------------------------------
20 //----------------------------------------------------------------------------
21 #ifndef MySQLInterface_H_
22 #define MySQLInterface_H_
23 // ---------------------------------------------------------------------------
24 #include <string>
25 #include <vector>
26 #include <deque>
27 #include <iostream>
28 //#warning Для использования mysql_create нужен define USE_OLD_FUNCTIONS
29 //#define USE_OLD_FUNCTIONS
30 #include <mysql/mysql.h>
31 #include <DBInterface.h>
32 // -------------------------------------------------------------------------
33 namespace uniset
34 {
35  // ----------------------------------------------------------------------------
36  // no thread safety
38  public DBNetInterface
39  {
40  public:
41 
43  ~MySQLInterface();
44 
45  // DBResult listFields( const std::string& table, const std::string& wild );
46 
47  virtual bool nconnect( const std::string& host, const std::string& user, const std::string& pswd,
48  const std::string& dbname, unsigned int port = 0 ) override;
49  virtual bool close() override;
50 
51  bool query_ok( const std::string& q );
52 
53  // \param finalize - освободить буфер после запроса
54  virtual DBResult query( const std::string& q ) override;
55 
56  virtual const std::string lastQuery() override;
57  virtual bool insert( const std::string& q ) override;
58 
59  std::string addslashes(const std::string& str);
60 
65  virtual bool ping() const override;
66 
68  virtual bool isConnection() const override;
69 
70  virtual double insert_id() override;
71 
72  virtual const std::string error() override;
73 
74  // *******************
75  const char* gethostinfo() const;
76  protected:
77 
78  private:
79 
80  DBResult makeResult( MYSQL_RES* r, bool finalize = true );
81  MYSQL* mysql;
82  std::string lastQ;
83  bool connected;
84  };
85  // ----------------------------------------------------------------------------------
86 } // end of namespace uniset
87 // ----------------------------------------------------------------------------------
88 #endif
Definition: DBInterface.h:37
Definition: DBInterface.h:52
Definition: MySQLInterface.h:39
virtual bool ping() const override
Definition: MySQLInterface.cc:150
virtual bool isConnection() const override
Definition: MySQLInterface.cc:160
Definition: CommonEventLoop.h:15