Skip to content

Instantly share code, notes, and snippets.

@showsky
Created July 21, 2014 08:29
Show Gist options
  • Select an option

  • Save showsky/3275bd1e3a40dc1fde56 to your computer and use it in GitHub Desktop.

Select an option

Save showsky/3275bd1e3a40dc1fde56 to your computer and use it in GitHub Desktop.
Content Provider recursive loop error
-----
private void insertVal(String val, int id) {
ContentValues r = new ContentValues();
r.put(COL_ID, Integer.valueOf(id));
r.put(KeyValContract.Columns.VAL, val);
getWriteableDatabase().insert(TAB_VALS, null, r);
}
-----
/*
Do not call getReadableDatabase or getWriteableDatabase
from an implementation of the onCreate method!
*/
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(“CREATE TABLE “ + TAB_VALS + “(“
+ COL_ID + “ integer PRIMARY KEY,”
+ KeyValContract.Columns.VAL + “ text)”);
// DON’T DO THIS!!!
insertVal(“bar”, 1);
// ...
}
/*
This won’t work. The call to getWriteableDatabase in insertVal
will cause a recursive loop.
ref: http://stackoverflow.com/questions/15955799/getdatabase-called-recursively
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment