2016-04-16 59 views
2
与TDS库存储过程

我收到以下错误尝试使用Tds库药剂HOW TO:调用药剂

存储过程get_account存在调用存储过程并有且只有一个参数@id

iex(5)>Tds.Connection.query(pid, "get_account",[%Tds.Parameter{name: "@id", value: 1}])               
{:error, 
%Tds.Error{message: nil, 
    mssql: %{class: 16, length: 252, line_number: 0, msg_text: "Procedure or function 'get_account' expects parameter '@id', which was not supplied.", number: 201, proc_name: "get_account", 
    server_name: "localhost\\SQLEXPRESS", state: 4}}} 
iex(6)> 

试图用这种Tds.proc(pid, "get_account",[1])无法正常工作或

+0

这大概是那些情况下,它更容易下到二郎ODBC层下降,做你想要做什么的。看到这个问题(http://stackoverflow.com/questions/18929391/how-to-call-stored-procedure-taking-array-using-odbcparam-query-in-erlang)了解更多详情。 –

回答

1

解决方法:

Tds.query(pid, "get_account 1",[]) 

以与使用EXEC将参数直接传递给存储过程的相同方式使用此方法。

更新时间:

这种格式也可以工作:

params = [ 
    %Tds.Parameter{name: "@1", value: 100, type: :integer}, 
    %Tds.Parameter{name: "@2", value: 100, type: :integer}, 
    %Tds.Parameter{name: "@3", value: <<0 ,0 ,0 ,0>>, type: :binary}, 
] 
    Conn.query(s.db, "save_auth_key @1, @2, @3", params)