forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SqlClient: Fix BulkCopy double and single null widening handling (dot…
…net/corefx#37603) * change BulkCopy double and single handling to handle Null values when converting to decimal without throwing and add tests * address feedback Commit migrated from dotnet/corefx@97ddad9
- Loading branch information
1 parent
6a988c7
commit 7356b91
Showing
4 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...stem.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyWidenNullInexactNumerics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace System.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
public class CopyWidenNullInexactNumerics | ||
{ | ||
public static void Test(string sourceDatabaseConnectionString, string destinationDatabaseConnectionString) | ||
{ | ||
// this test copies float and real inexact numeric types into decimal targets using bulk copy to check that the widening of the type succeeds. | ||
|
||
using (var sourceConnection = new SqlConnection(sourceDatabaseConnectionString)) | ||
using (var destinationConnection = new SqlConnection(destinationDatabaseConnectionString)) | ||
{ | ||
sourceConnection.Open(); | ||
destinationConnection.Open(); | ||
|
||
RunCommands(sourceConnection, | ||
new[] | ||
{ | ||
"drop table if exists dbo.__SqlBulkCopyBug_Source", | ||
"create table dbo.__SqlBulkCopyBug_Source (floatVal float null, realVal real null)", | ||
"insert dbo.__SqlBulkCopyBug_Source(floatVal,realVal) values(1,1),(2,2),(null,null),(0.00000000000001,0.00000000000001)" | ||
} | ||
); | ||
|
||
RunCommands(destinationConnection, | ||
new[] | ||
{ | ||
"drop table if exists dbo.__SqlBulkCopyBug_Destination", | ||
"create table dbo.__SqlBulkCopyBug_Destination (floatVal decimal(18,10) null,realVal decimal(18,10) null)" | ||
} | ||
); | ||
|
||
Exception error = null; | ||
try | ||
{ | ||
var bulkCopy = new SqlBulkCopy(destinationConnection, SqlBulkCopyOptions.Default, null); | ||
bulkCopy.DestinationTableName = "dbo.__SqlBulkCopyBug_Destination"; | ||
using (var sourceCommand = new SqlCommand("select * from dbo.__SqlBulkCopyBug_Source", sourceConnection, null)) | ||
using (var sourceReader = sourceCommand.ExecuteReader()) | ||
{ | ||
bulkCopy.WriteToServer(sourceReader); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
error = ex; | ||
} | ||
finally | ||
{ | ||
try | ||
{ | ||
RunCommands(sourceConnection, | ||
new[] | ||
{ | ||
"drop table if exists dbo.__SqlBulkCopyBug_Source", | ||
"drop table if exists dbo.__SqlBulkCopyBug_Destination", | ||
} | ||
); | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
|
||
Assert.Null(error); | ||
} | ||
} | ||
|
||
public static void RunCommands(SqlConnection connection, IEnumerable<string> commands) | ||
{ | ||
using (var sqlCommand = connection.CreateCommand()) | ||
{ | ||
foreach (var command in commands) | ||
{ | ||
Helpers.TryExecute(sqlCommand, command); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters