Closed jkporter closed 1 month ago
I can't repro the problem. Your code above doesn't run as-is - it's always better to provide an actual, verified, minimal and runnable console program that shows the problem - that saves everyone time.
Please try the below, and tweak it to make it fail in the same way you're seeing.
@roji I've updated my original comment and provided a project attached. SqliteBugDemo.zip
Stripped-down repro:
using var connection = new SqliteConnection("Data Source=demo.sqlite;Mode=ReadWriteCreate");
connection.Open();
using var createTableCommand = connection.CreateCommand();
createTableCommand.CommandText = """
DROP TABLE IF EXISTS main.test;
CREATE TABLE main.test
(
id INTEGER NOT NULL CONSTRAINT program_pk PRIMARY KEY,
_created REAL DEFAULT (unixepoch('subsec')) NOT NULL,
_modified REAL DEFAULT (unixepoch('subsec')) NOT NULL
) STRICT;
""";
createTableCommand.ExecuteNonQuery();
using var command = connection.CreateCommand();
command.CommandText = "INSERT INTO main.test (id) VALUES (8)";
Console.WriteLine(command.CommandText);
command.ExecuteNonQuery();
Console.WriteLine("Succeed");
Note that these same SQLs work fine when executed directly against Sqlite, outside of .NET.
The problem is that Microsoft.Data.Sqlite v8.0.8
uses SQLitePCLRaw.bundle_e_sqlite3
version 2.1.6
, which has SQLite 3.41.2
and that version seems to be "ignoring" the default clause (without NOT NULL
it inserts NULL
value). Manually upgrading to 2.1.7
and hence 3.44.0
solves the problem.
As a workaround now, you can explicitly reference it using <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.7" />
(or even 2.1.9
which is latest at the moment).
I'll make sure the next version of Microsoft.Data.Sqlite
has newer/fixed version.
Result:
2.1.7
. Changing the version, specifically the downstream version of SQLite seems to be too risky, especially given it is easy to reference newer versions as show above.2.1.10
), hence the fix will be there.
SqliteBugDemo.zip
File a bug
I created a table that had columns with a default value of "(unixepoch('subsec'))". When performing INSERTs excluding these columns initially, they were causing an error because the columns were also marked as NOT NULL and after relaxing that restriction, I just had NULLs in the respective columns. I modified my INSERT include the function "unixepoch('subsec')" directly as part of the VALUES however this still resulted in NULLs.
No issues executing the SQL statements with DataGrip IDE client.
Include your code
SqliteBugDemo.zip
Sample C
Stack Trace
Include version information
Microsoft.Data.Sqlite version: 8.08 Target framework: NET 8.0 Operating system: Windows 11