SQLite: Issues around support for unsigned long
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
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.
```c#
using var connection = new SqliteConnection("Data Source=:memory:");
connection.Open();
using var command = 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";
var json = (string)command.ExecuteScalar()!;
Console.WriteLine(json); // {"a":-2} when using a parameter, {"a":1.84467440737096e+19} when using a literal.
var reader = new Utf8JsonReader(Encoding.UTF8.GetBytes(json));
reader.Read();
reader.Read();
reader.Read();
var x = reader.GetUInt64(); // FormatException: Either the JSON value is not in a supported format, or is out of bounds for a UInt64
```
/cc @cincuranet, @AndriySvyryd (this probably also affects the update pipeline)
Contributor guide
Assessment
This issue has not been assessed yet.