- // Mark database as open
- dbIsOpen = TRUE;
-
- // Allocate a statement handle for the database connection
- if (SQLAllocStmt(hdbc, &hstmt) != SQL_SUCCESS)
- return(DispAllErrors(henv, hdbc));
-
- // Set Connection Options
- if (! setConnectionOptions())
- return(FALSE);
-
- // Query the data source for inf. about itself
- if (! getDbInfo())
- return(FALSE);
-
- // Query the data source regarding data type information
-
- //
- // The way I determined which SQL data types to use was by calling SQLGetInfo
- // for all of the possible SQL data types to see which ones were supported. If
- // a type is not supported, the SQLFetch() that's called from getDataTypeInfo()
- // fails with SQL_NO_DATA_FOUND. This is ugly because I'm sure the three SQL data
- // types I've selected below will not alway's be what we want. These are just
- // what happened to work against an Oracle 7/Intersolv combination. The following is
- // a complete list of the results I got back against the Oracle 7 database:
- //
- // SQL_BIGINT SQL_NO_DATA_FOUND
- // SQL_BINARY SQL_NO_DATA_FOUND
- // SQL_BIT SQL_NO_DATA_FOUND
- // SQL_CHAR type name = 'CHAR', Precision = 255
- // SQL_DATE SQL_NO_DATA_FOUND
- // SQL_DECIMAL type name = 'NUMBER', Precision = 38
- // SQL_DOUBLE type name = 'NUMBER', Precision = 15
- // SQL_FLOAT SQL_NO_DATA_FOUND
- // SQL_INTEGER SQL_NO_DATA_FOUND
- // SQL_LONGVARBINARY type name = 'LONG RAW', Precision = 2 billion
- // SQL_LONGVARCHAR type name = 'LONG', Precision = 2 billion
- // SQL_NUMERIC SQL_NO_DATA_FOUND
- // SQL_REAL SQL_NO_DATA_FOUND
- // SQL_SMALLINT SQL_NO_DATA_FOUND
- // SQL_TIME SQL_NO_DATA_FOUND
- // SQL_TIMESTAMP type name = 'DATE', Precision = 19
- // SQL_VARBINARY type name = 'RAW', Precision = 255
- // SQL_VARCHAR type name = 'VARCHAR2', Precision = 2000
- // =====================================================================
- // Results from a Microsoft Access 7.0 db, using a driver from Microsoft
- //
- // SQL_VARCHAR type name = 'TEXT', Precision = 255
- // SQL_TIMESTAMP type name = 'DATETIME'
- // SQL_DECIMAL SQL_NO_DATA_FOUND
- // SQL_NUMERIC type name = 'CURRENCY', Precision = 19
- // SQL_FLOAT SQL_NO_DATA_FOUND
- // SQL_REAL type name = 'SINGLE', Precision = 7
- // SQL_DOUBLE type name = 'DOUBLE', Precision = 15
- // SQL_INTEGER type name = 'LONG', Precision = 10
-
- // VARCHAR = Variable length character string
- if (! getDataTypeInfo(SQL_VARCHAR, typeInfVarchar))
- if (! getDataTypeInfo(SQL_CHAR, typeInfVarchar))
- return(FALSE);
- else
- typeInfVarchar.FsqlType = SQL_CHAR;
- else
- typeInfVarchar.FsqlType = SQL_VARCHAR;
-
- // Float
- if (! getDataTypeInfo(SQL_DOUBLE, typeInfFloat))
- if (! getDataTypeInfo(SQL_REAL, typeInfFloat))
- if (! getDataTypeInfo(SQL_FLOAT, typeInfFloat))
- if (! getDataTypeInfo(SQL_DECIMAL, typeInfFloat))
- if (! getDataTypeInfo(SQL_NUMERIC, typeInfFloat))
- return(FALSE);
- else
- typeInfFloat.FsqlType = SQL_NUMERIC;
- else
- typeInfFloat.FsqlType = SQL_DECIMAL;
- else
- typeInfFloat.FsqlType = SQL_FLOAT;
- else
- typeInfFloat.FsqlType = SQL_REAL;
- else
- typeInfFloat.FsqlType = SQL_DOUBLE;
-
- // Integer
- if (! getDataTypeInfo(SQL_INTEGER, typeInfInteger))
- // If SQL_INTEGER is not supported, use the floating point
- // data type to store integers as well as floats
- if (! getDataTypeInfo(typeInfFloat.FsqlType, typeInfInteger))
- return(FALSE);
- else
- typeInfInteger.FsqlType = typeInfFloat.FsqlType;
- else
- typeInfInteger.FsqlType = SQL_INTEGER;
-
- // Date/Time
- if (Dbms() != dbmsDBASE)
+ // Mark database as open
+ dbIsOpen = TRUE;
+
+ // Allocate a statement handle for the database connection
+ if (SQLAllocStmt(hdbc, &hstmt) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc));
+
+ // Set Connection Options
+ if (! setConnectionOptions())
+ return(FALSE);
+
+ // Query the data source for inf. about itself
+ if (! getDbInfo())
+ return(FALSE);
+
+ // Query the data source regarding data type information
+
+ //
+ // The way I determined which SQL data types to use was by calling SQLGetInfo
+ // for all of the possible SQL data types to see which ones were supported. If
+ // a type is not supported, the SQLFetch() that's called from getDataTypeInfo()
+ // fails with SQL_NO_DATA_FOUND. This is ugly because I'm sure the three SQL data
+ // types I've selected below will not alway's be what we want. These are just
+ // what happened to work against an Oracle 7/Intersolv combination. The following is
+ // a complete list of the results I got back against the Oracle 7 database:
+ //
+ // SQL_BIGINT SQL_NO_DATA_FOUND
+ // SQL_BINARY SQL_NO_DATA_FOUND
+ // SQL_BIT SQL_NO_DATA_FOUND
+ // SQL_CHAR type name = 'CHAR', Precision = 255
+ // SQL_DATE SQL_NO_DATA_FOUND
+ // SQL_DECIMAL type name = 'NUMBER', Precision = 38
+ // SQL_DOUBLE type name = 'NUMBER', Precision = 15
+ // SQL_FLOAT SQL_NO_DATA_FOUND
+ // SQL_INTEGER SQL_NO_DATA_FOUND
+ // SQL_LONGVARBINARY type name = 'LONG RAW', Precision = 2 billion
+ // SQL_LONGVARCHAR type name = 'LONG', Precision = 2 billion
+ // SQL_NUMERIC SQL_NO_DATA_FOUND
+ // SQL_REAL SQL_NO_DATA_FOUND
+ // SQL_SMALLINT SQL_NO_DATA_FOUND
+ // SQL_TIME SQL_NO_DATA_FOUND
+ // SQL_TIMESTAMP type name = 'DATE', Precision = 19
+ // SQL_VARBINARY type name = 'RAW', Precision = 255
+ // SQL_VARCHAR type name = 'VARCHAR2', Precision = 2000
+ // =====================================================================
+ // Results from a Microsoft Access 7.0 db, using a driver from Microsoft
+ //
+ // SQL_VARCHAR type name = 'TEXT', Precision = 255
+ // SQL_TIMESTAMP type name = 'DATETIME'
+ // SQL_DECIMAL SQL_NO_DATA_FOUND
+ // SQL_NUMERIC type name = 'CURRENCY', Precision = 19
+ // SQL_FLOAT SQL_NO_DATA_FOUND
+ // SQL_REAL type name = 'SINGLE', Precision = 7
+ // SQL_DOUBLE type name = 'DOUBLE', Precision = 15
+ // SQL_INTEGER type name = 'LONG', Precision = 10
+
+ // VARCHAR = Variable length character string
+ if (! getDataTypeInfo(SQL_VARCHAR, typeInfVarchar))
+ if (! getDataTypeInfo(SQL_CHAR, typeInfVarchar))
+ return(FALSE);
+ else
+ typeInfVarchar.FsqlType = SQL_CHAR;
+ else
+ typeInfVarchar.FsqlType = SQL_VARCHAR;
+
+ // Float
+ if (! getDataTypeInfo(SQL_DOUBLE, typeInfFloat))
+ if (! getDataTypeInfo(SQL_REAL, typeInfFloat))
+ if (! getDataTypeInfo(SQL_FLOAT, typeInfFloat))
+ if (! getDataTypeInfo(SQL_DECIMAL, typeInfFloat))
+ if (! getDataTypeInfo(SQL_NUMERIC, typeInfFloat))
+ return(FALSE);
+ else
+ typeInfFloat.FsqlType = SQL_NUMERIC;
+ else
+ typeInfFloat.FsqlType = SQL_DECIMAL;
+ else
+ typeInfFloat.FsqlType = SQL_FLOAT;
+ else
+ typeInfFloat.FsqlType = SQL_REAL;
+ else
+ typeInfFloat.FsqlType = SQL_DOUBLE;
+
+ // Integer
+ if (! getDataTypeInfo(SQL_INTEGER, typeInfInteger))
+ // If SQL_INTEGER is not supported, use the floating point
+ // data type to store integers as well as floats
+ if (! getDataTypeInfo(typeInfFloat.FsqlType, typeInfInteger))
+ return(FALSE);
+ else
+ typeInfInteger.FsqlType = typeInfFloat.FsqlType;
+ else
+ typeInfInteger.FsqlType = SQL_INTEGER;
+
+ // Date/Time
+ if (Dbms() != dbmsDBASE)
- cout << ">>>>> DATA SOURCE INFORMATION <<<<<" << endl;
- cout << "SERVER Name: " << dbInf.serverName << endl;
- cout << "DBMS Name: " << dbInf.dbmsName << "; DBMS Version: " << dbInf.dbmsVer << endl;
- cout << "ODBC Version: " << dbInf.odbcVer << "; Driver Version: " << dbInf.driverVer << endl;
-
- cout << "API Conf. Level: ";
- switch(dbInf.apiConfLvl)
- {
- case SQL_OAC_NONE: cout << "None"; break;
- case SQL_OAC_LEVEL1: cout << "Level 1"; break;
- case SQL_OAC_LEVEL2: cout << "Level 2"; break;
- }
- cout << endl;
-
- cout << "SAG CLI Conf. Level: ";
- switch(dbInf.cliConfLvl)
- {
- case SQL_OSCC_NOT_COMPLIANT: cout << "Not Compliant"; break;
- case SQL_OSCC_COMPLIANT: cout << "Compliant"; break;
- }
- cout << endl;
-
- cout << "SQL Conf. Level: ";
- switch(dbInf.sqlConfLvl)
- {
- case SQL_OSC_MINIMUM: cout << "Minimum Grammer"; break;
- case SQL_OSC_CORE: cout << "Core Grammer"; break;
- case SQL_OSC_EXTENDED: cout << "Extended Grammer"; break;
- }
- cout << endl;
-
- cout << "Max. Connections: " << dbInf.maxConnections << endl;
- cout << "Outer Joins: " << dbInf.outerJoins << endl;
- cout << "Support for Procedures: " << dbInf.procedureSupport << endl;
-
- cout << "Cursor COMMIT Behavior: ";
- switch(dbInf.cursorCommitBehavior)
- {
- case SQL_CB_DELETE: cout << "Delete cursors"; break;
- case SQL_CB_CLOSE: cout << "Close cursors"; break;
- case SQL_CB_PRESERVE: cout << "Preserve cursors"; break;
- }
- cout << endl;
-
- cout << "Cursor ROLLBACK Behavior: ";
- switch(dbInf.cursorRollbackBehavior)
- {
- case SQL_CB_DELETE: cout << "Delete cursors"; break;
- case SQL_CB_CLOSE: cout << "Close cursors"; break;
- case SQL_CB_PRESERVE: cout << "Preserve cursors"; break;
- }
- cout << endl;
-
- cout << "Support NOT NULL clause: ";
- switch(dbInf.supportNotNullClause)
- {
- case SQL_NNC_NULL: cout << "No"; break;
- case SQL_NNC_NON_NULL: cout << "Yes"; break;
- }
- cout << endl;
-
- cout << "Support IEF (Ref. Integrity): " << dbInf.supportIEF << endl;
- cout << "Login Timeout: " << dbInf.loginTimeout << endl;
-
- cout << endl << endl << "more ..." << endl;
- getchar();
-
- cout << "Default Transaction Isolation: ";
- switch(dbInf.txnIsolation)
- {
- case SQL_TXN_READ_UNCOMMITTED: cout << "Read Uncommitted"; break;
- case SQL_TXN_READ_COMMITTED: cout << "Read Committed"; break;
- case SQL_TXN_REPEATABLE_READ: cout << "Repeatable Read"; break;
- case SQL_TXN_SERIALIZABLE: cout << "Serializable"; break;
+ cout << "***** DATA SOURCE INFORMATION *****" << endl;
+ cout << "SERVER Name: " << dbInf.serverName << endl;
+ cout << "DBMS Name: " << dbInf.dbmsName << "; DBMS Version: " << dbInf.dbmsVer << endl;
+ cout << "ODBC Version: " << dbInf.odbcVer << "; Driver Version: " << dbInf.driverVer << endl;
+
+ cout << "API Conf. Level: ";
+ switch(dbInf.apiConfLvl)
+ {
+ case SQL_OAC_NONE: cout << "None"; break;
+ case SQL_OAC_LEVEL1: cout << "Level 1"; break;
+ case SQL_OAC_LEVEL2: cout << "Level 2"; break;
+ }
+ cout << endl;
+
+ cout << "SAG CLI Conf. Level: ";
+ switch(dbInf.cliConfLvl)
+ {
+ case SQL_OSCC_NOT_COMPLIANT: cout << "Not Compliant"; break;
+ case SQL_OSCC_COMPLIANT: cout << "Compliant"; break;
+ }
+ cout << endl;
+
+ cout << "SQL Conf. Level: ";
+ switch(dbInf.sqlConfLvl)
+ {
+ case SQL_OSC_MINIMUM: cout << "Minimum Grammer"; break;
+ case SQL_OSC_CORE: cout << "Core Grammer"; break;
+ case SQL_OSC_EXTENDED: cout << "Extended Grammer"; break;
+ }
+ cout << endl;
+
+ cout << "Max. Connections: " << dbInf.maxConnections << endl;
+ cout << "Outer Joins: " << dbInf.outerJoins << endl;
+ cout << "Support for Procedures: " << dbInf.procedureSupport << endl;
+
+ cout << "Cursor COMMIT Behavior: ";
+ switch(dbInf.cursorCommitBehavior)
+ {
+ case SQL_CB_DELETE: cout << "Delete cursors"; break;
+ case SQL_CB_CLOSE: cout << "Close cursors"; break;
+ case SQL_CB_PRESERVE: cout << "Preserve cursors"; break;
+ }
+ cout << endl;
+
+ cout << "Cursor ROLLBACK Behavior: ";
+ switch(dbInf.cursorRollbackBehavior)
+ {
+ case SQL_CB_DELETE: cout << "Delete cursors"; break;
+ case SQL_CB_CLOSE: cout << "Close cursors"; break;
+ case SQL_CB_PRESERVE: cout << "Preserve cursors"; break;
+ }
+ cout << endl;
+
+ cout << "Support NOT NULL clause: ";
+ switch(dbInf.supportNotNullClause)
+ {
+ case SQL_NNC_NULL: cout << "No"; break;
+ case SQL_NNC_NON_NULL: cout << "Yes"; break;
+ }
+ cout << endl;
+
+ cout << "Support IEF (Ref. Integrity): " << dbInf.supportIEF << endl;
+ cout << "Login Timeout: " << dbInf.loginTimeout << endl;
+
+ cout << endl << endl << "more ..." << endl;
+ getchar();
+
+ cout << "Default Transaction Isolation: ";
+ switch(dbInf.txnIsolation)
+ {
+ case SQL_TXN_READ_UNCOMMITTED: cout << "Read Uncommitted"; break;
+ case SQL_TXN_READ_COMMITTED: cout << "Read Committed"; break;
+ case SQL_TXN_REPEATABLE_READ: cout << "Repeatable Read"; break;
+ case SQL_TXN_SERIALIZABLE: cout << "Serializable"; break;
- if (dbInf.fetchDirections & SQL_FD_FETCH_BOOKMARK)
- cout << "Bookmark";
- cout << endl;
-
- cout << "Lock Types Supported (SQLSetPos): ";
- if (dbInf.lockTypes & SQL_LCK_NO_CHANGE)
- cout << "No Change, ";
- if (dbInf.lockTypes & SQL_LCK_EXCLUSIVE)
- cout << "Exclusive, ";
- if (dbInf.lockTypes & SQL_LCK_UNLOCK)
- cout << "UnLock";
- cout << endl;
-
- cout << "Position Operations Supported (SQLSetPos): ";
- if (dbInf.posOperations & SQL_POS_POSITION)
- cout << "Position, ";
- if (dbInf.posOperations & SQL_POS_REFRESH)
- cout << "Refresh, ";
- if (dbInf.posOperations & SQL_POS_UPDATE)
- cout << "Upd, ";
- if (dbInf.posOperations & SQL_POS_DELETE)
- cout << "Del, ";
- if (dbInf.posOperations & SQL_POS_ADD)
- cout << "Add";
- cout << endl;
-
- cout << "Positioned Statements Supported: ";
- if (dbInf.posStmts & SQL_PS_POSITIONED_DELETE)
- cout << "Pos delete, ";
- if (dbInf.posStmts & SQL_PS_POSITIONED_UPDATE)
- cout << "Pos update, ";
- if (dbInf.posStmts & SQL_PS_SELECT_FOR_UPDATE)
- cout << "Select for update";
- cout << endl;
-
- cout << "Scroll Concurrency: ";
- if (dbInf.scrollConcurrency & SQL_SCCO_READ_ONLY)
- cout << "Read Only, ";
- if (dbInf.scrollConcurrency & SQL_SCCO_LOCK)
- cout << "Lock, ";
- if (dbInf.scrollConcurrency & SQL_SCCO_OPT_ROWVER)
- cout << "Opt. Rowver, ";
- if (dbInf.scrollConcurrency & SQL_SCCO_OPT_VALUES)
- cout << "Opt. Values";
- cout << endl;
-
- cout << "Scroll Options: ";
- if (dbInf.scrollOptions & SQL_SO_FORWARD_ONLY)
- cout << "Fwd Only, ";
- if (dbInf.scrollOptions & SQL_SO_STATIC)
- cout << "Static, ";
- if (dbInf.scrollOptions & SQL_SO_KEYSET_DRIVEN)
- cout << "Keyset Driven, ";
- if (dbInf.scrollOptions & SQL_SO_DYNAMIC)
- cout << "Dynamic, ";
- if (dbInf.scrollOptions & SQL_SO_MIXED)
- cout << "Mixed";
- cout << endl;
-
- cout << "Static Sensitivity: ";
- if (dbInf.staticSensitivity & SQL_SS_ADDITIONS)
- cout << "Additions, ";
- if (dbInf.staticSensitivity & SQL_SS_DELETIONS)
- cout << "Deletions, ";
- if (dbInf.staticSensitivity & SQL_SS_UPDATES)
- cout << "Updates";
- cout << endl;
-
- cout << "Transaction Capable?: ";
- switch(dbInf.txnCapable)
- {
- case SQL_TC_NONE: cout << "No"; break;
- case SQL_TC_DML: cout << "DML Only"; break;
- case SQL_TC_DDL_COMMIT: cout << "DDL Commit"; break;
- case SQL_TC_DDL_IGNORE: cout << "DDL Ignore"; break;
- case SQL_TC_ALL: cout << "DDL & DML"; break;
- }
- cout << endl;
-
- cout << endl;
+ if (dbInf.fetchDirections & SQL_FD_FETCH_BOOKMARK)
+ cout << "Bookmark";
+ cout << endl;
+
+ cout << "Lock Types Supported (SQLSetPos): ";
+ if (dbInf.lockTypes & SQL_LCK_NO_CHANGE)
+ cout << "No Change, ";
+ if (dbInf.lockTypes & SQL_LCK_EXCLUSIVE)
+ cout << "Exclusive, ";
+ if (dbInf.lockTypes & SQL_LCK_UNLOCK)
+ cout << "UnLock";
+ cout << endl;
+
+ cout << "Position Operations Supported (SQLSetPos): ";
+ if (dbInf.posOperations & SQL_POS_POSITION)
+ cout << "Position, ";
+ if (dbInf.posOperations & SQL_POS_REFRESH)
+ cout << "Refresh, ";
+ if (dbInf.posOperations & SQL_POS_UPDATE)
+ cout << "Upd, ";
+ if (dbInf.posOperations & SQL_POS_DELETE)
+ cout << "Del, ";
+ if (dbInf.posOperations & SQL_POS_ADD)
+ cout << "Add";
+ cout << endl;
+
+ cout << "Positioned Statements Supported: ";
+ if (dbInf.posStmts & SQL_PS_POSITIONED_DELETE)
+ cout << "Pos delete, ";
+ if (dbInf.posStmts & SQL_PS_POSITIONED_UPDATE)
+ cout << "Pos update, ";
+ if (dbInf.posStmts & SQL_PS_SELECT_FOR_UPDATE)
+ cout << "Select for update";
+ cout << endl;
+
+ cout << "Scroll Concurrency: ";
+ if (dbInf.scrollConcurrency & SQL_SCCO_READ_ONLY)
+ cout << "Read Only, ";
+ if (dbInf.scrollConcurrency & SQL_SCCO_LOCK)
+ cout << "Lock, ";
+ if (dbInf.scrollConcurrency & SQL_SCCO_OPT_ROWVER)
+ cout << "Opt. Rowver, ";
+ if (dbInf.scrollConcurrency & SQL_SCCO_OPT_VALUES)
+ cout << "Opt. Values";
+ cout << endl;
+
+ cout << "Scroll Options: ";
+ if (dbInf.scrollOptions & SQL_SO_FORWARD_ONLY)
+ cout << "Fwd Only, ";
+ if (dbInf.scrollOptions & SQL_SO_STATIC)
+ cout << "Static, ";
+ if (dbInf.scrollOptions & SQL_SO_KEYSET_DRIVEN)
+ cout << "Keyset Driven, ";
+ if (dbInf.scrollOptions & SQL_SO_DYNAMIC)
+ cout << "Dynamic, ";
+ if (dbInf.scrollOptions & SQL_SO_MIXED)
+ cout << "Mixed";
+ cout << endl;
+
+ cout << "Static Sensitivity: ";
+ if (dbInf.staticSensitivity & SQL_SS_ADDITIONS)
+ cout << "Additions, ";
+ if (dbInf.staticSensitivity & SQL_SS_DELETIONS)
+ cout << "Deletions, ";
+ if (dbInf.staticSensitivity & SQL_SS_UPDATES)
+ cout << "Updates";
+ cout << endl;
+
+ cout << "Transaction Capable?: ";
+ switch(dbInf.txnCapable)
+ {
+ case SQL_TC_NONE: cout << "No"; break;
+ case SQL_TC_DML: cout << "DML Only"; break;
+ case SQL_TC_DDL_COMMIT: cout << "DDL Commit"; break;
+ case SQL_TC_DDL_IGNORE: cout << "DDL Ignore"; break;
+ case SQL_TC_ALL: cout << "DDL & DML"; break;
+ }
+ cout << endl;
+
+ cout << endl;
- if (!wxStrcmp(SQLState, "01000"))
- return(DB_ERR_GENERAL_WARNING);
- if (!wxStrcmp(SQLState, "01002"))
- return(DB_ERR_DISCONNECT_ERROR);
- if (!wxStrcmp(SQLState, "01004"))
- return(DB_ERR_DATA_TRUNCATED);
- if (!wxStrcmp(SQLState, "01006"))
- return(DB_ERR_PRIV_NOT_REVOKED);
- if (!wxStrcmp(SQLState, "01S00"))
- return(DB_ERR_INVALID_CONN_STR_ATTR);
- if (!wxStrcmp(SQLState, "01S01"))
- return(DB_ERR_ERROR_IN_ROW);
- if (!wxStrcmp(SQLState, "01S02"))
- return(DB_ERR_OPTION_VALUE_CHANGED);
- if (!wxStrcmp(SQLState, "01S03"))
- return(DB_ERR_NO_ROWS_UPD_OR_DEL);
- if (!wxStrcmp(SQLState, "01S04"))
- return(DB_ERR_MULTI_ROWS_UPD_OR_DEL);
- if (!wxStrcmp(SQLState, "07001"))
- return(DB_ERR_WRONG_NO_OF_PARAMS);
- if (!wxStrcmp(SQLState, "07006"))
- return(DB_ERR_DATA_TYPE_ATTR_VIOL);
- if (!wxStrcmp(SQLState, "08001"))
- return(DB_ERR_UNABLE_TO_CONNECT);
- if (!wxStrcmp(SQLState, "08002"))
- return(DB_ERR_CONNECTION_IN_USE);
- if (!wxStrcmp(SQLState, "08003"))
- return(DB_ERR_CONNECTION_NOT_OPEN);
- if (!wxStrcmp(SQLState, "08004"))
- return(DB_ERR_REJECTED_CONNECTION);
- if (!wxStrcmp(SQLState, "08007"))
- return(DB_ERR_CONN_FAIL_IN_TRANS);
- if (!wxStrcmp(SQLState, "08S01"))
- return(DB_ERR_COMM_LINK_FAILURE);
- if (!wxStrcmp(SQLState, "21S01"))
- return(DB_ERR_INSERT_VALUE_LIST_MISMATCH);
- if (!wxStrcmp(SQLState, "21S02"))
- return(DB_ERR_DERIVED_TABLE_MISMATCH);
- if (!wxStrcmp(SQLState, "22001"))
- return(DB_ERR_STRING_RIGHT_TRUNC);
- if (!wxStrcmp(SQLState, "22003"))
- return(DB_ERR_NUMERIC_VALUE_OUT_OF_RNG);
- if (!wxStrcmp(SQLState, "22005"))
- return(DB_ERR_ERROR_IN_ASSIGNMENT);
- if (!wxStrcmp(SQLState, "22008"))
- return(DB_ERR_DATETIME_FLD_OVERFLOW);
- if (!wxStrcmp(SQLState, "22012"))
- return(DB_ERR_DIVIDE_BY_ZERO);
- if (!wxStrcmp(SQLState, "22026"))
- return(DB_ERR_STR_DATA_LENGTH_MISMATCH);
- if (!wxStrcmp(SQLState, "23000"))
- return(DB_ERR_INTEGRITY_CONSTRAINT_VIOL);
- if (!wxStrcmp(SQLState, "24000"))
- return(DB_ERR_INVALID_CURSOR_STATE);
- if (!wxStrcmp(SQLState, "25000"))
- return(DB_ERR_INVALID_TRANS_STATE);
- if (!wxStrcmp(SQLState, "28000"))
- return(DB_ERR_INVALID_AUTH_SPEC);
- if (!wxStrcmp(SQLState, "34000"))
- return(DB_ERR_INVALID_CURSOR_NAME);
- if (!wxStrcmp(SQLState, "37000"))
- return(DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL);
- if (!wxStrcmp(SQLState, "3C000"))
- return(DB_ERR_DUPLICATE_CURSOR_NAME);
- if (!wxStrcmp(SQLState, "40001"))
- return(DB_ERR_SERIALIZATION_FAILURE);
- if (!wxStrcmp(SQLState, "42000"))
- return(DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2);
- if (!wxStrcmp(SQLState, "70100"))
- return(DB_ERR_OPERATION_ABORTED);
- if (!wxStrcmp(SQLState, "IM001"))
- return(DB_ERR_UNSUPPORTED_FUNCTION);
- if (!wxStrcmp(SQLState, "IM002"))
- return(DB_ERR_NO_DATA_SOURCE);
- if (!wxStrcmp(SQLState, "IM003"))
- return(DB_ERR_DRIVER_LOAD_ERROR);
- if (!wxStrcmp(SQLState, "IM004"))
- return(DB_ERR_SQLALLOCENV_FAILED);
- if (!wxStrcmp(SQLState, "IM005"))
- return(DB_ERR_SQLALLOCCONNECT_FAILED);
- if (!wxStrcmp(SQLState, "IM006"))
- return(DB_ERR_SQLSETCONNECTOPTION_FAILED);
- if (!wxStrcmp(SQLState, "IM007"))
- return(DB_ERR_NO_DATA_SOURCE_DLG_PROHIB);
- if (!wxStrcmp(SQLState, "IM008"))
- return(DB_ERR_DIALOG_FAILED);
- if (!wxStrcmp(SQLState, "IM009"))
- return(DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL);
- if (!wxStrcmp(SQLState, "IM010"))
- return(DB_ERR_DATA_SOURCE_NAME_TOO_LONG);
- if (!wxStrcmp(SQLState, "IM011"))
- return(DB_ERR_DRIVER_NAME_TOO_LONG);
- if (!wxStrcmp(SQLState, "IM012"))
- return(DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR);
- if (!wxStrcmp(SQLState, "IM013"))
- return(DB_ERR_TRACE_FILE_ERROR);
- if (!wxStrcmp(SQLState, "S0001"))
- return(DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS);
- if (!wxStrcmp(SQLState, "S0002"))
- return(DB_ERR_TABLE_NOT_FOUND);
- if (!wxStrcmp(SQLState, "S0011"))
- return(DB_ERR_INDEX_ALREADY_EXISTS);
- if (!wxStrcmp(SQLState, "S0012"))
- return(DB_ERR_INDEX_NOT_FOUND);
- if (!wxStrcmp(SQLState, "S0021"))
- return(DB_ERR_COLUMN_ALREADY_EXISTS);
- if (!wxStrcmp(SQLState, "S0022"))
- return(DB_ERR_COLUMN_NOT_FOUND);
- if (!wxStrcmp(SQLState, "S0023"))
- return(DB_ERR_NO_DEFAULT_FOR_COLUMN);
- if (!wxStrcmp(SQLState, "S1000"))
- return(DB_ERR_GENERAL_ERROR);
- if (!wxStrcmp(SQLState, "S1001"))
- return(DB_ERR_MEMORY_ALLOCATION_FAILURE);
- if (!wxStrcmp(SQLState, "S1002"))
- return(DB_ERR_INVALID_COLUMN_NUMBER);
- if (!wxStrcmp(SQLState, "S1003"))
- return(DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1004"))
- return(DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1008"))
- return(DB_ERR_OPERATION_CANCELLED);
- if (!wxStrcmp(SQLState, "S1009"))
- return(DB_ERR_INVALID_ARGUMENT_VALUE);
- if (!wxStrcmp(SQLState, "S1010"))
- return(DB_ERR_FUNCTION_SEQUENCE_ERROR);
- if (!wxStrcmp(SQLState, "S1011"))
- return(DB_ERR_OPERATION_INVALID_AT_THIS_TIME);
- if (!wxStrcmp(SQLState, "S1012"))
- return(DB_ERR_INVALID_TRANS_OPERATION_CODE);
- if (!wxStrcmp(SQLState, "S1015"))
- return(DB_ERR_NO_CURSOR_NAME_AVAIL);
- if (!wxStrcmp(SQLState, "S1090"))
- return(DB_ERR_INVALID_STR_OR_BUF_LEN);
- if (!wxStrcmp(SQLState, "S1091"))
- return(DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1092"))
- return(DB_ERR_OPTION_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1093"))
- return(DB_ERR_INVALID_PARAM_NO);
- if (!wxStrcmp(SQLState, "S1094"))
- return(DB_ERR_INVALID_SCALE_VALUE);
- if (!wxStrcmp(SQLState, "S1095"))
- return(DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1096"))
- return(DB_ERR_INF_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1097"))
- return(DB_ERR_COLUMN_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1098"))
- return(DB_ERR_SCOPE_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1099"))
- return(DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1100"))
- return(DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1101"))
- return(DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1103"))
- return(DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1104"))
- return(DB_ERR_INVALID_PRECISION_VALUE);
- if (!wxStrcmp(SQLState, "S1105"))
- return(DB_ERR_INVALID_PARAM_TYPE);
- if (!wxStrcmp(SQLState, "S1106"))
- return(DB_ERR_FETCH_TYPE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1107"))
- return(DB_ERR_ROW_VALUE_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1108"))
- return(DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE);
- if (!wxStrcmp(SQLState, "S1109"))
- return(DB_ERR_INVALID_CURSOR_POSITION);
- if (!wxStrcmp(SQLState, "S1110"))
- return(DB_ERR_INVALID_DRIVER_COMPLETION);
- if (!wxStrcmp(SQLState, "S1111"))
- return(DB_ERR_INVALID_BOOKMARK_VALUE);
- if (!wxStrcmp(SQLState, "S1C00"))
- return(DB_ERR_DRIVER_NOT_CAPABLE);
- if (!wxStrcmp(SQLState, "S1T00"))
- return(DB_ERR_TIMEOUT_EXPIRED);
-
- // No match
- return(0);
+ if (!wxStrcmp(SQLState, "01000"))
+ return(DB_ERR_GENERAL_WARNING);
+ if (!wxStrcmp(SQLState, "01002"))
+ return(DB_ERR_DISCONNECT_ERROR);
+ if (!wxStrcmp(SQLState, "01004"))
+ return(DB_ERR_DATA_TRUNCATED);
+ if (!wxStrcmp(SQLState, "01006"))
+ return(DB_ERR_PRIV_NOT_REVOKED);
+ if (!wxStrcmp(SQLState, "01S00"))
+ return(DB_ERR_INVALID_CONN_STR_ATTR);
+ if (!wxStrcmp(SQLState, "01S01"))
+ return(DB_ERR_ERROR_IN_ROW);
+ if (!wxStrcmp(SQLState, "01S02"))
+ return(DB_ERR_OPTION_VALUE_CHANGED);
+ if (!wxStrcmp(SQLState, "01S03"))
+ return(DB_ERR_NO_ROWS_UPD_OR_DEL);
+ if (!wxStrcmp(SQLState, "01S04"))
+ return(DB_ERR_MULTI_ROWS_UPD_OR_DEL);
+ if (!wxStrcmp(SQLState, "07001"))
+ return(DB_ERR_WRONG_NO_OF_PARAMS);
+ if (!wxStrcmp(SQLState, "07006"))
+ return(DB_ERR_DATA_TYPE_ATTR_VIOL);
+ if (!wxStrcmp(SQLState, "08001"))
+ return(DB_ERR_UNABLE_TO_CONNECT);
+ if (!wxStrcmp(SQLState, "08002"))
+ return(DB_ERR_CONNECTION_IN_USE);
+ if (!wxStrcmp(SQLState, "08003"))
+ return(DB_ERR_CONNECTION_NOT_OPEN);
+ if (!wxStrcmp(SQLState, "08004"))
+ return(DB_ERR_REJECTED_CONNECTION);
+ if (!wxStrcmp(SQLState, "08007"))
+ return(DB_ERR_CONN_FAIL_IN_TRANS);
+ if (!wxStrcmp(SQLState, "08S01"))
+ return(DB_ERR_COMM_LINK_FAILURE);
+ if (!wxStrcmp(SQLState, "21S01"))
+ return(DB_ERR_INSERT_VALUE_LIST_MISMATCH);
+ if (!wxStrcmp(SQLState, "21S02"))
+ return(DB_ERR_DERIVED_TABLE_MISMATCH);
+ if (!wxStrcmp(SQLState, "22001"))
+ return(DB_ERR_STRING_RIGHT_TRUNC);
+ if (!wxStrcmp(SQLState, "22003"))
+ return(DB_ERR_NUMERIC_VALUE_OUT_OF_RNG);
+ if (!wxStrcmp(SQLState, "22005"))
+ return(DB_ERR_ERROR_IN_ASSIGNMENT);
+ if (!wxStrcmp(SQLState, "22008"))
+ return(DB_ERR_DATETIME_FLD_OVERFLOW);
+ if (!wxStrcmp(SQLState, "22012"))
+ return(DB_ERR_DIVIDE_BY_ZERO);
+ if (!wxStrcmp(SQLState, "22026"))
+ return(DB_ERR_STR_DATA_LENGTH_MISMATCH);
+ if (!wxStrcmp(SQLState, "23000"))
+ return(DB_ERR_INTEGRITY_CONSTRAINT_VIOL);
+ if (!wxStrcmp(SQLState, "24000"))
+ return(DB_ERR_INVALID_CURSOR_STATE);
+ if (!wxStrcmp(SQLState, "25000"))
+ return(DB_ERR_INVALID_TRANS_STATE);
+ if (!wxStrcmp(SQLState, "28000"))
+ return(DB_ERR_INVALID_AUTH_SPEC);
+ if (!wxStrcmp(SQLState, "34000"))
+ return(DB_ERR_INVALID_CURSOR_NAME);
+ if (!wxStrcmp(SQLState, "37000"))
+ return(DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL);
+ if (!wxStrcmp(SQLState, "3C000"))
+ return(DB_ERR_DUPLICATE_CURSOR_NAME);
+ if (!wxStrcmp(SQLState, "40001"))
+ return(DB_ERR_SERIALIZATION_FAILURE);
+ if (!wxStrcmp(SQLState, "42000"))
+ return(DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2);
+ if (!wxStrcmp(SQLState, "70100"))
+ return(DB_ERR_OPERATION_ABORTED);
+ if (!wxStrcmp(SQLState, "IM001"))
+ return(DB_ERR_UNSUPPORTED_FUNCTION);
+ if (!wxStrcmp(SQLState, "IM002"))
+ return(DB_ERR_NO_DATA_SOURCE);
+ if (!wxStrcmp(SQLState, "IM003"))
+ return(DB_ERR_DRIVER_LOAD_ERROR);
+ if (!wxStrcmp(SQLState, "IM004"))
+ return(DB_ERR_SQLALLOCENV_FAILED);
+ if (!wxStrcmp(SQLState, "IM005"))
+ return(DB_ERR_SQLALLOCCONNECT_FAILED);
+ if (!wxStrcmp(SQLState, "IM006"))
+ return(DB_ERR_SQLSETCONNECTOPTION_FAILED);
+ if (!wxStrcmp(SQLState, "IM007"))
+ return(DB_ERR_NO_DATA_SOURCE_DLG_PROHIB);
+ if (!wxStrcmp(SQLState, "IM008"))
+ return(DB_ERR_DIALOG_FAILED);
+ if (!wxStrcmp(SQLState, "IM009"))
+ return(DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL);
+ if (!wxStrcmp(SQLState, "IM010"))
+ return(DB_ERR_DATA_SOURCE_NAME_TOO_LONG);
+ if (!wxStrcmp(SQLState, "IM011"))
+ return(DB_ERR_DRIVER_NAME_TOO_LONG);
+ if (!wxStrcmp(SQLState, "IM012"))
+ return(DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR);
+ if (!wxStrcmp(SQLState, "IM013"))
+ return(DB_ERR_TRACE_FILE_ERROR);
+ if (!wxStrcmp(SQLState, "S0001"))
+ return(DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS);
+ if (!wxStrcmp(SQLState, "S0002"))
+ return(DB_ERR_TABLE_NOT_FOUND);
+ if (!wxStrcmp(SQLState, "S0011"))
+ return(DB_ERR_INDEX_ALREADY_EXISTS);
+ if (!wxStrcmp(SQLState, "S0012"))
+ return(DB_ERR_INDEX_NOT_FOUND);
+ if (!wxStrcmp(SQLState, "S0021"))
+ return(DB_ERR_COLUMN_ALREADY_EXISTS);
+ if (!wxStrcmp(SQLState, "S0022"))
+ return(DB_ERR_COLUMN_NOT_FOUND);
+ if (!wxStrcmp(SQLState, "S0023"))
+ return(DB_ERR_NO_DEFAULT_FOR_COLUMN);
+ if (!wxStrcmp(SQLState, "S1000"))
+ return(DB_ERR_GENERAL_ERROR);
+ if (!wxStrcmp(SQLState, "S1001"))
+ return(DB_ERR_MEMORY_ALLOCATION_FAILURE);
+ if (!wxStrcmp(SQLState, "S1002"))
+ return(DB_ERR_INVALID_COLUMN_NUMBER);
+ if (!wxStrcmp(SQLState, "S1003"))
+ return(DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1004"))
+ return(DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1008"))
+ return(DB_ERR_OPERATION_CANCELLED);
+ if (!wxStrcmp(SQLState, "S1009"))
+ return(DB_ERR_INVALID_ARGUMENT_VALUE);
+ if (!wxStrcmp(SQLState, "S1010"))
+ return(DB_ERR_FUNCTION_SEQUENCE_ERROR);
+ if (!wxStrcmp(SQLState, "S1011"))
+ return(DB_ERR_OPERATION_INVALID_AT_THIS_TIME);
+ if (!wxStrcmp(SQLState, "S1012"))
+ return(DB_ERR_INVALID_TRANS_OPERATION_CODE);
+ if (!wxStrcmp(SQLState, "S1015"))
+ return(DB_ERR_NO_CURSOR_NAME_AVAIL);
+ if (!wxStrcmp(SQLState, "S1090"))
+ return(DB_ERR_INVALID_STR_OR_BUF_LEN);
+ if (!wxStrcmp(SQLState, "S1091"))
+ return(DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1092"))
+ return(DB_ERR_OPTION_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1093"))
+ return(DB_ERR_INVALID_PARAM_NO);
+ if (!wxStrcmp(SQLState, "S1094"))
+ return(DB_ERR_INVALID_SCALE_VALUE);
+ if (!wxStrcmp(SQLState, "S1095"))
+ return(DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1096"))
+ return(DB_ERR_INF_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1097"))
+ return(DB_ERR_COLUMN_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1098"))
+ return(DB_ERR_SCOPE_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1099"))
+ return(DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1100"))
+ return(DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1101"))
+ return(DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1103"))
+ return(DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1104"))
+ return(DB_ERR_INVALID_PRECISION_VALUE);
+ if (!wxStrcmp(SQLState, "S1105"))
+ return(DB_ERR_INVALID_PARAM_TYPE);
+ if (!wxStrcmp(SQLState, "S1106"))
+ return(DB_ERR_FETCH_TYPE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1107"))
+ return(DB_ERR_ROW_VALUE_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1108"))
+ return(DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE);
+ if (!wxStrcmp(SQLState, "S1109"))
+ return(DB_ERR_INVALID_CURSOR_POSITION);
+ if (!wxStrcmp(SQLState, "S1110"))
+ return(DB_ERR_INVALID_DRIVER_COMPLETION);
+ if (!wxStrcmp(SQLState, "S1111"))
+ return(DB_ERR_INVALID_BOOKMARK_VALUE);
+ if (!wxStrcmp(SQLState, "S1C00"))
+ return(DB_ERR_DRIVER_NOT_CAPABLE);
+ if (!wxStrcmp(SQLState, "S1T00"))
+ return(DB_ERR_TIMEOUT_EXPIRED);
+
+ // No match
+ return(0);
- int noCols = 0;
- int colNo = 0;
- wxColInf *colInf = 0;
-
- RETCODE retcode;
- SDWORD cb;
-
- wxString UserID;
- wxString TableName;
-
- if (userID)
- {
- if (!wxStrlen(userID))
- UserID = uid;
- else
- UserID = userID;
- }
- else
- UserID = "";
-
- // dBase does not use user names, and some drivers fail if you try to pass one
- if (Dbms() == dbmsDBASE)
- UserID = "";
-
- // Oracle user names may only be in uppercase, so force
- // the name to uppercase
- if (Dbms() == dbmsORACLE)
- UserID = UserID.Upper();
-
- // Pass 1 - Determine how many columns there are.
- // Pass 2 - Allocate the wxColInf array and fill in
- // the array with the column information.
- int pass;
- for (pass = 1; pass <= 2; pass++)
- {
- if (pass == 2)
- {
- if (noCols == 0) // Probably a bogus table name(s)
- break;
- // Allocate n wxColInf objects to hold the column information
- colInf = new wxColInf[noCols+1];
- if (!colInf)
- break;
- // Mark the end of the array
- wxStrcpy(colInf[noCols].tableName, "");
- wxStrcpy(colInf[noCols].colName, "");
- colInf[noCols].sqlDataType = 0;
- }
- // Loop through each table name
- int tbl;
- for (tbl = 0; tableName[tbl]; tbl++)
- {
- TableName = tableName[tbl];
- // Oracle table names are uppercase only, so force
- // the name to uppercase just in case programmer forgot to do this
- if (Dbms() == dbmsORACLE)
- TableName = TableName.Upper();
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
-
- // MySQL and Access cannot accept a user name when looking up column names, so we
- // use the call below that leaves out the user name
- if (wxStrcmp(UserID.GetData(),"") &&
- Dbms() != dbmsMY_SQL &&
- Dbms() != dbmsACCESS)
- {
- retcode = SQLColumns(hstmt,
- NULL, 0, // All qualifiers
- (UCHAR *) UserID.GetData(), SQL_NTS, // Owner
- (UCHAR *) TableName.GetData(), SQL_NTS,
- NULL, 0); // All columns
- }
- else
- {
- retcode = SQLColumns(hstmt,
- NULL, 0, // All qualifiers
- NULL, 0, // Owner
- (UCHAR *) TableName.GetData(), SQL_NTS,
- NULL, 0); // All columns
- }
- if (retcode != SQL_SUCCESS)
- { // Error occured, abort
- DispAllErrors(henv, hdbc, hstmt);
- if (colInf)
- delete [] colInf;
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return(0);
- }
-
- while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
- {
- if (pass == 1) // First pass, just add up the number of columns
- noCols++;
- else // Pass 2; Fill in the array of structures
- {
- if (colNo < noCols) // Some extra error checking to prevent memory overwrites
- {
- // NOTE: Only the ODBC 1.x fields are retrieved
- GetData( 1, SQL_C_CHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
- GetData( 2, SQL_C_CHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
- GetData( 3, SQL_C_CHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
- GetData( 4, SQL_C_CHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
- GetData( 5, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].sqlDataType, 0, &cb);
- GetData( 6, SQL_C_CHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
- GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnSize, 0, &cb);
- GetData( 8, SQL_C_SLONG, (UCHAR*) &colInf[colNo].bufferLength, 0, &cb);
- GetData( 9, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].decimalDigits,0, &cb);
- GetData(10, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].numPrecRadix, 0, &cb);
- GetData(11, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].nullable, 0, &cb);
- GetData(12, SQL_C_CHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb);
-
- // Determine the wxDB data type that is used to represent the native data type of this data source
- colInf[colNo].dbDataType = 0;
- if (!wxStricmp(typeInfVarchar.TypeName,colInf[colNo].typeName))
- colInf[colNo].dbDataType = DB_DATA_TYPE_VARCHAR;
- else if (!wxStricmp(typeInfInteger.TypeName,colInf[colNo].typeName))
- colInf[colNo].dbDataType = DB_DATA_TYPE_INTEGER;
- else if (!wxStricmp(typeInfFloat.TypeName,colInf[colNo].typeName))
- colInf[colNo].dbDataType = DB_DATA_TYPE_FLOAT;
- else if (!wxStricmp(typeInfDate.TypeName,colInf[colNo].typeName))
- colInf[colNo].dbDataType = DB_DATA_TYPE_DATE;
-
- colNo++;
- }
- }
- }
- if (retcode != SQL_NO_DATA_FOUND)
- { // Error occured, abort
- DispAllErrors(henv, hdbc, hstmt);
- if (colInf)
- delete [] colInf;
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return(0);
- }
- }
- }
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return colInf;
+ int noCols = 0;
+ int colNo = 0;
+ wxColInf *colInf = 0;
+
+ RETCODE retcode;
+ SDWORD cb;
+
+ wxString UserID;
+ wxString TableName;
+
+ if (userID)
+ {
+ if (!wxStrlen(userID))
+ UserID = uid;
+ else
+ UserID = userID;
+ }
+ else
+ UserID = "";
+
+ // dBase does not use user names, and some drivers fail if you try to pass one
+ if (Dbms() == dbmsDBASE)
+ UserID = "";
+
+ // Oracle user names may only be in uppercase, so force
+ // the name to uppercase
+ if (Dbms() == dbmsORACLE)
+ UserID = UserID.Upper();
+
+ // Pass 1 - Determine how many columns there are.
+ // Pass 2 - Allocate the wxColInf array and fill in
+ // the array with the column information.
+ int pass;
+ for (pass = 1; pass <= 2; pass++)
+ {
+ if (pass == 2)
+ {
+ if (noCols == 0) // Probably a bogus table name(s)
+ break;
+ // Allocate n wxColInf objects to hold the column information
+ colInf = new wxColInf[noCols+1];
+ if (!colInf)
+ break;
+ // Mark the end of the array
+ wxStrcpy(colInf[noCols].tableName, "");
+ wxStrcpy(colInf[noCols].colName, "");
+ colInf[noCols].sqlDataType = 0;
+ }
+ // Loop through each table name
+ int tbl;
+ for (tbl = 0; tableName[tbl]; tbl++)
+ {
+ TableName = tableName[tbl];
+ // Oracle table names are uppercase only, so force
+ // the name to uppercase just in case programmer forgot to do this
+ if (Dbms() == dbmsORACLE)
+ TableName = TableName.Upper();
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+
+ // MySQL and Access cannot accept a user name when looking up column names, so we
+ // use the call below that leaves out the user name
+ if (wxStrcmp(UserID.GetData(),"") &&
+ Dbms() != dbmsMY_SQL &&
+ Dbms() != dbmsACCESS)
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ (UCHAR *) UserID.GetData(), SQL_NTS, // Owner
+ (UCHAR *) TableName.GetData(), SQL_NTS,
+ NULL, 0); // All columns
+ }
+ else
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ NULL, 0, // Owner
+ (UCHAR *) TableName.GetData(), SQL_NTS,
+ NULL, 0); // All columns
+ }
+ if (retcode != SQL_SUCCESS)
+ { // Error occured, abort
+ DispAllErrors(henv, hdbc, hstmt);
+ if (colInf)
+ delete [] colInf;
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return(0);
+ }
+
+ while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
+ {
+ if (pass == 1) // First pass, just add up the number of columns
+ noCols++;
+ else // Pass 2; Fill in the array of structures
+ {
+ if (colNo < noCols) // Some extra error checking to prevent memory overwrites
+ {
+ // NOTE: Only the ODBC 1.x fields are retrieved
+ GetData( 1, SQL_C_CHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
+ GetData( 2, SQL_C_CHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
+ GetData( 3, SQL_C_CHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
+ GetData( 4, SQL_C_CHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
+ GetData( 5, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].sqlDataType, 0, &cb);
+ GetData( 6, SQL_C_CHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
+ GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnSize, 0, &cb);
+ GetData( 8, SQL_C_SLONG, (UCHAR*) &colInf[colNo].bufferLength, 0, &cb);
+ GetData( 9, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].decimalDigits,0, &cb);
+ GetData(10, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].numPrecRadix, 0, &cb);
+ GetData(11, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].nullable, 0, &cb);
+ GetData(12, SQL_C_CHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb);
+
+ // Determine the wxDB data type that is used to represent the native data type of this data source
+ colInf[colNo].dbDataType = 0;
+ if (!wxStricmp(typeInfVarchar.TypeName,colInf[colNo].typeName))
+ {
+ if (colInf[colNo].columnSize < 1)
+ {
+ // IODBC does not return a correct columnSize, so we set
+ // columnSize = bufferLength if no column size was returned
+ colInf[colNo].columnSize = colInf[colNo].bufferLength;
+ }
+ colInf[colNo].dbDataType = DB_DATA_TYPE_VARCHAR;
+ }
+ else if (!wxStricmp(typeInfInteger.TypeName,colInf[colNo].typeName))
+ colInf[colNo].dbDataType = DB_DATA_TYPE_INTEGER;
+ else if (!wxStricmp(typeInfFloat.TypeName,colInf[colNo].typeName))
+ colInf[colNo].dbDataType = DB_DATA_TYPE_FLOAT;
+ else if (!wxStricmp(typeInfDate.TypeName,colInf[colNo].typeName))
+ colInf[colNo].dbDataType = DB_DATA_TYPE_DATE;
+
+ colNo++;
+ }
+ }
+ }
+ if (retcode != SQL_NO_DATA_FOUND)
+ { // Error occured, abort
+ DispAllErrors(henv, hdbc, hstmt);
+ if (colInf)
+ delete [] colInf;
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return(0);
+ }
+ }
+ }
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return colInf;
- int noCols = 0;
- int colNo = 0;
- wxColInf *colInf = 0;
-
- RETCODE retcode;
- SDWORD cb;
-
- wxString UserID;
- wxString TableName;
-
- if (userID)
- {
- if (!wxStrlen(userID))
- UserID = uid;
- else
- UserID = userID;
- }
- else
- UserID = "";
-
- // dBase does not use user names, and some drivers fail if you try to pass one
- if (Dbms() == dbmsDBASE)
- UserID = "";
-
- // Oracle user names may only be in uppercase, so force
- // the name to uppercase
- if (Dbms() == dbmsORACLE)
- UserID = UserID.Upper();
-
- // Pass 1 - Determine how many columns there are.
- // Pass 2 - Allocate the wxColInf array and fill in
- // the array with the column information.
- int pass;
- for (pass = 1; pass <= 2; pass++)
- {
- if (pass == 2)
- {
- if (noCols == 0) // Probably a bogus table name(s)
- break;
- // Allocate n wxColInf objects to hold the column information
- colInf = new wxColInf[noCols+1];
- if (!colInf)
- break;
- // Mark the end of the array
- wxStrcpy(colInf[noCols].tableName, "");
- wxStrcpy(colInf[noCols].colName, "");
- colInf[noCols].sqlDataType = 0;
- }
-
- TableName = tableName;
- // Oracle table names are uppercase only, so force
- // the name to uppercase just in case programmer forgot to do this
- if (Dbms() == dbmsORACLE)
- TableName = TableName.Upper();
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
-
- // MySQL and Access cannot accept a user name when looking up column names, so we
- // use the call below that leaves out the user name
- if (wxStrcmp(UserID.GetData(),"") &&
- Dbms() != dbmsMY_SQL &&
- Dbms() != dbmsACCESS)
- {
- retcode = SQLColumns(hstmt,
- NULL, 0, // All qualifiers
- (UCHAR *) UserID.GetData(), SQL_NTS, // Owner
- (UCHAR *) TableName.GetData(), SQL_NTS,
- NULL, 0); // All columns
- }
- else
- {
- retcode = SQLColumns(hstmt,
- NULL, 0, // All qualifiers
- NULL, 0, // Owner
- (UCHAR *) TableName.GetData(), SQL_NTS,
- NULL, 0); // All columns
- }
- if (retcode != SQL_SUCCESS)
- { // Error occured, abort
- DispAllErrors(henv, hdbc, hstmt);
- if (colInf)
- delete [] colInf;
- SQLFreeStmt(hstmt, SQL_CLOSE);
- if (numCols)
- *numCols = 0;
- return(0);
- }
-
- while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
- {
- if (pass == 1) // First pass, just add up the number of columns
- noCols++;
- else // Pass 2; Fill in the array of structures
- {
- if (colNo < noCols) // Some extra error checking to prevent memory overwrites
- {
- // NOTE: Only the ODBC 1.x fields are retrieved
- GetData( 1, SQL_C_CHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
- GetData( 2, SQL_C_CHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
- GetData( 3, SQL_C_CHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
- GetData( 4, SQL_C_CHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
- GetData( 5, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].sqlDataType, 0, &cb);
- GetData( 6, SQL_C_CHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
- GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnSize, 0, &cb);
+ int noCols = 0;
+ int colNo = 0;
+ wxColInf *colInf = 0;
+
+ RETCODE retcode;
+ SDWORD cb;
+
+ wxString UserID;
+ wxString TableName;
+
+ if (userID)
+ {
+ if (!wxStrlen(userID))
+ UserID = uid;
+ else
+ UserID = userID;
+ }
+ else
+ UserID = "";
+
+ // dBase does not use user names, and some drivers fail if you try to pass one
+ if (Dbms() == dbmsDBASE)
+ UserID = "";
+
+ // Oracle user names may only be in uppercase, so force
+ // the name to uppercase
+ if (Dbms() == dbmsORACLE)
+ UserID = UserID.Upper();
+
+ // Pass 1 - Determine how many columns there are.
+ // Pass 2 - Allocate the wxColInf array and fill in
+ // the array with the column information.
+ int pass;
+ for (pass = 1; pass <= 2; pass++)
+ {
+ if (pass == 2)
+ {
+ if (noCols == 0) // Probably a bogus table name(s)
+ break;
+ // Allocate n wxColInf objects to hold the column information
+ colInf = new wxColInf[noCols+1];
+ if (!colInf)
+ break;
+ // Mark the end of the array
+ wxStrcpy(colInf[noCols].tableName, "");
+ wxStrcpy(colInf[noCols].colName, "");
+ colInf[noCols].sqlDataType = 0;
+ }
+
+ TableName = tableName;
+ // Oracle table names are uppercase only, so force
+ // the name to uppercase just in case programmer forgot to do this
+ if (Dbms() == dbmsORACLE)
+ TableName = TableName.Upper();
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+
+ // MySQL and Access cannot accept a user name when looking up column names, so we
+ // use the call below that leaves out the user name
+ if (wxStrcmp(UserID.GetData(),"") &&
+ Dbms() != dbmsMY_SQL &&
+ Dbms() != dbmsACCESS)
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ (UCHAR *) UserID.GetData(), SQL_NTS, // Owner
+ (UCHAR *) TableName.GetData(), SQL_NTS,
+ NULL, 0); // All columns
+ }
+ else
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ NULL, 0, // Owner
+ (UCHAR *) TableName.GetData(), SQL_NTS,
+ NULL, 0); // All columns
+ }
+ if (retcode != SQL_SUCCESS)
+ { // Error occured, abort
+ DispAllErrors(henv, hdbc, hstmt);
+ if (colInf)
+ delete [] colInf;
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ if (numCols)
+ *numCols = 0;
+ return(0);
+ }
+
+ while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
+ {
+ if (pass == 1) // First pass, just add up the number of columns
+ noCols++;
+ else // Pass 2; Fill in the array of structures
+ {
+ if (colNo < noCols) // Some extra error checking to prevent memory overwrites
+ {
+ // NOTE: Only the ODBC 1.x fields are retrieved
+ GetData( 1, SQL_C_CHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
+ GetData( 2, SQL_C_CHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
+ GetData( 3, SQL_C_CHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
+ GetData( 4, SQL_C_CHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
+ GetData( 5, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].sqlDataType, 0, &cb);
+ GetData( 6, SQL_C_CHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
+ GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnSize, 0, &cb);
- int noCols = 0;
-
- RETCODE retcode;
-
- wxString UserID;
- wxString TableName;
-
- if (userID)
- {
- if (!wxStrlen(userID))
- UserID = uid;
- else
- UserID = userID;
- }
- else
- UserID = "";
-
- // dBase does not use user names, and some drivers fail if you try to pass one
- if (Dbms() == dbmsDBASE)
- UserID = "";
-
- // Oracle user names may only be in uppercase, so force
- // the name to uppercase
- if (Dbms() == dbmsORACLE)
- UserID = UserID.Upper();
-
- {
- // Loop through each table name
- {
- TableName = tableName;
- // Oracle table names are uppercase only, so force
- // the name to uppercase just in case programmer forgot to do this
- if (Dbms() == dbmsORACLE)
- TableName = TableName.Upper();
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
-
- // MySQL and Access cannot accept a user name when looking up column names, so we
- // use the call below that leaves out the user name
- if (wxStrcmp(UserID.GetData(),"") &&
- Dbms() != dbmsMY_SQL &&
- Dbms() != dbmsACCESS)
- {
- retcode = SQLColumns(hstmt,
- NULL, 0, // All qualifiers
- (UCHAR *) UserID.GetData(), SQL_NTS, // Owner
- (UCHAR *) TableName.GetData(), SQL_NTS,
- NULL, 0); // All columns
- }
- else
- {
- retcode = SQLColumns(hstmt,
- NULL, 0, // All qualifiers
- NULL, 0, // Owner
- (UCHAR *) TableName.GetData(), SQL_NTS,
- NULL, 0); // All columns
- }
- if (retcode != SQL_SUCCESS)
- { // Error occured, abort
- DispAllErrors(henv, hdbc, hstmt);
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return(-1);
- }
-
- // Count the columns
- while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
- noCols++;
-
- if (retcode != SQL_NO_DATA_FOUND)
- { // Error occured, abort
- DispAllErrors(henv, hdbc, hstmt);
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return(-1);
- }
- }
- }
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return noCols;
+ int noCols = 0;
+
+ RETCODE retcode;
+
+ wxString UserID;
+ wxString TableName;
+
+ if (userID)
+ {
+ if (!wxStrlen(userID))
+ UserID = uid;
+ else
+ UserID = userID;
+ }
+ else
+ UserID = "";
+
+ // dBase does not use user names, and some drivers fail if you try to pass one
+ if (Dbms() == dbmsDBASE)
+ UserID = "";
+
+ // Oracle user names may only be in uppercase, so force
+ // the name to uppercase
+ if (Dbms() == dbmsORACLE)
+ UserID = UserID.Upper();
+
+ {
+ // Loop through each table name
+ {
+ TableName = tableName;
+ // Oracle table names are uppercase only, so force
+ // the name to uppercase just in case programmer forgot to do this
+ if (Dbms() == dbmsORACLE)
+ TableName = TableName.Upper();
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+
+ // MySQL and Access cannot accept a user name when looking up column names, so we
+ // use the call below that leaves out the user name
+ if (wxStrcmp(UserID.GetData(),"") &&
+ Dbms() != dbmsMY_SQL &&
+ Dbms() != dbmsACCESS)
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ (UCHAR *) UserID.GetData(), SQL_NTS, // Owner
+ (UCHAR *) TableName.GetData(), SQL_NTS,
+ NULL, 0); // All columns
+ }
+ else
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ NULL, 0, // Owner
+ (UCHAR *) TableName.GetData(), SQL_NTS,
+ NULL, 0); // All columns
+ }
+ if (retcode != SQL_SUCCESS)
+ { // Error occured, abort
+ DispAllErrors(henv, hdbc, hstmt);
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return(-1);
+ }
+
+ // Count the columns
+ while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
+ noCols++;
+
+ if (retcode != SQL_NO_DATA_FOUND)
+ { // Error occured, abort
+ DispAllErrors(henv, hdbc, hstmt);
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return(-1);
+ }
+ }
+ }
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return noCols;
- wxDbInf *pDbInf = NULL; // Array of catalog entries
- int noTab = 0; // Counter while filling table entries
- int pass;
- RETCODE retcode;
- SDWORD cb;
- char tblNameSave[DB_MAX_TABLE_NAME_LEN+1];
-
- wxString UserID;
-
- if (userID)
- {
- if (!wxStrlen(userID))
- UserID = uid;
- else
- UserID = userID;
- }
- else
- UserID = "";
-
- // dBase does not use user names, and some drivers fail if you try to pass one
- if (Dbms() == dbmsDBASE)
- UserID = "";
-
- // Oracle user names may only be in uppercase, so force
- // the name to uppercase
- if (Dbms() == dbmsORACLE)
- UserID = UserID.Upper();
-
- //-------------------------------------------------------------
- pDbInf = new wxDbInf; // Create the Database Arrray
- pDbInf->catalog[0] = 0;
- pDbInf->schema[0] = 0;
- pDbInf->numTables = 0; // Counter for Tables
- pDbInf->pTableInf = NULL; // Array of Tables
- //-------------------------------------------------------------
- // Table Information
- // Pass 1 - Determine how many Tables there are.
- // Pass 2 - Create the Table array and fill it
- // - Create the Cols array = NULL
- //-------------------------------------------------------------
- for (pass = 1; pass <= 2; pass++)
- {
- SQLFreeStmt(hstmt, SQL_CLOSE); // Close if Open
- strcpy(tblNameSave,"");
-
- if (wxStrcmp(UserID.GetData(),"") &&
- Dbms() != dbmsMY_SQL &&
- Dbms() != dbmsACCESS)
- {
- retcode = SQLTables(hstmt,
- NULL, 0, // All qualifiers
- (UCHAR *) UserID.GetData(), SQL_NTS, // User specified
- NULL, 0, // All tables
- NULL, 0); // All columns
- }
- else
- {
- retcode = SQLTables(hstmt,
- NULL, 0, // All qualifiers
- NULL, 0, // User specified
- NULL, 0, // All tables
- NULL, 0); // All columns
- }
- if (retcode != SQL_SUCCESS)
- {
- DispAllErrors(henv, hdbc, hstmt);
- pDbInf = NULL;
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return pDbInf;
- }
-
- while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS) // Table Information
- {
- if (pass == 1) // First pass, just count the Tables
- {
- if (pDbInf->numTables == 0)
- {
- GetData( 1, SQL_C_CHAR, (UCHAR*) pDbInf->catalog, 128+1, &cb);
- GetData( 2, SQL_C_CHAR, (UCHAR*) pDbInf->schema, 128+1, &cb);
- }
- pDbInf->numTables++; // Counter for Tables
- } // if (pass == 1)
- if (pass == 2) // Create and fill the Table entries
- {
- if (pDbInf->pTableInf == NULL) // Has the Table Array been created
- { // no, then create the Array
- pDbInf->pTableInf = new wxTableInf[pDbInf->numTables];
- for (noTab=0;noTab<pDbInf->numTables;noTab++)
- {
- (pDbInf->pTableInf+noTab)->tableName[0] = 0;
- (pDbInf->pTableInf+noTab)->tableType[0] = 0;
- (pDbInf->pTableInf+noTab)->tableRemarks[0] = 0;
- (pDbInf->pTableInf+noTab)->numCols = 0;
- (pDbInf->pTableInf+noTab)->pColInf = NULL;
- }
- noTab = 0;
- } // if (pDbInf->pTableInf == NULL) // Has the Table Array been created
- GetData( 3, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
- GetData( 4, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableType, 30+1, &cb);
- GetData( 5, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableRemarks, 254+1, &cb);
- noTab++;
- } // if (pass == 2) We now know the amount of Tables
- } // while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
- } // for (pass = 1; pass <= 2; pass++)
- SQLFreeStmt(hstmt, SQL_CLOSE);
-
- // Query how many columns are in each table
- for (noTab=0;noTab<pDbInf->numTables;noTab++)
- {
- (pDbInf->pTableInf+noTab)->numCols = GetColumnCount((pDbInf->pTableInf+noTab)->tableName,UserID);
- }
- return pDbInf;
+ wxDbInf *pDbInf = NULL; // Array of catalog entries
+ int noTab = 0; // Counter while filling table entries
+ int pass;
+ RETCODE retcode;
+ SDWORD cb;
+// char tblNameSave[DB_MAX_TABLE_NAME_LEN+1];
+ wxString tblNameSave;
+
+ wxString UserID;
+
+ if (userID)
+ {
+ if (!wxStrlen(userID))
+ UserID = uid;
+ else
+ UserID = userID;
+ }
+ else
+ UserID = "";
+
+ // dBase does not use user names, and some drivers fail if you try to pass one
+ if (Dbms() == dbmsDBASE)
+ UserID = "";
+
+ // Oracle user names may only be in uppercase, so force
+ // the name to uppercase
+ if (Dbms() == dbmsORACLE)
+ UserID = UserID.Upper();
+
+ //-------------------------------------------------------------
+ pDbInf = new wxDbInf; // Create the Database Arrray
+ pDbInf->catalog[0] = 0;
+ pDbInf->schema[0] = 0;
+ pDbInf->numTables = 0; // Counter for Tables
+ pDbInf->pTableInf = NULL; // Array of Tables
+ //-------------------------------------------------------------
+ // Table Information
+ // Pass 1 - Determine how many Tables there are.
+ // Pass 2 - Create the Table array and fill it
+ // - Create the Cols array = NULL
+ //-------------------------------------------------------------
+ for (pass = 1; pass <= 2; pass++)
+ {
+ SQLFreeStmt(hstmt, SQL_CLOSE); // Close if Open
+ tblNameSave = "";
+
+ if (wxStrcmp(UserID.GetData(),"") &&
+ Dbms() != dbmsMY_SQL &&
+ Dbms() != dbmsACCESS)
+ {
+ retcode = SQLTables(hstmt,
+ NULL, 0, // All qualifiers
+ (UCHAR *) UserID.GetData(), SQL_NTS, // User specified
+ NULL, 0, // All tables
+ NULL, 0); // All columns
+ }
+ else
+ {
+ retcode = SQLTables(hstmt,
+ NULL, 0, // All qualifiers
+ NULL, 0, // User specified
+ NULL, 0, // All tables
+ NULL, 0); // All columns
+ }
+ if (retcode != SQL_SUCCESS)
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ pDbInf = NULL;
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return pDbInf;
+ }
+
+ while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS) // Table Information
+ {
+ if (pass == 1) // First pass, just count the Tables
+ {
+ if (pDbInf->numTables == 0)
+ {
+ GetData( 1, SQL_C_CHAR, (UCHAR*) pDbInf->catalog, 128+1, &cb);
+ GetData( 2, SQL_C_CHAR, (UCHAR*) pDbInf->schema, 128+1, &cb);
+ }
+ pDbInf->numTables++; // Counter for Tables
+ } // if (pass == 1)
+ if (pass == 2) // Create and fill the Table entries
+ {
+ if (pDbInf->pTableInf == NULL) // Has the Table Array been created
+ { // no, then create the Array
+ pDbInf->pTableInf = new wxTableInf[pDbInf->numTables];
+ for (noTab=0;noTab<pDbInf->numTables;noTab++)
+ {
+ (pDbInf->pTableInf+noTab)->tableName[0] = 0;
+ (pDbInf->pTableInf+noTab)->tableType[0] = 0;
+ (pDbInf->pTableInf+noTab)->tableRemarks[0] = 0;
+ (pDbInf->pTableInf+noTab)->numCols = 0;
+ (pDbInf->pTableInf+noTab)->pColInf = NULL;
+ }
+ noTab = 0;
+ } // if (pDbInf->pTableInf == NULL) // Has the Table Array been created
+ GetData( 3, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
+ GetData( 4, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableType, 30+1, &cb);
+ GetData( 5, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableRemarks, 254+1, &cb);
+ noTab++;
+ } // if (pass == 2) We now know the amount of Tables
+ } // while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
+ } // for (pass = 1; pass <= 2; pass++)
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+
+ // Query how many columns are in each table
+ for (noTab=0;noTab<pDbInf->numTables;noTab++)
+ {
+ (pDbInf->pTableInf+noTab)->numCols = GetColumnCount((pDbInf->pTableInf+noTab)->tableName,UserID);
+ }
+ return pDbInf;
- assert(fileName && wxStrlen(fileName));
-
- RETCODE retcode;
- SDWORD cb;
- char tblName[DB_MAX_TABLE_NAME_LEN+1];
- char tblNameSave[DB_MAX_TABLE_NAME_LEN+1];
- char colName[DB_MAX_COLUMN_NAME_LEN+1];
- SWORD sqlDataType;
- char typeName[30+1];
- SWORD precision, length;
-
- wxString UserID;
-
- FILE *fp = fopen(fileName,"wt");
- if (fp == NULL)
- return(FALSE);
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
-
- if (userID)
- {
- if (!wxStrlen(userID))
- UserID = uid;
- else
- UserID = userID;
- }
- else
- UserID = "";
-
- // dBase does not use user names, and some drivers fail if you try to pass one
- if (Dbms() == dbmsDBASE)
- UserID = "";
-
- // Oracle user names may only be in uppercase, so force
- // the name to uppercase
- if (Dbms() == dbmsORACLE)
- UserID = UserID.Upper();
-
- if (wxStrcmp(UserID.GetData(),"") &&
- Dbms() != dbmsMY_SQL &&
- Dbms() != dbmsACCESS)
- {
- retcode = SQLColumns(hstmt,
- NULL, 0, // All qualifiers
- (UCHAR *) UserID.GetData(), SQL_NTS, // User specified
- NULL, 0, // All tables
- NULL, 0); // All columns
- }
- else
- {
- retcode = SQLColumns(hstmt,
- NULL, 0, // All qualifiers
- NULL, 0, // User specified
- NULL, 0, // All tables
- NULL, 0); // All columns
- }
- if (retcode != SQL_SUCCESS)
- {
- DispAllErrors(henv, hdbc, hstmt);
- fclose(fp);
- return(FALSE);
- }
-
- wxString outStr;
- wxStrcpy(tblNameSave,"");
- int cnt = 0;
-
- while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
- {
- if (wxStrcmp(tblName,tblNameSave))
- {
- if (cnt)
- fputs("\n", fp);
- fputs("================================ ", fp);
- fputs("================================ ", fp);
- fputs("===================== ", fp);
- fputs("========= ", fp);
- fputs("=========\n", fp);
- outStr.sprintf("%-32s %-32s %-21s %9s %9s\n",
- "TABLE NAME", "COLUMN NAME", "DATA TYPE", "PRECISION", "LENGTH");
- fputs(outStr.GetData(), fp);
- fputs("================================ ", fp);
- fputs("================================ ", fp);
- fputs("===================== ", fp);
- fputs("========= ", fp);
- fputs("=========\n", fp);
- wxStrcpy(tblNameSave,tblName);
- }
+ assert(fileName && wxStrlen(fileName));
+
+ RETCODE retcode;
+ SDWORD cb;
+ char tblName[DB_MAX_TABLE_NAME_LEN+1];
+ wxString tblNameSave;
+ char colName[DB_MAX_COLUMN_NAME_LEN+1];
+ SWORD sqlDataType;
+ char typeName[30+1];
+ SWORD precision, length;
+
+ wxString UserID;
+
+ FILE *fp = fopen(fileName,"wt");
+ if (fp == NULL)
+ return(FALSE);
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+
+ if (userID)
+ {
+ if (!wxStrlen(userID))
+ UserID = uid;
+ else
+ UserID = userID;
+ }
+ else
+ UserID = "";
+
+ // dBase does not use user names, and some drivers fail if you try to pass one
+ if (Dbms() == dbmsDBASE)
+ UserID = "";
+
+ // Oracle user names may only be in uppercase, so force
+ // the name to uppercase
+ if (Dbms() == dbmsORACLE)
+ UserID = UserID.Upper();
+
+ if (wxStrcmp(UserID.GetData(),"") &&
+ Dbms() != dbmsMY_SQL &&
+ Dbms() != dbmsACCESS)
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ (UCHAR *) UserID.GetData(), SQL_NTS, // User specified
+ NULL, 0, // All tables
+ NULL, 0); // All columns
+ }
+ else
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ NULL, 0, // User specified
+ NULL, 0, // All tables
+ NULL, 0); // All columns
+ }
+ if (retcode != SQL_SUCCESS)
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ fclose(fp);
+ return(FALSE);
+ }
+
+ wxString outStr;
+ tblNameSave = "";
+ int cnt = 0;
+
+ while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
+ {
+ if (wxStrcmp(tblName,tblNameSave.GetData()))
+ {
+ if (cnt)
+ fputs("\n", fp);
+ fputs("================================ ", fp);
+ fputs("================================ ", fp);
+ fputs("===================== ", fp);
+ fputs("========= ", fp);
+ fputs("=========\n", fp);
+ outStr.sprintf("%-32s %-32s %-21s %9s %9s\n",
+ "TABLE NAME", "COLUMN NAME", "DATA TYPE", "PRECISION", "LENGTH");
+ fputs(outStr.GetData(), fp);
+ fputs("================================ ", fp);
+ fputs("================================ ", fp);
+ fputs("===================== ", fp);
+ fputs("========= ", fp);
+ fputs("=========\n", fp);
+ tblNameSave = tblName;
+ }
- wxString UserID;
- wxString TableName;
-
- assert(tableName && wxStrlen(tableName));
-
- if (Dbms() == dbmsDBASE)
- {
- wxString dbName;
- if (tablePath && wxStrlen(tablePath))
- dbName.sprintf("%s/%s.dbf",tablePath,tableName);
- else
- dbName.sprintf("%s.dbf",tableName);
-
- bool exists;
- exists = wxFileExists(dbName.GetData());
- return exists;
- }
-
- if (userID)
- {
- if (!wxStrlen(userID))
- UserID = uid;
- else
- UserID = userID;
- }
- else
- UserID = "";
-
- // Oracle user names may only be in uppercase, so force
- // the name to uppercase
- if (Dbms() == dbmsORACLE)
- UserID = UserID.Upper();
-
- TableName = tableName;
- // Oracle table names are uppercase only, so force
- // the name to uppercase just in case programmer forgot to do this
- if (Dbms() == dbmsORACLE)
- TableName = TableName.Upper();
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
- RETCODE retcode;
-
- // MySQL and Access cannot accept a user name when looking up table names, so we
- // use the call below that leaves out the user name
- if (wxStrcmp(UserID,"") &&
- Dbms() != dbmsMY_SQL &&
- Dbms() != dbmsACCESS)
- {
- retcode = SQLTables(hstmt,
- NULL, 0, // All qualifiers
- (UCHAR *) UserID.GetData(), SQL_NTS, // All owners
- (UCHAR FAR *)TableName.GetData(), SQL_NTS,
- NULL, 0); // All table types
- }
- else
- {
- retcode = SQLTables(hstmt,
- NULL, 0, // All qualifiers
- NULL, 0, // All owners
- (UCHAR FAR *)TableName.GetData(), SQL_NTS,
- NULL, 0); // All table types
- }
- if (retcode != SQL_SUCCESS)
- return(DispAllErrors(henv, hdbc, hstmt));
-
- retcode = SQLFetch(hstmt);
- if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
- {
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return(DispAllErrors(henv, hdbc, hstmt));
- }
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return(TRUE);
+ wxString UserID;
+ wxString TableName;
+
+ assert(tableName && wxStrlen(tableName));
+
+ if (Dbms() == dbmsDBASE)
+ {
+ wxString dbName;
+ if (tablePath && wxStrlen(tablePath))
+ dbName.sprintf("%s/%s.dbf",tablePath,tableName);
+ else
+ dbName.sprintf("%s.dbf",tableName);
+
+ bool exists;
+ exists = wxFileExists(dbName.GetData());
+ return exists;
+ }
+
+ if (userID)
+ {
+ if (!wxStrlen(userID))
+ UserID = uid;
+ else
+ UserID = userID;
+ }
+ else
+ UserID = "";
+
+ // Oracle user names may only be in uppercase, so force
+ // the name to uppercase
+ if (Dbms() == dbmsORACLE)
+ UserID = UserID.Upper();
+
+ TableName = tableName;
+ // Oracle table names are uppercase only, so force
+ // the name to uppercase just in case programmer forgot to do this
+ if (Dbms() == dbmsORACLE)
+ TableName = TableName.Upper();
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ RETCODE retcode;
+
+ // MySQL and Access cannot accept a user name when looking up table names, so we
+ // use the call below that leaves out the user name
+ if (wxStrcmp(UserID,"") &&
+ Dbms() != dbmsMY_SQL &&
+ Dbms() != dbmsACCESS)
+ {
+ retcode = SQLTables(hstmt,
+ NULL, 0, // All qualifiers
+ (UCHAR *) UserID.GetData(), SQL_NTS, // All owners
+ (UCHAR FAR *)TableName.GetData(), SQL_NTS,
+ NULL, 0); // All table types
+ }
+ else
+ {
+ retcode = SQLTables(hstmt,
+ NULL, 0, // All qualifiers
+ NULL, 0, // All owners
+ (UCHAR FAR *)TableName.GetData(), SQL_NTS,
+ NULL, 0); // All table types
+ }
+ if (retcode != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc, hstmt));
+
+ retcode = SQLFetch(hstmt);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
+ {
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return(DispAllErrors(henv, hdbc, hstmt));
+ }
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return(TRUE);