Commit 99aa2f8e authored by Barry Lind's avatar Barry Lind

patch submitted by Jason Davies jason@netspade.com to improve...

patch submitted by Jason Davies jason@netspade.com to improve ResultSetMetaData.getColumnClassName() support
parent c50bf019
...@@ -935,9 +935,9 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -935,9 +935,9 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
switch (field.getSQLType()) switch (field.getSQLType())
{ {
case Types.BIT: case Types.BIT:
return new Boolean(getBoolean(columnIndex)); return getBoolean(columnIndex) ? Boolean.TRUE : Boolean.FALSE;
case Types.SMALLINT: case Types.SMALLINT:
return new Short((short)getInt(columnIndex)); return new Short(getShort(columnIndex));
case Types.INTEGER: case Types.INTEGER:
return new Integer(getInt(columnIndex)); return new Integer(getInt(columnIndex));
case Types.BIGINT: case Types.BIGINT:
......
...@@ -780,9 +780,9 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -780,9 +780,9 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
switch (field.getSQLType()) switch (field.getSQLType())
{ {
case Types.BIT: case Types.BIT:
return new Boolean(getBoolean(columnIndex)); return getBoolean(columnIndex) ? Boolean.TRUE : Boolean.FALSE;
case Types.SMALLINT: case Types.SMALLINT:
return new Short((short)getInt(columnIndex)); return new Short(getShort(columnIndex));
case Types.INTEGER: case Types.INTEGER:
return new Integer(getInt(columnIndex)); return new Integer(getInt(columnIndex));
case Types.BIGINT: case Types.BIGINT:
......
...@@ -471,6 +471,21 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData ...@@ -471,6 +471,21 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
// ** JDBC 2 Extensions ** // ** JDBC 2 Extensions **
// This can hook into our PG_Object mechanism // 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 public String getColumnClassName(int column) throws SQLException
{ {
/* /*
...@@ -505,34 +520,47 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData ...@@ -505,34 +520,47 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
Types.TIMESTAMP,Types.TIMESTAMP Types.TIMESTAMP,Types.TIMESTAMP
*/ */
int sql_type = getField(column).getSQLType(); Field field = getField(column);
int sql_type = field.getSQLType();
switch (sql_type)
{ switch (sql_type)
case Types.BIT: {
return("java.lang.Boolean"); case Types.BIT:
case Types.SMALLINT: return("java.lang.Boolean");
return("java.lang.Integer"); case Types.SMALLINT:
case Types.INTEGER: return("java.lang.Short");
return("java.lang.Integer"); case Types.INTEGER:
case Types.BIGINT: return("java.lang.Integer");
return("java.lang.Long"); case Types.BIGINT:
case Types.NUMERIC: return("java.lang.Long");
return("java.math.BigDecimal"); case Types.NUMERIC:
case Types.REAL: return("java.math.BigDecimal");
return("java.lang.Float"); case Types.REAL:
case Types.DOUBLE: return("java.lang.Float");
return("java.lang.Double"); case Types.DOUBLE:
case Types.CHAR: return("java.lang.Double");
case Types.VARCHAR: case Types.CHAR:
return("java.lang.String"); case Types.VARCHAR:
case Types.DATE: return("java.lang.String");
case Types.TIME: case Types.DATE:
case Types.TIMESTAMP: return("java.sql.Date");
return("java.sql.Timestamp"); case Types.TIME:
default: return("java.sql.Time");
throw org.postgresql.Driver.notImplemented(); case Types.TIMESTAMP:
} return("java.sql.Timestamp");
} case Types.BINARY:
case Types.VARBINARY:
return("java.sql.Object");
case Types.ARRAY:
return("java.sql.Array");
default:
String type = field.getPGType();
if ("unknown".equals(type))
{
return("java.lang.String");
}
return("java.lang.Object");
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment