Version: 1.0.0
mysql_database.cpp
Go to the documentation of this file.
1 #include "wx/database/wxprec.h"
2 
3 #if wxUSE_DATABASE_MYSQL
4 
5 #include <wx/tokenzr.h>
6 
7 // ctor
9 {
10 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING
11  m_pInterface = new wxMysqlDynamicInterface();
12  if (!m_pInterface->Init())
13  {
15  SetErrorMessage(wxT("Error loading MySQL library"));
16  ThrowDatabaseException();
17  return;
18  }
19 #endif
20  InitDatabase();
21  m_strServer = _("localhost");
22  m_iPort = 3306; // default
23  m_strDatabase = wxT("");
24  m_strUser = wxT("");
25  m_strPassword = wxT("");
26 }
27 
28 wxMysqlDatabase::wxMysqlDatabase(const wxString& strDatabase)
29  : wxDatabase()
30 {
31 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING
32  m_pInterface = new wxMysqlDynamicInterface();
33  if (!m_pInterface->Init())
34  {
36  SetErrorMessage(wxT("Error loading MySQL library"));
37  ThrowDatabaseException();
38  return;
39  }
40 #endif
41  InitDatabase();
42  m_strServer = _("localhost");
43  m_iPort = 3306; // default
44  m_strUser = wxT("");
45  m_strPassword = wxT("");
46  Open(strDatabase);
47 }
48 
49 wxMysqlDatabase::wxMysqlDatabase(const wxString& strServer, const wxString& strDatabase)
50  : wxDatabase()
51 {
52 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING
53  m_pInterface = new wxMysqlDynamicInterface();
54  if (!m_pInterface->Init())
55  {
57  SetErrorMessage(wxT("Error loading MySQL library"));
58  ThrowDatabaseException();
59  return;
60  }
61 #endif
62  InitDatabase();
63  ParseServerAndPort(strServer);
64  m_strUser = wxT("");
65  m_strPassword = wxT("");
66  Open(strDatabase);
67 }
68 
69 wxMysqlDatabase::wxMysqlDatabase(const wxString& strDatabase, const wxString& strUser, const wxString& strPassword)
70  : wxDatabase()
71 {
72 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING
73  m_pInterface = new wxMysqlDynamicInterface();
74  if (!m_pInterface->Init())
75  {
77  SetErrorMessage(wxT("Error loading MySQL library"));
78  ThrowDatabaseException();
79  return;
80  }
81 #endif
82  InitDatabase();
83  m_strServer = _("localhost");
84  m_iPort = 3306; // default
85  m_strUser = strUser;
86  m_strPassword = strPassword;
87  Open(strDatabase);
88 }
89 
90 wxMysqlDatabase::wxMysqlDatabase(const wxString& strServer, const wxString& strDatabase, const wxString& strUser, const wxString& strPassword)
91  : wxDatabase()
92 {
93 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING
94  m_pInterface = new wxMysqlDynamicInterface();
95  if (!m_pInterface->Init())
96  {
98  SetErrorMessage(wxT("Error loading MySQL library5"));
99  ThrowDatabaseException();
100  return;
101  }
102 #endif
103  InitDatabase();
104  ParseServerAndPort(strServer);
105  m_strUser = strUser;
106  m_strPassword = strPassword;
107  Open(strDatabase);
108 }
109 
110 // dtor
112 {
113  Close();
114  //m_pInterface->GetMysqlClose()(m_pDatabase);
115  //delete m_pDatabase;
116  //m_pInterface->GetMysqlLibraryEnd()();
118  wxDELETE(m_pInterface);
119 }
120 
121 // open database
123 {
124  //char *server_options[] = { "mysql_test", "--defaults-file=my.cnf" };
125  //int num_elements = sizeof(server_options)/ sizeof(char *);
126 
127  //char *server_groups[] = { "libmysqld_server", "libmysqld_client" };
128  //m_pInterface->GetMysqlServerInit()(num_elements, server_options, server_groups);
129  //m_pDatabase = new MYSQL();
130  //m_pInterface->GetMysqlLibraryInit()();
131  //m_pInterface->GetMysqlInit()(m_pDatabase);
132 // m_pInterface->GetMysqlServerInit()( 0, NULL, NULL );
134 }
135 
136 // open database
137 bool wxMysqlDatabase::Open(const wxString& strServer, const wxString& strDatabase)
138 {
139  ParseServerAndPort(strServer);
140  return Open(strDatabase);
141 }
142 
143 bool wxMysqlDatabase::Open(const wxString& strDatabase, const wxString& strUser, const wxString& strPassword)
144 {
145  m_strUser = strUser;
146  m_strPassword = strPassword;
147  return Open(strDatabase);
148 }
149 
150 bool wxMysqlDatabase::Open(const wxString& strServer, const wxString& strDatabase, const wxString& strUser, const wxString& strPassword)
151 {
152  ParseServerAndPort(strServer);
153  m_strUser = strUser;
154  m_strPassword = strPassword;
155  return Open(strDatabase);
156 }
157 
158 bool wxMysqlDatabase::Open(const wxString& strDatabase)
159 {
160  m_strDatabase = strDatabase;
161 
162  wxCharBuffer serverCharBuffer = ConvertToUnicodeStream(m_strServer);
163  wxCharBuffer userCharBuffer = ConvertToUnicodeStream(m_strUser);
164  wxCharBuffer passwordCharBuffer = ConvertToUnicodeStream(m_strPassword);
165  wxCharBuffer databaseNameCharBuffer = ConvertToUnicodeStream(m_strDatabase);
166  long connectFlags = 0;
167 #if MYSQL_VERSION_ID >= 40100
168  #if !defined ulong
169  #define ulong unsigned long
170  #endif
171  connectFlags |= CLIENT_MULTI_RESULTS;
172  connectFlags |= CLIENT_MULTI_STATEMENTS;
173 #endif
174  if (m_pInterface->GetMysqlRealConnect()((MYSQL*)m_pDatabase, serverCharBuffer, userCharBuffer, passwordCharBuffer, databaseNameCharBuffer, m_iPort, NULL/*socket*/, connectFlags) != NULL)
175  {
176 #if wxUSE_UNICODE
177  const char* sqlStatement = "SET CHARACTER_SET_CLIENT=utf8, "
178  "CHARACTER_SET_CONNECTION=utf8, "
179  "CHARACTER_SET_RESULTS=utf8;";
180 
181  m_pInterface->GetMysqlRealQuery()((MYSQL*)m_pDatabase, sqlStatement, strlen(sqlStatement));
182  wxCSConv conv(_("UTF-8"));
183  SetEncoding(&conv);
184 #endif
185 
186  return true;
187  }
188  else
189  {
193  return false;
194  }
195 }
196 
197 void wxMysqlDatabase::ParseServerAndPort(const wxString& strServer)
198 {
199  int portIndicator = strServer.Find(_(":"));
200  if (portIndicator > -1)
201  {
202  m_strServer = strServer.SubString(0, portIndicator-1);
203  m_iPort = wxAtoi(strServer.SubString(portIndicator+1, strServer.Length()-1));
204  }
205  else
206  {
207  m_strServer = strServer;
208  m_iPort = 3306; // default
209  }
210 }
211 
212 // close database
214 {
215  CloseResultSets();
216  CloseStatements();
217 
218  ResetErrorCodes();
219  if (m_pDatabase)
220  {
222  m_pDatabase = NULL;
223  }
224 // m_pInterface->GetMysqlServerEnd()();
225  //delete m_pDatabase;
226  //m_pDatabase = NULL;
227  return true;
228 }
229 
230 
232 {
233  return (m_pDatabase != NULL);
234 }
235 
236 bool wxMysqlDatabase::ChangeDatabase(const wxString& database)
237 {
238  const char* dbCstr = database.c_str();
239  int res = m_pInterface->GetMysqlSelectDatabase()((MYSQL*)m_pDatabase, dbCstr);
240  if(res==0)
241  return true;
242  else
243  return false;
244 }
245 
246 // transaction support
248 {
249  ResetErrorCodes();
250 
251  int nReturn = m_pInterface->GetMysqlAutoCommit()((MYSQL*)m_pDatabase, 0);
252  if (nReturn != 0)
253  {
257  }
258 }
259 
261 {
262  ResetErrorCodes();
263 
264  int nReturn = m_pInterface->GetMysqlCommit()((MYSQL*)m_pDatabase);
265  if (nReturn != 0)
266  {
270  }
271  nReturn = m_pInterface->GetMysqlAutoCommit()((MYSQL*)m_pDatabase, 1);
272  if (nReturn != 0)
273  {
277  }
278 }
279 
281 {
282  ResetErrorCodes();
283 
284  int nReturn = m_pInterface->GetMysqlRollback()((MYSQL*)m_pDatabase);
285  if (nReturn != 0)
286  {
290  }
291  nReturn = m_pInterface->GetMysqlAutoCommit()((MYSQL*)m_pDatabase, 1);
292  if (nReturn != 0)
293  {
297  }
298 }
299 
300 
301 // query database
302 int wxMysqlDatabase::RunQuery(const wxString& strQuery, bool bParseQuery)
303 {
304  ResetErrorCodes();
305 
306  wxArrayString QueryArray;
307  if (bParseQuery)
308  QueryArray = ParseQueries(strQuery);
309  else
310  QueryArray.push_back(strQuery);
311 
312  wxArrayString::iterator start = QueryArray.begin();
313  wxArrayString::iterator stop = QueryArray.end();
314 
315  while (start != stop)
316  {
317  wxCharBuffer sqlBuffer = ConvertToUnicodeStream(*start);
318  //puts(sqlBuffer);
319  int nReturn = m_pInterface->GetMysqlQuery()((MYSQL*)m_pDatabase, sqlBuffer);
320  if (nReturn != 0)
321  {
326  }
327  start++;
328  }
329  return m_pInterface->GetMysqlAffectedRows()((MYSQL*)m_pDatabase);
330 }
331 
333 {
334  ResetErrorCodes();
335 
336  wxArrayString QueryArray = ParseQueries(strQuery);
337 
338  int nArraySize = QueryArray.size();
339  wxMysqlPreparedStatementResultSet* pResultSet = NULL;
340  for (int i=0; i<nArraySize; i++)
341  {
342  wxString strCurrentQuery = QueryArray[i];
343  MYSQL_STMT* pMysqlStatement = m_pInterface->GetMysqlStmtInit()((MYSQL*)m_pDatabase);
344  if (pMysqlStatement != NULL)
345  {
346  wxCharBuffer sqlBuffer = ConvertToUnicodeStream(strCurrentQuery);
347  //puts(sqlBuffer);
348  wxString sqlUTF8((const char*)sqlBuffer, wxConvUTF8);
349  if (m_pInterface->GetMysqlStmtPrepare()(pMysqlStatement, sqlBuffer, sqlUTF8.Length()) == 0)
350  {
351  int nReturn = m_pInterface->GetMysqlStmtExecute()(pMysqlStatement);
352  if (nReturn != 0)
353  {
356 
357  // Clean up after ourselves
358  m_pInterface->GetMysqlStmtFreeResult()(pMysqlStatement);
359  m_pInterface->GetMysqlStmtClose()(pMysqlStatement);
360 
362  return NULL;
363  }
364  }
365  else
366  {
370  }
371  if (i == nArraySize-1)
372  {
373  pResultSet = new wxMysqlPreparedStatementResultSet(m_pInterface, pMysqlStatement, true);
374  if (pResultSet)
375  pResultSet->SetEncoding(GetEncoding());
376 #if wxUSE_UNICODE
377  //wxPrintf(_("Allocating statement at %d\n"), pMysqlStatement);
378  // m_ResultSets[pResultSet] = pMysqlStatement;
379 #endif
380  LogResultSetForCleanup(pResultSet);
381  return pResultSet;
382  }
383 
384  m_pInterface->GetMysqlStmtFreeResult()(pMysqlStatement);
385  m_pInterface->GetMysqlStmtClose()(pMysqlStatement);
386  }
387  else
388  {
392  return NULL;
393  }
394  }
395  LogResultSetForCleanup(pResultSet);
396  return pResultSet;
397 }
398 
399 // wxPreparedStatement support
401 {
402  ResetErrorCodes();
403 
404  wxArrayString QueryArray = ParseQueries(strQuery);
405 
406  wxArrayString::iterator start = QueryArray.begin();
407  wxArrayString::iterator stop = QueryArray.end();
408 
410  if (pStatement)
411  pStatement->SetEncoding(GetEncoding());
412  while (start != stop)
413  {
414  MYSQL_STMT* pMysqlStatement = m_pInterface->GetMysqlStmtInit()((MYSQL*)m_pDatabase);
415  if (pMysqlStatement != NULL)
416  {
417  wxCharBuffer sqlBuffer = ConvertToUnicodeStream((*start));
418  //puts(sqlBuffer);
419  if (m_pInterface->GetMysqlStmtPrepare()(pMysqlStatement, sqlBuffer, GetEncodedStreamLength((*start))) == 0)
420  {
421  pStatement->AddPreparedStatement(pMysqlStatement);
422  }
423  else
424  {
428  }
429  }
430  else
431  {
435  return NULL;
436  }
437  start++;
438  }
439  LogStatementForCleanup(pStatement);
440  return pStatement;
441 }
442 
443 bool wxMysqlDatabase::TableExists(const wxString& table)
444 {
445  bool bReturn = false;
446 /*
447  // This is the way that I'd prefer to retrieve the list of tables
448  // Unfortunately MySQL returns both tables and view together
449  // So we have to try a SQL call (which may be MySQL version dependent)
450  wxCharBuffer tableBuffer = ConvertToUnicodeStream(table);
451  MYSQL_RES* pResults = m_pInterface->GetMysqlListTables()(m_pDatabase, tableBuffer);
452  if (pResults != NULL)
453  {
454  MYSQL_ROW currentRow = NULL;
455  while ((currentRow = m_Interfce.GetMysqlFetchRow()(pResults)) != NULL)
456  {
457  wxString strTable = ConvertFromUnicodeStream(currentRow[0]);
458  if (strTable == table)
459  bReturn = true;
460  }
461  m_pInterface->GetMysqlFreeResult()(pResults);
462  }
463 */
464  // Keep these variables outside of scope so that we can clean them up
465  // in case of an error
466  wxPreparedStatement* pStatement = NULL;
467  wxDatabaseResultSet* pResult = NULL;
468 
469 #if wxUSE_DATABASE_EXCEPTIONS
470  try
471  {
472 #endif
473  wxString query = _("SHOW TABLE STATUS WHERE Comment != 'VIEW' AND Name=?;");
474  pStatement = PrepareStatement(query);
475  if (pStatement)
476  {
477  pStatement->SetParamString(1, table);
478  pResult = pStatement->ExecuteQuery();
479  if (pResult)
480  {
481  if (pResult->Next())
482  {
483  wxString strTable = pResult->GetResultString(1);
484  if (table == strTable)
485  bReturn = true;
486  }
487  }
488  }
489 #if wxUSE_DATABASE_EXCEPTIONS
490  }
491  catch (wxDatabaseException& e)
492  {
493  if (pResult != NULL)
494  {
495  CloseResultSet(pResult);
496  pResult = NULL;
497  }
498 
499  if (pStatement != NULL)
500  {
501  CloseStatement(pStatement);
502  pStatement = NULL;
503  }
504 
505  throw e;
506  }
507 #endif
508 
509  if (pResult != NULL)
510  {
511  CloseResultSet(pResult);
512  pResult = NULL;
513  }
514 
515  if (pStatement != NULL)
516  {
517  CloseStatement(pStatement);
518  pStatement = NULL;
519  }
520 
521  return bReturn;
522 }
523 
524 bool wxMysqlDatabase::ViewExists(const wxString& view)
525 {
526  bool bReturn = false;
527 /*
528  // This is the way that I'd prefer to retrieve the list of tables
529  // Unfortunately MySQL returns both tables and view together
530  // So we have to try a SQL call (which may be MySQL version dependent)
531  wxCharBuffer viewBuffer = ConvertToUnicodeStream(view);
532  MYSQL_RES* pResults = m_pInterface->GetMysqlListTables()(m_pDatabase, viewBuffer);
533  if (pResults != NULL)
534  {
535  MYSQL_ROW currentRow = NULL;
536  while ((currentRow = m_pInterface->GetMysqlFetchRow()(pResults)) != NULL)
537  {
538  wxString strView = ConvertFromUnicodeStream(currentRow[0]);
539  if (strView == view)
540  bReturn = true;
541  }
542  m_pInterface->GetMysqlFreeResult()(pResults);
543  }
544 */
545  // Keep these variables outside of scope so that we can clean them up
546  // in case of an error
547  wxPreparedStatement* pStatement = NULL;
548  wxDatabaseResultSet* pResult = NULL;
549 
550 #if wxUSE_DATABASE_EXCEPTIONS
551  try
552  {
553 #endif
554  wxString query = _("SHOW TABLE STATUS WHERE Comment = 'VIEW' AND Name=?;");
555  pStatement = PrepareStatement(query);
556  if (pStatement)
557  {
558  pStatement->SetParamString(1, view);
559  pResult = pStatement->ExecuteQuery();
560  if (pResult)
561  {
562  if (pResult->Next())
563  {
564  wxString strView = pResult->GetResultString(1);
565  if (view == strView)
566  bReturn = true;
567  }
568  }
569  }
570 #if wxUSE_DATABASE_EXCEPTIONS
571  }
572  catch (wxDatabaseException& e)
573  {
574  if (pResult != NULL)
575  {
576  CloseResultSet(pResult);
577  pResult = NULL;
578  }
579 
580  if (pStatement != NULL)
581  {
582  CloseStatement(pStatement);
583  pStatement = NULL;
584  }
585 
586  throw e;
587  }
588 #endif
589 
590  if (pResult != NULL)
591  {
592  CloseResultSet(pResult);
593  pResult = NULL;
594  }
595 
596  if (pStatement != NULL)
597  {
598  CloseStatement(pStatement);
599  pStatement = NULL;
600  }
601 
602  return bReturn;
603 }
604 
605 wxArrayString wxMysqlDatabase::GetTables()
606 {
607  wxArrayString returnArray;
608 
609  if (m_pInterface->GetMysqlGetServerVersion()((MYSQL*)m_pDatabase) >= 50010)
610  {
611  wxDatabaseResultSet* pResult = NULL;
612 #if wxUSE_DATABASE_EXCEPTIONS
613  try
614  {
615 #endif
616  wxString query = _("SHOW TABLE STATUS WHERE Comment != 'VIEW';");
617  pResult = ExecuteQuery(query);
618 
619  while (pResult->Next())
620  {
621  wxString table = pResult->GetResultString(1).Trim();
622  if (!table.IsEmpty())
623  returnArray.Add(table);
624  }
625 #if wxUSE_DATABASE_EXCEPTIONS
626  }
627  catch (wxDatabaseException& e)
628  {
629  if (pResult != NULL)
630  {
631  CloseResultSet(pResult);
632  pResult = NULL;
633  }
634 
635  throw e;
636  }
637 #endif
638 
639  if (pResult != NULL)
640  {
641  CloseResultSet(pResult);
642  pResult = NULL;
643  }
644  }
645 
646  // If no tables have been found, then try the MySQL API directly
647  // This may pick up VIEWS as well as tables unfortunately
648  if (returnArray.Count() == 0)
649  {
650  MYSQL_RES* pResults = m_pInterface->GetMysqlListTables()((MYSQL*)m_pDatabase, NULL);
651  if (pResults != NULL)
652  {
653  MYSQL_ROW currentRow = NULL;
654  while ((currentRow = m_pInterface->GetMysqlFetchRow()(pResults)) != NULL)
655  {
656  wxString strTable = ConvertFromUnicodeStream(currentRow[0]);
657  returnArray.Add(strTable);
658  }
659  m_pInterface->GetMysqlFreeResult()(pResults);
660  }
661  }
662 
663  return returnArray;
664 }
665 
666 wxArrayString wxMysqlDatabase::GetViews()
667 {
668  wxArrayString returnArray;
669 
670  if (m_pInterface->GetMysqlGetServerVersion()((MYSQL*)m_pDatabase) >= 50010)
671  {
672  wxDatabaseResultSet* pResult = NULL;
673 #if wxUSE_DATABASE_EXCEPTIONS
674  try
675  {
676 #endif
677  wxString query = _("SHOW TABLE STATUS WHERE Comment = 'VIEW';");
678  pResult = ExecuteQuery(query);
679 
680  while (pResult->Next())
681  {
682  returnArray.Add(pResult->GetResultString(1).Trim());
683  }
684 #if wxUSE_DATABASE_EXCEPTIONS
685  }
686  catch (wxDatabaseException& e)
687  {
688  if (pResult != NULL)
689  {
690  CloseResultSet(pResult);
691  pResult = NULL;
692  }
693 
694  throw e;
695  }
696 #endif
697 
698  if (pResult != NULL)
699  {
700  CloseResultSet(pResult);
701  pResult = NULL;
702  }
703  }
704 
705  return returnArray;
706 }
707 
708 wxArrayString wxMysqlDatabase::GetColumns(const wxString& table)
709 {
710  wxArrayString returnArray;
711  // Keep these variables outside of scope so that we can clean them up
712  // in case of an error
713  wxDatabaseResultSet* pResult = NULL;
714 #if wxUSE_DATABASE_EXCEPTIONS
715  try
716  {
717 #endif
718  wxString query = wxString::Format(_("SHOW COLUMNS FROM %s;"), table.c_str());
719  pResult = ExecuteQuery(query);
720 
721  while (pResult->Next())
722  {
723  returnArray.Add(pResult->GetResultString(1).Trim());
724  }
725 #if wxUSE_DATABASE_EXCEPTIONS
726  }
727  catch (wxDatabaseException& e)
728  {
729  if (pResult != NULL)
730  {
731  CloseResultSet(pResult);
732  pResult = NULL;
733  }
734 
735  throw e;
736  }
737 #endif
738 
739  if (pResult != NULL)
740  {
741  CloseResultSet(pResult);
742  pResult = NULL;
743  }
744 
745 
746  return returnArray;
747 }
748 
749 
750 
751 wxArrayString wxMysqlDatabase::GetPKColumns(const wxString& table)
752 {
753  wxArrayString returnArray;
754  // Keep these variables outside of scope so that we can clean them up
755  // in case of an error
756  wxDatabaseResultSet* pResult = NULL;
757 #if wxUSE_DATABASE_EXCEPTIONS
758  try
759  {
760 #endif
761  wxString query = wxString::Format(_("SHOW KEYS FROM %s WHERE Key_name = 'PRIMARY';"), table.c_str());
762  pResult = ExecuteQuery(query);
763 
764  while (pResult->Next())
765  {
766  returnArray.Add(pResult->GetResultString(wxT("Column_name")).Trim());
767  }
768 #if wxUSE_DATABASE_EXCEPTIONS
769  }
770  catch (wxDatabaseException& e)
771  {
772  if (pResult != NULL)
773  {
774  CloseResultSet(pResult);
775  pResult = NULL;
776  }
777 
778  throw e;
779  }
780 #endif
781 
782  if (pResult != NULL)
783  {
784  CloseResultSet(pResult);
785  pResult = NULL;
786  }
787 
788 
789  return returnArray;
790 }
791 
793 {
794  // Ultimately, this will probably be a map of Mysql database error code values to wxDatabase values
795  // For now though, we'll just return error
796  return nCode;
797  //return wxDATABASE_ERROR;
798 }
799 
801 {
802  bool bAvailable = false;
804  bAvailable = pInterface && pInterface->Init();
805  wxDELETE(pInterface);
806  return bAvailable;
807 }
808 
809 #endif//wxUSE_DATABASE_MYSQL
static bool IsAvailable()
MysqlCloseType GetMysqlClose()
MysqlQueryType GetMysqlQuery()
virtual int RunQuery(const wxString &strQuery, bool bParseQuery)
Run an insert, update, or delete query on the database.
virtual void RollBack()
Rollback the current transaction.
MysqlFreeResultType GetMysqlFreeResult()
virtual bool IsOpen()
Is the connection to the database open?
MysqlRealQueryType GetMysqlRealQuery()
virtual bool ViewExists(const wxString &view)
Check for the existence of a view by name.
MysqlStmtErrnoType GetMysqlStmtErrno()
virtual wxString GetResultString(int nField)=0
Retrieve a wxString from the result set by the 1-based field index.
MysqlErrnoType GetMysqlErrno()
wxString m_strPassword
MysqlStmtExecuteType GetMysqlStmtExecute()
wxDatabaseResultSet * ExecuteQuery(const wxString &strQuery)
See RunQueryWithResults.
Definition: database.h:64
virtual wxArrayString GetViews()
Retrieve all view names.
virtual wxArrayString GetPKColumns(const wxString &table)
get Primary keys column names
virtual wxPreparedStatement * PrepareStatement(const wxString &strQuery)
Prepare a SQL statement which can be reused with different parameters.
void ParseServerAndPort(const wxString &strServer)
MysqlCommitType GetMysqlCommit()
virtual bool ChangeDatabase(const wxString &database)
MysqlStmtCloseType GetMysqlStmtClose()
wxString m_strServer
MysqlInitType GetMysqlInit()
virtual void BeginTransaction()
Begin a transaction.
wxString m_strDatabase
MysqlListTablesType GetMysqlListTables()
virtual bool Close()
close database
virtual bool CloseStatement(wxPreparedStatement *pStatement)
Close a prepared statement previously prepared by the database.
Definition: database.cpp:95
MysqlStmtFreeResultType GetMysqlStmtFreeResult()
wxString m_strUser
void SetErrorMessage(const wxString &strErrorMessage)
MysqlStmtInitType GetMysqlStmtInit()
wxDatabaseResultSet * ExecuteQuery()
See RunQueryWithResults.
virtual bool Next()=0
Move to the next record in the result set.
wxArrayString ParseQueries(const wxString &strQuery)
void LogStatementForCleanup(wxPreparedStatement *pStatement)
Add prepared statement object pointer to the list for "garbage collection".
Definition: database.h:183
MysqlGetServerVersionType GetMysqlGetServerVersion()
void SetEncoding(wxFontEncoding encoding)
void LogResultSetForCleanup(wxDatabaseResultSet *pResultSet)
Add result set object pointer to the list for "garbage collection".
Definition: database.h:181
virtual void Commit()
Commit the current transaction.
#define wxDATABASE_QUERY_RESULT_ERROR
Definition: errorcodes.h:21
virtual bool TableExists(const wxString &table)
Check for the existence of a table by name.
virtual wxArrayString GetColumns(const wxString &table)
Retrieve all column names for a table.
virtual bool Open(const wxString &strDatabase)
static int TranslateErrorCode(int nCode)
void AddPreparedStatement(MYSQL_STMT *pStatement)
MysqlSelectDatabaseType GetMysqlSelectDatabase()
virtual size_t GetEncodedStreamLength(const wxString &inputString)
void SetErrorCode(int nErrorCode)
#define wxDATABASE_ERROR_LOADING_LIBRARY
Definition: errorcodes.h:16
MysqlStmtPrepareType GetMysqlStmtPrepare()
void CloseStatements()
Close all prepared statement objects that have been generated but not yet closed.
Definition: database.cpp:38
MysqlServerEndType GetMysqlServerEnd()
MysqlAutoCommitType GetMysqlAutoCommit()
MysqlAffectedRowsType GetMysqlAffectedRows()
virtual wxString ConvertFromUnicodeStream(const char *inputBuffer)
const wxCSConv * GetEncoding()
wxMysqlDynamicInterface * m_pInterface
virtual wxArrayString GetTables()
Retrieve all table names.
virtual const wxCharBuffer ConvertToUnicodeStream(const wxString &inputString)
virtual ~wxMysqlDatabase()
MysqlErrorType GetMysqlError()
void CloseResultSets()
Close all result set objects that have been generated but not yet closed.
Definition: database.cpp:24
MysqlFetchRowType GetMysqlFetchRow()
virtual bool CloseResultSet(wxDatabaseResultSet *pResultSet)
Close a result set returned by the database or a prepared statement previously.
Definition: database.cpp:52
MysqlRollbackType GetMysqlRollback()
MysqlStmtErrorType GetMysqlStmtError()
virtual wxDatabaseResultSet * RunQueryWithResults(const wxString &strQuery)
Run a select query on the database.
MysqlRealConnectType GetMysqlRealConnect()
virtual void SetParamString(int nPosition, const wxString &strValue)=0
Set the parameter at the 1-based position to a wxString value.