package com.beem.project.beem.provider;

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

/**
 * BeemDatabaseHelper class.
 * 
 * @author Jamu
 */
public class BeemDatabaseHelper extends SQLiteOpenHelper {

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

	/**
	 * BeemDatabaseHelper class.
	 * 
	 * @param context
	 *            the context.
	 * @param tag
	 *            the tag.
	 * @param tableName
	 *            the tableName.
	 * @param creationQuery
	 *            the creation query.
	 */
	public BeemDatabaseHelper(final Context context, final String tag, final String tableName,
			final 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);
	}
}
