[5.6] Add JSON SELECT queries to SQL Server#24397
Merged
Merged
Conversation
Contributor
|
Can we detect the version of SQL Server used and throw an exception telling the user that the feature is unsupported for older SQL Server versions? |
Contributor
Author
|
I'm not sure it's worth the effort. Users will get an error saying that the function doesn't exist. As far as I see, we don't do database version checks anywhere else. |
Contributor
|
I’m writing this as an email response from my phone, hopefully it will not be totally messed up.
It’s true that we haven’t checked for database versions historically, but that is slowly changing. As an example; we’re checking the version of MySQL you are using to make sure we don’t set any invalid sql modes. (Some were removed in the last version.)
A clear error message is the one thing that differs between users knowing that they need to upgrade their SQL Server version and users trying to figure out how to installing those functions. It would make since that we inform the user as early (and clearly) as possible instead of forcing them to start googling for their error message means and trying to decipher the unclear self-closed Stack Overflow questions I bet they will find.
There’s an issue in the ideas repository about introducing version-specific grammars. That would be relevant and make it easier to only implement this PR for some supported SQL Server versions.
Update:
This entry looked terrible on my phone, so I had to use a computer fix it. I'll take this time to also add some proper references.
Version check for sql modes: https://github.com/laravel/framework/blob/a49d506112917ad80a48f1dca3a5010a741dc37a/src/Illuminate/Database/Connectors/MySqlConnector.php#L177-L184
Splitting up grammars into specific versions; laravel/ideas#870
|
Contributor
Author
|
You're right about the error message. I like the idea of version-specific grammars. I think it's a better approach than checking the database version when individual features are used. Taylor, would you be open to such a change? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds JSON
SELECTqueries to SQL Server 2016+:I found two limitations:
where('foo->bool', 'true')The downside is that this also selects
"true"strings (PostgreSQL has the same problem).select('foo->array') // returns nullThe reason is that SQL Server uses different functions for scalar values (
JSON_VALUE()) and arrays/objects (JSON_QUERY()).MySQL and PostgreSQL return arrays and objects as JSON strings.