-
-
Notifications
You must be signed in to change notification settings - Fork 61
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 #58 from IvaYan/extened-types
All integers, decimal & guid
- Loading branch information
Showing
8 changed files
with
428 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Globalization; | ||
using DuckDB.NET.Data; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace DuckDB.NET.Test.Parameters; | ||
|
||
public class DecimalParameterTests | ||
{ | ||
[Fact] | ||
public void SimpleTest() | ||
{ | ||
using var connection = new DuckDBConnection("DataSource=:memory:"); | ||
connection.Open(); | ||
|
||
var values = new []{0m, decimal.Zero, decimal.MinValue, | ||
decimal.MaxValue, decimal.MaxValue / 3, decimal.One, | ||
decimal.One / 2, decimal.One / 3, decimal.MinusOne, | ||
decimal.MinusOne / 2, decimal.MinusOne / 3}; | ||
|
||
foreach (var value in values) | ||
{ | ||
var command = connection.CreateCommand(); | ||
command.CommandText = $"SELECT '{value}';"; | ||
command.ExecuteNonQuery(); | ||
|
||
var scalar = command.ExecuteScalar(); | ||
scalar.Should().Be(value.ToString(CultureInfo.InvariantCulture)); | ||
|
||
var reader = command.ExecuteReader(); | ||
reader.Read(); | ||
var receivedValue = reader.GetDecimal(0); | ||
receivedValue.Should().Be(value); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void BindValueTest() | ||
{ | ||
using var connection = new DuckDBConnection("DataSource=:memory:"); | ||
connection.Open(); | ||
|
||
var values = new []{0m, decimal.Zero, decimal.MinValue, | ||
decimal.MaxValue, decimal.MaxValue / 3, decimal.One, | ||
decimal.One / 2, decimal.One / 3, decimal.MinusOne, | ||
decimal.MinusOne / 2, decimal.MinusOne / 3}; | ||
|
||
foreach (var value in values) | ||
{ | ||
var command = connection.CreateCommand(); | ||
command.CommandText = "SELECT ?;"; | ||
command.Parameters.Add(new DuckDBParameter(value)); | ||
command.ExecuteNonQuery(); | ||
|
||
var scalar = command.ExecuteScalar(); | ||
scalar.Should().Be(value.ToString(CultureInfo.InvariantCulture)); | ||
|
||
var reader = command.ExecuteReader(); | ||
reader.Read(); | ||
var receivedValue = reader.GetDecimal(0); | ||
receivedValue.Should().Be(value); | ||
} | ||
} | ||
} |
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,58 @@ | ||
using System; | ||
using DuckDB.NET.Data; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace DuckDB.NET.Test.Parameters; | ||
|
||
public class GuidParameterTests | ||
{ | ||
[Fact] | ||
public void SimpleTest() | ||
{ | ||
using var connection = new DuckDBConnection("DataSource=:memory:"); | ||
connection.Open(); | ||
|
||
var guids = new[] { Guid.NewGuid(), Guid.Empty }; | ||
|
||
foreach (var guid in guids) | ||
{ | ||
var command = connection.CreateCommand(); | ||
command.CommandText = $"SELECT '{guid}';"; | ||
command.ExecuteNonQuery(); | ||
|
||
var scalar = command.ExecuteScalar(); | ||
scalar.Should().Be(guid.ToString()); | ||
|
||
var reader = command.ExecuteReader(); | ||
reader.Read(); | ||
var receivedValue = reader.GetGuid(0); | ||
receivedValue.Should().Be(guid); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void BindValueTest() | ||
{ | ||
using var connection = new DuckDBConnection("DataSource=:memory:"); | ||
connection.Open(); | ||
|
||
var guids = new[] { Guid.NewGuid(), Guid.Empty }; | ||
|
||
foreach (var guid in guids) | ||
{ | ||
var command = connection.CreateCommand(); | ||
command.CommandText = "SELECT ?;"; | ||
command.Parameters.Add(new DuckDBParameter(guid)); | ||
command.ExecuteNonQuery(); | ||
|
||
var scalar = command.ExecuteScalar(); | ||
scalar.Should().Be(guid.ToString()); | ||
|
||
var reader = command.ExecuteReader(); | ||
reader.Read(); | ||
var receivedValue = reader.GetGuid(0); | ||
receivedValue.Should().Be(guid); | ||
} | ||
} | ||
} |
Oops, something went wrong.