16
16
17
17
import static com .google .firebase .firestore .util .Assert .fail ;
18
18
import static com .google .firebase .firestore .util .Assert .hardAssert ;
19
+ import static com .google .firebase .firestore .util .Util .repeatSequence ;
19
20
20
- import android .text .TextUtils ;
21
21
import androidx .annotation .Nullable ;
22
22
import com .google .firebase .firestore .core .Bound ;
23
23
import com .google .firebase .firestore .core .FieldFilter ;
@@ -219,17 +219,17 @@ public Set<DocumentKey> getDocumentsMatchingTarget(Target target) {
219
219
220
220
/** Returns a SQL query on 'index_entries' that unions all bounds. */
221
221
private SQLitePersistence .Query generateQuery (int indexId , Object [] bounds , String op ) {
222
- String [] statements = new String [bounds .length ];
222
+ String statement =
223
+ String .format (
224
+ "SELECT document_name FROM index_entries WHERE index_id = ? AND index_value %s ?" , op );
225
+ String sql = repeatSequence (statement , bounds .length , " UNION " );
226
+
223
227
Object [] bingArgs = new Object [bounds .length * 2 ];
224
228
for (int i = 0 ; i < bounds .length ; ++i ) {
225
- statements [i ] =
226
- String .format (
227
- "SELECT document_name FROM index_entries WHERE index_id = ? AND index_value %s ?" ,
228
- op );
229
229
bingArgs [i * 2 ] = indexId ;
230
230
bingArgs [i * 2 + 1 ] = bounds [i ];
231
231
}
232
- String sql = TextUtils . join ( " UNION " , statements );
232
+
233
233
return db .query (sql ).binding (bingArgs );
234
234
}
235
235
@@ -240,22 +240,23 @@ private SQLitePersistence.Query generateQuery(
240
240
String lowerBoundOp ,
241
241
Object [] upperBounds ,
242
242
String upperBoundOp ) {
243
- String [] statements = new String [lowerBounds .length * upperBounds .length ];
243
+ String statement =
244
+ String .format (
245
+ "SELECT document_name FROM index_entries WHERE index_id = ? AND index_value %s ? AND index_value %s ?" ,
246
+ lowerBoundOp , upperBoundOp );
247
+ String sql = repeatSequence (statement , lowerBounds .length * upperBounds .length , " UNION " );
248
+
244
249
Object [] bingArgs = new Object [lowerBounds .length * upperBounds .length * 3 ];
245
250
int i = 0 ;
246
251
for (Object value1 : lowerBounds ) {
247
252
for (Object value2 : upperBounds ) {
248
- statements [i ] =
249
- String .format (
250
- "SELECT document_name FROM index_entries WHERE index_id = ? AND index_value %s ? AND index_value %s ?" ,
251
- lowerBoundOp , upperBoundOp );
252
253
bingArgs [i * 3 ] = indexId ;
253
254
bingArgs [i * 3 + 1 ] = value1 ;
254
255
bingArgs [i * 3 + 2 ] = value2 ;
255
256
++i ;
256
257
}
257
258
}
258
- String sql = TextUtils . join ( " UNION " , statements );
259
+
259
260
return db .query (sql ).binding (bingArgs );
260
261
}
261
262
0 commit comments