本文整理了Java中android.database.Cursor.isClosed()
方法的一些代码示例,展示了Cursor.isClosed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cursor.isClosed()
方法的具体详情如下:
包路径:android.database.Cursor
类名称:Cursor
方法名:isClosed
暂无
代码示例来源:origin: leolin310148/ShortcutBadger
public static void close(Cursor cursor) {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
代码示例来源:origin: yanzhenjie/NoHttp
/**
* Close the database when writing data.
*
* @param cursor {@link Cursor}.
*/
protected final void closeCursor(Cursor cursor) {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
代码示例来源:origin: ankidroid/Anki-Android
public void close() {
if (cur != null && !cur.isClosed())
cur.close();
}
}
代码示例来源:origin: stackoverflow.com
public int getRecordsCount() {
int count = 0;
String countQuery = "SELECT * FROM " + TABLE_LOGIN;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
if(cursor != null && !cursor.isClosed()){
count = cursor.getCount();
cursor.close();
}
return count;
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
protected final void closeDatabase(SQLiteDatabase database, Cursor cursor) {
if (cursor != null && !cursor.isClosed()) cursor.close();
if (database != null && database.isOpen()) database.close();
}
代码示例来源:origin: stackoverflow.com
public static String getContactName(Context context, String phoneNumber) {
ContentResolver cr = context.getContentResolver();
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
Cursor cursor = cr.query(uri, new String[]{PhoneLookup.DISPLAY_NAME}, null, null, null);
if (cursor == null) {
return null;
}
String contactName = null;
if(cursor.moveToFirst()) {
contactName = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
}
if(cursor != null && !cursor.isClosed()) {
cursor.close();
}
return contactName;
}
代码示例来源:origin: stackoverflow.com
public Bitmap getImage(int i){
String qu = "select img from table where feedid=" + i ;
Cursor cur = db.rawQuery(qu, null);
if (cur.moveToFirst()){
byte[] imgByte = cur.getBlob(0);
cur.close();
return BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length);
}
if (cur != null && !cur.isClosed()) {
cur.close();
}
return null ;
}
代码示例来源:origin: stackoverflow.com
public Account getCurrentAccount() {
SQLiteDatabase db = dbHelper.getWritableDatabase();
String sql = "SELECT * FROM ACCOUNTS";
Cursor cursor = db.rawQuery(sql, new String[] {});
if(cursor.moveToFirst()){
this.accId = cursor.getInt(0);
this.accName = cursor.getString(1);
this.accImage = cursor.getBlob(2);
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
db.close();
if(cursor.getCount() == 0){
return null;
} else {
return this;
}
}
代码示例来源:origin: ankidroid/Anki-Android
public ArrayList<Object[]> _qaData(String where) {
ArrayList<Object[]> data = new ArrayList<>();
Cursor cur = null;
try {
cur = mDb.getDatabase().query(
"SELECT c.id, n.id, n.mid, c.did, c.ord, "
+ "n.tags, n.flds FROM cards c, notes n WHERE c.nid == n.id " + where, null);
while (cur.moveToNext()) {
data.add(new Object[] { cur.getLong(0), cur.getLong(1), cur.getLong(2), cur.getLong(3), cur.getInt(4),
cur.getString(5), cur.getString(6) });
}
} finally {
if (cur != null && !cur.isClosed()) {
cur.close();
}
}
return data;
}
代码示例来源:origin: stackoverflow.com
if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) {
oldCursor.close();
if (mCursor != null && !mCursor.isClosed()) {
mCursor.close();
代码示例来源:origin: ankidroid/Anki-Android
/**
* Field checksums and sorting fields ***************************************
* ********************************************************
*/
private ArrayList<Object[]> _fieldData(String snids) {
ArrayList<Object[]> result = new ArrayList<>();
Cursor cur = null;
try {
cur = mDb.getDatabase().query("SELECT id, mid, flds FROM notes WHERE id IN " + snids, null);
while (cur.moveToNext()) {
result.add(new Object[] { cur.getLong(0), cur.getLong(1), cur.getString(2) });
}
} finally {
if (cur != null && !cur.isClosed()) {
cur.close();
}
}
return result;
}
代码示例来源:origin: ankidroid/Anki-Android
public TodayStats(SupportSQLiteDatabase db, long dayStartCutoff) {
Cursor cur = null;
String query = "select cards.did, "+
"sum(case when revlog.type = 0 then 1 else 0 end)"+ /* learning */
" from revlog, cards where revlog.cid = cards.id and revlog.id > " + dayStartCutoff +
" group by cards.did";
Timber.d("AdvancedStatistics.TodayStats query: %s", query);
try {
cur = db.query(query, null);
while(cur.moveToNext()) {
nLearnedPerDeckId.put(cur.getLong(0), cur.getInt(1));
}
} finally {
if (cur != null && !cur.isClosed()) {
cur.close();
}
}
}
代码示例来源:origin: ankidroid/Anki-Android
public static int getNotificationStatus(Context context) {
openDBIfClosed(context);
Cursor cursor = null;
int due = 0;
try {
cursor = mMetaDb.query("smallWidgetStatus", new String[] { "due" }, null, null, null, null, null);
if (cursor.moveToFirst()) {
return cursor.getInt(0);
}
} catch (SQLiteException e) {
Timber.e(e, "Error while querying widgetStatus");
} finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
return due;
}
代码示例来源:origin: ankidroid/Anki-Android
public String emptyCardReport(List<Long> cids) {
StringBuilder rep = new StringBuilder();
Cursor cur = null;
try {
cur = mDb.getDatabase().query("select group_concat(ord+1), count(), flds from cards c, notes n "
+ "where c.nid = n.id and c.id in " + Utils.ids2str(cids) + " group by nid", null);
while (cur.moveToNext()) {
String ords = cur.getString(0);
//int cnt = cur.getInt(1); // present but unused upstream as well
String flds = cur.getString(2);
rep.append(String.format("Empty card numbers: %s\nFields: %s\n\n", ords, flds.replace("\u001F", " / ")));
}
} finally {
if (cur != null && !cur.isClosed()) {
cur.close();
}
}
return rep.toString();
}
代码示例来源:origin: stackoverflow.com
} while (cur.moveToNext());
if (!cur.isClosed()) {
cur.close();
cur = null;
代码示例来源:origin: ankidroid/Anki-Android
/**
* Return the current status of the widget.
*
* @return [due, eta]
*/
public static int[] getWidgetSmallStatus(Context context) {
openDBIfClosed(context);
Cursor cursor = null;
try {
cursor = mMetaDb.query("smallWidgetStatus", new String[] { "due", "eta" },
null, null, null, null, null);
while (cursor.moveToNext()) {
return new int[]{cursor.getInt(0), cursor.getInt(1)};
}
} catch (SQLiteException e) {
Timber.e(e, "Error while querying widgetStatus");
} finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
return new int[]{0, 0};
}
代码示例来源:origin: ankidroid/Anki-Android
if (cur != null && !cur.isClosed()) {
cur.close();
代码示例来源:origin: ankidroid/Anki-Android
/**
* Returns the state of the whiteboard for the given deck.
*
* @return 1 if the whiteboard should be shown, 0 otherwise
*/
public static boolean getWhiteboardState(Context context, long did) {
openDBIfClosed(context);
Cursor cur = null;
try {
cur = mMetaDb.rawQuery("SELECT state FROM whiteboardState" + " WHERE did = " + did, null);
if (cur.moveToNext()) {
return cur.getInt(0) > 0;
} else {
return false;
}
} catch (Exception e) {
Timber.e(e, "Error retrieving whiteboard state from MetaDB ");
return false;
} finally {
if (cur != null && !cur.isClosed()) {
cur.close();
}
}
}
代码示例来源:origin: ankidroid/Anki-Android
/**
* Returns a custom dictionary associated to a deck
*
* @return integer number of dictionary, -1 if not set (standard dictionary will be used)
*/
public static int getLookupDictionary(Context context, long did) {
openDBIfClosed(context);
Cursor cur = null;
try {
cur = mMetaDb.rawQuery("SELECT dictionary FROM customDictionary" + " WHERE did = " + did, null);
if (cur.moveToNext()) {
return cur.getInt(0);
} else {
return -1;
}
} catch (Exception e) {
Timber.e(e, "Error retrieving custom dictionary from MetaDB ");
return -1;
} finally {
if (cur != null && !cur.isClosed()) {
cur.close();
}
}
}
代码示例来源:origin: stackoverflow.com
c.close();
.getColumnIndex(PhoneLookup.DISPLAY_NAME));
if (cursor != null && !cursor.isClosed()) {
cursor.close();
内容来源于网络,如有侵权,请联系作者删除!