1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-28 11:44:57 +03:00

Merge changes from head to 7.3 branch: better error message on character set conversion problems and patch from Kris Jurka for numeric scale

Modified Files:
  Tag: REL7_3_STABLE
 	jdbc/org/postgresql/errors.properties
 	jdbc/org/postgresql/core/Encoding.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
This commit is contained in:
Barry Lind
2003-02-09 23:41:46 +00:00
parent 521d70f661
commit 3448835967
3 changed files with 36 additions and 31 deletions

View File

@@ -8,7 +8,7 @@ import org.postgresql.util.*;
/* /*
* Converts to and from the character encoding used by the backend. * Converts to and from the character encoding used by the backend.
* *
* $Id: Encoding.java,v 1.7.2.1 2002/11/14 05:54:39 barry Exp $ * $Id: Encoding.java,v 1.7.2.2 2003/02/09 23:41:46 barry Exp $
*/ */
public class Encoding public class Encoding
@@ -235,36 +235,40 @@ public class Encoding
private static final int pow2_12 = 4096; // 212 private static final int pow2_12 = 4096; // 212
private char[] cdata = new char[50]; private char[] cdata = new char[50];
private synchronized String decodeUTF8(byte data[], int offset, int length) { private synchronized String decodeUTF8(byte data[], int offset, int length) throws SQLException {
char[] l_cdata = cdata; try {
if (l_cdata.length < (length)) { char[] l_cdata = cdata;
l_cdata = new char[length]; if (l_cdata.length < (length)) {
} l_cdata = new char[length];
int i = offset; }
int j = 0; int i = offset;
int k = length + offset; int j = 0;
int z, y, x, val; int k = length + offset;
while (i < k) { int z, y, x, val;
z = data[i] & 0xFF; while (i < k) {
if (z < 0x80) { z = data[i] & 0xFF;
l_cdata[j++] = (char)data[i]; if (z < 0x80) {
i++; l_cdata[j++] = (char)data[i];
} else if (z >= 0xE0) { // length == 3 i++;
y = data[i+1] & 0xFF; } else if (z >= 0xE0) { // length == 3
x = data[i+2] & 0xFF; y = data[i+1] & 0xFF;
val = (z-0xE0)*pow2_12 + (y-0x80)*pow2_6 + (x-0x80); x = data[i+2] & 0xFF;
l_cdata[j++] = (char) val; val = (z-0xE0)*pow2_12 + (y-0x80)*pow2_6 + (x-0x80);
i+= 3; l_cdata[j++] = (char) val;
} else { // length == 2 (maybe add checking for length > 3, throw exception if it is i+= 3;
y = data[i+1] & 0xFF; } else { // length == 2 (maybe add checking for length > 3, throw exception if it is
val = (z - 0xC0)* (pow2_6)+(y-0x80); y = data[i+1] & 0xFF;
l_cdata[j++] = (char) val; val = (z - 0xC0)* (pow2_6)+(y-0x80);
i+=2; l_cdata[j++] = (char) val;
i+=2;
}
} }
}
String s = new String(l_cdata, 0, j); String s = new String(l_cdata, 0, j);
return s; return s;
} catch (Exception l_e) {
throw new PSQLException("postgresql.con.invalidchar", l_e);
}
} }
} }

View File

@@ -5,6 +5,7 @@ postgresql.con.auth:The authentication type {0} is not supported. Check that you
postgresql.con.authfail:An error occured while getting the authentication request. postgresql.con.authfail:An error occured while getting the authentication request.
postgresql.con.backend:Backend start-up failed: {0} postgresql.con.backend:Backend start-up failed: {0}
postgresql.con.call:Callable Statements are not supported at this time. postgresql.con.call:Callable Statements are not supported at this time.
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.
postgresql.con.closed:Connection is closed. Operation is not permitted. postgresql.con.closed:Connection is closed. Operation is not permitted.
postgresql.con.creobj:Failed to create object for {0} {1} postgresql.con.creobj:Failed to create object for {0} {1}
postgresql.con.failed:The connection attempt failed because {0} postgresql.con.failed:The connection attempt failed because {0}

View File

@@ -2337,7 +2337,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
} }
else if (pgType.equals("numeric") || pgType.equals("decimal")) else if (pgType.equals("numeric") || pgType.equals("decimal"))
{ {
int attypmod = rs.getInt(8) - VARHDRSZ; int attypmod = rs.getInt("atttypmod") - VARHDRSZ;
tuple[6] = Integer.toString( ( attypmod >> 16 ) & 0xffff ).getBytes(); tuple[6] = Integer.toString( ( attypmod >> 16 ) & 0xffff ).getBytes();
tuple[8] = Integer.toString(attypmod & 0xffff).getBytes(); tuple[8] = Integer.toString(attypmod & 0xffff).getBytes();
tuple[9] = "10".getBytes(); tuple[9] = "10".getBytes();