def executeSQL(self, sql, connection=None, commit=False):
"""Execute the given SQL.
This will connect to the database for the first time if necessary.
This method will also log the SQL to self._sqlEcho, if it is not None.
Returns the connection and cursor used and relies on connectionAndCursor()
to obtain these. Note that you can pass in a connection to force a
particular one to be used and a flag to commit immediately.
"""
sql = str(sql) # Excel-based models yield Unicode strings which some db modules don't like
sql = sql.strip()
if aggressiveGC:
import gc
assert gc.isenabled()
gc.collect()
self._sqlCount += 1
if self._sqlEcho:
timestamp = funcs.timestamp()['pretty']
self._sqlEcho.write('SQL %04i. %s %s\n' % (self._sqlCount, timestamp, sql))
self._sqlEcho.flush()
conn, cur = self.connectionAndCursor(connection)
self._executeSQL(cur, sql)
if commit:
conn.commit()
return conn, cur
评论列表
文章目录