2 * Copyright (C) 2005-2009 Team XBMC
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; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #ifndef _MYSQLDATASET_H
23 #define _MYSQLDATASET_H
27 #include "mysql/mysql.h"
30 /***************** Class MysqlDatabase definition ******************
32 class 'MysqlDatabase' connects with MySQL-server
34 ******************************************************************/
35 class MysqlDatabase: public Database {
37 /* connect descriptor */
44 /* default constructor */
49 Dataset *CreateDataset() const;
51 /* func. returns connection handle with MySQL-server */
52 MYSQL *getHandle() { return conn; }
53 /* func. returns current status about MySQL-server connection */
55 virtual int setErr(int err_code,const char * qry);
56 /* func. returns error message if error occurs */
57 virtual const char *getErrorMsg();
59 /* func. connects to database-server */
60 virtual int connect(bool create);
61 /* func. disconnects from database-server */
62 virtual void disconnect();
63 /* func. creates new database */
65 /* func. deletes database */
67 /* check if database exists (ie has tables/views defined) */
68 virtual bool exists();
70 virtual long nextid(const char* seq_name);
72 /* virtual methods for transaction */
74 virtual void start_transaction();
75 virtual void commit_transaction();
76 virtual void rollback_transaction();
78 /* virtual methods for formatting */
79 virtual std::string vprepare(const char *format, va_list args);
81 bool in_transaction() {return _in_transaction;};
82 int query_with_reconnect(const char* query);
86 typedef struct StrAccum StrAccum;
88 char et_getdigit(double *val, int *cnt);
89 void appendSpace(StrAccum *pAccum, int N);
90 void mysqlVXPrintf(StrAccum *pAccum, int useExtended, const char *fmt, va_list ap);
91 void mysqlStrAccumAppend(StrAccum *p, const char *z, int N);
92 char * mysqlStrAccumFinish(StrAccum *p);
93 void mysqlStrAccumReset(StrAccum *p);
94 void mysqlStrAccumInit(StrAccum *p, char *zBase, int n, int mx);
95 char *mysql_vmprintf(const char *zFormat, va_list ap);
101 /***************** Class MysqlDataset definition *******************
103 class 'MysqlDataset' does a query to MySQL-server
105 ******************************************************************/
107 class MysqlDataset : public Dataset {
117 /* Makes direct queries to database */
118 virtual void make_query(StringList &_sql);
119 /* Makes direct inserts into database */
120 virtual void make_insert();
122 virtual void make_edit();
124 virtual void make_deletion();
127 /* This function works only with MySQL database
128 Filling the fields information from select statement */
129 virtual void fill_fields();
130 /* Changing field values during dataset navigation */
131 virtual void free_row(); // free the memory allocated for the current row
136 MysqlDataset(MysqlDatabase *newDb);
141 /* set autorefresh boolean value (if true - refresh the data after edit()
142 or insert() operations default = false) */
143 void set_autorefresh(bool val);
145 /* opens a query & then sets a query results */
147 virtual void open(const std::string &sql);
148 /* func. executes a query without results to return */
150 virtual int exec (const std::string &sql);
151 virtual const void* getExecRes();
152 /* as open, but with our query exept Sql */
153 virtual bool query(const char *query);
154 virtual bool query(const std::string &query);
155 /* func. closes a query */
156 virtual void close(void);
157 /* Cancel changes, made in insert or edit states of dataset */
158 virtual void cancel();
160 virtual int64_t lastinsertid();
161 /* sequence numbers */
162 virtual long nextid(const char *seq_name);
163 /* sequence numbers */
164 virtual int num_rows();
165 /* interupt any pending database operation */
166 virtual void interrupt();
170 virtual void first();
174 /* Go to record No (starting with 0) */
175 virtual bool seek(int pos=0);