Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSSQL adapter, tableX_view.insert (..) + trigger INSTEAD OF INSERT, .lastrowid (), "SELECT SCOPE_IDENTITY ()", return long (../ None / ..) #674

Open
mari0sz opened this issue Oct 21, 2021 · 0 comments

Comments

@mari0sz
Copy link

mari0sz commented Oct 21, 2021

pseudo:
CREATE TABLE tableX ..
CREATE VIEW tableX_view
CREATE TRIGGER tableX_view_trigger ON tableX_view INSTEAD OF INSERT AS ..
IF a=b
BEGIN
INSERT INTO tableY FROM inserted ..
END

File "C:\python\Python37-32\lib\site-packages\pydal\adapters\mssql.py", line 98, in lastrowid
return long(self.cursor.fetchone()[0])
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

"""
def lastrowid(self, table):
self.execute("SELECT SCOPE_IDENTITY();")
return long(self.cursor.fetchone()[0])
"""
suggestions:
1/ self.execute("SELECT @@IDENTITY();") MSSQL Docs
2/
try: return long(self.cursor.fetchone()[0])
except (TypeError): return None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant