-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathTestNullInference.fs
154 lines (141 loc) · 3.55 KB
/
TestNullInference.fs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
module Rezoom.SQL.Test.TestNullInference
open System
open NUnit.Framework
open FsUnit
open Rezoom.SQL.Compiler
open Rezoom.SQL.Mapping
let expect (sql : string) expectedColumns expectedParams =
let userModel = userModel1()
let parsed = CommandEffect.OfSQL(userModel.Model, "anonymous", sql)
let sets = parsed.ResultSets() |> Seq.toArray
if sets.Length <> 1 then failwith "expected 1 result set"
let cols = sets.[0].Columns |> Seq.map (fun c -> c.ColumnName.Value, c.Expr.Info.Type.ToString()) |> Seq.toList
printfn "%A" cols
Assert.AreEqual(expectedColumns, cols)
let pars =
parsed.Parameters
|> Seq.map (fun (NamedParameter name, ty) -> name.Value, ty.ToString())
|> Seq.toList
printfn "%A" pars
Assert.AreEqual(expectedParams, pars)
[<Test>]
let ``coalesce forces all but last arg nullable`` () =
expect
"""
select coalesce(@a, @b, @c, @d) as c
"""
[ "c", "<scalar>"
]
[ for p in "abc" -> (string p, "<scalar>?")
yield "d", "<scalar>"
]
[<Test>]
let ``coalesce(a + b, 1)`` () =
expect
"""
select coalesce(@a + @b, 1) as c
"""
[ "c", "<numeric>"
]
[ "a", "<numeric>?"
"b", "<numeric>?"
]
[<Test>]
let ``coalesce(a + b, null)`` () =
expect
"""
select coalesce(@a + @b, null) as c
"""
[ "c", "<numeric>?"
]
[ "a", "<numeric>?"
"b", "<numeric>?"
]
[<Test>]
let ``coalesce(nullable(a) + b, 1)`` () =
expect
"""
select coalesce(nullable(@a) + @b, 1) as c
"""
[ "c", "<numeric>"
]
[ "a", "<numeric>?"
"b", "<numeric>"
]
[<Test>]
let ``coalesce(a + nullable(b), 1)`` () =
expect
"""
select coalesce(@a + nullable(@b), 1) as c
"""
[ "c", "<numeric>"
]
[ "a", "<numeric>"
"b", "<numeric>?"
]
[<Test>]
let ``case nullable`` () =
expect
"""
select case when 1=1 then 1 else null end as c
"""
[ "c", "<numeric>?"
] []
[<Test>]
let ``case not nullable`` () =
expect
"""
select case when null then 1 else 0 end as c
"""
[ "c", "<numeric>"
] []
[<Test>]
let ``case not handled means null`` () =
expect
"""
select case when 1=0 then 1 end as c
"""
[
"c", "<numeric>?"
] []
[<Test>]
let ``insert into nullable column with parameter should be nullable`` () =
expect
"""
insert into Users(Id, Name, Email)
values (@x, @y, '');
select 0 as ignore;
"""
[ "ignore", "<numeric>"
]
[ "x", "INT"
"y", "STRING?"
]
[<Test>]
let ``insert into nullable column with parameter from select should be nullable`` () =
expect
"""
insert into Users(Id, Name, Email)
select @x, @y, '';
select 0 as ignore;
"""
[ "ignore", "<numeric>"
]
[ "x", "INT"
"y", "STRING?"
]
[<Test>]
let ``update into nullable column with parameter should be nullable`` () =
expect
"""
update Users
set Id = @x
, Name = @y
where true;
select 0 as ignore;
"""
[ "ignore", "<numeric>"
]
[ "x", "INT"
"y", "STRING?"
]