MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlClient.hpp
1 /*
2  Copyright (C) 2008 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef SQL_CLIENT_HPP
20 #define SQL_CLIENT_HPP
21 
22 #include <Vector.hpp>
23 #include <BaseString.hpp>
24 #include <Properties.hpp>
25 #include <mysql.h>
26 
27 class SqlResultSet : public Properties {
28 public:
29 
30  // Get row with number
31  bool get_row(int row_num);
32  // Load next row
33  bool next(void);
34  // Reset iterator
35  void reset(void);
36  // Remove current row from resultset
37  void remove();
38 
39  SqlResultSet();
40  ~SqlResultSet();
41 
42  const char* column(const char* col_name);
43  uint columnAsInt(const char* col_name);
44 
45  uint insertId();
46  uint affectedRows();
47  uint numRows(void);
48  uint mysqlErrno();
49  const char* mysqlError();
50  const char* mysqlSqlstate();
51 
52 private:
53  uint get_int(const char* name);
54  const char* get_string(const char* name);
55 
56  const Properties* m_curr_row;
57  uint m_curr_row_num;
58 };
59 
60 
61 class SqlClient {
62 public:
63  SqlClient(MYSQL* mysql);
64  SqlClient(const char* _user= "root",
65  const char* _password= "",
66  const char* _suffix= 0);
67  ~SqlClient();
68 
69  bool doQuery(const char* query);
70  bool doQuery(const char* query, SqlResultSet& result);
71  bool doQuery(const char* query, const Properties& args, SqlResultSet& result);
72 
73  bool doQuery(BaseString& str);
74  bool doQuery(BaseString& str, SqlResultSet& result);
75  bool doQuery(BaseString& str, const Properties& args, SqlResultSet& result);
76 
77  bool waitConnected(int timeout);
78 
79 protected:
80 
81  bool runQuery(const char* query,
82  const Properties& args,
83  SqlResultSet& rows);
84 
85  bool isConnected();
86 
87  int connect();
88  void disconnect();
89 
90 protected:
91  bool connected;
92  MYSQL* mysql;
93  bool free_mysql; /* Don't free mysql* if allocated elsewhere */
94  BaseString default_file;
95  BaseString default_group;
96  BaseString user;
97  BaseString password;
98 };
99 
100 #endif