Example usage for android.database Cursor getString

List of usage examples for android.database Cursor getString

Introduction

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

Prototype

String getString(int columnIndex);

Source Link

Document

Returns the value of the requested column as a String.

Usage

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

private static void cursorToGroupEntry(Cursor c, GroupEntry entry) throws ParseException {
    if (!TextUtils.isEmpty(c.getString(c.getColumnIndexOrThrow(Groups.SYSTEM_ID)))) {
        throw new ParseException("unable to modify system groups");
    }//from w  ww.  j  a  v  a 2s .  com
    entry.setTitle(c.getString(c.getColumnIndexOrThrow(Groups.NAME)));
    entry.setContent(c.getString(c.getColumnIndexOrThrow(Groups.NOTES)));
    entry.setSystemGroup(null);
}

From source file:org.npr.android.news.StationListAdapter.java

public void initializeList(Cursor cursor) {
    data = new ArrayList<Station>();

    while (cursor.moveToNext()) {
        Station.StationBuilder builder = new Station.StationBuilder(
                cursor.getString(cursor.getColumnIndex(FavoriteStationsProvider.Items.STATION_ID)));
        builder.withName(cursor.getString(cursor.getColumnIndex(FavoriteStationsProvider.Items.NAME)));
        builder.withMarketCity(cursor.getString(cursor.getColumnIndex(FavoriteStationsProvider.Items.MARKET)));
        builder.withFrequency(//from w  w w .java  2s  .  c  o  m
                cursor.getString(cursor.getColumnIndex(FavoriteStationsProvider.Items.FREQUENCY)));
        builder.withBand(cursor.getString(cursor.getColumnIndex(FavoriteStationsProvider.Items.BAND)));
        data.add(builder.build());
    }
}

From source file:org.thomnichols.android.gmarks.WebViewCookiesDB.java

List<Cookie> getCookies() {
    List<Cookie> cookies = new ArrayList<Cookie>();
    SQLiteDatabase db = openDatabase(SQLiteDatabase.OPEN_READONLY);
    if (db == null)
        return cookies;

    try {//  ww  w. ja  v  a 2  s.c om
        db.execSQL("PRAGMA read_uncommitted = true;");
        Cursor cursor = db.query(TABLE_NAME, COLUMNS, null, null, null, null, null);

        while (cursor.moveToNext()) {
            BasicClientCookie c = new BasicClientCookie(cursor.getString(COL_NAME),
                    cursor.getString(COL_VALUE));
            c.setDomain(cursor.getString(COL_DOMAIN));
            c.setPath(cursor.getString(COL_PATH));
            Long expiry = cursor.getLong(COL_EXPIRES);
            if (expiry != null)
                c.setExpiryDate(new Date(expiry));
            c.setSecure(cursor.getShort(COL_SECURE) == 1);
            Log.d(TAG, "Got cookie: " + c.getName());
            cookies.add(c);
        }
        cursor.close();

        //         cursor = db.query(TABLE_NAME, new String[] {"count(name)"}, null, null, null, null, null);
        //         cursor.moveToFirst();
        //         Log.d("WEBVIEW DB QUERY", "COunt: " + cursor.getLong(0) );
        //          cursor.close();
        return cookies;
    } finally {
        db.close();
    }
}

From source file:com.ichi2.libanki.Finder.java

public static int findReplace(Collection col, List<Long> nids, String src, String dst, boolean isRegex,
        String field, boolean fold) {
    Map<Long, Integer> mmap = new HashMap<Long, Integer>();
    if (field != null) {
        try {/*w ww . ja v  a 2s .  co  m*/
            for (JSONObject m : col.getModels().all()) {
                JSONArray flds = m.getJSONArray("flds");
                for (int fi = 0; fi < flds.length(); ++fi) {
                    JSONObject f = flds.getJSONObject(fi);
                    if (f.getString("name").equals(field)) {
                        mmap.put(m.getLong("id"), f.getInt("ord"));
                    }
                }
            }
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
        if (mmap.isEmpty()) {
            return 0;
        }
    }
    // find and gather replacements
    if (!isRegex) {
        src = Pattern.quote(src);
    }
    if (fold) {
        src = "(?i)" + src;
    }
    Pattern regex = Pattern.compile(src);

    ArrayList<Object[]> d = new ArrayList<Object[]>();
    String snids = Utils.ids2str(nids);
    nids = new ArrayList<Long>();
    Cursor cur = null;
    try {
        cur = col.getDb().getDatabase().rawQuery("select id, mid, flds from notes where id in " + snids, null);
        while (cur.moveToNext()) {
            String flds = cur.getString(2);
            String origFlds = flds;
            // does it match?
            String[] sflds = Utils.splitFields(flds);
            if (field != null) {
                long mid = cur.getLong(1);
                if (!mmap.containsKey(mid)) {
                    // note doesn't have that field
                    continue;
                }
                int ord = mmap.get(mid);
                sflds[ord] = regex.matcher(sflds[ord]).replaceAll(dst);
            } else {
                for (int i = 0; i < sflds.length; ++i) {
                    sflds[i] = regex.matcher(sflds[i]).replaceAll(dst);
                }
            }
            flds = Utils.joinFields(sflds);
            if (!flds.equals(origFlds)) {
                long nid = cur.getLong(0);
                nids.add(nid);
                d.add(new Object[] { flds, Utils.intNow(), col.usn(), nid }); // order based on query below
            }
        }
    } finally {
        if (cur != null) {
            cur.close();
        }
    }
    if (d.isEmpty()) {
        return 0;
    }
    // replace
    col.getDb().executeMany("update notes set flds=?,mod=?,usn=? where id=?", d);
    long[] pnids = Utils.toPrimitive(nids);
    col.updateFieldCache(pnids);
    col.genCards(pnids);
    return d.size();
}

From source file:net.eledge.android.toolkit.db.internal.FieldType.java

public void convertToField(Object instance, Field field, Cursor cursor, int columnIndex)
        throws IllegalArgumentException, IllegalAccessException {
    field.set(instance, cursor.getString(columnIndex));
}

From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java

private List<String> getExistingFields(Class<?> clazz) {
    List<String> names = new ArrayList<>();
    StringBuilder sb = new StringBuilder("pragma table_info(");
    sb.append(SQLBuilder.getTableName(clazz));
    sb.append(");");
    Cursor cursor = db.rawQuery(sb.toString(), new String[] {});
    if ((cursor != null) && cursor.moveToFirst()) {
        do {/*from w ww.  j  a v  a2 s.c  o  m*/
            names.add(cursor.getString(1));
        } while (cursor.moveToNext());
        cursor.close();
    }
    return names;
}

From source file:DictionaryDatabase.java

public String getDefinition(long id) {
    String returnVal = "";
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT definition FROM " + TABLE_DICTIONARY + " WHERE  _id = ?",
            new String[] { String.valueOf(id) });
    if (cursor.getCount() == 1) {
        cursor.moveToFirst();//from  w ww  . j  av  a2s .c  om
        returnVal = cursor.getString(0);
    }
    return returnVal;
}

From source file:com.textuality.lifesaver.Columns.java

public String cursorToKey(Cursor c) {
    if (key1Index == -1) {
        key1Index = c.getColumnIndex(key1);
        key2Index = c.getColumnIndex(key2);
    }/*from  w  w w. j  a v  a  2 s. c o m*/
    return c.getString(key1Index) + "/" + c.getString(key2Index);
}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

private static void cursorToContactEntry(String account, ContentResolver cr, Cursor c, ContactEntry entry)
        throws ParseException {
    entry.setTitle(c.getString(c.getColumnIndexOrThrow(People.NAME)));
    entry.setContent(c.getString(c.getColumnIndexOrThrow(People.NOTES)));
    entry.setYomiName(c.getString(c.getColumnIndexOrThrow(People.PHONETIC_NAME)));

    long syncLocalId = c.getLong(c.getColumnIndexOrThrow(SyncConstValue._SYNC_LOCAL_ID));
    addContactMethodsToContactEntry(cr, syncLocalId, entry);
    addPhonesToContactEntry(cr, syncLocalId, entry);
    addOrganizationsToContactEntry(cr, syncLocalId, entry);
    addGroupMembershipToContactEntry(account, cr, syncLocalId, entry);
    addExtensionsToContactEntry(cr, syncLocalId, entry);
}