|
1 | 1 | module rec OpenDiffix.Core.Expression
|
2 | 2 |
|
| 3 | +open System.Globalization |
| 4 | + |
3 | 5 | // ----------------------------------------------------------------
|
4 | 6 | // Type resolution
|
5 | 7 | // ----------------------------------------------------------------
|
@@ -88,7 +90,7 @@ let widthBucket v b t c =
|
88 | 90 |
|
89 | 91 | ((v - b) / step) |> floor |> int64 |> max -1L |> min c |> (+) 1L
|
90 | 92 |
|
91 |
| -let private doubleStyle = System.Globalization.NumberFormatInfo.InvariantInfo |
| 93 | +let private doubleStyle = NumberFormatInfo.InvariantInfo |
92 | 94 |
|
93 | 95 | /// Evaluates the result of a scalar function invocation.
|
94 | 96 | let rec evaluateScalarFunction fn args =
|
@@ -174,8 +176,14 @@ let rec evaluateScalarFunction fn args =
|
174 | 176 | else s.Substring(start - 1, min (s.Length - start + 1) length) |> String
|
175 | 177 | | Concat, [ String s1; String s2 ] -> String(s1 + s2)
|
176 | 178 |
|
177 |
| - | Cast, [ String s; String "integer" ] -> if s = "" then Null else s |> System.Int64.Parse |> Integer |
178 |
| - | Cast, [ String s; String "real" ] -> if s = "" then Null else System.Double.Parse(s, doubleStyle) |> Real |
| 179 | + | Cast, [ String s; String "integer" ] -> |
| 180 | + match System.Int64.TryParse(s) with |
| 181 | + | true, i -> Integer i |
| 182 | + | false, _ -> Null |
| 183 | + | Cast, [ String s; String "real" ] -> |
| 184 | + match System.Double.TryParse(s, NumberStyles.Float ||| NumberStyles.AllowThousands, doubleStyle) with |
| 185 | + | true, r -> Real r |
| 186 | + | false, _ -> Null |
179 | 187 | | Cast, [ String s; String "boolean" ] ->
|
180 | 188 | match s.ToLower() with
|
181 | 189 | | "true"
|
|
0 commit comments