+ 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_WXCHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
+ GetData( 2, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
+ GetData( 3, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
+ GetData( 4, SQL_C_WXCHAR, (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_WXCHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
+ GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnLength, 0, &cb);
+ GetData( 8, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].bufferSize, 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_WXCHAR, (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))
+ {
+#ifdef _IODBC_
+ // IODBC does not return a correct columnLength, so we set
+ // columnLength = bufferSize if no column length was returned
+ // IODBC returns the columnLength in bufferSize. (bug)
+ if (colInf[colNo].columnLength < 1)
+ {
+ colInf[colNo].columnLength = colInf[colNo].bufferSize;
+ }
+#endif
+ 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;
+ else if (!wxStricmp(typeInfBlob.TypeName, colInf[colNo].typeName))
+ colInf[colNo].dbDataType = DB_DATA_TYPE_BLOB;
+ colNo++;
+ }
+ }
+ }
+ if (retcode != SQL_NO_DATA_FOUND)
+ { // Error occurred, abort
+ DispAllErrors(henv, hdbc, hstmt);
+ if (colInf)
+ delete [] colInf;
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return(0);
+ }
+ }
+ }
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ return colInf;
+
+} // wxDb::GetColumns()
+
+
+/********** wxDb::GetColumns() **********/
+
+wxDbColInf *wxDb::GetColumns(const wxString &tableName, UWORD *numCols, const wxChar *userID)
+//
+// Same as the above GetColumns() function except this one gets columns
+// only for a single table, and if 'numCols' is not NULL, the number of
+// columns stored in the returned wxDbColInf is set in '*numCols'
+//
+// userID is evaluated in the following manner:
+// userID == NULL ... UserID is ignored
+// userID == "" ... UserID set equal to 'this->uid'
+// userID != "" ... UserID set equal to 'userID'
+//
+// NOTE: ALL column bindings associated with this wxDb instance are unbound
+// by this function. This function should use its own wxDb instance
+// to avoid undesired unbinding of columns.
+
+{
+ UWORD noCols = 0;
+ UWORD colNo = 0;
+ wxDbColInf *colInf = 0;
+
+ RETCODE retcode;
+ SQLLEN cb;
+
+ wxString TableName;
+
+ wxString UserID;
+ convertUserID(userID,UserID);
+
+ // Pass 1 - Determine how many columns there are.
+ // Pass 2 - Allocate the wxDbColInf 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 wxDbColInf objects to hold the column information
+ colInf = new wxDbColInf[noCols+1];
+ if (!colInf)
+ break;
+ // Mark the end of the array
+ wxStrcpy(colInf[noCols].tableName, wxEmptyString);
+ wxStrcpy(colInf[noCols].colName, wxEmptyString);
+ colInf[noCols].sqlDataType = 0;
+ }
+
+ TableName = tableName;
+ // Oracle and Interbase table names are uppercase only, so force
+ // the name to uppercase just in case programmer forgot to do this
+ if ((Dbms() == dbmsORACLE) ||
+ (Dbms() == dbmsFIREBIRD) ||
+ (Dbms() == dbmsINTERBASE))
+ TableName = TableName.Upper();
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+
+ // MySQL, SQLServer, 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 (!UserID.empty() &&
+ Dbms() != dbmsMY_SQL &&
+ Dbms() != dbmsACCESS &&
+ Dbms() != dbmsMS_SQL_SERVER)
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ (SQLTCHAR *) UserID.c_str(), SQL_NTS, // Owner
+ (SQLTCHAR *) TableName.c_str(), SQL_NTS,
+ NULL, 0); // All columns
+ }
+ else
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ NULL, 0, // Owner
+ (SQLTCHAR *) TableName.c_str(), SQL_NTS,
+ NULL, 0); // All columns
+ }
+ if (retcode != SQL_SUCCESS)
+ { // Error occurred, 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