Skip to content

Commit b75cfc7

Browse files
authored
Fix high precision printing
1 parent a0d7f11 commit b75cfc7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/SqlClient/ISqlCommand.fs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
147147
sprintf "%s %A(%d)" p.ParameterName p.SqlDbType p.Size
148148
else
149149
sprintf "%s %A" p.ParameterName p.SqlDbType
150+
151+
// helper map to resolve each parameter's target type
152+
let getSqlDbType name =
153+
let lookup = Map.ofSeq <| Seq.zip (parameters |> Seq.map (fun p -> p.name))
154+
(cmd.Parameters |> Seq.map (fun p -> p.SqlDbType))
155+
Map.find name lookup
156+
150157
seq {
151158

152159
yield sprintf "exec sp_executesql N'%s'" (cmd.CommandText.Replace("'", "''"))
@@ -169,10 +176,11 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
169176
| nonNullValue ->
170177
let printedValue =
171178
match nonNullValue with
172-
// print dates with timezone in roundtrip ISO8601 format "O"
179+
// print dates with high precision (SQL datetimeoffset, datetime2) in roundtrip ISO8601 format "O"
173180
| :? System.DateTimeOffset as d -> d.ToString("O")
174-
// print dates without timezones in legacy SQL Server format
175-
| :? System.DateTime as d -> d.ToString("yyyy-MM-ddTHH:mm:ss.fff")
181+
| :? System.DateTime as d when getSqlDbType d = SqlDbType.DateTime2 -> d.ToString("O")
182+
// print dates with low precision (SQL datetime) in legacy format
183+
| :? System.DateTime as d when getSqlDbType d <> SqlDbType.DateTime2 -> d.ToString("yyyy-MM-ddTHH:mm:ss.fff")
176184
// print timespans in constant format "c
177185
| :? System.TimeSpan as t -> t.ToString("c")
178186
// print numeric values in culture-invariant format

0 commit comments

Comments
 (0)