Code example for Cursor

Methods: closegetCountgetStringmoveToFirstsetNotificationUri

0
 
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
        qb.setTables(args.table);
 
        Cursor ret = qb.query(db, select, args.where, args.args, null, null, sort);
        ret.setNotificationUri(getContext().getContentResolver(), url);
        return ret;
    } 
 
    @Override 
    public String getType(Uri url) {
        // If SqlArguments supplies a where clause, then it must be an item 
        // (because we aren't supplying our own where clause). 
        SqlArguments args = new SqlArguments(url, null, null);
        if (TextUtils.isEmpty(args.where)) {
            return "vnd.android.cursor.dir/" + args.table;
        } else { 
            return "vnd.android.cursor.item/" + args.table;
        } 
    } 
 
    @Override 
    public int bulkInsert(Uri uri, ContentValues[] values) {
        SqlArguments args = new SqlArguments(uri);
        if (TABLE_FAVORITES.equals(args.table)) {
            return 0; 
        } 
        checkWritePermissions(args);
 
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        db.beginTransaction();
        try { 
            int numValues = values.length;
            for (int i = 0; i < numValues; i++) {
                if (db.insert(args.table, null, values[i]) < 0) return 0;
                if (LOCAL_LOGV) Log.v(TAG, args.table + " <- " + values[i]);
            } 
            db.setTransactionSuccessful();
        } finally { 
            db.endTransaction();
        } 
 
        sendNotify(uri);
        return values.length;
    } 
 
    /* 
     * Used to parse changes to the value of Settings.Secure.LOCATION_PROVIDERS_ALLOWED. 
     * This setting contains a list of the currently enabled location providers. 
     * But helper functions in android.providers.Settings can enable or disable 
     * a single provider by using a "+" or "-" prefix before the provider name. 
     */ 
    private boolean parseProviderList(Uri url, ContentValues initialValues) {
        String value = initialValues.getAsString(Settings.Secure.VALUE);
        String newProviders = null;
        if (value != null && value.length() > 1) {
            char prefix = value.charAt(0);
            if (prefix == '+' || prefix == '-') {
                // skip prefix 
                value = value.substring(1);
 
                // read list of enabled providers into "providers" 
                String providers = "";
                String[] columns = {Settings.Secure.VALUE};
                String where = Settings.Secure.NAME + "=\'" + Settings.Secure.LOCATION_PROVIDERS_ALLOWED + "\'";
                Cursor cursor = query(url, columns, where, null, null);
                if (cursor != null && cursor.getCount() == 1) {
                    try { 
                        cursor.moveToFirst();
                        providers = cursor.getString(0);
                    } finally { 
                        cursor.close();
                    } 
                } 
 
                int index = providers.indexOf(value);
                int end = index + value.length();