Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc545ec5

Browse files
committed
Backpatch jdbc fixes into 7.0.X.
1 parent3a82b67 commitc545ec5

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/1521:32:51 peter Exp $
7+
# $Id: Makefile,v 1.22.2.1 2000/06/1504: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+
intinsertedOID = ((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
importorg.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
intfqp =0;
318318
booleanhfr =false;
319319
Stringrecv_status =null,msg;
320-
intupdate_count =1;
320+
intupdate_count =1;
321+
intinsert_oid =0;
321322
SQLExceptionfinal_error =null;
322323

323-
if (sql.length() >8192)
324-
thrownewPSQLException("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(NumberFormatExceptionnfe) {
364367
thrownewPSQLException("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(NumberFormatExceptionnfe) {
373+
thrownewPSQLException("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
throwfinal_error;
425435

426-
returngetResultSet(this,fields,tuples,recv_status,update_count);
436+
returngetResultSet(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
privatestaticfinalStringdefaultObjectTypes[][] = {
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-
protectedabstractjava.sql.ResultSetgetResultSet(org.postgresql.Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount)throwsSQLException;
738+
protectedabstractjava.sql.ResultSetgetResultSet(org.postgresql.Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount,intinsertOID)throwsSQLException;
729739

730740
publicabstractvoidclose()throwsSQLException;
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
protectedFieldfields[];// The field descriptions
2020
protectedStringstatus;// Status of the result
2121
protectedintupdateCount;// How many rows did we get back?
22+
protectedintinsertOID;// The oid of an inserted row
2223
protectedintcurrent_row;// Our pointer to where we are at
2324
protectedbyte[][]this_row;// the current row result
2425
protectedConnectionconnection;// 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-
publicResultSet(Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount)
44+
publicResultSet(Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount,intinsertOID)
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+
publicResultSet(Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount)
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
returnfields[field-1].getOID();
149168
}
150169

170+
/**
171+
* returns the OID of the last inserted row
172+
*/
173+
publicintgetInsertedOID()
174+
{
175+
returninsertOID;
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
importorg.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-
protectedjava.sql.ResultSetgetResultSet(org.postgresql.Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount)throwsSQLException
381+
protectedjava.sql.ResultSetgetResultSet(org.postgresql.Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount,intinsertOID)throwsSQLException
382382
{
383-
returnneworg.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn,fields,tuples,status,updateCount);
383+
returnneworg.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
publicclassResultSetextendsorg.postgresql.ResultSetimplementsjava.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+
publicResultSet(Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount,intinsertOID)
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
publicResultSet(Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount)
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
returnnull;
439455

440-
SimpleDateFormatdf =newSimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
456+
SimpleDateFormatdf =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
441457

442458
try {
443459
returnnewTimestamp(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
importorg.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-
protectedjava.sql.ResultSetgetResultSet(org.postgresql.Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount)throwsSQLException
381+
protectedjava.sql.ResultSetgetResultSet(org.postgresql.Connectionconn,Field[]fields,Vectortuples,Stringstatus,intupdateCount,intinsertOID)throwsSQLException
382382
{
383-
returnneworg.postgresql.jdbc2.ResultSet((org.postgresql.jdbc2.Connection)conn,fields,tuples,status,updateCount);
383+
returnneworg.postgresql.jdbc2.ResultSet((org.postgresql.jdbc2.Connection)conn,fields,tuples,status,updateCount,insertOID);
384384
}
385385

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp