[libpostgresql-jdbc-java] 03/11: Do comparison of identifiers in a known Locale (specificially US). In Turkish for example "id".toLowerCase().equals("ID".toLowerCase()) is false. This breaks apps running a Turkish locale.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:32 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_2_509
in repository libpostgresql-jdbc-java.
commit cdfd810b3034a5896b4de51e20a9ed79f88e0add
Author: Kris Jurka <books at ejurka.com>
Date: Tue Feb 19 06:12:41 2008 +0000
Do comparison of identifiers in a known Locale (specificially US).
In Turkish for example "id".toLowerCase().equals("ID".toLowerCase())
is false. This breaks apps running a Turkish locale.
As reported by Dirk Moebius and Hakan Cunier.
Patch from Mikko Tiihonen.
---
org/postgresql/jdbc2/AbstractJdbc2Connection.java | 4 ++--
org/postgresql/jdbc2/AbstractJdbc2ResultSet.java | 11 ++++++-----
org/postgresql/jdbc2/EscapedFunctions.java | 7 ++++---
org/postgresql/test/jdbc2/EncodingTest.java | 7 ++++---
org/postgresql/test/jdbc2/ResultSetTest.java | 22 +++++++++++++++++++++-
5 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
index dd20521..4e14024 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Connection.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v 1.40 2006/12/01 08:53:45 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v 1.40.2.2 2007/12/01 09:17:49 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -731,7 +731,7 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
if (level == null)
return Connection.TRANSACTION_READ_COMMITTED; // Best guess.
- level = level.toUpperCase();
+ level = level.toUpperCase(Locale.US);
if (level.indexOf("READ COMMITTED") != -1)
return Connection.TRANSACTION_READ_COMMITTED;
if (level.indexOf("READ UNCOMMITTED") != -1)
diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index 0f48c2f..f2185d9 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -3,7 +3,7 @@
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.88.2.2 2007/04/16 16:36:49 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.88.2.5 2008/01/14 10:23:58 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Calendar;
+import java.util.Locale;
import java.util.TimeZone;
import org.postgresql.core.*;
import org.postgresql.largeobject.*;
@@ -1627,10 +1628,10 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
name = st.nextToken();
if ( !tableFound )
{
- if (name.toLowerCase().equals("from"))
+ if ("from".equalsIgnoreCase(name))
{
tableName = st.nextToken();
- if (tableName.toLowerCase().equals("only")) {
+ if ("only".equalsIgnoreCase(tableName)) {
tableName = st.nextToken();
onlyTable = "ONLY ";
}
@@ -2482,7 +2483,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
// reverse order so the first ones will overwrite later ones.
for (int i = fields.length - 1; i >= 0; i--)
{
- columnNameIndexMap.put(fields[i].getColumnLabel().toLowerCase(), new Integer(i + 1));
+ columnNameIndexMap.put(fields[i].getColumnLabel().toLowerCase(Locale.US), new Integer(i + 1));
}
}
@@ -2492,7 +2493,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
return index.intValue();
}
- index = (Integer)columnNameIndexMap.get(columnName.toLowerCase());
+ index = (Integer)columnNameIndexMap.get(columnName.toLowerCase(Locale.US));
if (index != null)
{
columnNameIndexMap.put(columnName, index);
diff --git a/org/postgresql/jdbc2/EscapedFunctions.java b/org/postgresql/jdbc2/EscapedFunctions.java
index 6037449..5a81ec0 100644
--- a/org/postgresql/jdbc2/EscapedFunctions.java
+++ b/org/postgresql/jdbc2/EscapedFunctions.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/EscapedFunctions.java,v 1.7 2006/03/27 12:07:57 davec Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/EscapedFunctions.java,v 1.8 2006/04/04 22:52:42 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -12,6 +12,7 @@ package org.postgresql.jdbc2;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.HashMap;
+import java.util.Locale;
import java.util.List;
import java.util.Map;
@@ -130,10 +131,10 @@ public class EscapedFunctions {
for (int i=0;i<arrayMeths.length;i++){
Method meth = arrayMeths[i];
if (meth.getName().startsWith("sql"))
- functionMap.put(meth.getName().toLowerCase(),meth);
+ functionMap.put(meth.getName().toLowerCase(Locale.US),meth);
}
}
- return (Method) functionMap.get("sql"+functionName.toLowerCase());
+ return (Method) functionMap.get("sql"+functionName.toLowerCase(Locale.US));
}
// ** numeric functions translations **
diff --git a/org/postgresql/test/jdbc2/EncodingTest.java b/org/postgresql/test/jdbc2/EncodingTest.java
index 5c00b1a..8bd9244 100644
--- a/org/postgresql/test/jdbc2/EncodingTest.java
+++ b/org/postgresql/test/jdbc2/EncodingTest.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/EncodingTest.java,v 1.8 2004/11/09 08:54:27 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/EncodingTest.java,v 1.9 2005/01/11 08:25:48 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -13,6 +13,7 @@ package org.postgresql.test.jdbc2;
import junit.framework.*;
import org.postgresql.core.Encoding;
import java.io.*;
+import java.util.Locale;
/*
* Tests for the Encoding class.
@@ -32,9 +33,9 @@ public class EncodingTest extends TestCase
{
Encoding encoding;
encoding = Encoding.getDatabaseEncoding("UNICODE");
- assertEquals("UTF", encoding.name().substring(0, 3).toUpperCase());
+ assertEquals("UTF", encoding.name().substring(0, 3).toUpperCase(Locale.US));
encoding = Encoding.getDatabaseEncoding("SQL_ASCII");
- assertTrue(encoding.name().toUpperCase().indexOf("ASCII") != -1);
+ assertTrue(encoding.name().toUpperCase(Locale.US).indexOf("ASCII") != -1);
assertEquals("When encoding is unknown the default encoding should be used",
Encoding.defaultEncoding(),
Encoding.getDatabaseEncoding("UNKNOWN"));
diff --git a/org/postgresql/test/jdbc2/ResultSetTest.java b/org/postgresql/test/jdbc2/ResultSetTest.java
index 4d1fa74..bd66085 100644
--- a/org/postgresql/test/jdbc2/ResultSetTest.java
+++ b/org/postgresql/test/jdbc2/ResultSetTest.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/ResultSetTest.java,v 1.26 2005/11/05 09:24:15 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/ResultSetTest.java,v 1.27.2.1 2008/01/14 10:23:58 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -14,6 +14,7 @@ import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
+import java.util.Locale;
import junit.framework.TestCase;
@@ -705,4 +706,23 @@ public class ResultSetTest extends TestCase
assertTrue(rs.next());
assertEquals(1, rs.getInt("a"));
}
+
+ public void testTurkishLocale() throws SQLException
+ {
+ Locale current = Locale.getDefault();
+ try {
+ Locale.setDefault(new Locale("tr", "TR"));
+ Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT id FROM testrs");
+ int sum = 0;
+ while (rs.next()) {
+ sum += rs.getInt("ID");
+ }
+ rs.close();
+ assertEquals(25, sum);
+ } finally {
+ Locale.setDefault(current);
+ }
+ }
+
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list