From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: getTables() doesn't handle umlauts correctly
Date: Tue, 23 Nov 2010 15:22:10 +0100
Message-ID: <icgimh$46u$1@dough.gmane.org> (raw)
In-Reply-To: <alpine.BSO.2.00.1011230301020.26635@leary.csoft.net>
References: <icc7cc$19a$1@dough.gmane.org>
<icdqc3$v7n$1@news.albasani.net>
<icdsfe$7j8$1@dough.gmane.org>
<AANLkTikcbX=9JD-R07fLa5YrHJc4yRbi-YP-mLsAC8_G@mail.gmail.com>
<4CEABC66.2010201@ttc-cmc.net>
<iceeib$7iu$1@dough.gmane.org>
<AANLkTingOB+gDrCtz4GDe5Z9x-gLfAOFk6U3d_FfKZOq@mail.gmail.com>
<icerif$7p2$1@dough.gmane.org>
<alpine.BSO.2.00.1011230301020.26635@leary.csoft.net>
Kris Jurka, 23.11.2010 09:13:
> As the discussion has shown, trying to determine who is at fault here
> is not trivial. The best way to show that postgresql (driver or
> server if you're seeing it in pgadmin too) is at fault is to create a
> test case creating the table and then querying the metadata. It would
> be helpful to use either a Java or PG escape code for the special
> character so it doesn't get mangled by either mail clients or build
> environments. Then use String.codePointAt to print out the actual
> data for both the table name used for construction and returned by
> the metadata. That would conclusively show that PG is at fault
> somewhere.
OK, this is my test program:
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "postgres");
Statement stmt = con.createStatement();
stmt.executeUpdate("create table umlaut_ö (some_data varchar(10))");
stmt.executeUpdate("insert into umlaut_ö (some_data) values ('öäü')");
ResultSet rs = con.getMetaData().getTables(null, "public", "umlaut%", null);
if (rs.next()) {
String name = rs.getString("TABLE_NAME");
System.out.println("table name: " + name);
System.out.print(" codepoints:");
for (int i = 0; i < name.length();)
{
int cp = name.codePointAt(i);
System.out.print(" " + cp);
i += Character.charCount(cp);
}
System.out.println("");
}
rs.close();
rs = stmt.executeQuery("select count(*) from umlaut_ö where some_data = 'öäü'");
if (rs.next()) {
int count = rs.getInt(1);
System.out.println("number of rows: " + count);
}
rs.close();
rs = stmt.executeQuery("select some_data from umlaut_ö");
if (rs.next()) {
String data = rs.getString(1);
System.out.println("data: " + data);
System.out.print(" codepoints:");
for (int i = 0; i < data.length();)
{
int cp = data.codePointAt(i);
System.out.print(" " + cp);
i += Character.charCount(cp);
}
System.out.println("");
}
rs.close();
stmt.executeUpdate("drop table umlaut_ö");
stmt.close();
con.close();
The output on my computer is:
table name: umlaut_test_�
codepoints: 117 109 108 97 117 116 95 116 101 115 116 95 65533
number of rows: 1
data: öäü
codepoints: 246 228 252
So it seems that the umlauts in the table name are returned with a different encoding than the data itself.
Nevertheless the umlauts when being *sent* to the server are always treated correctly (as part of a table name as well as column values)
This is with 9.0.1 on Windows XP using postgresql-9.0-801.jdbc4.jar
Regards
Thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: getTables() doesn't handle umlauts correctly
In-Reply-To: <icgimh$46u$1@dough.gmane.org>
References: <icc7cc$19a$1@dough.gmane.org> <icdqc3$v7n$1@news.albasani.net> <icdsfe$7j8$1@dough.gmane.org> <AANLkTikcbX=9JD-R07fLa5YrHJc4yRbi-YP-mLsAC8_G@mail.gmail.com> <4CEABC66.2010201@ttc-cmc.net> <iceeib$7iu$1@dough.gmane.org> <AANLkTingOB+gDrCtz4GDe5Z9x-gLfAOFk6U3d_FfKZOq@mail.gmail.com> <icerif$7p2$1@dough.gmane.org> <alpine.BSO.2.00.1011230301020.26635@leary.csoft.net> <icgimh$46u$1@dough.gmane.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox