126 lines
4.6 KiB
Java
126 lines
4.6 KiB
Java
package com.tencent.wxop.stat;
|
|
|
|
import android.content.ContentValues;
|
|
import android.content.Context;
|
|
import android.database.Cursor;
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
import android.database.sqlite.SQLiteOpenHelper;
|
|
import com.tencent.wxop.stat.common.StatLogger;
|
|
import java.util.ArrayList;
|
|
|
|
/* loaded from: classes.dex */
|
|
class bc extends SQLiteOpenHelper {
|
|
private String a;
|
|
private Context b;
|
|
|
|
public bc(Context context, String str) {
|
|
super(context, str, (SQLiteDatabase.CursorFactory) null, 3);
|
|
StatLogger statLogger;
|
|
this.a = "";
|
|
this.b = null;
|
|
this.a = str;
|
|
this.b = context.getApplicationContext();
|
|
if (StatConfig.isDebugEnable()) {
|
|
statLogger = au.h;
|
|
statLogger.i("SQLiteOpenHelper " + this.a);
|
|
}
|
|
}
|
|
|
|
private void a(SQLiteDatabase sQLiteDatabase) {
|
|
Cursor cursor;
|
|
StatLogger statLogger;
|
|
String str = null;
|
|
try {
|
|
cursor = sQLiteDatabase.query("user", null, null, null, null, null, null);
|
|
} catch (Throwable th) {
|
|
th = th;
|
|
cursor = null;
|
|
}
|
|
try {
|
|
ContentValues contentValues = new ContentValues();
|
|
if (cursor.moveToNext()) {
|
|
str = cursor.getString(0);
|
|
cursor.getInt(1);
|
|
cursor.getString(2);
|
|
cursor.getLong(3);
|
|
contentValues.put("uid", com.tencent.wxop.stat.common.r.b(str));
|
|
}
|
|
if (str != null) {
|
|
sQLiteDatabase.update("user", contentValues, "uid=?", new String[]{str});
|
|
}
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
try {
|
|
statLogger = au.h;
|
|
statLogger.e(th);
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
} finally {
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void b(SQLiteDatabase sQLiteDatabase) {
|
|
StatLogger statLogger;
|
|
Cursor cursor = null;
|
|
try {
|
|
cursor = sQLiteDatabase.query("events", null, null, null, null, null, null);
|
|
ArrayList<bd> arrayList = new ArrayList();
|
|
while (cursor.moveToNext()) {
|
|
arrayList.add(new bd(cursor.getLong(0), cursor.getString(1), cursor.getInt(2), cursor.getInt(3)));
|
|
}
|
|
ContentValues contentValues = new ContentValues();
|
|
for (bd bdVar : arrayList) {
|
|
contentValues.put("content", com.tencent.wxop.stat.common.r.b(bdVar.b));
|
|
sQLiteDatabase.update("events", contentValues, "event_id=?", new String[]{Long.toString(bdVar.a)});
|
|
}
|
|
} catch (Throwable th) {
|
|
try {
|
|
statLogger = au.h;
|
|
statLogger.e(th);
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
} finally {
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.database.sqlite.SQLiteOpenHelper, java.lang.AutoCloseable
|
|
public synchronized void close() {
|
|
super.close();
|
|
}
|
|
|
|
@Override // android.database.sqlite.SQLiteOpenHelper
|
|
public void onCreate(SQLiteDatabase sQLiteDatabase) {
|
|
sQLiteDatabase.execSQL("create table if not exists events(event_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, content TEXT, status INTEGER, send_count INTEGER, timestamp LONG)");
|
|
sQLiteDatabase.execSQL("create table if not exists user(uid TEXT PRIMARY KEY, user_type INTEGER, app_ver TEXT, ts INTEGER)");
|
|
sQLiteDatabase.execSQL("create table if not exists config(type INTEGER PRIMARY KEY NOT NULL, content TEXT, md5sum TEXT, version INTEGER)");
|
|
sQLiteDatabase.execSQL("create table if not exists keyvalues(key TEXT PRIMARY KEY NOT NULL, value TEXT)");
|
|
sQLiteDatabase.execSQL("CREATE INDEX if not exists status_idx ON events(status)");
|
|
}
|
|
|
|
@Override // android.database.sqlite.SQLiteOpenHelper
|
|
public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
|
|
StatLogger statLogger;
|
|
statLogger = au.h;
|
|
statLogger.debug("upgrade DB from oldVersion " + i + " to newVersion " + i2);
|
|
if (i == 1) {
|
|
sQLiteDatabase.execSQL("create table if not exists keyvalues(key TEXT PRIMARY KEY NOT NULL, value TEXT)");
|
|
a(sQLiteDatabase);
|
|
b(sQLiteDatabase);
|
|
}
|
|
if (i == 2) {
|
|
a(sQLiteDatabase);
|
|
b(sQLiteDatabase);
|
|
}
|
|
}
|
|
}
|