Skip to content

Commit e3cc370

Browse files
author
Peter Mount
committed
Added org/postgresql/DriverClass.java to the list of files removed by make clean (it's dynamically built)
Fixed Statement, so that the update count is valid when an SQL DELETE operation is done. While fixing the update count, made it easier to get the OID of the last insert as well. Example is in example/basic.java
1 parent 0e38f0a commit e3cc370

File tree

10 files changed

+102
-19
lines changed

10 files changed

+102
-19
lines changed

src/interfaces/jdbc/CHANGELOG

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Tue Jun 06 12:00:00 BST 2000 petermount@it.maidstone.gov.uk
2+
- Added org/postgresql/DriverClass.java to the list of files removed
3+
by make clean (it's dynamically built)
4+
- Fixed Statement, so that the update count is valid when an SQL
5+
DELETE operation is done.
6+
- While fixing the update count, made it easier to get the OID of
7+
the last insert as well. Example is in example/basic.java
8+
19
Tue Jun 06 08:37:00 BST 2000 petermount@it.maidstone.gov.uk
210
- Removed a hardwired 8K limit on query strings
311
- Added some missing org.'s in Connection that prevented

src/interfaces/jdbc/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for Java JDBC interface
55
#
66
# IDENTIFICATION
7-
# $Id: Makefile,v 1.22 2000/05/15 21:32:51 peter Exp $
7+
# $Id: Makefile,v 1.23 2000/06/06 11:05:56 peter Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -181,7 +181,7 @@ clean:
181181
$(FIND) . -name "*.class" -exec $(RM) {} \;
182182
$(FIND) . -name "*.html" -exec $(RM) {} \;
183183
-$(RM) -rf stock example/corba/stock.built
184-
-$(RM) postgresql.jar
184+
-$(RM) postgresql.jar org/postgresql/DriverClass.java
185185
-$(RM) -rf Package-postgresql *output
186186

187187
#######################################################################

src/interfaces/jdbc/example/basic.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/**
88
*
9-
* $Id: basic.java,v 1.4 2000/04/26 05:32:00 peter Exp $
9+
* $Id: basic.java,v 1.5 2000/06/06 11:05:57 peter Exp $
1010
*
1111
* This example tests the basic components of the JDBC driver, and shows
1212
* how even the simplest of queries can be implemented.
@@ -83,10 +83,19 @@ public void doexample() throws SQLException
8383
st.executeUpdate("insert into basic values (2,1)");
8484
st.executeUpdate("insert into basic values (3,1)");
8585

86+
// This shows how to get the oid of a just inserted row
87+
st.executeUpdate("insert into basic values (4,1)");
88+
int insertedOID = ((org.postgresql.ResultSet)st.getResultSet()).getInsertedOID();
89+
System.out.println("Inserted row with oid "+insertedOID);
90+
8691
// Now change the value of b from 1 to 8
8792
st.executeUpdate("update basic set b=8");
8893
System.out.println("Updated "+st.getUpdateCount()+" rows");
8994

95+
// Now delete 2 rows
96+
st.executeUpdate("delete from basic where a<3");
97+
System.out.println("deleted "+st.getUpdateCount()+" rows");
98+
9099
// For large inserts, a PreparedStatement is more efficient, because it
91100
// supports the idea of precompiling the SQL statement, and to store
92101
// directly, a Java object into any column. PostgreSQL doesnt support

src/interfaces/jdbc/org/postgresql/Connection.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.postgresql.util.*;
1111

1212
/**
13-
* $Id: Connection.java,v 1.3 2000/06/06 07:45:07 peter Exp $
13+
* $Id: Connection.java,v 1.4 2000/06/06 11:05:59 peter Exp $
1414
*
1515
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
1616
* JDBC2 versions of the Connection class.
@@ -317,7 +317,8 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
317317
int fqp = 0;
318318
boolean hfr = false;
319319
String recv_status = null, msg;
320-
int update_count = 1;
320+
int update_count = 1;
321+
int insert_oid = 0;
321322
SQLException final_error = null;
322323

323324
// Commented out as the backend can now handle queries
@@ -359,12 +360,19 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
359360
recv_status = pg_stream.ReceiveString(8192);
360361

361362
// Now handle the update count correctly.
362-
if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE")) {
363+
if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE") || recv_status.startsWith("DELETE")) {
363364
try {
364365
update_count = Integer.parseInt(recv_status.substring(1+recv_status.lastIndexOf(' ')));
365366
} catch(NumberFormatException nfe) {
366367
throw new PSQLException("postgresql.con.fathom",recv_status);
367368
}
369+
if(recv_status.startsWith("INSERT")) {
370+
try {
371+
insert_oid = Integer.parseInt(recv_status.substring(1+recv_status.indexOf(' '),recv_status.lastIndexOf(' ')));
372+
} catch(NumberFormatException nfe) {
373+
throw new PSQLException("postgresql.con.fathom",recv_status);
374+
}
375+
}
368376
}
369377
if (fields != null)
370378
hfr = true;
@@ -425,7 +433,7 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
425433
if (final_error != null)
426434
throw final_error;
427435

428-
return getResultSet(this, fields, tuples, recv_status, update_count);
436+
return getResultSet(this, fields, tuples, recv_status, update_count, insert_oid);
429437
}
430438
}
431439

@@ -727,7 +735,7 @@ private void initObjectTypes()
727735
* This returns a resultset. It must be overridden, so that the correct
728736
* version (from jdbc1 or jdbc2) are returned.
729737
*/
730-
protected abstract java.sql.ResultSet getResultSet(org.postgresql.Connection conn, Field[] fields, Vector tuples, String status, int updateCount) throws SQLException;
738+
protected abstract java.sql.ResultSet getResultSet(org.postgresql.Connection conn, Field[] fields, Vector tuples, String status, int updateCount,int insertOID) throws SQLException;
731739

732740
public abstract void close() throws SQLException;
733741

src/interfaces/jdbc/org/postgresql/ResultSet.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class ResultSet
1919
protected Field fields[]; // The field descriptions
2020
protected String status; // Status of the result
2121
protected int updateCount; // How many rows did we get back?
22+
protected int insertOID; // The oid of an inserted row
2223
protected int current_row; // Our pointer to where we are at
2324
protected byte[][] this_row; // the current row result
2425
protected Connection connection; // the connection which we returned from
@@ -40,17 +41,35 @@ public abstract class ResultSet
4041
* @param updateCount the number of rows affected by the operation
4142
* @param cursor the positioned update/delete cursor name
4243
*/
43-
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount)
44+
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount,int insertOID)
4445
{
4546
this.connection = conn;
4647
this.fields = fields;
4748
this.rows = tuples;
4849
this.status = status;
4950
this.updateCount = updateCount;
51+
this.insertOID = insertOID;
5052
this.this_row = null;
5153
this.current_row = -1;
5254
}
5355

