UniSet 2.32.1
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// -------------------------------------------------------------------------
33namespace uniset
34{
35 // ----------------------------------------------------------------------------
36 // no thread safety
38 public DBNetInterface
39 {
40 public:
41
42 MySQLInterface( size_t maxbuf = 4 * 1024 );
44
45 virtual bool nconnect( const std::string& host, const std::string& user, const std::string& pswd,
46 const std::string& dbname, unsigned int port = 0 ) override;
47 virtual bool close() override;
48
49 bool query_ok( const std::string& q );
50
51 // \param finalize - освободить буфер после запроса
52 virtual DBResult query( const std::string& q ) override;
53
54 virtual const std::string lastQuery() override;
55 virtual bool insert( const std::string& q ) override;
56
61 virtual bool ping() const override;
62
64 virtual bool isConnection() const override;
65
66 virtual double insert_id() override;
67
68 virtual const std::string error() override;
69
70 // *******************
71 const char* gethostinfo() const;
72 protected:
73
74 private:
75
76 DBResult makeResult( MYSQL_RES* r, bool finalize = true );
77 MYSQL* mysql;
78 std::string lastQ;
79 bool connected;
80 char* qbuf = { nullptr };
81 size_t qbufLen = { 0 };
82 };
83 // ----------------------------------------------------------------------------------
84} // end of namespace uniset
85// ----------------------------------------------------------------------------------
86#endif
Definition DBInterface.h:37
Definition DBInterface.h:52
Definition MySQLInterface.h:39
virtual bool ping() const override
Definition MySQLInterface.cc:175
virtual bool isConnection() const override
Definition MySQLInterface.cc:185
Definition Calibration.h:27