示例#1
0
class MSExecutionContext_zxjdbc(MSExecutionContext):

    _embedded_scope_identity = False

    def pre_exec(self):
        super(MSExecutionContext_zxjdbc, self).pre_exec()
        # scope_identity after the fact returns null in jTDS so we must
        # embed it
        if self._select_lastrowid and self.dialect.use_scope_identity:
            self._embedded_scope_identity = True
            self.statement += "; SELECT scope_identity()"

    def post_exec(self):
        if self._embedded_scope_identity:
            while True:
                try:
                    row = self.cursor.fetchall()[0]
                    break
                except self.dialect.dbapi.Error, e:
                    self.cursor.nextset()
            self._lastrowid = int(row[0])

        if (self.isinsert or self.isupdate or self.isdelete) and \
            self.compiled.returning:
            self._result_proxy = base.FullyBufferedResultProxy(self)

        if self._enable_identity_insert:
            table = self.dialect.identifier_preparer.format_table(
                self.compiled.statement.table)
            self.cursor.execute("SET IDENTITY_INSERT %s OFF" % table)
示例#2
0
    def post_exec(self):
        if self._embedded_scope_identity:
            while True:
                try:
                    row = self.cursor.fetchall()[0]
                    break
                except self.dialect.dbapi.Error as e:
                    self.cursor.nextset()
            self._lastrowid = int(row[0])

        if (self.isinsert or self.isupdate or self.isdelete) and \
            self.compiled.returning:
            self._result_proxy = base.FullyBufferedResultProxy(self)

        if self._enable_identity_insert:
            table = self.dialect.identifier_preparer.format_table(
                self.compiled.statement.table)
            self.cursor.execute("SET IDENTITY_INSERT %s OFF" % table)
示例#3
0
    def post_exec(self):
        """Disable IDENTITY_INSERT if enabled."""

        if self._select_lastrowid:
            if self.dialect.use_scope_identity:
                self.cursor.execute("SELECT scope_identity() AS lastrowid", ())
            else:
                self.cursor.execute("SELECT @@identity AS lastrowid", ())
            # fetchall() ensures the cursor is consumed without closing it
            row = self.cursor.fetchall()[0]
            self._lastrowid = int(row[0])

        if (self.isinsert or self.isupdate or self.isdelete) and \
                self.compiled.returning:
            self._result_proxy = base.FullyBufferedResultProxy(self)

        if self._enable_identity_insert:
            self.cursor.execute("SET IDENTITY_INSERT %s OFF" %
                                self.dialect.identifier_preparer.format_table(
                                    self.compiled.statement.table))