-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathtvp_test.exs
More file actions
55 lines (48 loc) · 1.33 KB
/
tvp_test.exs
File metadata and controls
55 lines (48 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
defmodule TvpTest do
import Tds.TestHelper
require Logger
use ExUnit.Case, async: true
alias Tds.Parameter
alias Tds.Column
@tag timeout: 50000
setup do
opts = Application.fetch_env!(:tds, :opts)
{:ok, pid} = Tds.start_link(opts)
{:ok, [pid: pid]}
end
test "TVP in stored proc", context do
assert :ok = query("BEGIN TRY DROP PROCEDURE __tvpTest DROP TYPE TvpTestType END TRY BEGIN CATCH END CATCH", [])
assert :ok = query("""
CREATE TYPE TvpTestType AS TABLE (
a int,
b uniqueidentifier,
c varchar(100),
d varbinary(max)
);
""", [])
assert :ok = query("""
CREATE PROCEDURE __tvpTest (@tvp TvpTestType readonly)
AS BEGIN
select * from @tvp
END
""", [])
rows = [1, <<158, 3, 157, 56, 133, 56, 73, 67, 128, 121, 126, 204, 115, 227, 162, 157>>, "foo", "{\"foo\":\"bar\",\"baz\":\"biz\"}"]
params = [
%Parameter{
name: "@tvp",
value: %{
name: "TvpTestType",
columns: [
%Column{name: "a", type: :int},
%Column{name: "b", type: :uuid},
%Column{name: "c", type: :varchar},
%Column{name: "d", type: :varbinary},
],
rows: [rows]
},
type: :tvp
}
]
assert [^rows] = proc("__tvpTest", params)
end
end