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

Commitd634a59

Browse files
author
Barry Lind
committed
Patches submitted by Kris Jurka (jurka@ejurka.com) for the following bugs:
- Properly drop tables in jdbc regression tests with cascade for 7.3 - problem with Statement.execute() and executeUpdate() not clearing binds - problem with ResultSet not correctly handling default encoding - changes to correctly support show transaction isolation level in 7.3 - changed DatabaseMetaDataTest to handle differences in FK names in 7.3 - better fix for dynamically checking server NAME data length (With the fixes above the jdbc regression tests pass on jdbc2 and jdbc3 against both a 7.2 and 7.3 server)Patchs submitted by David Wall (d.wall@computer.org): - problem with getBlob when largeobject oid is null - improvements to BlobOutputStreamPatch submitted by Haris Peco (snpe@snpe.co.yu): - problem with callable statement not supporting prepared statement methods Modified Files: jdbc/org/postgresql/Driver.java.in jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java jdbc/org/postgresql/jdbc3/Jdbc3ResultSet.java jdbc/org/postgresql/largeobject/BlobOutputStream.java jdbc/org/postgresql/largeobject/LargeObject.java jdbc/org/postgresql/test/TestUtil.java jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java jdbc/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java jdbc/org/postgresql/test/jdbc2/optional/SimpleDataSourceTest.java
1 parent8aa966e commitd634a59

16 files changed

+147
-61
lines changed

‎src/interfaces/jdbc/org/postgresql/Driver.java.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,6 @@ public class Driver implements java.sql.Driver
446446
}
447447

448448
//The build number should be incremented for every new build
449-
private static int m_buildNumber =104;
449+
private static int m_buildNumber =105;
450450

451451
}

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
importorg.postgresql.util.*;
1515

1616

