@@ -1040,7 +1040,7 @@ class SqliteDb(SimpleReprMixin):
1040
1040
1041
1041
"""
1042
1042
def __init__ (self , filename , debug ):
1043
- self .debug = debug if debug . should ( "sql" ) else None
1043
+ self .debug = debug
1044
1044
self .filename = filename
1045
1045
self .nest = 0
1046
1046
self .con = None
@@ -1055,7 +1055,7 @@ def _connect(self):
1055
1055
# effectively causing a nested context. However, given the idempotent
1056
1056
# nature of the tracer operations, sharing a connection among threads
1057
1057
# is not a problem.
1058
- if self .debug :
1058
+ if self .debug . should ( "sql" ) :
1059
1059
self .debug .write (f"Connecting to { self .filename !r} " )
1060
1060
try :
1061
1061
self .con = sqlite3 .connect (self .filename , check_same_thread = False )
@@ -1091,13 +1091,13 @@ def __exit__(self, exc_type, exc_value, traceback):
1091
1091
self .con .__exit__ (exc_type , exc_value , traceback )
1092
1092
self .close ()
1093
1093
except Exception as exc :
1094
- if self .debug :
1094
+ if self .debug . should ( "sql" ) :
1095
1095
self .debug .write (f"EXCEPTION from __exit__: { exc } " )
1096
1096
raise DataError (f"Couldn't end data file { self .filename !r} : { exc } " ) from exc
1097
1097
1098
1098
def execute (self , sql , parameters = ()):
1099
1099
"""Same as :meth:`python:sqlite3.Connection.execute`."""
1100
- if self .debug :
1100
+ if self .debug . should ( "sql" ) :
1101
1101
tail = f" with { parameters !r} " if parameters else ""
1102
1102
self .debug .write (f"Executing { sql !r} { tail } " )
1103
1103
try :
@@ -1122,7 +1122,7 @@ def execute(self, sql, parameters=()):
1122
1122
)
1123
1123
except Exception : # pragma: cant happen
1124
1124
pass
1125
- if self .debug :
1125
+ if self .debug . should ( "sql" ) :
1126
1126
self .debug .write (f"EXCEPTION from execute: { msg } " )
1127
1127
raise DataError (f"Couldn't use data file { self .filename !r} : { msg } " ) from exc
1128
1128
@@ -1145,7 +1145,7 @@ def execute_one(self, sql, parameters=()):
1145
1145
1146
1146
def executemany (self , sql , data ):
1147
1147
"""Same as :meth:`python:sqlite3.Connection.executemany`."""
1148
- if self .debug :
1148
+ if self .debug . should ( "sql" ) :
1149
1149
data = list (data )
1150
1150
self .debug .write (f"Executing many { sql !r} with { len (data )} rows" )
1151
1151
try :
@@ -1158,7 +1158,7 @@ def executemany(self, sql, data):
1158
1158
1159
1159
def executescript (self , script ):
1160
1160
"""Same as :meth:`python:sqlite3.Connection.executescript`."""
1161
- if self .debug :
1161
+ if self .debug . should ( "sql" ) :
1162
1162
self .debug .write ("Executing script with {} chars: {}" .format (
1163
1163
len (script ), clipped_repr (script , 100 ),
1164
1164
))
0 commit comments