Skip to content

[9.x] InteractsWithDatabase::castAsJson($value) incorrectly handles SQLite Database#44196

Merged
taylorotwell merged 8 commits intolaravel:9.xfrom
stevebauman:feature-cast-as-json-grammar
Sep 19, 2022
Merged

[9.x] InteractsWithDatabase::castAsJson($value) incorrectly handles SQLite Database#44196
taylorotwell merged 8 commits intolaravel:9.xfrom
stevebauman:feature-cast-as-json-grammar

Conversation

@stevebauman
Copy link
Copy Markdown
Contributor

Closes #43863

This PR implements a compileJsonCast() method on the base query grammar instance to allow the transformation of a raw JSON string into a "cast" operation compatible with its database.

This new method is then called in the castAsJson test utility method to generate a proper raw query expression into its compatible operation. Previously, castAsJson would only work with MySQL, as other databases do not have the same operation and will either fail, or (in SQLite's case) simply query for the whole operation's text.

I've tested these cast functions in where clauses using SQL Fiddle. SQLite and Postgres do not appear to require cast functions to be called on the raw JSON to properly query.

@browner12 Let me know your thoughts on this implementation 👍

Comment thread src/Illuminate/Database/Query/Grammars/MySqlGrammar.php Outdated
Comment thread src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php Outdated
Copy link
Copy Markdown
Contributor

@browner12 browner12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment on all the Nowdocs in the test.

Comment thread tests/Testing/Concerns/InteractsWithDatabaseTest.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[9.x] InteractsWithDatabase::castAsJson($value) incorrectly handles SQLite Database

3 participants