|
5 | 5 | using System.Collections.Generic; |
6 | 6 | using System.Data; |
7 | 7 | using System.Data.Common; |
| 8 | +using System.Numerics; |
8 | 9 | using Microsoft.Data.Sqlite.Properties; |
9 | 10 | using Microsoft.EntityFrameworkCore.TestUtilities.Xunit; |
10 | 11 | using Xunit; |
@@ -588,6 +589,86 @@ public void Add_range_of_parameters_using_DbCommand_base_class() |
588 | 589 | } |
589 | 590 | } |
590 | 591 |
|
| 592 | +#if NET7_0_OR_GREATER |
| 593 | + [Fact] |
| 594 | + public void Bind_UInt128_zero_as_text() |
| 595 | + { |
| 596 | + using (var connection = new SqliteConnection("Data Source=:memory:")) |
| 597 | + { |
| 598 | + var command = connection.CreateCommand(); |
| 599 | + command.CommandText = "SELECT @Parameter;"; |
| 600 | + var value = (UInt128)0; |
| 601 | + command.Parameters.AddWithValue("@Parameter", value); |
| 602 | + connection.Open(); |
| 603 | + var result = (string)command.ExecuteScalar()!; |
| 604 | + Assert.Equal("000000000000000000000000000000000000000", result); |
| 605 | + } |
| 606 | + } |
| 607 | + |
| 608 | + [Fact] |
| 609 | + public void Bind_UInt128_max_value_as_text() |
| 610 | + { |
| 611 | + using (var connection = new SqliteConnection("Data Source=:memory:")) |
| 612 | + { |
| 613 | + var command = connection.CreateCommand(); |
| 614 | + command.CommandText = "SELECT @Parameter;"; |
| 615 | + var value = UInt128.MaxValue; |
| 616 | + command.Parameters.AddWithValue("@Parameter", value); |
| 617 | + connection.Open(); |
| 618 | + var result = (string)command.ExecuteScalar()!; |
| 619 | + Assert.Equal("340282366920938463463374607431768211455", result); |
| 620 | + } |
| 621 | + } |
| 622 | + |
| 623 | + [Fact] |
| 624 | + public void Bind_UInt128_ordering_works() |
| 625 | + { |
| 626 | + using (var connection = new SqliteConnection("Data Source=:memory:")) |
| 627 | + { |
| 628 | + connection.Open(); |
| 629 | + |
| 630 | + var command = connection.CreateCommand(); |
| 631 | + command.CommandText = """ |
| 632 | + CREATE TABLE TestOrdering (Value TEXT); |
| 633 | + INSERT INTO TestOrdering VALUES (@A); |
| 634 | + INSERT INTO TestOrdering VALUES (@B); |
| 635 | + INSERT INTO TestOrdering VALUES (@C); |
| 636 | + SELECT Value FROM TestOrdering ORDER BY Value; |
| 637 | + """; |
| 638 | + command.Parameters.AddWithValue("@A", (UInt128)500); |
| 639 | + command.Parameters.AddWithValue("@B", UInt128.MaxValue); |
| 640 | + command.Parameters.AddWithValue("@C", (UInt128)1); |
| 641 | + |
| 642 | + var results = new List<string>(); |
| 643 | + using var reader = command.ExecuteReader(); |
| 644 | + while (reader.Read()) |
| 645 | + { |
| 646 | + results.Add(reader.GetString(0)); |
| 647 | + } |
| 648 | + |
| 649 | + Assert.Equal(3, results.Count); |
| 650 | + Assert.Equal("000000000000000000000000000000000000001", results[0]); |
| 651 | + Assert.Equal("000000000000000000000000000000000000500", results[1]); |
| 652 | + Assert.Equal("340282366920938463463374607431768211455", results[2]); |
| 653 | + } |
| 654 | + } |
| 655 | + |
| 656 | + [Fact] |
| 657 | + public void Bind_UInt128_concatenation_works() |
| 658 | + { |
| 659 | + using (var connection = new SqliteConnection("Data Source=:memory:")) |
| 660 | + { |
| 661 | + var command = connection.CreateCommand(); |
| 662 | + command.CommandText = "SELECT @Parameter || '_suffix';"; |
| 663 | + var value = (UInt128)42; |
| 664 | + command.Parameters.AddWithValue("@Parameter", value); |
| 665 | + connection.Open(); |
| 666 | + var result = (string)command.ExecuteScalar()!; |
| 667 | + Assert.Equal("000000000000000000000000000000000000042_suffix", result); |
| 668 | + } |
| 669 | + } |
| 670 | +#endif |
| 671 | + |
591 | 672 | public static IEnumerable<object[]> TypesData |
592 | 673 | => new List<object[]> |
593 | 674 | { |
|
0 commit comments