Skip to content

Commit a212ff0

Browse files
committed
Forgot new query params in some keyword docs
1 parent 8a35c1c commit a212ff0

2 files changed

Lines changed: 86 additions & 64 deletions

File tree

src/DatabaseLibrary/assertion.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,16 @@ def check_if_exists_in_database(
4141
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
4242
than one connection open.
4343
44+
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
45+
depending on the database client).
46+
4447
Examples:
4548
| Check If Exists In Database | SELECT id FROM person WHERE first_name = 'Franz Allan' |
4649
| Check If Exists In Database | SELECT id FROM person WHERE first_name = 'John' | msg=my error message |
4750
| Check If Exists In Database | SELECT id FROM person WHERE first_name = 'Franz Allan' | alias=my_alias |
4851
| Check If Exists In Database | SELECT id FROM person WHERE first_name = 'John' | sansTran=True |
52+
| @{parameters} | Create List | John |
53+
| Check If Exists In Database | SELECT id FROM person WHERE first_name = %s | parameters=${parameters} |
4954
"""
5055
logger.info(f"Executing : Check If Exists In Database | {selectStatement}")
5156
if not self.query(selectStatement, sansTran, alias=alias, parameters=parameters):
@@ -74,11 +79,16 @@ def check_if_not_exists_in_database(
7479
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
7580
than one connection open.
7681
82+
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
83+
depending on the database client).
84+
7785
Examples:
7886
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = 'John' |
7987
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = 'Franz Allan' | msg=my error message |
8088
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = 'Franz Allan' | alias=my_alias |
8189
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = 'John' | sansTran=True |
90+
| @{parameters} | Create List | John |
91+
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = %s | parameters=${parameters} |
8292
"""
8393
logger.info(f"Executing : Check If Not Exists In Database | {selectStatement}")
8494
query_results = self.query(selectStatement, sansTran, alias=alias, parameters=parameters)
@@ -107,11 +117,16 @@ def row_count_is_0(
107117
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
108118
than one connection open.
109119
120+
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
121+
depending on the database client).
122+
110123
Examples:
111124
| Row Count is 0 | SELECT id FROM person WHERE first_name = 'Franz Allan' |
112125
| Row Count is 0 | SELECT id FROM person WHERE first_name = 'Franz Allan' | msg=my error message |
113126
| Row Count is 0 | SELECT id FROM person WHERE first_name = 'John' | alias=my_alias |
114127
| Row Count is 0 | SELECT id FROM person WHERE first_name = 'John' | sansTran=True |
128+
| @{parameters} | Create List | John |
129+
| Row Count is 0 | SELECT id FROM person WHERE first_name = %s | parameters=${parameters} |
115130
"""
116131
logger.info(f"Executing : Row Count Is 0 | {selectStatement}")
117132
num_rows = self.row_count(selectStatement, sansTran, alias=alias, parameters=parameters)
@@ -138,11 +153,16 @@ def row_count_is_equal_to_x(
138153
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
139154
than one connection open.
140155
156+
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
157+
depending on the database client).
158+
141159
Examples:
142160
| Row Count Is Equal To X | SELECT id FROM person | 1 |
143161
| Row Count Is Equal To X | SELECT id FROM person | 3 | msg=my error message |
144162
| Row Count Is Equal To X | SELECT id FROM person WHERE first_name = 'John' | 0 | alias=my_alias |
145163
| Row Count Is Equal To X | SELECT id FROM person WHERE first_name = 'John' | 0 | sansTran=True |
164+
| @{parameters} | Create List | John |
165+
| Row Count Is Equal To X | SELECT id FROM person WHERE first_name = %s | 0 | parameters=${parameters} |
146166
"""
147167
logger.info(f"Executing : Row Count Is Equal To X | {selectStatement} | {numRows}")
148168
num_rows = self.row_count(selectStatement, sansTran, alias=alias, parameters=parameters)
@@ -171,11 +191,16 @@ def row_count_is_greater_than_x(
171191
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
172192
than one connection open.
173193
194+
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
195+
depending on the database client).
196+
174197
Examples:
175198
| Row Count Is Greater Than X | SELECT id FROM person WHERE first_name = 'John' | 0 |
176199
| Row Count Is Greater Than X | SELECT id FROM person WHERE first_name = 'John' | 0 | msg=my error message |
177200
| Row Count Is Greater Than X | SELECT id FROM person WHERE first_name = 'John' | 0 | alias=my_alias |
178201
| Row Count Is Greater Than X | SELECT id FROM person | 1 | sansTran=True |
202+
| @{parameters} | Create List | John |
203+
| Row Count Is Greater Than X | SELECT id FROM person WHERE first_name = %s | 0 | parameters=${parameters} |
179204
"""
180205
logger.info(f"Executing : Row Count Is Greater Than X | {selectStatement} | {numRows}")
181206
num_rows = self.row_count(selectStatement, sansTran, alias=alias, parameters=parameters)
@@ -204,12 +229,16 @@ def row_count_is_less_than_x(
204229
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
205230
than one connection open.
206231
232+
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
233+
depending on the database client).
234+
207235
Examples:
208236
| Row Count Is Less Than X | SELECT id FROM person WHERE first_name = 'John' | 1 |
209237
| Row Count Is Less Than X | SELECT id FROM person WHERE first_name = 'John' | 2 | msg=my error message |
210238
| Row Count Is Less Than X | SELECT id FROM person WHERE first_name = 'John' | 3 | alias=my_alias |
211239
| Row Count Is Less Than X | SELECT id FROM person WHERE first_name = 'John' | 4 | sansTran=True |
212-
240+
| @{parameters} | Create List | John |
241+
| Row Count Is Less Than X | SELECT id FROM person WHERE first_name = %s | 5 | parameters=${parameters} |
213242
"""
214243
logger.info(f"Executing : Row Count Is Less Than X | {selectStatement} | {numRows}")
215244
num_rows = self.row_count(selectStatement, sansTran, alias=alias, parameters=parameters)

