[libpostgresql-jdbc-java] 03/09: 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:14 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_1_413
in repository libpostgresql-jdbc-java.

commit 5e57f3407022392362d7507df5b9febd330d747a
Author: Kris Jurka <books at ejurka.com>
Date:   Tue Feb 19 06:12:51 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 f2ca327..5828529 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.32 2005/08/01 06:54:14 oliver Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v 1.32.2.2 2007/12/01 09:17:59 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -699,7 +699,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 d261bc4..3468745 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.80.2.4 2007/04/16 16:36:56 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.80.2.7 2008/01/14 10:24:07 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -24,6 +24,7 @@ import java.util.StringTokenizer;
 import java.util.Vector;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
+import java.util.Locale;
 import java.util.TimeZone;
 import org.postgresql.Driver;
 import org.postgresql.core.*;
@@ -1663,10 +1664,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 ";
                     }
@@ -2371,7 +2372,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));
             }
         }
 
@@ -2381,7 +2382,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 df1b73e..4899a69 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.5 2005/01/25 06:49:28 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/EscapedFunctions.java,v 1.6 2005/06/04 18:24:08 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;
 
@@ -113,10 +114,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 b669fa8..438a4bc 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.25 2005/01/11 08:25:48 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/ResultSetTest.java,v 1.26.2.1 2008/01/14 10:24:07 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