def _execute_context(self, dialect, constructor,
                         statement, parameters,
                         *args):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`.ResultProxy`."""

        try:
            try:
                conn = self.__connection
            except __HOLE__:
                conn = self._revalidate_connection()

            context = constructor(dialect, self, conn, *args)
        except Exception as e:
            self._handle_dbapi_exception(e,
                                         util.text_type(statement), parameters,
                                         None, None)

        if context.compiled:
            context.pre_exec()

        cursor, statement, parameters = context.cursor, \
            context.statement, \
            context.parameters

        if not context.executemany:
            parameters = parameters[0]

        if self._has_events or self.engine._has_events:
            for fn in self.dispatch.before_cursor_execute:
                statement, parameters = \
                    fn(self, cursor, statement, parameters,
                       context, context.executemany)

        if self._echo:
            self.engine.logger.info(statement)
            self.engine.logger.info(
                "%r",
                sql_util._repr_params(parameters, batches=10)
            )
        try:
            if context.executemany:
                for fn in () if not self.dialect._has_events \
                        else self.dialect.dispatch.do_executemany:
                    if fn(cursor, statement, parameters, context):
                        break
                else:
                    self.dialect.do_executemany(
                        cursor,
                        statement,
                        parameters,
                        context)

            elif not parameters and context.no_parameters:
                for fn in () if not self.dialect._has_events \
                        else self.dialect.dispatch.do_execute_no_params:
                    if fn(cursor, statement, context):
                        break
                else:
                    self.dialect.do_execute_no_params(
                        cursor,
                        statement,
                        context)

            else:
                for fn in () if not self.dialect._has_events \
                        else self.dialect.dispatch.do_execute:
                    if fn(cursor, statement, parameters, context):
                        break
                else:
                    self.dialect.do_execute(
                        cursor,
                        statement,
                        parameters,
                        context)
        except Exception as e:
            self._handle_dbapi_exception(
                e,
                statement,
                parameters,
                cursor,
                context)

        if self._has_events or self.engine._has_events:
            self.dispatch.after_cursor_execute(self, cursor,
                                               statement,
                                               parameters,
                                               context,
                                               context.executemany)

        if context.compiled:
            context.post_exec()

            if context.isinsert and not context.executemany:
                context.post_insert()

        # create a resultproxy, get rowcount/implicit RETURNING
        # rows, close cursor if no further results pending
        result = context.get_result_proxy()
        if context.isinsert:
            if context._is_implicit_returning:
                context._fetch_implicit_returning(result)
                result.close(_autoclose_connection=False)
                result._metadata = None
            elif not context._is_explicit_returning:
                result.close(_autoclose_connection=False)
                result._metadata = None
        elif context.isupdate and context._is_implicit_returning:
            context._fetch_implicit_update_returning(result)
            result.close(_autoclose_connection=False)
            result._metadata = None

        elif result._metadata is None:
            # no results, get rowcount
            # (which requires open cursor on some drivers
            # such as kintersbasdb, mxodbc),
            result.rowcount
            result.close(_autoclose_connection=False)

        if self.__transaction is None and context.should_autocommit:
            self._commit_impl(autocommit=True)

        if result.closed and self.should_close_with_result:
            self.close()

        return result
dataset/ETHPy150Open goFrendiAsgard/kokoropy/kokoropy/packages/sqlalchemy/engine/base.py/Connection._execute_context