diff -bBdNrw -U5 OLD/errors.properties NEW/errors.properties --- OLD/errors.properties Thu Jan 18 09:37:13 2001 +++ NEW/errors.properties Tue Aug 7 12:54:15 2001 @@ -1,6 +1,7 @@ # This is the default errors +postgresql.arr.range:The array index is out of range. postgresql.drv.version:An internal error has occured. Please recompile the driver. postgresql.con.auth:The authentication type {0} is not supported. Check that you have configured the pg_hba.conf file to include the client's IP address or Subnet, and that it is using an authentication scheme supported by the driver. postgresql.con.authfail:An error occured while getting the authentication request. postgresql.con.call:Callable Statements are not supported at this time. postgresql.con.creobj:Failed to create object for {0} {1} diff -bBdNrw -U5 OLD/jdbc2/Array.java NEW/jdbc2/Array.java --- OLD/jdbc2/Array.java Wed Dec 31 16:00:00 1969 +++ NEW/jdbc2/Array.java Tue Aug 7 13:44:53 2001 @@ -0,0 +1,301 @@ +package org.postgresql.jdbc2; + +import java.sql.*; +import java.util.*; +import java.math.BigDecimal; +import org.postgresql.Field; +import org.postgresql.util.*; + +/** + * Array is used collect one column of query result data. + * + *

JDBC provides the Array object as an alternative access method + * for query results. Rather than iterate through each row of a table + * the Array object allows the caller to load up a Java array from one + * column of result data. There are also methods for carving off slices + * of results. The resulting Array may itself be returned as a + * ResultSet using the included JDBC-defined methods. + * + *

