From afdeb6de01e896d1c7917286aae243b9d5d2bbb9 Mon Sep 17 00:00:00 2001 From: amochin Date: Fri, 27 Jun 2025 11:09:20 +0200 Subject: [PATCH] fix #243 - parsing SQL scripts with semicolons and escaped single quotes --- src/DatabaseLibrary/query.py | 1 - .../script_file_tests/semicolons_and_quotes_in_values.sql | 3 ++- test/tests/common_tests/script_files.robot | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/DatabaseLibrary/query.py b/src/DatabaseLibrary/query.py index 3649203..0c68f99 100644 --- a/src/DatabaseLibrary/query.py +++ b/src/DatabaseLibrary/query.py @@ -346,7 +346,6 @@ def execute_sql_script( # check if the semicolon is a part of the value (quoted string) quotes += sqlFragment.count("'") quotes -= sqlFragment.count("\\'") - quotes -= sqlFragment.count("''") inside_quoted_string = quotes % 2 != 0 if inside_quoted_string: sqlFragment += ";" # restore the semicolon diff --git a/test/resources/script_file_tests/semicolons_and_quotes_in_values.sql b/test/resources/script_file_tests/semicolons_and_quotes_in_values.sql index d5a846a..1a9813b 100644 --- a/test/resources/script_file_tests/semicolons_and_quotes_in_values.sql +++ b/test/resources/script_file_tests/semicolons_and_quotes_in_values.sql @@ -1 +1,2 @@ -INSERT INTO person VALUES(5, 'Miles', 'O''Brian'); \ No newline at end of file +INSERT INTO person VALUES(5, 'Miles', 'O''Brian'); +INSERT INTO person VALUES(6, 'Keiko', 'O''Brian'); diff --git a/test/tests/common_tests/script_files.robot b/test/tests/common_tests/script_files.robot index 2d067ec..09d3ae0 100644 --- a/test/tests/common_tests/script_files.robot +++ b/test/tests/common_tests/script_files.robot @@ -29,10 +29,11 @@ Semicolons In Values Semicolons And Quotes In Values Run SQL Script File semicolons_and_quotes_in_values ${sql}= Catenate select * from person - ... where id=5 + ... where LAST_NAME='O''Brian' ${results}= Query ${sql} - Length Should Be ${results} 1 + Length Should Be ${results} 2 Should Be Equal As Strings ${results}[0] (5, 'Miles', "O'Brian") + Should Be Equal As Strings ${results}[1] (6, 'Keiko', "O'Brian") *** Keywords ***