-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong ErrorCode reported by SqliteException #27597
Comments
Also, if I explicitly set the parameter size to zero I get the command.CommandText = @"INSERT INTO ""Products"" (""Name"") VALUES (@p0);";
command.Parameters.Add("@p0", SqliteType.Text, 0);
command.Parameters[0].Value = new string('A', 15); |
The error code is |
@Giorgi Are you using the same version of the native SQLite library and the PCLraw package in both cases? Or are these also changing with EF version? |
@ajcvickers I use the version that the Microsoft.Data.SQLite pulls as a dependency but I'm pretty sure that this isn't caused by SQLite because when I tried to reproduce it with plain ADO.NET with the version of To summarize, the behavior does not change when using plain ADO.NET between the old version and new version of Microsoft.Data.SQLite. The behavior only changes depending how I set parameter or when I upgrade between EF Core versions |
I tried doing running the same ado.net code with System.Data.SQLite.Core and I get var connection = new SQLiteConnection("Data Source=sqlite_test.db;");
connection.Open();
var command = connection.CreateCommand();
command.CommandText = @"CREATE TABLE ""Products"" (
""Id"" INTEGER NOT NULL CONSTRAINT ""PK_Products"" PRIMARY KEY AUTOINCREMENT,
""Name"" TEXT NOT NULL
);";
command.ExecuteNonQuery();
connection.SetLimitOption(SQLiteLimitOpsEnum.SQLITE_LIMIT_LENGTH, 10);
command.CommandText = @"INSERT INTO ""Products"" (""Name"") VALUES (@p0);";
command.Parameters.Add("@p0", DbType.String);
command.Parameters[0].Value = new string('A', 15);
try
{
command.ExecuteReader();
}
catch (SQLiteException ex)
{
Console.WriteLine($"Sqlite error: {ex.ErrorCode} ");
}
finally
{
connection.Close();
} This results in SQLite error: 18 If I do the same with Microsoft.Data.Sqlite.Core I get |
@bricelam Any update on this bug? |
I haven't looked into it yet. I'm focusing on my 7.0 enhancements right now. Will shift my focus to bugs closer to the end of the release. |
* Microsoft.Data.Sqlite: Check error code when binding parameters Fixes #27597 * Use reflection to call into PCLraw * Call into PCLraw directly.
When using
sqlite3_limit
to limit length of string or blob (SQLITE_LIMIT_LENGTH
from https://www.sqlite.org/c3ref/c_limit_attached.html) and running an insert statement with value larger than the limit, theSqliteException
has wrongSqliteErrorCode
andSqliteExtendedErrorCode
Include your code
This prints 19 and 1299 (
SQLITE_CONSTRAINT
andSQLITE_CONSTRAINT_NOTNULL
respectively) instead of printing 18 and 18 (SQLITE_TOOBIG
)If I put the value directly in the SQL statement the correct error code is reported:
command.CommandText = @"INSERT INTO ""Products"" (""Name"") VALUES ('AAAAAAAAAAAAAAA');";
Also, when using EF Core and SQLite together the behavior in EF Core 3.1.1 and Microsoft.Data.SQLite was that the insert statement was failing with the correct error code (
SQLITE_TOOBIG
). I have a unit test that verifies that behavior: https://github.com/Giorgi/EntityFramework.Exceptions/blob/main/EntityFramework.Exceptions.Tests/SqliteTests.cs#L24 but the test fails when I upgrade to EF Core 6. Did the interaction between EF Core and SQLite provider change so drasticly between these versions that result in the new behavior? For example, did the EF Core 3 not use parameterized insert statements or is there a change in the way parameters are passed to the SQLite driver?Finally, the SQLite shell works as expected:
Version information
Microsoft.Data.Sqlite version: 6.0.3
Target framework: .Net 6
Operating system: Windows
The text was updated successfully, but these errors were encountered: