abstractjdbc2resultsetmetadata.java

来自「PostgreSQL7.4.6 for Linux」· Java 代码 · 共 554 行 · 第 1/2 页

JAVA
554
字号
		{			case Types.SMALLINT:				return 5;			case Types.INTEGER:				return 10;			case Types.REAL:				return 8;			case Types.FLOAT:				return 16;			case Types.DOUBLE:				return 16;			case Types.VARCHAR:				return 0;			case Types.NUMERIC:				Field f = getField(column);				if (f != null)					return ((0xFFFF0000)&f.getMod()) >> 16;				else					return 0;			default:				return 0;		}	}	/*	 * What is a column's number of digits to the right of the	 * decimal point?	 *	 * @param column the first column is 1, the second is 2...	 * @return the scale	 * @exception SQLException if a database access error occurs	 */	public int getScale(int column) throws SQLException	{		int sql_type = getField(column).getSQLType();		switch (sql_type)		{			case Types.SMALLINT:				return 0;			case Types.INTEGER:				return 0;			case Types.REAL:				return 8;			case Types.FLOAT:				return 16;			case Types.DOUBLE:				return 16;			case Types.VARCHAR:				return 0;			case Types.NUMERIC:				Field f = getField(column);				if (f != null)					return (((0x0000FFFF)&f.getMod()) - 4);				else					return 0;			default:				return 0;		}	}	/*	 * Whats a column's table's name?  How do I find this out?	Both	 * getSchemaName() and getCatalogName() rely on knowing the table	 * Name, so we need this before we can work on them.	 *	 * @param column the first column is 1, the second is 2...	 * @return column name, or "" if not applicable	 * @exception SQLException if a database access error occurs	 */	public String getTableName(int column) throws SQLException	{		return "";	}	/*	 * What's a column's table's catalog name?  As with getSchemaName(),	 * we can say that if getTableName() returns n/a, then we can too -	 * otherwise, we need to work on it.	 *	 * @param column the first column is 1, the second is 2...	 * @return catalog name, or "" if not applicable	 * @exception SQLException if a database access error occurs	 */	public String getCatalogName(int column) throws SQLException	{		return "";	}	/*	 * What is a column's SQL Type? (java.sql.Type int)	 *	 * @param column the first column is 1, the second is 2, etc.	 * @return the java.sql.Type value	 * @exception SQLException if a database access error occurs	 * @see org.postgresql.Field#getSQLType	 * @see java.sql.Types	 */	public int getColumnType(int column) throws SQLException	{		return getField(column).getSQLType();	}	/*	 * Whats is the column's data source specific type name?	 *	 * @param column the first column is 1, the second is 2, etc.	 * @return the type name	 * @exception SQLException if a database access error occurs	 */	public String getColumnTypeName(int column) throws SQLException	{		return getField(column).getPGType();	}	/**	 * Is the column definitely not writable?  In reality, we would	 * have to check the GRANT/REVOKE stuff for this to be effective,	 * and I haven't really looked into that yet, so this will get	 * re-visited.	 *	 * @param column the first column is 1, the second is 2, etc.	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean isReadOnly(int column) throws SQLException	{		return false;	}	/**	 * Is it possible for a write on the column to succeed?  Again, we	 * would in reality have to check the GRANT/REVOKE stuff, which	 * I haven't worked with as yet.  However, if it isn't ReadOnly, then	 * it is obviously writable.	 *	 * @param column the first column is 1, the second is 2, etc.	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean isWritable(int column) throws SQLException	{		return !isReadOnly(column);	}	/**	 * Will a write on this column definately succeed?	Hmmm...this	 * is a bad one, since the two preceding functions have not been	 * really defined.	I cannot tell is the short answer.	I thus	 * return isWritable() just to give us an idea.	 *	 * @param column the first column is 1, the second is 2, etc..	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean isDefinitelyWritable(int column) throws SQLException	{		return false;	}	// ********************************************************	//	END OF PUBLIC INTERFACE	// ********************************************************	/**	 * For several routines in this package, we need to convert	 * a columnIndex into a Field[] descriptor.  Rather than do	 * the same code several times, here it is.	 *	 * @param columnIndex the first column is 1, the second is 2...	 * @return the Field description	 * @exception SQLException if a database access error occurs	 */	private Field getField(int columnIndex) throws SQLException	{		if (columnIndex < 1 || columnIndex > fields.length)			throw new PSQLException("postgresql.res.colrange", PSQLState.INVALID_PARAMETER_VALUE);		return fields[columnIndex - 1];	}	// ** JDBC 2 Extensions **	// This can hook into our PG_Object mechanism	/**	 * Returns the fully-qualified name of the Java class whose instances	 * are manufactured if the method <code>ResultSet.getObject</code>	 * is called to retrieve a value from the column.	 *	 * <code>ResultSet.getObject</code> may return a subclass of the class	 * returned by this method.	 *	 * @param column the first column is 1, the second is 2, ...	 * @return the fully-qualified name of the class in the Java programming	 *		   language that would be used by the method	 *		   <code>ResultSet.getObject</code> to retrieve the value in the specified	 *		   column. This is the class name used for custom mapping.	 * @exception SQLException if a database access error occurs	 */	public String getColumnClassName(int column) throws SQLException	{		/*			The following data type mapping came from ../Field.java.			"int2",			"int4","oid",			"int8",			"cash","money",			"numeric",			"float4",			"float8",			"bpchar","char","char2","char4","char8","char16",			"varchar","text","name","filename",			"bool",			"date",			"time",			"abstime","timestamp"			Types.SMALLINT,			Types.INTEGER,Types.INTEGER,			Types.BIGINT,			Types.DOUBLE,Types.DOUBLE,			Types.NUMERIC,			Types.REAL,			Types.DOUBLE,			Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,			Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,			Types.BIT,			Types.DATE,			Types.TIME,			Types.TIMESTAMP,Types.TIMESTAMP		*/		Field field = getField(column);		int sql_type = field.getSQLType();		switch (sql_type)		{			case Types.BIT:				return ("java.lang.Boolean");			case Types.SMALLINT:				return ("java.lang.Short");			case Types.INTEGER:				return ("java.lang.Integer");			case Types.BIGINT:				return ("java.lang.Long");			case Types.NUMERIC:				return ("java.math.BigDecimal");			case Types.REAL:				return ("java.lang.Float");			case Types.DOUBLE:				return ("java.lang.Double");			case Types.CHAR:			case Types.VARCHAR:				return ("java.lang.String");			case Types.DATE:				return ("java.sql.Date");			case Types.TIME:				return ("java.sql.Time");			case Types.TIMESTAMP:				return ("java.sql.Timestamp");			case Types.BINARY:			case Types.VARBINARY:				return ("[B");			case Types.ARRAY:				return ("java.sql.Array");			default:				String type = field.getPGType();				if ("unknown".equals(type))				{					return ("java.lang.String");				}				return ("java.lang.Object");		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?