List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
From source file:com.jpa.JPAApplication.java
public ArrayList<String> getDbAuth() { DbModel db = new DbModel(getApplicationContext()); ArrayList<String> s = new ArrayList<String>(); db.open();//w w w . j a v a 2 s .c o m Cursor c = db.getDbAuth(); int urlCol = c.getColumnIndex(DbModel.MetaData.JPA_URL_KEY); int passwordCol = c.getColumnIndex(DbModel.MetaData.JPA_PASSWORD_KEY); c.moveToFirst(); s.add(c.getString(urlCol)); s.add(c.getString(passwordCol)); db.close(); return s; }
From source file:com.ruuhkis.cookies.CookieSQLSource.java
/** * /* w w w . j a v a 2s . c o m*/ * @return a list of all cookies stored in cookies table */ public List<SQLCookie> getCookies() { List<SQLCookie> cookies = new ArrayList<SQLCookie>(); Cursor cursor = db.query(CookieSQLHelper.COOKIE_TABLE_NAME, null, null, null, null, null, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { cookies.add(cursorToCookie(cursor)); cursor.moveToNext(); } cursor.close(); return cookies; }
From source file:edu.asu.bscs.csiebler.waypointdatabase.MainActivity.java
private JSONArray getJsonResults() { JSONArray resultSet = new JSONArray(); try {//from w ww . ja v a2 s . c o m WaypointDB db = new WaypointDB(this); db.copyDB(); SQLiteDatabase waypointDB = db.openDB(); waypointDB.beginTransaction(); String searchQuery = "SELECT * FROM waypoint"; Cursor cursor = waypointDB.rawQuery(searchQuery, null); cursor.moveToFirst(); while (cursor.isAfterLast() == false) { int totalColumn = cursor.getColumnCount(); JSONObject rowObject = new JSONObject(); for (int i = 0; i < totalColumn; i++) { if (cursor.getColumnName(i) != null) { try { if (cursor.getString(i) != null) { Log.d("TAG_NAME", cursor.getString(i)); rowObject.put(cursor.getColumnName(i), cursor.getString(i)); } else { rowObject.put(cursor.getColumnName(i), ""); } } catch (Exception e) { Log.d("TAG_NAME", e.getMessage()); } } } resultSet.put(rowObject); cursor.moveToNext(); } cursor.close(); waypointDB.endTransaction(); waypointDB.close(); db.close(); Log.d("TAG_NAME", resultSet.toString()); } catch (Exception ex) { Log.w(getClass().getSimpleName(), "Exception creating adapter: " + ex.getMessage()); } return resultSet; }
From source file:com.pdftron.pdf.utils.Utils.java
public static String getRealPathFromImageURI(Context context, Uri contentUri) { if (null == context || null == contentUri) { return ""; }//from w w w.jav a2s . co m Cursor cursor = null; try { // can post image String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) if (null != cursor) { cursor.moveToFirst(); int column_index = cursor.getColumnIndexOrThrow(proj[0]); return cursor.getString(column_index); } return ""; } catch (Exception e) { AnalyticsHandlerAdapter.getInstance().sendException(e); } finally { if (cursor != null) { cursor.close(); } } return ""; }
From source file:DictionaryDatabase.java
public long findWordID(String word) { long returnVal = -1; SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.rawQuery("SELECT _id FROM " + TABLE_DICTIONARY + " WHERE " + FIELD_WORD + " = ?", new String[] { word }); if (cursor.getCount() == 1) { cursor.moveToFirst(); returnVal = cursor.getInt(0);// w w w .j a va 2 s .c om } return returnVal; }
From source file:com.looseboxes.idisc.common.util.ContactEmailsExtractor.java
public JSONObject getNameEmailDetails(Context context) { JSONObject emailsMap = new JSONObject(); Set<String> emailsSet = new HashSet<String>(); ContentResolver contentResolver = context.getContentResolver(); String[] PROJECTION = new String[] { ContactsContract.RawContacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.PHOTO_ID, ContactsContract.CommonDataKinds.Email.DATA, ContactsContract.CommonDataKinds.Photo.CONTACT_ID }; String order = "CASE WHEN " + ContactsContract.Contacts.DISPLAY_NAME + " NOT LIKE '%@%' THEN 1 ELSE 2 END, " + ContactsContract.Contacts.DISPLAY_NAME + ", " + ContactsContract.CommonDataKinds.Email.DATA + " COLLATE NOCASE"; String filter = ContactsContract.CommonDataKinds.Email.DATA + " NOT LIKE ''"; Cursor cur = contentResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, PROJECTION, filter, null, order);/*w w w. j a v a2 s. c o m*/ if (cur.moveToFirst()) { do { // names comes in hand sometimes String name = cur.getString(1); String email = cur.getString(3); // keep unique only if (emailsSet.add(email.toLowerCase())) { emailsMap.put(email, name); } } while (cur.moveToNext()); } cur.close(); return emailsMap; }
From source file:de.golov.zeitgeistreich.ZeitGeistReichActivity.java
protected void submitImage(String tags) { Intent intent = getIntent();//from w w w .j a v a2 s .co m Bundle extras = intent.getExtras(); Uri mImageUri = null; File mFilename = null; if (Intent.ACTION_SEND.equals(intent.getAction()) && extras != null) { if (extras.containsKey(Intent.EXTRA_STREAM)) { mImageUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); if (mImageUri != null) { Cursor cursor = getContentResolver().query(mImageUri, null, null, null, null); if (cursor.moveToFirst()) { mFilename = new File(cursor.getString(cursor.getColumnIndexOrThrow(ImageColumns.DATA))); } cursor.close(); if (mFilename != null) { ZeitGeistReichUploaderTask task = new ZeitGeistReichUploaderTask(); ZeitGeistObject o = new ZeitGeistObject(mFilename, tags); task.execute(o); } } } } }
From source file:com.tct.mail.providers.Attachment.java
/** * Get the value of the data column for this Uri. This is useful for * MediaStore Uris, and other file-based ContentProviders. * * @param context The context./*ww w.j a v a2s . co m*/ * @param uri The Uri to query. * @param selection (Optional) Filter used in the query. * @param selectionArgs (Optional) Selection arguments used in the query. * @return The value of the _data column, which is typically a file path. */ public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S if (uri == null) { return null; } //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } catch (IllegalArgumentException e) { LogUtils.e(LOG_TAG, e, "ArgumentException in projection"); } // TS: Gantao 2016-02-19 EMAIL BUGFIX_1650866 ADD_S catch (NullPointerException e) { LogUtils.e(LOG_TAG, e, "NullPointerException while query"); } // TS: Gantao 2016-02-19 EMAIL BUGFIX_1650866 ADD_E finally { if (cursor != null) cursor.close(); } return null; }
From source file:DictionaryDatabase.java
public String getDefinition(long id) { String returnVal = ""; SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.rawQuery("SELECT definition FROM " + TABLE_DICTIONARY + " WHERE _id = ?", new String[] { String.valueOf(id) }); if (cursor.getCount() == 1) { cursor.moveToFirst(); returnVal = cursor.getString(0); }// w w w . j a v a 2 s. c o m return returnVal; }
From source file:com.hemou.android.core.sync.persistence.DatabaseCache.java
private <E> List<E> loadFromDB(final SQLiteOpenHelper helper, final PersistableResource<E> persistableResource) { final SQLiteDatabase db = getReadable(helper); if (db == null) return null; Cursor cursor = persistableResource.getCursor(db); try {/*from w w w . j ava2 s .c o m*/ if (!cursor.moveToFirst()) return null; List<E> cached = new ArrayList<E>(); do cached.add(persistableResource.loadFrom(cursor)); while (cursor.moveToNext()); return cached; } finally { cursor.close(); } }