看起来sqlAlchemy似乎不支持调用存储过程.有没有人找到适用于sql Server的解决方法?
样品程序:
CREATE PROCEDURE list_lock_set @name varchar (5),@requester varchar(30)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO list_lock (name,requester,acquired) values (@name,@requester,GETDATE())
RETURN 0
END
GO
这有效:
import pyodbc
dbh = pyodbc.connect(driver=''{sql Server}'',server=srv,database=db,uid=uid,pwd=pwd)
dbc = dbh.cursor()
dbc.execute("list_lock_set ?,?",['bbc','pyodbc'])
dbc.commit()
这不会产生错误,但也不起作用:
from sqlalchemy import create_engine
engine = create_engine('mssql+pyodbc://usr:passw@srv/db?driver=sql Server',echo=True)
engine.execute("list_lock_set ?,'sqlalchemy'])
谢谢.
cursor = engine.raw_connection().cursor()
cursor.execute("list_lock_set ?,'using cursor'])
cursor.commit()
我也可以获得pyodbc连接:
engine.raw_connection().connection
并设置autocommit = True,但这可能会干扰引擎逻辑.非常感谢@Batman.
最佳答案
原文链接:https://www.f2er.com/python/438647.html