mardi 15 décembre 2015

How to remove the table SQlite?

I create a table in a database, and when trying to overwrite the data, then "DROP TABLE IF EXISTS" + TABLE CONTACT can not remove the old table. What is wrong?

This my DBHeper class

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;

        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);
           }
        }
    }

Aucun commentaire:

Enregistrer un commentaire