- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
140 lines
4.6 KiB
Java
140 lines
4.6 KiB
Java
package androidx.sqlite.db;
|
|
|
|
import java.util.regex.Pattern;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
import kotlin.jvm.internal.SourceDebugExtension;
|
|
|
|
@SourceDebugExtension({"SMAP\nSupportSQLiteQueryBuilder.kt\nKotlin\n*S Kotlin\n*F\n+ 1 SupportSQLiteQueryBuilder.kt\nandroidx/sqlite/db/SupportSQLiteQueryBuilder\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,187:1\n1#2:188\n*E\n"})
|
|
/* loaded from: classes.dex */
|
|
public final class SupportSQLiteQueryBuilder {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final Pattern limitPattern = Pattern.compile("\\s*\\d+\\s*(,\\s*\\d+\\s*)?");
|
|
private Object[] bindArgs;
|
|
private String[] columns;
|
|
private boolean distinct;
|
|
private String groupBy;
|
|
private String having;
|
|
private String limit;
|
|
private String orderBy;
|
|
private String selection;
|
|
private final String table;
|
|
|
|
public /* synthetic */ SupportSQLiteQueryBuilder(String str, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(str);
|
|
}
|
|
|
|
public static final SupportSQLiteQueryBuilder builder(String str) {
|
|
return Companion.builder(str);
|
|
}
|
|
|
|
public final SupportSQLiteQueryBuilder columns(String[] strArr) {
|
|
this.columns = strArr;
|
|
return this;
|
|
}
|
|
|
|
public final SupportSQLiteQueryBuilder distinct() {
|
|
this.distinct = true;
|
|
return this;
|
|
}
|
|
|
|
public final SupportSQLiteQueryBuilder groupBy(String str) {
|
|
this.groupBy = str;
|
|
return this;
|
|
}
|
|
|
|
public final SupportSQLiteQueryBuilder having(String str) {
|
|
this.having = str;
|
|
return this;
|
|
}
|
|
|
|
public final SupportSQLiteQueryBuilder orderBy(String str) {
|
|
this.orderBy = str;
|
|
return this;
|
|
}
|
|
|
|
public final SupportSQLiteQueryBuilder selection(String str, Object[] objArr) {
|
|
this.selection = str;
|
|
this.bindArgs = objArr;
|
|
return this;
|
|
}
|
|
|
|
private SupportSQLiteQueryBuilder(String str) {
|
|
this.table = str;
|
|
}
|
|
|
|
public final SupportSQLiteQueryBuilder limit(String limit) {
|
|
Intrinsics.checkNotNullParameter(limit, "limit");
|
|
boolean matches = limitPattern.matcher(limit).matches();
|
|
if (limit.length() == 0 || matches) {
|
|
this.limit = limit;
|
|
return this;
|
|
}
|
|
throw new IllegalArgumentException(("invalid LIMIT clauses:" + limit).toString());
|
|
}
|
|
|
|
public final SupportSQLiteQuery create() {
|
|
String str;
|
|
String str2 = this.groupBy;
|
|
if ((str2 == null || str2.length() == 0) && (str = this.having) != null && str.length() != 0) {
|
|
throw new IllegalArgumentException("HAVING clauses are only permitted when using a groupBy clause".toString());
|
|
}
|
|
StringBuilder sb = new StringBuilder(120);
|
|
sb.append("SELECT ");
|
|
if (this.distinct) {
|
|
sb.append("DISTINCT ");
|
|
}
|
|
String[] strArr = this.columns;
|
|
if (strArr != null && strArr.length != 0) {
|
|
Intrinsics.checkNotNull(strArr);
|
|
appendColumns(sb, strArr);
|
|
} else {
|
|
sb.append("* ");
|
|
}
|
|
sb.append("FROM ");
|
|
sb.append(this.table);
|
|
appendClause(sb, " WHERE ", this.selection);
|
|
appendClause(sb, " GROUP BY ", this.groupBy);
|
|
appendClause(sb, " HAVING ", this.having);
|
|
appendClause(sb, " ORDER BY ", this.orderBy);
|
|
appendClause(sb, " LIMIT ", this.limit);
|
|
String sb2 = sb.toString();
|
|
Intrinsics.checkNotNullExpressionValue(sb2, "StringBuilder(capacity).…builderAction).toString()");
|
|
return new SimpleSQLiteQuery(sb2, this.bindArgs);
|
|
}
|
|
|
|
private final void appendClause(StringBuilder sb, String str, String str2) {
|
|
if (str2 == null || str2.length() == 0) {
|
|
return;
|
|
}
|
|
sb.append(str);
|
|
sb.append(str2);
|
|
}
|
|
|
|
private final void appendColumns(StringBuilder sb, String[] strArr) {
|
|
int length = strArr.length;
|
|
for (int i = 0; i < length; i++) {
|
|
String str = strArr[i];
|
|
if (i > 0) {
|
|
sb.append(", ");
|
|
}
|
|
sb.append(str);
|
|
}
|
|
sb.append(' ');
|
|
}
|
|
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
private Companion() {
|
|
}
|
|
|
|
public final SupportSQLiteQueryBuilder builder(String tableName) {
|
|
Intrinsics.checkNotNullParameter(tableName, "tableName");
|
|
return new SupportSQLiteQueryBuilder(tableName, null);
|
|
}
|
|
}
|
|
}
|