This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 914b87d356 Double quote the quotes in identifiers inside SQL 
statements.
914b87d356 is described below

commit 914b87d356e1ed64318790e858e738722b681746
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Tue Sep 29 15:05:45 2026 +0900

    Double quote the quotes in identifiers inside SQL statements.
---
 .../apache/sis/metadata/sql/internal/shared/SQLBuilder.java  | 10 +++++++++-
 .../sis/metadata/sql/internal/shared/SQLBuilderTest.java     | 12 ++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/SQLBuilder.java
 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/SQLBuilder.java
index 7e70bfb436..01e4015e7f 100644
--- 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/SQLBuilder.java
+++ 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/SQLBuilder.java
@@ -165,12 +165,20 @@ public class SQLBuilder extends Syntax {
 
     /**
      * Appends an identifier between quote characters.
+     * If the identifier contains quotes, the quotes will be doubled.
      *
      * @param  name  the identifier to append.
      * @return this builder, for method call chaining.
      */
     public final SQLBuilder appendIdentifier(final String name) {
-        buffer.append(identifierQuote).append(name).append(identifierQuote);
+        int i = buffer.append(identifierQuote).length();
+        buffer.append(name);
+        while ((i = buffer.indexOf(identifierQuote, i)) >= 0) {
+            final int n = identifierQuote.length();
+            buffer.insert(i += n, identifierQuote);
+            i += n;
+        }
+        buffer.append(identifierQuote);
         return this;
     }
 
diff --git 
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/internal/shared/SQLBuilderTest.java
 
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/internal/shared/SQLBuilderTest.java
index 0b8787f6e0..a8a0ea3306 100644
--- 
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/internal/shared/SQLBuilderTest.java
+++ 
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/internal/shared/SQLBuilderTest.java
@@ -62,6 +62,18 @@ public final class SQLBuilderTest extends TestCase {
         assertSame(builder, builder.clear());
     }
 
+    /**
+     * Tests the appending of an identifier.
+     */
+    public void testAppendIdentifier() {
+        assertSame(builder, builder.appendIdentifier("Foo"));
+        compareAndClear("\"Foo\"");
+        assertSame(builder, builder.appendIdentifier("Foo\"bar"));
+        compareAndClear("\"Foo\"\"bar\"");
+        assertSame(builder, builder.appendIdentifier("Foo\"bar\"\"more\""));
+        compareAndClear("\"Foo\"\"bar\"\"\"\"more\"\"\"");
+    }
+
     /**
      * Tests the formatting of values of different types.
      */

Reply via email to