-
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #557 from mathijs-dumon/OracleInsertMany
Fix for Oracle insert many
- Loading branch information
Showing
3 changed files
with
130 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using SqlKata.Compilers; | ||
using SqlKata.Tests.Infrastructure; | ||
using Xunit; | ||
|
||
namespace SqlKata.Tests.Oracle | ||
{ | ||
public class OracleInsertManyTests : TestSupport | ||
{ | ||
private const string TableName = "Table"; | ||
private readonly OracleCompiler compiler; | ||
|
||
public OracleInsertManyTests() | ||
{ | ||
compiler = Compilers.Get<OracleCompiler>(EngineCodes.Oracle); | ||
} | ||
|
||
[Fact] | ||
public void InsertManyForOracle_ShouldRepeatColumnsAndAddSelectFromDual() | ||
{ | ||
// Arrange: | ||
var cols = new[] { "Name", "Price" }; | ||
|
||
var data = new[] { | ||
new object[] { "A", 1000 }, | ||
new object[] { "B", 2000 }, | ||
new object[] { "C", 3000 }, | ||
}; | ||
|
||
var query = new Query(TableName) | ||
.AsInsert(cols, data); | ||
|
||
|
||
// Act: | ||
var ctx = compiler.Compile(query); | ||
|
||
// Assert: | ||
Assert.Equal($@"INSERT ALL INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?) INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?) INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?) SELECT 1 FROM DUAL", ctx.RawSql); | ||
} | ||
|
||
[Fact] | ||
public void InsertForOracle_SingleInsertShouldNotAddALLKeywordAndNotHaveSelectFromDual() | ||
{ | ||
// Arrange: | ||
var cols = new[] { "Name", "Price" }; | ||
|
||
var data = new[] { | ||
new object[] { "A", 1000 } | ||
}; | ||
|
||
var query = new Query(TableName) | ||
.AsInsert(cols, data); | ||
|
||
|
||
// Act: | ||
var ctx = compiler.Compile(query); | ||
|
||
// Assert: | ||
Assert.Equal($@"INSERT INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?)", ctx.RawSql); | ||
} | ||
} | ||
} |
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