Skip to content

Commit 84e662f

Browse files
Vasily KirichenkoVasily Kirichenko
authored andcommitted
ISqlCommand Implementation.Dispose disposes cmd.Connection if it's created in the ctor
target .NET 4.6.2 reference FSharp.Core and FSharp.Compiler.Tools via NuGet
1 parent e818907 commit 84e662f

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

src/SqlClient/DesignTime.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ open System.Diagnostics
1010
open Microsoft.FSharp.Quotations
1111
open ProviderImplementation.ProvidedTypes
1212
open FSharp.Data
13+
open FSharp.Data.SqlClient.Extensions
1314

1415
type internal RowType = {
1516
Provided: Type

src/SqlClient/ISqlCommand.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type internal Connection = Choice<string, SqlConnection, SqlTransaction>
5858
type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connection, commandTimeout) =
5959

6060
let cmd = new SqlCommand(cfg.SqlStatement, CommandTimeout = commandTimeout)
61+
6162
let manageConnection =
6263
match connection with
6364
| Choice1Of3 connectionString ->
@@ -73,7 +74,7 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
7374

7475
do
7576
cmd.CommandType <- if cfg.IsStoredProcedure then CommandType.StoredProcedure else CommandType.Text
76-
cmd.Parameters.AddRange( cfg.Parameters)
77+
cmd.Parameters.AddRange(cfg.Parameters)
7778

7879
let getReaderBehavior() =
7980
seq {
@@ -169,6 +170,8 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
169170

170171
interface IDisposable with
171172
member this.Dispose() =
173+
if manageConnection then
174+
cmd.Connection.Dispose()
172175
cmd.Dispose()
173176

174177
static member internal SetParameters(cmd: SqlCommand, parameters: (string * obj)[]) =
@@ -305,9 +308,9 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
305308
assert (rank = ResultRank.Sequence)
306309
box xs
307310

308-
static member internal ExecuteNonQuery manageConnection (cmd, _, parameters, _) =
311+
static member internal ExecuteNonQuery (manageConnection: bool) (cmd, _, parameters, _) =
309312
``ISqlCommand Implementation``.SetParameters(cmd, parameters)
310-
use openedConnection = cmd.Connection.UseLocally(manageConnection )
313+
use openedConnection = cmd.Connection.UseLocally(manageConnection)
311314
let recordsAffected = cmd.ExecuteNonQuery()
312315
for i = 0 to parameters.Length - 1 do
313316
let name, _ = parameters.[i]

src/SqlClient/ProvidedTypes.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ module internal Misc =
494494
else
495495
Some (args.[1], args.[1])
496496
)
497-
|> Seq.nth (n - 1)
497+
|> Seq.item (n - 1)
498498

499499
let adaptMethod = getFastFuncType args resultType
500500
let adapted = E.Call(adaptMethod, [loop applicable])

src/SqlClient/SqlClient.fsproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\packages\FSharp.Compiler.Tools.10.0.1\build\FSharp.Compiler.Tools.props" Condition="Exists('..\..\packages\FSharp.Compiler.Tools.10.0.1\build\FSharp.Compiler.Tools.props')" />
34
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
45
<PropertyGroup>
56
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -9,7 +10,7 @@
910
<OutputType>Library</OutputType>
1011
<RootNamespace>SqlCommandTypeProvider</RootNamespace>
1112
<AssemblyName>FSharp.Data.SqlClient</AssemblyName>
12-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1314
<Name>SqlClient</Name>
1415
<TargetFrameworkProfile />
1516
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
@@ -51,7 +52,8 @@
5152
<OtherFlags>--warnon:1182</OtherFlags>
5253
</PropertyGroup>
5354
<ItemGroup>
54-
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
55+
<Reference Include="FSharp.Core, Version=4.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
56+
<HintPath>..\..\packages\FSharp.Core.4.3.4\lib\net45\FSharp.Core.dll</HintPath>
5557
<Private>True</Private>
5658
</Reference>
5759
<Reference Include="Microsoft.SqlServer.TransactSql.ScriptDom">
@@ -114,6 +116,7 @@
114116
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
115117
</PropertyGroup>
116118
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
119+
<Error Condition="!Exists('..\..\packages\FSharp.Compiler.Tools.10.0.1\build\FSharp.Compiler.Tools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\FSharp.Compiler.Tools.10.0.1\build\FSharp.Compiler.Tools.props'))" />
117120
</Target>
118121
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
119122
Other similar extension points exist, see Microsoft.Common.targets.

src/SqlClient/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="FSharp.Compiler.Tools" version="10.0.1" targetFramework="net462" />
4+
<package id="FSharp.Core" version="4.3.4" targetFramework="net462" />
35
<package id="FSharp.TypeProviders.StarterPack" version="1.1.3.72" targetFramework="net40" />
46
</packages>

0 commit comments

Comments
 (0)