1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package com.xtremelabs.robolectric.shadows;
import android.database.sqlite.SQLiteQueryBuilder;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.util.Join;
/**
* Shadow for {@code SQLiteQueryBuilder}.
*/
@Implements(SQLiteQueryBuilder.class)
public class ShadowSQLiteQueryBuilder {
@Implementation
public static String buildQueryString(boolean distinct, String tables,
String[] columns, String where, String groupBy, String having,
String orderBy, String limit) {
StringBuilder sb = new StringBuilder("SELECT ");
if (distinct) {
sb.append("DISTINCT ");
}
if (columns != null) {
sb.append(Join.join(", ", (Object[]) columns));
} else {
sb.append("*");
}
sb.append(" FROM ");
sb.append(tables);
conditionallyAppend(sb, " WHERE ", where);
conditionallyAppend(sb, " GROUP BY ", groupBy);
conditionallyAppend(sb, " HAVING ", having);
conditionallyAppend(sb, " ORDER BY ", orderBy);
conditionallyAppend(sb, " LIMIT ", limit);
return sb.toString();
}
private static void conditionallyAppend(StringBuilder sb, String keyword, String value) {
if (value != null) {
sb.append(keyword);
sb.append(value);
}
}
}
|