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

Commitabcec0c

Browse files
author
Barry Lind
committed
Better error message on character set mismatches during conversion to unicode.
Also applied patch from Lars Stenberg to make callable statements use the formselect * from func() when running against a 7.3 server instead of select func() to allow for set returning functions to be called. Modified Files: jdbc/org/postgresql/errors.properties jdbc/org/postgresql/core/Encoding.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
1 parent39b7ec3 commitabcec0c

File tree

3 files changed

+43
-33
lines changed

3 files changed

+43
-33
lines changed

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

Lines changed: 34 additions & 30 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.8 2002/11/14 05:35:45 barry Exp $
11+
* $Id: Encoding.java,v 1.9 2003/02/09 23:14:55 barry Exp $
1212
*/
1313

1414
publicclassEncoding
@@ -235,36 +235,40 @@ private static boolean isAvailable(String encodingName)
235235
privatestaticfinalintpow2_12 =4096;// 212
236236
privatechar[]cdata =newchar[50];
237237

238-
privatesynchronizedStringdecodeUTF8(bytedata[],intoffset,intlength) {
239-
char[]l_cdata =cdata;
240-
if (l_cdata.length < (length)) {
241-
l_cdata =newchar[length];
242-
}
243-
inti =offset;
244-
intj =0;
245-
intk =length +offset;
246-
intz,y,x,val;
247-
while (i <k) {
248-
z =data[i] &0xFF;
249-
if (z <0x80) {
250-
l_cdata[j++] = (char)data[i];
251-
i++;
252-
}elseif (z >=0xE0) {// length == 3
253-
y =data[i+1] &0xFF;
254-
x =data[i+2] &0xFF;
255-
val = (z-0xE0)*pow2_12 + (y-0x80)*pow2_6 + (x-0x80);
256-
l_cdata[j++] = (char)val;
257-
i+=3;
258-
}else {// length == 2 (maybe add checking for length > 3, throw exception if it is
259-
y =data[i+1] &0xFF;
260-
val = (z -0xC0)* (pow2_6)+(y-0x80);
261-
l_cdata[j++] = (char)val;
262-
i+=2;
263-
}
264-
}
238+
privatesynchronizedStringdecodeUTF8(bytedata[],intoffset,intlength)throwsSQLException {
239+
try {
240+
char[]l_cdata =cdata;
241+
if (l_cdata.length < (length)) {
242+
l_cdata =newchar[length];
243+
}
244+
inti =offset;
245+
intj =0;
246+
intk =length +offset;
247+
intz,y,x,val;
248+
while (i <k) {
249+
z =data[i] &0xFF;
250+
if (z <0x80) {
251+
l_cdata[j++] = (char)data[i];
252+
i++;
253+
}elseif (z >=0xE0) {// length == 3
254+
y =data[i+1] &0xFF;
255+
x =data[i+2] &0xFF;
256+
val = (z-0xE0)*pow2_12 + (y-0x80)*pow2_6 + (x-0x80);
257+
l_cdata[j++] = (char)val;
258+
i+=3;
259+
}else {// length == 2 (maybe add checking for length > 3, throw exception if it is
260+
y =data[i+1] &0xFF;
261+
val = (z -0xC0)* (pow2_6)+(y-0x80);
262+
l_cdata[j++] = (char)val;
263+
i+=2;
264+
}
265+
}
265266

266-
Strings =newString(l_cdata,0,j);
267-
returns;
267+
Strings =newString(l_cdata,0,j);
268+
returns;
269+
}catch (Exceptionl_e) {
270+
thrownewPSQLException("postgresql.con.invalidchar",l_e);
271+
}
268272
}
269273

270274
}

‎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.invalidchar:Invalid character data was found. This is most likely caused by stored data containing characters that are invalid for the character set the database was created in. The most common example of this is storing 8bit data in a SQL_ASCII database.
89
postgresql.con.closed:Connection is closed. Operation is not permitted.
910
postgresql.con.creobj:Failed to create object for {0} {1}
1011
postgresql.con.failed:The connection attempt failed because {0}

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

Lines changed: 8 additions & 3 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.16 2003/02/04 10:09:32 barry Exp $
11+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.17 2003/02/09 23:14:55 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
@@ -63,7 +63,7 @@ public org.postgresql.PGConnection getPGConnection() {
6363

6464
//Used by the callablestatement style methods
6565
privatestaticfinalStringJDBC_SYNTAX ="{[? =] call <some_function> ([? [,?]*]) }";
66-
privatestaticfinalStringRESULT_COLUMN ="result";
66+
privatestaticfinalStringRESULT_ALIAS ="result";
6767
privateStringoriginalSql ="";
6868
privatebooleanisFunction;
6969
// functionReturnType contains the user supplied value to check
@@ -1957,6 +1957,7 @@ private void setSerialize(int parameterIndex, long x, String classname) throws S
19571957
* {? = call <some_function> (?, [?,..]) }
19581958
* into the PostgreSQL format which is
19591959
* select <some_function> (?, [?, ...]) as result
1960+
* or select * from <some_function> (?, [?, ...]) as result (7.3)
19601961
*
19611962
*/
19621963
privateStringmodifyJdbcCall(Stringp_sql)throwsSQLException
@@ -2000,7 +2001,11 @@ private String modifyJdbcCall(String p_sql) throws SQLException
20002001
// sure that the parameter numbers are the same as in the original
20012002
// sql we add a dummy parameter in this case
20022003
l_sql = (isFunction ?"?" :"") +l_sql.substring (index +4);
2003-
l_sql ="select " +l_sql +" as " +RESULT_COLUMN +";";
2004+
if (connection.haveMinimumServerVersion("7.3")) {
2005+
l_sql ="select * from " +l_sql +" as " +RESULT_ALIAS +";";
2006+
}else {
2007+
l_sql ="select " +l_sql +" as " +RESULT_ALIAS +";";
2008+
}
20042009
returnl_sql;
20052010
}
20062011

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp