+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_CURSOR_COMMIT_BEHAVIOR, (UCHAR*) &dbInf.cursorCommitBehavior, sizeof(dbInf.cursorCommitBehavior), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_CURSOR_ROLLBACK_BEHAVIOR, (UCHAR*) &dbInf.cursorRollbackBehavior, sizeof(dbInf.cursorRollbackBehavior), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_NON_NULLABLE_COLUMNS, (UCHAR*) &dbInf.supportNotNullClause, sizeof(dbInf.supportNotNullClause), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_ODBC_SQL_OPT_IEF, (UCHAR*) dbInf.supportIEF, sizeof(dbInf.supportIEF), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_DEFAULT_TXN_ISOLATION, (UCHAR*) &dbInf.txnIsolation, sizeof(dbInf.txnIsolation), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_TXN_ISOLATION_OPTION, (UCHAR*) &dbInf.txnIsolationOptions, sizeof(dbInf.txnIsolationOptions), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_FETCH_DIRECTION, (UCHAR*) &dbInf.fetchDirections, sizeof(dbInf.fetchDirections), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_LOCK_TYPES, (UCHAR*) &dbInf.lockTypes, sizeof(dbInf.lockTypes), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_POS_OPERATIONS, (UCHAR*) &dbInf.posOperations, sizeof(dbInf.posOperations), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_POSITIONED_STATEMENTS, (UCHAR*) &dbInf.posStmts, sizeof(dbInf.posStmts), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_SCROLL_CONCURRENCY, (UCHAR*) &dbInf.scrollConcurrency, sizeof(dbInf.scrollConcurrency), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_SCROLL_OPTIONS, (UCHAR*) &dbInf.scrollOptions, sizeof(dbInf.scrollOptions), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_STATIC_SENSITIVITY, (UCHAR*) &dbInf.staticSensitivity, sizeof(dbInf.staticSensitivity), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_TXN_CAPABLE, (UCHAR*) &dbInf.txnCapable, sizeof(dbInf.txnCapable), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+ retcode = SQLGetInfo(hdbc, SQL_LOGIN_TIMEOUT, (UCHAR*) &dbInf.loginTimeout, sizeof(dbInf.loginTimeout), &cb);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
+ {
+ DispAllErrors(henv, hdbc);
+ if (failOnDataTypeUnsupported)
+ return false;
+ }
+
+#ifdef DBDEBUG_CONSOLE
+ cout << wxT("***** DATA SOURCE INFORMATION *****") << endl;
+ cout << wxT(wxT("SERVER Name: ") << dbInf.serverName << endl;
+ cout << wxT("DBMS Name: ") << dbInf.dbmsName << wxT("; DBMS Version: ") << dbInf.dbmsVer << endl;
+ cout << wxT("ODBC Version: ") << dbInf.odbcVer << wxT("; Driver Version: ") << dbInf.driverVer << endl;
+
+ cout << wxT("API Conf. Level: ");
+ switch(dbInf.apiConfLvl)
+ {
+ case SQL_OAC_NONE: cout << wxT("None"); break;
+ case SQL_OAC_LEVEL1: cout << wxT("Level 1"); break;
+ case SQL_OAC_LEVEL2: cout << wxT("Level 2"); break;
+ }
+ cout << endl;
+
+ cout << wxT("SAG CLI Conf. Level: ");
+ switch(dbInf.cliConfLvl)
+ {
+ case SQL_OSCC_NOT_COMPLIANT: cout << wxT("Not Compliant"); break;
+ case SQL_OSCC_COMPLIANT: cout << wxT("Compliant"); break;
+ }
+ cout << endl;
+
+ cout << wxT("SQL Conf. Level: ");
+ switch(dbInf.sqlConfLvl)
+ {
+ case SQL_OSC_MINIMUM: cout << wxT("Minimum Grammar"); break;
+ case SQL_OSC_CORE: cout << wxT("Core Grammar"); break;
+ case SQL_OSC_EXTENDED: cout << wxT("Extended Grammar"); break;
+ }
+ cout << endl;
+
+ cout << wxT("Max. Connections: ") << dbInf.maxConnections << endl;
+ cout << wxT("Outer Joins: ") << dbInf.outerJoins << endl;
+ cout << wxT("Support for Procedures: ") << dbInf.procedureSupport << endl;
+ cout << wxT("All tables accessible : ") << dbInf.accessibleTables << endl;
+ cout << wxT("Cursor COMMIT Behavior: ");
+ switch(dbInf.cursorCommitBehavior)
+ {
+ case SQL_CB_DELETE: cout << wxT("Delete cursors"); break;
+ case SQL_CB_CLOSE: cout << wxT("Close cursors"); break;
+ case SQL_CB_PRESERVE: cout << wxT("Preserve cursors"); break;
+ }
+ cout << endl;
+
+ cout << wxT("Cursor ROLLBACK Behavior: ");
+ switch(dbInf.cursorRollbackBehavior)
+ {
+ case SQL_CB_DELETE: cout << wxT("Delete cursors"); break;
+ case SQL_CB_CLOSE: cout << wxT("Close cursors"); break;
+ case SQL_CB_PRESERVE: cout << wxT("Preserve cursors"); break;
+ }
+ cout << endl;
+
+ cout << wxT("Support NOT NULL clause: ");
+ switch(dbInf.supportNotNullClause)
+ {
+ case SQL_NNC_NULL: cout << wxT("No"); break;
+ case SQL_NNC_NON_NULL: cout << wxT("Yes"); break;
+ }
+ cout << endl;
+
+ cout << wxT("Support IEF (Ref. Integrity): ") << dbInf.supportIEF << endl;
+ cout << wxT("Login Timeout: ") << dbInf.loginTimeout << endl;
+
+ cout << endl << endl << wxT("more ...") << endl;
+ getchar();
+
+ cout << wxT("Default Transaction Isolation: ";
+ switch(dbInf.txnIsolation)
+ {
+ case SQL_TXN_READ_UNCOMMITTED: cout << wxT("Read Uncommitted"); break;
+ case SQL_TXN_READ_COMMITTED: cout << wxT("Read Committed"); break;
+ case SQL_TXN_REPEATABLE_READ: cout << wxT("Repeatable Read"); break;
+ case SQL_TXN_SERIALIZABLE: cout << wxT("Serializable"); break;
+#ifdef ODBC_V20
+ case SQL_TXN_VERSIONING: cout << wxT("Versioning"); break;
+#endif
+ }
+ cout << endl;
+
+ cout << wxT("Transaction Isolation Options: ");
+ if (dbInf.txnIsolationOptions & SQL_TXN_READ_UNCOMMITTED)
+ cout << wxT("Read Uncommitted, ");
+ if (dbInf.txnIsolationOptions & SQL_TXN_READ_COMMITTED)
+ cout << wxT("Read Committed, ");
+ if (dbInf.txnIsolationOptions & SQL_TXN_REPEATABLE_READ)
+ cout << wxT("Repeatable Read, ");
+ if (dbInf.txnIsolationOptions & SQL_TXN_SERIALIZABLE)
+ cout << wxT("Serializable, ");
+#ifdef ODBC_V20
+ if (dbInf.txnIsolationOptions & SQL_TXN_VERSIONING)
+ cout << wxT("Versioning");
+#endif
+ cout << endl;
+
+ cout << wxT("Fetch Directions Supported:") << endl << wxT(" ");
+ if (dbInf.fetchDirections & SQL_FD_FETCH_NEXT)
+ cout << wxT("Next, ");
+ if (dbInf.fetchDirections & SQL_FD_FETCH_PRIOR)
+ cout << wxT("Prev, ");
+ if (dbInf.fetchDirections & SQL_FD_FETCH_FIRST)
+ cout << wxT("First, ");
+ if (dbInf.fetchDirections & SQL_FD_FETCH_LAST)
+ cout << wxT("Last, ");
+ if (dbInf.fetchDirections & SQL_FD_FETCH_ABSOLUTE)
+ cout << wxT("Absolute, ");
+ if (dbInf.fetchDirections & SQL_FD_FETCH_RELATIVE)
+ cout << wxT("Relative, ");
+#ifdef ODBC_V20
+ if (dbInf.fetchDirections & SQL_FD_FETCH_RESUME)
+ cout << wxT("Resume, ");
+#endif
+ if (dbInf.fetchDirections & SQL_FD_FETCH_BOOKMARK)
+ cout << wxT("Bookmark");
+ cout << endl;
+
+ cout << wxT("Lock Types Supported (SQLSetPos): ");
+ if (dbInf.lockTypes & SQL_LCK_NO_CHANGE)
+ cout << wxT("No Change, ");
+ if (dbInf.lockTypes & SQL_LCK_EXCLUSIVE)
+ cout << wxT("Exclusive, ");
+ if (dbInf.lockTypes & SQL_LCK_UNLOCK)
+ cout << wxT("UnLock");
+ cout << endl;
+
+ cout << wxT("Position Operations Supported (SQLSetPos): ");
+ if (dbInf.posOperations & SQL_POS_POSITION)
+ cout << wxT("Position, ");
+ if (dbInf.posOperations & SQL_POS_REFRESH)
+ cout << wxT("Refresh, ");
+ if (dbInf.posOperations & SQL_POS_UPDATE)
+ cout << wxT("Upd, "));
+ if (dbInf.posOperations & SQL_POS_DELETE)
+ cout << wxT("Del, ");
+ if (dbInf.posOperations & SQL_POS_ADD)
+ cout << wxT("Add");
+ cout << endl;
+
+ cout << wxT("Positioned Statements Supported: ");
+ if (dbInf.posStmts & SQL_PS_POSITIONED_DELETE)
+ cout << wxT("Pos delete, ");
+ if (dbInf.posStmts & SQL_PS_POSITIONED_UPDATE)
+ cout << wxT("Pos update, ");
+ if (dbInf.posStmts & SQL_PS_SELECT_FOR_UPDATE)
+ cout << wxT("Select for update");
+ cout << endl;
+
+ cout << wxT("Scroll Concurrency: ");
+ if (dbInf.scrollConcurrency & SQL_SCCO_READ_ONLY)
+ cout << wxT("Read Only, ");
+ if (dbInf.scrollConcurrency & SQL_SCCO_LOCK)
+ cout << wxT("Lock, ");
+ if (dbInf.scrollConcurrency & SQL_SCCO_OPT_ROWVER)
+ cout << wxT("Opt. Rowver, ");
+ if (dbInf.scrollConcurrency & SQL_SCCO_OPT_VALUES)
+ cout << wxT("Opt. Values");
+ cout << endl;
+
+ cout << wxT("Scroll Options: ");
+ if (dbInf.scrollOptions & SQL_SO_FORWARD_ONLY)
+ cout << wxT("Fwd Only, ");
+ if (dbInf.scrollOptions & SQL_SO_STATIC)
+ cout << wxT("Static, ");
+ if (dbInf.scrollOptions & SQL_SO_KEYSET_DRIVEN)
+ cout << wxT("Keyset Driven, ");
+ if (dbInf.scrollOptions & SQL_SO_DYNAMIC)
+ cout << wxT("Dynamic, ");
+ if (dbInf.scrollOptions & SQL_SO_MIXED)
+ cout << wxT("Mixed");
+ cout << endl;
+
+ cout << wxT("Static Sensitivity: ");
+ if (dbInf.staticSensitivity & SQL_SS_ADDITIONS)
+ cout << wxT("Additions, ");
+ if (dbInf.staticSensitivity & SQL_SS_DELETIONS)
+ cout << wxT("Deletions, ");
+ if (dbInf.staticSensitivity & SQL_SS_UPDATES)
+ cout << wxT("Updates");
+ cout << endl;
+
+ cout << wxT("Transaction Capable?: ");
+ switch(dbInf.txnCapable)
+ {
+ case SQL_TC_NONE: cout << wxT("No"); break;
+ case SQL_TC_DML: cout << wxT("DML Only"); break;
+ case SQL_TC_DDL_COMMIT: cout << wxT("DDL Commit"); break;
+ case SQL_TC_DDL_IGNORE: cout << wxT("DDL Ignore"); break;
+ case SQL_TC_ALL: cout << wxT("DDL & DML"); break;
+ }
+ cout << endl;
+
+ cout << endl;
+#endif
+
+ // Completed Successfully
+ return true;
+
+} // wxDb::getDbInfo()
+
+
+/********** wxDb::getDataTypeInfo() **********/
+bool wxDb::getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo)
+{
+/*
+ * fSqlType will be something like SQL_VARCHAR. This parameter determines
+ * the data type inf. is gathered for.
+ *
+ * wxDbSqlTypeInfo is a structure that is filled in with data type information,
+ */
+ RETCODE retcode;
+ SQLLEN cbRet;
+
+ // Get information about the data type specified
+ if (SQLGetTypeInfo(hstmt, fSqlType) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc, hstmt));
+
+ // Fetch the record
+ retcode = SQLFetch(hstmt);
+ if (retcode != SQL_SUCCESS)
+ {
+#ifdef DBDEBUG_CONSOLE
+ if (retcode == SQL_NO_DATA_FOUND)
+ cout << wxT("SQL_NO_DATA_FOUND fetching information about data type.") << endl;
+#endif
+ DispAllErrors(henv, hdbc, hstmt);
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return false;
+ }
+
+ wxChar typeName[DB_TYPE_NAME_LEN+1];
+
+ // Obtain columns from the record
+ if (SQLGetData(hstmt, 1, SQL_C_WXCHAR, typeName, sizeof(typeName), &cbRet) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc, hstmt));
+
+ structSQLTypeInfo.TypeName = typeName;
+
+ // BJO 20000503: no more needed with new GetColumns...
+#if OLD_GETCOLUMNS
+ // BJO 991209
+ if (Dbms() == dbmsMY_SQL)
+ {
+ if (structSQLTypeInfo.TypeName == wxT("middleint"))
+ structSQLTypeInfo.TypeName = wxT("mediumint");
+ else if (structSQLTypeInfo.TypeName == wxT("middleint unsigned"))
+ structSQLTypeInfo.TypeName = wxT("mediumint unsigned");
+ else if (structSQLTypeInfo.TypeName == wxT("integer"))
+ structSQLTypeInfo.TypeName = wxT("int");
+ else if (structSQLTypeInfo.TypeName == wxT("integer unsigned"))
+ structSQLTypeInfo.TypeName = wxT("int unsigned");
+ else if (structSQLTypeInfo.TypeName == wxT("middleint"))
+ structSQLTypeInfo.TypeName = wxT("mediumint");
+ else if (structSQLTypeInfo.TypeName == wxT("varchar"))
+ structSQLTypeInfo.TypeName = wxT("char");
+ }
+
+ // BJO 20000427 : OpenLink driver
+ if (!wxStrncmp(dbInf.driverName, wxT("oplodbc"), 7) ||
+ !wxStrncmp(dbInf.driverName, wxT("OLOD"), 4))
+ {
+ if (structSQLTypeInfo.TypeName == wxT("double precision"))
+ structSQLTypeInfo.TypeName = wxT("real");
+ }
+#endif
+
+ if (SQLGetData(hstmt, 3, SQL_C_LONG, (UCHAR*) &structSQLTypeInfo.Precision, 0, &cbRet) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc, hstmt));
+ if (SQLGetData(hstmt, 8, SQL_C_SHORT, (UCHAR*) &structSQLTypeInfo.CaseSensitive, 0, &cbRet) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc, hstmt));
+// if (SQLGetData(hstmt, 14, SQL_C_SHORT, (UCHAR*) &structSQLTypeInfo.MinimumScale, 0, &cbRet) != SQL_SUCCESS)
+// return(DispAllErrors(henv, hdbc, hstmt));
+
+ if (SQLGetData(hstmt, 15, SQL_C_SHORT,(UCHAR*) &structSQLTypeInfo.MaximumScale, 0, &cbRet) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc, hstmt));
+
+ if (structSQLTypeInfo.MaximumScale < 0)
+ structSQLTypeInfo.MaximumScale = 0;
+
+ // Close the statement handle which closes open cursors
+ if (SQLFreeStmt(hstmt, SQL_CLOSE) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc, hstmt));
+
+ // Completed Successfully
+ return true;
+
+} // wxDb::getDataTypeInfo()
+
+
+/********** wxDb::Close() **********/
+void wxDb::Close(void)
+{
+ // Close the Sql Log file
+ if (fpSqlLog)
+ {
+ fclose(fpSqlLog);
+ fpSqlLog = 0;
+ }
+
+ // Free statement handle
+ if (dbIsOpen)
+ {
+ if (SQLFreeStmt(hstmt, SQL_DROP) != SQL_SUCCESS)
+ DispAllErrors(henv, hdbc);
+ }
+
+ // Disconnect from the datasource
+ if (SQLDisconnect(hdbc) != SQL_SUCCESS)
+ DispAllErrors(henv, hdbc);
+
+ // Free the connection to the datasource
+ if (SQLFreeConnect(hdbc) != SQL_SUCCESS)
+ DispAllErrors(henv, hdbc);
+
+ // There should be zero Ctable objects still connected to this db object
+ wxASSERT(nTables == 0);
+
+#ifdef __WXDEBUG__
+ wxTablesInUse *tiu;
+ wxList::compatibility_iterator pNode;
+ pNode = TablesInUse.GetFirst();
+ wxString s,s2;
+ while (pNode)
+ {
+ tiu = (wxTablesInUse *)pNode->GetData();
+ if (tiu->pDb == this)
+ {
+ s.Printf(wxT("(%-20s) tableID:[%6lu] pDb:[%p]"), tiu->tableName,tiu->tableID,tiu->pDb);
+ s2.Printf(wxT("Orphaned table found using pDb:[%p]"),this);
+ wxLogDebug(s.c_str(),s2.c_str());
+ }
+ pNode = pNode->GetNext();
+ }
+#endif
+
+ // Copy the error messages to a global variable
+ int i;
+ for (i = 0; i < DB_MAX_ERROR_HISTORY; i++)
+ wxStrcpy(DBerrorList[i], errorList[i]);
+
+ dbmsType = dbmsUNIDENTIFIED;
+ dbIsOpen = false;
+
+} // wxDb::Close()
+
+
+/********** wxDb::CommitTrans() **********/
+bool wxDb::CommitTrans(void)
+{
+ if (this)
+ {
+ // Commit the transaction
+ if (SQLTransact(henv, hdbc, SQL_COMMIT) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc));
+ }
+
+ // Completed successfully
+ return true;
+
+} // wxDb::CommitTrans()
+
+
+/********** wxDb::RollbackTrans() **********/
+bool wxDb::RollbackTrans(void)
+{
+ // Rollback the transaction
+ if (SQLTransact(henv, hdbc, SQL_ROLLBACK) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc));
+
+ // Completed successfully
+ return true;
+
+} // wxDb::RollbackTrans()
+
+
+/********** wxDb::DispAllErrors() **********/
+bool wxDb::DispAllErrors(HENV aHenv, HDBC aHdbc, HSTMT aHstmt)
+/*
+ * This function is called internally whenever an error condition prevents the user's
+ * request from being executed. This function will query the datasource as to the
+ * actual error(s) that just occurred on the previous request of the datasource.
+ *
+ * The function will retrieve each error condition from the datasource and
+ * Printf the codes/text values into a string which it then logs via logError().
+ * If in DBDEBUG_CONSOLE mode, the constructed string will be displayed in the console
+ * window and program execution will be paused until the user presses a key.
+ *
+ * This function always returns false, so that functions which call this function
+ * can have a line like "return (DispAllErrors(henv, hdbc));" to indicate the failure
+ * of the user's request, so that the calling code can then process the error message log.
+ */
+{
+ wxString odbcErrMsg;
+
+ while (SQLError(aHenv, aHdbc, aHstmt, (SQLTCHAR FAR *) sqlState, &nativeError, (SQLTCHAR FAR *) errorMsg, SQL_MAX_MESSAGE_LENGTH - 1, &cbErrorMsg) == SQL_SUCCESS)
+ {
+ odbcErrMsg.Printf(wxT("SQL State = %s\nNative Error Code = %li\nError Message = %s\n"), sqlState, nativeError, errorMsg);
+ logError(odbcErrMsg, sqlState);
+ if (!silent)
+ {
+#ifdef DBDEBUG_CONSOLE
+ // When run in console mode, use standard out to display errors.
+ cout << odbcErrMsg.c_str() << endl;
+ cout << wxT("Press any key to continue...") << endl;
+ getchar();
+#endif
+
+#ifdef __WXDEBUG__
+ wxLogDebug(odbcErrMsg,wxT("ODBC DEBUG MESSAGE from DispAllErrors()"));
+#endif
+ }
+ }
+
+ return false; // This function always returns false.
+
+} // wxDb::DispAllErrors()
+
+
+/********** wxDb::GetNextError() **********/
+bool wxDb::GetNextError(HENV aHenv, HDBC aHdbc, HSTMT aHstmt)
+{
+ if (SQLError(aHenv, aHdbc, aHstmt, (SQLTCHAR FAR *) sqlState, &nativeError, (SQLTCHAR FAR *) errorMsg, SQL_MAX_MESSAGE_LENGTH - 1, &cbErrorMsg) == SQL_SUCCESS)
+ return true;
+ else
+ return false;
+
+} // wxDb::GetNextError()
+
+
+/********** wxDb::DispNextError() **********/
+void wxDb::DispNextError(void)
+{
+ wxString odbcErrMsg;
+
+ odbcErrMsg.Printf(wxT("SQL State = %s\nNative Error Code = %li\nError Message = %s\n"), sqlState, nativeError, errorMsg);
+ logError(odbcErrMsg, sqlState);
+
+ if (silent)
+ return;
+
+#ifdef DBDEBUG_CONSOLE
+ // When run in console mode, use standard out to display errors.
+ cout << odbcErrMsg.c_str() << endl;
+ cout << wxT("Press any key to continue...") << endl;
+ getchar();
+#endif
+
+#ifdef __WXDEBUG__
+ wxLogDebug(odbcErrMsg,wxT("ODBC DEBUG MESSAGE"));
+#endif // __WXDEBUG__
+
+} // wxDb::DispNextError()
+
+
+/********** wxDb::logError() **********/
+void wxDb::logError(const wxString &errMsg, const wxString &SQLState)
+{
+ wxASSERT(errMsg.Length());
+
+ static int pLast = -1;
+ int dbStatus;
+
+ if (++pLast == DB_MAX_ERROR_HISTORY)
+ {
+ int i;
+ for (i = 0; i < DB_MAX_ERROR_HISTORY-1; i++)
+ wxStrcpy(errorList[i], errorList[i+1]);
+ pLast--;
+ }
+
+ wxStrncpy(errorList[pLast], errMsg, DB_MAX_ERROR_MSG_LEN);
+ errorList[pLast][DB_MAX_ERROR_MSG_LEN] = 0;
+
+ if (SQLState.Length())
+ if ((dbStatus = TranslateSqlState(SQLState)) != DB_ERR_FUNCTION_SEQUENCE_ERROR)
+ DB_STATUS = dbStatus;
+
+ // Add the errmsg to the sql log
+ WriteSqlLog(errMsg);
+
+} // wxDb::logError()
+
+
+/**********wxDb::TranslateSqlState() **********/
+int wxDb::TranslateSqlState(const wxString &SQLState)
+{
+ if (!wxStrcmp(SQLState, wxT("01000")))
+ return(DB_ERR_GENERAL_WARNING);
+ if (!wxStrcmp(SQLState, wxT("01002")))
+ return(DB_ERR_DISCONNECT_ERROR);
+ if (!wxStrcmp(SQLState, wxT("01004")))
+ return(DB_ERR_DATA_TRUNCATED);
+ if (!wxStrcmp(SQLState, wxT("01006")))
+ return(DB_ERR_PRIV_NOT_REVOKED);
+ if (!wxStrcmp(SQLState, wxT("01S00")))
+ return(DB_ERR_INVALID_CONN_STR_ATTR);
+ if (!wxStrcmp(SQLState, wxT("01S01")))
+ return(DB_ERR_ERROR_IN_ROW);
+ if (!wxStrcmp(SQLState, wxT("01S02")))
+ return(DB_ERR_OPTION_VALUE_CHANGED);
+ if (!wxStrcmp(SQLState, wxT("01S03")))
+ return(DB_ERR_NO_ROWS_UPD_OR_DEL);
+ if (!wxStrcmp(SQLState, wxT("01S04")))
+ return(DB_ERR_MULTI_ROWS_UPD_OR_DEL);
+ if (!wxStrcmp(SQLState, wxT("07001")))
+ return(DB_ERR_WRONG_NO_OF_PARAMS);
+ if (!wxStrcmp(SQLState, wxT("07006")))
+ return(DB_ERR_DATA_TYPE_ATTR_VIOL);
+ if (!wxStrcmp(SQLState, wxT("08001")))
+ return(DB_ERR_UNABLE_TO_CONNECT);
+ if (!wxStrcmp(SQLState, wxT("08002")))
+ return(DB_ERR_CONNECTION_IN_USE);
+ if (!wxStrcmp(SQLState, wxT("08003")))
+ return(DB_ERR_CONNECTION_NOT_OPEN);
+ if (!wxStrcmp(SQLState, wxT("08004")))
+ return(DB_ERR_REJECTED_CONNECTION);
+ if (!wxStrcmp(SQLState, wxT("08007")))
+ return(DB_ERR_CONN_FAIL_IN_TRANS);
+ if (!wxStrcmp(SQLState, wxT("08S01")))
+ return(DB_ERR_COMM_LINK_FAILURE);
+ if (!wxStrcmp(SQLState, wxT("21S01")))
+ return(DB_ERR_INSERT_VALUE_LIST_MISMATCH);
+ if (!wxStrcmp(SQLState, wxT("21S02")))
+ return(DB_ERR_DERIVED_TABLE_MISMATCH);
+ if (!wxStrcmp(SQLState, wxT("22001")))
+ return(DB_ERR_STRING_RIGHT_TRUNC);
+ if (!wxStrcmp(SQLState, wxT("22003")))
+ return(DB_ERR_NUMERIC_VALUE_OUT_OF_RNG);
+ if (!wxStrcmp(SQLState, wxT("22005")))
+ return(DB_ERR_ERROR_IN_ASSIGNMENT);
+ if (!wxStrcmp(SQLState, wxT("22008")))
+ return(DB_ERR_DATETIME_FLD_OVERFLOW);
+ if (!wxStrcmp(SQLState, wxT("22012")))
+ return(DB_ERR_DIVIDE_BY_ZERO);
+ if (!wxStrcmp(SQLState, wxT("22026")))
+ return(DB_ERR_STR_DATA_LENGTH_MISMATCH);
+ if (!wxStrcmp(SQLState, wxT("23000")))
+ return(DB_ERR_INTEGRITY_CONSTRAINT_VIOL);
+ if (!wxStrcmp(SQLState, wxT("24000")))
+ return(DB_ERR_INVALID_CURSOR_STATE);
+ if (!wxStrcmp(SQLState, wxT("25000")))
+ return(DB_ERR_INVALID_TRANS_STATE);
+ if (!wxStrcmp(SQLState, wxT("28000")))
+ return(DB_ERR_INVALID_AUTH_SPEC);
+ if (!wxStrcmp(SQLState, wxT("34000")))
+ return(DB_ERR_INVALID_CURSOR_NAME);
+ if (!wxStrcmp(SQLState, wxT("37000")))
+ return(DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL);
+ if (!wxStrcmp(SQLState, wxT("3C000")))
+ return(DB_ERR_DUPLICATE_CURSOR_NAME);
+ if (!wxStrcmp(SQLState, wxT("40001")))
+ return(DB_ERR_SERIALIZATION_FAILURE);
+ if (!wxStrcmp(SQLState, wxT("42000")))
+ return(DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2);
+ if (!wxStrcmp(SQLState, wxT("70100")))
+ return(DB_ERR_OPERATION_ABORTED);
+ if (!wxStrcmp(SQLState, wxT("IM001")))
+ return(DB_ERR_UNSUPPORTED_FUNCTION);
+ if (!wxStrcmp(SQLState, wxT("IM002")))
+ return(DB_ERR_NO_DATA_SOURCE);
+ if (!wxStrcmp(SQLState, wxT("IM003")))
+ return(DB_ERR_DRIVER_LOAD_ERROR);
+ if (!wxStrcmp(SQLState, wxT("IM004")))
+ return(DB_ERR_SQLALLOCENV_FAILED);
+ if (!wxStrcmp(SQLState, wxT("IM005")))
+ return(DB_ERR_SQLALLOCCONNECT_FAILED);
+ if (!wxStrcmp(SQLState, wxT("IM006")))
+ return(DB_ERR_SQLSETCONNECTOPTION_FAILED);
+ if (!wxStrcmp(SQLState, wxT("IM007")))
+ return(DB_ERR_NO_DATA_SOURCE_DLG_PROHIB);
+ if (!wxStrcmp(SQLState, wxT("IM008")))
+ return(DB_ERR_DIALOG_FAILED);
+ if (!wxStrcmp(SQLState, wxT("IM009")))
+ return(DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL);
+ if (!wxStrcmp(SQLState, wxT("IM010")))
+ return(DB_ERR_DATA_SOURCE_NAME_TOO_LONG);
+ if (!wxStrcmp(SQLState, wxT("IM011")))
+ return(DB_ERR_DRIVER_NAME_TOO_LONG);
+ if (!wxStrcmp(SQLState, wxT("IM012")))
+ return(DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR);
+ if (!wxStrcmp(SQLState, wxT("IM013")))
+ return(DB_ERR_TRACE_FILE_ERROR);
+ if (!wxStrcmp(SQLState, wxT("S0001")))
+ return(DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS);
+ if (!wxStrcmp(SQLState, wxT("S0002")))
+ return(DB_ERR_TABLE_NOT_FOUND);
+ if (!wxStrcmp(SQLState, wxT("S0011")))
+ return(DB_ERR_INDEX_ALREADY_EXISTS);
+ if (!wxStrcmp(SQLState, wxT("S0012")))
+ return(DB_ERR_INDEX_NOT_FOUND);
+ if (!wxStrcmp(SQLState, wxT("S0021")))
+ return(DB_ERR_COLUMN_ALREADY_EXISTS);
+ if (!wxStrcmp(SQLState, wxT("S0022")))
+ return(DB_ERR_COLUMN_NOT_FOUND);
+ if (!wxStrcmp(SQLState, wxT("S0023")))
+ return(DB_ERR_NO_DEFAULT_FOR_COLUMN);
+ if (!wxStrcmp(SQLState, wxT("S1000")))
+ return(DB_ERR_GENERAL_ERROR);
+ if (!wxStrcmp(SQLState, wxT("S1001")))
+ return(DB_ERR_MEMORY_ALLOCATION_FAILURE);
+ if (!wxStrcmp(SQLState, wxT("S1002")))
+ return(DB_ERR_INVALID_COLUMN_NUMBER);
+ if (!wxStrcmp(SQLState, wxT("S1003")))
+ return(DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1004")))
+ return(DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1008")))
+ return(DB_ERR_OPERATION_CANCELLED);
+ if (!wxStrcmp(SQLState, wxT("S1009")))
+ return(DB_ERR_INVALID_ARGUMENT_VALUE);
+ if (!wxStrcmp(SQLState, wxT("S1010")))
+ return(DB_ERR_FUNCTION_SEQUENCE_ERROR);
+ if (!wxStrcmp(SQLState, wxT("S1011")))
+ return(DB_ERR_OPERATION_INVALID_AT_THIS_TIME);
+ if (!wxStrcmp(SQLState, wxT("S1012")))
+ return(DB_ERR_INVALID_TRANS_OPERATION_CODE);
+ if (!wxStrcmp(SQLState, wxT("S1015")))
+ return(DB_ERR_NO_CURSOR_NAME_AVAIL);
+ if (!wxStrcmp(SQLState, wxT("S1090")))
+ return(DB_ERR_INVALID_STR_OR_BUF_LEN);
+ if (!wxStrcmp(SQLState, wxT("S1091")))
+ return(DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1092")))
+ return(DB_ERR_OPTION_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1093")))
+ return(DB_ERR_INVALID_PARAM_NO);
+ if (!wxStrcmp(SQLState, wxT("S1094")))
+ return(DB_ERR_INVALID_SCALE_VALUE);
+ if (!wxStrcmp(SQLState, wxT("S1095")))
+ return(DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1096")))
+ return(DB_ERR_INF_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1097")))
+ return(DB_ERR_COLUMN_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1098")))
+ return(DB_ERR_SCOPE_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1099")))
+ return(DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1100")))
+ return(DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1101")))
+ return(DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1103")))
+ return(DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1104")))
+ return(DB_ERR_INVALID_PRECISION_VALUE);
+ if (!wxStrcmp(SQLState, wxT("S1105")))
+ return(DB_ERR_INVALID_PARAM_TYPE);
+ if (!wxStrcmp(SQLState, wxT("S1106")))
+ return(DB_ERR_FETCH_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1107")))
+ return(DB_ERR_ROW_VALUE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1108")))
+ return(DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, wxT("S1109")))
+ return(DB_ERR_INVALID_CURSOR_POSITION);
+ if (!wxStrcmp(SQLState, wxT("S1110")))
+ return(DB_ERR_INVALID_DRIVER_COMPLETION);
+ if (!wxStrcmp(SQLState, wxT("S1111")))
+ return(DB_ERR_INVALID_BOOKMARK_VALUE);
+ if (!wxStrcmp(SQLState, wxT("S1C00")))
+ return(DB_ERR_DRIVER_NOT_CAPABLE);
+ if (!wxStrcmp(SQLState, wxT("S1T00")))
+ return(DB_ERR_TIMEOUT_EXPIRED);
+
+ // No match
+ return(0);
+
+} // wxDb::TranslateSqlState()
+
+
+/********** wxDb::Grant() **********/
+bool wxDb::Grant(int privileges, const wxString &tableName, const wxString &userList)
+{
+ wxString sqlStmt;
+
+ // Build the grant statement
+ sqlStmt = wxT("GRANT ");
+ if (privileges == DB_GRANT_ALL)
+ sqlStmt += wxT("ALL");
+ else
+ {
+ int c = 0;
+ if (privileges & DB_GRANT_SELECT)
+ {
+ sqlStmt += wxT("SELECT");
+ c++;
+ }
+ if (privileges & DB_GRANT_INSERT)
+ {
+ if (c++)
+ sqlStmt += wxT(", ");
+ sqlStmt += wxT("INSERT");
+ }
+ if (privileges & DB_GRANT_UPDATE)
+ {
+ if (c++)
+ sqlStmt += wxT(", ");
+ sqlStmt += wxT("UPDATE");
+ }
+ if (privileges & DB_GRANT_DELETE)
+ {
+ if (c++)
+ sqlStmt += wxT(", ");
+ sqlStmt += wxT("DELETE");
+ }
+ }
+
+ sqlStmt += wxT(" ON ");
+ sqlStmt += SQLTableName(tableName);
+ sqlStmt += wxT(" TO ");
+ sqlStmt += userList;
+
+#ifdef DBDEBUG_CONSOLE
+ cout << endl << sqlStmt.c_str() << endl;
+#endif
+
+ WriteSqlLog(sqlStmt);
+
+ return(ExecSql(sqlStmt));
+
+} // wxDb::Grant()
+
+
+/********** wxDb::CreateView() **********/
+bool wxDb::CreateView(const wxString &viewName, const wxString &colList,
+ const wxString &pSqlStmt, bool attemptDrop)
+{
+ wxString sqlStmt;
+
+ // Drop the view first
+ if (attemptDrop && !DropView(viewName))
+ return false;
+
+ // Build the create view statement
+ sqlStmt = wxT("CREATE VIEW ");
+ sqlStmt += viewName;
+
+ if (colList.Length())
+ {
+ sqlStmt += wxT(" (");
+ sqlStmt += colList;
+ sqlStmt += wxT(")");
+ }
+
+ sqlStmt += wxT(" AS ");
+ sqlStmt += pSqlStmt;
+
+ WriteSqlLog(sqlStmt);
+
+#ifdef DBDEBUG_CONSOLE
+ cout << sqlStmt.c_str() << endl;
+#endif
+
+ return(ExecSql(sqlStmt));
+
+} // wxDb::CreateView()
+
+
+/********** wxDb::DropView() **********/
+bool wxDb::DropView(const wxString &viewName)
+{
+/*
+ * NOTE: This function returns true if the View does not exist, but
+ * only for identified databases. Code will need to be added
+ * below for any other databases when those databases are defined
+ * to handle this situation consistently
+ */
+ wxString sqlStmt;
+
+ sqlStmt.Printf(wxT("DROP VIEW %s"), viewName.c_str());
+
+ WriteSqlLog(sqlStmt);
+
+#ifdef DBDEBUG_CONSOLE
+ cout << endl << sqlStmt.c_str() << endl;
+#endif
+
+ if (SQLExecDirect(hstmt, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
+ {
+ // Check for "Base table not found" error and ignore
+ GetNextError(henv, hdbc, hstmt);
+ if (wxStrcmp(sqlState,wxT("S0002"))) // "Base table not found"
+ {
+ // Check for product specific error codes
+ if (!((Dbms() == dbmsSYBASE_ASA && !wxStrcmp(sqlState,wxT("42000"))))) // 5.x (and lower?)
+ {
+ DispNextError();
+ DispAllErrors(henv, hdbc, hstmt);
+ RollbackTrans();
+ return false;
+ }
+ }
+ }
+
+ // Commit the transaction
+ if (!CommitTrans())
+ return false;
+
+ return true;
+
+} // wxDb::DropView()
+
+
+/********** wxDb::ExecSql() **********/
+bool wxDb::ExecSql(const wxString &pSqlStmt)
+{
+ RETCODE retcode;
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+
+ retcode = SQLExecDirect(hstmt, (SQLTCHAR FAR *) pSqlStmt.c_str(), SQL_NTS);
+ if (retcode == SQL_SUCCESS ||
+ (Dbms() == dbmsDB2 && (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_NO_DATA_FOUND)))
+ {
+ return true;
+ }
+ else
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ return false;
+ }
+
+} // wxDb::ExecSql()
+
+
+/********** wxDb::ExecSql() with column info **********/
+bool wxDb::ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcols)
+{
+ //execute the statement first
+ if (!ExecSql(pSqlStmt))
+ return false;
+
+ SWORD noCols;
+ if (SQLNumResultCols(hstmt, &noCols) != SQL_SUCCESS)
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ return false;
+ }
+
+ if (noCols == 0)
+ return false;
+ else
+ numcols = noCols;
+
+ // Get column information
+ short colNum;
+ wxChar name[DB_MAX_COLUMN_NAME_LEN+1];
+ SWORD Sword;
+ SQLLEN Sqllen;
+ wxDbColInf* pColInf = new wxDbColInf[noCols];
+
+ // Fill in column information (name, datatype)
+ for (colNum = 0; colNum < noCols; colNum++)
+ {
+ if (SQLColAttributes(hstmt, (UWORD)(colNum+1), SQL_COLUMN_NAME,
+ name, sizeof(name),
+ &Sword, &Sqllen) != SQL_SUCCESS)
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ delete[] pColInf;
+ return false;
+ }
+
+ wxStrncpy(pColInf[colNum].colName, name, DB_MAX_COLUMN_NAME_LEN);
+ pColInf[colNum].colName[DB_MAX_COLUMN_NAME_LEN] = 0; // Prevent buffer overrun
+
+ if (SQLColAttributes(hstmt, (UWORD)(colNum+1), SQL_COLUMN_TYPE,
+ NULL, 0, &Sword, &Sqllen) != SQL_SUCCESS)
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ delete[] pColInf;
+ return false;
+ }
+
+ switch (Sqllen)
+ {
+#if wxUSE_UNICODE
+ #if defined(SQL_WCHAR)
+ case SQL_WCHAR:
+ #endif
+ #if defined(SQL_WVARCHAR)
+ case SQL_WVARCHAR:
+ #endif
+#endif
+ case SQL_VARCHAR:
+ case SQL_CHAR:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_VARCHAR;
+ break;
+ case SQL_TINYINT:
+ case SQL_SMALLINT:
+ case SQL_INTEGER:
+ case SQL_BIT:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_INTEGER;
+ break;
+ case SQL_DOUBLE:
+ case SQL_DECIMAL:
+ case SQL_NUMERIC:
+ case SQL_FLOAT:
+ case SQL_REAL:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_FLOAT;
+ break;
+ case SQL_DATE:
+ case SQL_TIMESTAMP:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_DATE;
+ break;
+ case SQL_BINARY:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_BLOB;
+ break;
+#ifdef __WXDEBUG__
+ default:
+ wxString errMsg;
+ errMsg.Printf(wxT("SQL Data type %ld currently not supported by wxWidgets"), (long)Sqllen);
+ wxLogDebug(errMsg,wxT("ODBC DEBUG MESSAGE"));
+#endif
+ }
+ }
+
+ *columns = pColInf;
+ return true;
+} // wxDb::ExecSql()
+
+/********** wxDb::GetNext() **********/
+bool wxDb::GetNext(void)
+{
+ if (SQLFetch(hstmt) == SQL_SUCCESS)
+ return true;
+ else
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ return false;
+ }
+
+} // wxDb::GetNext()
+
+
+/********** wxDb::GetData() **********/
+bool wxDb::GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SQLLEN FAR *cbReturned)
+{
+ wxASSERT(pData);
+ wxASSERT(cbReturned);
+
+ long bufferSize = maxLen;
+
+ if (cType == SQL_C_WXCHAR)
+ bufferSize = maxLen * sizeof(wxChar);
+
+ if (SQLGetData(hstmt, colNo, cType, pData, bufferSize, cbReturned) == SQL_SUCCESS)
+ return true;
+ else
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ return false;
+ }
+
+} // wxDb::GetData()
+
+
+/********** wxDb::GetKeyFields() **********/
+int wxDb::GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCols)
+{
+ wxChar szPkTable[DB_MAX_TABLE_NAME_LEN+1]; /* Primary key table name */
+ wxChar szFkTable[DB_MAX_TABLE_NAME_LEN+1]; /* Foreign key table name */
+ SWORD iKeySeq;
+ wxChar szPkCol[DB_MAX_COLUMN_NAME_LEN+1]; /* Primary key column */
+ wxChar szFkCol[DB_MAX_COLUMN_NAME_LEN+1]; /* Foreign key column */
+ SQLRETURN retcode;
+ SQLLEN cb;
+ SWORD i;
+ wxString tempStr;
+ /*
+ * -----------------------------------------------------------------------
+ * -- 19991224 : mj10777 : Create ------
+ * -- : Three things are done and stored here : ------
+ * -- : 1) which Column(s) is/are Primary Key(s) ------
+ * -- : 2) which tables use this Key as a Foreign Key ------
+ * -- : 3) which columns are Foreign Key and the name ------
+ * -- : of the Table where the Key is the Primary Key -----
+ * -- : Called from GetColumns(const wxString &tableName, ------
+ * -- int *numCols,const wxChar *userID ) ------
+ * -----------------------------------------------------------------------
+ */
+
+ /*---------------------------------------------------------------------*/
+ /* Get the names of the columns in the primary key. */
+ /*---------------------------------------------------------------------*/
+ retcode = SQLPrimaryKeys(hstmt,
+ NULL, 0, /* Catalog name */
+ NULL, 0, /* Schema name */
+ (SQLTCHAR FAR *) tableName.c_str(), SQL_NTS); /* Table name */
+
+ /*---------------------------------------------------------------------*/
+ /* Fetch and display the result set. This will be a list of the */
+ /* columns in the primary key of the tableName table. */
+ /*---------------------------------------------------------------------*/
+ while ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO))
+ {
+ retcode = SQLFetch(hstmt);
+ if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
+ {
+ GetData( 4, SQL_C_WXCHAR, szPkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb);