mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
This patch fixes a bug reported by Graham Leggett (minfrin@sharp.fm).
The bug was that any insert or update would fail if the returned oid was larger than a signed int. Since OIDs are unsigned int's it was a bug that the code used a java signed int to deal with the values. The bug would result in the error message: "Unable to fathom update count". While fixing the bug, it became apparent that other code made a similar assumption about OIDs being signed ints. Therefore some methods that returned or took OIDs are arguements also needed to be changed. Since we are so close to the 7.2 release I have added new methods that return longs and deprecated the old methods returning ints. Therefore all old code should still work without requiring a code change to cast from long to int. Also note that the methods below are PostgreSQL specific extensions to the JDBC api are are not part of the spec from Sun, thus it is unlikely that they are used much or at all. The deprecated methods are: ResultSet.getInsertedOID() Statement.getInsertedOID() Serialize.store() Connection.putObject() and are replaced by: ResultSet.getLastOID() Statement.getLastOID() Serialize.storeObject() Connection.storeObject() All the deprecated methods returned int, while their replacements return long This patch also fixes two comments in MD5Digest that the author Jeremy Wohl submitted. --Barry
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user