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

desruisseaux 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 8e43f19394 Revert the removal of the escape character sequences in 
`ScriptRunner`. This removal was done in commit 
967360a5f7c37127c9e1cec5a00605c5246168f0 because escape was not used by Apache 
SIS for metadata and EPSG scripts. However, we depend on it for prototypes in 
external repositories, and there is a possibility that SIS needs escaping in 
the future.
8e43f19394 is described below

commit 8e43f193946b4bd50f8dfa04a411aae821942274
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Wed Apr 15 18:10:09 2026 +0200

    Revert the removal of the escape character sequences in `ScriptRunner`.
    This removal was done in commit 967360a5f7c37127c9e1cec5a00605c5246168f0
    because escape was not used by Apache SIS for metadata and EPSG scripts.
    However, we depend on it for prototypes in external repositories,
    and there is a possibility that SIS needs escaping in the future.
---
 .../metadata/sql/internal/shared/ScriptRunner.java | 39 +++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/ScriptRunner.java
 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/ScriptRunner.java
index 65aaf34aa0..c681adf465 100644
--- 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/ScriptRunner.java
+++ 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/ScriptRunner.java
@@ -98,6 +98,22 @@ public class ScriptRunner implements AutoCloseable {
      */
     private static final char END_OF_STATEMENT = ';';
 
+    /**
+     * An escape sequence for delimiting a portion of the <abbr>SQL</abbr> 
script to copy verbatim.
+     * Escapes can be used, for example, for the definition of a trigger in a 
PostgreSQL script.
+     * The escape sequence should appear at the beginning of a line (ignoring 
whitespaces),
+     * because the characters before the escape sequence will not be parsed.
+     *
+     * <p><b>Restriction:</b> this string shall not begin with a whitespace or
+     * {@linkplain Character#isUnicodeIdentifierPart(int) Unicode identifier 
part}.</p>
+     *
+     * <p><b>Usage note:</b> this is currently not used directly by Apache 
<abbr>SIS</abbr>,
+     * but this is used by prototypes on external repositories which may or 
may not be ported
+     * to <abbr>SIS</abbr> in the future. If the experiments are not ported, 
this feature may
+     * be removed in any future <abbr>SIS</abbr> version.</p>
+     */
+    private static final String ESCAPE = "$BODY$";
+
     /**
      * The presumed dialect spoken by the database.
      */
@@ -451,13 +467,34 @@ public class ScriptRunner implements AutoCloseable {
             } else {
                 buffer.append('\n');
             }
+            /*
+             * If we find the "$BODY$" string, copy verbatism (without any 
attempt to parse the lines) until
+             * the next occurrence of "$BODY$".  This simple algorithm does 
not allow more than one block of
+             * "$BODY$ ... $BODY$" on the same statement and presumes that the 
text before "$BODY$" contains
+             * nothing that need to be parsed.
+             */
+            int pos = line.indexOf(ESCAPE);
+            if (pos >= 0) {
+                pos += ESCAPE.length();
+                while ((pos = line.indexOf(ESCAPE, pos)) < 0) {
+                    buffer.append(line).append('\n');
+                    line = in.readLine();
+                    if (line == null) {
+                        throw new EOFException();
+                    }
+                    pos = 0;
+                }
+                pos += ESCAPE.length();
+                buffer.append(line, 0, pos);
+                line = line.substring(pos);
+            }
             /*
              * Copy the current line in the buffer. Then, the loop will search 
for words or characters to replace
              * (for example replacements of IDENTIFIER_QUOTE character by the 
database-specific quote character).
              * Replacements (if any) will be performed in-place in the buffer. 
Concequently the buffer length may
              * vary during the loop execution.
              */
-            int pos = buffer.length();
+            pos = buffer.length();
             int length = buffer.append(line).length();
 parseLine:  while (pos < length) {
                 int c = buffer.codePointAt(pos);

Reply via email to