diff options
| author | PostgreSQL Daemon <webmaster@postgresql.org> | 2004-01-19 20:07:14 +0000 |
|---|---|---|
| committer | PostgreSQL Daemon <webmaster@postgresql.org> | 2004-01-19 20:07:14 +0000 |
| commit | 2a9bf5b33d0b82e9f483f6a5ced9d71e1c009441 (patch) | |
| tree | 8c0c38494985b8dbfd2311b5be51fa76a271ba17 /src/interfaces/jdbc/org/postgresql/jdbc2 | |
| parent | 9bd681a5220186230e0ea0f718a71af7ebe4b560 (diff) | |
| download | postgresql-2a9bf5b33d0b82e9f483f6a5ced9d71e1c009441.tar.gz | |
JDBC is now on GBorg
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/jdbc2')
19 files changed, 0 insertions, 3657 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Blob.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Blob.java deleted file mode 100644 index 27e10af2b9..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Blob.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.postgresql.jdbc2; - -import org.postgresql.PGConnection; -import org.postgresql.largeobject.LargeObject; -import org.postgresql.largeobject.LargeObjectManager; -import java.io.InputStream; -import java.sql.Blob; -import java.sql.SQLException; - -public abstract class AbstractJdbc2Blob -{ - private int oid; - private LargeObject lo; - - public AbstractJdbc2Blob(PGConnection conn, int oid) throws SQLException - { - this.oid = oid; - LargeObjectManager lom = conn.getLargeObjectAPI(); - this.lo = lom.open(oid); - } - - public long length() throws SQLException - { - return lo.size(); - } - - public InputStream getBinaryStream() throws SQLException - { - return lo.getInputStream(); - } - - public byte[] getBytes(long pos, int length) throws SQLException - { - lo.seek((int)pos, LargeObject.SEEK_SET); - return lo.read(length); - } - - /* - * For now, this is not implemented. - */ - public long position(byte[] pattern, long start) throws SQLException - { - throw org.postgresql.Driver.notImplemented(); - } - - /* - * This should be simply passing the byte value of the pattern Blob - */ - public long position(Blob pattern, long start) throws SQLException - { - return position(pattern.getBytes(0, (int)pattern.length()), start); - } - -} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Clob.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Clob.java deleted file mode 100644 index d1948f6331..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Clob.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.postgresql.jdbc2; - - -import org.postgresql.PGConnection; -import org.postgresql.largeobject.LargeObject; -import org.postgresql.largeobject.LargeObjectManager; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.sql.Clob; -import java.sql.SQLException; - -public class AbstractJdbc2Clob -{ - private int oid; - private LargeObject lo; - - public AbstractJdbc2Clob(PGConnection conn, int oid) throws SQLException - { - this.oid = oid; - LargeObjectManager lom = conn.getLargeObjectAPI(); - this.lo = lom.open(oid); - } - - public long length() throws SQLException - { - return lo.size(); - } - - public InputStream getAsciiStream() throws SQLException - { - return lo.getInputStream(); - } - - public Reader getCharacterStream() throws SQLException - { - return new InputStreamReader(lo.getInputStream()); - } - - public String getSubString(long i, int j) throws SQLException - { - lo.seek((int)i - 1); - return new String(lo.read(j)); - } - - /* - * For now, this is not implemented. - */ - public long position(String pattern, long start) throws SQLException - { - throw org.postgresql.Driver.notImplemented(); - } - - /* - * This should be simply passing the byte value of the pattern Blob - */ - public long position(Clob pattern, long start) throws SQLException - { - throw org.postgresql.Driver.notImplemented(); - } - -} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java deleted file mode 100644 index feba229f7c..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.postgresql.jdbc2; - - -import java.io.PrintWriter; -import java.sql.DriverManager; -import java.sql.SQLData; -import java.sql.SQLException; -import java.sql.Types; - -/* $PostgreSQL: pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v 1.7 2003/11/29 19:52:10 pgsql Exp $ - * This class defines methods of the jdbc2 specification. This class extends - * org.postgresql.jdbc1.AbstractJdbc1Connection which provides the jdbc1 - * methods. The real Connection class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Connection - */ -public abstract class AbstractJdbc2Connection extends org.postgresql.jdbc1.AbstractJdbc1Connection -{ - /* - * The current type mappings - */ - protected java.util.Map typemap; - - public java.sql.Statement createStatement() throws SQLException - { - // The spec says default of TYPE_FORWARD_ONLY but everyone is used to - // using TYPE_SCROLL_INSENSITIVE - return createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY); - } - - public abstract java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException; - - public java.sql.PreparedStatement prepareStatement(String sql) throws SQLException - { - return prepareStatement(sql, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY); - } - - public abstract java.sql.PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException; - - public java.sql.CallableStatement prepareCall(String sql) throws SQLException - { - return prepareCall(sql, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY); - } - - public abstract java.sql.CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException; - - public java.util.Map getTypeMap() throws SQLException - { - return typemap; - } - - - public void setTypeMap(java.util.Map map) throws SQLException - { - typemap = map; - } - - /* - * This overides the standard internal getObject method so that we can - * check the jdbc2 type map first - */ - public Object getObject(String type, String value) throws SQLException - { - if (typemap != null) - { - SQLData d = (SQLData) typemap.get(type); - if (d != null) - { - // Handle the type (requires SQLInput & SQLOutput classes to be implemented) - throw org.postgresql.Driver.notImplemented(); - } - } - - // Default to the original method - return super.getObject(type, value); - } - - - //Because the get/setLogStream methods are deprecated in JDBC2 - //we use the get/setLogWriter methods here for JDBC2 by overriding - //the base version of this method - protected void enableDriverManagerLogging() - { - if (DriverManager.getLogWriter() == null) - { - DriverManager.setLogWriter(new PrintWriter(System.out)); - } - } - - - /* - * This implemetation uses the jdbc2Types array to support the jdbc2 - * datatypes. Basically jdbc1 and jdbc2 are the same, except that - * jdbc2 adds the Array types. - */ - public int getSQLType(String pgTypeName) - { - int sqlType = Types.OTHER; // default value - for (int i = 0;i < jdbc2Types.length;i++) - { - if (pgTypeName.equals(jdbc2Types[i])) - { - sqlType = jdbc2Typei[i]; - break; - } - } - return sqlType; - } - - /* - * This table holds the org.postgresql names for the types supported. - * Any types that map to Types.OTHER (eg POINT) don't go into this table. - * They default automatically to Types.OTHER - * - * Note: This must be in the same order as below. - * - * Tip: keep these grouped together by the Types. value - */ - private static final String jdbc2Types[] = { - "int2", - "int4", "oid", - "int8", - "cash", "money", - "numeric", - "float4", - "float8", - "bpchar", "char", "char2", "char4", "char8", "char16", - "varchar", "text", "name", "filename", - "bytea", - "bool", - "bit", - "date", - "time", - "abstime", "timestamp", "timestamptz", - "_bool", "_char", "_int2", "_int4", "_text", - "_oid", "_varchar", "_int8", "_float4", "_float8", - "_abstime", "_date", "_time", "_timestamp", "_numeric", - "_bytea" - }; - - /* - * This table holds the JDBC type for each entry above. - * - * Note: This must be in the same order as above - * - * Tip: keep these grouped together by the Types. value - */ - private static final int jdbc2Typei[] = { - 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.BINARY, - Types.BIT, - Types.BIT, - Types.DATE, - Types.TIME, - Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, - Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, - Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, - Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, - Types.ARRAY - }; - - - - -} - - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java deleted file mode 100644 index d3f7e1253d..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.postgresql.jdbc2; - -import java.sql.SQLException; - -public abstract class AbstractJdbc2DatabaseMetaData extends org.postgresql.jdbc1.AbstractJdbc1DatabaseMetaData -{ - - public AbstractJdbc2DatabaseMetaData(AbstractJdbc2Connection conn) - { - super(conn); - } - - - - // ** JDBC 2 Extensions ** - - /* - * Does the database support the given result set type? - * - * @param type - defined in java.sql.ResultSet - * @return true if so; false otherwise - * @exception SQLException - if a database access error occurs - */ - public boolean supportsResultSetType(int type) throws SQLException - { - // The only type we don't support - return type != java.sql.ResultSet.TYPE_SCROLL_SENSITIVE; - } - - - /* - * Does the database support the concurrency type in combination - * with the given result set type? - * - * @param type - defined in java.sql.ResultSet - * @param concurrency - type defined in java.sql.ResultSet - * @return true if so; false otherwise - * @exception SQLException - if a database access error occurs - */ - public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException - { - // These combinations are not supported! - if (type == java.sql.ResultSet.TYPE_SCROLL_SENSITIVE) - return false; - - // We do support Updateable ResultSets - if (concurrency == java.sql.ResultSet.CONCUR_UPDATABLE) - return true; - - // Everything else we do - return true; - } - - - /* lots of unsupported stuff... */ - public boolean ownUpdatesAreVisible(int type) throws SQLException - { - return true; - } - - public boolean ownDeletesAreVisible(int type) throws SQLException - { - return true; - } - - public boolean ownInsertsAreVisible(int type) throws SQLException - { - // indicates that - return true; - } - - public boolean othersUpdatesAreVisible(int type) throws SQLException - { - return false; - } - - public boolean othersDeletesAreVisible(int i) throws SQLException - { - return false; - } - - public boolean othersInsertsAreVisible(int type) throws SQLException - { - return false; - } - - public boolean updatesAreDetected(int type) throws SQLException - { - return false; - } - - public boolean deletesAreDetected(int i) throws SQLException - { - return false; - } - - public boolean insertsAreDetected(int type) throws SQLException - { - return false; - } - - /* - * Indicates whether the driver supports batch updates. - */ - public boolean supportsBatchUpdates() throws SQLException - { - return true; - } - - /* - * Return user defined types in a schema - */ - public java.sql.ResultSet getUDTs(String catalog, - String schemaPattern, - String typeNamePattern, - int[] types - ) throws SQLException - { - throw org.postgresql.Driver.notImplemented(); - } - - - /* - * Retrieves the connection that produced this metadata object. - * - * @return the connection that produced this metadata object - */ - public java.sql.Connection getConnection() throws SQLException - { - return (java.sql.Connection)connection; - } - - /* I don't find these in the spec!?! */ - - public boolean rowChangesAreDetected(int type) throws SQLException - { - return false; - } - - public boolean rowChangesAreVisible(int type) throws SQLException - { - return false; - } -} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java deleted file mode 100644 index 37d7f9cf07..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java +++ /dev/null @@ -1,1548 +0,0 @@ -/*------------------------------------------------------------------------- - * - * AbstractJdbc2ResultSet.java - * This class defines methods of the jdbc2 specification. This class - * extends org.postgresql.jdbc1.AbstractJdbc1ResultSet which provides the - * jdbc1 methods. The real Statement class (for jdbc2) is - * org.postgresql.jdbc2.Jdbc2ResultSet - * - * Copyright (c) 2003, PostgreSQL Global Development Group - * - * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.28 2003/12/12 18:34:14 davec Exp $ - * - *------------------------------------------------------------------------- - */ -package org.postgresql.jdbc2; - -import java.io.CharArrayReader; -import java.io.InputStream; -import java.io.IOException; -import java.math.BigDecimal; -import java.sql.*; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.StringTokenizer; -import java.util.Vector; -import org.postgresql.Driver; -import org.postgresql.core.BaseStatement; -import org.postgresql.core.Field; -import org.postgresql.core.Encoding; -import org.postgresql.util.PSQLException; -import org.postgresql.util.PSQLState; - - -public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.AbstractJdbc1ResultSet -{ - - //needed for updateable result set support - protected boolean updateable = false; - protected boolean doingUpdates = false; - protected boolean onInsertRow = false; - protected Hashtable updateValues = new Hashtable(); - private boolean usingOID = false; // are we using the OID for the primary key? - private Vector primaryKeys; // list of primary keys - private int numKeys = 0; - private boolean singleTable = false; - protected String tableName = null; - protected PreparedStatement updateStatement = null; - protected PreparedStatement insertStatement = null; - protected PreparedStatement deleteStatement = null; - private PreparedStatement selectStatement = null; - - - public AbstractJdbc2ResultSet(BaseStatement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) - { - super (statement, fields, tuples, status, updateCount, insertOID, binaryCursor); - } - - public java.net.URL getURL(int columnIndex) throws SQLException - { - return null; - } - - - public java.net.URL getURL(String columnName) throws SQLException - { - return null; - } - - - /* - * Get the value of a column in the current row as a Java object - * - * <p>This method will return the value of the given column as a - * Java object. The type of the Java object will be the default - * Java Object type corresponding to the column's SQL type, following - * the mapping specified in the JDBC specification. - * - * <p>This method may also be used to read database specific abstract - * data types. - * - * @param columnIndex the first column is 1, the second is 2... - * @return a Object holding the column value - * @exception SQLException if a database access error occurs - */ - public Object getObject(int columnIndex) throws SQLException - { - Field field; - - checkResultSet( columnIndex ); - - wasNullFlag = (this_row[columnIndex - 1] == null); - if (wasNullFlag) - return null; - - field = fields[columnIndex - 1]; - - // some fields can be null, mainly from those returned by MetaData methods - if (field == null) - { - wasNullFlag = true; - return null; - } - - switch (field.getSQLType()) - { - case Types.BIT: - return getBoolean(columnIndex) ? Boolean.TRUE : Boolean.FALSE; - - case Types.SMALLINT: - return new Short(getShort(columnIndex)); - - case Types.INTEGER: - return new Integer(getInt(columnIndex)); - - case Types.BIGINT: - return new Long(getLong(columnIndex)); - - case Types.NUMERIC: - return getBigDecimal - (columnIndex, (field.getMod() == -1) ? -1 : ((field.getMod() - 4) & 0xffff)); - - case Types.REAL: - return new Float(getFloat(columnIndex)); - - case Types.DOUBLE: - return new Double(getDouble(columnIndex)); - - case Types.CHAR: - case Types.VARCHAR: - return getString(columnIndex); - - case Types.DATE: - return getDate(columnIndex); - - case Types.TIME: - return getTime(columnIndex); - - case Types.TIMESTAMP: - return getTimestamp(columnIndex); - - case Types.BINARY: - case Types.VARBINARY: - return getBytes(columnIndex); - - case Types.ARRAY: - return getArray(columnIndex); - - default: - String type = field.getPGType(); - - // if the backend doesn't know the type then coerce to String - if (type.equals("unknown")) - { - return getString(columnIndex); - } - // Specialized support for ref cursors is neater. - else if (type.equals("refcursor")) - { - String cursorName = getString(columnIndex); - return statement.createRefCursorResultSet(cursorName); - } - else - { - return connection.getObject(field.getPGType(), getString(columnIndex)); - } - } - } - - - public boolean absolute(int index) throws SQLException - { - // index is 1-based, but internally we use 0-based indices - int internalIndex; - - if (index == 0) - throw new SQLException("Cannot move to index of 0"); - - final int rows_size = rows.size(); - - //if index<0, count from the end of the result set, but check - //to be sure that it is not beyond the first index - if (index < 0) - { - if (index >= -rows_size) - internalIndex = rows_size + index; - else - { - beforeFirst(); - return false; - } - } - else - { - //must be the case that index>0, - //find the correct place, assuming that - //the index is not too large - if (index <= rows_size) - internalIndex = index - 1; - else - { - afterLast(); - return false; - } - } - - current_row = internalIndex; - this_row = (byte[][]) rows.elementAt(internalIndex); - - rowBuffer = new byte[this_row.length][]; - System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length); - - return true; - } - - - public void afterLast() throws SQLException - { - final int rows_size = rows.size(); - if (rows_size > 0) - current_row = rows_size; - } - - - public void beforeFirst() throws SQLException - { - if (rows.size() > 0) - current_row = -1; - } - - - public boolean first() throws SQLException - { - if (rows.size() <= 0) - return false; - - onInsertRow = false; - current_row = 0; - this_row = (byte[][]) rows.elementAt(current_row); - - rowBuffer = new byte[this_row.length][]; - System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length); - - return true; - } - - - public java.sql.Array getArray(String colName) throws SQLException - { - return getArray(findColumn(colName)); - } - - - public java.sql.Array getArray(int i) throws SQLException - { - checkResultSet( i ); - - wasNullFlag = (this_row[i - 1] == null); - if (wasNullFlag) - return null; - - if (i < 1 || i > fields.length) - throw new PSQLException("postgresql.res.colrange", PSQLState.INVALID_PARAMETER_VALUE); - return (java.sql.Array) new org.postgresql.jdbc2.Array( connection, i, fields[i - 1], this ); - } - - - public java.math.BigDecimal getBigDecimal(int columnIndex) throws SQLException - { - return getBigDecimal(columnIndex, -1); - } - - - public java.math.BigDecimal getBigDecimal(String columnName) throws SQLException - { - return getBigDecimal(findColumn(columnName)); - } - - - public Blob getBlob(String columnName) throws SQLException - { - return getBlob(findColumn(columnName)); - } - - - public abstract Blob getBlob(int i) throws SQLException; - - - public java.io.Reader getCharacterStream(String columnName) throws SQLException - { - return getCharacterStream(findColumn(columnName)); - } - - - public java.io.Reader getCharacterStream(int i) throws SQLException - { - checkResultSet( i ); - wasNullFlag = (this_row[i - 1] == null); - if (wasNullFlag) - return null; - - if (((AbstractJdbc2Connection) connection).haveMinimumCompatibleVersion("7.2")) - { - //Version 7.2 supports AsciiStream for all the PG text types - //As the spec/javadoc for this method indicate this is to be used for - //large text values (i.e. LONGVARCHAR) PG doesn't have a separate - //long string datatype, but with toast the text datatype is capable of - //handling very large values. Thus the implementation ends up calling - //getString() since there is no current way to stream the value from the server - return new CharArrayReader(getString(i).toCharArray()); - } - else - { - // In 7.1 Handle as BLOBS so return the LargeObject input stream - Encoding encoding = connection.getEncoding(); - InputStream input = getBinaryStream(i); - return encoding.getDecodingReader(input); - } - } - - - public Clob getClob(String columnName) throws SQLException - { - return getClob(findColumn(columnName)); - } - - - public abstract Clob getClob(int i) throws SQLException; - - - public int getConcurrency() throws SQLException - { - if (statement == null) - return java.sql.ResultSet.CONCUR_READ_ONLY; - return statement.getResultSetConcurrency(); - } - - - public java.sql.Date getDate(int i, java.util.Calendar cal) throws SQLException - { - // If I read the specs, this should use cal only if we don't - // store the timezone, and if we do, then act just like getDate()? - // for now... - return getDate(i); - } - - - public Time getTime(int i, java.util.Calendar cal) throws SQLException - { - // If I read the specs, this should use cal only if we don't - // store the timezone, and if we do, then act just like getTime()? - // for now... - return getTime(i); - } - - - public Timestamp getTimestamp(int i, java.util.Calendar cal) throws SQLException - { - // If I read the specs, this should use cal only if we don't - // store the timezone, and if we do, then act just like getDate()? - // for now... - return getTimestamp(i); - } - - - public java.sql.Date getDate(String c, java.util.Calendar cal) throws SQLException - { - return getDate(findColumn(c), cal); - } - - - public Time getTime(String c, java.util.Calendar cal) throws SQLException - { - return getTime(findColumn(c), cal); - } - - - public Timestamp getTimestamp(String c, java.util.Calendar cal) throws SQLException - { - return getTimestamp(findColumn(c), cal); - } - - - public int getFetchDirection() throws SQLException - { - //PostgreSQL normally sends rows first->last - return java.sql.ResultSet.FETCH_FORWARD; - } - - - public Object getObject(String columnName, java.util.Map map) throws SQLException - { - return getObject(findColumn(columnName), map); - } - - - /* - * This checks against map for the type of column i, and if found returns - * an object based on that mapping. The class must implement the SQLData - * interface. - */ - public Object getObject(int i, java.util.Map map) throws SQLException - { - throw org.postgresql.Driver.notImplemented(); - } - - - public Ref getRef(String columnName) throws SQLException - { - return getRef(findColumn(columnName)); - } - - - public Ref getRef(int i) throws SQLException - { - //The backend doesn't yet have SQL3 REF types - throw new PSQLException("postgresql.psqlnotimp", PSQLState.NOT_IMPLEMENTED); - } - - - public int getRow() throws SQLException - { - final int rows_size = rows.size(); - - if (current_row < 0 || current_row >= rows_size) - return 0; - - return current_row + 1; - } - - - // This one needs some thought, as not all ResultSets come from a statement - public Statement getStatement() throws SQLException - { - return (Statement) statement; - } - - - public int getType() throws SQLException - { - // This implementation allows scrolling but is not able to - // see any changes. Sub-classes may overide this to return a more - // meaningful result. - return java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE; - } - - - public boolean isAfterLast() throws SQLException - { - final int rows_size = rows.size(); - return (current_row >= rows_size && rows_size > 0); - } - - - public boolean isBeforeFirst() throws SQLException - { - return (current_row < 0 && rows.size() > 0); - } - - - public boolean isFirst() throws SQLException - { - return (current_row == 0 && rows.size() >= 0); - } - - - public boolean isLast() throws SQLException - { - final int rows_size = rows.size(); - return (current_row == rows_size - 1 && rows_size > 0); - } - - - public boolean last() throws SQLException - { - final int rows_size = rows.size(); - if (rows_size <= 0) - return false; - - current_row = rows_size - 1; - this_row = (byte[][]) rows.elementAt(current_row); - - rowBuffer = new byte[this_row.length][]; - System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length); - - return true; - } - - - public boolean previous() throws SQLException - { - if (--current_row < 0) - return false; - this_row = (byte[][]) rows.elementAt(current_row); - rowBuffer = new byte[this_row.length][]; - System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length); - return true; - } - - - public boolean relative(int rows) throws SQLException - { - //have to add 1 since absolute expects a 1-based index - return absolute(current_row + 1 + rows); - } - - - public void setFetchDirection(int direction) throws SQLException - { - throw new PSQLException("postgresql.psqlnotimp", PSQLState.NOT_IMPLEMENTED); - } - - - public synchronized void cancelRowUpdates() - throws SQLException - { - if (doingUpdates) - { - doingUpdates = false; - - clearRowBuffer(true); - } - } - - - public synchronized void deleteRow() - throws SQLException - { - if ( !isUpdateable() ) - { - throw new PSQLException( "postgresql.updateable.notupdateable" ); - } - - if (onInsertRow) - { - throw new PSQLException( "postgresql.updateable.oninsertrow" ); - } - - if (rows.size() == 0) - { - throw new PSQLException( "postgresql.updateable.emptydelete" ); - } - if (isBeforeFirst()) - { - throw new PSQLException( "postgresql.updateable.beforestartdelete" ); - } - if (isAfterLast()) - { - throw new PSQLException( "postgresql.updateable.afterlastdelete" ); - } - - - int numKeys = primaryKeys.size(); - if ( deleteStatement == null ) - { - - - StringBuffer deleteSQL = new StringBuffer("DELETE FROM " ).append(tableName).append(" where " ); - - for ( int i = 0; i < numKeys; i++ ) - { - deleteSQL.append( ((PrimaryKey) primaryKeys.get(i)).name ).append( " = ? " ); - if ( i < numKeys - 1 ) - { - deleteSQL.append( " and " ); - } - } - - deleteStatement = ((java.sql.Connection) connection).prepareStatement(deleteSQL.toString()); - } - deleteStatement.clearParameters(); - - for ( int i = 0; i < numKeys; i++ ) - { - deleteStatement.setObject(i + 1, ((PrimaryKey) primaryKeys.get(i)).getValue()); - } - - - deleteStatement.executeUpdate(); - - rows.removeElementAt(current_row); - } - - - public synchronized void insertRow() - throws SQLException - { - if ( !isUpdateable() ) - { - throw new PSQLException( "postgresql.updateable.notupdateable" ); - } - - if (!onInsertRow) - { - throw new PSQLException( "postgresql.updateable.notoninsertrow" ); - } - else - { - - // loop through the keys in the insertTable and create the sql statement - // we have to create the sql every time since the user could insert different - // columns each time - - StringBuffer insertSQL = new StringBuffer("INSERT INTO ").append(tableName).append(" ("); - StringBuffer paramSQL = new StringBuffer(") values (" ); - - Enumeration columnNames = updateValues.keys(); - int numColumns = updateValues.size(); - - for ( int i = 0; columnNames.hasMoreElements(); i++ ) - { - String columnName = (String) columnNames.nextElement(); - - insertSQL.append( columnName ); - if ( i < numColumns - 1 ) - { - insertSQL.append(", "); - paramSQL.append("?,"); - } - else - { - paramSQL.append("?)"); - } - - } - - insertSQL.append(paramSQL.toString()); - insertStatement = ((java.sql.Connection) connection).prepareStatement(insertSQL.toString()); - - Enumeration keys = updateValues.keys(); - - for ( int i = 1; keys.hasMoreElements(); i++) - { - String key = (String) keys.nextElement(); - Object o = updateValues.get(key); - if (o instanceof NullObject) - insertStatement.setNull(i,java.sql.Types.NULL); - else - insertStatement.setObject(i, o); - } - - insertStatement.executeUpdate(); - - if ( usingOID ) - { - // we have to get the last inserted OID and put it in the resultset - - long insertedOID = ((AbstractJdbc2Statement) insertStatement).getLastOID(); - - updateValues.put("oid", new Long(insertedOID) ); - - } - - // update the underlying row to the new inserted data - updateRowBuffer(); - - rows.addElement(rowBuffer); - - // we should now reflect the current data in this_row - // that way getXXX will get the newly inserted data - this_row = rowBuffer; - - // need to clear this in case of another insert - clearRowBuffer(false); - - - } - } - - - public synchronized void moveToCurrentRow() - throws SQLException - { - if (!updateable) - { - throw new PSQLException( "postgresql.updateable.notupdateable" ); - } - - if (current_row < 0) { - this_row = null; - rowBuffer = null; - } else { - this_row = (byte[][]) rows.elementAt(current_row); - - rowBuffer = new byte[this_row.length][]; - System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length); - } - - onInsertRow = false; - doingUpdates = false; - } - - - public synchronized void moveToInsertRow() - throws SQLException - { - if ( !isUpdateable() ) - { - throw new PSQLException( "postgresql.updateable.notupdateable" ); - } - - if (insertStatement != null) - { - insertStatement = null; - } - - - // make sure the underlying data is null - clearRowBuffer(false); - - onInsertRow = true; - doingUpdates = false; - - } - - - private synchronized void clearRowBuffer(boolean copyCurrentRow) - throws SQLException - { - // rowBuffer is the temporary storage for the row - rowBuffer = new byte[fields.length][]; - - // inserts want an empty array while updates want a copy of the current row - if (copyCurrentRow) { - System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length); - } - - // clear the updateValues hashTable for the next set of updates - updateValues.clear(); - - } - - - public boolean rowDeleted() throws SQLException - { - // only sub-classes implement CONCURuPDATEABLE - throw Driver.notImplemented(); - } - - - public boolean rowInserted() throws SQLException - { - // only sub-classes implement CONCURuPDATEABLE - throw Driver.notImplemented(); - } - - - public boolean rowUpdated() throws SQLException - { - // only sub-classes implement CONCURuPDATEABLE - throw Driver.notImplemented(); - } - - - public synchronized void updateAsciiStream(int columnIndex, - java.io.InputStream x, - int length - ) - throws SQLException - { - byte[] theData = null; - try - { - x.read(theData, 0, length); - } - catch (NullPointerException ex ) - { - throw new PSQLException("postgresql.updateable.inputstream"); - } - catch (IOException ie) - { - throw new PSQLException("postgresql.updateable.ioerror", ie); - } - - updateValue(columnIndex, theData); - } - - - public synchronized void updateBigDecimal(int columnIndex, - java.math.BigDecimal x ) - throws SQLException - { - updateValue(columnIndex, x); - } - - - public synchronized void updateBinaryStream(int columnIndex, - java.io.InputStream x, - int length - ) - throws SQLException - { - byte[] theData = null; - try - { - x.read(theData, 0, length); - - } - catch ( NullPointerException ex ) - { - throw new PSQLException("postgresql.updateable.inputstream"); - } - catch (IOException ie) - { - throw new PSQLException("postgresql.updateable.ioerror", ie); - } - updateValue(columnIndex, theData); - } - - - public synchronized void updateBoolean(int columnIndex, boolean x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("updating boolean " + fields[columnIndex - 1].getName() + "=" + x); - updateValue(columnIndex, new Boolean(x)); - } - - - public synchronized void updateByte(int columnIndex, byte x) - throws SQLException - { - updateValue(columnIndex, String.valueOf(x)); - } - - - public synchronized void updateBytes(int columnIndex, byte[] x) - throws SQLException - { - updateValue(columnIndex, x); - } - - - public synchronized void updateCharacterStream(int columnIndex, - java.io.Reader x, - int length - ) - throws SQLException - { - char[] theData = null; - try - { - x.read(theData, 0, length); - - } - catch (NullPointerException ex) - { - throw new PSQLException("postgresql.updateable.inputstream"); - } - catch (IOException ie) - { - throw new PSQLException("postgresql.updateable.ioerror", ie); - } - updateValue(columnIndex, theData); - } - - - public synchronized void updateDate(int columnIndex, java.sql.Date x) - throws SQLException - { - updateValue(columnIndex, x); - } - - - public synchronized void updateDouble(int columnIndex, double x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("updating double " + fields[columnIndex - 1].getName() + "=" + x); - updateValue(columnIndex, new Double(x)); - } - - - public synchronized void updateFloat(int columnIndex, float x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("updating float " + fields[columnIndex - 1].getName() + "=" + x); - updateValue(columnIndex, new Float(x)); - } - - - public synchronized void updateInt(int columnIndex, int x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("updating int " + fields[columnIndex - 1].getName() + "=" + x); - updateValue(columnIndex, new Integer(x)); - } - - - public synchronized void updateLong(int columnIndex, long x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("updating long " + fields[columnIndex - 1].getName() + "=" + x); - updateValue(columnIndex, new Long(x)); - } - - - public synchronized void updateNull(int columnIndex) - throws SQLException - { - updateValue(columnIndex, new NullObject()); - } - - - public synchronized void updateObject(int columnIndex, Object x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("updating object " + fields[columnIndex - 1].getName() + " = " + x); - updateValue(columnIndex, x); - } - - - public synchronized void updateObject(int columnIndex, Object x, int scale) - throws SQLException - { - if ( !isUpdateable() ) - { - throw new PSQLException( "postgresql.updateable.notupdateable" ); - } - - this.updateObject(columnIndex, x); - - } - - - public void refreshRow() throws SQLException - { - if ( !isUpdateable() ) - { - throw new PSQLException( "postgresql.updateable.notupdateable" ); - } - - try - { - StringBuffer selectSQL = new StringBuffer( "select "); - - final int numColumns = java.lang.reflect.Array.getLength(fields); - - for (int i = 0; i < numColumns; i++ ) - { - - selectSQL.append( fields[i].getName() ); - - if ( i < numColumns - 1 ) - { - - selectSQL.append(", "); - } - - } - selectSQL.append(" from " ).append(tableName).append(" where "); - - int numKeys = primaryKeys.size(); - - for ( int i = 0; i < numKeys; i++ ) - { - - PrimaryKey primaryKey = ((PrimaryKey) primaryKeys.get(i)); - selectSQL.append(primaryKey.name).append("= ?"); - - if ( i < numKeys - 1 ) - { - selectSQL.append(" and "); - } - } - if ( Driver.logDebug ) - Driver.debug("selecting " + selectSQL.toString()); - selectStatement = ((java.sql.Connection) connection).prepareStatement(selectSQL.toString()); - - - for ( int j = 0, i = 1; j < numKeys; j++, i++) - { - selectStatement.setObject( i, ((PrimaryKey) primaryKeys.get(j)).getValue() ); - } - - AbstractJdbc2ResultSet rs = (AbstractJdbc2ResultSet) selectStatement.executeQuery(); - - if ( rs.first() ) - { - rowBuffer = rs.rowBuffer; - } - - rows.setElementAt( rowBuffer, current_row ); - this_row = rowBuffer; - if ( Driver.logDebug ) - Driver.debug("done updates"); - - rs.close(); - selectStatement.close(); - selectStatement = null; - - } - catch (Exception e) - { - if ( Driver.logDebug ) - Driver.debug(e.getClass().getName() + e); - throw new SQLException( e.getMessage() ); - } - - } - - - public synchronized void updateRow() - throws SQLException - { - if ( !isUpdateable() ) - { - throw new PSQLException( "postgresql.updateable.notupdateable" ); - } - - if (doingUpdates) - { - - try - { - - StringBuffer updateSQL = new StringBuffer("UPDATE " + tableName + " SET "); - - int numColumns = updateValues.size(); - Enumeration columns = updateValues.keys(); - - for (int i = 0; columns.hasMoreElements(); i++ ) - { - - String column = (String) columns.nextElement(); - updateSQL.append("\""); - updateSQL.append( column ); - updateSQL.append("\" = ?"); - - if ( i < numColumns - 1 ) - { - - updateSQL.append(", "); - } - - } - updateSQL.append( " WHERE " ); - - int numKeys = primaryKeys.size(); - - for ( int i = 0; i < numKeys; i++ ) - { - - PrimaryKey primaryKey = ((PrimaryKey) primaryKeys.get(i)); - updateSQL.append("\""); - updateSQL.append(primaryKey.name); - updateSQL.append("\" = ?"); - - if ( i < numKeys - 1 ) - { - updateSQL.append(" and "); - } - } - if ( Driver.logDebug ) - Driver.debug("updating " + updateSQL.toString()); - updateStatement = ((java.sql.Connection) connection).prepareStatement(updateSQL.toString()); - - int i = 0; - Iterator iterator = updateValues.values().iterator(); - for (; iterator.hasNext(); i++) - { - Object o = iterator.next(); - if (o instanceof NullObject) - updateStatement.setNull(i+1,java.sql.Types.NULL); - else - updateStatement.setObject( i + 1, o ); - - } - for ( int j = 0; j < numKeys; j++, i++) - { - updateStatement.setObject( i + 1, ((PrimaryKey) primaryKeys.get(j)).getValue() ); - } - - updateStatement.executeUpdate(); - updateStatement.close(); - - updateStatement = null; - updateRowBuffer(); - - - if ( Driver.logDebug ) - Driver.debug("copying data"); - System.arraycopy(rowBuffer, 0, this_row, 0, rowBuffer.length); - - rows.setElementAt( rowBuffer, current_row ); - if ( Driver.logDebug ) - Driver.debug("done updates"); - updateValues.clear(); - doingUpdates = false; - } - catch (Exception e) - { - if ( Driver.logDebug ) - Driver.debug(e.getClass().getName() + e); - throw new SQLException( e.getMessage() ); - } - - } - - } - - - public synchronized void updateShort(int columnIndex, short x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("in update Short " + fields[columnIndex - 1].getName() + " = " + x); - updateValue(columnIndex, new Short(x)); - } - - - public synchronized void updateString(int columnIndex, String x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("in update String " + fields[columnIndex - 1].getName() + " = " + x); - updateValue(columnIndex, x); - } - - - public synchronized void updateTime(int columnIndex, Time x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("in update Time " + fields[columnIndex - 1].getName() + " = " + x); - updateValue(columnIndex, x); - } - - - public synchronized void updateTimestamp(int columnIndex, Timestamp x) - throws SQLException - { - if ( Driver.logDebug ) - Driver.debug("updating Timestamp " + fields[columnIndex - 1].getName() + " = " + x); - updateValue(columnIndex, x); - - } - - - public synchronized void updateNull(String columnName) - throws SQLException - { - updateNull(findColumn(columnName)); - } - - - public synchronized void updateBoolean(String columnName, boolean x) - throws SQLException - { - updateBoolean(findColumn(columnName), x); - } - - - public synchronized void updateByte(String columnName, byte x) - throws SQLException - { - updateByte(findColumn(columnName), x); - } - - - public synchronized void updateShort(String columnName, short x) - throws SQLException - { - updateShort(findColumn(columnName), x); - } - - - public synchronized void updateInt(String columnName, int x) - throws SQLException - { - updateInt(findColumn(columnName), x); - } - - - public synchronized void updateLong(String columnName, long x) - throws SQLException - { - updateLong(findColumn(columnName), x); - } - - - public synchronized void updateFloat(String columnName, float x) - throws SQLException - { - updateFloat(findColumn(columnName), x); - } - - - public synchronized void updateDouble(String columnName, double x) - throws SQLException - { - updateDouble(findColumn(columnName), x); - } - - - public synchronized void updateBigDecimal(String columnName, BigDecimal x) - throws SQLException - { - updateBigDecimal(findColumn(columnName), x); - } - - - public synchronized void updateString(String columnName, String x) - throws SQLException - { - updateString(findColumn(columnName), x); - } - - - public synchronized void updateBytes(String columnName, byte x[]) - throws SQLException - { - updateBytes(findColumn(columnName), x); - } - - - public synchronized void updateDate(String columnName, java.sql.Date x) - throws SQLException - { - updateDate(findColumn(columnName), x); - } - - - public synchronized void updateTime(String columnName, java.sql.Time x) - throws SQLException - { - updateTime(findColumn(columnName), x); - } - - - public synchronized void updateTimestamp(String columnName, java.sql.Timestamp x) - throws SQLException - { - updateTimestamp(findColumn(columnName), x); - } - - - public synchronized void updateAsciiStream( - String columnName, - java.io.InputStream x, - int length) - throws SQLException - { - updateAsciiStream(findColumn(columnName), x, length); - } - - - public synchronized void updateBinaryStream( - String columnName, - java.io.InputStream x, - int length) - throws SQLException - { - updateBinaryStream(findColumn(columnName), x, length); - } - - - public synchronized void updateCharacterStream( - String columnName, - java.io.Reader reader, - int length) - throws SQLException - { - updateCharacterStream(findColumn(columnName), reader, length); - } - - - public synchronized void updateObject(String columnName, Object x, int scale) - throws SQLException - { - updateObject(findColumn(columnName), x); - } - - - public synchronized void updateObject(String columnName, Object x) - throws SQLException - { - updateObject(findColumn(columnName), x); - } - - - /** - * Is this ResultSet updateable? - */ - - boolean isUpdateable() throws SQLException - { - - if (updateable) - return true; - - if ( Driver.logDebug ) - Driver.debug("checking if rs is updateable"); - - parseQuery(); - - if ( singleTable == false ) - { - if ( Driver.logDebug ) - Driver.debug("not a single table"); - return false; - } - - if ( Driver.logDebug ) - Driver.debug("getting primary keys"); - - // - // Contains the primary key? - // - - primaryKeys = new Vector(); - - // this is not stricty jdbc spec, but it will make things much faster if used - // the user has to select oid, * from table and then we will just use oid - - - usingOID = false; - int oidIndex = 0; - try { - oidIndex = findColumn( "oid" ); - } catch (SQLException l_se) { - //Ignore if column oid isn't selected - } - int i = 0; - - - // if we find the oid then just use it - - //oidIndex will be >0 if the oid was in the select list - if ( oidIndex > 0 ) - { - i++; - primaryKeys.add( new PrimaryKey( oidIndex, "oid" ) ); - usingOID = true; - } - else - { - // otherwise go and get the primary keys and create a hashtable of keys - String[] s = quotelessTableName(tableName); - String quotelessTableName = s[0]; - String quotelessSchemaName = s[1]; - java.sql.ResultSet rs = ((java.sql.Connection) connection).getMetaData().getPrimaryKeys("", quotelessSchemaName, quotelessTableName); - for (; rs.next(); i++ ) - { - String columnName = rs.getString(4); // get the columnName - int index = findColumn( columnName ); - - if ( index > 0 ) - { - primaryKeys.add( new PrimaryKey(index, columnName ) ); // get the primary key information - } - } - - rs.close(); - } - - numKeys = primaryKeys.size(); - - if ( Driver.logDebug ) - Driver.debug( "no of keys=" + i ); - - if ( i < 1 ) - { - throw new SQLException("No Primary Keys"); - } - - updateable = primaryKeys.size() > 0; - - if ( Driver.logDebug ) - Driver.debug( "checking primary key " + updateable ); - - return updateable; - } - - /** Cracks out the table name and schema (if it exists) from a fully - * qualified table name. - * @param fullname string that we are trying to crack. Test cases:<pre> - * Table: table () - * "Table": Table () - * Schema.Table: table (schema) - * "Schema"."Table": Table (Schema) - * "Schema"."Dot.Table": Dot.Table (Schema) - * Schema."Dot.Table": Dot.Table (schema) - * </pre> - * @return String array with element zero always being the tablename and - * element 1 the schema name which may be a zero length string. - */ - public static String[] quotelessTableName(String fullname) { - StringBuffer buf = new StringBuffer(fullname); - String[] parts = new String[] {null, ""}; - StringBuffer acc = new StringBuffer(); - boolean betweenQuotes = false; - for (int i = 0; i < buf.length(); i++) { - char c = buf.charAt(i); - switch (c) { - case '"': - if ((i < buf.length() - 1) && (buf.charAt(i+1) == '"')) { - // two consecutive quotes - keep one - i++; - acc.append(c); // keep the quote - } - else { // Discard it - betweenQuotes = !betweenQuotes; - } - break; - case '.': - if (betweenQuotes) { // Keep it - acc.append(c); - } - else { // Have schema name - parts[1] = acc.toString(); - acc = new StringBuffer(); - } - break; - default: - acc.append((betweenQuotes) ? c : Character.toLowerCase(c)); - break; - } - } - // Always put table in slot 0 - parts[0] = acc.toString(); - return parts; - } - - public void parseQuery() - { - String[] l_sqlFragments = ((AbstractJdbc2Statement)statement).getSqlFragments(); - String l_sql = l_sqlFragments[0]; - StringTokenizer st = new StringTokenizer(l_sql, " \r\t\n"); - boolean tableFound = false, tablesChecked = false; - String name = ""; - - singleTable = true; - - while ( !tableFound && !tablesChecked && st.hasMoreTokens() ) - { - name = st.nextToken(); - if ( !tableFound ) - { - if (name.toLowerCase().equals("from")) - { - tableName = st.nextToken(); - tableFound = true; - } - } - else - { - tablesChecked = true; - // if the very next token is , then there are multiple tables - singleTable = !name.equalsIgnoreCase(","); - } - } - } - - - private void updateRowBuffer() throws SQLException - { - - Enumeration columns = updateValues.keys(); - - while ( columns.hasMoreElements() ) - { - String columnName = (String) columns.nextElement(); - int columnIndex = findColumn( columnName ) - 1; - - Object valueObject = updateValues.get(columnName); - if (valueObject instanceof NullObject) { - rowBuffer[columnIndex] = null; - } - else - { - - switch ( connection.getSQLType( fields[columnIndex].getPGType() ) ) - { - - case Types.DECIMAL: - case Types.BIGINT: - case Types.DOUBLE: - case Types.BIT: - case Types.VARCHAR: - case Types.DATE: - case Types.TIME: - case Types.TIMESTAMP: - case Types.SMALLINT: - case Types.FLOAT: - case Types.INTEGER: - case Types.CHAR: - case Types.NUMERIC: - case Types.REAL: - case Types.TINYINT: - - rowBuffer[columnIndex] = connection.getEncoding().encode(String.valueOf( valueObject)); - - case Types.NULL: - continue; - - default: - rowBuffer[columnIndex] = (byte[]) valueObject; - } - - } - } - } - - - public void setStatement(BaseStatement statement) - { - this.statement = statement; - } - - protected void updateValue(int columnIndex, Object value) throws SQLException { - if ( !isUpdateable() ) - { - throw new PSQLException( "postgresql.updateable.notupdateable" ); - } - doingUpdates = !onInsertRow; - if (value == null) - updateNull(columnIndex); - else - updateValues.put(fields[columnIndex - 1].getName(), value); - } - - private class PrimaryKey - { - int index; // where in the result set is this primaryKey - String name; // what is the columnName of this primary Key - - PrimaryKey( int index, String name) - { - this.index = index; - this.name = name; - } - Object getValue() throws SQLException - { - return getObject(index); - } - }; - - class NullObject { - }; - -} - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java deleted file mode 100644 index d65634a60d..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java +++ /dev/null @@ -1,553 +0,0 @@ -package org.postgresql.jdbc2; - - -import org.postgresql.core.Field; -import org.postgresql.util.PSQLException; -import org.postgresql.util.PSQLState; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Vector; - -public abstract class AbstractJdbc2ResultSetMetaData extends org.postgresql.jdbc1.AbstractJdbc1ResultSetMetaData -{ - - /* - * Initialise for a result with a tuple set and - * a field descriptor set - * - * @param rows the Vector of rows returned by the ResultSet - * @param fields the array of field descriptors - */ - public AbstractJdbc2ResultSetMetaData(Vector rows, Field[] fields) - { - super(rows, fields); - } - - /* - * Whats the number of columns in the ResultSet? - * - * @return the number - * @exception SQLException if a database access error occurs - */ - public int getColumnCount() throws SQLException - { - return fields.length; - } - - /* - * Is the column automatically numbered (and thus read-only) - * I believe that PostgreSQL does not support this feature. - * - * @param column the first column is 1, the second is 2... - * @return true if so - * @exception SQLException if a database access error occurs - */ - public boolean isAutoIncrement(int column) throws SQLException - { - return false; - } - - /* - * Does a column's case matter? ASSUMPTION: Any field that is - * not obviously case insensitive is assumed to be case sensitive - * - * @param column the first column is 1, the second is 2... - * @return true if so - * @exception SQLException if a database access error occurs - */ - public boolean isCaseSensitive(int column) throws SQLException - { - int sql_type = getField(column).getSQLType(); - - switch (sql_type) - { - case Types.SMALLINT: - case Types.INTEGER: - case Types.FLOAT: - case Types.REAL: - case Types.DOUBLE: - case Types.DATE: - case Types.TIME: - case Types.TIMESTAMP: - return false; - default: - return true; - } - } - - /* - * Can the column be used in a WHERE clause? Basically for - * this, I split the functions into two types: recognised - * types (which are always useable), and OTHER types (which - * may or may not be useable). The OTHER types, for now, I - * will assume they are useable. We should really query the - * catalog to see if they are useable. - * - * @param column the first column is 1, the second is 2... - * @return true if they can be used in a WHERE clause - * @exception SQLException if a database access error occurs - */ - public boolean isSearchable(int column) throws SQLException - { - int sql_type = getField(column).getSQLType(); - - // This switch is pointless, I know - but it is a set-up - // for further expansion. - switch (sql_type) - { - case Types.OTHER: - return true; - default: - return true; - } - } - - /* - * Is the column a cash value? 6.1 introduced the cash/money - * type, which haven't been incorporated as of 970414, so I - * just check the type name for both 'cash' and 'money' - * - * @param column the first column is 1, the second is 2... - * @return true if its a cash column - * @exception SQLException if a database access error occurs - */ - public boolean isCurrency(int column) throws SQLException - { - String type_name = getField(column).getPGType(); - - return type_name.equals("cash") || type_name.equals("money"); - } - - /* - * Indicates the nullability of values in the designated column. - * - * @param column the first column is 1, the second is 2... - * @return one of the columnNullable values - * @exception SQLException if a database access error occurs - */ - public int isNullable(int column) throws SQLException - { - /* - * TODO This needs a real implementation, taking into account columns - * defined with NOT NULL or PRIMARY KEY, CHECK constraints, views, - * functions etc. - */ - return java.sql.ResultSetMetaData.columnNullableUnknown; - } - - /* - * Is the column a signed number? In PostgreSQL, all numbers - * are signed, so this is trivial. However, strings are not - * signed (duh!) - * - * @param column the first column is 1, the second is 2... - * @return true if so - * @exception SQLException if a database access error occurs - */ - public boolean isSigned(int column) throws SQLException - { - int sql_type = getField(column).getSQLType(); - - switch (sql_type) - { - case Types.SMALLINT: - case Types.INTEGER: - case Types.FLOAT: - case Types.REAL: - case Types.DOUBLE: - return true; - case Types.DATE: - case Types.TIME: - case Types.TIMESTAMP: - return false; // I don't know about these? - default: - return false; - } - } - - /* - * What is the column's normal maximum width in characters? - * - * @param column the first column is 1, the second is 2, etc. - * @return the maximum width - * @exception SQLException if a database access error occurs - */ - public int getColumnDisplaySize(int column) throws SQLException - { - Field f = getField(column); - String type_name = f.getPGType(); - int typmod = f.getMod(); - - // I looked at other JDBC implementations and couldn't find a consistent - // interpretation of the "display size" for numeric values, so this is our's - // FIXME: currently, only types with a SQL92 or SQL3 pendant are implemented - jens@jens.de - - // fixed length data types - if (type_name.equals( "int2" )) - return 6; // -32768 to +32768 (5 digits and a sign) - if (type_name.equals( "int4" ) - || type_name.equals( "oid" )) - return 11; // -2147483648 to +2147483647 - if (type_name.equals( "int8" )) - return 20; // -9223372036854775808 to +9223372036854775807 - if (type_name.equals( "money" )) - return 12; // MONEY = DECIMAL(9,2) - if (type_name.equals( "float4" )) - return 11; // i checked it out ans wasn't able to produce more than 11 digits - if (type_name.equals( "float8" )) - return 20; // dito, 20 - if (type_name.equals( "char" )) - return 1; - if (type_name.equals( "bool" )) - return 1; - if (type_name.equals( "date" )) - return 14; // "01/01/4713 BC" - "31/12/32767 AD" - if (type_name.equals( "time" )) - return 8; // 00:00:00-23:59:59 - if (type_name.equals( "timestamp" )) - return 22; // hhmmm ... the output looks like this: 1999-08-03 22:22:08+02 - - // variable length fields - typmod -= 4; - if (type_name.equals( "bpchar" ) - || type_name.equals( "varchar" )) - return typmod; // VARHDRSZ=sizeof(int32)=4 - if (type_name.equals( "numeric" )) - return ( (typmod >> 16) & 0xffff ) - + 1 + ( typmod & 0xffff ); // DECIMAL(p,s) = (p digits).(s digits) - - // if we don't know better - return f.getLength(); - } - - /* - * What is the suggested column title for use in printouts and - * displays? We suggest the ColumnName! - * - * @param column the first column is 1, the second is 2, etc. - * @return the column label - * @exception SQLException if a database access error occurs - */ - public String getColumnLabel(int column) throws SQLException - { - return getColumnName(column); - } - - /* - * What's a column's name? - * - * @param column the first column is 1, the second is 2, etc. - * @return the column name - * @exception SQLException if a database access error occurs - */ - public String getColumnName(int column) throws SQLException - { - Field f = getField(column); - if (f != null) - return f.getName(); - return "field" + column; - } - - /* - * What is a column's table's schema? This relies on us knowing - * the table name....which I don't know how to do as yet. The - * JDBC specification allows us to return "" if this is not - * applicable. - * - * @param column the first column is 1, the second is 2... - * @return the Schema - * @exception SQLException if a database access error occurs - */ - public String getSchemaName(int column) throws SQLException - { - return ""; - } - - /* - * What is a column's number of decimal digits. - * - * @param column the first column is 1, the second is 2... - * @return the precision - * @exception SQLException if a database access error occurs - */ - public int getPrecision(int column) throws SQLException - { - int sql_type = getField(column).getSQLType(); - - switch (sql_type) - { - 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"); - } - } -} - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java deleted file mode 100644 index d96f0f97f9..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java +++ /dev/null @@ -1,434 +0,0 @@ -package org.postgresql.jdbc2; - - -import java.io.*; -import java.math.*; -import java.sql.*; -import java.util.Vector; -import org.postgresql.Driver; -import org.postgresql.largeobject.*; -import org.postgresql.util.PSQLException; -import org.postgresql.util.PSQLState; - -/* $PostgreSQL: pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.18 2003/11/29 19:52:10 pgsql Exp $ - * This class defines methods of the jdbc2 specification. This class extends - * org.postgresql.jdbc1.AbstractJdbc1Statement which provides the jdbc1 - * methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Statement - */ -public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.AbstractJdbc1Statement -{ - - protected Vector batch = null; - protected int resultsettype; // the resultset type to return - protected int concurrency; // is it updateable or not? - - public AbstractJdbc2Statement (AbstractJdbc2Connection c) - { - super(c); - resultsettype = ResultSet.TYPE_SCROLL_INSENSITIVE; - concurrency = ResultSet.CONCUR_READ_ONLY; - } - - public AbstractJdbc2Statement(AbstractJdbc2Connection connection, String sql) throws SQLException - { - super(connection, sql); - } - - /* - * Execute a SQL statement that may return multiple results. We - * don't have to worry about this since we do not support multiple - * ResultSets. You can use getResultSet or getUpdateCount to - * retrieve the result. - * - * @param sql any SQL statement - * @return true if the next result is a ResulSet, false if it is - * an update count or there are no more results - * @exception SQLException if a database access error occurs - */ - public boolean execute() throws SQLException - { - boolean l_return = super.execute(); - //Now do the jdbc2 specific stuff - //required for ResultSet.getStatement() to work and updateable resultsets - result.setStatement(this); - - return l_return; - } - - // ** JDBC 2 Extensions ** - - public void addBatch(String p_sql) throws SQLException - { - if (batch == null) - batch = new Vector(); - Object[] l_statement = new Object[] {new String[] {p_sql}, new Object[0], new String[0]}; - batch.addElement(l_statement); - } - - public void clearBatch() throws SQLException - { - batch = null; - } - - public int[] executeBatch() throws SQLException - { - if (batch == null) - batch = new Vector(); - int size = batch.size(); - int[] result = new int[size]; - int i = 0; - try - { - //copy current state of statement - String[] l_origSqlFragments = m_sqlFragments; - Object[] l_origBinds = m_binds; - String[] l_origBindTypes = m_bindTypes; - - for (i = 0;i < size;i++) { - //set state from batch - Object[] l_statement = (Object[])batch.elementAt(i); - this.m_sqlFragments = (String[])l_statement[0]; - this.m_binds = (Object[])l_statement[1]; - this.m_bindTypes = (String[])l_statement[2]; - result[i] = this.executeUpdate(); - } - - //restore state of statement - m_sqlFragments = l_origSqlFragments; - m_binds = l_origBinds; - m_bindTypes = l_origBindTypes; - - } - catch (SQLException e) - { - int[] resultSucceeded = new int[i]; - System.arraycopy(result, 0, resultSucceeded, 0, i); - - PBatchUpdateException updex = - new PBatchUpdateException("postgresql.stat.batch.error", - new Integer(i), m_sqlFragments[0], resultSucceeded); - updex.setNextException(e); - - throw updex; - } - finally - { - batch.removeAllElements(); - } - return result; - } - - public void cancel() throws SQLException - { - connection.cancelQuery(); - } - - public Connection getConnection() throws SQLException - { - return (Connection) connection; - } - - public int getFetchDirection() throws SQLException - { - throw new PSQLException("postgresql.psqlnotimp", PSQLState.NOT_IMPLEMENTED); - } - - public int getResultSetConcurrency() throws SQLException - { - return concurrency; - } - - public int getResultSetType() throws SQLException - { - return resultsettype; - } - - public void setFetchDirection(int direction) throws SQLException - { - // I don't think this should happen, since it's a hint it should just - // fail quietly. - // throw Driver.notImplemented(); - } - - public void setFetchSize(int rows) throws SQLException - { - if (rows<0) throw new PSQLException("postgresql.input.fetch.gt0"); - super.fetchSize = rows; - } - - public void setResultSetConcurrency(int value) throws SQLException - { - concurrency = value; - } - - public void setResultSetType(int value) throws SQLException - { - resultsettype = value; - } - - public void addBatch() throws SQLException - { - if (batch == null) - batch = new Vector(); - - //we need to create copies, otherwise the values can be changed - Object[] l_newSqlFragments = null; - if (m_sqlFragments != null) { - l_newSqlFragments = new String[m_sqlFragments.length]; - System.arraycopy(m_sqlFragments,0,l_newSqlFragments,0,m_sqlFragments.length); - } - Object[] l_newBinds = new Object[m_binds.length]; - System.arraycopy(m_binds,0,l_newBinds,0,m_binds.length); - String[] l_newBindTypes = new String[m_bindTypes.length]; - System.arraycopy(m_bindTypes,0,l_newBindTypes,0,m_bindTypes.length); - Object[] l_statement = new Object[] {l_newSqlFragments, l_newBinds, l_newBindTypes}; - batch.addElement(l_statement); - } - - public ResultSetMetaData getMetaData() throws SQLException - { - ResultSet rs = getResultSet(); - if (rs != null) - return rs.getMetaData(); - - // Does anyone really know what this method does? - return null; - } - - public void setArray(int i, java.sql.Array x) throws SQLException - { - setString(i, x.toString()); - } - - public void setBlob(int i, Blob x) throws SQLException - { - InputStream l_inStream = x.getBinaryStream(); - LargeObjectManager lom = connection.getLargeObjectAPI(); - int oid = lom.create(); - LargeObject lob = lom.open(oid); - OutputStream los = lob.getOutputStream(); - byte[] buf = new byte[4096]; - try - { - // could be buffered, but then the OutputStream returned by LargeObject - // is buffered internally anyhow, so there would be no performance - // boost gained, if anything it would be worse! - int bytesRemaining = (int)x.length(); - int numRead = l_inStream.read(buf, 0, Math.min(buf.length, bytesRemaining)); - while (numRead != -1 && bytesRemaining > 0) - { - bytesRemaining -= numRead; - if ( numRead == buf.length ) - los.write(buf); // saves a buffer creation and copy in LargeObject since it's full - else - los.write(buf,0,numRead); - numRead = l_inStream.read(buf, 0, Math.min(buf.length, bytesRemaining)); - } - } - catch (IOException se) - { - throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, se); - } - finally - { - try - { - los.close(); - l_inStream.close(); - } - catch( Exception e ) {} - } - setInt(i, oid); - } - - public void setCharacterStream(int i, java.io.Reader x, int length) throws SQLException - { - if (connection.haveMinimumCompatibleVersion("7.2")) - { - //Version 7.2 supports CharacterStream for for the PG text types - //As the spec/javadoc for this method indicate this is to be used for - //large text values (i.e. LONGVARCHAR) PG doesn't have a separate - //long varchar datatype, but with toast all the text datatypes are capable of - //handling very large values. Thus the implementation ends up calling - //setString() since there is no current way to stream the value to the server - char[] l_chars = new char[length]; - int l_charsRead; - try - { - l_charsRead = x.read(l_chars, 0, length); - } - catch (IOException l_ioe) - { - throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_ioe); - } - setString(i, new String(l_chars, 0, l_charsRead)); - } - else - { - //Version 7.1 only supported streams for LargeObjects - //but the jdbc spec indicates that streams should be - //available for LONGVARCHAR instead - LargeObjectManager lom = connection.getLargeObjectAPI(); - int oid = lom.create(); - LargeObject lob = lom.open(oid); - OutputStream los = lob.getOutputStream(); - try - { - // could be buffered, but then the OutputStream returned by LargeObject - // is buffered internally anyhow, so there would be no performance - // boost gained, if anything it would be worse! - int c = x.read(); - int p = 0; - while (c > -1 && p < length) - { - los.write(c); - c = x.read(); - p++; - } - los.close(); - } - catch (IOException se) - { - throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, se); - } - // lob is closed by the stream so don't call lob.close() - setInt(i, oid); - } - } - - public void setClob(int i, Clob x) throws SQLException - { - InputStream l_inStream = x.getAsciiStream(); - int l_length = (int) x.length(); - LargeObjectManager lom = connection.getLargeObjectAPI(); - int oid = lom.create(); - LargeObject lob = lom.open(oid); - OutputStream los = lob.getOutputStream(); - try - { - // could be buffered, but then the OutputStream returned by LargeObject - // is buffered internally anyhow, so there would be no performance - // boost gained, if anything it would be worse! - int c = l_inStream.read(); - int p = 0; - while (c > -1 && p < l_length) - { - los.write(c); - c = l_inStream.read(); - p++; - } - los.close(); - } - catch (IOException se) - { - throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, se); - } - // lob is closed by the stream so don't call lob.close() - setInt(i, oid); - } - - public void setNull(int i, int t, String s) throws SQLException - { - setNull(i, t); - } - - public void setRef(int i, Ref x) throws SQLException - { - throw Driver.notImplemented(); - } - - public void setDate(int i, java.sql.Date d, java.util.Calendar cal) throws SQLException - { - if (cal == null) - setDate(i, d); - else - { - cal.setTime(d); - setDate(i, new java.sql.Date(cal.getTime().getTime())); - } - } - - public void setTime(int i, Time t, java.util.Calendar cal) throws SQLException - { - if (cal == null) - setTime(i, t); - else - { - cal.setTime(t); - setTime(i, new java.sql.Time(cal.getTime().getTime())); - } - } - - public void setTimestamp(int i, Timestamp t, java.util.Calendar cal) throws SQLException - { - if (cal == null) - setTimestamp(i, t); - else - { - cal.setTime(t); - setTimestamp(i, new java.sql.Timestamp(cal.getTime().getTime())); - } - } - - // ** JDBC 2 Extensions for CallableStatement** - - public java.sql.Array getArray(int i) throws SQLException - { - throw Driver.notImplemented(); - } - - public java.math.BigDecimal getBigDecimal(int parameterIndex) throws SQLException - { - checkIndex (parameterIndex, Types.NUMERIC, "BigDecimal"); - return ((BigDecimal)callResult); - } - - public Blob getBlob(int i) throws SQLException - { - throw Driver.notImplemented(); - } - - public Clob getClob(int i) throws SQLException - { - throw Driver.notImplemented(); - } - - public Object getObject(int i, java.util.Map map) throws SQLException - { - throw Driver.notImplemented(); - } - - public Ref getRef(int i) throws SQLException - { - throw Driver.notImplemented(); - } - - public java.sql.Date getDate(int i, java.util.Calendar cal) throws SQLException - { - throw Driver.notImplemented(); - } - - public Time getTime(int i, java.util.Calendar cal) throws SQLException - { - throw Driver.notImplemented(); - } - - public Timestamp getTimestamp(int i, java.util.Calendar cal) throws SQLException - { - throw Driver.notImplemented(); - } - - // no custom types allowed yet.. - public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException - { - throw Driver.notImplemented(); - } - - - //This is needed by AbstractJdbc2ResultSet to determine if the query is updateable or not - protected String[] getSqlFragments() - { - return m_sqlFragments; - } - -} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java deleted file mode 100644 index e38b0c92ed..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java +++ /dev/null @@ -1,364 +0,0 @@ -package org.postgresql.jdbc2; - -import org.postgresql.core.BaseConnection; -import org.postgresql.core.BaseResultSet; -import org.postgresql.core.BaseStatement; -import org.postgresql.core.Field; -import org.postgresql.util.PSQLException; -import org.postgresql.util.PSQLState; - -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.sql.Types; -import java.util.ArrayList; -import java.util.Map; -import java.util.Vector; - -/* - * Array is used collect one column of query result data. - * - * <p>Read a field of type Array into either a natively-typed - * Java array object or a ResultSet. Accessor methods provide - * the ability to capture array slices. - * - * <p>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 BaseConnection conn = null; - private Field field = null; - private BaseResultSet rs; - private int idx = 0; - private String rawString = null; - - /* - * 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(BaseConnection conn, int idx, Field field, BaseResultSet rs ) - throws SQLException - { - this.conn = conn; - this.field = field; - this.rs = rs; - this.idx = idx; - this.rawString = rs.getFixedString(idx); - } - - public Object getArray() throws SQLException - { - return getArray( 1, 0, null ); - } - - public Object getArray(long index, int count) throws SQLException - { - return getArray( index, count, null ); - } - - public Object getArray(Map map) throws SQLException - { - return getArray( 1, 0, map ); - } - - public Object getArray(long index, int count, Map map) throws SQLException - { - if ( map != null ) // For now maps aren't supported. - throw org.postgresql.Driver.notImplemented(); - - if (index < 1) - throw new PSQLException("postgresql.arr.range", PSQLState.DATA_ERROR); - Object retVal = null; - - ArrayList array = new ArrayList(); - - /* Check if the String is also not an empty array - * otherwise there will be an exception thrown below - * in the ResultSet.toX with an empty string. - * -- Doug Fields <dfields-pg-jdbc@pexicom.com> Feb 20, 2002 */ - - if ( rawString != null && !rawString.equals("{}") ) - { - char[] chars = rawString.toCharArray(); - StringBuffer sbuf = new StringBuffer(); - boolean foundOpen = false; - boolean insideString = false; - for ( int i = 0; i < chars.length; i++ ) - { - if ( chars[i] == '\\' ) - //escape character that we need to skip - i++; - else if (!insideString && chars[i] == '{' ) - { - if ( foundOpen ) // Only supports 1-D arrays for now - throw org.postgresql.Driver.notImplemented(); - foundOpen = true; - continue; - } - else if (chars[i] == '"') - { - insideString = !insideString; - continue; - } - else if (!insideString && (chars[i] == ',' || chars[i] == '}') || - i == chars.length - 1) - { - if ( chars[i] != '"' && chars[i] != '}' && chars[i] != ',' ) - sbuf.append(chars[i]); - array.add( sbuf.toString() ); - sbuf = new StringBuffer(); - continue; - } - sbuf.append( chars[i] ); - } - } - String[] arrayContents = (String[]) array.toArray( new String[array.size()] ); - if ( count == 0 ) - count = arrayContents.length; - index--; - if ( index + count > arrayContents.length ) - throw new PSQLException("postgresql.arr.range", PSQLState.DATA_ERROR); - - int i = 0; - switch ( getBaseType() ) - { - case Types.BIT: - retVal = new boolean[ count ]; - for ( ; count > 0; count-- ) - ((boolean[])retVal)[i++] = AbstractJdbc2ResultSet.toBoolean( arrayContents[(int)index++] ); - break; - case Types.SMALLINT: - case Types.INTEGER: - retVal = new int[ count ]; - for ( ; count > 0; count-- ) - ((int[])retVal)[i++] = AbstractJdbc2ResultSet.toInt( arrayContents[(int)index++] ); - break; - case Types.BIGINT: - retVal = new long[ count ]; - for ( ; count > 0; count-- ) - ((long[])retVal)[i++] = AbstractJdbc2ResultSet.toLong( arrayContents[(int)index++] ); - break; - case Types.NUMERIC: - retVal = new BigDecimal[ count ]; - for ( ; count > 0; count-- ) - ((BigDecimal[])retVal)[i++] = AbstractJdbc2ResultSet.toBigDecimal( arrayContents[(int)index++], 0 ); - break; - case Types.REAL: - retVal = new float[ count ]; - for ( ; count > 0; count-- ) - ((float[])retVal)[i++] = AbstractJdbc2ResultSet.toFloat( arrayContents[(int)index++] ); - break; - case Types.DOUBLE: - retVal = new double[ count ]; - for ( ; count > 0; count-- ) - ((double[])retVal)[i++] = AbstractJdbc2ResultSet.toDouble( arrayContents[(int)index++] ); - break; - case Types.CHAR: - case Types.VARCHAR: - retVal = new String[ count ]; - for ( ; count > 0; count-- ) - ((String[])retVal)[i++] = arrayContents[(int)index++]; - break; - case Types.DATE: - retVal = new java.sql.Date[ count ]; - for ( ; count > 0; count-- ) - ((java.sql.Date[])retVal)[i++] = AbstractJdbc2ResultSet.toDate( arrayContents[(int)index++] ); - break; - case Types.TIME: - retVal = new java.sql.Time[ count ]; - for ( ; count > 0; count-- ) - ((java.sql.Time[])retVal)[i++] = AbstractJdbc2ResultSet.toTime( arrayContents[(int)index++], rs, getBaseTypeName() ); - break; - case Types.TIMESTAMP: - retVal = new Timestamp[ count ]; - for ( ; count > 0; count-- ) - ((java.sql.Timestamp[])retVal)[i++] = AbstractJdbc2ResultSet.toTimestamp( arrayContents[(int)index++], rs, getBaseTypeName() ); - break; - - // Other datatypes not currently supported. If you are really using other types ask - // yourself if an array of non-trivial data types is really good database design. - default: - throw org.postgresql.Driver.notImplemented(); - } - return retVal; - } - - public int getBaseType() throws SQLException - { - return conn.getSQLType(getBaseTypeName()); - } - - public String getBaseTypeName() throws SQLException - { - String fType = field.getPGType(); - if ( fType.charAt(0) == '_' ) - fType = fType.substring(1); - return fType; - } - - public java.sql.ResultSet getResultSet() throws SQLException - { - return getResultSet( 1, 0, null ); - } - - public java.sql.ResultSet getResultSet(long index, int count) throws SQLException - { - return getResultSet( index, count, null ); - } - - public java.sql.ResultSet getResultSet(Map map) throws SQLException - { - return getResultSet( 1, 0, map ); - } - - public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map) throws SQLException - { - Object array = getArray( index, count, map ); - Vector rows = new Vector(); - Field[] fields = new Field[2]; - fields[0] = new Field(conn, "INDEX", conn.getPGType("int2"), 2); - switch ( getBaseType() ) - { - case Types.BIT: - boolean[] booleanArray = (boolean[]) array; - fields[1] = new Field(conn, "VALUE", conn.getPGType("bool"), 1); - for ( int i = 0; i < booleanArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( (booleanArray[i] ? "YES" : "NO") ); // Value - rows.addElement(tuple); - } - case Types.SMALLINT: - fields[1] = new Field(conn, "VALUE", conn.getPGType("int2"), 2); - case Types.INTEGER: - int[] intArray = (int[]) array; - if ( fields[1] == null ) - fields[1] = new Field(conn, "VALUE", conn.getPGType("int4"), 4); - for ( int i = 0; i < intArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( Integer.toString(intArray[i]) ); // Value - rows.addElement(tuple); - } - break; - case Types.BIGINT: - long[] longArray = (long[]) array; - fields[1] = new Field(conn, "VALUE", conn.getPGType("int8"), 8); - for ( int i = 0; i < longArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( Long.toString(longArray[i]) ); // Value - rows.addElement(tuple); - } - break; - case Types.NUMERIC: - BigDecimal[] bdArray = (BigDecimal[]) array; - fields[1] = new Field(conn, "VALUE", conn.getPGType("numeric"), -1); - for ( int i = 0; i < bdArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( bdArray[i].toString() ); // Value - rows.addElement(tuple); - } - break; - case Types.REAL: - float[] floatArray = (float[]) array; - fields[1] = new Field(conn, "VALUE", conn.getPGType("float4"), 4); - for ( int i = 0; i < floatArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( Float.toString(floatArray[i]) ); // Value - rows.addElement(tuple); - } - break; - case Types.DOUBLE: - double[] doubleArray = (double[]) array; - fields[1] = new Field(conn, "VALUE", conn.getPGType("float8"), 8); - for ( int i = 0; i < doubleArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( Double.toString(doubleArray[i]) ); // Value - rows.addElement(tuple); - } - break; - case Types.CHAR: - fields[1] = new Field(conn, "VALUE", conn.getPGType("char"), 1); - case Types.VARCHAR: - String[] strArray = (String[]) array; - if ( fields[1] == null ) - fields[1] = new Field(conn, "VALUE", conn.getPGType("varchar"), -1); - for ( int i = 0; i < strArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( strArray[i] ); // Value - rows.addElement(tuple); - } - break; - case Types.DATE: - java.sql.Date[] dateArray = (java.sql.Date[]) array; - fields[1] = new Field(conn, "VALUE", conn.getPGType("date"), 4); - for ( int i = 0; i < dateArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( dateArray[i].toString() ); // Value - rows.addElement(tuple); - } - break; - case Types.TIME: - java.sql.Time[] timeArray = (java.sql.Time[]) array; - fields[1] = new Field(conn, "VALUE", conn.getPGType("time"), 8); - for ( int i = 0; i < timeArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( timeArray[i].toString() ); // Value - rows.addElement(tuple); - } - break; - case Types.TIMESTAMP: - java.sql.Timestamp[] timestampArray = (java.sql.Timestamp[]) array; - fields[1] = new Field(conn, "VALUE", conn.getPGType("timestamp"), 8); - for ( int i = 0; i < timestampArray.length; i++ ) - { - byte[][] tuple = new byte[2][0]; - tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index - tuple[1] = conn.getEncoding().encode( timestampArray[i].toString() ); // Value - rows.addElement(tuple); - } - break; - - // Other datatypes not currently supported. If you are really using other types ask - // yourself if an array of non-trivial data types is really good database design. - default: - throw org.postgresql.Driver.notImplemented(); - } - BaseStatement stat = (BaseStatement) conn.createStatement(); - return (ResultSet) stat.createResultSet(fields, rows, "OK", 1, 0, false); - } - - public String toString() - { - return rawString; - } -} - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Blob.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Blob.java deleted file mode 100644 index 5f5d28a5e5..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Blob.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.postgresql.jdbc2; - - -public class Jdbc2Blob extends AbstractJdbc2Blob implements java.sql.Blob -{ - - public Jdbc2Blob(org.postgresql.PGConnection conn, int oid) throws java.sql.SQLException - { - super(conn, oid); - } - -} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java deleted file mode 100644 index e10223e975..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.postgresql.jdbc2; - - -import java.sql.*; -import java.util.Vector; -import org.postgresql.PGRefCursorResultSet; -import org.postgresql.core.BaseResultSet; -import org.postgresql.core.Field; - -public class Jdbc2CallableStatement extends org.postgresql.jdbc2.AbstractJdbc2Statement implements java.sql.CallableStatement -{ - - public Jdbc2CallableStatement(Jdbc2Connection connection, String sql) throws SQLException - { - super(connection, sql); - } - - public BaseResultSet createResultSet (Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException - { - return new Jdbc2ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor); - } - - public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException - { - return new Jdbc2RefCursorResultSet(this, cursorName); - } -} - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Clob.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Clob.java deleted file mode 100644 index 71de2f5433..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Clob.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.postgresql.jdbc2; - - -public class Jdbc2Clob extends AbstractJdbc2Clob implements java.sql.Clob -{ - - public Jdbc2Clob(org.postgresql.PGConnection conn, int oid) throws java.sql.SQLException - { - super(conn, oid); - } - -} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Connection.java deleted file mode 100644 index 50b66d20d2..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Connection.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.postgresql.jdbc2; - - -import java.sql.*; -import java.util.Vector; -import java.util.Hashtable; -import org.postgresql.core.Field; - -/* $PostgreSQL: pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Connection.java,v 1.8 2003/11/29 19:52:10 pgsql Exp $ - * This class implements the java.sql.Connection interface for JDBC2. - * However most of the implementation is really done in - * org.postgresql.jdbc2.AbstractJdbc2Connection or one of it's parents - */ -public class Jdbc2Connection extends org.postgresql.jdbc2.AbstractJdbc2Connection implements java.sql.Connection -{ - - public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException - { - Jdbc2Statement s = new Jdbc2Statement(this); - s.setResultSetType(resultSetType); - s.setResultSetConcurrency(resultSetConcurrency); - return s; - } - - - public java.sql.PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - { - Jdbc2PreparedStatement s = new Jdbc2PreparedStatement(this, sql); - s.setResultSetType(resultSetType); - s.setResultSetConcurrency(resultSetConcurrency); - return s; - } - - public java.sql.CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - { - Jdbc2CallableStatement s = new org.postgresql.jdbc2.Jdbc2CallableStatement(this, sql); - s.setResultSetType(resultSetType); - s.setResultSetConcurrency(resultSetConcurrency); - return s; - } - - public java.sql.DatabaseMetaData getMetaData() throws SQLException - { - if (metadata == null) - metadata = new org.postgresql.jdbc2.Jdbc2DatabaseMetaData(this); - return metadata; - } - -} - - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2DatabaseMetaData.java deleted file mode 100644 index 7dbf8a0f17..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2DatabaseMetaData.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.postgresql.jdbc2; - - -public class Jdbc2DatabaseMetaData extends org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData implements java.sql.DatabaseMetaData -{ - public Jdbc2DatabaseMetaData(Jdbc2Connection conn) - { - super(conn); - } - -} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java deleted file mode 100644 index 83023f05f4..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.postgresql.jdbc2; - - -import java.sql.*; -import java.util.Vector; -import org.postgresql.PGRefCursorResultSet; -import org.postgresql.core.BaseResultSet; -import org.postgresql.core.Field; - -public class Jdbc2PreparedStatement extends org.postgresql.jdbc2.AbstractJdbc2Statement implements java.sql.PreparedStatement -{ - - public Jdbc2PreparedStatement(Jdbc2Connection connection, String sql) throws SQLException - { - super(connection, sql); - } - - public BaseResultSet createResultSet (Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException - { - return new Jdbc2ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor); - } - - - public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException - { - return new Jdbc2RefCursorResultSet(this, cursorName); - } -} - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2RefCursorResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2RefCursorResultSet.java deleted file mode 100644 index 08ec33d752..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2RefCursorResultSet.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.postgresql.jdbc2; - - -import org.postgresql.core.QueryExecutor; -import org.postgresql.core.BaseStatement; -import org.postgresql.PGRefCursorResultSet; - - -/** A real result set based on a ref cursor. - * - * @author Nic Ferrier <nferrier@tapsellferrier.co.uk> - */ -public class Jdbc2RefCursorResultSet extends Jdbc2ResultSet - implements PGRefCursorResultSet -{ - - String refCursorHandle; - - // Indicates when the result set has activaly bound to the cursor. - boolean isInitialized = false; - - Jdbc2RefCursorResultSet(BaseStatement statement, String refCursorName) throws java.sql.SQLException - { - super(statement, null, null, null, -1, 0L, false); - this.refCursorHandle = refCursorName; - } - - public String getRefCursor () - { - return refCursorHandle; - } - - public boolean next () throws java.sql.SQLException - { - if (isInitialized) - return super.next(); - // Initialize this res set with the rows from the cursor. - String[] toExec = { "FETCH ALL IN \"" + refCursorHandle + "\";" }; - QueryExecutor.execute(toExec, new String[0], this); - isInitialized = true; - return super.next(); - } -} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java deleted file mode 100644 index a6132cb860..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.postgresql.jdbc2; - - -import java.sql.*; -import java.util.Vector; -import org.postgresql.core.BaseStatement; -import org.postgresql.core.Field; - -/* $PostgreSQL: pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java,v 1.9 2003/11/29 19:52:10 pgsql Exp $ - * This class implements the java.sql.ResultSet interface for JDBC2. - * However most of the implementation is really done in - * org.postgresql.jdbc2.AbstractJdbc2ResultSet or one of it's parents - */ -public class Jdbc2ResultSet extends org.postgresql.jdbc2.AbstractJdbc2ResultSet implements java.sql.ResultSet -{ - - public Jdbc2ResultSet(BaseStatement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) - { - super(statement, fields, tuples, status, updateCount, insertOID, binaryCursor); - } - - public ResultSetMetaData getMetaData() throws SQLException - { - return new Jdbc2ResultSetMetaData(rows, fields); - } - - public java.sql.Clob getClob(int i) throws SQLException - { - wasNullFlag = (this_row[i - 1] == null); - if (wasNullFlag) - return null; - - return new org.postgresql.jdbc2.Jdbc2Clob(connection, getInt(i)); - } - - public java.sql.Blob getBlob(int i) throws SQLException - { - wasNullFlag = (this_row[i - 1] == null); - if (wasNullFlag) - return null; - - return new org.postgresql.jdbc2.Jdbc2Blob(connection, getInt(i)); - } - -} - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSetMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSetMetaData.java deleted file mode 100644 index 97762a938e..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSetMetaData.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.postgresql.jdbc2; - -import java.util.Vector; -import org.postgresql.core.Field; - -public class Jdbc2ResultSetMetaData extends AbstractJdbc2ResultSetMetaData implements java.sql.ResultSetMetaData -{ - public Jdbc2ResultSetMetaData(Vector rows, Field[] fields) - { - super(rows, fields); - } -} - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Statement.java deleted file mode 100644 index f786af59c3..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Statement.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.postgresql.jdbc2; - - -import java.sql.*; -import java.util.Vector; -import org.postgresql.PGRefCursorResultSet; -import org.postgresql.core.BaseResultSet; -import org.postgresql.core.Field; - -/* $PostgreSQL: pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Statement.java,v 1.7 2003/11/29 19:52:10 pgsql Exp $ - * This class implements the java.sql.Statement interface for JDBC2. - * However most of the implementation is really done in - * org.postgresql.jdbc2.AbstractJdbc2Statement or one of it's parents - */ -public class Jdbc2Statement extends org.postgresql.jdbc2.AbstractJdbc2Statement implements java.sql.Statement -{ - - public Jdbc2Statement (Jdbc2Connection c) - { - super(c); - } - - public BaseResultSet createResultSet (Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException - { - return new Jdbc2ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor); - } - - public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException - { - return new Jdbc2RefCursorResultSet(this, cursorName); - } -} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/PBatchUpdateException.java b/src/interfaces/jdbc/org/postgresql/jdbc2/PBatchUpdateException.java deleted file mode 100644 index 1b30e53de3..0000000000 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/PBatchUpdateException.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.postgresql.jdbc2; - -import org.postgresql.util.MessageTranslator; - -/* - * This class extends java.sql.BatchUpdateException, and provides our - * internationalisation handling. - */ -class PBatchUpdateException extends java.sql.BatchUpdateException -{ - - private String message; - - public PBatchUpdateException( - String error, Object arg1, Object arg2, int[] updateCounts ) - { - - super(updateCounts); - - Object[] argv = new Object[2]; - argv[0] = arg1; - argv[1] = arg2; - translate(error, argv); - } - - private void translate(String error, Object[] args) - { - message = MessageTranslator.translate(error, args); - } - - // Overides Throwable - public String getLocalizedMessage() - { - return message; - } - - // Overides Throwable - public String getMessage() - { - return message; - } - - // Overides Object - public String toString() - { - return message; - } -} |
