mardi 16 juin 2015

Android import database file in to my project [duplicate]

This question is an exact duplicate of:

i have a database which work fine.now i am doing to add my database file into project. i have a database file in asset folder. but do not know how to import it in the project any body here to solve my issue.i ask many time question but no proper answer found .

this is my dbhelper class

    public class FoodDbHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "pkfood_calories.DB";
private static final int DATABASE_VERSION = 1;
private static final String CREATE_QUERY =
        "CREATE TABLE "+ Food.NewDishInfo.TABLE_NAME+"("
                + Food.NewDishInfo.DISH_NAME+" TEXT NOT NULL,"
                + Food.NewDishInfo.DISH_QUANTITY+" TEXT NOT NULL,"
                + Food.NewDishInfo.DISH_CALORIE+" INTEGER,"
                + Food.NewDishInfo.DISH_FAT+" TEXT NOT NULL,"
                + Food.NewDishInfo.DISH_PROTEIN+" TEXT NOT NULL,"
                + Food.NewDishInfo.DISH_SUGAR+" TEXT NOT NULL,"
                + Food.NewDishInfo.DISH_VITAMINS+" TEXT NOT NULL);";
public FoodDbHelper(Context context)
{
    super(context,DATABASE_NAME,null,DATABASE_VERSION);
    Log.e("DATABASE OPERATION","Database created / opened...");
}
@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(CREATE_QUERY);
    Log.e("DATABASE OPERATION","Table created...");


}
public void addInformations(String name ,String quantity, Integer calorie, String fat ,
                            String protein,String sugar,String vitamins, SQLiteDatabase db){


    ContentValues contentValues = new ContentValues();
    contentValues.put(Food.NewDishInfo.DISH_NAME,name);
    contentValues.put(Food.NewDishInfo.DISH_QUANTITY,quantity);
    contentValues.put(Food.NewDishInfo.DISH_CALORIE,calorie);
    contentValues.put(Food.NewDishInfo.DISH_FAT,fat);
    contentValues.put(Food.NewDishInfo.DISH_PROTEIN,protein);
    contentValues.put(Food.NewDishInfo.DISH_SUGAR,sugar);
    contentValues.put(Food.NewDishInfo.DISH_VITAMINS,vitamins);
    db.insert(Food.NewDishInfo.TABLE_NAME, null, contentValues);
    Log.e("DATABASE OPERATION","one row inserted...");
}
public Cursor getInformations(SQLiteDatabase db){
    Cursor cursor;
    String[] projections = {Food.NewDishInfo.DISH_NAME,Food.NewDishInfo.DISH_QUANTITY,
            Food.NewDishInfo.DISH_CALORIE,Food.NewDishInfo.DISH_FAT,Food.NewDishInfo.DISH_PROTEIN,
            Food.NewDishInfo.DISH_SUGAR, Food.NewDishInfo.DISH_VITAMINS};
    cursor= db.query(Food.NewDishInfo.TABLE_NAME,projections,null,null,null,null,"DISH_NAME ASC");
    return cursor;
}

Aucun commentaire:

Enregistrer un commentaire