When using Microsoft.Data.SQLite version 3.0.0-preview8.19405.11, it seems we can no longer insert empty blobs/byte arrays using a parameter; instead a NULL value gets inserted.
Steps to reproduce
- Create a new .NET Core 3.0 console project on Windows using .NET Core SDK 3.0.100 - preview8.
- Add
<PackageReference Include="Microsoft.Data.SQLite" Version="3.0.0-preview8.19405.11" />
- Add the following code in
Program.cs:
using System;
using System.IO;
using Microsoft.Data.Sqlite;
namespace Test
{
class Program
{
static void Main(string[] args)
{
string dbFile = "mytestdb1.db";
// Clean the file if it already exists
if (File.Exists(dbFile))
File.Delete(dbFile);
var conSb = new SqliteConnectionStringBuilder();
conSb.DataSource = dbFile;
using (var con = new SqliteConnection(conSb.ConnectionString)) {
con.Open();
using (var cmd = con.CreateCommand()) {
cmd.CommandText = "CREATE TABLE Abc(MyValue BLOB NOT NULL);";
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO Abc (MyValue) VALUES (@P1);";
var p1 = cmd.Parameters.AddWithValue("@P1", new byte[0]);
cmd.ExecuteNonQuery();
}
}
}
}
}
Expected behavior: No exception occurs; a row is inserted containing an empty blob.
Actual behavior:
Exception message: Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 19: 'NOT NULL constraint failed: Abc.Col2'.
Stack trace:
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
at Test.Program.Main(String[] args) in C:\Users\developer4\Desktop\DebugMicrosoftSqlite\Program.cs:line 30
This problem doesn't occur when using version 2.2.6 of Microsoft.Data.SQLite. The problem also doesn't occur when using a byte array with length 1 or higher.
Further technical details
EF Core version: 3.0.0-preview8.19405.11
Database Provider: Microsoft.Data.SQLite
Operating system: Windows 10 Version 1903 x64
IDE: Visual Studio 2019 16.2.3
When using
Microsoft.Data.SQLiteversion3.0.0-preview8.19405.11, it seems we can no longer insert empty blobs/byte arrays using a parameter; instead a NULL value gets inserted.Steps to reproduce
<PackageReference Include="Microsoft.Data.SQLite" Version="3.0.0-preview8.19405.11" />Program.cs:Expected behavior: No exception occurs; a row is inserted containing an empty blob.
Actual behavior:
Exception message:
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 19: 'NOT NULL constraint failed: Abc.Col2'.Stack trace:
This problem doesn't occur when using version
2.2.6ofMicrosoft.Data.SQLite. The problem also doesn't occur when using a byte array with length 1 or higher.Further technical details
EF Core version: 3.0.0-preview8.19405.11
Database Provider: Microsoft.Data.SQLite
Operating system: Windows 10 Version 1903 x64
IDE: Visual Studio 2019 16.2.3