+/********** wxDB::Catalog() **********/
+bool wxDB::Catalog(char *userID, char *fileName)
+{
+ assert(fileName && strlen(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;
+
+ FILE *fp = fopen(fileName,"wt");
+ if (fp == NULL)
+ return(FALSE);
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+
+ if (!userID || !strlen(userID))
+ userID = uid;
+
+ char userIdUC[80+1];
+ // Oracle user names may only be in uppercase, so force
+ // the name to uppercase
+ if (Dbms() == dbmsORACLE)
+ {
+ int i = 0;
+ for (char *p = userID; *p; p++)
+ userIdUC[i++] = toupper(*p);
+ userIdUC[i] = 0;
+ userID = userIdUC;
+ }
+
+ if (strcmp(userID,""))
+ {
+ retcode = SQLColumns(hstmt,
+ NULL, 0, // All qualifiers
+ (UCHAR *) userID, 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];
+ strcpy(tblNameSave,"");
+ int cnt = 0;
+
+ while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
+ {
+ if (strcmp(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);
+ strcpy(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()
+
+