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 embedded library
38#ifndef EMBEDDED_LIBRARY
39#define EMBEDDED_LIBRARY
40#endif
41
42#include "mysql.h"
43// #include <wx/arrstr.h> // array string
44// #include <wx/strconv.h> // unicode conversion
45
46// #include <wx/filename.h>
47
48#include <wx/buffer.h>
49#include <wx/tokenzr.h> // tokenizer of string
50#include <wx/dir.h> // directory operation (size)
51#include <wx/config.h>
52#include <wx/fileconf.h>
53
54WX_DEFINE_ARRAY_LONG(unsigned long, tmArrayULong);
55
56class DataBaseResult;
57
58// WX_DEFINE_ARRAY_(int, ArrayOfInts);
59
60class DataBase {
61 private:
62 // member
63 bool m_IsLibraryStarted;
64 bool m_IsDatabaseOpened;
65 bool m_IsDatabaseConnected;
66 MYSQL* m_MySQL;
67 MYSQL_RES* m_MySQLRes;
68 wxString m_DBName;
69 wxString m_DBPath;
70 wxString m_ErrMsgPath;
71
72 // functions
73 bool DBLibraryInit(const wxString& datadir);
74
75 void DBLibraryEnd();
76
77 bool DBUseDataBase(const wxString& dbname);
78
79 bool DBIsDataBaseReady();
80
81 bool DBGetNextRecord(MYSQL_ROW& record);
82
83 bool DBResultsNotNull();
84
85 protected:
86 public:
87 DataBase(const wxString& errmsgpath = wxEmptyString);
88
89 virtual ~DataBase();
90
91 // database operations
92 bool DataBaseCreateNew(const wxString& datadir, const wxString& name);
93
94 bool DataBaseOpen(const wxString& datadir, const wxString& name);
95
96 bool DataBaseDelete();
97
98 wxString DataBaseGetName();
99
100 wxString DataBaseGetPath();
101
102 wxString DataBaseGetSize(int precision = 2, const wxString& failmsg = _("Not available"));
103
104 static wxString DataBaseGetVersion();
105
106 wxString DataBaseGetLastError();
107
108 // thread operations
109 bool DataBaseThreadInit();
110
111 void DataBaseThreadEnd();
112
113 // query operations
114 bool DataBaseQueryNoResults(const wxString& query, bool logerror = true);
115
116 bool DataBaseQuery(const wxString& query, bool logerror = true);
117
118 int DataBaseQueriesNumber(const wxString& query);
119
120 long DataBaseGetLastInsertedID();
121
122 long DataBaseGetAffectedRows();
123
124 // query transformations
125 static bool DataBaseStringEscapeQuery(const wxString& query, wxString& results);
126
127 // results operations
128 bool DataBaseHasResults();
129
130 void DataBaseClearResults();
131
132 // results by rows (clear after use)
133 bool DataBaseGetResultSize(unsigned int* pcols, long* prows);
134
135 bool DataBaseGetNextResult(wxString& result);
136
137 bool DataBaseGetNextResult(wxArrayString& results);
138
139 bool DataBaseGetNextResult(long& result);
140
141 bool DataBaseGetNextResult(wxArrayLong& results);
142
143 bool DataBaseGetNextResult(wxDouble& result);
144
145 bool DataBaseGetNextResult(wxArrayDouble& results);
146
147 bool DataBaseGetNextRowResult(MYSQL_ROW& row, tmArrayULong& lengths);
148
149 // results set (auto cleared after use)
150 bool DataBaseGetResults(wxArrayString& results);
151
152 bool DataBaseGetResults(wxArrayLong& results);
153
154 bool DataBaseGetResults(wxArrayDouble& results);
155
156 bool DataBaseGetResults(DataBaseResult* results);
157};
158
159#if (0)
160const wxString DATABASE_TYPE_STRING = _T("MYSQL");
161
166enum Lang_Flag {
167 LANG_UTF8,
168 LANG_LATIN1
169};
170
171//----------------------------------------------------------------------------
172// DataBase
173//----------------------------------------------------------------------------
181class DataBase {
182 public:
183 // constructors and destructors
187 // DataBase();
192 //~DataBase();
201 // bool DataBaseOpen(wxString path,enum Lang_Flag flag);
202
203 // int DataBaseInitLibrary (const wxString & path);
204
211 // bool DataBaseClose ();
212
217 // bool DataBaseIsOpen();
218
219 // wxString DataBaseGetLastError();
220
227 wxArrayString DataBaseListTables();
228
235 // static wxString DatabaseGetVersion();
236
237 // long DatabaseGetCountResults();
238
239 // int DatabaseGetCountCols();
240
246 wxArrayString DatabaseListFields(wxString sTable);
247
257 bool DataBaseGetAllTableContent(wxString sTable);
258
264 // wxArrayString DataBaseGetNextResult();
265
266 long DataBaseGetLastInsertID();
267
268 // bool DataBaseGetNextResult(wxString & result);
269
270 unsigned long* DataBaseGetNextRowResult(MYSQL_ROW& row);
271
272 bool DataBaseTableExist(const wxString& tableName);
273
274 // int DataBaseGetResultAsInt(bool ClearResultDirect = TRUE);
275
276 // long DataBaseGetNextResultAsLong();
277
278 // void DataBaseGetNextResultAsLong(wxArrayLong & resultArray);
279
280 // double DataBaseGetResultAsDouble();
281
282 bool DataBaseIsTableEmpty(const wxString& tableName);
283
300 // bool DataBaseQueryNoResult(wxString myQuery, bool logerror = false);
314 // bool DataBaseQuery(const wxString & myQuery, bool logerror = false);
315
316 // wxArrayLong * DataBaseQuerySafe (const wxString & myQuery);
317
318 // bool DataBaseHasResult ();
319
320 // bool DataBaseResultExists();
321
322 // void DataBaseDestroyResults ();
323
327 // int DataBaseQueryMultiple (const wxString & myQuery);
328
329 // int DataBaseQueryReal (wxString myQuery);
330
337 // wxString DataBaseGetPath();
338
345 // wxString DataBaseGetName();
346
353 // wxString DatabaseGetCharacterSet();
354
364 // bool DataBaseCreateNew(wxString DataBasePath, wxString DataBaseName,enum Lang_Flag Flag=LANG_UTF8);
365
375 // wxArrayString DataBaseCutRequest (wxString theRequest);
376
384 // wxString DataBaseGetSize (int iPrecision=2);
385
386 // static void DataBaseCloseLibrary();
387
388 // static void DataBaseConvertWindowsPath (wxString & spath);
389
390 bool DataBaseNewThreadInit();
391
392 void DataBaseNewThreadUnInit();
393
394 // bool DataBaseQueryBinary(const char * query, bool DestroyResult = FALSE);
395
396 protected:
397 // MYSQL * pMySQL;
398
399 // for storing restults
400 // MYSQL_RES * pResults;
401 // int m_resultNumber;
402 // long m_resultCount;
403
404 // storing database path and name.
405 // wxString m_DBPath;
406 // wxString m_DBName;
407
408 // bool IsDatabaseOpen;
409
410 // static bool bIsLibInit;
411
417 // bool DataBaseConvertFullPath(wxString fullpath);
418
428 // wxString DataBaseConvertMYSQLPath(wxString originalPath);
429
435 // bool DataBaseSetCharacterSet (enum Lang_Flag myFlag);
436};
437#endif
438
439#endif
Definition databaseresult.h:30
Definition database.h:60
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