(self)
| 1916 | self.statement += "; select scope_identity()" |
| 1917 | |
| 1918 | def post_exec(self): |
| 1919 | |
| 1920 | conn = self.root_connection |
| 1921 | |
| 1922 | if self.isinsert or self.isupdate or self.isdelete: |
| 1923 | self._rowcount = self.cursor.rowcount |
| 1924 | |
| 1925 | # handle INSERT with embedded SELECT SCOPE_IDENTITY() call |
| 1926 | if self._embedded_scope_identity: |
| 1927 | # Fetch the last inserted id from the manipulated statement |
| 1928 | # We may have to skip over a number of result sets with |
| 1929 | # no data (due to triggers, etc.) so run up to three times |
| 1930 | |
| 1931 | row = None |
| 1932 | for _ in range(3): |
| 1933 | if self.cursor.description: |
| 1934 | rows = self.cursor.fetchall() |
| 1935 | if rows: |
| 1936 | row = rows[0] |
| 1937 | break |
| 1938 | else: |
| 1939 | self.cursor.nextset() |
| 1940 | |
| 1941 | self._lastrowid = int(row[0]) if row else None |
| 1942 | |
| 1943 | self.cursor_fetch_strategy = _cursor._NO_CURSOR_DML |
| 1944 | |
| 1945 | elif self._select_lastrowid: |
| 1946 | if self.dialect.use_scope_identity: |
| 1947 | conn._cursor_execute( |
| 1948 | self.cursor, |
| 1949 | "SELECT scope_identity() AS lastrowid", |
| 1950 | (), |
| 1951 | self, |
| 1952 | ) |
| 1953 | else: |
| 1954 | conn._cursor_execute( |
| 1955 | self.cursor, "SELECT @@identity AS lastrowid", (), self |
| 1956 | ) |
| 1957 | # fetchall() ensures the cursor is consumed without closing it |
| 1958 | row = self.cursor.fetchall()[0] |
| 1959 | self._lastrowid = int(row[0]) |
| 1960 | |
| 1961 | self.cursor_fetch_strategy = _cursor._NO_CURSOR_DML |
| 1962 | elif ( |
| 1963 | self.compiled is not None |
| 1964 | and is_sql_compiler(self.compiled) |
| 1965 | and self.compiled.effective_returning |
| 1966 | ): |
| 1967 | self.cursor_fetch_strategy = ( |
| 1968 | _cursor.FullyBufferedCursorFetchStrategy( |
| 1969 | self.cursor, |
| 1970 | self.cursor.description, |
| 1971 | self.cursor.fetchall(), |
| 1972 | ) |
| 1973 | ) |
| 1974 | |
| 1975 | if self._enable_identity_insert: |
nothing calls this directly
no test coverage detected