|
| 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} |
0 commit comments