Unsigned int fields are displayed incorrectly on System.Int32 by System.Data.SQLite

Using System.Data.SQLite , I create a table with unsigned integer columns:

 @"CREATE TABLE widgets (" + @"id unsigned integer(10) PRIMARY KEY, " + @"fkey unsigned integer(10), " + ... 

and then paste the values ​​like

 INSERT INTO widgets (id, fkey, ...) VALUES (4294967295, 3456, ... 

However, looking through the rows and columns of this table, I found that row["id"] is of type System.Int32 (not UInt32 ), and it is not surprising that 4294967295 is interpreted as -1. In fact, all unsigned int fields in the table (and not just the primary key identifier are incorrectly entered as System.Int32 )

Meanwhile, a SQLite type specification says that integers are stored in 1, 2, 3, 4, 6, or 8 bytes, depending on the value. 4294967295 = 0xFFFFFFFF fits in just four bytes. This also contradicts the so-called "dynamic typing" of SQLite. When I insert more than 4294967295 positive values, the type remains System.Int32 .

Is this a bug or a function?

PS1:

my table contains 1 row with the column id = 2 ^ 32-1 = 4294967295 (or more), and I print the types of all columns with

 public void PrintDataTypes(DataTable dt) { foreach (DataRow row in dt.Rows) { foreach (DataColumn col in dt.Columns) Console.WriteLine("name={0}, type={1}", col.ToString(), row[col].GetType().ToString()); return; // after 1st row is done } } 

And I always get

 name=id, type=System.Int32 name=fkey, type=System.Int32 ... 
+6
source share
1 answer

You will not get an unsigned column in SqLite, although you specified unsigned in your SQL. Yes, I personally think that this is a glaring flaw - it does not even display a warning after seeing your "unsigned" specification in your SQL. So your column is subscribed to 64 bits, and your maximum value that you can save is really 2 to 63rd power.

0
source

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


All Articles