From 9b780dd8f27b7665f34c54ae738c41eccf73ad44 Mon Sep 17 00:00:00 2001 From: Peter Halicky Date: Mon, 6 May 2024 22:30:27 +0200 Subject: [PATCH] Add support for backtick enquoting in SQL script splitter (#8593) --- .../main/java/org/testcontainers/ext/ScriptScanner.java | 7 ++++++- .../java/org/testcontainers/ext/ScriptSplittingTest.java | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/database-commons/src/main/java/org/testcontainers/ext/ScriptScanner.java b/modules/database-commons/src/main/java/org/testcontainers/ext/ScriptScanner.java index 686527e9364..8350f7fbf38 100644 --- a/modules/database-commons/src/main/java/org/testcontainers/ext/ScriptScanner.java +++ b/modules/database-commons/src/main/java/org/testcontainers/ext/ScriptScanner.java @@ -141,7 +141,12 @@ Lexem next() { return Lexem.SEPARATOR; } else if (matchesSingleLineComment() || matchesMultilineComment()) { return Lexem.COMMENT; - } else if (matchesQuotedString('\'') || matchesQuotedString('"') || matchesDollarQuotedString()) { + } else if ( + matchesQuotedString('\'') || + matchesQuotedString('"') || + matchesQuotedString('`') || + matchesDollarQuotedString() + ) { return Lexem.QUOTED_STRING; } else if (matches(identifier)) { return Lexem.IDENTIFIER; diff --git a/modules/database-commons/src/test/java/org/testcontainers/ext/ScriptSplittingTest.java b/modules/database-commons/src/test/java/org/testcontainers/ext/ScriptSplittingTest.java index baaf3bbd08c..3f78e5c51db 100644 --- a/modules/database-commons/src/test/java/org/testcontainers/ext/ScriptSplittingTest.java +++ b/modules/database-commons/src/test/java/org/testcontainers/ext/ScriptSplittingTest.java @@ -68,6 +68,15 @@ public void testIssue1547Case2() { splitAndCompare(script, expected); } + @Test + public void testSplittingEnquotedSemicolon() { + String script = "CREATE TABLE `bar;bar` (\n" + " end_time VARCHAR(255)\n" + ");"; + + List expected = Arrays.asList("CREATE TABLE `bar;bar` ( end_time VARCHAR(255) )"); + + splitAndCompare(script, expected); + } + @Test public void testUnusualSemicolonPlacement() { String script = "SELECT 1;;;;;SELECT 2;\n;SELECT 3\n; SELECT 4;\n SELECT 5";