Skip to content

Commit c545ec5

Browse files
committed
Backpatch jdbc fixes into 7.0.X.
1 parent 3a82b67 commit c545ec5

File tree

10 files changed

+156
-41
lines changed

10 files changed

+156
-41
lines changed

src/interfaces/jdbc/CHANGELOG

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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+
9+
Tue Jun 06 08:37:00 BST 2000 petermount@it.maidstone.gov.uk
10+
- Removed a hardwired 8K limit on query strings
11+
- Added some missing org.'s in Connection that prevented
12+
the use of the geometric types.
13+
14+
Thu Jun 01 07:26:00 BST 2000 petermount@it.maidstone.gov.uk
15+
- Removed timezone in getTimestamp() methods in ResultSet.
16+
117
Mon May 15 22:30:00 BST 2000 peter@retep.org.uk
218
- Fixed the message Makefile produces after compiling. It still said
319
about the old Driver class, not the new package. Spotted by

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.22.2.1 2000/06/15 04:12:23 momjian 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.4.2.1 2000/06/15 04:12:24 momjian 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: 25 additions & 15 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.1 2000/04/26 05:39:32 peter Exp $
13+
* $Id: Connection.java,v 1.1.2.1 2000/06/15 04:12:28 momjian 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,11 +317,14 @@ 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

323-
if (sql.length() > 8192)
324-
throw new PSQLException("postgresql.con.toolong",sql);
324+
// Commented out as the backend can now handle queries
325+
// larger than 8K. Peter June 6 2000
326+
//if (sql.length() > 8192)
327+
//throw new PSQLException("postgresql.con.toolong",sql);
325328
try
326329
{
327330
pg_stream.SendChar('Q');
@@ -357,12 +360,19 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
357360
recv_status = pg_stream.ReceiveString(8192);
358361

359362
// Now handle the update count correctly.
360-
if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE")) {
363+
if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE") || recv_status.startsWith("DELETE")) {
361364
try {
362365
update_count = Integer.parseInt(recv_status.substring(1+recv_status.lastIndexOf(' ')));
363366
} catch(NumberFormatException nfe) {
364367
throw new PSQLException("postgresql.con.fathom",recv_status);
365368
}
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+
}
366376
}
367377
if (fields != null)
368378
hfr = true;
@@ -423,7 +433,7 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
423433
if (final_error != null)
424434
throw final_error;
425435

426-
return getResultSet(this, fields, tuples, recv_status, update_count);
436+
return getResultSet(this, fields, tuples, recv_status, update_count, insert_oid);
427437
}
428438
}
429439

@@ -701,14 +711,14 @@ public void addDataType(String type,String name)
701711
// the full class name of the handling class.
702712
//
703713
private static final String defaultObjectTypes[][] = {
704-
{"box", "postgresql.geometric.PGbox"},
705-
{"circle", "postgresql.geometric.PGcircle"},
706-
{"line", "postgresql.geometric.PGline"},
707-
{"lseg", "postgresql.geometric.PGlseg"},
708-
{"path", "postgresql.geometric.PGpath"},
709-
{"point", "postgresql.geometric.PGpoint"},
710-
{"polygon", "postgresql.geometric.PGpolygon"},
711-
{"money", "postgresql.util.PGmoney"}
714+
{"box", "org.postgresql.geometric.PGbox"},
715+
{"circle", "org.postgresql.geometric.PGcircle"},
716+
{"line", "org.postgresql.geometric.PGline"},
717+
{"lseg", "org.postgresql.geometric.PGlseg"},
718+
{"path", "org.postgresql.geometric.PGpath"},
719+
{"point", "org.postgresql.geometric.PGpoint"},
720+
{"polygon", "org.postgresql.geometric.PGpolygon"},
721+
{"money", "org.postgresql.util.PGmoney"}
712722
};
713723

714724
// This initialises the objectTypes hashtable
@@ -725,7 +735,7 @@ private void initObjectTypes()
725735
* This returns a resultset. It must be overridden, so that the correct
726736
* version (from jdbc1 or jdbc2) are returned.
727737
*/
728-
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;
729739

730740
public abstract void close() throws SQLException;
731741

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.1.2.1 2000/06/15 04:12:36 momjian 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: 18 additions & 2 deletions
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
/**
@@ -437,7 +453,7 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
437453
if(s==null)
438454
return null;
439455

440-
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
456+
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
441457

442458
try {
443459
return new Timestamp(df.parse(s).getTime());

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.1.2.1 2000/06/15 04:12:41 momjian 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
// *****************

0 commit comments

Comments
 (0)