17-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.8 2002/09/06 21:23:05 momjian Exp $
17+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.9 2002/09/11 05:38:44 barry Exp $
1818
* This class defines methods of the jdbc1 specification. This class is
1919
* extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
2020
* methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection
@@ -982,21 +982,32 @@ public void rollback() throws SQLException
982982
*/
983983
publicintgetTransactionIsolation()throwsSQLException
984984
{
985-
clearWarnings();
986-
ExecSQL("show transaction isolation level");
987-
988-
SQLWarningwarning =getWarnings();
989-
if (warning !=null)
990-
{
991-
Stringmessage =warning.getMessage();
985+
Stringsql ="show transaction isolation level";
986+
Stringlevel =null;
987+
if (haveMinimumServerVersion("7.3")) {
988+
ResultSetrs =ExecSQL(sql);
989+
if (rs.next()) {
990+
level =rs.getString(1);
991+
}
992+
rs.close();
993+
}else {
992994
clearWarnings();
993-
if (message.indexOf("READ COMMITTED") != -1)
995+
ExecSQL(sql);
996+
SQLWarningwarning =getWarnings();
997+
if (warning !=null)
998+
{
999+
level =warning.getMessage();
1000+
}
1001+
clearWarnings();
1002+
}
1003+
if (level !=null) {
1004+
if (level.indexOf("READ COMMITTED") != -1)
9941005
returnjava.sql.Connection.TRANSACTION_READ_COMMITTED;
995-
elseif (message.indexOf("READ UNCOMMITTED") != -1)
1006+
elseif (level.indexOf("READ UNCOMMITTED") != -1)
9961007
returnjava.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
997-
elseif (message.indexOf("REPEATABLE READ") != -1)
1008+
elseif (level.indexOf("REPEATABLE READ") != -1)
9981009
returnjava.sql.Connection.TRANSACTION_REPEATABLE_READ;
999-
elseif (message.indexOf("SERIALIZABLE") != -1)
1010+
elseif (level.indexOf("SERIALIZABLE") != -1)
10001011
returnjava.sql.Connection.TRANSACTION_SERIALIZABLE;
10011012
}
10021013
returnjava.sql.Connection.TRANSACTION_READ_COMMITTED;

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,28 @@ public abstract class AbstractJdbc1DatabaseMetaData
2727
protectedstaticfinalintiInt2Oid =21;// OID for int2
2828
protectedstaticfinalintiInt4Oid =23;// OID for int4
2929
protectedstaticfinalintVARHDRSZ =4;// length for int4
30-
protectedstaticintNAME_SIZE =64;// length for name datatype
30+
protectedstaticintNAME_SIZE =63;// length for name datatype
3131

3232
publicAbstractJdbc1DatabaseMetaData(AbstractJdbc1Connectionconn)
3333
{
3434
this.connection =conn;
35+
Stringsql;
3536
try {
3637
if (connection.haveMinimumServerVersion("7.3")) {
37-
NAME_SIZE =64;
38+
sql ="SELECT t.typlen FROM pg_catalog.pg_type t, pg_catalog.pg_namespace n WHERE t.typnamespace=n.oid AND t.typname='name' AND n.nspname='pg_catalog'";
39+
NAME_SIZE =63;
3840
}else {
39-
NAME_SIZE =32;
41+
sql ="SELECT typlen FROM pg_type WHERE typname='name'";
42+
NAME_SIZE =31;
4043
}
44+
ResultSetrs =connection.createStatement().executeQuery(sql);
45+
if (rs.next()) {
46+
NAME_SIZE =rs.getInt("typlen") -1;
47+
}
48+
rs.close();
4149
}catch (SQLExceptionl_se) {
42-
//leave value at default
50+
// depending on the error the NAME_SIZE value will
51+
// be the original or the value set before the query.
4352
}
4453
}
4554

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
importorg.postgresql.largeobject.*;
99
importorg.postgresql.util.*;
1010

11-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.8 2002/09/08 00:15:29 barry Exp $
11+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.9 2002/09/11 05:38:44 barry Exp $
1212
* This class defines methods of the jdbc1 specification. This class is
1313
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
1414
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -170,6 +170,7 @@ public int executeUpdate(String p_sql) throws SQLException
170170
{
171171
Stringl_sql =replaceProcessing(p_sql);
172172
m_sqlFragments =newString[] {l_sql};
173+
m_binds =newObject[0];
173174
//If we have already created a server prepared statement, we need
174175
//to deallocate the existing one
175176
if (m_statementName !=null) {
@@ -213,6 +214,7 @@ public boolean execute(String p_sql) throws SQLException
213214
{
214215
Stringl_sql =replaceProcessing(p_sql);
215216
m_sqlFragments =newString[] {l_sql};
217+
m_binds =newObject[0];
216218
//If we have already created a server prepared statement, we need
217219
//to deallocate the existing one
218220
if (m_statementName !=null) {
@@ -1775,6 +1777,12 @@ private void setSerialize(int parameterIndex, long x, String classname) throws S
17751777
*/
17761778
privateStringmodifyJdbcCall(Stringp_sql)throwsSQLException
17771779
{
1780+
//Check that this is actually a call which should start with a {
1781+
//if not do nothing and treat this as a standard prepared sql
1782+
if (!p_sql.trim().startsWith("{")) {
1783+
returnp_sql;
1784+
}
1785+
17781786
// syntax checking is not complete only a few basics :(
17791787
originalSql =p_sql;// save for error msgs..
17801788
Stringl_sql =p_sql;

‎src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
importorg.postgresql.util.PSQLException;
1616

1717

18-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.7 2002/09/06 21:23:06 momjian Exp $
18+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.8 2002/09/11 05:38:45 barry Exp $
1919
* This class defines methods of the jdbc2 specification. This class extends
2020
* org.postgresql.jdbc1.AbstractJdbc1ResultSet which provides the jdbc1
2121
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2ResultSet
@@ -1546,14 +1546,7 @@ private void updateRowBuffer() throws SQLException
15461546
caseTypes.REAL:
15471547
caseTypes.TINYINT:
15481548

1549-
try
1550-
{
1551-
rowBuffer[columnIndex] =String.valueOf(updateValues.get(columnName ) ).getBytes(connection.getEncoding().name() );
1552-
}
1553-
catch (UnsupportedEncodingExceptionex)
1554-
{
1555-
thrownewSQLException("Unsupported Encoding " +connection.getEncoding().name());
1556-
}
1549+
rowBuffer[columnIndex] =connection.getEncoding().encode(String.valueOf(updateValues.get(columnName ) ));
15571550

15581551
caseTypes.NULL:
15591552
continue;

‎src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
importorg.postgresql.largeobject.*;
99
importorg.postgresql.util.PSQLException;
1010

11-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.6 2002/09/06 21:23:06 momjian Exp $
11+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.7 2002/09/11 05:38:45 barry Exp $
1212
* This class defines methods of the jdbc2 specification. This class extends
1313
* org.postgresql.jdbc1.AbstractJdbc1Statement which provides the jdbc1
1414
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Statement
@@ -187,16 +187,26 @@ public void setBlob(int i, Blob x) throws SQLException
187187
while (numRead != -1 &&bytesRemaining >0)
188188
{
189189
bytesRemaining -=numRead;
190-
los.write(buf,0,numRead);
190+
if (numRead ==buf.length )
191+
los.write(buf);// saves a buffer creation and copy in LargeObject since it's full
192+
else
193+
los.write(buf,0,numRead);
191194
numRead =l_inStream.read(buf,0,Math.min(buf.length,bytesRemaining));
192195
}
193-
los.close();
194196
}
195197
catch (IOExceptionse)
196198
{
197199
thrownewPSQLException("postgresql.unusual",se);
198200
}
199-
// lob is closed by the stream so don't call lob.close()
201+
finally
202+
{
203+
try
204+
{
205+
los.close();
206+
l_inStream.close();
207+
}
208+
catch(Exceptione ) {}
209+
}
200210
setInt(i,oid);
201211
}
202212

‎src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
importjava.util.Vector;
66
importorg.postgresql.Field;
77

8-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2ResultSet.java,v 1.5 2002/09/06 21:23:06 momjian Exp $
8+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2ResultSet.java,v 1.6 2002/09/11 05:38:45 barry Exp $
99
* This class implements the java.sql.ResultSet interface for JDBC2.
1010
* However most of the implementation is really done in
1111
* org.postgresql.jdbc2.AbstractJdbc2ResultSet or one of it's parents
@@ -25,11 +25,19 @@ public java.sql.ResultSetMetaData getMetaData() throws SQLException
2525

2626
publicjava.sql.ClobgetClob(inti)throwsSQLException
2727
{
28+
wasNullFlag = (this_row[i -1] ==null);
29+
if (wasNullFlag)
30+
returnnull;
31+
2832
returnneworg.postgresql.jdbc2.Jdbc2Clob(connection,getInt(i));
2933
}
3034

3135
publicjava.sql.BlobgetBlob(inti)throwsSQLException
3236
{
37+
wasNullFlag = (this_row[i -1] ==null);
38+
if (wasNullFlag)
39+
returnnull;
40+
3341
returnneworg.postgresql.jdbc2.Jdbc2Blob(connection,getInt(i));
3442
}
3543

‎src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ResultSet.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
importjava.util.Vector;
66
importorg.postgresql.Field;
77

8-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3ResultSet.java,v 1.2 2002/09/06 21:23:06 momjian Exp $
8+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3ResultSet.java,v 1.3 2002/09/11 05:38:45 barry Exp $
99
* This class implements the java.sql.ResultSet interface for JDBC3.
1010
* However most of the implementation is really done in
1111
* org.postgresql.jdbc3.AbstractJdbc3ResultSet or one of it's parents
@@ -25,11 +25,19 @@ public java.sql.ResultSetMetaData getMetaData() throws SQLException
2525

2626
publicjava.sql.ClobgetClob(inti)throwsSQLException
2727
{
28+
wasNullFlag = (this_row[i -1] ==null);
29+
if (wasNullFlag)
30+
returnnull;
31+
2832
returnnewJdbc3Clob(connection,getInt(i));
2933
}
3034

3135
publicjava.sql.BlobgetBlob(inti)throwsSQLException
3236
{
37+
wasNullFlag = (this_row[i -1] ==null);
38+
if (wasNullFlag)
39+
returnnull;
40+
3341
returnnewJdbc3Blob(connection,getInt(i));
3442
}
3543

‎src/interfaces/jdbc/org/postgresql/largeobject/BlobOutputStream.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ public void write(int b) throws java.io.IOException
6868
}
6969
}
7070

71+
publicvoidwrite(byte[]buf,intoff,intlen)throwsjava.io.IOException
72+
{
73+
try
74+
{
75+
// If we have any internally buffered data, send it first
76+
if (bpos >0 )
77+
flush();
78+
79+
if (off ==0 &&len ==buf.length )
80+
lo.write(buf);// save a buffer creation and copy since full buffer written
81+
else
82+
lo.write(buf,off,len);
83+
}
84+
catch (SQLExceptionse)
85+
{
86+
thrownewIOException(se.toString());
87+
}
88+
}
89+
90+
7191
/*
7292
* Flushes this output stream and forces any buffered output bytes
7393
* to be written out. The general contract of <code>flush</code> is

‎src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public int size() throws SQLException
304304
*/
305305
publicInputStreamgetInputStream()throwsSQLException
306306
{
307-
returnnewBlobInputStream(this);
307+
returnnewBlobInputStream(this,4096);
308308
}
309309

310310
/*
@@ -318,7 +318,7 @@ public InputStream getInputStream() throws SQLException
318318
publicOutputStreamgetOutputStream()throwsSQLException
319319
{
320320
if (os ==null)
321-
os =newBlobOutputStream(this);
321+
os =newBlobOutputStream(this,4096);
322322
returnos;
323323
}
324324

‎src/interfaces/jdbc/org/postgresql/test/TestUtil.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,26 @@ public static void dropTable(Connection con, String table)
109109
Statementstmt =con.createStatement();
110110
try
111111
{
112-
stmt.executeUpdate("DROP TABLE " +table);
112+
Stringsql ="DROP TABLE " +table;
113+
if (coninstanceoforg.postgresql.jdbc1.AbstractJdbc1Connection && ((org.postgresql.jdbc1.AbstractJdbc1Connection)con).haveMinimumServerVersion("7.3")) {
114+
sql +=" CASCADE ";
115+
}
116+
stmt.executeUpdate(sql);
113117
}
114118
catch (SQLExceptionex)
115119
{
116-
// ignore
120+
// Since every create table issues a drop table
121+
// it's easy to get a table doesn't exist error.
122+
// we want to ignore these, but if we're in a
123+
// transaction we need to restart.
124+
// If the test case wants to catch this error
125+
// itself it should issue the drop SQL directly.
126+
if (ex.getMessage().indexOf("does not exist") != -1) {
127+
if (!con.getAutoCommit()) {
128+
con.rollback();
129+
}
130+
131+
}
117132
}
118133
}
119134
catch (SQLExceptionex)

‎src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* PS: Do you know how difficult it is to type on a train? ;-)
1111
*
12-
* $Id: DatabaseMetaDataTest.java,v 1.13 2002/09/06 21:23:06 momjian Exp $
12+
* $Id: DatabaseMetaDataTest.java,v 1.14 2002/09/11 05:38:45 barry Exp $
1313
*/
1414

1515
publicclassDatabaseMetaDataTestextendsTestCase
@@ -264,7 +264,11 @@ public void testCrossReference()
264264
assertTrue(fkColumnName.equals("m" ) ||fkColumnName.equals("n" ) ) ;
265265

266266
StringfkName =rs.getString("FK_NAME" );
267-
assertTrue(fkName.equals("<unnamed>") );
267+
if (((org.postgresql.jdbc1.AbstractJdbc1Connection)con1).haveMinimumServerVersion("7.3")) {
268+
assertTrue(fkName.startsWith("$1"));
269+
}else {
270+
assertTrue(fkName.startsWith("<unnamed>") );
271+
}
268272

269273
StringpkName =rs.getString("PK_NAME" );
270274
assertTrue(pkName.equals("vv_pkey") );
@@ -317,7 +321,7 @@ public void testForeignKeys()
317321
assertTrue(fkColumnName.equals("people_id" ) ||fkColumnName.equals("policy_id" ) ) ;
318322

319323
StringfkName =rs.getString("FK_NAME" );
320-
assertTrue(fkName.equals("people") ||fkName.equals("policy" ) );
324+
assertTrue(fkName.startsWith("people") ||fkName.startsWith("policy" ) );
321325

322326
StringpkName =rs.getString("PK_NAME" );
323327
assertTrue(pkName.equals("people_pkey") ||pkName.equals("policy_pkey" ) );
@@ -337,7 +341,7 @@ public void testForeignKeys()
337341
assertTrue(rs.getString("FKTABLE_NAME" ).equals("users" ) );
338342
assertTrue(rs.getString("FKCOLUMN_NAME" ).equals("people_id" ) );
339343

340-
assertTrue(rs.getString("FK_NAME" ).equals("people" ) );
344+
assertTrue(rs.getString("FK_NAME" ).startsWith("people" ) );
341345

342346

343347
TestUtil.dropTable(con1,"users" );

‎src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public void testUpdateable()
124124
st.close();
125125

126126
TestUtil.dropTable(con,"updateable" );
127+
TestUtil.dropTable(con,"second" );
127128
TestUtil.closeDB(con );
128129
}
129130
catch (Exceptionex)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp