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

Commitcfae073

Browse files
author
Barry Lind
committed
Applied patch submitted by Mats Lofkvist fixing serious threading problem introduced in beta3.
Fixed bug with using setNull()(or setXXX(x, null)) and serverside prepare statements.Improved error message when using a connection object that has already been closed. Modified Files: jdbc/org/postgresql/errors.properties jdbc/org/postgresql/core/Encoding.java jdbc/org/postgresql/core/QueryExecutor.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
1 parent4a57ef6 commitcfae073

File tree

5 files changed

+109
-17
lines changed

5 files changed

+109
-17
lines changed

‎src/interfaces/jdbc/org/postgresql/core/Encoding.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/*
99
* Converts to and from the character encoding used by the backend.
1010
*
11-
* $Id: Encoding.java,v 1.7 2002/10/20 02:55:50 barry Exp $
11+
* $Id: Encoding.java,v 1.8 2002/11/14 05:35:45 barry Exp $
1212
*/
1313

1414
publicclassEncoding
@@ -233,17 +233,18 @@ private static boolean isAvailable(String encodingName)
233233
*/
234234
privatestaticfinalintpow2_6 =64;// 26
235235
privatestaticfinalintpow2_12 =4096;// 212
236-
privatestaticchar[]cdata =newchar[50];
236+
privatechar[]cdata =newchar[50];
237237

238238
privatesynchronizedStringdecodeUTF8(bytedata[],intoffset,intlength) {
239239
char[]l_cdata =cdata;
240-
if (l_cdata.length < (length-offset)) {
241-
l_cdata =newchar[length-offset];
240+
if (l_cdata.length < (length)) {
241+
l_cdata =newchar[length];
242242
}
243243
inti =offset;
244244
intj =0;
245+
intk =length +offset;
245246
intz,y,x,val;
246-
while (i <length) {
247+
while (i <k) {
247248
z =data[i] &0xFF;
248249
if (z <0x80) {
249250
l_cdata[j++] = (char)data[i];

‎src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* <p>The lifetime of a QueryExecutor object is from sending the query
1414
* until the response has been received from the backend.
1515
*
16-
* $Id: QueryExecutor.java,v 1.16 2002/09/06 21:23:05 momjian Exp $
16+
* $Id: QueryExecutor.java,v 1.17 2002/11/14 05:35:45 barry Exp $
1717
*/
1818

1919
publicclassQueryExecutor
@@ -59,6 +59,11 @@ public java.sql.ResultSet execute() throws SQLException
5959

6060
StringBuffererrorMessage =null;
6161

62+
if (pg_stream ==null)
63+
{
64+
thrownewPSQLException("postgresql.con.closed");
65+
}
66+
6267
synchronized (pg_stream)
6368
{
6469

‎src/interfaces/jdbc/org/postgresql/errors.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ postgresql.con.auth:The authentication type {0} is not supported. Check that you
55
postgresql.con.authfail:An error occured while getting the authentication request.
66
postgresql.con.backend:Backend start-up failed: {0}
77
postgresql.con.call:Callable Statements are not supported at this time.
8+
postgresql.con.closed:Connection is closed. Operation is not permitted.
89
postgresql.con.creobj:Failed to create object for {0} {1}
910
postgresql.con.failed:The connection attempt failed because {0}
1011
postgresql.con.fathom:Unable to fathom update count {0}

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

Lines changed: 9 additions & 1 deletion
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.12 2002/10/20 02:55:50 barry Exp $
17+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.13 2002/11/14 05:35:45 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
@@ -475,6 +475,10 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
475475
*/
476476
publicjava.sql.ResultSetExecSQL(Stringsql,java.sql.Statementstat)throwsSQLException
477477
{
478+
if (isClosed())
479+
{
480+
thrownewPSQLException("postgresql.con.closed");
481+
}
478482
returnnewQueryExecutor(newString[] {sql},EMPTY_OBJECT_ARRAY,stat,pg_stream, (java.sql.Connection)this).execute();
479483
}
480484
privatestaticfinalObject[]EMPTY_OBJECT_ARRAY =newObject[0];
@@ -494,6 +498,10 @@ public java.sql.ResultSet ExecSQL(String sql, java.sql.Statement stat) throws SQ
494498
*/
495499
publicjava.sql.ResultSetExecSQL(String[]p_sqlFragments,Object[]p_binds,java.sql.Statementstat)throwsSQLException
496500
{
501+
if (isClosed())
502+
{
503+
thrownewPSQLException("postgresql.con.closed");
504+
}
497505
returnnewQueryExecutor(p_sqlFragments,p_binds,stat,pg_stream, (java.sql.Connection)this).execute();
498506
}
499507

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

Lines changed: 87 additions & 10 deletions
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.12 2002/10/19 21:53:42 barry Exp $
11+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.13 2002/11/14 05:35:45 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
@@ -724,7 +724,55 @@ public long getLastOID() throws SQLException
724724
*/
725725
publicvoidsetNull(intparameterIndex,intsqlType)throwsSQLException
726726
{
727-
bind(parameterIndex,"null",PG_TEXT);
727+
Stringl_pgType;
728+
switch (sqlType)
729+
{
730+
caseTypes.INTEGER:
731+
l_pgType =PG_INTEGER;
732+
break;
733+
caseTypes.TINYINT:
734+
caseTypes.SMALLINT:
735+
l_pgType =PG_INT2;
736+
break;
737+
caseTypes.BIGINT:
738+
l_pgType =PG_INT8;
739+
break;
740+
caseTypes.REAL:
741+
caseTypes.FLOAT:
742+
l_pgType =PG_FLOAT;
743+
break;
744+
caseTypes.DOUBLE:
745+
l_pgType =PG_DOUBLE;
746+
break;
747+
caseTypes.DECIMAL:
748+
caseTypes.NUMERIC:
749+
l_pgType =PG_NUMERIC;
750+
break;
751+
caseTypes.CHAR:
752+
caseTypes.VARCHAR:
753+
caseTypes.LONGVARCHAR:
754+
l_pgType =PG_TEXT;
755+
break;
756+
caseTypes.DATE:
757+
l_pgType =PG_DATE;
758+
break;
759+
caseTypes.TIME:
760+
l_pgType =PG_TIME;
761+
break;
762+
caseTypes.TIMESTAMP:
763+
l_pgType =PG_TIMESTAMPTZ;
764+
break;
765+
caseTypes.BINARY:
766+
caseTypes.VARBINARY:
767+
l_pgType =PG_BYTEA;
768+
break;
769+
caseTypes.OTHER:
770+
l_pgType =PG_TEXT;
771+
break;
772+
default:
773+
l_pgType =PG_TEXT;
774+
}
775+
bind(parameterIndex,"null",l_pgType);
728776
}
729777

730778
/*
@@ -830,7 +878,7 @@ public void setDouble(int parameterIndex, double x) throws SQLException
830878
publicvoidsetBigDecimal(intparameterIndex,BigDecimalx)throwsSQLException
831879
{
832880
if (x ==null)
833-
setNull(parameterIndex,Types.OTHER);
881+
setNull(parameterIndex,Types.DECIMAL);
834882
else
835883
{
836884
bind(parameterIndex,x.toString(),PG_NUMERIC);
@@ -856,7 +904,7 @@ public void setString(int parameterIndex, String x, String type) throws SQLExcep
856904
{
857905
// if the passed string is null, then set this column to null
858906
if (x ==null)
859-
setNull(parameterIndex,Types.OTHER);
907+
setNull(parameterIndex,Types.VARCHAR);
860908
else
861909
{
862910
// use the shared buffer object. Should never clash but this makes
@@ -902,7 +950,7 @@ public void setBytes(int parameterIndex, byte x[]) throws SQLException
902950
//Version 7.2 supports the bytea datatype for byte arrays
903951
if (null ==x)
904952
{
905-
setNull(parameterIndex,Types.OTHER);
953+
setNull(parameterIndex,Types.VARBINARY);
906954
}
907955
else
908956
{
@@ -933,7 +981,7 @@ public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
933981
{
934982
if (null ==x)
935983
{
936-
setNull(parameterIndex,Types.OTHER);
984+
setNull(parameterIndex,Types.DATE);
937985
}
938986
else
939987
{
@@ -953,7 +1001,7 @@ public void setTime(int parameterIndex, Time x) throws SQLException
9531001
{
9541002
if (null ==x)
9551003
{
956-
setNull(parameterIndex,Types.OTHER);
1004+
setNull(parameterIndex,Types.TIME);
9571005
}
9581006
else
9591007
{
@@ -973,7 +1021,7 @@ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
9731021
{
9741022
if (null ==x)
9751023
{
976-
setNull(parameterIndex,Types.OTHER);
1024+
setNull(parameterIndex,Types.TIMESTAMP);
9771025
}
9781026
else
9791027
{
@@ -1288,7 +1336,7 @@ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale
12881336
{
12891337
if (x ==null)
12901338
{
1291-
setNull(parameterIndex,Types.OTHER);
1339+
setNull(parameterIndex,targetSqlType);
12921340
return ;
12931341
}
12941342
switch (targetSqlType)
@@ -1360,7 +1408,35 @@ public void setObject(int parameterIndex, Object x) throws SQLException
13601408
{
13611409
if (x ==null)
13621410
{
1363-
setNull(parameterIndex,Types.OTHER);
1411+
intl_sqlType;
1412+
if (xinstanceofString)
1413+
l_sqlType =Types.VARCHAR;
1414+
elseif (xinstanceofBigDecimal)
1415+
l_sqlType =Types.DECIMAL;
1416+
elseif (xinstanceofShort)
1417+
l_sqlType =Types.SMALLINT;
1418+
elseif (xinstanceofInteger)
1419+
l_sqlType =Types.INTEGER;
1420+
elseif (xinstanceofLong)
1421+
l_sqlType =Types.BIGINT;
1422+
elseif (xinstanceofFloat)
1423+
l_sqlType =Types.FLOAT;
1424+
elseif (xinstanceofDouble)
1425+
l_sqlType =Types.DOUBLE;
1426+
elseif (xinstanceofbyte[])
1427+
l_sqlType =Types.BINARY;
1428+
elseif (xinstanceofjava.sql.Date)
1429+
l_sqlType =Types.DATE;
1430+
elseif (xinstanceofTime)
1431+
l_sqlType =Types.TIME;
1432+
elseif (xinstanceofTimestamp)
1433+
l_sqlType =Types.TIMESTAMP;
1434+
elseif (xinstanceofBoolean)
1435+
l_sqlType =Types.OTHER;
1436+
else
1437+
l_sqlType =Types.OTHER;
1438+
1439+
setNull(parameterIndex,l_sqlType);
13641440
return ;
13651441
}
13661442
if (xinstanceofString)
@@ -1863,6 +1939,7 @@ public boolean isUseServerPrepare()
18631939
privatestaticfinalStringPG_DATE ="date";
18641940
privatestaticfinalStringPG_TIME ="time";
18651941
privatestaticfinalStringPG_TIMESTAMPTZ ="timestamptz";
1942+
privatestaticfinalStringPG_BYTEA ="bytea";
18661943

18671944

18681945
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp