From e31f6905f6cf736519f8d4236ccbb2453088807d Mon Sep 17 00:00:00 2001 From: amochin Date: Tue, 27 Feb 2024 15:05:17 +0100 Subject: [PATCH 1/9] Add .DS_Store to ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0c61da21..56a41d3d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ output.xml report.html venv .runNumber +.DS_Store From 4a63bd7f877385ad34b1d3760760309fafb3792c Mon Sep 17 00:00:00 2001 From: amochin Date: Wed, 28 Feb 2024 11:47:02 +0100 Subject: [PATCH 2/9] Add test with multiple query params --- test/tests/common_tests/query_params.robot | 44 ++++++++++++---------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/test/tests/common_tests/query_params.robot b/test/tests/common_tests/query_params.robot index 839059b5..236ff9e2 100644 --- a/test/tests/common_tests/query_params.robot +++ b/test/tests/common_tests/query_params.robot @@ -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} From a69ace4c4b53f4a949d532c45bed6651acccc41f Mon Sep 17 00:00:00 2001 From: amochin Date: Wed, 28 Feb 2024 11:59:20 +0100 Subject: [PATCH 3/9] Handle query params as tuples, not as lists - fix #211 --- src/DatabaseLibrary/assertion.py | 14 +++++++------- src/DatabaseLibrary/query.py | 16 ++++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/DatabaseLibrary/assertion.py b/src/DatabaseLibrary/assertion.py index c3ecb878..88d1a917 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 33e41f5c..8b40a073 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. From 11adf00632bd07cdcdb5158119e9d8b329f83441 Mon Sep 17 00:00:00 2001 From: amochin Date: Wed, 28 Feb 2024 15:39:43 +0100 Subject: [PATCH 4/9] Typo --- test/tests/common_tests/query_params.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/common_tests/query_params.robot b/test/tests/common_tests/query_params.robot index 236ff9e2..0bdab735 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 From fc76ca4e1fa6900da80eff3b3361e3274b0c1056 Mon Sep 17 00:00:00 2001 From: amochin Date: Wed, 28 Feb 2024 15:39:59 +0100 Subject: [PATCH 5/9] Add "precommit" into requirements --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 82fd6ece..57f82554 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ robotframework -robotframework-excellib \ No newline at end of file +robotframework-excellib +pre-commit \ No newline at end of file From d6c36d78bae1a48a3c9e4043e8e2750120952497 Mon Sep 17 00:00:00 2001 From: amochin Date: Wed, 28 Feb 2024 15:43:11 +0100 Subject: [PATCH 6/9] Bump version to 1.4.4 --- src/DatabaseLibrary/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DatabaseLibrary/version.py b/src/DatabaseLibrary/version.py index fd870296..8f8e75e9 100644 --- a/src/DatabaseLibrary/version.py +++ b/src/DatabaseLibrary/version.py @@ -1 +1 @@ -VERSION = "1.4.3" +VERSION = "1.4.4" From e6b25fc1826d1be86c9d64d287221adfaf1f29a8 Mon Sep 17 00:00:00 2001 From: amochin Date: Wed, 28 Feb 2024 16:20:32 +0100 Subject: [PATCH 7/9] Fix stored procedures script for MSSQL --- test/resources/create_stored_procedures_mssql.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/resources/create_stored_procedures_mssql.sql b/test/resources/create_stored_procedures_mssql.sql index 9baf3961..79d31bad 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'; From 585638ed7427b03d1c3c5d0ef96e613430b67f0e Mon Sep 17 00:00:00 2001 From: amochin Date: Wed, 28 Feb 2024 16:22:02 +0100 Subject: [PATCH 8/9] Add build into requirements --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 57f82554..2276acda 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ robotframework robotframework-excellib -pre-commit \ No newline at end of file +pre-commit +build \ No newline at end of file From c6170a32228a210143fd0b8f19e0ebd3234cbd75 Mon Sep 17 00:00:00 2001 From: amochin Date: Wed, 28 Feb 2024 16:22:31 +0100 Subject: [PATCH 9/9] Add twine into requirements --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2276acda..a6421b7a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ robotframework robotframework-excellib pre-commit -build \ No newline at end of file +build +twine \ No newline at end of file