Skip to content

Commit 0153ae0

Browse files
authored
Merge pull request #174 from jonstace-hsf/mssql-verbose-error
MSSQL: TypeError when --verbose is enabled.
2 parents db07553 + 2b0e683 commit 0153ae0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1818
## [Unreleased]
1919
## Fixed
2020
- Fixed a issue when updates to MSSQL data would result in multiple messages coming back from the server, e.g. when triggers update multiple tables and NOCOUNT is OFF. Another scenario is before or after scripts that call stored procs wth PRINT statements in them or that return multiple resultsets before completing. Without the fix, this issue can result in tables only partially anonymized.
21+
- Fix error messages when running MSSQL anonymization with --verbose enabled
2122

2223
## [2.4.0] 2024-07-30
2324
## Changed

pynonymizer/database/mssql/__init__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -137,28 +137,29 @@ def __db_connection(self):
137137
return self.__db_conn
138138

139139
def __execute_dml(self, statement, *args):
140-
logger.debug(statement, args)
140+
logger.debug("sql: %s, args: %s", statement, args)
141141
c = self.__db_connection()
142142
# If timeout is set, then apply it to the connection. PyODBC will then assign that value to the Cursor created during execute()
143143
if self.timeout:
144144
c.timeout = self.timeout
145145
cur = c.execute(statement, *args)
146+
logger.debug("%s row(s) affected", cur.rowcount)
146147
# If the SQL query causes multiple messages to come back (either extra row counts from triggers, or PRINT statements),
147148
# then we need to keep running nextset() for PyODBC to get the query to run to completion
148149
while cur.nextset():
149-
pass
150+
logger.debug("%s row(s) affected", cur.rowcount)
150151
return cur
151152

152153
def __execute_ddl(self, statement, *args):
153-
logger.debug(statement, args)
154+
logger.debug("sql: %s, args: %s", statement, args)
154155
c = self.__db_connection()
155156
# If timeout is set, then apply it to the connection. PyODBC will then assign that value to the Cursor created during execute()
156157
if self.timeout:
157158
c.timeout = self.timeout
158159
return c.execute(statement, *args)
159160

160161
def __execute_server(self, statement, *args):
161-
logger.debug(statement, args)
162+
logger.debug("sql: %s, args: %s", statement, args)
162163
c = self.__connection()
163164
# If timeout is set, then apply it to the connection. PyODBC will then assign that value to the Cursor created during execute()
164165
if self.timeout:

0 commit comments

Comments
 (0)