如何:在 Elixir 中使用 Tds 库调用存储过程
HOW TO: call stored procedures with Tds Library in Elixir
我在尝试使用 ElixirTds 库调用存储过程时遇到以下错误
存储过程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])
试试这个也不行
解决方法:
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)
我在尝试使用 ElixirTds 库调用存储过程时遇到以下错误
存储过程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])
试试这个也不行
解决方法:
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)