diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs b/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs index c9eabf0bc27..4d98d243e7a 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Numerics; using Microsoft.Data.Sqlite.Properties; namespace Microsoft.Data.Sqlite; @@ -238,6 +239,20 @@ public virtual void Bind() var value1 = (long)(ushort)value; BindInt64(value1); } + else if (type == typeof(BigInteger)) + { + BindText(((BigInteger)value).ToString(CultureInfo.InvariantCulture)); + } +#if NET7_0_OR_GREATER + else if (type == typeof(Int128)) + { + BindText(((Int128)value).ToString(CultureInfo.InvariantCulture)); + } + else if (type == typeof(UInt128)) + { + BindText(((UInt128)value).ToString(CultureInfo.InvariantCulture)); + } +#endif else { throw new InvalidOperationException(Resources.UnknownDataType(type)); @@ -259,7 +274,13 @@ public virtual void Bind() { typeof(DateOnly), SqliteType.Text }, { typeof(TimeOnly), SqliteType.Text }, #endif + { typeof(DBNull), SqliteType.Text }, + { typeof(BigInteger), SqliteType.Text }, +#if NET7_0_OR_GREATER + { typeof(Int128), SqliteType.Text }, + { typeof(UInt128), SqliteType.Text }, +#endif { typeof(decimal), SqliteType.Text }, { typeof(double), SqliteType.Real }, { typeof(float), SqliteType.Real }, diff --git a/test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs b/test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs index cc5f4a314a6..f569abb4d60 100644 --- a/test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs +++ b/test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Data; using System.Data.Common; +using System.Numerics; using Microsoft.Data.Sqlite.Properties; using Microsoft.Data.Sqlite.TestUtilities; using Xunit; @@ -588,6 +589,54 @@ public void Add_range_of_parameters_using_DbCommand_base_class() } } + [Fact] + public void Bind_BigInteger_parameter_as_text() + { + using (var connection = new SqliteConnection("Data Source=:memory:")) + { + var command = connection.CreateCommand(); + command.CommandText = "SELECT @Parameter;"; + var value = BigInteger.Parse("1234567890123456789012345678901234567890"); + command.Parameters.AddWithValue("@Parameter", value); + connection.Open(); + var result = (string)command.ExecuteScalar()!; + Assert.Equal("1234567890123456789012345678901234567890", result); + } + } + + +#if NET7_0_OR_GREATER + [Fact] + public void Bind_Int128_parameter_as_text() + { + using (var connection = new SqliteConnection("Data Source=:memory:")) + { + var command = connection.CreateCommand(); + command.CommandText = "SELECT @Parameter;"; + var value = Int128.Parse("170141183460469231731687303715884105727"); + command.Parameters.AddWithValue("@Parameter", value); + connection.Open(); + var result = (string)command.ExecuteScalar()!; + Assert.Equal("170141183460469231731687303715884105727", result); + } + } + + [Fact] + public void Bind_UInt128_parameter_as_text() + { + using (var connection = new SqliteConnection("Data Source=:memory:")) + { + var command = connection.CreateCommand(); + command.CommandText = "SELECT @Parameter;"; + var value = UInt128.Parse("340282366920938463463374607431768211455"); + command.Parameters.AddWithValue("@Parameter", value); + connection.Open(); + var result = (string)command.ExecuteScalar()!; + Assert.Equal("340282366920938463463374607431768211455", result); + } + } +#endif + public static IEnumerable TypesData => new List {