3 #if wxUSE_DATABASE_ODBC 8 m_bIsConnected =
false;
15 SetErrorMessage(wxT(
"Error loading ODBC library"));
16 ThrowDatabaseException();
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 )
25 InterpretErrorCodes( nRet );
26 ThrowDatabaseException();
29 nRet =
m_pInterface->GetSQLSetEnvAttr()((SQLHENV)m_sqlEnvHandle, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
30 if ( nRet != SQL_SUCCESS )
32 InterpretErrorCodes( nRet );
33 ThrowDatabaseException();
36 SQLHDBC sqlHDBC = (SQLHDBC)m_sqlHDBC;
37 nRet =
m_pInterface->GetSQLAllocHandle()(SQL_HANDLE_DBC, (SQLHENV)m_sqlEnvHandle, &sqlHDBC);
39 if ( nRet != SQL_SUCCESS )
41 InterpretErrorCodes( nRet );
42 ThrowDatabaseException();
45 m_strDSN = wxEmptyString;
46 m_strUser = wxEmptyString;
47 m_strPassword = wxEmptyString;
48 m_strConnection = wxEmptyString;
60 if ( nRet != SQL_SUCCESS )
67 if ( nRet != SQL_SUCCESS )
87 void* dsnCharBuffer = (
void*)
m_strDSN.c_str();
88 void* userCharBuffer = (
void*)
m_strUser.c_str();
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 )
107 memset(buff, 0, 8192*
sizeof(SQLTCHAR));
113 (SQLSMALLINT)
m_strConnection.Length(), (SQLTCHAR*)buff, 8192, &iLen, m_bPrompt ? SQL_DRIVER_PROMPT : SQL_DRIVER_NOPROMPT);
116 (SQLSMALLINT)
m_strConnection.Length(), (SQLTCHAR*)buff, 8192, &iLen, SQL_DRIVER_NOPROMPT);
119 if ( nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO )
153 m_bPrompt = bPromptForInfo;
163 bool wxOdbcDatabase::Open(
const wxString& strDSN,
const wxString& strUser,
const wxString& strPassword )
187 if ( nRet != SQL_SUCCESS )
209 if ( nRet != SQL_SUCCESS )
221 if ( nRet != SQL_SUCCESS )
228 if ( nRet != SQL_SUCCESS )
240 if ( nRet != SQL_SUCCESS )
247 if ( nRet != SQL_SUCCESS )
266 wxDELETE( pStatement );
273 wxDELETE( pStatement );
301 wxDELETE( pStatement );
314 SQLHANDLE handle = NULL;
317 if ( nRet != SQL_SUCCESS )
336 wxArrayString QueryArray;
340 QueryArray.push_back(strQuery);
344 if (pReturnStatement)
347 for (
unsigned int i=0; i<(QueryArray.size()); i++)
358 if ( nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO )
370 return pReturnStatement;
375 bool bReturn =
false;
379 wxString tableType = _(
"TABLE");
385 (SQLTCHAR*)(
const char*)tableBuffer, SQL_NTS,
386 (SQLTCHAR*)(
const char*)tableTypeBuffer, tableTypeBufferLength);
388 if (nRet != SQL_SUCCESS)
397 if (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
407 bool bReturn =
false;
411 wxString tableType = _(
"VIEW");
417 (SQLTCHAR*)(
const char*)viewBuffer, SQL_NTS,
418 (SQLTCHAR*)(
const char*)tableTypeBuffer, tableTypeBufferLength);
420 if (nRet != SQL_SUCCESS)
429 if (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
439 wxArrayString returnArray;
441 wxString tableType = _(
"TABLE");
448 (SQLTCHAR*)(
const char*)tableTypeBuffer, tableTypeBufferLength);
450 if (nRet != SQL_SUCCESS)
459 while (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
463 memset(buff, 0, 8192*
sizeof(SQLTCHAR));
465 SQLINTEGER col_size = 8192;
466 SQLLEN real_size = 0;
470 col_size, &real_size);
471 if ( nGetDataReturn != SQL_SUCCESS && nGetDataReturn != SQL_SUCCESS_WITH_INFO )
479 returnArray.Add(strTable);
490 wxArrayString returnArray;
492 wxString tableType = _(
"VIEW");
499 (SQLTCHAR*)(
const char*)tableTypeBuffer, tableTypeBufferLength);
501 if (nRet != SQL_SUCCESS)
510 while (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
514 memset(buff, 0, 8192*
sizeof(SQLTCHAR));
516 SQLINTEGER col_size = 8192;
517 SQLLEN real_size = 0;
521 col_size, &real_size );
522 if ( nGetDataReturn != SQL_SUCCESS && nGetDataReturn != SQL_SUCCESS_WITH_INFO )
530 returnArray.Add(strView);
541 wxArrayString returnArray;
549 (SQLTCHAR*)(
const char*)tableBuffer, tableBufferLength,
552 if (nRet != SQL_SUCCESS)
561 while (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
563 SQLPOINTER buff[8192];
565 memset(buff, 0, 8192*
sizeof(SQLTCHAR));
567 SQLINTEGER col_size = 8192;
568 SQLLEN real_size = 0;
572 col_size, &real_size );
573 if ( nGetDataReturn != SQL_SUCCESS && nGetDataReturn != SQL_SUCCESS_WITH_INFO )
581 returnArray.Add(strColumn);
593 wxArrayString returnArray;
601 (SQLTCHAR*)(
const char*)tableBuffer, tableBufferLength,
604 if (nRet != SQL_SUCCESS)
613 while (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO)
615 SQLPOINTER buff[8192];
617 memset(buff, 0, 8192*
sizeof(SQLTCHAR));
619 SQLINTEGER col_size = 8192;
620 SQLLEN real_size = 0;
624 col_size, &real_size );
625 if ( nGetDataReturn != SQL_SUCCESS && nGetDataReturn != SQL_SUCCESS_WITH_INFO )
633 returnArray.Add(strColumn);
646 wxLogDebug(_(
"wxOdbcDatabase::InterpretErrorCodes()\n"));
650 SQLINTEGER iNativeCode;
673 bool bAvailable =
false;
675 bAvailable = pInterface && pInterface->
Init();
676 wxDELETE(pInterface);
680 #endif//wxUSE_DATABASE_ODBC SQLColumnsType GetSQLColumns()
SQLFreeStmtType GetSQLFreeStmt()
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
virtual wxDatabaseResultSet * RunQueryWithResults(const wxString &strQuery)
Run a select query on the database.
virtual wxArrayString GetViews()
Retrieve all view names.
SQLAllocHandleType GetSQLAllocHandle()
virtual ~wxOdbcDatabase()
virtual void Commit()
Commit the current transaction.
SQLConnectType GetSQLConnect()
virtual wxDatabaseResultSet * RunQueryWithResults()
Run an insert, update, or delete query on the database.
SQLColumnsType GetSQLPKColumns()
SQLDisconnectType GetSQLDisconnect()
void ThrowDatabaseException()
const wxString & GetErrorMessage()
virtual void RollBack()
Rollback the current transaction.
SQLTablesType GetSQLTables()
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".
void SetEncoding(wxFontEncoding encoding)
void LogResultSetForCleanup(wxDatabaseResultSet *pResultSet)
Add result set object pointer to the list for "garbage collection".
void InterpretErrorCodes(long nCode, void *stmth_ptr=NULL)
#define wxDATABASE_QUERY_RESULT_ERROR
static bool IsAvailable()
SQLPrepareType GetSQLPrepare()
SQLEndTranType GetSQLEndTran()
SQLDriverConnectType GetSQLDriverConnect()
void SetOneTimer(bool bOneTimer=true)
SQLSetConnectAttrType GetSQLSetConnectAttr()
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()
void SetErrorCode(int nErrorCode)
#define wxDATABASE_ERROR_LOADING_LIBRARY
void CloseStatements()
Close all prepared statement objects that have been generated but not yet closed.
SQLGetDiagRecType GetSQLGetDiagRec()
virtual wxString ConvertFromUnicodeStream(const char *inputBuffer)
const wxCSConv * GetEncoding()
SQLGetDataType GetSQLGetData()
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.
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()