+/********** wxDB::Catalog() **********/
+bool wxDB::Catalog(const char *userID, const char *fileName)
+{
+ 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 || !wxStrlen(userID))
+ UserID = uid;
+ else
+ UserID = 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(),""))
+ {
+ 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);
+ }
+
+ SQLBindCol(hstmt, 3, SQL_C_CHAR, (UCHAR*) tblName, DB_MAX_TABLE_NAME_LEN+1, &cb);
+ SQLBindCol(hstmt, 4, SQL_C_CHAR, (UCHAR*) colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
+ SQLBindCol(hstmt, 5, SQL_C_SSHORT, (UCHAR*) &sqlDataType, 0, &cb);
+ SQLBindCol(hstmt, 6, SQL_C_CHAR, (UCHAR*) typeName, sizeof(typeName), &cb);
+ SQLBindCol(hstmt, 7, SQL_C_SSHORT, (UCHAR*) &precision, 0, &cb);
+ SQLBindCol(hstmt, 8, SQL_C_SSHORT, (UCHAR*) &length, 0, &cb);
+
+ char outStr[256];
+ 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);
+ sprintf(outStr, "%-32s %-32s %-21s %9s %9s\n",
+ "TABLE NAME", "COLUMN NAME", "DATA TYPE", "PRECISION", "LENGTH");
+ fputs(outStr, fp);
+ fputs("================================ ", fp);
+ fputs("================================ ", fp);
+ fputs("===================== ", fp);
+ fputs("========= ", fp);
+ fputs("=========\n", fp);
+ wxStrcpy(tblNameSave,tblName);
+ }
+ sprintf(outStr, "%-32s %-32s (%04d)%-15s %9d %9d\n",
+ tblName, colName, sqlDataType, typeName, precision, length);
+ if (fputs(outStr, fp) == EOF)
+ {
+ SQLFreeStmt(hstmt, SQL_UNBIND);
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ fclose(fp);
+ return(FALSE);
+ }
+ cnt++;
+ }
+
+ if (retcode != SQL_NO_DATA_FOUND)
+ DispAllErrors(henv, hdbc, hstmt);
+
+ SQLFreeStmt(hstmt, SQL_UNBIND);
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+
+ fclose(fp);
+ return(retcode == SQL_NO_DATA_FOUND);
+
+} // wxDB::Catalog()
+
+