Ejemplo n.º 1
0
 def execute(self, sql, params=[], has_result=False):
     """
     Executes the given SQL statement, with optional parameters.
     """
     result = None
     # Log the command we're running, then run it
     logger.debug("%s; (params %r)",
                  sql,
                  params,
                  extra={
                      'params': params,
                      'sql': sql
                  })
     if self.collect_sql:
         ending = "" if sql.endswith(";") else ";"
         if params is not None:
             self.collected_sql.append(
                 (sql % tuple(map(self.quote_value, params))) + ending)
         else:
             self.collected_sql.append(sql + ending)
     else:
         cursor = self.connection.cursor()
         cursor.execute(sql, params)
         if has_result:
             result = cursor.fetchall()
         # the cursor can be closed only when the driver supports opening
         # multiple cursors on a connection because the migration command
         # has already opened a cursor outside this method
         if self.connection.supports_mars:
             cursor.close()
     return result
Ejemplo n.º 2
0
 def execute(self, sql, params=(), has_result=False):
     """
     Executes the given SQL statement, with optional parameters.
     """
     result = None
     # Don't perform the transactional DDL check if SQL is being collected
     # as it's not going to be executed anyway.
     if not self.collect_sql and self.connection.in_atomic_block and not self.connection.features.can_rollback_ddl:
         raise TransactionManagementError(
             "Executing DDL statements while in a transaction on databases "
             "that can't perform a rollback is prohibited."
         )
     # Account for non-string statement objects.
     sql = str(sql)
     # Log the command we're running, then run it
     logger.debug("%s; (params %r)", sql, params, extra={'params': params, 'sql': sql})
     if self.collect_sql:
         ending = "" if sql.endswith(";") else ";"
         if params is not None:
             self.collected_sql.append((sql % tuple(map(self.quote_value, params))) + ending)
         else:
             self.collected_sql.append(sql + ending)
     else:
         cursor = self.connection.cursor()
         cursor.execute(sql, params)
         if has_result:
             result = cursor.fetchall()
         # the cursor can be closed only when the driver supports opening
         # multiple cursors on a connection because the migration command
         # has already opened a cursor outside this method
         if self.connection.supports_mars:
             cursor.close()
     return result
Ejemplo n.º 3
0
 def execute(self, sql, params=(), has_result=False):
     """
     Executes the given SQL statement, with optional parameters.
     """
     result = None
     # Don't perform the transactional DDL check if SQL is being collected
     # as it's not going to be executed anyway.
     if not self.collect_sql and self.connection.in_atomic_block and not self.connection.features.can_rollback_ddl:
         raise TransactionManagementError(
             "Executing DDL statements while in a transaction on databases "
             "that can't perform a rollback is prohibited."
         )
     # Log the command we're running, then run it
     logger.debug("%s; (params %r)", sql, params, extra={'params': params, 'sql': sql})
     if self.collect_sql:
         ending = "" if sql.endswith(";") else ";"
         if params is not None:
             self.collected_sql.append((sql % tuple(map(self.quote_value, params))) + ending)
         else:
             self.collected_sql.append(sql + ending)
     else:
         cursor = self.connection.cursor()
         cursor.execute(sql, params)
         if has_result:
             result = cursor.fetchall()
         # the cursor can be closed only when the driver supports opening
         # multiple cursors on a connection because the migration command
         # has already opened a cursor outside this method
         if self.connection.supports_mars:
             cursor.close()
     return result
Ejemplo n.º 4
0
 def execute(self, sql, params=[], has_result=False):
     """
     Executes the given SQL statement, with optional parameters.
     """
     result = None
     # Log the command we're running, then run it
     logger.debug("%s; (params %r)" % (sql, params))
     if self.collect_sql:
         ending = "" if sql.endswith(";") else ";"
         if params is not None:
             self.collected_sql.append((sql % tuple(map(self.quote_value, params))) + ending)
         else:
             self.collected_sql.append(sql + ending)
     else:
         cursor = self.connection.cursor()
         cursor.execute(sql, params)
         if has_result:
             result = cursor.fetchall()
         # the cursor can be closed only when the driver supports opening
         # multiple cursors on a connection because the migration command
         # has already opened a cursor outside this method
         if self.connection.supports_mars:
             cursor.close()
     return result