/*
*
- * $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.
// 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
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.
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
{
{
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");
* 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
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
* @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;
}
/*
- * 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;
}
* 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
}
/*
- * 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();
}
/*
* <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
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;
/*
}
if (status.startsWith("INSERT"))
{
- insert_oid = Integer.parseInt(status.substring(1 + status.indexOf(' '),
+ insert_oid = Long.parseLong(status.substring(1 + status.indexOf(' '),
status.lastIndexOf(' ')));
}
}
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
* 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);
else if (x instanceof PGobject)
setString(parameterIndex, ((PGobject)x).getValue());
else
- setLong(parameterIndex, connection.putObject(x));
+ setLong(parameterIndex, connection.storeObject(x));
}
/*
* @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);
}
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
* 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.
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() );
}
/*
* @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);
}
* @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);
}
* 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.*;
* @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)
{
}
}
+ /*
+ * 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>
*
* @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
{
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;
}