Хорошо, я создал базу данных и понял, что каждый раз, когда я что-то изменяю в базе данных, мне приходится удалять, а затем переустанавливать приложение :(, что очень расстраивает ... вот мой код для моей базы данных, надеюсь, вы сможете помочья! я не знаю, что не так с моим кодом:
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Cook_tab_snacks_data extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "Snacks";
public Cook_tab_snacks_data(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE IF NOT EXISTS snacks (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"name TEXT, " +
"disc TEXT, " +
"photo TEXT, " +
"prep TEXT, " +
"thumb TEXT, " +
"ingre TEXT, " +
"howto TEXT, " +
"info TEXT, " +
"snackId INTEGER)";
db.execSQL(sql);
ContentValues values = new ContentValues();
values.put("name", "Name 1");
values.put("disc", "here is the description");
values.put("photo", "stub.png");
values.put("thumb", "stub.png");
values.put("prep", "takes 30 mins");
values.put("ingre", "the ingredients of the snack");
values.put("howto", "how to make this thing");
values.put("info", "basically its this much calorie and such and such");
db.insert("snacks", "name", values);
values.put("name", "Name 2");
values.put("disc", "here is the description");
values.put("photo", "stub.png");
values.put("thumb", "ic_launcher.png");
values.put("prep", "takes 500 mins");
values.put("ingre", "the ingredients of the snack");
values.put("howto", "how to make this thing");
values.put("info", "basically its this much calorie and such and such");
db.insert("snacks", "name", values);
values.put("name", "Name 3");
values.put("disc", "here is the description");
values.put("photo", "stub.png");
values.put("thumb", "stub.png");
values.put("ingre", "the ingredients of the snack");
values.put("howto", "how to make this thing");
values.put("info", "basically its this much calorie and such and such");
db.insert("snacks", "name", values);
values.put("name", "Name 4");
values.put("disc", "here is the description");
values.put("photo", "stub.png");
values.put("ingre", "the ingredients of the snack");
values.put("howto", "how to make this thing");
values.put("info", "basically its this much calorie and such and such");
db.insert("snacks", "name", values);
values.put("name", "Name 5");
values.put("disc", "here is the description");
values.put("photo", "stub.png");
values.put("ingre", "the ingredients of the snack");
values.put("howto", "how to make this thing");
values.put("info", "basically its this much calorie and such and such");
db.insert("snacks", "name", values);
values.put("name", "Name 6");
values.put("disc", "here is the description");
values.put("photo", "stub.png");
values.put("ingre", "the ingredients of the snack");
values.put("howto", "how to make this thing");
values.put("info", "basically its this much calorie and such and such");
db.insert("snacks", "name", values);
values.put("name", "Name 7");
values.put("disc", "here is the description");
values.put("photo", "stub.png");
values.put("ingre", "the ingredients of the snack");
values.put("howto", "how to make this thing");
values.put("info", "basically its this much calorie and such and such");
db.insert("snacks", "name", values);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS snacks");
onCreate(db);
}}
Я не могу добавить какой-либо элемент или отредактировать какой-либо элемент без необходимости деинсталлировать приложение и затем переустановить :( ПОМОГИТЕ ПОЖАЛУЙСТА !!!много! * * 1004