I want to make sure to delete a table (if it exists) before creating another table with the same name. But this does not happen, I realize because I make changes in the code and command to compile and execute, and I only notice the changes (which tells me that the new table was created) when I uninstall the application previously.
package net.eqsoft.pacienteapp;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class PacienteSQLiteHelper extends SQLiteOpenHelper {
String sqlDrop = "drop table if exists registro";
String sqlCreate = "create table registro (reg integer, familiar text)";
String sqlIniciar = "insert into registro (reg, familiar) values (2, 'none')";
public PacienteSQLiteHelper(Context context, String nombre, CursorFactory factory, int version) {
super(context, nombre, factory, version);
}
@Override
public void onCreate(SQLiteDatabase pacientedb) {
pacientedb.execSQL(sqlDrop);
pacientedb.execSQL(sqlCreate);
pacientedb.execSQL(sqlIniciar);
}
@Override
public void onUpgrade(SQLiteDatabase pacientedb, int versionAnterior, int versionNueva) {
pacientedb.execSQL("drop table if exists registro");
onCreate(pacientedb);
}
}