187 lines
5.5 KiB
Java
187 lines
5.5 KiB
Java
package com.ubtrobot.analytics;
|
|
|
|
import android.content.ContentValues;
|
|
import android.content.Context;
|
|
import android.database.Cursor;
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
import android.database.sqlite.SQLiteDiskIOException;
|
|
import android.database.sqlite.SQLiteFullException;
|
|
import android.database.sqlite.SQLiteOpenHelper;
|
|
import android.util.Log;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class AnalyticsDBHelper extends SQLiteOpenHelper {
|
|
private static final byte[] a = new byte[0];
|
|
private static volatile AnalyticsDBHelper b;
|
|
private static volatile SQLiteDatabase c;
|
|
|
|
private AnalyticsDBHelper(Context context) {
|
|
super(context, "analytics", (SQLiteDatabase.CursorFactory) null, 4);
|
|
}
|
|
|
|
public static AnalyticsDBHelper a(Context context) {
|
|
if (b != null) {
|
|
return b;
|
|
}
|
|
synchronized (a) {
|
|
if (b != null) {
|
|
return b;
|
|
}
|
|
b = new AnalyticsDBHelper(context);
|
|
return b;
|
|
}
|
|
}
|
|
|
|
public void b(String str) {
|
|
try {
|
|
a().execSQL(str);
|
|
} catch (SQLiteDiskIOException e) {
|
|
Log.e("Analytics", "Exec sql fail, msg:" + e.getMessage());
|
|
}
|
|
}
|
|
|
|
public int c(String str) {
|
|
try {
|
|
Cursor rawQuery = a().rawQuery("SELECT COUNT(*) FROM " + str, null);
|
|
try {
|
|
rawQuery.moveToFirst();
|
|
return (int) rawQuery.getLong(0);
|
|
} finally {
|
|
rawQuery.close();
|
|
}
|
|
} catch (SQLiteDiskIOException e) {
|
|
Log.e("Analytics", "GetCount fail, msg:" + e.getMessage());
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public Cursor d(String str) {
|
|
try {
|
|
return a().rawQuery(str, null);
|
|
} catch (SQLiteDiskIOException e) {
|
|
Log.e("Analytics", "CheckColumnExists fail, msg:" + e.getMessage());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override // android.database.sqlite.SQLiteOpenHelper
|
|
public void onCreate(SQLiteDatabase sQLiteDatabase) {
|
|
c = sQLiteDatabase;
|
|
EventScheme.a(b);
|
|
ActivenessScheme.a(b);
|
|
}
|
|
|
|
@Override // android.database.sqlite.SQLiteOpenHelper
|
|
public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
|
|
c = sQLiteDatabase;
|
|
while (i <= i2) {
|
|
if (i == 2) {
|
|
b();
|
|
} else if (i == 3) {
|
|
c();
|
|
} else if (i == 4) {
|
|
d();
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
|
|
private void b() {
|
|
EventScheme.b(b);
|
|
}
|
|
|
|
private void d() {
|
|
EventScheme.d(b);
|
|
ActivenessScheme.b(b);
|
|
}
|
|
|
|
private void c() {
|
|
EventScheme.c(b);
|
|
ActivenessScheme.a(b);
|
|
}
|
|
|
|
public void a(String str) {
|
|
Log.i("Analytics", "Create table: " + str);
|
|
try {
|
|
a().execSQL(str);
|
|
} catch (SQLiteDiskIOException e) {
|
|
Log.e("Analytics", "Create table fail, msg:" + e.getMessage());
|
|
}
|
|
}
|
|
|
|
private SQLiteDatabase a() {
|
|
c = c != null ? c : b.getWritableDatabase();
|
|
return c;
|
|
}
|
|
|
|
public void a(List<String> list) {
|
|
try {
|
|
a().beginTransaction();
|
|
Iterator<String> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
a().execSQL(it.next());
|
|
}
|
|
a().setTransactionSuccessful();
|
|
a().endTransaction();
|
|
} catch (SQLiteDiskIOException e) {
|
|
Log.e("Analytics", "Exec sql list fail, msg:" + e.getMessage());
|
|
}
|
|
}
|
|
|
|
public int a(String str, String str2, String[] strArr) {
|
|
try {
|
|
return a().delete(str, str2, strArr);
|
|
} catch (SQLiteDiskIOException e) {
|
|
Log.e("Analytics", "Delete fail, msg:" + e.getMessage());
|
|
return 0;
|
|
} catch (SQLiteFullException e2) {
|
|
Log.e("Analytics", "Delete fail, msg:" + e2.getMessage());
|
|
a().execSQL(String.format("DROP TABLE %s", str));
|
|
if (str.equals("event")) {
|
|
EventScheme.a(b);
|
|
} else if (str.equals("activeness")) {
|
|
ActivenessScheme.a(b);
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public void a(String str, ContentValues contentValues, String str2, String[] strArr) {
|
|
try {
|
|
SQLiteDatabase a2 = a();
|
|
a2.beginTransaction();
|
|
if (a2.update(str, contentValues, str2, strArr) <= 0) {
|
|
a2.insert(str, null, contentValues);
|
|
}
|
|
a2.setTransactionSuccessful();
|
|
a2.endTransaction();
|
|
} catch (SQLiteDiskIOException e) {
|
|
Log.e("Analytics", "UpdateIfExist fail, msg:" + e.getMessage());
|
|
}
|
|
}
|
|
|
|
public void a(String str, ContentValues contentValues) {
|
|
try {
|
|
a().insert(str, null, contentValues);
|
|
} catch (SQLiteDiskIOException e) {
|
|
Log.e("Analytics", "Insert fail, msg:" + e.getMessage());
|
|
}
|
|
}
|
|
|
|
public boolean a(String str, String str2) {
|
|
try {
|
|
Cursor rawQuery = a().rawQuery("select * from sqlite_master where name = ? and sql like ?", new String[]{str, "%" + str2 + "%"});
|
|
boolean moveToFirst = rawQuery.moveToFirst();
|
|
if (!rawQuery.isClosed()) {
|
|
rawQuery.close();
|
|
}
|
|
return moveToFirst;
|
|
} catch (SQLiteDiskIOException e) {
|
|
Log.e("Analytics", "CheckColumnExists fail, msg:" + e.getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
}
|