56+
57+
/**
58+
* Create a new ResultSet - Note that we create ResultSets to
59+
* represent the results of everything.
60+
*
61+
* @param fields an array of Field objects (basically, the
62+
* ResultSet MetaData)
63+
* @param tuples Vector of the actual data
64+
* @param status the status string returned from the back end
65+
* @param updateCount the number of rows affected by the operation
66+
* @param cursor the positioned update/delete cursor name
67+
*/
68+
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount)
69+
{
70+
this(conn,fields,tuples,status,updateCount,0);
71+
}
72+
5473
/**
5574
* We at times need to know if the resultSet we are working
5675
* with is the result of an UPDATE, DELETE or INSERT (in which
@@ -148,6 +167,14 @@ public int getColumnOID(int field)
148167
return fields[field-1].getOID();
149168
}
150169

170+
/**
171+
* returns the OID of the last inserted row
172+
*/
173+
public int getInsertedOID()
174+
{
175+
return insertOID;
176+
}
177+
151178
/**
152179
* This is part of the JDBC API, but is required by org.postgresql.Field
153180
*/

src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.postgresql.util.*;
1818

1919
/**
20-
* $Id: Connection.java,v 1.1 2000/04/17 20:07:48 peter Exp $
20+
* $Id: Connection.java,v 1.2 2000/06/06 11:06:04 peter Exp $
2121
*
2222
* A Connection represents a session with a specific database. Within the
2323
* context of a Connection, SQL statements are executed and results are
@@ -378,9 +378,9 @@ public void clearWarnings() throws SQLException
378378
* This overides the method in org.postgresql.Connection and returns a
379379
* ResultSet.
380380
*/
381-
protected java.sql.ResultSet getResultSet(org.postgresql.Connection conn, Field[] fields, Vector tuples, String status, int updateCount) throws SQLException
381+
protected java.sql.ResultSet getResultSet(org.postgresql.Connection conn, Field[] fields, Vector tuples, String status, int updateCount,int insertOID) throws SQLException
382382
{
383-
return new org.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn,fields,tuples,status,updateCount);
383+
return new org.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn,fields,tuples,status,updateCount,insertOID);
384384
}
385385

