lundi 20 juillet 2015

Upgrade my Database

I have a database on my apps, but I have 2 problems:

  • The Database name don't correspond to which i writted:

An error:

sqlite returned: error code = 1, msg = table demandes has no column named dateEnvoie, db=/data/data/(package)/databases/google_analytics_v4.db

My code :

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "Solutis";

// Contacts table name
private static final String TABLE_DEMANDES = "demandes";

// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_XML = "xml";
private static final String KEY_STATUTENVOIE = "statutEnvoie";
private static final String KEY_DATEENVOIE = "dateEnvoie";

public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

Error say that my db name is = google_analytics_v4.db but in my code DATABASE_NAME = "Solutis".

  • My second problem is the Database Upgrade, I did some changes (i added a column)

I have to call it:

// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_DEMANDES);

    // Create tables again
    onCreate(db);
}

But how to do ? I'm working in a Fragment, what I pass in parameters ?

Aucun commentaire:

Enregistrer un commentaire