Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Inline SQL queries using boolean parameters #15515

Closed
H-Shay opened this issue May 1, 2023 · 3 comments · Fixed by #15525
Closed

Inline SQL queries using boolean parameters #15515

H-Shay opened this issue May 1, 2023 · 3 comments · Fixed by #15525
Labels
good first issue Good for newcomers O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. Z-Help-Wanted We know exactly how to fix this issue, and would be grateful for any contribution

Comments

@H-Shay
Copy link
Contributor

H-Shay commented May 1, 2023

Before SQLite 3.23, TRUE and FALSE were not recognised as constants by SQLite, and the IS [NOT] TRUE/IS [NOT] FALSE operators were not supported. While Synapse supported SQLite versions older 3.23 that made it necessary to avoid using TRUE and FALSE constants in SQL commands. To work around this constraint the boolean operators were passed as parameters like so:

txn.execute(
"UPDATE events SET outlier = ?"
" WHERE event_id IN ("
" SELECT event_id FROM events_to_purge "
" WHERE NOT should_delete"
")",
(True,),
)

However, Synapse now requires a SQLite version of 3.27.0 or higher if SQLite is configured so we no longer need to do this and futhermore should convert old-style queries in the codebase to use TRUE/FALSE inline as it is easier to parse/read.

@H-Shay H-Shay added Z-Help-Wanted We know exactly how to fix this issue, and would be grateful for any contribution good first issue Good for newcomers T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Tolerable Minor significance, cosmetic issues, low or no impact to users. labels May 1, 2023
@hi-anshul hi-anshul mentioned this issue May 3, 2023
4 tasks
hi-anshul added a commit to hi-anshul/synapse that referenced this issue May 3, 2023
Updated Inline SQL queries according so SQLite 3.27
@prithvi009
Copy link

Is this issue still open?

@clokep
Copy link
Member

clokep commented May 8, 2023

Is this issue still open?

Yes, there's the start of a PR at #15525, however.

@Attul-Sharma
Copy link

txn.execute(
"UPDATE events SET outlier = ?"
" WHERE event_id IN ("
" SELECT event_id FROM events_to_purge"
" WHERE NOT should_delete"
")",
(1,),
)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. Z-Help-Wanted We know exactly how to fix this issue, and would be grateful for any contribution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants