1. edgewall
  2. Trac

Commits

Remy Blank  committed 3042603

db: Fixed `Cursor.executemany()` to handle the case where `args=None` correctly, and made the argument mandatory.

Closes #9268.

  • Participants
  • Parent commits 1fdcfb2
  • Branches trunk

Comments (0)

Files changed (2)

File trac/db/sqlite_backend.py

View file
  • Ignore whitespace
                 sql = sql % (('?',) * len(args))
             return self._rollback_on_error(sqlite.Cursor.execute, sql,
                                            args or [])
-        def executemany(self, sql, args=None):
-            if args:
-                sql = sql % (('?',) * len(args[0]))
+        def executemany(self, sql, args):
+            if not args:
+                return
+            sql = sql % (('?',) * len(args[0]))
             return self._rollback_on_error(sqlite.Cursor.executemany, sql,
-                                           args or [])
+                                           args)
 
     # EagerCursor taken from the example in pysqlite's repository:
     #

File trac/db/util.py

View file
  • Ignore whitespace
             return self.cursor.execute(sql_escape_percent(sql), args)
         return self.cursor.execute(sql)
 
-    def executemany(self, sql, args=None):
+    def executemany(self, sql, args):
         if self.log:
             self.log.debug('SQL: %r', sql)
+            self.log.debug('args: %r', args)
+            if not args:
+                return
             try:
-                if args:
-                    self.log.debug('args: %r', args)
+                if args[0]:
                     return self.cursor.executemany(sql_escape_percent(sql),
                                                    args)
-                return self.cursor.execute(sql)
+                return self.cursor.executemany(sql, args)
             except Exception, e:
                 self.log.debug('executemany exception: %r', e)
                 raise
-        if args:
+        if not args:
+            return
+        if args[0]:
             return self.cursor.executemany(sql_escape_percent(sql), args)
-        return self.cursor.executemany(sql)
+        return self.cursor.executemany(sql, args)
 
 
 class ConnectionWrapper(object):