-
Notifications
You must be signed in to change notification settings - Fork 21
Conversation
* @param size The number of selection arguments | ||
* @return Example: for size == 3 : "?, ?, ?" | ||
*/ | ||
public static String createQuerySelectionPlaceholdersOfSize(int size) { |
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 would be a good thing to test (if notils has tests)
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.
It does, good point 👍
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 created string is for us with IN
operators. Should be mentioned in the comment. It could also contain the operator and the brackets.
For other queries this is not a very common pattern for place holders.
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.
should not contain Query
in the name, as the class contains it.
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.
👍 for removing Query
from the name and mentioning IN
in the comment.
I would avoid adding brackets and operator
@friedger @amlcurran method name updated and tests added |
* @return Example: for size == 3 : "?, ?, ?" | ||
*/ | ||
public static String createSelectionPlaceholdersOfSize(int size) { | ||
String[] questionMarks = new String[size]; |
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.
what about something like:
int sizeOfResult = size * 3 - 2;
char[] result = new char[sizeOfResult];
for (int i = 0; i < size -1; i++) {
result[i] = '?';
result[i + 1] = ',';
result[i + 2] = ' ';
}
if (i > 0) {
result[sizeOfResult - 1] = '?';
}
return new String(result);
it creates only two objects, instead of size + 5, and is still understandable and simple.
This PR adds a couple of methods useful for
ContentResolver
operations, when multiple selection arguments are needed.ContentResolver
operations can use?
for placeholders to be replaced from the content of the operationselectionArgs
parameter. Every selectionArg, however, requires a dedicated placeholders.For example the following code won't work:
while this will:
The two added methods allows to easily create both the selection part (
?, ?, ... ?
) and the selectionArgs String array