def _raise_if_closed(self): """Helper to check the connection state before running a query. Raises an exception if this connection is closed. :raises: :class:`InterfaceError`: if this connection is closed. """ if self.is_closed: raise InterfaceError("connection is already closed")
def wrapper(cursor, *args, **kwargs): if not cursor.connection: raise ProgrammingError("Cursor is not connected to the database") if cursor.is_closed: raise InterfaceError("Cursor and/or connection is already closed.") return function(cursor, *args, **kwargs)
def _raise_if_closed(self): """Raise an exception if this cursor is closed. Helper to check this cursor's state before running a SQL/DDL/DML query. If the parent connection is already closed it also raises an error. :raises: :class:`InterfaceError` if this cursor is closed. """ if self.is_closed: raise InterfaceError("Cursor and/or connection is already closed.")
def wrapper(connection, *args, **kwargs): if connection.is_closed: raise InterfaceError("Connection is already closed") return function(connection, *args, **kwargs)