blob: 36eacbd852b1a0df41b14d0053dd4a91f2052ec6 [file] [log] [blame]
/*
* Copyright (C) 2016 Fairphone B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fairphone.hiccup.app;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
class HiccupReportDBHelper extends SQLiteOpenHelper {
// If you change the database schema, you must increment the database version.
private static final int DATABASE_VERSION = 4;
private static final String DATABASE_NAME = "crashreport.db";
private static final String TEXT_TYPE = " TEXT";
private static final String COMMA_SEP = ",";
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + HiccupReportDBContract.reportEntry.TABLE_NAME + " (" +
HiccupReportDBContract.reportEntry._ID + " INTEGER PRIMARY KEY," +
HiccupReportDBContract.reportEntry.COLUMN_NAME_BUILDFINGERPRINT + TEXT_TYPE + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_UPTIME + TEXT_TYPE + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_AUX_DATA + TEXT_TYPE + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_BOOTREASON + TEXT_TYPE + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_POWERONREASON + TEXT_TYPE + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_POWEROFFREASON + TEXT_TYPE + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_DATE + " DATETIME " + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_LOGFILE_PATH + TEXT_TYPE + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_REPORT_TYPE + TEXT_TYPE + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_UPLOAD_COMPLETE + " BOOLEAN " + COMMA_SEP +
HiccupReportDBContract.reportEntry.COLUMN_NAME_DEVICE_LOCAL_ID + " INTEGER " +
" );";
private static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + HiccupReportDBContract.reportEntry.TABLE_NAME + ";";
public HiccupReportDBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
HiccupUtil.LOG("creating database");
db.execSQL(SQL_CREATE_ENTRIES);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// This database is only a cache for online data, so its upgrade policy is
// to simply to discard the data and start over
db.execSQL(SQL_DELETE_ENTRIES);
onCreate(db);
}
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
}