Example usage for android.database Cursor close

List of usage examples for android.database Cursor close

Introduction

In this page you can find the example usage for android.database Cursor close.

Prototype

void close();

Source Link

Document

Closes the Cursor, releasing all of its resources and making it completely invalid.

Usage

From source file:com.tcity.android.sync.SyncService.java

@Override
protected void onHandleIntent(@Nullable Intent intent) {
    Cursor cursor = myDB.getBuildConfigurations(null, true);

    //noinspection TryFinallyCanBeTryWithResources
    try {/*from ww  w.j ava  2s.  c  o m*/
        syncAll(cursor);
    } finally {
        cursor.close();
    }
}

From source file:com.zzl.zl_app.cache.Utility.java

/**
 * Get a HttpClient object which is setting correctly .
 * //from w w  w .  j ava 2  s . com
 * @param context
 *            : context of activity
 * @return HttpClient: HttpClient object
 */
public static HttpClient getHttpClient(Context context) {
    BasicHttpParams httpParameters = new BasicHttpParams();
    // Set the default socket timeout (SO_TIMEOUT) // in
    // milliseconds which is the timeout for waiting for data.
    HttpConnectionParams.setConnectionTimeout(httpParameters, Utility.SET_CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParameters, Utility.SET_SOCKET_TIMEOUT);
    HttpClient client = new DefaultHttpClient(httpParameters);
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    if (!wifiManager.isWifiEnabled() || -1 == info.getNetworkId()) {
        // ??APN?
        Uri uri = Uri.parse("content://telephony/carriers/preferapn");
        Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
        if (mCursor != null && mCursor.moveToFirst()) {
            // ???
            String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy"));
            if (proxyStr != null && proxyStr.trim().length() > 0) {
                HttpHost proxy = new HttpHost(proxyStr, 80);
                client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
            }
            mCursor.close();
        }
    }
    return client;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void updateStarredThread(boolean starred, String clean_subject, int groupid, Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbWrite = db.getWritableDatabase();

    clean_subject = clean_subject.replace("'", "''");

    String query;/*from   ww  w.j ava 2 s  .  co  m*/

    if (starred == false) {
        query = "DELETE FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject="
                + esc(clean_subject);
        dbWrite.execSQL(query);
    } else {
        // Check that it's not already on the table
        query = "SELECT _ID FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject="
                + esc(clean_subject);
        Cursor c = dbWrite.rawQuery(query, null);

        if (c.getCount() == 0) {
            ContentValues cv = new ContentValues();
            cv.put("subscribed_group_id", groupid);
            cv.put("clean_subject", clean_subject);
            dbWrite.insert("starred_threads", null, cv);
        }
        c.close();
    }
    dbWrite.close();
    db.close();
}

From source file:io.vit.vitio.Managers.ConnectDatabase.java

public void clear() {
    SQLiteDatabase sqLiteDatabase = getWritableDatabase();
    String deleteQuery = "DELETE FROM " + TABLE_COURSES + ";";
    sqLiteDatabase.delete(TABLE_COURSES, "1", null);
    Cursor cursor = sqLiteDatabase.rawQuery(deleteQuery, null);
    cursor.close();
    sqLiteDatabase.close();/* www  .ja va  2 s .  c  o m*/
}

From source file:com.money.manager.ex.datalayer.StockRepository.java

private List<Stock> getEntities(Cursor c) {
    List<Stock> result = new ArrayList<>();
    while (c.moveToNext()) {
        result.add(Stock.from(c));//from   w  w w.j  a va 2s  . c  o  m
    }
    c.close();

    return result;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static HashSet<String> getReadMessagesSet(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    HashSet<String> readSet = null;

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    String q = "SELECT server_article_id FROM headers WHERE read=1 AND subscribed_group_id=" + groupid;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    if (count > 0) {
        readSet = new HashSet<String>(c.getCount());
        c.moveToFirst();/*from   ww w. jav  a 2  s  .c  o  m*/

        for (int i = 0; i < count; i++) {
            readSet.add(c.getString(0));
            c.moveToNext();
        }
    }

    c.close();
    dbread.close();
    db.close();

    if (readSet == null)
        readSet = new HashSet<String>(0);
    return readSet;
}

From source file:ro.weednet.contactssync.platform.ContactManager.java

public static void updateContactPhotoHd(Context context, ContentResolver resolver, long rawContactId,
        ContactPhoto photo, BatchOperation batchOperation) {
    final Cursor c = resolver.query(DataQuery.CONTENT_URI, DataQuery.PROJECTION,
            Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(rawContactId), Photo.CONTENT_ITEM_TYPE }, null);
    final ContactOperations contactOp = ContactOperations.updateExistingContact(context, rawContactId, true,
            batchOperation);/*  w ww  .java2  s  . c o  m*/

    if ((c != null) && c.moveToFirst()) {
        final long id = c.getLong(DataQuery.COLUMN_ID);
        final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, id);
        contactOp.updateAvatar(c.getString(DataQuery.COLUMN_DATA1), photo.getPhotoUrl(), uri);
        c.close();
    } else {
        Log.i(TAG, "creating row, count: " + c.getCount());
        contactOp.addAvatar(photo.getPhotoUrl());
    }
    Log.d(TAG, "updating check timestamp");
    final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
    contactOp.updateSyncTimestamp1(System.currentTimeMillis(), uri);
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static HashSet<String> getBannedTrolls(Context context) {

    HashSet<String> bannedTrolls = null;

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    String q = "SELECT name FROM banned_users WHERE bandisabled=0";

    Cursor c = dbwrite.rawQuery(q, null);

    int count = c.getCount();
    if (count > 0) {

        bannedTrolls = new HashSet<String>(c.getColumnCount());
        c.moveToFirst();/* w  ww. j av a2s. c  o  m*/

        for (int i = 0; i < count; i++) {
            bannedTrolls.add(c.getString(0));
            c.moveToNext();
        }
    }

    c.close();
    dbwrite.close();
    db.close();

    if (bannedTrolls == null)
        bannedTrolls = new HashSet<String>(0);
    return bannedTrolls;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static HashSet<String> getStarredSubjectsSet(Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();
    Cursor c;

    String query = "SELECT clean_subject FROM starred_threads";
    c = dbread.rawQuery(query, null);/*  ww  w  . j  a  v  a2  s.  c  o m*/
    HashSet<String> set = new HashSet<String>(c.getCount());

    c.moveToFirst();
    int count = c.getCount();
    for (int i = 0; i < count; i++) {
        set.add(c.getString(0));
        c.moveToNext();
    }

    c.close();
    dbread.close();
    db.close();
    return set;
}

From source file:com.polyvi.xface.extension.XStorageExt.java

/**
 * SQL?./*w  w w .j a v a 2s . c o  m*/
 *
 * @param query
 *            SQL?
 * @param params
 *            SQL??
 * @param tx_id
 *             id
 * @param callbackCtx
 *            
 */
private void executeSql(String query, String[] params, String tx_id, XCallbackContext callbackCtx) {
    try {
        if (isDDL(query)) {
            mMyDb.execSQL(query);
            String jsScript = "xFace.require('xFace/extension/android/storage').completeQuery('" + tx_id
                    + "', '');";
            mWebContext.getApplication().loadJavascript(jsScript);
        } else {
            Cursor myCursor = mMyDb.rawQuery(query, params);
            processResults(myCursor, tx_id, callbackCtx);
            myCursor.close();
        }
    } catch (SQLiteException ex) {
        XLog.e(CLASS_NAME, "Storage.executeSql(): Error=" + ex.getMessage());
        String jsScript = "xFace.require('xFace/extension/android/storage').failQuery('" + ex.getMessage()
                + "','" + tx_id + "');";
        callbackCtx.sendExtensionResult(jsScript);
    }
}