I have a table that has a Column called "color." In the database previously the "color" column did not exist. It is now there so about half of my entries have the "color" column.
When I attempt to retrieve all of my entries I get:
android.database.sqlite.SQLiteException: no such column: color (code 1): , while compiling: SELECT color FROM locationsxyz WHERE fieldname = ?
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
How do I continue to retrieve my table data to show the color column when it exists and to show "no data" when it does not exist when calling my entire table? Is there a preferred method for handling this condition?
Here is my DB file:
public String getFieldColor(){
String fieldcolor = new String();
String selectQuery = "SELECT " + COLOR + " FROM " + DATABASE_TABLE + " WHERE" + " fieldname = ?" ;
SQLiteDatabase db = this.getReadableDatabase();
String logitem = Logs.getLabel();
Cursor c= db.rawQuery(selectQuery, new String[] {logitem});
c.moveToFirst();
while (!c.isAfterLast()) {
fieldcolor = c.getString(c.getColumnIndex(LocationsDB.COLOR));
c.moveToNext();
}
c.close();
db.close();
return fieldcolor;
}
Aucun commentaire:
Enregistrer un commentaire