List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:com.markupartist.sthlmtraveling.FavoritesFragment.java
private void updateListPosition(long id, boolean increase) { Uri uri = ContentUris.withAppendedId(Journeys.CONTENT_URI, id); Cursor cursor = getActivity().managedQuery(uri, PROJECTION, null, null, null); cursor.moveToFirst();/* w ww .j a va 2 s .c o m*/ int position = cursor.getInt(COLUMN_INDEX_POSITION); if (increase) { position = position + 1; } else { position = position - 1; } ContentValues values = new ContentValues(); values.put(Journeys.POSITION, position); getActivity().getContentResolver().update(uri, values, null, null); }
From source file:com.googlecode.android_scripting.facade.ContactsFacade.java
@Rpc(description = "Returns a List of all contact IDs.") public List<Integer> contactsGetIds() { List<Integer> result = new ArrayList<Integer>(); String[] columns = { "_id" }; Cursor cursor = mContentResolver.query(CONTACTS_URI, columns, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { result.add(cursor.getInt(0)); }/*from w ww . j a v a 2 s .com*/ cursor.close(); } return result; }
From source file:com.earthblood.tictactoe.activity.GameActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { int[] XIds = new int[9]; int countX = 0; int[] OIds = new int[9]; int countO = 0; data.moveToFirst();//from w w w. ja va 2 s.com while (data.isAfterLast() == false) { int boxId = data.getInt(1); int gameSymbolId = data.getInt(2); if (GameSymbol.X.getId() == gameSymbolId) { XIds[countX++] = boxId; } else { OIds[countO++] = boxId; } Button button = (Button) gridLayout.findViewById(GameBox.byLayoutId(boxId).layoutBoxId()); button.setText(GameSymbol.byId(gameSymbolId).getValue()); button.setEnabled(false); data.moveToNext(); } if (toeGame.inProgress()) { endTurn(XIds, OIds, data.getCount()); } }
From source file:foam.zizim.android.BoskoiService.java
public static CategoriesData[] getCategoriesDetails(String categoryIds) { String[] categories = categoryIds.split(","); CategoriesData result[] = new CategoriesData[categories.length]; int i = 0;/*www. j a va2 s. co m*/ for (String categoryId : categories) { Cursor cursor = BoskoiApplication.mDb.fetchCategoriesById(Integer.parseInt(categoryId)); if (cursor.moveToFirst()) { int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE); int titleNL = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_NL); int titleLA = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_LA); int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_ID); int parentId = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_PARENT_ID); int color = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_COLOR); int desc = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_DESC); CategoriesData cat = new CategoriesData(); cat.setCategoryId(cursor.getInt(idIndex)); cat.setCategoryTitle(cursor.getString(titleIndex)); cat.setCategoryTitleNL(cursor.getString(titleNL)); cat.setCategoryTitleLA(cursor.getString(titleLA)); cat.setCategoryParentId(cursor.getInt(parentId)); cat.setCategoryColor(cursor.getString(color)); cat.setCategoryDescription(cursor.getString(desc)); result[i] = cat; i++; } cursor.close(); } return result; }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
/** * ??ID????//w ww. j a v a 2 s. co m * * @param threadId ??ID * @return ? */ public static int getTotalCount(long threadId) { String sql = "SELECT COUNT(*) FROM " + DatabaseHelper.TABLES_NAME_IM_MESSAGE + " WHERE " + "sid" + "=" + threadId; Cursor cursor = getInstance().sqliteDB().rawQuery(sql, null); int count = 0; if (cursor.moveToLast()) { count = cursor.getInt(0); } cursor.close(); return count; }
From source file:com.github.gw2app.events.Gw2ApiEvents.java
private HashMap<Integer, String> _getMapNamesFromDB() { Log.d("Gw2", "Fetching map names from DB."); SQLiteDatabase db = this.dbhelper.getReadableDatabase(); Cursor cursor = db.query(Gw2DB.MAP_NAMES_TABLE, null, null, null, null, null, null); cursor.moveToFirst();/*from ww w . jav a 2 s . c om*/ HashMap<Integer, String> mapNames = new HashMap<Integer, String>(); while (!cursor.isLast()) { Integer id = cursor.getInt(0); String name = cursor.getString(1); mapNames.put(id, name); cursor.moveToNext(); } cursor.close(); return mapNames; }
From source file:com.odoo.support.provider.OContentProvider.java
@Override public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { reInitModel();/*from w w w .ja v a 2 s . c om*/ SelectionBuilder builder = new SelectionBuilder(); final SQLiteDatabase db = model.getWritableDatabase(); final int match = matcher.match(uri); int count; switch (match) { case COLLECTION: Cursor cr = query(uri, new String[] { OColumn.ROW_ID }, where, whereArgs, null); while (cr.moveToNext()) { int id = cr.getInt(cr.getColumnIndex(OColumn.ROW_ID)); handleManyToMany(getManyToManyRecords(values), id); } cr.close(); count = builder.table(model.getTableName()).where(where, whereArgs).update(db, values); break; case SINGLE_ROW: String id = uri.getLastPathSegment(); handleManyToMany(getManyToManyRecords(values), Integer.parseInt(id)); count = builder.table(model.getTableName()).where(where, whereArgs).where(OColumn.ROW_ID + "=?", id) .where(where, whereArgs).update(db, values); break; default: throw new UnsupportedOperationException("Unknown uri: " + uri); } Context ctx = getContext(); assert ctx != null; ctx.getContentResolver().notifyChange(uri, null, false); return count; }
From source file:com.github.gw2app.events.Gw2ApiEvents.java
private HashMap<Integer, String> _getWorldNamesFromDB() { Log.d("Gw2", "Fetching world names from DB."); SQLiteDatabase db = this.dbhelper.getReadableDatabase(); Cursor cursor = db.query(Gw2DB.WORLD_NAMES_TABLE, null, null, null, null, null, null); cursor.moveToFirst();// w w w. j a v a 2 s . co m HashMap<Integer, String> worldNames = new HashMap<Integer, String>(); while (!cursor.isLast()) { Integer id = cursor.getInt(0); String name = cursor.getString(1); worldNames.put(id, name); cursor.moveToNext(); } cursor.close(); return worldNames; }
From source file:com.granita.contacticloudsync.syncadapter.AccountSettings.java
@SuppressWarnings("Recycle") private void update_0_1() throws URISyntaxException { String v0_principalURL = accountManager.getUserData(account, "principal_url"), v0_addressBookPath = accountManager.getUserData(account, "addressbook_path"); Constants.log.debug("Old principal URL = " + v0_principalURL); Constants.log.debug("Old address book path = " + v0_addressBookPath); URI principalURI = new URI(v0_principalURL); // update address book if (v0_addressBookPath != null) { String addressBookURL = principalURI.resolve(v0_addressBookPath).toASCIIString(); Constants.log.debug("New address book URL = " + addressBookURL); accountManager.setUserData(account, "addressbook_url", addressBookURL); }//from ww w . j a v a2s .c o m // update calendars ContentResolver resolver = context.getContentResolver(); Uri calendars = Calendars.CONTENT_URI.buildUpon().appendQueryParameter(Calendars.ACCOUNT_NAME, account.name) .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type) .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true").build(); @Cleanup Cursor cursor = resolver.query(calendars, new String[] { Calendars._ID, Calendars.NAME }, null, null, null); while (cursor != null && cursor.moveToNext()) { int id = cursor.getInt(0); String v0_path = cursor.getString(1), v1_url = principalURI.resolve(v0_path).toASCIIString(); Constants.log.debug("Updating calendar #" + id + " name: " + v0_path + " -> " + v1_url); Uri calendar = ContentUris.appendId( Calendars.CONTENT_URI.buildUpon().appendQueryParameter(Calendars.ACCOUNT_NAME, account.name) .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type) .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true"), id).build(); ContentValues newValues = new ContentValues(1); newValues.put(Calendars.NAME, v1_url); if (resolver.update(calendar, newValues, null, null) != 1) Constants.log.debug("Number of modified calendars != 1"); } accountManager.setUserData(account, "principal_url", null); accountManager.setUserData(account, "addressbook_path", null); accountManager.setUserData(account, KEY_SETTINGS_VERSION, "1"); }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java
public JSONArray getAlljsonData() { JSONArray jArray = new JSONArray(); String q = "SELECT * FROM " + LocalTransformationDB.TABLE_JSON_DATA_EXCHANGE + " ORDER BY " + LocalTransformationDB.COLUMN_JSON_ID + ";"; Cursor cursor = database.rawQuery(q, null); if (cursor.moveToFirst()) { do {// ww w .ja v a 2 s . co m String contents = cursor.getString(cursor.getColumnIndex(LocalTransformationDB.COUMN_JSON_CONTENT)); int id = cursor.getInt(cursor.getColumnIndex(LocalTransformationDB.COLUMN_JSON_ID)); try { JSONObject jObj = new JSONObject(contents); jObj.put(JSONDataExchange.JSON_CONTENT_ID, id); jArray.put(jObj); } catch (JSONException e) { e.printStackTrace(); } } while (cursor.moveToNext()); } cursor.close(); return jArray; }