-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use SQLite native representations in JSON #31490
Conversation
WHERE ( | ||
SELECT COUNT(*) | ||
FROM json_each("t"."SomeArray") AS "s" | ||
WHERE unhex("s"."value") = X'0102') = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we the JSON representation for binary data is now a hexadecimal string (same as the output of the SQLite function hex; we do a server-side conversion back to blob via unhex
. Note that unhex was only introduced relatively recently (version 3.41.0, released 2023-02-08).
This is now the only case where we need a server-side conversion, because the other types (e.g. date/time) really are strings in SQLite, whereas BLOB is its own separate type.
2d499a4
to
d8164f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff!
233e015
to
2c85727
Compare
namespace Microsoft.EntityFrameworkCore; | ||
|
||
[SpatialiteRequired] | ||
public class JsonTypesSqliteTest : JsonTypesRelationalTestBase | ||
{ | ||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
=> base.OnConfiguring(optionsBuilder.UseSqlite(b => b.UseNetTopologySuite())); | ||
|
||
public override void Can_read_write_binary_JSON_values(string value, string json) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajcvickers note this annoying thing... when you override a virtual test method, apparently the [InlineData] attributes on the base are still inherited; this makes it impossible to override methods when what you want is to replace the [InlineData] (which is the case here).
I hacked around it for now, we can think about it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing you can do is add a placeholder and then mutate the value before passing it down to the base method. See public override void Can_read_write_collection_of_ASCII_string_JSON_values(object? storeType)
in JsonTypesSqlServerTest
. But maybe this is just as much as a hack, and is only useful in limited cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... Unfortunately [MemberData] can only point to static properties/methods, otherwise that could have been virtual and overridden (xunit is really limited here). Let's revisit this later.
2c85727
to
e294428
Compare
Closes #30727
/cc @danmoseley