public void runInternal() throws DatabaseUnavailableException { SQLiteDatabase database = HubApplication._().getDatabaseHandle(); Cursor c = database.query("SyncableUser", null, null, null, null, null, null); try { SyncableUser actionable = null; for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { SyncableUser u = SyncableUser.fromDb(c); if (u.getStatus() != SyncableUser.UserStatus.ModelFetched && u.getStatus() != SyncableUser.UserStatus.AuthError) { //Only grab the first user to act on, we don't wanna be greedy in this thread actionable = u; break; } } if (actionable == null) { return; } if (actionable.getStatus() == SyncableUser.UserStatus.Requested) { fetchKeyForUser(actionable, database); } else if(actionable.getStatus() == SyncableUser.UserStatus.KeysFetched) { try { fetchModelForUser(actionable, database); } catch(IOException ioe) { ServicesMonitor.reportMessage("Error fetching user model for " + actionable.getUsername()+ " - " + ioe.getMessage()); } } } finally { c.close(); } }
@OnClick({R.id.add_data, R.id.query_data}) public void onClick(View view) { switch (view.getId()) { case R.id.add_data: ContentValues values = new ContentValues(); values.put("name", "GOT"); values.put("pages", 566); database.insert("Book", null, values); break; case R.id.query_data: Cursor cursor = database.query("Book", null, null, null, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { String name = cursor.getString(cursor.getColumnIndex("name")); int pages = cursor.getInt(cursor.getColumnIndex("pages")); Log.d("TAG", "book names is " + name); Log.d("TAG", "book pages is " + pages); } } cursor.close(); break; } }