0

I'm trying to store a set of string variables into an SQLite database, it worked until I added two more columns called "Weight" and "Goal". Unfortunately, whenever I try to compile it now it stops working, stating that

04-21 20:19:11.675    2000-2000/com.example.wolfe_000.final_final_zeno E/SQLiteLog﹕ (1) table Registered_Info has no column named Goal

As I said before it worked before I added weight and goal, here is the code for the database operations:

public class DatabaseOperations extends SQLiteOpenHelper {

public static int database_version = 1;
public String CREATE_QUERY = "CREATE TABLE "+TableData.TableInfo.TABLE_NAME + "("+TableData.TableInfo.USER_NAME+" TEXT,"+TableData.TableInfo.USER_PASS+" TEXT,"+TableData.TableInfo.USER_EMAIL+" TEXT,"+ TableData.TableInfo.USER_WEIGHT+" TEXT,"+ TableData.TableInfo.USER_GOAL+" TEXT );";


public DatabaseOperations(Context context) {
    super(context, TableData.TableInfo.DATABASE_NAME, null, database_version);
    Log.d("Database Operations", "Database Created");
}

@Override
public void onCreate(SQLiteDatabase sdb) {
    sdb.execSQL(CREATE_QUERY);
    Log.d("Database Operations", "Table Created");
    sdb.close();
}

@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {

}

public void putInformation(DatabaseOperations dop, String name, String pass, String email, String weight, String goal) {
    SQLiteDatabase SQ = dop.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put(TableData.TableInfo.USER_NAME, name);
    cv.put(TableData.TableInfo.USER_PASS, pass);
    cv.put(TableData.TableInfo.USER_EMAIL, email);
    cv.put(TableData.TableInfo.USER_WEIGHT,weight);
    cv.put(TableData.TableInfo.USER_GOAL,goal);
    long k = SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
    Log.d("Database Operations", "One Row Inserted");
    SQ.close();
}

public Cursor getInformation(DatabaseOperations dop){
    SQLiteDatabase SQ = dop.getReadableDatabase();
    String[] columns = {TableData.TableInfo.USER_NAME, TableData.TableInfo.USER_PASS, TableData.TableInfo.USER_EMAIL, TableData.TableInfo.USER_WEIGHT, TableData.TableInfo.USER_GOAL};
    Cursor CR = SQ.query(TableData.TableInfo.TABLE_NAME, columns, null, null, null, null, null);
    return CR;
}

1 Answers1

0

change database_version = 2; or delete app from device.

then try

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.w(NkSQLiteOpenHelper.class.getName(),
            "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
    onCreate(db);
}
nkcode
  • 361
  • 3
  • 12