else:
return rows[0]
+ # rowcount is a more reasonable default return value than lastrowid,
+ # but for historical compatibility execute() must return lastrowid.
def execute(self, query, *parameters):
+ """Executes the given query, returning the lastrowid from the query."""
+ return self.execute_lastrowid(query, *parameters)
+
+ def execute_lastrowid(self, query, *parameters):
"""Executes the given query, returning the lastrowid from the query."""
cursor = self._cursor()
try:
finally:
cursor.close()
+ def execute_rowcount(self, query, *parameters):
+ """Executes the given query, returning the rowcount from the query."""
+ cursor = self._cursor()
+ try:
+ self._execute(cursor, query, parameters)
+ return cursor.rowcount
+ finally:
+ cursor.close()
+
def executemany(self, query, parameters):
"""Executes the given query against all the given param sequences.
+ We return the lastrowid from the query.
+ """
+ return self.executemany_lastrowid(query, parameters)
+
+ def executemany_lastrowid(self, query, parameters):
+ """Executes the given query against all the given param sequences.
+
We return the lastrowid from the query.
"""
cursor = self._cursor()
finally:
cursor.close()
+ def executemany_rowcount(self, query, parameters):
+ """Executes the given query against all the given param sequences.
+
+ We return the rowcount from the query.
+ """
+ cursor = self._cursor()
+ try:
+ cursor.executemany(query, parameters)
+ return cursor.rowcount
+ finally:
+ cursor.close()
+
def _ensure_connected(self):
# Mysql by default closes client connections that are idle for
# 8 hours, but the client library does not report this fact until