예제 #1
0
 def execute_sql(self,
                 sql,
                 params=None,
                 require_commit=True,
                 named_cursor=False):
     logger.debug((sql, params))
     use_named_cursor = (named_cursor
                         or (self.server_side_cursors
                             and sql.lower().startswith('select')))
     with self.exception_wrapper():
         if use_named_cursor:
             cursor = self.get_cursor(name=str(uuid.uuid1()))
             require_commit = False
         else:
             cursor = self.get_cursor()
         try:
             cursor.execute(sql, params or ())
         except Exception as exc:
             logger.exception('%s %s', sql, params)
             if self.get_autocommit() and self.autorollback:
                 self.rollback()
             if self.sql_error_handler(exc, sql, params, require_commit):
                 raise
         else:
             if require_commit and self.get_autocommit():
                 self.commit()
     return cursor
예제 #2
0
 def execute_sql(self, sql, params=None, require_commit=True, named_cursor=False):
     logger.debug((sql, params))
     use_named_cursor = named_cursor or (self.server_side_cursors and sql.lower().startswith("select"))
     with self.exception_wrapper():
         if use_named_cursor:
             cursor = self.get_cursor(name=str(uuid.uuid1()))
             require_commit = False
         else:
             cursor = self.get_cursor()
         try:
             res = cursor.execute(sql, params or ())
         except Exception as exc:
             logger.exception("%s %s", sql, params)
             if self.sql_error_handler(exc, sql, params, require_commit):
                 raise
         else:
             if require_commit and self.get_autocommit():
                 self.commit()
     return cursor