-
Notifications
You must be signed in to change notification settings - Fork 822
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
Bug Fix - Ensure DataQuery::exists() SQL is both valid MySQL and T-SQL #9845
Bug Fix - Ensure DataQuery::exists() SQL is both valid MySQL and T-SQL #9845
Conversation
The original SQL statement is not valid T-SQL for use with SQL Server
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.
This is changing the selected value from a boolean to an integer on PostgreSQL, but it's probably fine as we're checking for 1
in the following condition.
Should work on Postgres (although I haven't tested it) - it only hurts my dev heart a little to see us using ints instead of booleans for a binary value.
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.
the return statement can then be simplified I believe?
return (((int) $result) === 1);
You have to be careful as PostgreSQL can return You could write |
Re: "using int rather than boolean for a binary value" - Perhaps I am misinterpreting what you mean, but I have tried replacing 1/0 in the SQL statement with true/false instead but that throws "Invalid column name 'true'" in T-SQL and although it doesn't error in MySQL, the boolean based return values are converted to Int in the resulting output anyway. Re: making the return statement more succinct, as well as your suggestion, this would also do the trick I suspect: I won't weigh in on the PostgreSQL comments on 't'/'f' vs 1/0 as I have no experience with PostgreSQL |
Your PR is fine imo. FYI Postgres has a native boolean type, which is why it's often the odd one out here. TSQL and MySQL don't - but I know that MySQL has some |
I believe this should be fine - note that our Boolean types use a 1-bit integer for PostgreSQL as well to keep a bit more cross-database consistency, so a 1/0 here is fine too IMO. |
@sminnee does your latest comment support @xini 's proposal to simplify the return statement to 2/3 of you have approved these changes, Xini's feedback is still marked as 'requesting changes' of the above, which I am happy to do if we are all in agreement that it is suitable? Either way if/when that additional change is made and approved, what are the next steps here, all I have an option for is 'Close pull request', should I do that once approval is reached as the creator to confirm it is finished, or is that something one of the three of you do once unanimous approval has been given? (I am not a frequent contributor, bit hazy on the process) |
Bump ☝️ What needs to be done for this to be merged in? |
I just need to press the button 🙂 |
The original SQL statement for checking at the DB level if a DataQuery result set has any rows (implemented in #8915) is not valid T-SQL for use with SQL Server.
This pull request aims to tweak that SQL so that it is valid MySQL and T-SQL.
Note that I am not familiar with any other supported DB backends such as SQLite or PostgreSQL so someone with knowledge of these should review this change for compatibility with those please
I have made a more detailed reference to the errors this fixes in #9809