This runs slower and less efficiently than a magical INTEGER PRIMARY KEY / ROW ID alias, but at least it works.Īnyway, I hope that's helpful for developers working to improve linq2db. The simple work around for linq2db users, if they are free to edit their database schema, is to set the primary key to "autoincrement". So you'd just have to re-implement the heuristics of SQLite's decision logic found in their " Create Table" document. It short, it seems there's currently no direct way short of writing an extension method for SQLite in C. I've written up some details about how I've tried to figure out how to extract this piece of metadata directly from the database on another github project. The main difficulty I foresee in fixing this is that SQLite does not expose whether a table is using an INTEGER PRIMARY KEY, or whether it is just an INTEGER column which also happens to be a PRIMARY KEY. The user should be able to leave them as null when inserting new rows and find each is given a different ID, as provided by SQLite. Linq2db should really treat these special "INTEGER PRIMARY KEY" (RowIDs) more or less the same as an autoincrement column. This causes every inserted row to overwrite the last. Linq2db, unfortunately, believes this, and so doesn't let the user leave the column blank or null, unhelpfully setting the PK to 0 during insert. SQLite's metadata does not tell linq2db that these special primary keys might be nullable, nor does it flag them with "autoincrement". Linq2db's LoadSQLiteMetadata() does not pick up on when a column is a ROW ID alias. More details about SQLite's ROW ID alias columns are at the " Create Table" documentation. But it executes faster and can be searched faster. It differs from a "true" autoincrementing field in that IDs of deleted rows are re-used. These columns act something like an auto-increment column, so that when it's left empty or NULL during an insert, SQLite gives it a value automatically. These columns act differently to a regular INTEGER column, or to a BIGINT PRIMARY KEY column (despite BIGINT being otherwise synonymous with INTEGER). When a table has an "INTEGER PRIMARY KEY" then that column might become an alias for ROW ID. SQLite tables have a hidden "ROW ID" column.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |