Version: 1.0.0
odbc_database.cpp
Go to the documentation of this file.
1 #include "wx/database/wxprec.h"
2 
3 #if wxUSE_DATABASE_ODBC
4 
5 // ctor()
7 {
8  m_bIsConnected = false;
9  ResetErrorCodes();
10 
12  if (!m_pInterface->Init())
13  {
15  SetErrorMessage(wxT("Error loading ODBC library"));
16  ThrowDatabaseException();
17  return;
18  }
19 
20  SQLHENV sqlEnvHandle = (SQLHENV)m_sqlEnvHandle;
21  SQLRETURN nRet = m_pInterface->GetSQLAllocHandle()(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlEnvHandle);
22  m_sqlEnvHandle = sqlEnvHandle;
23  if ( nRet != SQL_SUCCESS )
24  {
25  InterpretErrorCodes( nRet );
26  ThrowDatabaseException();
27  }
28 
29  nRet = m_pInterface->GetSQLSetEnvAttr()((SQLHENV)m_sqlEnvHandle, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
30  if ( nRet != SQL_SUCCESS )
31  {
32  InterpretErrorCodes( nRet );
33  ThrowDatabaseException();
34  }
35 
36  SQLHDBC sqlHDBC = (SQLHDBC)m_sqlHDBC;
37  nRet = m_pInterface->GetSQLAllocHandle()(SQL_HANDLE_DBC, (SQLHENV)m_sqlEnvHandle, &sqlHDBC);
38  m_sqlHDBC = sqlHDBC;
39  if ( nRet != SQL_SUCCESS )
40  {
41  InterpretErrorCodes( nRet );
42  ThrowDatabaseException();
43  }
44 
45  m_strDSN = wxEmptyString;
46  m_strUser = wxEmptyString;
47  m_strPassword = wxEmptyString;
48  m_strConnection = wxEmptyString;
49 #if wxUSE_GUI
50  m_bPrompt = false;
51  m_pParent = NULL;
52 #endif
53 }
54 
56 {
57  Close();
58 
59  SQLRETURN nRet = m_pInterface->GetSQLFreeHandle()(SQL_HANDLE_DBC, (SQLHDBC)m_sqlHDBC);
60  if ( nRet != SQL_SUCCESS )
61  {
62  InterpretErrorCodes( nRet );
64  }
65 
66  nRet = m_pInterface->GetSQLFreeHandle()(SQL_HANDLE_ENV, (SQLHENV)m_sqlEnvHandle);
67  if ( nRet != SQL_SUCCESS )
68  {
69  InterpretErrorCodes( nRet );
71  }
72 
73  wxDELETE(m_pInterface);
74 }
75 
77 {
79 
80  if ( !m_strDSN.IsEmpty() )
81  {
82 #ifdef wxUSE_UNICODE
83  wxCharBuffer dsnCharBuffer = ConvertToUnicodeStream(m_strDSN);
84  wxCharBuffer userCharBuffer = ConvertToUnicodeStream(m_strUser);
85  wxCharBuffer passwordCharBuffer = ConvertToUnicodeStream(m_strPassword);
86 #else
87  void* dsnCharBuffer = (void*)m_strDSN.c_str();
88  void* userCharBuffer = (void*)m_strUser.c_str();
89  void* passwordCharBuffer = (void*)m_strPassword.c_str();
90 #endif
91 
92  SQLRETURN nRet;
93  nRet = m_pInterface->GetSQLConnect()((SQLHDBC)m_sqlHDBC, (SQLTCHAR FAR*)(const char*)dsnCharBuffer,
94  SQL_NTS, (SQLTCHAR FAR*)(const char*)userCharBuffer, SQL_NTS,
95  (SQLTCHAR FAR*)(const char*)passwordCharBuffer, SQL_NTS);
96  if ( nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO )
97  {
98  InterpretErrorCodes( nRet );
100  }
101  }
102  else if ( !m_strConnection.IsEmpty() )
103  {
104  SQLTCHAR buff[8192];
105  SQLSMALLINT iLen;
106 
107  memset(buff, 0, 8192*sizeof(SQLTCHAR));
108 
109  wxCharBuffer connectionCharBuffer = ConvertToUnicodeStream(m_strConnection); //AML
110  //AMLvoid* connectionCharBuffer = (void*)m_strConnection.c_str();
111 #if wxUSE_GUI
112  SQLRETURN nRet = m_pInterface->GetSQLDriverConnect()((SQLHDBC)m_sqlHDBC, m_pParent ? (SQLHWND)m_pParent->GetHandle() : NULL, (SQLTCHAR*)(const char*)connectionCharBuffer,
113  (SQLSMALLINT)m_strConnection.Length(), (SQLTCHAR*)buff, 8192, &iLen, m_bPrompt ? SQL_DRIVER_PROMPT : SQL_DRIVER_NOPROMPT);
114 #else
115  SQLRETURN nRet = m_pInterface->GetSQLDriverConnect()((SQLHDBC)m_sqlHDBC, NULL, (SQLTCHAR*)(const char*)connectionCharBuffer,
116  (SQLSMALLINT)m_strConnection.Length(), (SQLTCHAR*)buff, 8192, &iLen, SQL_DRIVER_NOPROMPT);
117 #endif
118 
119  if ( nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO )
120  {
121  InterpretErrorCodes( nRet );
123  }
124  }
125  else
126  {
127  return false;
128  }
129 
130  m_bIsConnected = true;
131 
132  return true;
133 }
134 
135 bool wxOdbcDatabase::Open( const wxString& strConnection )
136 {
137  m_strDSN = wxEmptyString;
138  m_strUser = wxEmptyString;
139  m_strPassword = wxEmptyString;
140  m_strConnection = strConnection;
141 #if wxUSE_GUI
142  m_bPrompt = false;
143  m_pParent = NULL;
144 #endif
145 
146  return Open();
147 }
148 
149 #if wxUSE_GUI
150 bool wxOdbcDatabase::Open(const wxString& strConnection, bool bPromptForInfo, wxWindow* parent)
151 {
152  m_strConnection = strConnection;
153  m_bPrompt = bPromptForInfo;
154  m_pParent = parent;
155  m_strDSN = wxEmptyString;
156  m_strUser = wxEmptyString;
157  m_strPassword = wxEmptyString;
158 
159  return Open();
160 }
161 #endif
162 
163 bool wxOdbcDatabase::Open( const wxString& strDSN, const wxString& strUser, const wxString& strPassword )
164 {
165  m_strDSN = strDSN;
166  m_strUser = strUser;
167  m_strPassword = strPassword;
168  m_strConnection = wxEmptyString;
169 #if wxUSE_GUI
170  m_bPrompt = false;
171  m_pParent = NULL;
172 #endif
173 
174  return Open();
175 }
176 
178 {
179  ResetErrorCodes();
180 
181  CloseResultSets();
182  CloseStatements();
183 
184  if (m_bIsConnected)
185  {
186  SQLRETURN nRet = m_pInterface->GetSQLDisconnect()((SQLHDBC)m_sqlHDBC);
187  if ( nRet != SQL_SUCCESS )
188  {
189  InterpretErrorCodes( nRet );
191  }
192 
193  m_bIsConnected=false;
194  }
195 
196  return true;
197 }
198 
200 {
201  return m_bIsConnected;
202 }
203 
205 {
206  ResetErrorCodes();
207 
208  SQLRETURN nRet = m_pInterface->GetSQLSetConnectAttr()((SQLHDBC)m_sqlHDBC, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, 0);
209  if ( nRet != SQL_SUCCESS )
210  {
211  InterpretErrorCodes( nRet );
213  }
214 }
215 
217 {
218  ResetErrorCodes();
219 
220  SQLRETURN nRet = m_pInterface->GetSQLEndTran()(SQL_HANDLE_DBC, (SQLHDBC)m_sqlHDBC, SQL_COMMIT);
221  if ( nRet != SQL_SUCCESS )
222  {
223  InterpretErrorCodes( nRet );
225  }
226 
227  nRet = m_pInterface->GetSQLSetConnectAttr()((SQLHDBC)m_sqlHDBC, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_IS_INTEGER);
228  if ( nRet != SQL_SUCCESS )
229  {
230  InterpretErrorCodes( nRet );
232  }
233 }
234 
236 {
237  ResetErrorCodes();
238 
239  SQLRETURN nRet = m_pInterface->GetSQLEndTran()(SQL_HANDLE_DBC, (SQLHDBC)m_sqlHDBC, SQL_ROLLBACK);
240  if ( nRet != SQL_SUCCESS )
241  {
242  InterpretErrorCodes( nRet );
244  }
245 
246  nRet = m_pInterface->GetSQLSetConnectAttr()((SQLHDBC)m_sqlHDBC, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_IS_INTEGER);
247  if ( nRet != SQL_SUCCESS )
248  {
249  InterpretErrorCodes( nRet );
251  }
252 }
253 
254 int wxOdbcDatabase::RunQuery( const wxString& strQuery, bool bParseQuery )
255 {
256  ResetErrorCodes();
257 
258  //wxPrintf("Running: '%s'\n", strQuery.c_str());
259  wxOdbcPreparedStatement* pStatement = (wxOdbcPreparedStatement*)PrepareStatement( strQuery, bParseQuery );
260 
261  if ( pStatement )
262  {
263  try
264  {
265  int nRows = pStatement->RunQuery();
266  wxDELETE( pStatement );
267  return nRows;
268  }
269  catch (...)
270  {
271  SetErrorCode(pStatement->GetErrorCode());
272  SetErrorMessage(pStatement->GetErrorMessage());
273  wxDELETE( pStatement );
276  }
277  }
278  else
280 }
281 
283 {
284  ResetErrorCodes();
285 
286  wxOdbcPreparedStatement* pStatement = (wxOdbcPreparedStatement*)PrepareStatement( strQuery, true );
287 
288  if ( pStatement )
289  {
290  try
291  {
292  pStatement->SetOneTimer(true);
293  wxDatabaseResultSet* pResults = pStatement->RunQueryWithResults(false /*false for "Don't log this result set for cleanup*/);
294  LogResultSetForCleanup(pResults);
295  return pResults;
296  }
297  catch (...)
298  {
299  SetErrorCode(pStatement->GetErrorCode());
300  SetErrorMessage(pStatement->GetErrorMessage());
301  wxDELETE( pStatement );
303  return NULL;
304  }
305  }
306  else
307  return NULL;
308 }
309 
311 {
312  ResetErrorCodes();
313 
314  SQLHANDLE handle = NULL;
315 
316  SQLRETURN nRet = m_pInterface->GetSQLAllocHandle()(SQL_HANDLE_STMT, (SQLHDBC)m_sqlHDBC, &handle);
317  if ( nRet != SQL_SUCCESS )
318  {
319  InterpretErrorCodes( nRet );
321  }
322  return handle;
323 }
324 
325 wxPreparedStatement* wxOdbcDatabase::PrepareStatement( const wxString& strQuery )
326 {
327  wxPreparedStatement* pStatement = PrepareStatement(strQuery, true);
328  LogStatementForCleanup(pStatement);
329  return pStatement;
330 }
331 
332 wxPreparedStatement* wxOdbcDatabase::PrepareStatement( const wxString& strQuery, bool bParseQuery )
333 {
334  ResetErrorCodes();
335 
336  wxArrayString QueryArray;
337  if (bParseQuery)
338  QueryArray = ParseQueries(strQuery);
339  else
340  QueryArray.push_back(strQuery);
341 
342  wxOdbcPreparedStatement* pReturnStatement = new wxOdbcPreparedStatement(m_pInterface, (SQLHENV)m_sqlEnvHandle, (SQLHDBC)m_sqlHDBC);
343 
344  if (pReturnStatement)
345  pReturnStatement->SetEncoding(GetEncoding());
346 
347  for (unsigned int i=0; i<(QueryArray.size()); i++)
348  {
349 //#if wxUSE_UNICODE
350 // void* sqlBuffer = (void*)(QueryArray[i].c_str());
351 //#else
352  wxCharBuffer sqlBuffer = ConvertToUnicodeStream(QueryArray[i]);
353 //#endif
354  //wxPrintf(_("Preparing statement: '%s'\n"), sqlBuffer);
355 
356  SQLHSTMT pSqlStatement = allocStmth();
357  SQLRETURN nRet = m_pInterface->GetSQLPrepare()(pSqlStatement, (SQLTCHAR*)(const char*)sqlBuffer, SQL_NTS);
358  if ( nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO )
359  {
360  InterpretErrorCodes( nRet );
361  m_pInterface->GetSQLFreeStmt()(pSqlStatement, SQL_CLOSE);
363  return NULL;
364  }
365 
366  if ( pSqlStatement )
367  pReturnStatement->AddPreparedStatement( pSqlStatement );
368  }
369 
370  return pReturnStatement;
371 }
372 
373 bool wxOdbcDatabase::TableExists(const wxString& table)
374 {
375  bool bReturn = false;
376  // Use SQLTables
377  SQLHSTMT pStatement = allocStmth();
378  wxCharBuffer tableBuffer = ConvertToUnicodeStream(table);
379  wxString tableType = _("TABLE");
380  wxCharBuffer tableTypeBuffer = ConvertToUnicodeStream(tableType);
381  int tableTypeBufferLength = GetEncodedStreamLength(tableType);
382  SQLRETURN nRet = m_pInterface->GetSQLTables()(pStatement,
383  NULL, 0,
384  NULL, 0,
385  (SQLTCHAR*)(const char*)tableBuffer, SQL_NTS,
386  (SQLTCHAR*)(const char*)tableTypeBuffer, tableTypeBufferLength);
387 
388  if (nRet != SQL_SUCCESS)
389  {
390  InterpretErrorCodes( nRet );
391  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
393  return false;
394  }
395 
396  nRet = m_pInterface->GetSQLFetch()(pStatement);
397  if (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
398  bReturn = true;
399 
400  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
401 
402  return bReturn;
403 }
404 
405 bool wxOdbcDatabase::ViewExists(const wxString& view)
406 {
407  bool bReturn = false;
408  // Use SQLTables
409  SQLHSTMT pStatement = allocStmth();
410  wxCharBuffer viewBuffer = ConvertToUnicodeStream(view);
411  wxString tableType = _("VIEW");
412  wxCharBuffer tableTypeBuffer = ConvertToUnicodeStream(tableType);
413  int tableTypeBufferLength = GetEncodedStreamLength(tableType);
414  SQLRETURN nRet = m_pInterface->GetSQLTables()(pStatement,
415  NULL, 0,
416  NULL, 0,
417  (SQLTCHAR*)(const char*)viewBuffer, SQL_NTS,
418  (SQLTCHAR*)(const char*)tableTypeBuffer, tableTypeBufferLength);
419 
420  if (nRet != SQL_SUCCESS)
421  {
422  InterpretErrorCodes( nRet );
423  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
425  return false;
426  }
427 
428  nRet = m_pInterface->GetSQLFetch()(pStatement);
429  if (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
430  bReturn = true;
431 
432  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
433 
434  return bReturn;
435 }
436 
437 wxArrayString wxOdbcDatabase::GetTables()
438 {
439  wxArrayString returnArray;
440  SQLHSTMT pStatement = allocStmth();
441  wxString tableType = _("TABLE");
442  wxCharBuffer tableTypeBuffer = ConvertToUnicodeStream(tableType);
443  int tableTypeBufferLength = GetEncodedStreamLength(tableType);
444  SQLRETURN nRet = m_pInterface->GetSQLTables()(pStatement,
445  NULL, 0,
446  NULL, 0,
447  NULL, 0,
448  (SQLTCHAR*)(const char*)tableTypeBuffer, tableTypeBufferLength);
449 
450  if (nRet != SQL_SUCCESS)
451  {
452  InterpretErrorCodes( nRet );
453  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
455  return returnArray;
456  }
457 
458  nRet = m_pInterface->GetSQLFetch()(pStatement);
459  while (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
460  {
461  SQLTCHAR buff[8192];
462 
463  memset(buff, 0, 8192*sizeof(SQLTCHAR));
464 
465  SQLINTEGER col_size = 8192;
466  SQLLEN real_size = 0;
467  int nField = 3;
468 
469  SQLRETURN nGetDataReturn = m_pInterface->GetSQLGetData()(pStatement, nField, SQL_C_CHAR, buff,
470  col_size, &real_size);
471  if ( nGetDataReturn != SQL_SUCCESS && nGetDataReturn != SQL_SUCCESS_WITH_INFO )
472  {
473  InterpretErrorCodes(nRet);
474  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
476  return returnArray;
477  }
478  wxString strTable = ConvertFromUnicodeStream((const char*)buff);
479  returnArray.Add(strTable);
480  nRet = m_pInterface->GetSQLFetch()(pStatement);
481  }
482 
483  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
484 
485  return returnArray;
486 }
487 
488 wxArrayString wxOdbcDatabase::GetViews()
489 {
490  wxArrayString returnArray;
491  SQLHSTMT pStatement = allocStmth();
492  wxString tableType = _("VIEW");
493  wxCharBuffer tableTypeBuffer = ConvertToUnicodeStream(tableType);
494  int tableTypeBufferLength = GetEncodedStreamLength(tableType);
495  SQLRETURN nRet = m_pInterface->GetSQLTables()(pStatement,
496  NULL, 0,
497  NULL, 0,
498  NULL, 0,
499  (SQLTCHAR*)(const char*)tableTypeBuffer, tableTypeBufferLength);
500 
501  if (nRet != SQL_SUCCESS)
502  {
503  InterpretErrorCodes( nRet );
504  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
506  return returnArray;
507  }
508 
509  nRet = m_pInterface->GetSQLFetch()(pStatement);
510  while (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
511  {
512  SQLTCHAR buff[8192];
513 
514  memset(buff, 0, 8192*sizeof(SQLTCHAR));
515 
516  SQLINTEGER col_size = 8192;
517  SQLLEN real_size = 0;
518  int nField = 3;
519 
520  SQLRETURN nGetDataReturn = m_pInterface->GetSQLGetData()( pStatement, nField, SQL_C_CHAR, buff,
521  col_size, &real_size );
522  if ( nGetDataReturn != SQL_SUCCESS && nGetDataReturn != SQL_SUCCESS_WITH_INFO )
523  {
524  InterpretErrorCodes(nRet);
525  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
527  return returnArray;
528  }
529  wxString strView = ConvertFromUnicodeStream((const char*)buff);
530  returnArray.Add(strView);
531  nRet = m_pInterface->GetSQLFetch()(pStatement);
532  }
533 
534  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
535 
536  return returnArray;
537 }
538 
539 wxArrayString wxOdbcDatabase::GetColumns(const wxString& table)
540 {
541  wxArrayString returnArray;
542  // Use SQLColumns
543  SQLHSTMT pStatement = allocStmth();
544  wxCharBuffer tableBuffer = ConvertToUnicodeStream(table);
545  int tableBufferLength = GetEncodedStreamLength(table);
546  SQLRETURN nRet = m_pInterface->GetSQLColumns()(pStatement,
547  NULL, 0,
548  NULL, 0,
549  (SQLTCHAR*)(const char*)tableBuffer, tableBufferLength,
550  NULL, 0);
551 
552  if (nRet != SQL_SUCCESS)
553  {
554  InterpretErrorCodes( nRet );
555  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
557  return returnArray;
558  }
559 
560  nRet = m_pInterface->GetSQLFetch()(pStatement);
561  while (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
562  {
563  SQLPOINTER buff[8192];
564 
565  memset(buff, 0, 8192*sizeof(SQLTCHAR));
566 
567  SQLINTEGER col_size = 8192;
568  SQLLEN real_size = 0;
569  int nField = 4;
570 
571  SQLRETURN nGetDataReturn = m_pInterface->GetSQLGetData()( pStatement, nField, SQL_C_CHAR, buff,
572  col_size, &real_size );
573  if ( nGetDataReturn != SQL_SUCCESS && nGetDataReturn != SQL_SUCCESS_WITH_INFO )
574  {
575  InterpretErrorCodes(nRet);
576  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
578  return returnArray;
579  }
580  wxString strColumn = ConvertFromUnicodeStream((const char*)buff);
581  returnArray.Add(strColumn);
582  nRet = m_pInterface->GetSQLFetch()(pStatement);
583  }
584 
585  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
586 
587  return returnArray;
588 }
589 
590 
591 wxArrayString wxOdbcDatabase::GetPKColumns(const wxString& table)
592 {
593  wxArrayString returnArray;
594  // Use SQLColumns
595  SQLHSTMT pStatement = allocStmth();
596  wxCharBuffer tableBuffer = ConvertToUnicodeStream(table);
597  int tableBufferLength = GetEncodedStreamLength(table);
598  SQLRETURN nRet = m_pInterface->GetSQLPKColumns()(pStatement,
599  NULL, 0,
600  NULL, 0,
601  (SQLTCHAR*)(const char*)tableBuffer, tableBufferLength,
602  NULL, 0);
603 
604  if (nRet != SQL_SUCCESS)
605  {
606  InterpretErrorCodes( nRet );
607  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
609  return returnArray;
610  }
611 
612  nRet = m_pInterface->GetSQLFetch()(pStatement);
613  while (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
614  {
615  SQLPOINTER buff[8192];
616 
617  memset(buff, 0, 8192*sizeof(SQLTCHAR));
618 
619  SQLINTEGER col_size = 8192;
620  SQLLEN real_size = 0;
621  int nField = 4;
622 
623  SQLRETURN nGetDataReturn = m_pInterface->GetSQLGetData()( pStatement, nField, SQL_C_CHAR, buff,
624  col_size, &real_size );
625  if ( nGetDataReturn != SQL_SUCCESS && nGetDataReturn != SQL_SUCCESS_WITH_INFO )
626  {
627  InterpretErrorCodes(nRet);
628  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
630  return returnArray;
631  }
632  wxString strColumn = ConvertFromUnicodeStream((const char*)buff);
633  returnArray.Add(strColumn);
634  nRet = m_pInterface->GetSQLFetch()(pStatement);
635  }
636 
637  m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE);
638 
639  return returnArray;
640 }
641 
642 
643 //void wxOdbcDatabase::InterpretErrorCodes( long nCode, SQLHSTMT stmth_ptr )
644 void wxOdbcDatabase::InterpretErrorCodes( long WXUNUSED(nCode), void* stmth_ptr )
645 {
646  wxLogDebug(_("wxOdbcDatabase::InterpretErrorCodes()\n"));
647 
648  //if ((nCode != SQL_SUCCESS) ) // && (nCode != SQL_SUCCESS_WITH_INFO))
649  //{
650  SQLINTEGER iNativeCode;
651  SQLTCHAR strState[ERR_STATE_LEN];
652  SQLTCHAR strBuffer[ERR_BUFFER_LEN];
653  SQLSMALLINT iMsgLen;
654 
655  memset(strState, 0, ERR_STATE_LEN*sizeof(SQLTCHAR));
656  memset(strBuffer, 0, ERR_BUFFER_LEN*sizeof(SQLTCHAR));
657 
658  if (stmth_ptr)
659  m_pInterface->GetSQLGetDiagRec()(SQL_HANDLE_STMT, (SQLHSTMT)stmth_ptr, 1, strState, &iNativeCode,
660  strBuffer, ERR_BUFFER_LEN, &iMsgLen);
661  else
662  m_pInterface->GetSQLGetDiagRec()(SQL_HANDLE_DBC, (SQLHDBC)m_sqlHDBC, 1, strState, &iNativeCode,
663  strBuffer, ERR_BUFFER_LEN, &iMsgLen);
664 
665  SetErrorCode((int)iNativeCode);
666  SetErrorMessage(ConvertFromUnicodeStream((char*)strBuffer)); //AML
667  //AML SetErrorMessage(wxString((wxChar*)strBuffer));
668  //}
669 }
670 
672 {
673  bool bAvailable = false;
674  wxOdbcInterface* pInterface = new wxOdbcInterface();
675  bAvailable = pInterface && pInterface->Init();
676  wxDELETE(pInterface);
677  return bAvailable;
678 }
679 
680 #endif//wxUSE_DATABASE_ODBC
SQLColumnsType GetSQLColumns()
Definition: odbc_inteface.h:65
SQLFreeStmtType GetSQLFreeStmt()
Definition: odbc_inteface.h:61
virtual bool ViewExists(const wxString &view)
Check for the existence of a view by name.
virtual int RunQuery()
Run an insert, update, or delete query on the database.
wxOdbcInterface * m_pInterface
Definition: odbc_database.h:76
wxString m_strConnection
Definition: odbc_database.h:69
wxMysqlDynamicInterface * m_pInterface
virtual wxDatabaseResultSet * RunQueryWithResults(const wxString &strQuery)
Run a select query on the database.
virtual wxArrayString GetViews()
Retrieve all view names.
SQLAllocHandleType GetSQLAllocHandle()
Definition: odbc_inteface.h:52
virtual ~wxOdbcDatabase()
virtual void Commit()
Commit the current transaction.
wxString m_strDSN
Definition: odbc_database.h:65
wxString m_strPassword
Definition: odbc_database.h:67
SQLConnectType GetSQLConnect()
Definition: odbc_inteface.h:55
virtual wxDatabaseResultSet * RunQueryWithResults()
Run an insert, update, or delete query on the database.
SQLColumnsType GetSQLPKColumns()
Definition: odbc_inteface.h:66
#define ERR_BUFFER_LEN
Definition: odbc_database.h:8
SQLDisconnectType GetSQLDisconnect()
Definition: odbc_inteface.h:57
const wxString & GetErrorMessage()
wxString m_strUser
Definition: odbc_database.h:66
virtual void RollBack()
Rollback the current transaction.
SQLTablesType GetSQLTables()
Definition: odbc_inteface.h:62
void SetErrorMessage(const wxString &strErrorMessage)
void AddPreparedStatement(SQLHSTMT pStatement)
virtual int RunQuery(const wxString &strQuery, bool bParseQuery)
Run an insert, update, or delete query on the database.
wxArrayString ParseQueries(const wxString &strQuery)
void LogStatementForCleanup(wxPreparedStatement *pStatement)
Add prepared statement object pointer to the list for "garbage collection".
Definition: database.h:183
void * allocStmth()
void SetEncoding(wxFontEncoding encoding)
void LogResultSetForCleanup(wxDatabaseResultSet *pResultSet)
Add result set object pointer to the list for "garbage collection".
Definition: database.h:181
void InterpretErrorCodes(long nCode, void *stmth_ptr=NULL)
void * m_sqlEnvHandle
Definition: odbc_database.h:61
#define wxDATABASE_QUERY_RESULT_ERROR
Definition: errorcodes.h:21
static bool IsAvailable()
SQLPrepareType GetSQLPrepare()
Definition: odbc_inteface.h:60
SQLEndTranType GetSQLEndTran()
Definition: odbc_inteface.h:59
SQLDriverConnectType GetSQLDriverConnect()
Definition: odbc_inteface.h:56
void SetOneTimer(bool bOneTimer=true)
SQLSetConnectAttrType GetSQLSetConnectAttr()
Definition: odbc_inteface.h:58
virtual bool Close()
close database
virtual wxArrayString GetPKColumns(const wxString &table)
get Primary keys column names
virtual size_t GetEncodedStreamLength(const wxString &inputString)
virtual void BeginTransaction()
Begin a transaction.
SQLFetchType GetSQLFetch()
Definition: odbc_inteface.h:63
void SetErrorCode(int nErrorCode)
#define wxDATABASE_ERROR_LOADING_LIBRARY
Definition: errorcodes.h:16
virtual bool Open()
void CloseStatements()
Close all prepared statement objects that have been generated but not yet closed.
Definition: database.cpp:38
SQLGetDiagRecType GetSQLGetDiagRec()
Definition: odbc_inteface.h:67
virtual wxString ConvertFromUnicodeStream(const char *inputBuffer)
const wxCSConv * GetEncoding()
SQLGetDataType GetSQLGetData()
Definition: odbc_inteface.h:64
virtual wxArrayString GetTables()
Retrieve all table names.
virtual const wxCharBuffer ConvertToUnicodeStream(const wxString &inputString)
virtual wxPreparedStatement * PrepareStatement(const wxString &strQuery)
Prepare a SQL statement which can be reused with different parameters.
virtual wxArrayString GetColumns(const wxString &table)
Retrieve all column names for a table.
void CloseResultSets()
Close all result set objects that have been generated but not yet closed.
Definition: database.cpp:24
#define ERR_STATE_LEN
Definition: odbc_database.h:9
virtual bool IsOpen()
Is the connection to the database open?
virtual bool TableExists(const wxString &table)
Check for the existence of a table by name.
SQLFreeHandleType GetSQLFreeHandle()
Definition: odbc_inteface.h:54