List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java
public JsServerProfile createProfileFromCursor(Cursor cursor) { long id = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID)); ServerProfiles dbProfile = new ServerProfiles(cursor); return new JsServerProfile(id, dbProfile.getAlias(), dbProfile.getServerUrl(), dbProfile.getOrganization(), dbProfile.getUsername(), dbProfile.getPassword()); }
From source file:com.ruuhkis.cookies.CookieSQLSource.java
/** * Creates SQLCookie from cursor that is assumed * to be located at SQLCookie entry/*from ww w .j a v a2 s.c om*/ * @param cursor * @return */ private SQLCookie cursorToCookie(Cursor cursor) { SQLCookie cookie = new SQLCookie(); cookie.setComment(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COMMENT))); cookie.setCommentURL(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COMMENT_URL))); cookie.setDomain(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_DOMAIN))); long expiryDate = cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_EXPIRY_DATE)); cookie.setExpiryDate(expiryDate != -1 ? new Date(expiryDate) : null); cookie.setName(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_NAME))); cookie.setPath(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PATH))); cookie.setPersistent(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PERSISTENT)) == 1); cookie.setPorts(getPorts(cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_ID)))); cookie.setSecure(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_SECURE)) == 1); cookie.setValue(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_VALUE))); cookie.setVersion(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_VERSION))); cookie.setId(cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_ID))); return cookie; }
From source file:com.android.emailcommon.provider.Account.java
public static Account restoreAccountWithAddress(Context context, String emailAddress, ContentObserver observer) {//from w w w . j a va2s. c o m final Cursor c = context.getContentResolver().query(CONTENT_URI, new String[] { AccountColumns._ID }, AccountColumns.EMAIL_ADDRESS + "=?", new String[] { emailAddress }, null); try { if (c == null || !c.moveToFirst()) { return null; } final long id = c.getLong(c.getColumnIndex(AccountColumns._ID)); return restoreAccountWithId(context, id, observer); } finally { if (c != null) { c.close(); } } }
From source file:net.benmoran.affectsampler.AffectSerializer.java
public JSONArray toJSONArray() throws JSONException { Uri samples = AffectSamples.CONTENT_URI; String[] projection = new String[] { AffectSamples.COMMENT, AffectSamples.SCHEDULED_DATE, AffectSamples.CREATED_DATE, AffectSamples.EMOTION, AffectSamples.INTENSITY }; Cursor cursor = mContentResolver.query(samples, projection, null, null, AffectSamples.CREATED_DATE + " ASC"); JSONArray arr = new JSONArray(); int emIndex = cursor.getColumnIndex(AffectSamples.EMOTION); int inIndex = cursor.getColumnIndex(AffectSamples.INTENSITY); int cdIndex = cursor.getColumnIndex(AffectSamples.CREATED_DATE); int sdIndex = cursor.getColumnIndex(AffectSamples.SCHEDULED_DATE); int coIndex = cursor.getColumnIndex(AffectSamples.COMMENT); for (cursor.moveToPosition(0); !cursor.isLast(); cursor.moveToNext()) { JSONObject o = new JSONObject(); o.put(AffectSamples.EMOTION, cursor.getDouble(emIndex)); o.put(AffectSamples.INTENSITY, cursor.getDouble(inIndex)); if (cursor.getLong(sdIndex) > 0) { o.put(AffectSamples.SCHEDULED_DATE, cursor.getLong(sdIndex)); } else {/*from w w w . ja v a 2 s. com*/ o.put(AffectSamples.SCHEDULED_DATE, null); } o.put(AffectSamples.CREATED_DATE, cursor.getLong(cdIndex)); if (cursor.getString(coIndex) != null) { o.put(AffectSamples.COMMENT, cursor.getString(coIndex)); } else { o.put(AffectSamples.COMMENT, null); } arr.put(o); } cursor.close(); return arr; }
From source file:com.textuality.lifesaver2.Columns.java
public String cursorToKey(Cursor c) { if (mKey1Index == -1) { mKey1Index = c.getColumnIndex(mKey1); mKey2Index = c.getColumnIndex(mKey2); }/*from www . j a v a 2 s . co m*/ return c.getString(mKey1Index) + "/" + c.getString(mKey2Index); }
From source file:com.android.email.provider.EmailMessageCursor.java
public EmailMessageCursor(final Context c, final Cursor cursor, final String htmlColumn, final String textColumn) { super(cursor); mHtmlColumnIndex = cursor.getColumnIndex(htmlColumn); mTextColumnIndex = cursor.getColumnIndex(textColumn); final int cursorSize = cursor.getCount(); mHtmlParts = new SparseArray<String>(cursorSize); mTextParts = new SparseArray<String>(cursorSize); final ContentResolver cr = c.getContentResolver(); while (cursor.moveToNext()) { final int position = cursor.getPosition(); final long messageId = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); try {/*from ww w . j a v a 2 s . c o m*/ if (mHtmlColumnIndex != -1) { final Uri htmlUri = Body.getBodyHtmlUriForMessageWithId(messageId); final InputStream in = cr.openInputStream(htmlUri); final String underlyingHtmlString; try { underlyingHtmlString = IOUtils.toString(in); } finally { in.close(); } final String sanitizedHtml = HtmlSanitizer.sanitizeHtml(underlyingHtmlString); mHtmlParts.put(position, sanitizedHtml); } } catch (final IOException e) { LogUtils.v(LogUtils.TAG, e, "Did not find html body for message %d", messageId); } try { if (mTextColumnIndex != -1) { final Uri textUri = Body.getBodyTextUriForMessageWithId(messageId); final InputStream in = cr.openInputStream(textUri); final String underlyingTextString; try { underlyingTextString = IOUtils.toString(in); } finally { in.close(); } mTextParts.put(position, underlyingTextString); } } catch (final IOException e) { LogUtils.v(LogUtils.TAG, e, "Did not find text body for message %d", messageId); } } cursor.moveToPosition(-1); }
From source file:com.mobeelizer.mobile.android.types.FileFieldTypeHelper.java
@Override public <T> void setValueFromDatabaseToEntity(final Cursor cursor, final T entity, final MobeelizerFieldAccessor field, final Map<String, String> options) { int columnIndex = cursor.getColumnIndex(field.getName() + FileFieldTypeHelper._GUID); if (cursor.isNull(columnIndex)) { return;/* w w w . ja v a2s.c om*/ } String[] file = new String[] { cursor.getString(columnIndex), cursor.getString(cursor.getColumnIndex(field.getName() + FileFieldTypeHelper._NAME)) }; MobeelizerFile mobeelizerFile = (MobeelizerFile) getType().convertFromDatabaseValueToEntityValue(field, file); setValue(field, entity, new MobeelizerFileImpl(mobeelizerFile.getName(), mobeelizerFile.getGuid())); }
From source file:com.android.unit_tests.CheckinProviderTest.java
@MediumTest public void testStatsUpdate() { ContentResolver r = getContext().getContentResolver(); // First, delete any existing data associated with the TEST tag. Uri uri = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, 0, 0); assertNotNull(uri);/*from w ww .jav a 2s. c o m*/ assertEquals(1, r.delete(uri, null, null)); assertFalse(r.query(uri, null, null, null, null).moveToNext()); // Now, add a known quantity to the TEST tag. Uri u2 = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, 1, 0.5); assertFalse(uri.equals(u2)); Cursor c = r.query(u2, null, null, null, null); assertTrue(c.moveToNext()); assertEquals(1, c.getInt(c.getColumnIndex(Checkin.Stats.COUNT))); assertEquals(0.5, c.getDouble(c.getColumnIndex(Checkin.Stats.SUM))); assertFalse(c.moveToNext()); // Only one. // Add another known quantity to TEST (should sum with the first). Uri u3 = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, 2, 1.0); assertEquals(u2, u3); c.requery(); assertTrue(c.moveToNext()); assertEquals(3, c.getInt(c.getColumnIndex(Checkin.Stats.COUNT))); assertEquals(1.5, c.getDouble(c.getColumnIndex(Checkin.Stats.SUM))); assertFalse(c.moveToNext()); // Only one. // Now subtract the values; the whole row should disappear. Uri u4 = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, -3, -1.5); assertNull(u4); c.requery(); assertFalse(c.moveToNext()); // Row has been deleted. c.close(); }
From source file:edu.mit.mobile.android.locast.data.JsonSyncableItem.java
/** * @param context/*from ww w . j a v a 2s . co m*/ * @param localItem Will contain the URI of the local item being referenced in the cursor * @param c active cursor with the item to sync selected. * @param mySyncMap * @return a new JSONObject representing the item * @throws JSONException * @throws NetworkProtocolException * @throws IOException */ public final static JSONObject toJSON(Context context, Uri localItem, Cursor c, SyncMap mySyncMap) throws JSONException, NetworkProtocolException, IOException { final JSONObject jo = new JSONObject(); for (final String lProp : mySyncMap.keySet()) { final SyncItem map = mySyncMap.get(lProp); if (!map.isDirection(SyncItem.SYNC_TO)) { continue; } final int colIndex = c.getColumnIndex(lProp); // if it's a real property that's optional and is null on the local side if (!lProp.startsWith("_") && map.isOptional()) { if (colIndex == -1) { throw new RuntimeException("Programming error: Cursor does not have column '" + lProp + "', though sync map says it should. Sync Map: " + mySyncMap); } if (c.isNull(colIndex)) { continue; } } final Object jsonObject = map.toJSON(context, localItem, c, lProp); if (jsonObject instanceof MultipleJsonObjectKeys) { for (final Entry<String, Object> entry : ((MultipleJsonObjectKeys) jsonObject).entrySet()) { jo.put(entry.getKey(), entry.getValue()); } } else { jo.put(map.remoteKey, jsonObject); } } return jo; }
From source file:com.putlocker.upload.concurrency.PutlockerDownloadJob.java
@Override public void parseResult(Cursor cursor) { int url_key = cursor.getColumnIndex(DOWNLOAD_URL_KEY); int status_column_key = cursor.getColumnIndex(DOWNLOAD_STATUS_KEY); int file_name_key = cursor.getColumnIndex(DOWNLOAD_FILENAME_KEY); int download_type_key = cursor.getColumnIndex(DOWNLOAD_TYPE_KEY); int file_size_index = cursor.getColumnIndex(DOWNLOAD_FILE_SIZE_KEY); int file_location_index = cursor.getColumnIndex(DOWNLOAD_FILE_LOCATION); int id_key = cursor.getColumnIndex(getIdKey()); int original_file_location = cursor.getColumnIndex(DOWNLOAD_ORIGINAL_FILE_LOCATION); _id = cursor.getInt(id_key);//from w w w . j a v a2 s . co m url = cursor.getString(url_key); setStatus(DownloadStatus.statusForString(cursor.getString(status_column_key))); _fileLocation = cursor.getString(file_location_index); _fileName = cursor.getString(file_name_key); type = DownloadType.getTypeForInt(Integer.valueOf(cursor.getString(download_type_key))); _fileSize = Long.valueOf(cursor.getString(file_size_index)); _originalFileLocation = cursor.getString(original_file_location); }