Android Open Source - TacoTool D B S Q Lite Helper






From Project

Back to project page TacoTool.

License

The source code is released under:

GNU General Public License

If you think the Android project TacoTool listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package database;
/* w w w.  j ava 2s.  c  om*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBSQLiteHelper extends SQLiteOpenHelper {






  public static final String TABLE_INGREDIENTS = "ingredients";
  public static final String TABLE_RECIPES = "recipes";
  public static final String COLUMN_RECIPE = "recipeName";
  public static final String COLUMN_INGREDIENT = "ingredient";
  private static final String DATABASE_NAME = "ingredients.db";
  private static final String COLUMN_ID = "ingredientID";
  private static final int DATABASE_VERSION = 1;

//  private static final String DATABASE_CREATE = "create table " + TABLE_INGREDIENTS + 
//      "(" + COLUMN_INGREDIENT + "," + COLUMN_ID + " integer unsigned auto_increment, "
//      + "primary key (" + COLUMN_ID + "));";
  
  
  private static final String DATABASE_CREATE = "create table " + TABLE_INGREDIENTS + 
      "(" + COLUMN_INGREDIENT + ", primary key (" + COLUMN_INGREDIENT + "));";
  

  private static final String RECIPE_TABLE = "create table " + TABLE_RECIPES + "(" + 
      COLUMN_RECIPE + ", " + COLUMN_INGREDIENT + ", primary key (" + COLUMN_RECIPE 
      + ", " + COLUMN_INGREDIENT + "));";
  
  public DBSQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    // TODO Auto-generated constructor stub
  }

  @Override
  public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
    database.execSQL(RECIPE_TABLE);
  }
  
  public void clearTable (SQLiteDatabase db){
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_INGREDIENTS);
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_RECIPES);
    onCreate(db);
  }
  



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

  }
}




Java Source Code List

com.example.tacotool.CreateActivity.java
com.example.tacotool.MainActivity.java
com.example.tacotool.ManageActivity.java
com.example.tacotool.SettingsActivity.java
com.example.tacotool.Taco.java
database.DBManager.java
database.DBSQLiteHelper.java