]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- remove the clever approach w/ dialect events, and remove the need
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 Jan 2015 23:22:00 +0000 (18:22 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 Jan 2015 23:22:00 +0000 (18:22 -0500)
for a for-loop through an empty tuple.   we add one more local flag
to handle the logic without repetition of dialect.do_execute()
calls.

lib/sqlalchemy/engine/base.py

index aba0d29df3e95107aaa34c7e9369078bfac9220d..8d816b7fdadbdb12e57921959a99cbb0e247a48f 100644 (file)
@@ -1079,36 +1079,39 @@ class Connection(Connectable):
                 "%r",
                 sql_util._repr_params(parameters, batches=10)
             )
+
+        evt_handled = False
         try:
             if context.executemany:
-                for fn in () if not self.dialect._has_events \
-                        else self.dialect.dispatch.do_executemany:
-                    if fn(cursor, statement, parameters, context):
-                        break
-                else:
+                if self.dialect._has_events:
+                    for fn in self.dialect.dispatch.do_executemany:
+                        if fn(cursor, statement, parameters, context):
+                            evt_handled = True
+                            break
+                if not evt_handled:
                     self.dialect.do_executemany(
                         cursor,
                         statement,
                         parameters,
                         context)
-
             elif not parameters and context.no_parameters:
-                for fn in () if not self.dialect._has_events \
-                        else self.dialect.dispatch.do_execute_no_params:
-                    if fn(cursor, statement, context):
-                        break
-                else:
+                if self.dialect._has_events:
+                    for fn in self.dialect.dispatch.do_execute_no_params:
+                        if fn(cursor, statement, context):
+                            evt_handled = True
+                            break
+                if not evt_handled:
                     self.dialect.do_execute_no_params(
                         cursor,
                         statement,
                         context)
-
             else:
-                for fn in () if not self.dialect._has_events \
-                        else self.dialect.dispatch.do_execute:
-                    if fn(cursor, statement, parameters, context):
-                        break
-                else:
+                if self.dialect._has_events:
+                    for fn in self.dialect.dispatch.do_execute:
+                        if fn(cursor, statement, parameters, context):
+                            evt_handled = True
+                            break
+                if not evt_handled:
                     self.dialect.do_execute(
                         cursor,
                         statement,