diff --git a/.gitignore b/.gitignore index 0c61da2..56a41d3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ output.xml report.html venv .runNumber +.DS_Store diff --git a/requirements.txt b/requirements.txt index 82fd6ec..a6421b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ robotframework -robotframework-excellib \ No newline at end of file +robotframework-excellib +pre-commit +build +twine \ No newline at end of file diff --git a/src/DatabaseLibrary/assertion.py b/src/DatabaseLibrary/assertion.py index c3ecb87..88d1a91 100644 --- a/src/DatabaseLibrary/assertion.py +++ b/src/DatabaseLibrary/assertion.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from typing import List, Optional +from typing import Optional, Tuple from robot.api import logger @@ -27,7 +27,7 @@ def check_if_exists_in_database( sansTran: bool = False, msg: Optional[str] = None, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, ): """ Check if any row would be returned by given the input ``selectStatement``. If there are no results, then this will @@ -64,7 +64,7 @@ def check_if_not_exists_in_database( sansTran: bool = False, msg: Optional[str] = None, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, ): """ This is the negation of `check_if_exists_in_database`. @@ -103,7 +103,7 @@ def row_count_is_0( sansTran: bool = False, msg: Optional[str] = None, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, ): """ Check if any rows are returned from the submitted ``selectStatement``. If there are, then this will throw an @@ -140,7 +140,7 @@ def row_count_is_equal_to_x( sansTran: bool = False, msg: Optional[str] = None, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, ): """ Check if the number of rows returned from ``selectStatement`` is equal to the value submitted. If not, then this @@ -178,7 +178,7 @@ def row_count_is_greater_than_x( sansTran: bool = False, msg: Optional[str] = None, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, ): """ Check if the number of rows returned from ``selectStatement`` is greater than the value submitted. If not, then @@ -216,7 +216,7 @@ def row_count_is_less_than_x( sansTran: bool = False, msg: Optional[str] = None, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, ): """ Check if the number of rows returned from ``selectStatement`` is less than the value submitted. If not, then this diff --git a/src/DatabaseLibrary/query.py b/src/DatabaseLibrary/query.py index 33e41f5..8b40a07 100644 --- a/src/DatabaseLibrary/query.py +++ b/src/DatabaseLibrary/query.py @@ -15,7 +15,7 @@ import inspect import re import sys -from typing import List, Optional +from typing import List, Optional, Tuple from robot.api import logger @@ -31,7 +31,7 @@ def query( sansTran: bool = False, returnAsDict: bool = False, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, ): """ Runs a query with the ``selectStatement`` and returns the result as a list of rows. @@ -98,7 +98,7 @@ def row_count( selectStatement: str, sansTran: bool = False, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, ): """ Uses the input ``selectStatement`` to query the database and returns the number of rows from the query. @@ -137,7 +137,7 @@ def description( selectStatement: str, sansTran: bool = False, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, ): """ Uses the input ``selectStatement`` to query a table in the db which will be used to determine the description. @@ -364,7 +364,7 @@ def execute_sql_string( sqlString: str, sansTran: bool = False, alias: Optional[str] = None, - parameters: Optional[List] = None, + parameters: Optional[Tuple] = None, omitTrailingSemicolon: Optional[bool] = None, ): """ @@ -547,7 +547,11 @@ def call_stored_procedure( db_connection.client.rollback() def __execute_sql( - self, cur, sql_statement: str, omit_trailing_semicolon: Optional[bool] = None, parameters: Optional[List] = None + self, + cur, + sql_statement: str, + omit_trailing_semicolon: Optional[bool] = None, + parameters: Optional[Tuple] = None, ): """ Runs the `sql_statement` using `cur` as Cursor object. diff --git a/src/DatabaseLibrary/version.py b/src/DatabaseLibrary/version.py index fd87029..8f8e75e 100644 --- a/src/DatabaseLibrary/version.py +++ b/src/DatabaseLibrary/version.py @@ -1 +1 @@ -VERSION = "1.4.3" +VERSION = "1.4.4" diff --git a/test/resources/create_stored_procedures_mssql.sql b/test/resources/create_stored_procedures_mssql.sql index 9baf396..79d31ba 100644 --- a/test/resources/create_stored_procedures_mssql.sql +++ b/test/resources/create_stored_procedures_mssql.sql @@ -38,7 +38,9 @@ END; DROP PROCEDURE IF EXISTS check_condition; CREATE PROCEDURE check_condition AS -DECLARE @v_condition BIT = 1; +BEGIN +DECLARE @v_condition BIT; +SET @v_condition = 1; IF @v_condition = 1 BEGIN PRINT 'Condition is true'; diff --git a/test/tests/common_tests/query_params.robot b/test/tests/common_tests/query_params.robot index 839059b..0bdab73 100644 --- a/test/tests/common_tests/query_params.robot +++ b/test/tests/common_tests/query_params.robot @@ -1,5 +1,5 @@ *** Settings *** -Documentation Keywords with query params as seperate arguments work across all databases. +Documentation Keywords with query params as separate arguments work across all databases. Resource ../../resources/common.resource @@ -10,58 +10,62 @@ Test Teardown Drop Tables Person And Foobar *** Variables *** -@{PARAMS} Franz Allan +@{SINGLE_PARAM} Franz Allan +@{MULTI_PARAM} Jerry Schneider *** Keywords *** Connect To DB And Build Query Connect To DB - Build Query String With Params + Build Query Strings With Params -Build Query String With Params - ${sql}= Set Variable SELECT id FROM person WHERE FIRST_NAME= +Build Query Strings With Params + ${placeholder}= Set Variable %s IF "${DB_MODULE}" in ["oracledb", "cx_Oracle"] - ${sql}= Catenate ${sql} :id + ${placeholder}= Set Variable :id ELSE IF "${DB_MODULE}" in ["sqlite3", "pyodbc"] - ${sql}= Catenate ${sql} ? - ELSE - ${sql}= Catenate ${sql} %s + ${placeholder}= Set Variable ? END - Set Suite Variable ${QUERY} ${sql} + Set Suite Variable ${QUERY_SINGLE_PARAM} SELECT id FROM person WHERE FIRST_NAME=${placeholder} + Set Suite Variable ${QUERY_MULTI_PARAM} ${QUERY_SINGLE_PARAM} AND LAST_NAME=${placeholder} *** Test Cases *** -Query - ${out}= Query ${QUERY} parameters=${PARAMS} +Query Single Param + ${out}= Query ${QUERY_SINGLE_PARAM} parameters=${SINGLE_PARAM} + Length Should Be ${out} 1 + +Query Multiple Params + ${out}= Query ${QUERY_MULTI_PARAM} parameters=${MULTI_PARAM} Length Should Be ${out} 1 Row Count - ${out}= Row Count ${QUERY} parameters=${PARAMS} + ${out}= Row Count ${QUERY_SINGLE_PARAM} parameters=${SINGLE_PARAM} Should Be Equal As Strings ${out} 1 Description - ${out}= Description ${QUERY} parameters=${PARAMS} + ${out}= Description ${QUERY_SINGLE_PARAM} parameters=${SINGLE_PARAM} Length Should Be ${out} 1 Execute SQL String - Execute Sql String ${QUERY} parameters=${PARAMS} + Execute Sql String ${QUERY_SINGLE_PARAM} parameters=${SINGLE_PARAM} Check If Exists In DB - Check If Exists In Database ${QUERY} parameters=${PARAMS} + Check If Exists In Database ${QUERY_SINGLE_PARAM} parameters=${SINGLE_PARAM} Check If Not Exists In DB @{Wrong params}= Create List Joe - Check If Not Exists In Database ${QUERY} parameters=${Wrong params} + Check If Not Exists In Database ${QUERY_SINGLE_PARAM} parameters=${Wrong params} Row Count is 0 @{Wrong params}= Create List Joe - Row Count is 0 ${QUERY} parameters=${Wrong params} + Row Count is 0 ${QUERY_SINGLE_PARAM} parameters=${Wrong params} Row Count is Equal to X - Row Count is Equal to X ${QUERY} 1 parameters=${PARAMS} + Row Count is Equal to X ${QUERY_SINGLE_PARAM} 1 parameters=${SINGLE_PARAM} Row Count is Less Than X - Row Count is Less Than X ${QUERY} 5 parameters=${PARAMS} + Row Count is Less Than X ${QUERY_SINGLE_PARAM} 5 parameters=${SINGLE_PARAM} Row Count is Greater Than X - Row Count is Greater Than X ${QUERY} 0 parameters=${PARAMS} + Row Count is Greater Than X ${QUERY_SINGLE_PARAM} 0 parameters=${SINGLE_PARAM}