我在 SQL 电子表格中保留旧数据时遇到问题。

huangapple go评论82阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年4月9日 04:11:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/61109222.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定