Skip to content
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

Desktop,Mobile,Cli: Fixes #11630: Adjust how items are queried by ID #11734

Conversation

personalizedrefrigerator
Copy link
Collaborator

Summary

This pull request adjusts how ID SQL queries are written. Follow-up to #11657.

Fixes #11630.

@personalizedrefrigerator personalizedrefrigerator merged commit cc1582d into laurent22:dev Jan 27, 2025
7 checks passed
@@ -345,13 +345,17 @@ class BaseModel {
return this.modelSelectAll(q.sql, q.params);
}

public static escapeIdsForSql(ids: string[]) {
return this.db().escapeValues(ids).join(', ');
Copy link
Contributor

Choose a reason for hiding this comment

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

The solution and usage of escapeIdsForSql looks ok, but I just have one question:
How / are single quotes added at the start and end of the contents of the IN clause?

The previous logic used:
IN ('${ids.join('','')}')
new logic uses:
(${this.escapeIdsForSql(ids)})

So I don't understand how enclosing quotes can be added when they are omitted for usages of the escapeIdsForSql function and not added within the function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In addition to escaping enclosed quotes by doubling them, .escapeValues surrounds each of the IDs in 's.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that makes sense. Didn't notice the join here no longer includes quotes in the value

'Test\'\'\'a\'\'',
'% test',
])('should support querying items with IDs containing special characters (id: %j)', async (id) => {
const note = await Note.save({ id }, { isNew: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to add a test which includes more than 1 id passed at the same time, so that the join logic is tested

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the feedback! That would be useful.

Note that for standard IDs, there's already several tests that indirectly test this case. For example,

However, these tests only check standard IDs without 's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants