Skip to content

Commit

Permalink
Revert autocommitgenericsql (demisto#29504)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yucohen authored Sep 7, 2023
1 parent 47738d5 commit da93bf0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
12 changes: 5 additions & 7 deletions Packs/GenericSQL/Integrations/GenericSQL/GenericSQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions Packs/GenericSQL/Integrations/GenericSQL/GenericSQL_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Packs/GenericSQL/ReleaseNotes/1_0_25.json
Original file line number Diff line number Diff line change
@@ -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"}
4 changes: 4 additions & 0 deletions Packs/GenericSQL/ReleaseNotes/1_0_25.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion Packs/GenericSQL/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down

0 comments on commit da93bf0

Please sign in to comment.