List of usage examples for android.database Cursor close
void close();
From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java
public void setCurrentInfoSnapshot(long profileId) { Cursor cursor = queryServerProfile(profileId); if (cursor != null) { try {/*ww w . j ava2 s .co m*/ if (cursor.getCount() > 0) { cursor.moveToPosition(0); serverInfoSnapshot.setProfile(new ServerProfiles(cursor)); } } finally { cursor.close(); } } }
From source file:com.onesignal.OneSignal.java
static boolean isDuplicateNotification(String id, Context context) { if (id == null || "".equals(id)) return false; OneSignalDbHelper dbHelper = new OneSignalDbHelper(context); SQLiteDatabase readableDb = dbHelper.getReadableDatabase(); String[] retColumn = { NotificationTable.COLUMN_NAME_NOTIFICATION_ID }; String[] whereArgs = { id };/* ww w . j ava2 s.c o m*/ Cursor cursor = readableDb.query(NotificationTable.TABLE_NAME, retColumn, NotificationTable.COLUMN_NAME_NOTIFICATION_ID + " = ?", // Where String whereArgs, null, null, null); boolean exists = cursor.moveToFirst(); cursor.close(); readableDb.close(); if (exists) { Log(LOG_LEVEL.DEBUG, "Duplicate GCM message received, skipping processing. " + id); return true; } return false; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static Hashtable<String, Object> getHeaderRecordCatchedData(String group, long serverMsgNum, Context context) {//from w w w . ja v a2s . c o m int groupid = getGroupIdFromName(group, context); Hashtable<String, Object> result = null; DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); Cursor c = dbread.rawQuery("SELECT _id, server_article_id, catched FROM headers WHERE subscribed_group_id=" + groupid + " AND server_article_number=" + serverMsgNum, null); if (c.getCount() == 1) { c.moveToFirst(); result = new Hashtable<String, Object>(3); result.put("id", c.getInt(0)); result.put("server_article_id", c.getString(1)); if (c.getInt(2) == 1) result.put("catched", true); else result.put("catched", false); } c.close(); dbread.close(); db.close(); return result; }
From source file:com.googlecode.android_scripting.facade.ContactsFacade.java
@Rpc(description = "Content Resolver Query Attributes", returns = "a list of available columns for a given content uri") public JSONArray queryAttributes( @RpcParameter(name = "uri", description = "The URI, using the content:// scheme, for the content to retrieve.") String uri) throws JSONException { JSONArray result = new JSONArray(); Cursor cursor = mContentResolver.query(Uri.parse(uri), null, "1=0", null, null); if (cursor != null) { String[] names = cursor.getColumnNames(); for (String name : names) { result.put(name);//from w ww . j a va 2 s.c o m } cursor.close(); } return result; }
From source file:it.ms.theing.loquitur.functions.PhoneDir.java
private String getEmail(String ID) { Cursor emails = context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + ID, null, null); String s = ""; if (emails.moveToNext()) { s = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)); }/*from w w w . ja va 2s.c o m*/ emails.close(); return s; }
From source file:it.ms.theing.loquitur.functions.PhoneDir.java
private String getPhone(String ID) { Cursor phones = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + ID, null, null); String s = ""; if (phones.moveToNext()) { s = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); }//from w ww . java 2s . c om phones.close(); return s; }
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 {/* w w w .j a v a 2s . 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(); } }
From source file:com.bellman.bible.service.db.mynote.MyNoteDBAdapter.java
public MyNoteDto getMyNoteDto(long id) { MyNoteDto mynote = null;/*from www. jav a 2 s .co m*/ Cursor c = db.query(MyNoteQuery.TABLE, MyNoteQuery.COLUMNS, MyNoteColumn._ID + "=?", new String[] { String.valueOf(id) }, null, null, null); try { if (c.moveToFirst()) { mynote = getMyNoteDto(c); } } finally { c.close(); } return mynote; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static Set<Integer> getChildrenIds(String resourcePath) { Set<Integer> ids = new TreeSet<Integer>(); final String[] projection = new String[] { Nodes._ID, Nodes.NODE_RESOURCE_STATE }; final String selection = Nodes.NODE_PARENT_PATH + "=?"; //+ " AND " + Nodes.NODE_RESOURCE_STATE + " IS NULL"; // FIXME final String[] selectionArgs = new String[] { resourcePath }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); try {//from w ww. j a v a 2s . co m if (c.moveToFirst()) { int id; do { id = c.getInt(c.getColumnIndex(Nodes._ID)); // We check the state, above SQL is failing to filter out // nodes which are in non-null state. No idea why. String s = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_STATE)); if (s == null) { ids.add(id); } else { Log.d("MetaUtilities", "child state != null, ignoring"); } } while (c.moveToNext()); } } finally { c.close(); } return ids; }
From source file:jp.ac.tokushima_u.is.ll.io.LanguageJsonHandler.java
public ArrayList<ContentProviderOperation> parse(ContentResolver resolver) { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); Uri uri = Languages.CONTENT_URI; String sortOrder = SyncColumns.UPDATED + " desc"; Cursor cursor = resolver.query(uri, LanguagesQuery.PROJECTION, null, null, sortOrder); try {/*from w w w . j a va2 s .c om*/ if (cursor.moveToFirst()) { Log.d(TAG, "Language has been inserted"); int count = cursor.getCount(); if (count > 3) { return batch; } } } finally { cursor.close(); } HttpPost httpPost = new HttpPost(this.systemUrl + this.syncServiceUrl + this.languageSearchUrl); try { DefaultHttpClient client = HttpClientFactory.createHttpClient(); MultipartEntity params = new MultipartEntity(); httpPost.setEntity(params); HttpResponse response = client.execute(httpPost); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); String result = convertStreamToString(instream); instream.close(); JSONObject json = new JSONObject(result); if (json != null) { JSONArray array = json.getJSONArray("languages"); if (array != null) { for (int i = 0; i < array.length(); i++) { JSONObject o = array.getJSONObject(i); String languageId = o.getString("id"); if (languageId == null || languageId.length() <= 0) continue; ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(Languages.CONTENT_URI); builder.withValue(Languages.LANGUAGE_ID, languageId); if (o.getString("code") != null && o.getString("code").length() > 0 && !"null".equals(o.getString("code"))) builder.withValue(Languages.CODE, o.getString("code")); if (o.getString("name") != null && o.getString("name").length() > 0 && !"null".equals(o.getString("name"))) builder.withValue(Languages.NAME, o.getString("name")); builder.withValue(SyncColumns.UPDATED, Calendar.getInstance().getTimeInMillis()); batch.add(builder.build()); } } } } } catch (Exception e) { Log.d(TAG, "exception occured", e); } return batch; }