ToolMap
Loading...
Searching...
No Matches
database.h
Go to the documentation of this file.
1/***************************************************************************
2 database.h
3 Basic function for connecting a MySQL embedded database
4 -------------------
5 copyright : (C) 2007 CREALP Lucien Schreiber
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
26#ifndef __database_H__
27#define __database_H__
28
29#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
30#pragma interface "database.cpp"
31#endif
32
33#ifndef WX_PRECOMP
34#include <wx/wx.h>
35#endif
36
37#include "mysql.h"
38// #include <wx/arrstr.h> // array string
39// #include <wx/strconv.h> // unicode conversion
40
41// #include <wx/filename.h>
42
43#include <wx/buffer.h>
44#include <wx/tokenzr.h> // tokenizer of string
45#include <wx/dir.h> // directory operation (size)
46#include <wx/config.h>
47#include <wx/fileconf.h>
48
49WX_DEFINE_ARRAY_LONG(unsigned long, tmArrayULong);
50
51class DataBaseResult;
52
53// WX_DEFINE_ARRAY_(int, ArrayOfInts);
54
55class DataBase {
56 private:
57 // member
58 bool m_IsLibraryStarted;
59 bool m_IsDatabaseOpened;
60 bool m_IsDatabaseConnected;
61 MYSQL* m_MySQL;
62 MYSQL_RES* m_MySQLRes;
63 wxString m_DBName;
64 wxString m_DBPath;
65 wxString m_ErrMsgPath;
66
67 // functions
68 bool DBLibraryInit(const wxString& datadir);
69
70 void DBLibraryEnd();
71
72 bool DBUseDataBase(const wxString& dbname);
73
74 bool DBIsDataBaseReady();
75
76 bool DBGetNextRecord(MYSQL_ROW& record);
77
78 bool DBResultsNotNull();
79
80 protected:
81 public:
82 DataBase(const wxString& errmsgpath = wxEmptyString);
83
84 virtual ~DataBase();
85
86 // database operations
87 bool DataBaseCreateNew(const wxString& datadir, const wxString& name);
88
89 bool DataBaseOpen(const wxString& datadir, const wxString& name);
90
91 bool DataBaseDelete();
92
93 wxString DataBaseGetName();
94
95 wxString DataBaseGetPath();
96
97 wxString DataBaseGetSize(int precision = 2, const wxString& failmsg = _("Not available"));
98
99 static wxString DataBaseGetVersion();
100
101 wxString DataBaseGetLastError();
102
103 // thread operations
104 bool DataBaseThreadInit();
105
106 void DataBaseThreadEnd();
107
108 // query operations
109 bool DataBaseQueryNoResults(const wxString& query, bool logerror = true);
110
111 bool DataBaseQuery(const wxString& query, bool logerror = true);
112
113 int DataBaseQueriesNumber(const wxString& query);
114
115 long DataBaseGetLastInsertedID();
116
117 long DataBaseGetAffectedRows();
118
119 // query transformations
120 static bool DataBaseStringEscapeQuery(const wxString& query, wxString& results);
121
122 // results operations
123 bool DataBaseHasResults();
124
125 void DataBaseClearResults();
126
127 // results by rows (clear after use)
128 bool DataBaseGetResultSize(unsigned int* pcols, long* prows);
129
130 bool DataBaseGetNextResult(wxString& result);
131
132 bool DataBaseGetNextResult(wxArrayString& results);
133
134 bool DataBaseGetNextResult(long& result);
135
136 bool DataBaseGetNextResult(wxArrayLong& results);
137
138 bool DataBaseGetNextResult(wxDouble& result);
139
140 bool DataBaseGetNextResult(wxArrayDouble& results);
141
142 bool DataBaseGetNextRowResult(MYSQL_ROW& row, tmArrayULong& lengths);
143
144 // results set (auto cleared after use)
145 bool DataBaseGetResults(wxArrayString& results);
146
147 bool DataBaseGetResults(wxArrayLong& results);
148
149 bool DataBaseGetResults(wxArrayDouble& results);
150
151 bool DataBaseGetResults(DataBaseResult* results);
152};
153
154#if (0)
155const wxString DATABASE_TYPE_STRING = _T("MYSQL");
156
161enum Lang_Flag {
162 LANG_UTF8,
163 LANG_LATIN1
164};
165
166//----------------------------------------------------------------------------
167// DataBase
168//----------------------------------------------------------------------------
176class DataBase {
177 public:
178 // constructors and destructors
182 // DataBase();
187 //~DataBase();
196 // bool DataBaseOpen(wxString path,enum Lang_Flag flag);
197
198 // int DataBaseInitLibrary (const wxString & path);
199
206 // bool DataBaseClose ();
207
212 // bool DataBaseIsOpen();
213
214 // wxString DataBaseGetLastError();
215
222 wxArrayString DataBaseListTables();
223
230 // static wxString DatabaseGetVersion();
231
232 // long DatabaseGetCountResults();
233
234 // int DatabaseGetCountCols();
235
241 wxArrayString DatabaseListFields(wxString sTable);
242
252 bool DataBaseGetAllTableContent(wxString sTable);
253
259 // wxArrayString DataBaseGetNextResult();
260
261 long DataBaseGetLastInsertID();
262
263 // bool DataBaseGetNextResult(wxString & result);
264
265 unsigned long* DataBaseGetNextRowResult(MYSQL_ROW& row);
266
267 bool DataBaseTableExist(const wxString& tableName);
268
269 // int DataBaseGetResultAsInt(bool ClearResultDirect = TRUE);
270
271 // long DataBaseGetNextResultAsLong();
272
273 // void DataBaseGetNextResultAsLong(wxArrayLong & resultArray);
274
275 // double DataBaseGetResultAsDouble();
276
277 bool DataBaseIsTableEmpty(const wxString& tableName);
278
295 // bool DataBaseQueryNoResult(wxString myQuery, bool logerror = false);
309 // bool DataBaseQuery(const wxString & myQuery, bool logerror = false);
310
311 // wxArrayLong * DataBaseQuerySafe (const wxString & myQuery);
312
313 // bool DataBaseHasResult ();
314
315 // bool DataBaseResultExists();
316
317 // void DataBaseDestroyResults ();
318
322 // int DataBaseQueryMultiple (const wxString & myQuery);
323
324 // int DataBaseQueryReal (wxString myQuery);
325
332 // wxString DataBaseGetPath();
333
340 // wxString DataBaseGetName();
341
348 // wxString DatabaseGetCharacterSet();
349
359 // bool DataBaseCreateNew(wxString DataBasePath, wxString DataBaseName,enum Lang_Flag Flag=LANG_UTF8);
360
370 // wxArrayString DataBaseCutRequest (wxString theRequest);
371
379 // wxString DataBaseGetSize (int iPrecision=2);
380
381 // static void DataBaseCloseLibrary();
382
383 // static void DataBaseConvertWindowsPath (wxString & spath);
384
385 bool DataBaseNewThreadInit();
386
387 void DataBaseNewThreadUnInit();
388
389 // bool DataBaseQueryBinary(const char * query, bool DestroyResult = FALSE);
390
391 protected:
392 // MYSQL * pMySQL;
393
394 // for storing restults
395 // MYSQL_RES * pResults;
396 // int m_resultNumber;
397 // long m_resultCount;
398
399 // storing database path and name.
400 // wxString m_DBPath;
401 // wxString m_DBName;
402
403 // bool IsDatabaseOpen;
404
405 // static bool bIsLibInit;
406
412 // bool DataBaseConvertFullPath(wxString fullpath);
413
423 // wxString DataBaseConvertMYSQLPath(wxString originalPath);
424
430 // bool DataBaseSetCharacterSet (enum Lang_Flag myFlag);
431};
432#endif
433
434#endif
Definition databaseresult.h:30
Definition database.h:55
bool DataBaseOpen(const wxString &datadir, const wxString &name)
Open a mysql / mariadb database This function performs the following work:
Definition database.cpp:218
void DataBaseThreadEnd()
End internal variables for new thread.
Definition database.cpp:347
bool DataBaseThreadInit()
Init internal variables for new thread.
Definition database.cpp:330