-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port bulk copy tests from devdiv (#1177)
- Loading branch information
Johnny Pham
authored
Aug 4, 2021
1 parent
ba2dbfe
commit df9990c
Showing
10 changed files
with
217 additions
and
70 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
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
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
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
49 changes: 49 additions & 0 deletions
49
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/KeepNulls.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,49 @@ | ||
// 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.Data; | ||
|
||
namespace Microsoft.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
class KeepNulls | ||
{ | ||
public static void Test(string srcconstr, string dstconstr, string srctable, string dsttable) | ||
{ | ||
using SqlConnection destConn = new(dstconstr); | ||
destConn.Open(); | ||
|
||
using SqlCommand dstcmd = destConn.CreateCommand(); | ||
Helpers.TryExecute(dstcmd, "create table " + srctable + " (col1 int, col2 text, col3 text)"); | ||
Helpers.TryExecute(dstcmd, "insert into " + srctable + "(col1, col3) values (1, 'Michael')"); | ||
Helpers.TryExecute(dstcmd, "insert into " + srctable + "(col1, col2, col3) values (2, 'Quark', 'Astrid')"); | ||
Helpers.TryExecute(dstcmd, "insert into " + srctable + "(col1, col2) values (66, 'K�se');"); | ||
|
||
Helpers.TryExecute(dstcmd, "create table " + dsttable + " (col1 int identity(1,1), col2 text default 'Jogurt', col3 text)"); | ||
|
||
using SqlConnection sourceConn = new(srcconstr); | ||
sourceConn.Open(); | ||
|
||
using SqlCommand srccmd = new("select * from " + srctable, sourceConn); | ||
using IDataReader reader = srccmd.ExecuteReader(); | ||
|
||
try | ||
{ | ||
using SqlBulkCopy bulkcopy = new(destConn, SqlBulkCopyOptions.KeepNulls, null); | ||
bulkcopy.DestinationTableName = dsttable; | ||
SqlBulkCopyColumnMappingCollection ColumnMappings = bulkcopy.ColumnMappings; | ||
ColumnMappings.Add("col1", "col1"); | ||
ColumnMappings.Add("col2", "col2"); | ||
ColumnMappings.Add("col3", "col3"); | ||
|
||
bulkcopy.WriteToServer(reader); | ||
Helpers.VerifyResults(destConn, dsttable, 3, 3); | ||
} | ||
finally | ||
{ | ||
Helpers.TryDropTable(dstconstr, srctable); | ||
Helpers.TryDropTable(dstconstr, dsttable); | ||
} | ||
} | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/TableLock.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,48 @@ | ||
// 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.Data; | ||
|
||
namespace Microsoft.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
class TableLock | ||
{ | ||
public static void Test(string srcconstr, string dstconstr, string srctable, string dsttable) | ||
{ | ||
using SqlConnection destConn = new(dstconstr); | ||
destConn.Open(); | ||
|
||
using SqlCommand dstcmd = destConn.CreateCommand(); | ||
Helpers.TryExecute(dstcmd, "create table " + srctable + " (col1 int, col2 text, col3 text)"); | ||
Helpers.TryExecute(dstcmd, "insert into " + srctable + "(col1, col3) values (1, 'Michael')"); | ||
Helpers.TryExecute(dstcmd, "insert into " + srctable + "(col1, col2, col3) values (2, 'Quark', 'Astrid')"); | ||
Helpers.TryExecute(dstcmd, "insert into " + srctable + "(col1, col2) values (66, 'K�se');"); | ||
|
||
Helpers.TryExecute(dstcmd, "create table " + dsttable + " (col1 int identity(1,1), col2 text default 'Jogurt', col3 text)"); | ||
|
||
using SqlConnection sourceConn = new(srcconstr); | ||
sourceConn.Open(); | ||
|
||
using SqlCommand srccmd = new SqlCommand("select * from " + srctable, sourceConn); | ||
using IDataReader reader = srccmd.ExecuteReader(); | ||
try | ||
{ | ||
using SqlBulkCopy bulkcopy = new(destConn, SqlBulkCopyOptions.TableLock, null); | ||
bulkcopy.DestinationTableName = dsttable; | ||
SqlBulkCopyColumnMappingCollection ColumnMappings = bulkcopy.ColumnMappings; | ||
ColumnMappings.Add("col1", "col1"); | ||
ColumnMappings.Add("col2", "col2"); | ||
ColumnMappings.Add("col3", "col3"); | ||
|
||
bulkcopy.WriteToServer(reader); | ||
Helpers.VerifyResults(destConn, dsttable, 3, 3); | ||
} | ||
finally | ||
{ | ||
Helpers.TryDropTable(dstconstr, srctable); | ||
Helpers.TryDropTable(dstconstr, dsttable); | ||
} | ||
} | ||
} | ||
} |
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