试图找到最后插入的行 ID;返回值已加密
Trying to find last insert row ID; returned value is encrypted
我在 SQL Server 2016 中使用 pypyodbc。
我正在尝试插入并获取在 another user's remarks 之后插入数据库的最后一个 ID,但返回的值似乎已加密。有办法解密吗?
def executeSQL (command):
connection = pypyodbc.connect('Driver={SQL Native Client};'
'Server=blah\blah;'
'Database=Impact;'
'uid=Admin;pwd=F$sfgdfgs99')
cursor=connection.cursor()
cursor.execute(command)
id = cursor.execute("SELECT @@IDENTITY")
connection.commit()
connection.close()
return id
sqlexecute = 'INSERT INTO PERSONS([LastName], [FirstName]) VALUES(\''+lastname.encode('utf-8')+'\',\''+firstname.encode('utf-8')+'\');\n'
lastid = executeSQL(sqlexecute)
print lastid
输出:
<pypyodbc.Cursor instance at 0x000000000B870C88>
它没有加密,它告诉你这是对象的实例。在这种情况下,它是 pypyodbc.Cursor
。
要获取实际行,您需要执行 id.fetchall()
,这将 return 一个结果列表。然后您可以遍历它们以阅读内容。
我在 SQL Server 2016 中使用 pypyodbc。
我正在尝试插入并获取在 another user's remarks 之后插入数据库的最后一个 ID,但返回的值似乎已加密。有办法解密吗?
def executeSQL (command):
connection = pypyodbc.connect('Driver={SQL Native Client};'
'Server=blah\blah;'
'Database=Impact;'
'uid=Admin;pwd=F$sfgdfgs99')
cursor=connection.cursor()
cursor.execute(command)
id = cursor.execute("SELECT @@IDENTITY")
connection.commit()
connection.close()
return id
sqlexecute = 'INSERT INTO PERSONS([LastName], [FirstName]) VALUES(\''+lastname.encode('utf-8')+'\',\''+firstname.encode('utf-8')+'\');\n'
lastid = executeSQL(sqlexecute)
print lastid
输出:
<pypyodbc.Cursor instance at 0x000000000B870C88>
它没有加密,它告诉你这是对象的实例。在这种情况下,它是 pypyodbc.Cursor
。
要获取实际行,您需要执行 id.fetchall()
,这将 return 一个结果列表。然后您可以遍历它们以阅读内容。