Posts

Showing posts with the label Sqlite

Android SQLite Auto Increment

Answer : Make it INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL . Here's what the docs say: If a column has the type INTEGER PRIMARY KEY AUTOINCREMENT then... the ROWID chosen for the new row is at least one larger than the largest ROWID that has ever before existed in that same table. The behavior implemented by the AUTOINCREMENT keyword is subtly different from the default behavior. With AUTOINCREMENT, rows with automatically selected ROWIDs are guaranteed to have ROWIDs that have never been used before by the same table in the same database. And the automatically generated ROWIDs are guaranteed to be monotonically increasing. SQLite AUTOINCREMENT is a keyword used for auto incrementing a value of a field in the table. We can auto increment a field value by using AUTOINCREMENT keyword when creating a table with specific column name to auto incrementing it. The keyword AUTOINCREMENT can be used with INTEGER field only. Syntax: The basic usage of AU...

ASP.NET Core Testing - Get NullReferenceException When Initializing InMemory SQLite Dbcontext In Fixture

Answer : I encountered this problem while trying to do EF Core scaffolding for an Sqlite database. The problem was that I had installed Microsoft.EntityFrameworkCore.Sqlite.Core rather than Microsoft.EntityFrameworkCore.Sqlite . I uninstalled the former package, and ran this command: Install-Package Microsoft.EntityFrameworkCore.Sqlite -Version 3.1.2 Then everything worked. Yup... My bad. I had installed Microsoft.Data.Sqlite.Core version 3.0.0 when I needed version 2.2.6 and I had not installed Microsoft.Data.Sqlite 2.2.6, which I have since installed. It's working now. Also, FYI: both .UseSqlite("Data Source=:memory:") and .UseSqlite("DataSource=:memory:") work. I had similar issue when trying to open Microsoft.Data.Sqlite.SqliteConnection , it was throwing System.NullReferenceException as well. The class which was initializing the connection was in library project referencing: Microsoft.Data.Sqlite - v3.1.2 Microsoft.Data.Sqlite.Core - v3...