英文:
I have problem keeping old data in SQL spreadsheet
问题
我已经在应用商店发布了我的应用程序,数据库版本是8,但出现了问题。数据库已经升级到版本10,并已添加了新的列,但现在我无法恢复旧数据,这会对用户造成很大伤害。所以我希望你提供一个有用的解决方案,不要删除先前的数据。
谢谢
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DB_BALL = "ball.db";
public DatabaseHelper(@Nullable Context context) {
super(context, DB_BALL, null, 10);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table volleyball_db " +
"( id INTEGER PRIMARY KEY AUTOINCREMENT, team_a TEXT ,goals_a TEXT," +
" team_b TEXT, goals_b TEXT, round TEXT, date_volleyball TEXT, clock_volleyball TEXT)");
db.execSQL("create table basketball_db " +
"( id INTEGER PRIMARY KEY AUTOINCREMENT, team_a TEXT ,goals_a TEXT," +
" team_b TEXT, goals_b TEXT, round TEXT, date_basketball TEXT,clock_basketball TEXT)");
db.execSQL("create table football_db " +
"( id INTEGER PRIMARY KEY AUTOINCREMENT, team_a TEXT ,goals_a TEXT, card_red_a TEXT, card_yellow_a TEXT," +
" team_b TEXT, goals_b TEXT , card_red_b TEXT, card_yellow_b TEXT, round TEXT, date_football TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS volleyball_db ");
db.execSQL("DROP TABLE IF EXISTS basketball_db ");
db.execSQL("DROP TABLE IF EXISTS football_db ");
onCreate(db);
}
}
英文:
I have already released my app in the app store and the database version was 8, but there is a problem. The database has already updated to version 10 and has already added new columns, but now I can't recover old data and this will hurt users a lot. So I wish you a useful solution that does not delete the previous data
Thank you
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DB_BALL = "ball.db";
public DatabaseHelper(@Nullable Context context) {
super(context, DB_BALL, null, 10);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table volleyball_db "+ "( id INTEGER PRIMARY KEY AUTOINCREMENT, team_a TEXT ,goals_a TEXT," +
" team_b TEXT, goals_b TEXT, round TEXT, date_volleyball TEXT, clock_volleyball TEXT)");
db.execSQL("create table basketball_db "+ "( id INTEGER PRIMARY KEY AUTOINCREMENT, team_a TEXT ,goals_a TEXT," +
" team_b TEXT, goals_b TEXT, round TEXT, date_basketball TEXT,clock_basketball TEXT)");
db.execSQL("create table football_db "+ "( id INTEGER PRIMARY KEY AUTOINCREMENT, team_a TEXT ,goals_a TEXT, card_red_a TEXT, card_yellow_a TEXT," +
" team_b TEXT, goals_b TEXT , card_red_b TEXT, card_yellow_b TEXT, round TEXT, date_football TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS volleyball_db ");
db.execSQL("DROP TABLE IF EXISTS basketball_db ");
db.execSQL("DROP TABLE IF EXISTS football_db ");
onCreate(db);
}
答案1
得分: 1
数据库表格被删除后,无法恢复数据。您应该使用 ALTER TABLE
更新表格。
英文:
Once the database tables have been dropped, you cannot recover the data. you should use ALTER TABLE
to update the tables
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论