Hi,

for interop with some production MySQL DB, I have to use
DATABASE_TO_UPPER=FALSE on H2. An unwanted side effect of this setting
is that function names become case-sensitive and fail to resolve
unless given in all upper-case. The following patch extends the logic
seen in isKeyword() to function lookups:

Index: src/main/org/h2/command/Parser.java
===================================================================
--- src/main/org/h2/command/Parser.java (revision 3778)
+++ src/main/org/h2/command/Parser.java (working copy)
@@ -2138,11 +2138,11 @@
         if (schema != null) {
             return readJavaFunction(schema, name);
         }
-        int agg = Aggregate.getAggregateType(name);
+        int agg = getAggregateType(name);
         if (agg >= 0) {
             return readAggregate(agg);
         }
-        Function function = Function.getFunction(database, name);
+        Function function = getFunction(database, name);
         if (function == null) {
             UserAggregate aggregate = database.findAggregate(name);
             if (aggregate != null) {
@@ -2280,7 +2280,7 @@
         if (readIf("(")) {
             read(")");
         }
-        Function function = Function.getFunction(database, name);
+        Function function = getFunction(database, name);
         function.doneWithParameters();
         return function;
     }
@@ -4053,7 +4053,7 @@
         CreateAggregate command = new CreateAggregate(session);
         command.setForce(force);
         String name = readIdentifierWithSchema();
-        if (isKeyword(name) || Function.getFunction(database, name) !
= null || Aggregate.getAggregateType(name) >= 0) {
+        if (isKeyword(name) || getFunction(database, name) != null ||
getAggregateType(name) >= 0) {
             throw
DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name);
         }
         command.setName(name);
@@ -4170,8 +4170,8 @@
         boolean ifNotExists = readIfNoExists();
         String aliasName = readIdentifierWithSchema();
         if (isKeyword(aliasName) ||
-                Function.getFunction(database, aliasName) != null ||
-                Aggregate.getAggregateType(aliasName) >= 0) {
+                getFunction(database, aliasName) != null ||
+                getAggregateType(aliasName) >= 0) {
             throw
DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, aliasName);
         }
         CreateFunctionAlias command = new
CreateFunctionAlias(session, getSchema());
@@ -5306,4 +5306,20 @@
         return readExpression();
     }

+    private int getAggregateType(String name) {
+        if (!identifiersToUpper) {
+            // if not yet converted to uppercase, do it now
+            name = StringUtils.toUpperEnglish(name);
+        }
+        return Aggregate.getAggregateType(name);
+    }
+
+    private Function getFunction(Database database, String name) {
+        if (!identifiersToUpper) {
+            // if not yet converted to uppercase, do it now
+            name = StringUtils.toUpperEnglish(name);
+        }
+        return Function.getFunction(database, name);
+    }
+
 }


Benjamin

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to