/** * The name of a given column * @see java.sql.ResultSetMetaData#getColumnName * @param column the column whose name is wanted * @return the name of the requested column */ public String getColumnName(int column) {// throws SQLException { // get the column and return its name // String columnName; int dotAt; TsColumn col = tsql.columnAtIndex(column - 1); dotAt = col.name.indexOf("."); columnName = col.name; if (dotAt > -1) { columnName = col.name.substring(dotAt + 1); } if (col.alias != (String)null) { if (!col.alias.equals(columnName)) { return(col.alias); } } columnName = TinySQLGlobals.getLongName(columnName); return(columnName); }
/** * Gets a description of table columns available in * the specified catalog. * * <P>Only column descriptions matching the catalog, schema, table * and column name criteria are returned. They are ordered by * TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION. * * <P>Each column description has the following columns: * <OL> * <LI><B>TABLE_CAT</B> String => table catalog (may be null) * <LI><B>TABLE_SCHEM</B> String => table schema (may be null)sRow record = new TsRow(); * * <LI><B>TABLE_NAME</B> String => table name * <LI><B>COLUMN_NAME</B> String => column name * <LI><B>DATA_TYPE</B> short => SQL type from java.sql.Types * <LI><B>TYPE_NAME</B> String => Data source dependent type name, * for a UDT the type name is fully qualified * <LI><B>COLUMN_SIZE</B> int => column size. For char or date * types this is the maximum number of characters, for numeric or * decimal types this is precision. * <LI><B>BUFFER_LENGTH</B> is not used. * <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits * <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2) * <LI><B>NULLABLE</B> int => is NULL allowed? * <UL> * <LI> columnNoNulls - might not allow NULL values * <LI> columnNullable - definitely allows NULL values * <LI> columnNullableUnknown - nullability unknown * </UL> * <LI><B>REMARKS</B> String => comment describing column (may be null) * <LI><B>COLUMN_DEF</B> String => default value (may be null) * <LI><B>SQL_DATA_TYPE</B> int => unused * <LI><B>SQL_DATETIME_SUB</B> int => unused * <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the * maximum number of bytes in the column * <LI><B>ORDINAL_POSITION</B> int => index of column in table * (starting at 1) * <LI><B>IS_NULLABLE</B> String => "NO" means column definitely * does not allow NULL values; "YES" means the column might * allow NULL values. An empty string means nobody knows. * </OL> * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schemaPattern a schema name pattern; "" retrieves those * without a schema * @param tableNamePattern a table name pattern * @param columnNamePattern a column name pattern * @return ResultSet - each row is a column description * @exception SQLException if a database access error occurs * @see #getSearchStringEscape */ public override java.sql.ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) { int i; String columnNameKey; try { String dataDir = getDataDir(); Utils.log("Entering getColumns(tableNamePattern='" + tableNamePattern + "')"); if (dataDir == null) { return(null); } java.sql.ResultSet tableRs = getTables(catalog, schemaPattern, tableNamePattern, null); TsResultSet jrs = new TsResultSet(); TsColumn jsc = new TsColumn("TABLE_CAT"); jsc.type = java.sql.Types.CHAR; jsc.size = 9; jrs.addColumn(jsc); jsc = new TsColumn("TABLE_SCHEM"); jsc.type = java.sql.Types.CHAR; jsc.size = 11; jrs.addColumn(jsc); jsc = new TsColumn("TABLE_NAME"); jsc.type = java.sql.Types.CHAR; jsc.size = 10; jrs.addColumn(jsc); jsc = new TsColumn("COLUMN_NAME"); jsc.type = java.sql.Types.CHAR; jsc.size = 11; jrs.addColumn(jsc); jsc = new TsColumn("DATA_TYPE"); jsc.type = java.sql.Types.INTEGER; jsc.size = 6; jrs.addColumn(jsc); jsc = new TsColumn("TYPE_NAME"); jsc.type = java.sql.Types.CHAR; jsc.size = 9; jrs.addColumn(jsc); jsc = new TsColumn("COLUMN_SIZE"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("BUFFER_LENGTH"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("DECIMAL_DIGITS"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("NUM_PREC_RADIX"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("NULLABLE"); jsc.type = java.sql.Types.INTEGER; jsc.size = 8; jrs.addColumn(jsc); jsc = new TsColumn("REMARKS"); jsc.type = java.sql.Types.CHAR; jsc.size = 128; jrs.addColumn(jsc); jsc = new TsColumn("COLUMN_DEF"); jsc.type = java.sql.Types.CHAR; jsc.size = 128; jrs.addColumn(jsc); jsc = new TsColumn("SQL_DATA_TYPE"); jsc.type = java.sql.Types.INTEGER; jsc.size = 128; jrs.addColumn(jsc); // Several parameters missing. jsc = new TsColumn("IS_NULLABLE"); jsc.type = java.sql.Types.CHAR; jsc.size = 3; jrs.addColumn(jsc); while (tableRs.next()) { // process each DBF file and extract column info ... String tableName = tableRs.getString("TABLE_NAME"); DBFFileTable tbl; try { tbl = new DBFFileTable(dataDir, tableName); } catch (Exception) { continue; // ignore buggy and empty (zero byte size) DBF files } Utils.log("Accessing column info for table " + tableName); java.util.Hashtable <Object, Object> column_info = tbl.column_info; for (i = 0; i < tbl.columnNameKeys.size(); i++) { columnNameKey = (String)tbl.columnNameKeys.elementAt(i); TsColumn tsc = (TsColumn)column_info.get(columnNameKey); // process each column of the current table ... TsRow record = new TsRow(); record.put("TABLE_CAT", ""); record.put("TABLE_SCHEM", ""); record.put("TABLE_NAME", tableName); record.put("COLUMN_NAME", TinySQLGlobals.getLongName(tsc.name)); record.put("DATA_TYPE", new java.lang.Integer(tsc.type).toString()); record.put("TYPE_NAME", DBFFile.typeToLiteral(tsc.type).toString()); record.put("COLUMN_SIZE", new java.lang.Integer(tsc.size).toString()); record.put("DECIMAL_DIGITS", new java.lang.Integer(tsc.decimalPlaces).toString()); int nullable = columnNoNulls; if (tsc.notNull == true) { nullable = columnNullable; } record.put("NULLABLE", new java.lang.Integer(nullable).toString()); record.put("REMARKS", "noRemarks"); String defaultVal = tsc.defaultVal; if (defaultVal == null) { defaultVal = ""; } record.put("COLUMN_DEF", defaultVal); String isNullable = "NO"; if (tsc.notNull == true) { isNullable = "YES"; } record.put("IS_NULLABLE", isNullable); /* * Suppress any sorting of the ResultSet. Column Metadata should * be presented in the order the columns exist in the dBase header. */ jrs.addRow(record, false); } tbl.close(); tbl = null; } return(new TinySQLResultSet(jrs, (TinySQLStatement)null)); } catch (Exception) { return(null); } }