DataTable.Load() fails when joining SQLite tables with UNIQUE constraint #30765
Labels
area-adonet-sqlite
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
When using the
DataTable.Load()
method to load data from a SQLite query with aLEFT JOIN
on a column with aUNIQUE
constraint, an error is thrown. The error message is "Column 'guildId' is constrained to be unique. Value '1' is already present." even though the join operation should not enforce the unique constraint on the joined columns.To reproduce the issue, consider the following SQLite schema and data:
And the following pseudo C# code using Microsoft.Data.Sqlite:
Expected behavior is to receive two rows of data:
Actual behavior:
The line
dt.Load(reader)
throws an exception: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.If you wrap the last line into a try-catch and add a breakpoint in the catch statement, then going into the Command Window and typing
? dt.GetErrors()[1].RowError
would produce an explanation: "Column 'guildName' is constrained to be unique. Value 'Testers' is already present."The UNIQUE constraint is meant to enforce uniqueness on the data stored in the table, not on the results of join operations. As such, the join operation should not enforce the unique constraint on the
DataTable
. Furthermore, executing the same code with MySqlConnector produces desired result. And other software such as DB Browser for SQLite doesn't exhibit the problem, either.Microsoft.Data.Sqlite version: 7.0.5
Target framework: .NET 6.0
Operating system: Windows 11
The text was updated successfully, but these errors were encountered: