コード例 #1
0
    def _create_trigger(self, field):
        # import MySQLdb as Database
        from warnings import filterwarnings, resetwarnings

        filterwarnings('ignore', message='Trigger does not exist',
                       category=Warning)

        opts = field.model._meta
        trigger_name = get_trigger_name(field, opts)

        stm = self.sql.format(trigger_name=trigger_name,
                              opts=opts, field=field)
        cursor = self.connection._clone().cursor()
        try:
            cursor.execute(stm)
            self._triggers[field] = trigger_name

        except (BaseException, _mysql_exceptions.ProgrammingError) as exc:
            errno, message = exc.args
            if errno != 2014:
                import traceback
                traceback.print_exc(exc)
                raise
        resetwarnings()
        return trigger_name
コード例 #2
0
    def _create_trigger(self, field):
        # import MySQLdb as Database
        from warnings import filterwarnings, resetwarnings

        filterwarnings('ignore',
                       message='Trigger does not exist',
                       category=Warning)

        opts = field.model._meta
        trigger_name = get_trigger_name(field, opts)

        stm = self.sql.format(trigger_name=trigger_name,
                              opts=opts,
                              field=field)
        cursor = self.connection._clone().cursor()
        try:
            cursor.execute(stm)
            self._triggers[field] = trigger_name

        except (BaseException, _mysql_exceptions.ProgrammingError) as exc:
            errno, message = exc.args
            if errno != 2014:
                import traceback
                traceback.print_exc(exc)
                raise
        resetwarnings()
        return trigger_name
コード例 #3
0
    def _create_trigger(self, field):
        from django.db.utils import DatabaseError
        cursor = self.connection.cursor()

        opts = field.model._meta
        trigger_name = get_trigger_name(field, opts)

        stms = self.sql.split('##')
        for template in stms:
            stm = template.format(trigger_name=trigger_name,
                                  opts=opts,
                                  field=field)
            try:
                cursor.execute(stm)
            except BaseException as exc:
                raise DatabaseError(exc)

        return trigger_name
コード例 #4
0
    def _create_trigger(self, field):
        from django.db.utils import DatabaseError

        opts = field.model._meta
        trigger_name = get_trigger_name(field, opts)

        stm = self.sql.format(trigger_name=trigger_name,
                              opts=opts,
                              field=field)

        self.connection.drop_trigger('{}_i'.format(trigger_name))
        self.connection.drop_trigger('{}_u'.format(trigger_name))
        try:
            self.connection.cursor().execute(stm)
            self._triggers[field] = trigger_name
        except BaseException as exc:  # pragma: no cover
            raise DatabaseError(exc)

        return trigger_name