From da93bf0b6a0d3a7d4149526a58c6b4302040d52e Mon Sep 17 00:00:00 2001 From: Yuval Cohen <86777474+yucohen@users.noreply.github.com> Date: Thu, 7 Sep 2023 17:14:46 +0300 Subject: [PATCH] Revert autocommitgenericsql (#29504) * reverted autocommit * reverted autocommit * added bc changes and docs to default value * reverted bc file * added autocommit by default to ms sql * added test case * added to ms odbc as well * removed commented code --- .../Integrations/GenericSQL/GenericSQL.py | 12 +++++------- .../Integrations/GenericSQL/GenericSQL_test.py | 14 +++++++++++--- Packs/GenericSQL/ReleaseNotes/1_0_25.json | 1 + Packs/GenericSQL/ReleaseNotes/1_0_25.md | 4 ++++ Packs/GenericSQL/pack_metadata.json | 2 +- 5 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 Packs/GenericSQL/ReleaseNotes/1_0_25.json create mode 100644 Packs/GenericSQL/ReleaseNotes/1_0_25.md diff --git a/Packs/GenericSQL/Integrations/GenericSQL/GenericSQL.py b/Packs/GenericSQL/Integrations/GenericSQL/GenericSQL.py index 98a5dc97770e..b43dbda64445 100644 --- a/Packs/GenericSQL/Integrations/GenericSQL/GenericSQL.py +++ b/Packs/GenericSQL/Integrations/GenericSQL/GenericSQL.py @@ -69,8 +69,10 @@ def parse_connect_parameters(connect_parameters: str, dialect: str, verify_certi connect_parameters_dict[key] = value if dialect == "Microsoft SQL Server": connect_parameters_dict['driver'] = 'FreeTDS' + connect_parameters_dict.setdefault('autocommit', 'True') elif dialect == 'Microsoft SQL Server - MS ODBC Driver': connect_parameters_dict['driver'] = 'ODBC Driver 18 for SQL Server' + connect_parameters_dict.setdefault('autocommit', 'True') if not verify_certificate: connect_parameters_dict['TrustServerCertificate'] = 'yes' return connect_parameters_dict @@ -151,13 +153,9 @@ def sql_query_execute_request(self, sql_query: str, bind_vars: Any, fetch_limit= if type(bind_vars) is dict: sql_query = text(sql_query) - with self.connection as connection: - # The isolation level is for stored procedures SQL queries that include INSERT, DELETE etc. - connection.execution_options(isolation_level="AUTOCOMMIT") - result = self.connection.execute(sql_query, bind_vars) - # For avoiding responses with lots of records - results = result.fetchmany(fetch_limit) if fetch_limit else result.fetchall() - + result = self.connection.execute(sql_query, bind_vars) + # For avoiding responses with lots of records + results = result.fetchmany(fetch_limit) if fetch_limit else result.fetchall() headers = [] if results: # if the table isn't empty diff --git a/Packs/GenericSQL/Integrations/GenericSQL/GenericSQL_test.py b/Packs/GenericSQL/Integrations/GenericSQL/GenericSQL_test.py index f9a135d9399a..f47959d38390 100644 --- a/Packs/GenericSQL/Integrations/GenericSQL/GenericSQL_test.py +++ b/Packs/GenericSQL/Integrations/GenericSQL/GenericSQL_test.py @@ -263,10 +263,18 @@ def test_mysql_integration(): @pytest.mark.parametrize('connect_parameters, dialect, expected_response', [ - ('arg1=value1&arg2=value2', 'MySQL', {'arg1': 'value1', 'arg2': 'value2'}), - ('arg1=value1&arg2=value2', 'Microsoft SQL Server', {'arg1': 'value1', 'arg2': 'value2', 'driver': 'FreeTDS'}), + ('arg1=value1&arg2=value2', 'MySQL', + {'arg1': 'value1', 'arg2': 'value2'}), + ('arg1=value1&arg2=value2', 'Microsoft SQL Server', + {'arg1': 'value1', 'arg2': 'value2', 'driver': 'FreeTDS', 'autocommit': 'True'}), + ('arg1=value1&arg2=value2&autocommit=False', 'Microsoft SQL Server', + {'arg1': 'value1', 'arg2': 'value2', 'driver': 'FreeTDS', 'autocommit': 'False'}), ('arg1=value1&arg2=value2', 'Microsoft SQL Server - MS ODBC Driver', - {'arg1': 'value1', 'arg2': 'value2', 'driver': 'ODBC Driver 18 for SQL Server', 'TrustServerCertificate': 'yes'})]) + {'arg1': 'value1', 'arg2': 'value2', 'driver': 'ODBC Driver 18 for SQL Server', + 'TrustServerCertificate': 'yes', 'autocommit': 'True'}), + ('arg1=value1&arg2=value2&autocommit=False', 'Microsoft SQL Server - MS ODBC Driver', + {'arg1': 'value1', 'arg2': 'value2', 'driver': 'ODBC Driver 18 for SQL Server', + 'TrustServerCertificate': 'yes', 'autocommit': 'False'})]) def test_parse_connect_parameters(connect_parameters, dialect, expected_response): assert Client.parse_connect_parameters(connect_parameters, dialect, False) == expected_response diff --git a/Packs/GenericSQL/ReleaseNotes/1_0_25.json b/Packs/GenericSQL/ReleaseNotes/1_0_25.json new file mode 100644 index 000000000000..dac8e8d0dbe9 --- /dev/null +++ b/Packs/GenericSQL/ReleaseNotes/1_0_25.json @@ -0,0 +1 @@ +{"breakingChanges":true,"breakingChangesNotes": "The ***Connection Argument*** 'autocommit' is now True by default for Microsoft SQL server and Microsoft SQL Server - MS ODBC Driver dialects. Set 'autocommit=False' in order to disable it.\n"} \ No newline at end of file diff --git a/Packs/GenericSQL/ReleaseNotes/1_0_25.md b/Packs/GenericSQL/ReleaseNotes/1_0_25.md new file mode 100644 index 000000000000..13e7d11aee96 --- /dev/null +++ b/Packs/GenericSQL/ReleaseNotes/1_0_25.md @@ -0,0 +1,4 @@ + +#### Integrations +##### Generic SQL +- The ***Connection Argument*** 'autocommit' is now True by default for Microsoft SQL server and Microsoft SQL Server - MS ODBC Driver dialects. Set 'autocommit=False' in order to disable it. diff --git a/Packs/GenericSQL/pack_metadata.json b/Packs/GenericSQL/pack_metadata.json index 2eff9fa824b0..6b11dae66f48 100644 --- a/Packs/GenericSQL/pack_metadata.json +++ b/Packs/GenericSQL/pack_metadata.json @@ -3,7 +3,7 @@ "description": "Connect and execute sql queries in 4 Databases: MySQL, PostgreSQL, Microsoft SQL Server and Oracle", "support": "xsoar", "serverMinVersion": "5.0.0", - "currentVersion": "1.0.24", + "currentVersion": "1.0.25", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "",