Skip to content

Commit 0fa30cb

Browse files
committed
Add RawSQLParameter union case.
1 parent 6677b0a commit 0fa30cb

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/Rezoom.SQL.Mapping/CommandBatch.fs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ type private CommandBatchBuilder(conn : DbConnection, tran : DbTransaction) =
4343
j <- j + 1
4444
| ScalarParameter(parameterType, o) ->
4545
addParam (parameterName (parameterOffset + i)) parameterType o
46-
for fragment in command.Fragments do
46+
| RawSQLParameter _ -> ()
47+
let rec addFragment fragment =
4748
let fragmentString =
4849
match fragment with
4950
| LocalName name -> localName commandIndex name
@@ -57,6 +58,10 @@ type private CommandBatchBuilder(conn : DbConnection, tran : DbTransaction) =
5758
}
5859
"(" + String.concat "," parNames + ")"
5960
| ScalarParameter _ -> parameterName (parameterOffset + i)
61+
| RawSQLParameter frags ->
62+
for frag in frags do
63+
addFragment frag
64+
""
6065
| InlineParameter (dbType, value) ->
6166
let name = dynamicParameterName dbCommand.Parameters.Count
6267
addParam name dbType value
@@ -65,6 +70,8 @@ type private CommandBatchBuilder(conn : DbConnection, tran : DbTransaction) =
6570
| Whitespace -> " "
6671
| LineBreak -> "\n"
6772
ignore <| builder.Append(fragmentString)
73+
for fragment in command.Fragments do
74+
addFragment fragment
6875
match command.ResultSetCount with
6976
| Some _ -> () // no need to add terminator statement
7077
| None when commandIndex + 1 >= commands.Count -> ()
@@ -78,12 +85,22 @@ type private CommandBatchBuilder(conn : DbConnection, tran : DbTransaction) =
7885
dbCommand.CommandText <- builder.ToString()
7986

8087
member __.BatchCommand(cmd : Command) =
81-
let mutable count = 0
88+
let countInlineParameters fragments =
89+
let mutable i = 0
90+
for fragment in fragments do
91+
match fragment with
92+
| InlineParameter _ -> i <- i + 1
93+
| _ -> ()
94+
i
95+
96+
let mutable count = countInlineParameters cmd.Fragments
8297
for par in cmd.Parameters do
8398
count <- count +
8499
match par with
85100
| ListParameter (_, os) -> os.Length
86101
| ScalarParameter _ -> 1
102+
| RawSQLParameter frags -> countInlineParameters frags
103+
87104
if parameterCount + count > maxParameters then
88105
Nullable()
89106
else

src/Rezoom.SQL.Mapping/CommandParts.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type CommandCategory = CommandCategory of connectionName : string
9191
type CommandParameter =
9292
| ListParameter of DbType * Array
9393
| ScalarParameter of DbType * obj
94+
| RawSQLParameter of CommandFragment list
9495
member this.Equals(other : CommandParameter) =
9596
match this, other with
9697
| ListParameter (ty1, arr1), ListParameter (ty2, arr2) ->
@@ -108,6 +109,8 @@ type CommandParameter =
108109
| ScalarParameter (ty1, obj1), ScalarParameter (ty2, obj2) ->
109110
ty1 = ty2 && EqualityComparer<obj>.Default.Equals(obj1, obj2)
110111

112+
| RawSQLParameter frags1, RawSQLParameter frags2 -> frags1 = frags2
113+
111114
| _ -> false
112115
override this.Equals(other : obj) =
113116
match other with
@@ -122,6 +125,9 @@ type CommandParameter =
122125
h <- ((h <<< 5) + h) ^^^ hash ty
123126
for o in os do
124127
h <- ((h <<< 5) + h) ^^^ hash o
128+
| RawSQLParameter frags ->
129+
for frag in frags do
130+
h <- ((h <<< 5) + h) ^^^ hash frag
125131
h
126132
interface IEquatable<CommandParameter> with
127133
member this.Equals(other) = this.Equals(other)

0 commit comments

Comments
 (0)