Skip to content

Commit 17d4e82

Browse files
author
Jerry Schneider
committed
changed sql commands to uppercase and fixed delete all keyword
1 parent cf13da1 commit 17d4e82

File tree

2 files changed

+54
-53
lines changed

2 files changed

+54
-53
lines changed

src/DatabaseLibrary/assertion.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ def check_if_exists_in_database(self,selectStatement):
2828
| 1 | Franz Allan | See |
2929
3030
When you have the following assertions in your robot
31-
| Check If Exists In Database | select id from person where first_name = 'Franz Allan' |
32-
| Check If Exists In Database | select id from person where first_name = 'John' |
31+
| Check If Exists In Database | SELECT id FROM person WHERE first_name = 'Franz Allan' |
32+
| Check If Exists In Database | SELECT id FROM person WHERE first_name = 'John' |
3333
3434
Then you will get the following:
35-
| Check If Exists In Database | select id from person where first_name = 'Franz Allan' | # PASS |
36-
| Check If Exists In Database | select id from person where first_name = 'John' | # FAIL |
35+
| Check If Exists In Database | SELECT id FROM person WHERE first_name = 'Franz Allan' | # PASS |
36+
| Check If Exists In Database | SELECT id FROM person WHERE first_name = 'John' | # FAIL |
3737
"""
3838
if not self.query(selectStatement):
3939
raise AssertionError("Expected to have have at least one row from '%s' "
@@ -52,12 +52,12 @@ def check_if_not_exists_in_database(self,selectStatement):
5252
| 1 | Franz Allan | See |
5353
5454
When you have the following assertions in your robot
55-
| Check If Not Exists In Database | select id from person where first_name = 'John' |
56-
| Check If Not Exists In Database | select id from person where first_name = 'Franz Allan' |
55+
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = 'John' |
56+
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = 'Franz Allan' |
5757
5858
Then you will get the following:
59-
| Check If Not Exists In Database | select id from person where first_name = 'John' | # PASS |
60-
| Check If Not Exists In Database | select id from person where first_name = 'Franz Allan' | # FAIL |
59+
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = 'John' | # PASS |
60+
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = 'Franz Allan' | # FAIL |
6161
"""
6262
queryResults = self.query(selectStatement)
6363
if queryResults:
@@ -74,12 +74,12 @@ def row_count_is_0(self,selectStatement):
7474
| 1 | Franz Allan | See |
7575
7676
When you have the following assertions in your robot
77-
| Row Count is 0 | select id from person where first_name = 'Franz Allan' |
78-
| Row Count is 0 | select id from person where first_name = 'John' |
77+
| Row Count is 0 | SELECT id FROM person WHERE first_name = 'Franz Allan' |
78+
| Row Count is 0 | SELECT id FROM person WHERE first_name = 'John' |
7979
8080
Then you will get the following:
81-
| Row Count is 0 | select id from person where first_name = 'Franz Allan' | # FAIL |
82-
| Row Count is 0 | select id from person where first_name = 'John' | # PASS |
81+
| Row Count is 0 | SELECT id FROM person WHERE first_name = 'Franz Allan' | # FAIL |
82+
| Row Count is 0 | SELECT id FROM person WHERE first_name = 'John' | # PASS |
8383
"""
8484
num_rows = self.row_count(selectStatement)
8585
if (num_rows > 0):
@@ -97,12 +97,12 @@ def row_count_is_equal_to_x(self,selectStatement,numRows):
9797
| 2 | Jerry | Schneider |
9898
9999
When you have the following assertions in your robot
100-
| Row Count Is Equal To X | select id from person | 1 |
101-
| Row Count Is Equal To X | select id from person where first_name = 'John' | 0 |
100+
| Row Count Is Equal To X | SELECT id FROM person | 1 |
101+
| Row Count Is Equal To X | SELECT id FROM person WHERE first_name = 'John' | 0 |
102102
103103
Then you will get the following:
104-
| Row Count Is Equal To X | select id from person | 1 | # FAIL |
105-
| Row Count Is Equal To X | select id from person where first_name = 'John' | 0 | # PASS |
104+
| Row Count Is Equal To X | SELECT id FROM person | 1 | # FAIL |
105+
| Row Count Is Equal To X | SELECT id FROM person WHERE first_name = 'John' | 0 | # PASS |
106106
"""
107107
num_rows = self.row_count(selectStatement)
108108
if (num_rows != int(numRows.encode('ascii'))):
@@ -120,12 +120,12 @@ def row_count_is_greater_than_x(self,selectStatement,numRows):
120120
| 2 | Jerry | Schneider |
121121
122122
When you have the following assertions in your robot
123-
| Row Count Is Greater Than X | select id from person | 1 |
124-
| Row Count Is Greater Than X | select id from person where first_name = 'John' | 0 |
123+
| Row Count Is Greater Than X | SELECT id FROM person | 1 |
124+
| Row Count Is Greater Than X | SELECT id FROM person WHERE first_name = 'John' | 0 |
125125
126126
Then you will get the following:
127-
| Row Count Is Greater Than X | select id from person | 1 | # PASS |
128-
| Row Count Is Greater Than X | select id from person where first_name = 'John' | 0 | # FAIL |
127+
| Row Count Is Greater Than X | SELECT id FROM person | 1 | # PASS |
128+
| Row Count Is Greater Than X | SELECT id FROM person WHERE first_name = 'John' | 0 | # FAIL |
129129
"""
130130
num_rows = self.row_count(selectStatement)
131131
if (num_rows <= int(numRows.encode('ascii'))):
@@ -143,12 +143,12 @@ def row_count_is_less_than_x(self,selectStatement,numRows):
143143
| 2 | Jerry | Schneider |
144144
145145
When you have the following assertions in your robot
146-
| Row Count Is Less Than X | select id from person | 3 |
147-
| Row Count Is Less Than X | select id from person where first_name = 'John' | 1 |
146+
| Row Count Is Less Than X | SELECT id FROM person | 3 |
147+
| Row Count Is Less Than X | SELECT id FROM person WHERE first_name = 'John' | 1 |
148148
149149
Then you will get the following:
150-
| Row Count Is Less Than X | select id from person | 3 | # PASS |
151-
| Row Count Is Less Than X | select id from person where first_name = 'John' | 1 | # FAIL |
150+
| Row Count Is Less Than X | SELECT id FROM person | 3 | # PASS |
151+
| Row Count Is Less Than X | SELECT id FROM person WHERE first_name = 'John' | 1 | # FAIL |
152152
"""
153153
num_rows = self.row_count(selectStatement)
154154
if (num_rows >= int(numRows.encode('ascii'))):
@@ -169,11 +169,11 @@ def table_must_exist(self,tableName):
169169
| Table Must Exist | first_name | # FAIL |
170170
"""
171171
if self.db_api_module_name in ["cx_Oracle"]:
172-
selectStatement = ("select * from all_objects where object_type in ('TABLE','VIEW') and owner = SYS_CONTEXT('USERENV', 'SESSION_USER') and object_name = upper('%s')" % tableName)
172+
selectStatement = ("SELECT * FROM all_objects WHERE object_type IN ('TABLE','VIEW') AND owner = SYS_CONTEXT('USERENV', 'SESSION_USER') AND object_name = UPPER('%s')" % tableName)
173173
elif self.db_api_module_name in ["sqlite3"]:
174174
selectStatement = ("SELECT name FROM sqlite_master WHERE type='table' AND name='%s' COLLATE NOCASE" % tableName)
175175
else:
176-
selectStatement = ("select * from information_schema.tables where table_name='%s'" % tableName)
176+
selectStatement = ("SELECT * FROM information_schema.tables WHERE table_name='%s'" % tableName)
177177
num_rows = self.row_count(selectStatement)
178178
if (num_rows == 0):
179179
raise AssertionError("Table '%s' does not exist in the db" % tableName)

src/DatabaseLibrary/query.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def query(self, selectStatement):
3636
| 1 | Franz Allan | See |
3737
3838
When you do the following:
39-
| @{queryResults} | Query | select * from person |
39+
| @{queryResults} | Query | SELECT * FROM person |
4040
| Log Many | @{queryResults} |
4141
4242
You will get the following:
4343
[1, 'Franz Allan', 'See']
4444
4545
Also, you can do something like this:
46-
| ${queryResults} | Query | select first_name, last_name from person |
46+
| ${queryResults} | Query | SELECT first_name, last_name FROM person |
4747
| Log | ${queryResults[0][1]}, ${queryResults[0][0]} |
4848
4949
And get the following
@@ -70,14 +70,14 @@ def row_count(self, selectStatement):
7070
| 2 | Jerry | Schneider |
7171
7272
When you do the following:
73-
| ${rowCount} | Row Count | select * from person |
73+
| ${rowCount} | Row Count | SELECT * FROM person |
7474
| Log | ${rowCount} |
7575
7676
You will get the following:
7777
2
7878
7979
Also, you can do something like this:
80-
| ${rowCount} | Row Count | select * from person where id = 2 |
80+
| ${rowCount} | Row Count | SELECT * FROM person WHERE id = 2 |
8181
| Log | ${rowCount} |
8282
8383
And get the following
@@ -107,7 +107,7 @@ def description(self, selectStatement):
107107
| 1 | Franz Allan | See |
108108
109109
When you do the following:
110-
| @{queryResults} | Description | select * from person |
110+
| @{queryResults} | Description | SELECT * FROM person |
111111
| Log Many | @{queryResults} |
112112
113113
You will get the following:
@@ -141,12 +141,13 @@ def delete_all_rows_from_table(self, tableName):
141141
| Delete All Rows From Table | first_name | # FAIL |
142142
"""
143143
cur = None
144-
selectStatement = ("delete from %s;" % tableName)
144+
selectStatement = ("DELETE FROM %s;" % tableName)
145145
try:
146146
cur = self._dbconnection.cursor()
147147
result = self.__execute_sql(cur, selectStatement)
148148
if result is not None:
149-
return result.fetchall()
149+
self._dbconnection.commit()
150+
return result
150151
self._dbconnection.commit()
151152
finally :
152153
if cur :
@@ -169,40 +170,40 @@ def execute_sql_script(self, sqlScriptFileName):
169170
SQL commands are expected to be delimited by a semi-colon (';').
170171
171172
For example:
172-
delete from person_employee_table;
173-
delete from person_table;
174-
delete from employee_table;
173+
DELETE FROM person_employee_table;
174+
DELETE FROM person_table;
175+
DELETE FROM employee_table;
175176
176177
Also, the last SQL command can optionally omit its trailing semi-colon.
177178
178179
For example:
179-
delete from person_employee_table;
180-
delete from person_table;
181-
delete from employee_table
180+
DELETE FROM person_employee_table;
181+
DELETE FROM person_table;
182+
DELETE FROM employee_table
182183
183184
Given this, that means you can create spread your SQL commands in several
184185
lines.
185186
186187
For example:
187-
delete
188-
from person_employee_table;
189-
delete
190-
from person_table;
191-
delete
192-
from employee_table
188+
DELETE
189+
FROM person_employee_table;
190+
DELETE
191+
FROM person_table;
192+
DELETE
193+
FROM employee_table
193194
194195
However, lines that starts with a number sign (`#`) are treated as a
195196
commented line. Thus, none of the contents of that line will be executed.
196197
197198
For example:
198199
# Delete the bridging table first...
199-
delete
200-
from person_employee_table;
200+
DELETE
201+
FROM person_employee_table;
201202
# ...and then the bridged tables.
202-
delete
203-
from person_table;
204-
delete
205-
from employee_table
203+
DELETE
204+
FROM person_table;
205+
DELETE
206+
FROM employee_table
206207
"""
207208
sqlScriptFile = open(sqlScriptFileName)
208209

@@ -248,10 +249,10 @@ def execute_sql_string(self, sqlString):
248249
SQL commands are expected to be delimited by a semi-colon (';').
249250
250251
For example:
251-
| Execute Sql String | delete from person_employee_table; delete from person_table |
252+
| Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table |
252253
253254
For example with an argument:
254-
| Execute Sql String | select from person where first_name = ${FIRSTNAME} |
255+
| Execute Sql String | SELECT * FROM person WHERE first_name = ${FIRSTNAME} |
255256
"""
256257
try:
257258
cur = self._dbconnection.cursor()

0 commit comments

Comments
 (0)