sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1771153 - /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
Date Thu, 24 Nov 2016 14:31:09 GMT
Author: desruisseaux
Date: Thu Nov 24 14:31:09 2016
New Revision: 1771153

URL: http://svn.apache.org/viewvc?rev=1771153&view=rev
Log:
More robust handling of "EPSG" schema name in SQL statements.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java?rev=1771153&r1=1771152&r2=1771153&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] Thu Nov 24 14:31:09 2016
@@ -118,9 +118,10 @@ final class EPSGInstaller extends Script
              * Creates the schema on the database. We do that before to setup the 'toSchema'
map, while the map still null.
              * Note that we do not quote the schema name, which is a somewhat arbitrary choice.
              */
-            execute(new StringBuilder("CREATE SCHEMA ").append(schema));
+            execute(new StringBuilder("CREATE SCHEMA ").append(identifierQuote).append(schema).append(identifierQuote));
             if (isGrantOnSchemaSupported) {
-                execute(new StringBuilder("GRANT USAGE ON SCHEMA ").append(schema).append("
TO ").append(PUBLIC));
+                execute(new StringBuilder("GRANT USAGE ON SCHEMA ")
+                        .append(identifierQuote).append(schema).append(identifierQuote).append("
TO ").append(PUBLIC));
             }
             /*
              * Mapping from the table names used in the SQL scripts to the original names
used in the MS-Access database.
@@ -167,8 +168,18 @@ final class EPSGInstaller extends Script
      * Prepends the given schema or catalog to all table names.
      */
     final void prependNamespace(final String schema) {
-        modifyReplacements((key, value) -> key.startsWith(SQLTranslator.TABLE_PREFIX)
-                ? schema + '.' + identifierQuote + value + identifierQuote : value);
+        modifyReplacements((key, value) -> {
+            if (key.startsWith(SQLTranslator.TABLE_PREFIX)) {
+                final StringBuilder buffer = new StringBuilder(value.length() + schema.length()
+ 5);
+                buffer.append(identifierQuote).append(schema).append(identifierQuote).append('.');
+                final boolean isQuoted = value.endsWith(identifierQuote);
+                if (!isQuoted) buffer.append(identifierQuote);
+                buffer.append(value);
+                if (!isQuoted) buffer.append(identifierQuote);
+                value = buffer.toString();
+            }
+            return value;
+        });
     }
 
     /**



Mime
View raw message