Skip to content

Commit 486cc51

Browse files
committed
Tests for SQL splitting
1 parent b13a8ea commit 486cc51

File tree

4 files changed

+124
-58
lines changed

4 files changed

+124
-58
lines changed

test/tests/common_tests/basic_tests.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,4 @@ Verify Query - Row Count foobar table 0 row
161161
Query Returns Zero Results
162162
[Documentation] Tests that nothing crashes when there are zero results
163163
${results}= Query SELECT * FROM person WHERE id < 0
164-
Should Be Empty ${results}
164+
Should Be Empty ${results}

test/tests/common_tests/script_files.robot

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Suite Teardown Disconnect From Database
66
Test Setup Create Person Table
77
Test Teardown Drop Tables Person And Foobar
88

9-
109
*** Test Cases ***
1110
Semicolons As Statement Separators In One Line
1211
Run SQL Script File statements_in_one_line
@@ -35,40 +34,6 @@ Semicolons And Quotes In Values
3534
Should Be Equal As Strings ${results}[0] (5, 'Miles', "O'Brian")
3635
Should Be Equal As Strings ${results}[1] (6, 'Keiko', "O'Brian")
3736

38-
Split Script Into Statements - Internal Parser
39-
Insert Data In Person Table Using SQL Script
40-
@{Expected commands}= Create List
41-
... SELECT * FROM person
42-
... SELECT * FROM person WHERE id=1
43-
${extracted commands}= Split Sql Script ${Script files dir}/split_commands.sql
44-
Lists Should Be Equal ${Expected commands} ${extracted commands}
45-
FOR ${command} IN @{extracted commands}
46-
${results}= Query ${command}
47-
END
48-
49-
Split Script Into Statements - External Parser
50-
Insert Data In Person Table Using SQL Script
51-
@{Expected commands}= Create List
52-
... SELECT * FROM person;
53-
... SELECT * FROM person WHERE id=1;
54-
${extracted commands}= Split Sql Script ${Script files dir}/split_commands.sql external_parser=True
55-
Lists Should Be Equal ${Expected commands} ${extracted commands}
56-
FOR ${command} IN @{extracted commands}
57-
${results}= Query ${command}
58-
END
59-
60-
Split Script Into Statements - External Parser - Comments Are Removed
61-
Insert Data In Person Table Using SQL Script
62-
@{Expected commands}= Create List
63-
... SELECT * FROM person;
64-
... SELECT * FROM person WHERE id=1;
65-
${extracted commands}= Split Sql Script ${Script files dir}/split_commands_comments.sql external_parser=True
66-
Lists Should Be Equal ${Expected commands} ${extracted commands}
67-
FOR ${command} IN @{extracted commands}
68-
${results}= Query ${command}
69-
END
70-
71-
7237
*** Keywords ***
7338
Run SQL Script File
7439
[Arguments] ${File Name}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
*** Settings ***
2+
Documentation Tests for the splitting SQL scripts and string into separate statements.
3+
...
4+
... First time implementation of the _split_ parameter see in:
5+
... https://github.com/MarketSquare/Robotframework-Database-Library/issues/184
6+
7+
Resource ../../resources/common.resource
8+
Suite Setup Connect To DB
9+
Suite Teardown Disconnect From Database
10+
Test Setup Create Person Table
11+
Test Teardown Drop Tables Person And Foobar
12+
13+
*** Variables ***
14+
@{SQL Commands No Semicolons}
15+
... SELECT * FROM person
16+
... SELECT * FROM person WHERE id=1
17+
18+
@{SQL Commands With Semicolons}
19+
... SELECT * FROM person;
20+
... SELECT * FROM person WHERE id=1;
21+
22+
*** Test Cases ***
23+
Run Script With Commands Splitting
24+
[Documentation] Such a simple script works always,
25+
... just check in the logs if the parameter value was processed properly
26+
Run SQL Script File insert_data_in_person_table split=True
27+
28+
Run Script Without Commands Splitting
29+
[Documentation] Running such a script as a single statement works for PostgreSQL,
30+
... but fails in Oracle. Check in the logs if the splitting was disabled.
31+
Skip If $DB_MODULE != "psycopg2"
32+
Run SQL Script File insert_data_in_person_table split=False
33+
34+
Run Script Split With External Parser
35+
[Documentation] We don't want to test the external parser itself, but just assure
36+
... the parameter works properly
37+
Run SQL Script File insert_data_in_person_table split=True external_parser=True
38+
39+
Run Script With Semicolons As Statement Separators In One Line
40+
Run SQL Script File statements_in_one_line split=True
41+
${sql}= Catenate select * from person
42+
... where id=6 or id=7
43+
${results}= Query ${sql}
44+
Length Should Be ${results} 2
45+
Should Be Equal As Strings ${results}[0] (6, 'Julian', 'Bashir')
46+
Should Be Equal As Strings ${results}[1] (7, 'Jadzia', 'Dax')
47+
48+
Run Script With Semicolons In Values
49+
Run SQL Script File semicolons_in_values split=True
50+
${sql}= Catenate select * from person
51+
... where id=3 or id=4
52+
${results}= Query ${sql}
53+
Length Should Be ${results} 2
54+
Should Be Equal As Strings ${results}[0] (3, 'Hello; world', 'Another; value')
55+
Should Be Equal As Strings ${results}[1] (4, 'May the Force; ', 'be with you;')
56+
57+
Run Script With Semicolons And Quotes In Values
58+
Run SQL Script File semicolons_and_quotes_in_values split=True
59+
${sql}= Catenate select * from person
60+
... where LAST_NAME='O''Brian'
61+
${results}= Query ${sql}
62+
Length Should Be ${results} 2
63+
Should Be Equal As Strings ${results}[0] (5, 'Miles', "O'Brian")
64+
Should Be Equal As Strings ${results}[1] (6, 'Keiko', "O'Brian")
65+
66+
Split Script Into Statements - Internal Parser
67+
Insert Data In Person Table Using SQL Script
68+
${extracted commands}= Split Sql Script ${Script files dir}/split_commands.sql
69+
Lists Should Be Equal ${SQL Commands No Semicolons} ${extracted commands}
70+
FOR ${command} IN @{extracted commands}
71+
${results}= Query ${command}
72+
END
73+
74+
Split Script Into Statements - External Parser
75+
Insert Data In Person Table Using SQL Script
76+
${extracted commands}= Split Sql Script ${Script files dir}/split_commands.sql external_parser=True
77+
Lists Should Be Equal ${SQL Commands With Semicolons} ${extracted commands}
78+
FOR ${command} IN @{extracted commands}
79+
${results}= Query ${command}
80+
END
81+
82+
Split Script Into Statements - External Parser - Comments Are Removed
83+
Insert Data In Person Table Using SQL Script
84+
${extracted commands}= Split Sql Script ${Script files dir}/split_commands_comments.sql external_parser=True
85+
Lists Should Be Equal ${SQL Commands With Semicolons} ${extracted commands}
86+
FOR ${command} IN @{extracted commands}
87+
${results}= Query ${command}
88+
END
89+
90+
Split SQL String Into Statements - Internal Parser
91+
Insert Data In Person Table Using SQL Script
92+
${merged command}= Catenate @{SQL Commands With Semicolons}
93+
${extracted commands}= Split Sql String ${merged command}
94+
Lists Should Be Equal ${extracted commands} ${SQL Commands No Semicolons}
95+
96+
Split SQL String Into Statements - External Parser
97+
Insert Data In Person Table Using SQL Script
98+
${merged command}= Catenate @{SQL Commands With Semicolons}
99+
${extracted commands}= Split Sql String ${merged command} external_parser=True
100+
Lists Should Be Equal ${extracted commands} ${SQL Commands With Semicolons}
101+
102+
Execute SQL String Without Splitting
103+
[Documentation] Running such a command as a single statement works for PostgreSQL,
104+
... but fails in Oracle. Check in the logs if the splitting was disabled.
105+
Skip If $DB_MODULE != "psycopg2"
106+
Insert Data In Person Table Using SQL Script
107+
${merged command}= Catenate @{SQL Commands With Semicolons}
108+
Execute Sql String ${merged command} split=False
109+
110+
Execute SQL String With Splitting - Internal Parser
111+
Insert Data In Person Table Using SQL Script
112+
${merged command}= Catenate @{SQL Commands With Semicolons}
113+
Execute Sql String ${merged command} split=True
114+
115+
Execute SQL String With Splitting - External Parser
116+
Insert Data In Person Table Using SQL Script
117+
${merged command}= Catenate @{SQL Commands With Semicolons}
118+
Execute Sql String ${merged command} split=True external_parser=True
119+
120+
*** Keywords ***
121+
Run SQL Script File
122+
[Arguments] ${File Name} ${split} ${external_parser}=False
123+
Execute Sql Script ${Script files dir}/${File Name}.sql split=${Split} external_parser=${external_parser}

test/tests/custom_db_tests/sql_script_split_commands.robot

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)