Problem with integer SQLite and int datatype

I encounter a problem: An object of type "System.Int64" cannot be converted to type "System.Int32" when starting the SubSonic.Examples.SimpleRepo database on the SQLite provider.

I like that the data type for the Category table column CategoryID is " integer ", and the "integer" in SQLite will be returned as Int64 , at the same time, the data type of the Category category in the int class category , the error is higher.

I checked the source code of SubSonic: \ SubSonic.Core \ SQLGeneration \ Schema \ SQLiteSchema.cs and found the following codes:

else if (column.IsPrimaryKey && column.DataType == DbType.Int32
    || column.IsPrimaryKey && column.DataType == DbType.Int16
    || column.IsPrimaryKey && column.DataType == DbType.Int64
    )
    sb.Append(" integer ");

Who can tell me the purpose for these codes? How to solve data type conversion error?

+3
source share
3 answers

Funny, I just read the sqlite3 documentation about this about an hour ago. So, you are lucky :)

See the doc document yourself (Scroll down, 64-bit ROWID section).

Here's an excerpt:

To minimize storage space, the 64-bit rowid is stored as a variable-length integer. Rowids 0 to 127 use only one byte. Rowids from 0 to 16383 use only 2 bytes. Until 2097152 uses three bytes. Etc. Negative rowids are acceptable, but they always use nine bytes of memory, so their use is not recommended. When rowid are automatically generated by SQLite, they will always be non-negative.

+6

PrimaryKey int 64 (long) SQLite, .

+7

I just mumbled the merge procedure by grabbing a SQL Server DataTable and combining (updating) it with SQLite DataTable (a C # .NET form creation application). You definitely need to install whole PK columns in the SQL Server database for BIGINT in order to fly. Otherwise, when you call a merge in SQLite DataTable, you get a type mismatch error.

0
source

Source: https://habr.com/ru/post/1715858/


All Articles