📄 monetresultset.java
字号:
* @throws SQLException if a database access error occurs */ public int getFetchSize() throws SQLException { return(header.getCacheSize()); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a float in the Java programming language. * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL NULL, the value returned * is 0 * @throws SQLException if there is no such column */ public float getFloat(int columnIndex) throws SQLException { float ret = 0; // note: relaxing by compiler here String flt = getString(columnIndex); if (flt != null) { try { ret = Float.parseFloat(flt); } catch (NumberFormatException e) { // ignore, return the default: 0 } // do not catch SQLException for it is declared to be thrown } return(ret); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a float in the Java programming language. * * @param columnName the SQL name of the column * @return the column value; if the value is SQL NULL, the value returned * is 0 * @throws SQLException if the ResultSet object does not contain columnName */ public float getFloat(String columnName) throws SQLException { return(getFloat(findColumn(columnName))); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as an int in the Java programming language. * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL NULL, the value returned * is 0 * @throws SQLException if there is no such column */ public int getInt(int columnIndex) throws SQLException { int ret = 0; try { // note: Integer.parseInt DOES unlike Double and Float // accept a null value ret = Integer.parseInt(getString(columnIndex)); } catch (NumberFormatException e) { // ignore, return the default: 0 } // do not catch SQLException for it is declared to be thrown return(ret); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as an int in the Java programming language. * * @param columnName the SQL name of the column * @return the column value; if the value is SQL NULL, the value returned * is 0 * @throws SQLException if the ResultSet object does not contain columnName */ public int getInt(String columnName) throws SQLException { return(getInt(findColumn(columnName))); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a long in the Java programming language. * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL NULL, the value returned * is 0 * @throws SQLException if there is no such column */ public long getLong(int columnIndex) throws SQLException { long ret = 0; try { // note: Long.parseLong DOES unlike Double and Float // accept a null value ret = Long.parseLong(getString(columnIndex)); } catch (NumberFormatException e) { // ignore, return the default: 0 } // do not catch SQLException for it is declared to be thrown return(ret); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a long in the Java programming language. * * @param columnName the SQL name of the column * @return the column value; if the value is SQL NULL, the value returned * is 0 * @throws SQLException if the ResultSet object does not contain columnName */ public long getLong(String columnName) throws SQLException { return(getLong(findColumn(columnName))); } /** * Retrieves the number, types and properties of this ResultSet object's * columns. * * @return the description of this ResultSet object's columns */ public ResultSetMetaData getMetaData() { // return inner class which implements the ResultSetMetaData interface return(new ResultSetMetaData() { // for the more expensive methods, we provide a simple cache // for the most expensive part; getting the ResultSet which // contains the data private DatabaseMetaData dbmd = null; private ResultSet[] colrs = new ResultSet[columns.length]; /** * Returns the number of columns in this ResultSet object. * * @returns the number of columns */ public int getColumnCount() { return(columns.length); } /** * Indicates whether the designated column is automatically * numbered, thus read-only. * * @param column the first column is 1, the second is 2, ... * @return true if so; false otherwise * @throws SQLException if a database access error occurs */ public boolean isAutoIncrement(int column) throws SQLException { // the only column I know of is a 'secret' column called rowid // with datatype oid // avoid nullpointer exception here if ("oid".equals(getColumnTypeName(column))) { return(true); } else { return(false); } } /** * Indicates whether a column's case matters. This holds for all * columns in MonetDB resultsets since the mapping is done case * insensitive, therefore this method will always return false. * * @param column the first column is 1, the second is 2, ... * @returns false */ public boolean isCaseSensitive(int column) { return(false); } /** * Indicates whether the designated column can be used in a * where clause. * It is unknown to me what kind ot columns they regard to, * as I think all columns are useable in a where clause. * Returning true for all here, for the time being. * Possible thought; maybe they want to know here if it's a * real column existing in a table or not... * * @param column the first column is 1, the second is 2, ... * @returns true */ public boolean isSearchable(int column) { return(true); } /** * Indicates whether the designated column is a cash value. * From the MonetDB database perspective it is by definition * unknown whether the value is a currency, because there are * no currency datatypes such as MONEY. With this knowledge * we can always return false here. * * @param column the first column is 1, the second is 2, ... * @returns false */ public boolean isCurrency(int column) { return(false); } /** * Indicates whether values in the designated column are signed * numbers. * Within MonetDB all numeric types are signed. * * @param column the first column is 1, the second is 2, ... * @return true if so; false otherwise */ public boolean isSigned(int column) throws SQLException { // we can hardcode this, based on the colum type switch (getColumnType(column)) { case Types.NUMERIC: case Types.DECIMAL: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.REAL: case Types.FLOAT: case Types.DOUBLE: return(true); case Types.BIT: // we don't use type BIT, it's here for completeness case Types.BOOLEAN: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: default: return(false); } } /** * Indicates the designated column's normal maximum width in * characters. * * @param column the first column is 1, the second is 2, ... * @return the normal maximum number of characters allowed as the * width of the designated column * @throws SQLException if there is no such column */ public int getColumnDisplaySize(int column) throws SQLException { int ret; try { ret = header.getColumnLengths()[column - 1]; } catch (IndexOutOfBoundsException e) { throw new SQLException("No such column " + column); } return(ret); } /** * Get the designated column's table's schema. * * @param column the first column is 1, the second is 2, ... * @return schema name or "" if not applicable * @throws SQLException if a database access error occurs */ public String getSchemaName(int column) throws SQLException { String schema = ""; // figure the name out try { schema = header.getTableNames()[column - 1]; } catch (IndexOutOfBoundsException e) { throw new SQLException("No such column " + column); } if (schema == null) throw new AssertionError("table_name header is empty!"); int dot = schema.indexOf("."); if (dot == -1) throw new AssertionError("table_name is not fully qualified! (" + schema + ")"); return(schema.substring(0, dot)); } /** * Gets the designated column's table name. * * @param column the first column is 1, the second is 2, ... * @return table name or "" if not applicable */ public String getTableName(int column) throws SQLException { String table = ""; // figure the name out try { table = header.getTableNames()[column - 1]; } catch (IndexOutOfBoundsException e) { throw new SQLException("No such column " + column); } if (table == null) throw new AssertionError("table_name header is empty!"); int dot = table.indexOf("."); if (dot == -1) throw new AssertionError("table_name is not fully qualified! (" + table + ")"); return(table.substring(dot + 1)); } /** * Get the designated column's number of decimal digits. * This method is currently very expensive as it needs to * retrieve the information from the database using an SQL * query. * * @param column the first column is 1, the second is 2, ... * @return precision * @throws SQLException if a database access error occurs */ public int getPrecision(int column) throws SQLException { int precision = 0; ResultSet col = getColumnResultSet(column); // the result has either zero or one results, as the // schema, table and column should be unique... if (col.next()) precision = col.getInt("COLUMN_SIZE"); return(precision); } /** * Gets the designated column's number of digits to right of * the decimal point. This method is currently very * expensive as it needs to retrieve the information from * the database using an SQL query. * * @param column the first column is 1, the second is 2, ... * @return scale * @throws SQLException if a database access error occurs */ public int getScale(int column) throws SQLException { int scale = 0; ResultSet col = getColumnResultSet(column); // the result has either zero or one results, as the // schema, table and column should be unique... if (col.next()) scale = col.getInt("DECIMAL_DIGITS"); return(scale); } /** * Indicates the nullability of values in the designated * column. This method is currently very expensive as it * needs to retrieve the information from the database using * an SQL query. * * @param column the first column is 1, the second is 2, ... * @return scale * @throws SQLException if a database access error occurs */ public int isNullable(int column) throws SQLException { int ret = columnNullableUnknown; ResultSet col = getColumnResultSet(column); // the result has either zero or one results, as the // schema, table and column should be unique... if (col.next()) ret = col.getInt("NULLABLE"); return(ret); } /** * Gets the designated column's table's catalog name. * Because MonetDB handles only one catalog (dbfarm) at a * time, the current one is the one we deal with here. * * @param column the first column is 1, the second is 2, ... * @return the name of the catalog for the table in which the given * column appears or "" if not applicable */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -