Skip to content

Commit 87adb58

Browse files
authored
Merge pull request MarketSquare#108 from franz-see/revert-105-pk_return_rows
Revert "Make Execute SQL keywords return number of rows affected"
2 parents 35b86ca + 870987c commit 87adb58

File tree

6 files changed

+52
-60
lines changed

6 files changed

+52
-60
lines changed

src/DatabaseLibrary/query.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,9 @@ def delete_all_rows_from_table(self, tableName, sansTran=False):
196196

197197
def execute_sql_script(self, sqlScriptFileName, sansTran=False):
198198
"""
199-
Executes the content of the `sqlScriptFileName` as SQL commands and
200-
returns number of rows affected. Useful for setting the database to
201-
a known state before running your tests, or clearing out your test
202-
data after running each a test. Set optional input `sansTran` to
203-
True to run command without an explicit transaction commit or rollback.
199+
Executes the content of the `sqlScriptFileName` as SQL commands. Useful for setting the database to a known
200+
state before running your tests, or clearing out your test data after running each a test. Set optional input
201+
`sansTran` to True to run command without an explicit transaction commit or rollback.
204202
205203
Sample usage :
206204
| Execute Sql Script | ${EXECDIR}${/}resources${/}DDL-setup.sql |
@@ -253,7 +251,6 @@ def execute_sql_script(self, sqlScriptFileName, sansTran=False):
253251
sqlScriptFile = open(sqlScriptFileName)
254252

255253
cur = None
256-
result = 0
257254
try:
258255
cur = self._dbconnection.cursor()
259256
logger.info('Executing : Execute SQL Script | %s ' % sqlScriptFileName)
@@ -279,27 +276,24 @@ def execute_sql_script(self, sqlScriptFileName, sansTran=False):
279276

280277
sqlStatement += sqlFragment + ' '
281278

282-
result = result + self.__execute_sql(cur, sqlStatement)
279+
self.__execute_sql(cur, sqlStatement)
283280
sqlStatement = ''
284281

285282
sqlStatement = sqlStatement.strip()
286283
if len(sqlStatement) != 0:
287-
result = self.__execute_sql(cur, sqlStatement)
284+
self.__execute_sql(cur, sqlStatement)
288285

289286
if not sansTran:
290287
self._dbconnection.commit()
291288
finally:
292289
if cur:
293290
if not sansTran:
294291
self._dbconnection.rollback()
295-
return result
296292

297293
def execute_sql_string(self, sqlString, sansTran=False):
298294
"""
299-
Executes the sqlString as SQL commands and returns number of rows
300-
affected. Useful to pass arguments to your sql. Set optional input
301-
`sansTran` to True to run command without an explicit transaction
302-
commit or rollback.
295+
Executes the sqlString as SQL commands. Useful to pass arguments to your sql. Set optional input `sansTran` to
296+
True to run command without an explicit transaction commit or rollback.
303297
304298
SQL commands are expected to be delimited by a semi-colon (';').
305299
@@ -313,18 +307,16 @@ def execute_sql_string(self, sqlString, sansTran=False):
313307
| Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table | True |
314308
"""
315309
cur = None
316-
result = 0
317310
try:
318311
cur = self._dbconnection.cursor()
319312
logger.info('Executing : Execute SQL String | %s ' % sqlString)
320-
result = self.__execute_sql(cur, sqlString)
313+
self.__execute_sql(cur, sqlString)
321314
if not sansTran:
322315
self._dbconnection.commit()
323316
finally:
324317
if cur:
325318
if not sansTran:
326319
self._dbconnection.rollback()
327-
return result
328320

329321
def call_stored_procedure(self, spName, spParams=None, sansTran=False):
330322
"""

test/DB2SQL_DB_Tests.robot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ Library DatabaseLibrary
88
Create person table
99
${output} = Execute SQL String CREATE TABLE person (id decimal(10,0),first_name varchar(30),last_name varchar(30));
1010
Log ${output}
11-
Should Be Equal As Strings ${output} 0
11+
Should Be Equal As Strings ${output} None
1212

1313
Execute SQL Script - Insert Data person table
1414
Comment ${output} = Execute SQL Script ./my_db_test_insertData.sql
1515
${output} = Execute SQL Script ../test/my_db_test_insertData.sql
1616
Log ${output}
17-
Should Be Equal As Strings ${output} 2
17+
Should Be Equal As Strings ${output} None
1818

1919
Execute SQL String - Create Table
2020
${output} = Execute SQL String create table foobar (id integer , firstname varchar(20) )
2121
Log ${output}
22-
Should Be Equal As Strings ${output} 0
22+
Should Be Equal As Strings ${output} None
2323

2424
Check If Exists In DB - Franz Allan
2525
Check If Exists In Database SELECT id FROM person WHERE first_name = 'Franz Allan';
@@ -81,7 +81,7 @@ Verify Query - Get results as a list of dictionaries
8181
Insert Data Into Table foobar
8282
${output} = Execute SQL String INSERT INTO foobar VALUES(1,'Jerry');
8383
Log ${output}
84-
Should Be Equal As Strings ${output} 1
84+
Should Be Equal As Strings ${output} None
8585

8686
Verify Query - Row Count foobar table 1 row
8787
${output} = Query SELECT COUNT(*) FROM foobar;

test/MSSQL_DB_Tests.robot

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ Create person table
1616
[Tags] db smoke
1717
${output} = Execute SQL String CREATE TABLE person (id integer unique, first_name varchar(20), last_name varchar(20));
1818
Log ${output}
19-
Should Be Equal As Strings ${output} 0
19+
Should Be Equal As Strings ${output} None
2020

2121
Execute SQL Script - Insert Data person table
2222
[Tags] db smoke
2323
${output} = Execute SQL Script ./my_db_test_insertData.sql
2424
Log ${output}
25-
Should Be Equal As Strings ${output} 2
25+
Should Be Equal As Strings ${output} None
2626

2727
Execute SQL String - Create Table
2828
[Tags] db smoke
2929
${output} = Execute SQL String create table foobar (id integer primary key, firstname varchar(20) unique)
3030
Log ${output}
31-
Should Be Equal As Strings ${output} 0
31+
Should Be Equal As Strings ${output} None
3232

3333
Check If Exists In DB - Franz Allan
3434
[Tags] db smoke
@@ -125,13 +125,13 @@ Verify Execute SQL String - Row Count foobar table
125125
[Tags] db smoke
126126
${output} = Execute SQL String SELECT COUNT(*) FROM foobar;
127127
Log ${output}
128-
Should Be Equal As Strings ${output} 1
128+
Should Be Equal As Strings ${output} None
129129

130130
Insert Data Into Table foobar
131131
[Tags] db smoke
132132
${output} = Execute SQL String INSERT INTO foobar VALUES(1,'Jerry');
133133
Log ${output}
134-
Should Be Equal As Strings ${output} 1
134+
Should Be Equal As Strings ${output} None
135135

136136
Verify Query - Row Count foobar table 1 row
137137
[Tags] db smoke
@@ -152,13 +152,13 @@ Begin first transaction
152152
[Tags] db smoke
153153
${output} = Execute SQL String SAVE TRANSACTION first True
154154
Log ${output}
155-
Should Be Equal As Strings ${output} 0
155+
Should Be Equal As Strings ${output} None
156156

157157
Add person in first transaction
158158
[Tags] db smoke
159159
${output} = Execute SQL String INSERT INTO person VALUES(101,'Bilbo','Baggins'); True
160160
Log ${output}
161-
Should Be Equal As Strings ${output} 1
161+
Should Be Equal As Strings ${output} None
162162

163163
Verify person in first transaction
164164
[Tags] db smoke
@@ -204,7 +204,7 @@ Drop person and foobar tables
204204
[Tags] db smoke
205205
${output} = Execute SQL String DROP TABLE IF EXISTS person;
206206
Log ${output}
207-
Should Be Equal As Strings ${output} 0
207+
Should Be Equal As Strings ${output} None
208208
${output} = Execute SQL String DROP TABLE IF EXISTS foobar;
209209
Log ${output}
210-
Should Be Equal As Strings ${output} 0
210+
Should Be Equal As Strings ${output} None

test/MySQL_DB_Tests.robot

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ Create person table
1616
[Tags] db smoke
1717
${output} = Execute SQL String CREATE TABLE person (id integer unique,first_name varchar(20),last_name varchar(20));
1818
Log ${output}
19-
Should Be Equal As Strings ${output} 0
19+
Should Be Equal As Strings ${output} None
2020

2121
Execute SQL Script - Insert Data person table
2222
[Tags] db smoke
2323
Comment ${output} = Execute SQL Script ./${DBName}_insertData.sql
2424
${output} = Execute SQL Script ./my_db_test_insertData.sql
2525
Log ${output}
26-
Should Be Equal As Strings ${output} 2
26+
Should Be Equal As Strings ${output} None
2727

2828
Execute SQL String - Create Table
2929
[Tags] db smoke
3030
${output} = Execute SQL String create table foobar (id integer primary key, firstname varchar(20) unique)
3131
Log ${output}
32-
Should Be Equal As Strings ${output} 0
32+
Should Be Equal As Strings ${output} None
3333

3434
Check If Exists In DB - Franz Allan
3535
[Tags] db smoke
@@ -69,7 +69,7 @@ Retrieve records from person table
6969
[Tags] db smoke
7070
${output} = Execute SQL String SELECT * FROM person;
7171
Log ${output}
72-
Should Be Equal As Strings ${output} 2
72+
Should Be Equal As Strings ${output} None
7373

7474
Verify person Description
7575
[Tags] db smoke
@@ -120,19 +120,19 @@ Verify Execute SQL String - Row Count person table
120120
[Tags] db smoke
121121
${output} = Execute SQL String SELECT COUNT(*) FROM person;
122122
Log ${output}
123-
Should Be Equal As Strings ${output} 1
123+
Should Be Equal As Strings ${output} None
124124

125125
Verify Execute SQL String - Row Count foobar table
126126
[Tags] db smoke
127127
${output} = Execute SQL String SELECT COUNT(*) FROM foobar;
128128
Log ${output}
129-
Should Be Equal As Strings ${output} 1
129+
Should Be Equal As Strings ${output} None
130130

131131
Insert Data Into Table foobar
132132
[Tags] db smoke
133133
${output} = Execute SQL String INSERT INTO foobar VALUES(1,'Jerry');
134134
Log ${output}
135-
Should Be Equal As Strings ${output} 1
135+
Should Be Equal As Strings ${output} None
136136

137137
Verify Query - Row Count foobar table 1 row
138138
[Tags] db smoke
@@ -156,13 +156,13 @@ Begin first transaction
156156
[Tags] db smoke
157157
${output} = Execute SQL String SAVEPOINT first True
158158
Log ${output}
159-
Should Be Equal As Strings ${output} 0
159+
Should Be Equal As Strings ${output} None
160160

161161
Add person in first transaction
162162
[Tags] db smoke
163163
${output} = Execute SQL String INSERT INTO person VALUES(101,'Bilbo','Baggins'); True
164164
Log ${output}
165-
Should Be Equal As Strings ${output} 1
165+
Should Be Equal As Strings ${output} None
166166

167167
Verify person in first transaction
168168
[Tags] db smoke
@@ -172,13 +172,13 @@ Begin second transaction
172172
[Tags] db smoke
173173
${output} = Execute SQL String SAVEPOINT second True
174174
Log ${output}
175-
Should Be Equal As Strings ${output} 0
175+
Should Be Equal As Strings ${output} None
176176

177177
Add person in second transaction
178178
[Tags] db smoke
179179
${output} = Execute SQL String INSERT INTO person VALUES(102,'Frodo','Baggins'); True
180180
Log ${output}
181-
Should Be Equal As Strings ${output} 1
181+
Should Be Equal As Strings ${output} None
182182

183183
Verify persons in first and second transactions
184184
[Tags] db smoke
@@ -188,7 +188,7 @@ Rollback second transaction
188188
[Tags] db smoke
189189
${output} = Execute SQL String ROLLBACK TO SAVEPOINT second True
190190
Log ${output}
191-
Should Be Equal As Strings ${output} 0
191+
Should Be Equal As Strings ${output} None
192192

193193
Verify second transaction rollback
194194
[Tags] db smoke
@@ -198,7 +198,7 @@ Rollback first transaction
198198
[Tags] db smoke
199199
${output} = Execute SQL String ROLLBACK TO SAVEPOINT first True
200200
Log ${output}
201-
Should Be Equal As Strings ${output} 0
201+
Should Be Equal As Strings ${output} None
202202

203203
Verify first transaction rollback
204204
[Tags] db smoke
@@ -208,4 +208,4 @@ Drop person and foobar tables
208208
[Tags] db smoke
209209
${output} = Execute SQL String DROP TABLE IF EXISTS person,foobar;
210210
Log ${output}
211-
Should Be Equal As Strings ${output} 0
211+
Should Be Equal As Strings ${output} None

test/PostgreSQL_DB_Tests.robot

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ ${DBUser} postgres
1616
Create person table
1717
${output} = Execute SQL String CREATE TABLE person (id integer unique,first_name varchar,last_name varchar);
1818
Log ${output}
19-
Should Be Equal As Strings ${output} 0
19+
Should Be Equal As Strings ${output} None
2020

2121
Execute SQL Script - Insert Data person table
2222
Comment ${output} = Execute SQL Script ./${DBName}_insertData.sql
2323
${output} = Execute SQL Script ./my_db_test_insertData.sql
2424
Log ${output}
25-
Should Be Equal As Strings ${output} 2
25+
Should Be Equal As Strings ${output} None
2626

2727
Execute SQL String - Create Table
2828
${output} = Execute SQL String create table foobar (id integer primary key, firstname varchar unique)
2929
Log ${output}
30-
Should Be Equal As Strings ${output} 0
30+
Should Be Equal As Strings ${output} None
3131

3232
Check If Exists In DB - Franz Allan
3333
Check If Exists In Database SELECT id FROM person WHERE first_name = 'Franz Allan';
@@ -117,12 +117,12 @@ Verify Execute SQL String - Row Count person table
117117
Verify Execute SQL String - Row Count foobar table
118118
${output} = Execute SQL String SELECT COUNT(*) FROM foobar;
119119
Log ${output}
120-
Should Be Equal As Strings ${output} 1
120+
Should Be Equal As Strings ${output} None
121121

122122
Insert Data Into Table foobar
123123
${output} = Execute SQL String INSERT INTO foobar VALUES(1,'Jerry');
124124
Log ${output}
125-
Should Be Equal As Strings ${output} 1
125+
Should Be Equal As Strings ${output} None
126126

127127
Verify Query - Row Count foobar table 1 row
128128
${output} = Query SELECT COUNT(*) FROM foobar;
@@ -145,4 +145,4 @@ Verify Query - Row Count foobar table 0 row
145145
Drop person and foobar tables
146146
${output} = Execute SQL String DROP TABLE IF EXISTS person,foobar;
147147
Log ${output}
148-
Should Be Equal As Strings ${output} 0
148+
Should Be Equal As Strings ${output} None

0 commit comments

Comments
 (0)