diff --git a/src/interfaces/jdbc/example/basic.java b/src/interfaces/jdbc/example/basic.java index f01cb9cb8c..9a4469d83a 100644 --- a/src/interfaces/jdbc/example/basic.java +++ b/src/interfaces/jdbc/example/basic.java @@ -6,7 +6,7 @@ import java.text.*; /* * - * $Id: basic.java,v 1.10 2001/11/19 23:16:44 momjian Exp $ + * $Id: basic.java,v 1.11 2001/11/25 23:26:56 barry Exp $ * * This example tests the basic components of the JDBC driver, and shows * how even the simplest of queries can be implemented. @@ -89,7 +89,7 @@ public class basic // This shows how to get the oid of a just inserted row // updated for 7.1 st.executeUpdate("insert into basic values (4,1)"); - int insertedOID = ((org.postgresql.Statement)st).getInsertedOID(); + long insertedOID = ((org.postgresql.Statement)st).getLastOID(); System.out.println("Inserted row with oid " + insertedOID); // Now change the value of b from 1 to 8 diff --git a/src/interfaces/jdbc/org/postgresql/Connection.java b/src/interfaces/jdbc/org/postgresql/Connection.java index e767ac0ed9..6bbdd1fe97 100644 --- a/src/interfaces/jdbc/org/postgresql/Connection.java +++ b/src/interfaces/jdbc/org/postgresql/Connection.java @@ -11,7 +11,7 @@ import org.postgresql.util.*; import org.postgresql.core.*; /* - * $Id: Connection.java,v 1.38 2001/11/19 23:19:20 momjian Exp $ + * $Id: Connection.java,v 1.39 2001/11/25 23:26:56 barry Exp $ * * This abstract class is used by org.postgresql.Driver to open either the JDBC1 or * JDBC2 versions of the Connection class. @@ -594,14 +594,26 @@ public abstract class Connection return null; } + /* + * This stores an object into the database. This method was + * deprecated in 7.2 bacause an OID can be larger than the java signed + * int returned by this method. + * @deprecated Replaced by storeObject() in 7.2 + */ + public int putObject(Object o) throws SQLException + { + return (int) storeObject(o); + } + /* * This stores an object into the database. * @param o Object to store * @return OID of the new rectord * @exception SQLException if value is not correct for this type * @see org.postgresql.util.Serialize + * @since 7.2 */ - public int putObject(Object o) throws SQLException + public long storeObject(Object o) throws SQLException { try { @@ -615,13 +627,13 @@ public abstract class Connection { Serialize ser = new Serialize(this, type); objectTypes.put(type, ser); - return ser.store(o); + return ser.storeObject(o); } // If it's an object, it should be an instance of our Serialize class // If so, then call it's fetch method. if (x instanceof Serialize) - return ((Serialize)x).store(o); + return ((Serialize)x).storeObject(o); // Thow an exception because the type is unknown throw new PSQLException("postgresql.con.strobj"); @@ -697,7 +709,7 @@ public abstract class Connection * This returns a resultset. It must be overridden, so that the correct * version (from jdbc1 or jdbc2) are returned. */ - public abstract java.sql.ResultSet getResultSet(org.postgresql.Connection conn, java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, int insertOID, boolean binaryCursor) throws SQLException; + public abstract java.sql.ResultSet getResultSet(org.postgresql.Connection conn, java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException; /* * In some cases, it is desirable to immediately release a Connection's diff --git a/src/interfaces/jdbc/org/postgresql/ResultSet.java b/src/interfaces/jdbc/org/postgresql/ResultSet.java index 22a49fa6e2..a9da22d4f4 100644 --- a/src/interfaces/jdbc/org/postgresql/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/ResultSet.java @@ -20,7 +20,7 @@ public abstract class ResultSet protected String status; // Status of the result protected boolean binaryCursor = false; // is the data binary or Strings protected int updateCount; // How many rows did we get back? - protected int insertOID; // The oid of an inserted row + protected long insertOID; // The oid of an inserted row protected int current_row; // Our pointer to where we are at protected byte[][] this_row; // the current row result protected Connection connection; // the connection which we returned from @@ -42,7 +42,7 @@ public abstract class ResultSet * @param updateCount the number of rows affected by the operation * @param cursor the positioned update/delete cursor name */ - public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount, int insertOID, boolean binaryCursor) + public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) { this.connection = conn; this.fields = fields; @@ -170,9 +170,21 @@ public abstract class ResultSet } /* - * returns the OID of the last inserted row + * returns the OID of the last inserted row. Deprecated in 7.2 because + * range for OID values is greater than java signed int. + * @deprecated Replaced by getLastOID() in 7.2 */ public int getInsertedOID() + { + return (int) getLastOID(); + } + + + /* + * returns the OID of the last inserted row + * @since 7.2 + */ + public long getLastOID() { return insertOID; } diff --git a/src/interfaces/jdbc/org/postgresql/Statement.java b/src/interfaces/jdbc/org/postgresql/Statement.java index 95fd62d9f8..932b93aec8 100644 --- a/src/interfaces/jdbc/org/postgresql/Statement.java +++ b/src/interfaces/jdbc/org/postgresql/Statement.java @@ -8,19 +8,6 @@ import org.postgresql.util.PSQLException; * org.postgresql.jdbc1.Statement and org.postgresql.jdbc2.Statement that are * unique to PostgreSQL's JDBC driver. * - *

They are defined so that client code can cast to org.postgresql.Statement - * without having to predetermine the jdbc driver type. - * - *

ie: Before this class existed, you had to use: - * - *

((org.postgresql.jdbc2.Statement)stat).getInsertedOID(); - * - *

now you use: - * - *

((org.postgresql.Statement)stat).getInsertedOID(); - * - *

As you can see, this is independent of JDBC1.2, JDBC2.0 or the upcoming - * JDBC3. */ public abstract class Statement @@ -196,16 +183,27 @@ public abstract class Statement } /* - * New in 7.1: Returns the Last inserted oid. This should be used, rather - * than the old method using getResultSet, which for executeUpdate returns - * null. - * @return OID of last insert + * Returns the Last inserted/updated oid. Deprecated in 7.2 because + * range of OID values is greater than a java signed int. + * @deprecated Replaced by getLastOID in 7.2 */ public int getInsertedOID() throws SQLException { if (result == null) return 0; - return ((org.postgresql.ResultSet) result).getInsertedOID(); + return (int)((org.postgresql.ResultSet) result).getLastOID(); + } + + /* + * Returns the Last inserted/updated oid. + * @return OID of last insert + * @since 7.2 + */ + public long getLastOID() throws SQLException + { + if (result == null) + return 0; + return ((org.postgresql.ResultSet) result).getLastOID(); } /* diff --git a/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java b/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java index 7e85dcd583..aad95f1e4b 100644 --- a/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java +++ b/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java @@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException; *

The lifetime of a QueryExecutor object is from sending the query * until the response has been received from the backend. * - * $Id: QueryExecutor.java,v 1.5 2001/11/19 23:16:45 momjian Exp $ + * $Id: QueryExecutor.java,v 1.6 2001/11/25 23:26:56 barry Exp $ */ public class QueryExecutor @@ -46,7 +46,7 @@ public class QueryExecutor private boolean binaryCursor = false; private String status = null; private int update_count = 1; - private int insert_oid = 0; + private long insert_oid = 0; private int maxRows; /* @@ -173,7 +173,7 @@ public class QueryExecutor } if (status.startsWith("INSERT")) { - insert_oid = Integer.parseInt(status.substring(1 + status.indexOf(' '), + insert_oid = Long.parseLong(status.substring(1 + status.indexOf(' '), status.lastIndexOf(' '))); } } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java index 71a8fb4462..4507a27285 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java @@ -17,7 +17,7 @@ import org.postgresql.largeobject.*; import org.postgresql.util.*; /* - * $Id: Connection.java,v 1.13 2001/11/19 22:33:38 momjian Exp $ + * $Id: Connection.java,v 1.14 2001/11/25 23:26:58 barry Exp $ * * A Connection represents a session with a specific database. Within the * context of a Connection, SQL statements are executed and results are @@ -131,7 +131,7 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co * This overides the method in org.postgresql.Connection and returns a * ResultSet. */ - public java.sql.ResultSet getResultSet(org.postgresql.Connection conn, java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, int insertOID, boolean binaryCursor) throws SQLException + public java.sql.ResultSet getResultSet(org.postgresql.Connection conn, java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException { // in jdbc1 stat is ignored. return new org.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn, fields, tuples, status, updateCount, insertOID, binaryCursor); diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java index 7116d0b669..1da1da6711 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java @@ -712,7 +712,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta else if (x instanceof PGobject) setString(parameterIndex, ((PGobject)x).getValue()); else - setLong(parameterIndex, connection.putObject(x)); + setLong(parameterIndex, connection.storeObject(x)); } /* diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java index 33c7de5862..7fea1dab6b 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java @@ -70,7 +70,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu * @param updateCount the number of rows affected by the operation * @param cursor the positioned update/delete cursor name */ - public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount, int insertOID, boolean binaryCursor) + public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) { super(conn, fields, tuples, status, updateCount, insertOID, binaryCursor); } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java index 19795840ef..355c240fab 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java @@ -17,7 +17,7 @@ import org.postgresql.largeobject.*; import org.postgresql.util.*; /* - * $Id: Connection.java,v 1.15 2001/11/19 22:33:38 momjian Exp $ + * $Id: Connection.java,v 1.16 2001/11/25 23:26:59 barry Exp $ * * A Connection represents a session with a specific database. Within the * context of a Connection, SQL statements are executed and results are @@ -207,7 +207,7 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co * This overides the method in org.postgresql.Connection and returns a * ResultSet. */ - public java.sql.ResultSet getResultSet(org.postgresql.Connection conn, java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, int insertOID, boolean binaryCursor) throws SQLException + public java.sql.ResultSet getResultSet(org.postgresql.Connection conn, java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException { // In 7.1 we now test concurrency to see which class to return. If we are not working with a // Statement then default to a normal ResultSet object. diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java index 3c3146e83e..d5418bd1be 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java @@ -748,7 +748,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta setString(parameterIndex, ((PGobject)x).getValue()); else // Try to store java object in database - setSerialize(parameterIndex, connection.putObject(x), x.getClass().getName() ); + setSerialize(parameterIndex, connection.storeObject(x), x.getClass().getName() ); } /* diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java index 765fb46146..66e7b4d3fa 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java @@ -74,7 +74,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu * @param updateCount the number of rows affected by the operation * @param cursor the positioned update/delete cursor name */ - public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount, int insertOID, boolean binaryCursor) + public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) { super(conn, fields, tuples, status, updateCount, insertOID, binaryCursor); } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/UpdateableResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/UpdateableResultSet.java index 2bd2023170..108125a7d9 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/UpdateableResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/UpdateableResultSet.java @@ -40,7 +40,7 @@ public class UpdateableResultSet extends org.postgresql.jdbc2.ResultSet * @param updateCount the number of rows affected by the operation * @param cursor the positioned update/delete cursor name */ - public UpdateableResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount, int insertOID, boolean binaryCursor) + public UpdateableResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) { super(conn, fields, tuples, status, updateCount, insertOID, binaryCursor); } diff --git a/src/interfaces/jdbc/org/postgresql/util/MD5Digest.java b/src/interfaces/jdbc/org/postgresql/util/MD5Digest.java index 9d7a7d3617..4090289dbc 100644 --- a/src/interfaces/jdbc/org/postgresql/util/MD5Digest.java +++ b/src/interfaces/jdbc/org/postgresql/util/MD5Digest.java @@ -4,7 +4,7 @@ package org.postgresql.util; * MD5-based utility function to obfuscate passwords before network transmission * * @author Jeremy Wohl - * + * $Id: MD5Digest.java,v 1.3 2001/11/25 23:26:59 barry Exp $ */ import java.security.*; @@ -23,7 +23,7 @@ public class MD5Digest * @param password The connecting user's password. * @param salt A four-character string sent by the server. * - * @return A 35-byte array, comprising the string "md5", followed by an MD5 digest. + * @return A 35-byte array, comprising the string "md5" and an MD5 digest. */ public static byte[] encode(String user, String password, String salt) { diff --git a/src/interfaces/jdbc/org/postgresql/util/Serialize.java b/src/interfaces/jdbc/org/postgresql/util/Serialize.java index f49b7570ea..59d9c03206 100644 --- a/src/interfaces/jdbc/org/postgresql/util/Serialize.java +++ b/src/interfaces/jdbc/org/postgresql/util/Serialize.java @@ -267,6 +267,17 @@ public class Serialize } } + /* + * This stores an object into a table, returning it's OID.

+ * This method was deprecated in 7.2 because the value of an OID + * can be larger than a java signed int. + * @deprecated Replaced by storeObject() in 7.2 + */ + public int store(Object o) throws SQLException + { + return (int) storeObject(o); + } + /* * This stores an object into a table, returning it's OID.

* @@ -284,8 +295,9 @@ public class Serialize * @param o Object to store (must implement Serializable) * @return oid of stored object * @exception SQLException on error + * @since 7.2 */ - public int store(Object o) throws SQLException + public long storeObject(Object o) throws SQLException { try { @@ -390,11 +402,11 @@ public class Serialize else { // new record inserted has new oid; rs should be not null - int newOID = ((org.postgresql.ResultSet)rs).getInsertedOID(); + long newOID = ((org.postgresql.ResultSet)rs).getLastOID(); rs.close(); // update the java object's oid field if it has the oid field if (hasOID) - f[oidFIELD].setInt(o, newOID); + f[oidFIELD].setLong(o, newOID); // new object stored, return newly inserted oid return newOID; }