I’m trying to modify an SQL table to have true false values. I am using type BIT for a 1 or 0. I tried to alter the table but it does not seems to be working properly. The column index is -1.
For my sqlitehelper class, I tried using this for my onupgrade method:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.d(TAG,"inner onupgrade called");
Log.w(TAG, "Upgrading database from version "
+ oldVersion + " to "
+ newVersion + ", which will destroy all old data");
//db.execSQL("DROP TABLE IF EXISTS " + TableMetaData.TABLE_NAME);
db.execSQL("ALTER TABLE " + TableMetaData.TABLE_NAME
+ " ADD COLUMN " + TableMetaData.HAS_UPLOADED + " BIT DEFAULT 0"
+ ";");
//onCreate(db);
}
When I try to read the column later in my app I get an error and I find that the column index is -1. Am I modifying the table correctly?
Here is the error I get from the logcat:
03-27 17:48:37.111: E/CursorWindow(2884): Bad request for field slot 0,-1. numRows = 1, numColumns = 5
03-27 17:48:37.111: D/AndroidRuntime(2884): Shutting down VM
03-27 17:48:37.111: W/dalvikvm(2884): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
03-27 17:48:37.131: E/AndroidRuntime(2884): FATAL EXCEPTION: main
03-27 17:48:37.131: E/AndroidRuntime(2884): java.lang.IllegalStateException: get field slot from row 0 col -1 failed
03-27 17:48:37.131: E/AndroidRuntime(2884): at android.database.CursorWindow.getString_native(Native Method)
03-27 17:48:37.131: E/AndroidRuntime(2884): at android.database.CursorWindow.getString(CursorWindow.java:329)
03-27 17:48:37.131: E/AndroidRuntime(2884): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
In the contentprovider I did not add the column in the hashmap.