Skip to content

fix #243 - parsing SQL scripts with semicolons and escaped single quotes #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/DatabaseLibrary/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
INSERT INTO person VALUES(5, 'Miles', 'O''Brian');
INSERT INTO person VALUES(5, 'Miles', 'O''Brian');
INSERT INTO person VALUES(6, 'Keiko', 'O''Brian');
5 changes: 3 additions & 2 deletions test/tests/common_tests/script_files.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***
Expand Down