src/DatabaseLibrary/query.py

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ class Query:
2525
"""
2626

2727
def query(
28-
self, selectStatement: str, sansTran: bool = False, returnAsDict: bool = False, alias: Optional[str] = None, parameters: Optional[List] = None
28+
self,
29+
selectStatement: str,
30+
sansTran: bool = False,
31+
returnAsDict: bool = False,
32+
alias: Optional[str] = None,
33+
parameters: Optional[List] = None,
2934
):
3035
"""
3136
Uses the input ``selectStatement`` to query for the values that will be returned as a list of tuples.
@@ -34,6 +39,14 @@ def query(
3439
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
3540
than one connection open.
3641
42+
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
43+
depending on the database client):
44+
| @{parameters} | Create List | person |
45+
| Query | SELECT * FROM %s | parameters=${parameters} |
46+
47+
Use optional ``sansTran`` to run command without an explicit transaction commit or rollback:
48+
| @{queryResults} | Query | SELECT * FROM person | True |
49+
3750
Tip: Unless you want to log all column values of the specified rows,
3851
try specifying the column names in your select statements
3952
as much as possible to prevent any unnecessary surprises with schema
@@ -59,14 +72,6 @@ def query(
5972
6073
And get the following
6174
See, Franz Allan
62-
63-
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
64-
depending on the database client):
65-
| parameters | Create List | person |
66-
| Query | SELECT * FROM %s | parameters=${parameters} |
67-
68-
Use optional ``sansTran`` to run command without an explicit transaction commit or rollback:
69-
| @{queryResults} | Query | SELECT * FROM person | True |
7075
"""
7176
db_connection = self.connection_store.get_connection(alias)
7277
cur = None
@@ -83,40 +88,30 @@ def query(
8388
if cur and not sansTran:
8489
db_connection.client.rollback()
8590

86-
def row_count(self, selectStatement: str, sansTran: bool = False, alias: Optional[str] = None, parameters: Optional[List] = None):
91+
def row_count(
92+
self,
93+
selectStatement: str,
94+
sansTran: bool = False,
95+
alias: Optional[str] = None,
96+
parameters: Optional[List] = None,
97+
):
8798
"""
8899
Uses the input ``selectStatement`` to query the database and returns the number of rows from the query.
89100
90-
For example, given we have a table `person` with the following data:
91-
| id | first_name | last_name |
92-
| 1 | Franz Allan | See |
93-
| 2 | Jerry | Schneider |
94-
95-
When you do the following:
96-
| ${rowCount} | Row Count | SELECT * FROM person |
97-
| ${rowCount} | Row Count | SELECT * FROM person | alias=my_alias |
98-
| Log | ${rowCount} |
99-
100-
You will get the following:
101-
2
102-
103-
Also, you can do something like this:
104-
| ${rowCount} | Row Count | SELECT * FROM person WHERE id = 2 |
105-
| Log | ${rowCount} |
106-
107-
And get the following
108-
1
109-
110101
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
111102
than one connection open.
112103
104+
Use optional ``sansTran`` to run command without an explicit transaction commit or rollback:
105+
113106
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
114107
depending on the database client):
115-
| parameters | Create List | person |
116-
| ${rowCount} | Row Count | SELECT * FROM %s | parameters=${parameters} |
117108
118-
Use optional ``sansTran`` to run command without an explicit transaction commit or rollback:
119-
| ${rowCount} | Row Count | SELECT * FROM person | True |
109+
Examples:
110+
| ${rowCount} | Row Count | SELECT * FROM person |
111+
| ${rowCount} | Row Count | SELECT * FROM person | sansTran=True |
112+
| ${rowCount} | Row Count | SELECT * FROM person | alias=my_alias |
113+
| @{parameters} | Create List | person |
114+
| ${rowCount} | Row Count | SELECT * FROM %s | parameters=${parameters} |
120115
"""
121116
db_connection = self.connection_store.get_connection(alias)
122117
cur = None
@@ -132,7 +127,13 @@ def row_count(self, selectStatement: str, sansTran: bool = False, alias: Optiona
132127
if cur and not sansTran:
133128
db_connection.client.rollback()
134129

135-
def description(self, selectStatement: str, sansTran: bool = False, alias: Optional[str] = None, parameters: Optional[List] = None):
130+
def description(
131+
self,
132+
selectStatement: str,
133+
sansTran: bool = False,
134+
alias: Optional[str] = None,
135+
parameters: Optional[List] = None,
136+
):
136137
"""
137138
Uses the input ``selectStatement`` to query a table in the db which will be used to determine the description.
138139
@@ -155,7 +156,7 @@ def description(self, selectStatement: str, sansTran: bool = False, alias: Optio
155156
156157
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
157158
depending on the database client):
158-
| parameters | Create List | person |
159+
| @{parameters} | Create List | person |
159160
| ${desc} | Description | SELECT * FROM %s | parameters=${parameters} |
160161
161162
Using optional `sansTran` to run command without an explicit transaction commit or rollback:
@@ -180,23 +181,15 @@ def delete_all_rows_from_table(self, tableName: str, sansTran: bool = False, ali
180181
"""
181182
Delete all the rows within a given table.
182183
183-
For example, given we have a table `person` in a database
184-
185-
When you do the following:
186-
| Delete All Rows From Table | person |
187-
| Delete All Rows From Table | person | alias=my_alias |
188-
189-
If all the rows can be successfully deleted, then you will get:
190-
| Delete All Rows From Table | person | # PASS |
191-
If the table doesn't exist or all the data can't be deleted, then you
192-
will get:
193-
| Delete All Rows From Table | first_name | # FAIL |
184+
Use optional `sansTran` to run command without an explicit transaction commit or rollback.
194185
195186
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
196187
than one connection open.
197188
198-
Use optional `sansTran` to run command without an explicit transaction commit or rollback:
199-
| Delete All Rows From Table | person | True |
189+
Examples:
190+
| Delete All Rows From Table | person |
191+
| Delete All Rows From Table | person | alias=my_alias |
192+
| Delete All Rows From Table | person | sansTran=True |
200193
"""
201194
db_connection = self.connection_store.get_connection(alias)
202195
cur = None
@@ -341,29 +334,27 @@ def execute_sql_script(self, sqlScriptFileName: str, sansTran: bool = False, ali
341334
if cur and not sansTran:
342335
db_connection.client.rollback()
343336

344-
def execute_sql_string(self, sqlString: str, sansTran: bool = False, alias: Optional[str] = None, parameters: Optional[List] = None):
337+
def execute_sql_string(
338+
self, sqlString: str, sansTran: bool = False, alias: Optional[str] = None, parameters: Optional[List] = None
339+
):
345340
"""
346341
Executes the sqlString as SQL commands. Useful to pass arguments to your sql.
347-
348342
SQL commands are expected to be delimited by a semicolon (';').
349343
350-
For example:
351-
| Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table |
352-
| Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table | alias=my_alias |
353-
354-
For example with an argument:
355-
| Execute Sql String | SELECT * FROM person WHERE first_name = ${FIRSTNAME} |
344+
Use optional `sansTran` to run command without an explicit transaction commit or rollback:
356345
357346
Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
358347
than one connection open.
359348
360349
Use optional ``parameters`` for query variable substitution (variable substitution syntax may be different
361-
depending on the database client):
362-
| parameters | Create List | person_employee_table |
363-
| Execute Sql String | SELECT * FROM %s | parameters=${parameters} |
350+
depending on the database client).
364351
365-
Use optional `sansTran` to run command without an explicit transaction commit or rollback:
366-
| Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table | True |
352+
For example:
353+
| Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table |
354+
| Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table | alias=my_alias |
355+
| Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table | sansTran=True |
356+
| @{parameters} | Create List | person_employee_table |
357+
| Execute Sql String | SELECT * FROM %s | parameters=${parameters} |
367358
"""
368359
db_connection = self.connection_store.get_connection(alias)
369360
cur = None
@@ -519,7 +510,9 @@ def call_stored_procedure(
519510
if cur and not sansTran:
520511
db_connection.client.rollback()
521512

522-
def __execute_sql(self, cur, sql_statement: str, omit_trailing_semicolon: Optional[bool] = None, parameters: Optional[List] = None):
513+
def __execute_sql(
514+
self, cur, sql_statement: str, omit_trailing_semicolon: Optional[bool] = None, parameters: Optional[List] = None
515+
):
523516
"""
524517
Runs the `sql_statement` using `cur` as Cursor object.
525518
Use `omit_trailing_semicolon` parameter (bool) for explicit instruction,

0 commit comments

Comments
 (0)