You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SQLite: Issues around support for unsigned long #36689
While working on JSON partial updates for ExecuteUpdate (#28766), I ran into some issues with corruption of ulong values - see code sample below. Although the below sample is JSON-specific (and maybe even specific to json_set), I suspect SQLite doesn't actually fully support ulong, and we maybe shouldn't have supported this in M.D.SQLite.
For now, I'll throw for ExecuteUpdate partial updates on ulong properties inside JSON.
usingvarconnection=newSqliteConnection("Data Source=:memory:");connection.Open();usingvarcommand=connection.CreateCommand();command.CommandText="""CREATE TABLE foo (json TEXT);INSERT INTO foo (json) VALUES ('{ "a": 8 }');""";command.ExecuteNonQuery();// command.CommandText = """UPDATE foo SET json = json_set(json, '$.a', @p)""";// command.Parameters.Add(new SqliteParameter("p", DbType.UInt64) { Value = ulong.MaxValue - 1 });command.CommandText="""UPDATE foo SET json = json_set(json, '$.a', 18446744073709551615)""";command.ExecuteNonQuery();command.CommandText="SELECT json FROM foo";varjson=(string)command.ExecuteScalar()!;Console.WriteLine(json);// {"a":-2} when using a parameter, {"a":1.84467440737096e+19} when using a literal.varreader=newUtf8JsonReader(Encoding.UTF8.GetBytes(json));reader.Read();reader.Read();reader.Read();varx=reader.GetUInt64();// FormatException: Either the JSON value is not in a supported format, or is out of bounds for a UInt64
OK, good that it's documented... And yeah, I agree there's probably not much we can do. I'd argue that if large values overflow, maybe ulong shouldn't be "supported" at all (given that it doesn't support half of the range, which is the main reason one would use ulong rather than long...). In other words, maybe let's bring up the question of removing support for it (breaking change)?
Activity
cincuranet commentedon Sep 1, 2025
As the documentation says: UInt64: Large values overflow.
Int64is fine.I'm not sure we can do better here.
roji commentedon Sep 1, 2025
OK, good that it's documented... And yeah, I agree there's probably not much we can do. I'd argue that if large values overflow, maybe ulong shouldn't be "supported" at all (given that it doesn't support half of the range, which is the main reason one would use ulong rather than long...). In other words, maybe let's bring up the question of removing support for it (breaking change)?
AraHaan commentedon Apr 20, 2026
It seems one can work around that problem by storing the data as
TEXTand using aValueConverterto convert betweenstringandulong😂.Although it is sad that SQLite lacks support for this, while SQLServer seems to not mind at all with
ulong.roji commentedon Apr 20, 2026
@AraHaan AFAIK SQL Server doesn't support ulong either, really - EF simply value-converts implicitly from ulong to bigint (which is signed long).