package com.ae.apps.common.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Boilerplate code and helper for a simple database
 * 
 * @author Midhun
 * 
 */
public class DataBaseHelper extends SQLiteOpenHelper {

	private SQLiteDatabase	mDataBase;
	private String[]		mCreateTables;

	public DataBaseHelper(Context context, String name, CursorFactory factory, int version, String[] createTables) {
		super(context, name, factory, version);
		mCreateTables = createTables;
		mDataBase = this.getWritableDatabase();
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// Create the requested tables
		for (String query : mCreateTables) {
			db.execSQL(query);
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

	/**
	 * Runs a query on the real database
	 * 
	 * @param table
	 * @param columns
	 * @param selection
	 * @param selectionArgs
	 * @param groupBy
	 * @param having
	 * @param orderBy
	 * @return
	 */
	protected Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy,
			String having, String orderBy) {
		return mDataBase.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
	}

	protected Cursor query(String table, String[] columns, String selection, String[] selectionArgs) {
		return mDataBase.query(table, columns, selection, selectionArgs, null, null, null);
	}

	protected Cursor rawQuery(String sql, String[] selectionArgs) {
		return mDataBase.rawQuery(sql, selectionArgs);
	}

	/**
	 * Inserts a row
	 * 
	 * @param table
	 * @param values
	 * @return
	 */
	protected long insert(String table, ContentValues values) {
		return mDataBase.insert(table, null, values);
	}

	/**
	 * Updates an existing row
	 * 
	 * @param table
	 * @param values
	 * @param whereClause
	 * @param whereArgs
	 * @return
	 */
	protected long update(String table, ContentValues values, String whereClause, String[] whereArgs) {
		return mDataBase.update(table, values, whereClause, whereArgs);
	}

}

@@ -1036,32 +1036,47 @@
 %09 * @param table
+ The table name
 %0A%09 * @param colu
@@ -1078,16 +1078,28 @@
  columns
+ The columns
 %0A%09 * @pa
@@ -1111,16 +1111,30 @@
 election
+ The selection
 %0A%09 * @pa
@@ -1146,24 +1146,42 @@
 electionArgs
+ the selectionArgs
 %0A%09 * @param 
@@ -1191,45 +1191,101 @@
 upBy
-%0A%09 * @param having%0A%09 * @param orderBy
+ The groupBy clause%0A%09 * @param having The having clause%0A%09 * @param orderBy The orderBy clause
 %0A%09 *
@@ -1284,32 +1284,39 @@
 ause%0A%09 * @return
+ Cursor
 %0A%09 */%0A%09protected
@@ -1897,32 +1897,47 @@
 %09 * @param table
+ The table name
 %0A%09 * @param valu
@@ -1938,28 +1938,64 @@
 m values
-%0A%09 * @return
+ Values to be inserted%0A%09 * @return insert result
 %0A%09 */%0A%09p
@@ -2159,16 +2159,31 @@
 am table
+ The table name
 %0A%09 * @pa
@@ -2192,16 +2192,27 @@
 m values
+ the values
 %0A%09 * @pa
@@ -2222,24 +2222,40 @@
  whereClause
+ the whereClause
 %0A%09 * @param 
@@ -2263,28 +2263,56 @@
 hereArgs
-%0A%09 * @return
+ the WhereArgs%0A%09 * @return update result
 %0A%09 */%0A%09p

update comments