diff --git a/src/interfaces/jdbc/example/basic.java b/src/interfaces/jdbc/example/basic.java index f01cb9cb8c572ea4e8962343581feefc85d88389..9a4469d83a0d92555df9246ce59302818ad0eb14 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 e767ac0ed9a63fecc90b604473da47494a525da7..6bbdd1fe97974b2f5d322281eca0a01f49c1daef 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 22a49fa6e21b0735adef657609410c2d349ab57b..a9da22d4f46474e2c858e0951dfe6037842f1662 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 95fd62d9f81fe6666506ebb84dc4e0464cf4cc0c..932b93aec8010e04a3e372861b667e7935999656 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. * - * <p>They are defined so that client code can cast to org.postgresql.Statement - * without having to predetermine the jdbc driver type. - * - * <p>ie: Before this class existed, you had to use: - * - * <p>((org.postgresql.jdbc2.Statement)stat).getInsertedOID(); - * - * <p>now you use: - * - * <p>((org.postgresql.Statement)stat).getInsertedOID(); - * - * <p>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 7e85dcd583bd7c44a13b56225295600aea4a9cf4..aad95f1e4b7fc1f6a4848911310d5ef04cbf93d9 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; * <p>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 71a8fb4462ad7cba679d53b77de5887f1561e6e4..4507a2728526348a402a17453aae029619afcf5f 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 7116d0b66920b24e1ad1ce18b91900f3ef3e5d6d..1da1da671153f349e4082955ff4eae70cc498430 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 33c7de58627010601b4051d6c1318cb3b7e420c6..7fea1dab6bea3c3d485b324cb4c418753714a937 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 19795840ef318ebd1f49c538503c52876b67c2e8..355c240fab02c9fc41fb0e22dca7e41da3c9631c 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 3c3146e83ec8f32ff49e27f04f71dd3eb51e86ed..d5418bd1be7642970e4bbfbb6dcfc29c81944663 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 765fb46146e87247100f47b39665157035f6d59b..66e7b4d3fac77dcbaa8413754415a365f12bd6bc 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 2bd20231706fb7b06964ac8dfbd4cf1dd50bdb9a..108125a7d9d57351350f2c25bef51f97fbe7a5fc 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 9d7a7d3617ede6bbf5a1fabbb8e7aa8ca2467556..4090289dbc3b76a4fa9ab8edf17cd395cd7c60fc 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 f49b7570ea1b030f46c5f1ef33a698972d591368..59d9c03206e1d207262e74b1c9d96e867b3352b1 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.<p> + * 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.<p> * @@ -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; }