Other than the constructor all methods are direct implementations + * of those specified for java.sql.Array. Please refer to the javadoc + * for java.sql.Array for detailed descriptions of the functionality + * and parameters of the methods of this class. + * + * @see ResultSet#getArray + */ + + +public class Array implements java.sql.Array +{ + private org.postgresql.Connection conn = null; + private org.postgresql.Field field = null; + private org.postgresql.jdbc2.ResultSet rs = null; + private int idx = 0; + + /** + * Create a new Array + * + * @param conn a database connection + * @param idx 1-based index of the query field to load into this Array + * @param field the Field descriptor for the field to load into this Array + * @param rs the ResultSet from which to get the data for this Array + */ + public Array( org.postgresql.Connection conn, int idx, Field field, org.postgresql.jdbc2.ResultSet rs ) { + this.conn = conn; + this.field = field; + this.rs = rs; + this.idx = idx; + } + + public Object getArray() throws SQLException { + return getArray( 1, rs.getTupleCount(), null ); + } + + public Object getArray(long index, int count) throws SQLException { + return getArray( index, count, null ); + } + + public Object getArray(long index, int count, Map map) throws SQLException { + if (index < 1 || index > rs.getTupleCount()) + throw new PSQLException("postgresql.arr.range"); + Object retVal = null; + if( !rs.absolute( (int)index ) ) + throw new PSQLException("postgresql.arr.range"); + int i = 0; + if( map != null ) { + throw org.postgresql.Driver.notImplemented(); + } else { + switch (field.getSQLType()) + { + case Types.BIT: + retVal = new boolean[ count ]; + for( ; count > 0; count-- ) { + ((boolean[])retVal)[i++] = rs.getBoolean(idx); + rs.next(); + } + break; + case Types.SMALLINT: + case Types.INTEGER: + retVal = new int[ count ]; + for( ; count > 0; count-- ) { + ((int[])retVal)[i++] = rs.getInt(idx); + rs.next(); + } + break; + case Types.BIGINT: + retVal = new long[ count ]; + for( ; count > 0; count-- ) { + ((long[])retVal)[i++] = rs.getLong(idx); + rs.next(); + } + break; + case Types.NUMERIC: + retVal = new BigDecimal[ rs.getTupleCount() ]; + for( ; count > 0; count-- ) { + ((BigDecimal[])retVal)[i++] = rs.getBigDecimal(idx); + rs.next(); + } + break; + case Types.REAL: + retVal = new float[ rs.getTupleCount() ]; + for( ; count > 0; count-- ) { + ((float[])retVal)[i++] = rs.getFloat(idx); + rs.next(); + } + break; + case Types.DOUBLE: + retVal = new double[ rs.getTupleCount() ]; + for( ; count > 0; count-- ) { + ((double[])retVal)[i++] = rs.getDouble(idx); + rs.next(); + } + break; + case Types.CHAR: + case Types.VARCHAR: + retVal = new String[ rs.getTupleCount() ]; + for( ; count > 0; count-- ) { + ((String[])retVal)[i++] = rs.getString(idx); + rs.next(); + } + break; + case Types.DATE: + retVal = new java.sql.Date[ rs.getTupleCount() ]; + for( ; count > 0; count-- ) { + ((java.sql.Date[])retVal)[i++] = rs.getDate(idx); + rs.next(); + } + break; + case Types.TIME: + retVal = new Time[ rs.getTupleCount() ]; + for( ; count > 0; count-- ) { + ((Time[])retVal)[i++] = rs.getTime(idx); + rs.next(); + } + break; + case Types.TIMESTAMP: + retVal = new Timestamp[ rs.getTupleCount() ]; + for( ; count > 0; count-- ) { + ((Timestamp[])retVal)[i++] = rs.getTimestamp(idx); + rs.next(); + } + break; + case Types.BINARY: + case Types.VARBINARY: + throw org.postgresql.Driver.notImplemented(); + default: + retVal = new Object[ rs.getTupleCount() ]; + for( ; count > 0; count-- ) { + ((Object[])retVal)[i++] = rs.getObject(idx); + rs.next(); + } + } + } + return retVal; + } + + public Object getArray(Map map) throws SQLException { + return getArray( 1, rs.getTupleCount(), map ); + } + + public int getBaseType() throws SQLException { + return field.getSQLType(); + } + + public String getBaseTypeName() throws SQLException { + return field.getTypeName(); + } + + public java.sql.ResultSet getResultSet() throws SQLException { + return getResultSet( 1, rs.getTupleCount(), null ); + } + + public java.sql.ResultSet getResultSet(long index, int count) throws SQLException { + return getResultSet( index, count, null ); + } + + public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map) throws SQLException { + if (index < 1 || index > rs.getTupleCount()) + throw new PSQLException("postgresql.arr.range"); + Object retVal = null; + if( !rs.absolute( (int)index ) ) + throw new PSQLException("postgresql.arr.range"); + int i = 0; + Vector rows = new Vector(); + Field[] fields = { new Field(conn, "INDEX", DatabaseMetaData.iInt2Oid, 2), new Field(conn, "VALUE", DatabaseMetaData.iInt2Oid, 2) }; + if( map != null ) { + throw org.postgresql.Driver.notImplemented(); + } else { + switch (field.getSQLType()) + { + case Types.BIT: + retVal = new boolean[ count ]; + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = (rs.getBoolean(idx)?"YES":"NO").getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + case Types.SMALLINT: + case Types.INTEGER: + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = Integer.toString(rs.getInt(idx)).getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + case Types.BIGINT: + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = Long.toString(rs.getLong(idx)).getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + case Types.NUMERIC: + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = rs.getBigDecimal(idx).toString().getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + case Types.REAL: + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = Float.toString(rs.getFloat(idx)).getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + case Types.DOUBLE: + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = Double.toString(rs.getDouble(idx)).getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + case Types.CHAR: + case Types.VARCHAR: + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = rs.getString(idx).getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + case Types.DATE: + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = rs.getDate(idx).toString().getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + case Types.TIME: + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = rs.getTime(idx).toString().getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + case Types.TIMESTAMP: + for( ; count > 0; count-- ) { + byte[][] tuple = new byte[2][0]; + tuple[0] = Integer.toString((int)index+i++).getBytes(); // Index + tuple[1] = rs.getTimestamp(idx).toString().getBytes(); // Value + rows.addElement(tuple); + rs.next(); + } + break; + + // NOTE: These throw not implemented exceptions because there weren't enough + // examples in the code for me to figure out how to correctly pack these types into + // the tuples' byte representation! + // + case Types.BINARY: + case Types.VARBINARY: + default: // Object + throw org.postgresql.Driver.notImplemented(); + } + } + return new ResultSet((org.postgresql.jdbc2.Connection)conn, fields, rows, "OK", 1 ); + } + + public java.sql.ResultSet getResultSet(Map map) throws SQLException { + return getResultSet( 1, rs.getTupleCount(), map ); + } +} + diff -bBdNrw -U5 OLD/jdbc2/ResultSet.java NEW/jdbc2/ResultSet.java --- OLD/jdbc2/ResultSet.java Tue May 22 07:46:46 2001 +++ NEW/jdbc2/ResultSet.java Tue Aug 7 12:54:44 2001 @@ -931,18 +931,21 @@ current_row = 0; this_row = (byte [][])rows.elementAt(current_row); return true; } - public Array getArray(String colName) throws SQLException + public java.sql.Array getArray(String colName) throws SQLException { return getArray(findColumn(colName)); } - public Array getArray(int i) throws SQLException + public java.sql.Array getArray(int i) throws SQLException { - throw org.postgresql.Driver.notImplemented(); + if (i < 1 || i > fields.length) + throw new PSQLException("postgresql.res.colrange"); + first(); + return (java.sql.Array) new org.postgresql.jdbc2.Array( connection, i, fields[i-1], this ); } public java.math.BigDecimal getBigDecimal(int columnIndex) throws SQLException { // Now must call BigDecimal with a scale otherwise JBuilder barfs