Skip to content

Commit 6dfb257

Browse files
committed
Add support for inline parameters as CommandFragments.
An inline parameter is one that directly carries a DbType and value, instead of indexing into the command's parameter array.
1 parent d903ca2 commit 6dfb257

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/Rezoom.SQL.Compiler/BackendUtilities.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ open System.Configuration
44
open System.Data
55
open System.Data.Common
66
open System.Text
7-
open System.Globalization
8-
open System.Collections.Generic
97
open Rezoom.SQL.Mapping
108
open Rezoom.SQL.Migrations
119
open Rezoom.SQL.Compiler
@@ -29,6 +27,7 @@ let simplifyFragments (fragments : Fragments) =
2927
| Indent
3028
| Outdent
3129
| Parameter _
30+
| InlineParameter _
3231
| LocalName _ ->
3332
if builder.Length > 0 then
3433
yield CommandText <| builder.ToString()

src/Rezoom.SQL.Mapping/CommandBatch.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type private CommandBatchBuilder(conn : DbConnection, tran : DbTransaction) =
2020
static let terminator i = ";--'*/;SELECT NULL AS " + terminatorColumn i
2121
static let parameterName i = "@RZSQL_" + string i
2222
static let parameterNameArray i j = "@RZSQL_" + string i + "_" + string j
23+
static let dynamicParameterName i = "@RZSQL_INLINE_" + string i
2324
static let localName i name = "RZSQL_" + name + "_" + string i
2425
let commands = ResizeArray<Command>()
2526
let mutable parameterCount = 0
@@ -56,6 +57,10 @@ type private CommandBatchBuilder(conn : DbConnection, tran : DbTransaction) =
5657
}
5758
"(" + String.concat "," parNames + ")"
5859
| ScalarParameter _ -> parameterName (parameterOffset + i)
60+
| InlineParameter (dbType, value) ->
61+
let name = dynamicParameterName dbCommand.Parameters.Count
62+
addParam name dbType value
63+
name
5964
| Indent | Outdent -> ""
6065
| Whitespace -> " "
6166
| LineBreak -> "\n"

src/Rezoom.SQL.Mapping/CommandParts.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type CommandFragment =
1313
| CommandText of string
1414
/// References parameter by index.
1515
| Parameter of int
16+
/// Directly specifies parameter value.
17+
| InlineParameter of DbType * obj
1618
/// At least one unit of whitespace.
1719
| Whitespace
1820
/// Whitespace, preferably a line break.
@@ -33,6 +35,7 @@ type CommandFragment =
3335
| CommandText text -> Some text
3436
| Whitespace -> Some " "
3537
| Parameter i -> Some ("@P" + string i)
38+
| InlineParameter (_, p) -> Some ("@{" + string p + "}")
3639
| LineBreak ->
3740
pendingLine <- true
3841
None

0 commit comments

Comments
 (0)