List of usage examples for android.database Cursor close
void close();
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
/** * ??ID????//from w w w. ja v a 2s .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:org.noorganization.instalistsynch.controller.local.dba.impl.ClientLogDbController.java
@Override public Date getLeastRecentUpdateTimeForUuid(String _clientUuid) { Cursor cursor = mContentResolver.query(Uri.withAppendedPath(InstalistProvider.BASE_CONTENT_URI, "log"), LogInfo.COLUMN.ALL_COLUMNS, LogInfo.COLUMN.ITEM_UUID + " LIKE ? ", new String[] { _clientUuid }, LogInfo.COLUMN.ACTION_DATE + " DESC "); if (cursor == null) { return null; }/* ww w. jav a 2 s .c om*/ if (cursor.getCount() == 0) { cursor.close(); return null; } cursor.moveToFirst(); String date = cursor.getString(cursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); try { return ISO8601Utils.parse(date, new ParsePosition(0)); } catch (ParseException e) { e.printStackTrace(); return null; } finally { cursor.close(); } }
From source file:foam.zizim.android.BoskoiService.java
public static List<BlogData> getSimpleBlogData() { Cursor cursor; cursor = BoskoiApplication.mDb.fetchAllSimpleBlog(); List blog = new ArrayList<BlogData>(); if (cursor.moveToFirst()) { int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_ID); int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_TITLE); int dateIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_DATE); int linkIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_LINK); do {// w ww . j a v a2 s .c o m BlogData blogData = new BlogData(); blogData.setId(Util.toInt(cursor.getString(idIndex))); blogData.setTitle(cursor.getString(titleIndex)); blogData.setLink(cursor.getString(linkIndex)); blogData.setDate(cursor.getString(dateIndex)); blog.add(blogData); } while (cursor.moveToNext()); } cursor.close(); return blog; }
From source file:org.geometerplus.zlibrary.ui.android.network.SQLiteCookieDatabase.java
@Override protected List<Cookie> loadCookies() { final List<Cookie> list = new LinkedList<Cookie>(); final Cursor cursor = myDatabase .rawQuery("SELECT cookie_id,host,path,name,value,date_of_expiration,secure FROM Cookie", null); while (cursor.moveToNext()) { final long id = cursor.getLong(0); final String host = cursor.getString(1); final String path = cursor.getString(2); final String name = cursor.getString(3); final String value = cursor.getString(4); final Date date = SQLiteUtil.getDate(cursor, 5); final boolean secure = cursor.getLong(6) == 1; Set<Integer> portSet = null; final Cursor portsCursor = myDatabase.rawQuery("SELECT port FROM CookiePort WHERE cookie_id = " + id, null);/*from www.j a v a 2s . com*/ while (portsCursor.moveToNext()) { if (portSet == null) { portSet = new HashSet<Integer>(); } portSet.add((int) portsCursor.getLong(1)); } portsCursor.close(); final BasicClientCookie2 c = new BasicClientCookie2(name, value); c.setDomain(host); c.setPath(path); if (portSet != null) { final int ports[] = new int[portSet.size()]; int index = 0; for (int p : portSet) { ports[index] = p; ++index; } c.setPorts(ports); } c.setExpiryDate(date); c.setSecure(secure); c.setDiscard(false); list.add(c); } cursor.close(); return list; }
From source file:net.bible.service.db.mynote.MyNoteDBAdapter.java
public MyNoteDto getMyNoteByKey(String key) { MyNoteDto mynote = null;/*from w ww. jav a2 s. c o m*/ Cursor c = db.query(MyNoteQuery.TABLE, MyNoteQuery.COLUMNS, MyNoteColumn.KEY + "=?", new String[] { key }, null, null, null); try { if (c.moveToFirst()) { mynote = getMyNoteDto(c); } } finally { c.close(); } return mynote; }
From source file:com.ubikod.urbantag.model.TagManager.java
/** * Get all tags from a pivot table// w w w .ja v a 2s.c o m * @param pivotTable pivot table name * @param pivotColumn pivot table column * @param id * @return */ private List<Tag> dbGetAllFor(String pivotTable, String pivotColumn, int id) { open(); String query = "SELECT " + DatabaseHelper.TAG_COL_ID + ", " + DatabaseHelper.TAG_COL_NAME + ", " + DatabaseHelper.TAG_COL_COLOR + ", " + DatabaseHelper.TAG_COL_NOTIFY + " FROM " + DatabaseHelper.TABLE_TAGS + " tags INNER JOIN " + pivotTable + " pivot ON tags." + DatabaseHelper.TAG_COL_ID + "=pivot." + DatabaseHelper.CONTENT_TAG_COL_TAG + " WHERE pivot." + pivotColumn + "=?"; Cursor c = mDB.rawQuery(query, new String[] { String.valueOf(id) }); List<Tag> tags = new ArrayList<Tag>(); if (c.getCount() == 0) { c.close(); close(); return tags; } c.moveToFirst(); do { Tag t = cursorToTag(c); tags.add(t); } while (c.moveToNext()); c.close(); close(); return tags; }
From source file:com.cryart.sabbathschool.util.SSCore.java
public void ssSaveComments(int ssDaySerial, String comments) { SQLiteDatabase db = this.getWritableDatabase(); Cursor cu = db.rawQuery("UPDATE ss_days SET day_comments = ? " + "WHERE serial = ?", new String[] { comments, String.valueOf(ssDaySerial) }); cu.moveToFirst();// w w w.ja v a 2 s .c om cu.close(); db.close(); }
From source file:com.smarthome.deskclock.Alarms.java
public static Alarm calculateNextAlert(final Context context) { Alarm alarm = null;/*from w w w .j av a2s . c om*/ long minTime = Long.MAX_VALUE; long now = System.currentTimeMillis(); Cursor cursor = getFilteredAlarmsCursor(context.getContentResolver()); if (cursor != null) { if (cursor.moveToFirst()) { do { Alarm a = new Alarm(cursor); // A time of 0 indicates this is a repeating alarm, so // calculate the time to get the next alert. if (a.time == 0) { a.time = calculateAlarm(a); } else if (a.time < now) { Log.v("Disabling expired alarm set for " + Log.formatTime(a.time)); // Expired alarm, disable it and move along. enableAlarmInternal(context, a, false); continue; } if (a.time < minTime) { minTime = a.time; alarm = a; } } while (cursor.moveToNext()); } cursor.close(); } return alarm; }
From source file:com.gimranov.zandy.app.task.APIRequest.java
/** * Returns APIRequest objects from the database * @return/* w ww . j ava 2 s .co m*/ */ public static ArrayList<APIRequest> queue(Database db) { ArrayList<APIRequest> list = new ArrayList<APIRequest>(); String[] cols = Database.REQUESTCOLS; String[] args = {}; Cursor cur = db.query("apirequests", cols, "", args, null, null, null, null); if (cur == null) return list; do { APIRequest req = new APIRequest(cur); list.add(req); Log.d(TAG, "Queueing request: " + req.query); } while (cur.moveToNext() != false); cur.close(); return list; }
From source file:com.cryart.sabbathschool.util.SSCore.java
public void ssSaveHighlights(int ssDaySerial, String highlights) { SQLiteDatabase db = this.getWritableDatabase(); Cursor cu = db.rawQuery("UPDATE ss_days SET day_highlights = ? " + "WHERE serial = ?", new String[] { highlights, String.valueOf(ssDaySerial) }); cu.moveToFirst();//from w ww . j a v a2 s . com cu.close(); db.close(); }