package com.beem.project.beem.provider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class BeemDatabaseHelper extends SQLiteOpenHelper {

    private String mTag;
    private String mTableName;
    private String mCreationQuery;

    public BeemDatabaseHelper(Context context, String tag, String tableName, String creationQuery) {
	super(context, Beem.DB_NAME, null, Beem.DB_VERSION);

	this.mTag = tag;
	this.mTableName = tableName;
	this.mCreationQuery = creationQuery;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
	db.execSQL(this.mCreationQuery);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	Log.w(this.mTag, "Upgrading database from version " + oldVersion + " to " + newVersion
	        + ", which will destroy all old data");
	db.execSQL("DROP TABLE IF EXISTS " + this.mTableName + ";");
	onCreate(db);
    }
}