386386
}

src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@
5858
*/
5959
public class ResultSet extends org.postgresql.ResultSet implements java.sql.ResultSet
6060
{
61+
/**
62+
* Create a new ResultSet - Note that we create ResultSets to
63+
* represent the results of everything.
64+
*
65+
* @param fields an array of Field objects (basically, the
66+
* ResultSet MetaData)
67+
* @param tuples Vector of the actual data
68+
* @param status the status string returned from the back end
69+
* @param updateCount the number of rows affected by the operation
70+
* @param cursor the positioned update/delete cursor name
71+
*/
72+
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount,int insertOID)
73+
{
74+
super(conn,fields,tuples,status,updateCount,insertOID);
75+
}
76+
6177
/**
6278
* Create a new ResultSet - Note that we create ResultSets to
6379
* represent the results of everything.
@@ -71,7 +87,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
7187
*/
7288
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount)
7389
{
74-
super(conn,fields,tuples,status,updateCount);
90+
super(conn,fields,tuples,status,updateCount,0);
7591
}
7692

7793
/**

src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.postgresql.util.*;
1818

1919
/**
20-
* $Id: Connection.java,v 1.1 2000/04/17 20:07:50 peter Exp $
20+
* $Id: Connection.java,v 1.2 2000/06/06 11:06:09 peter Exp $
2121
*
2222
* A Connection represents a session with a specific database. Within the
2323
* context of a Connection, SQL statements are executed and results are
@@ -378,9 +378,9 @@ public void clearWarnings() throws SQLException
378378
* This overides the method in org.postgresql.Connection and returns a
379379
* ResultSet.
380380
*/
381-
protected java.sql.ResultSet getResultSet(org.postgresql.Connection conn, Field[] fields, Vector tuples, String status, int updateCount) throws SQLException
381+
protected java.sql.ResultSet getResultSet(org.postgresql.Connection conn, Field[] fields, Vector tuples, String status, int updateCount, int insertOID) throws SQLException
382382
{
383-
return new org.postgresql.jdbc2.ResultSet((org.postgresql.jdbc2.Connection)conn,fields,tuples,status,updateCount);
383+
return new org.postgresql.jdbc2.ResultSet((org.postgresql.jdbc2.Connection)conn,fields,tuples,status,updateCount,insertOID);
384384
}
385385

386386
// *****************

src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,27 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
7070
* @param updateCount the number of rows affected by the operation
7171
* @param cursor the positioned update/delete cursor name
7272
*/
73-
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount)
73+
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount,int insertOID)
7474
{
75-
super(conn,fields,tuples,status,updateCount);
75+
super(conn,fields,tuples,status,updateCount,insertOID);
7676
}
7777

78+
/**
79+
* Create a new ResultSet - Note that we create ResultSets to
80+
* represent the results of everything.
81+
*
82+
* @param fields an array of Field objects (basically, the
83+
* ResultSet MetaData)
84+
* @param tuples Vector of the actual data
85+
* @param status the status string returned from the back end
86+
* @param updateCount the number of rows affected by the operation
87+
* @param cursor the positioned update/delete cursor name
88+
*/
89+
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount)
90+
{
91+
super(conn,fields,tuples,status,updateCount,0);
92+
}
93+
7894
/**
7995
* A ResultSet is initially positioned before its first row,
8096
* the first call to next makes the first row the current row;

src/interfaces/jdbc/org/postgresql/jdbc2/Statement.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,5 +417,4 @@ public void setResultSetType(int value) throws SQLException
417417
throw org.postgresql.Driver.notImplemented();
418418
}
419419

420-
421420
}

0 commit comments

Comments
 (0)