@@ -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