How do you delete the SQlite table?
-
"DROP TABLE IF EXISTS" + TABLE_CONTACT does not remove the old table. What's wrong?
public class DBHelper extends SQLiteOpenHelper { public static final String TABLE_CONTACT = "autowash"; public static final String COLUMN_LATLNG = "latlng"; public static final String COLUMN_ID = "id"; public static final String COLUMN_NAME = "name"; public static final String COLUMN_SITY = "sity"; public static final String COLUMN_ADRESS = "adr"; public static final String COLUMN_PHONE = "phone"; public static final String COLUMN_BEGIN = "begin"; public static final String COLUMN_ENDING = "ending";
private static final String DATABASE_NAME = "autowash.db"; private static final int DATABASE_VERSION = 2; // Database creation sql statement private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_CONTACT + "(" + COLUMN_ID + " INTEGER PRIMARY KEY, " + COLUMN_NAME + " TEXT, " + COLUMN_SITY + " TEXT, " + COLUMN_LATLNG + " REAL, " + COLUMN_ADRESS + " TEXT, " + COLUMN_PHONE + " TEXT, " + COLUMN_BEGIN + " TEXT, " + COLUMN_ENDING + " TEXT " + ");"; public DBHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase database) { database.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (newVersion > oldVersion) { db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACT); onCreate(db); } } }
-
Are you sure this line is being implemented?
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACT);
After this request has been completed, the table shall be shattered. After you have the code:
onCreate(db);
of which
database.execSQL(DATABASE_CREATE);
which means the table is created again.
Method onUpgrade You fall in case the version of the db has changed that. DATABASE_VERSIONa condition
if (newVersion > oldVersion)
It is necessary to clarify the case (if you, for example, support the annex, which will often change versions of the bud and will need to be retained.
Try to undress and put the braacpoin on the line.
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACT);
It's got to be that way. If you change the code you gave DATABASE_VERSION Three, you'll get it after you've got the application. autowash.db with empty table autowash♪