Java Code Examples for net.sqlcipher.Cursor#getString()

The following examples show how to use net.sqlcipher.Cursor#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexedFixturePathUtils.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
public static IndexedFixtureIdentifier lookupIndexedFixturePaths(SQLiteDatabase db,
                                                                 String fixtureName) {
    Cursor c = db.query(INDEXED_FIXTURE_PATHS_TABLE,
            new String[]{INDEXED_FIXTURE_PATHS_COL_BASE, INDEXED_FIXTURE_PATHS_COL_CHILD, INDEXED_FIXTURE_PATHS_COL_ATTRIBUTES},
            INDEXED_FIXTURE_PATHS_COL_NAME + "=?", new String[]{fixtureName}, null, null, null);
    try {
        if (c.getCount() == 0) {
            return null;
        } else {
            c.moveToFirst();
            return new IndexedFixtureIdentifier(
                    c.getString(c.getColumnIndexOrThrow(INDEXED_FIXTURE_PATHS_COL_BASE)),
                    c.getString(c.getColumnIndexOrThrow(INDEXED_FIXTURE_PATHS_COL_CHILD)),
                    c.getBlob(c.getColumnIndexOrThrow(INDEXED_FIXTURE_PATHS_COL_ATTRIBUTES)));
        }
    } finally {
        c.close();
    }
}
 
Example 2
Source File: IndexedFixturePathUtils.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
public static List<String> getAllIndexedFixtureNames(SQLiteDatabase db) {
    Cursor c = db.query(INDEXED_FIXTURE_PATHS_TABLE,
            new String[]{INDEXED_FIXTURE_PATHS_COL_NAME},
            null, null, null, null, null);
    List<String> fixtureNames = new ArrayList<>();
    try {
        if (c.moveToFirst()) {
            int desiredColumnIndex = c.getColumnIndexOrThrow(
                    INDEXED_FIXTURE_PATHS_COL_NAME);
            while (!c.isAfterLast()) {
                String name = c.getString(desiredColumnIndex);
                fixtureNames.add(name);
                c.moveToNext();
            }
        }
        return fixtureNames;
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
 
Example 3
Source File: HybridFileBackedSqlHelpers.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
protected static Pair<String, byte[]> getEntryFilenameAndKey(AndroidDbHelper helper,
                                                             String table,
                                                             int id) {
    Cursor c;
    c = helper.getHandle().query(table, HybridFileBackedSqlStorage.dataColumns,
            DatabaseHelper.ID_COL + "=?",
            new String[]{String.valueOf(id)}, null, null, null);

    try {
        c.moveToFirst();
        return new Pair<>(c.getString(c.getColumnIndexOrThrow(DatabaseHelper.FILE_COL)),
                c.getBlob(c.getColumnIndexOrThrow(DatabaseHelper.AES_COL)));
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
 
Example 4
Source File: HybridFileBackedSqlHelpers.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
protected static String getEntryFilename(AndroidDbHelper helper,
                                         String table, int id) {
    Cursor c;
    SQLiteDatabase db = helper.getHandle();

    String[] columns = new String[]{DatabaseHelper.FILE_COL};
    c = db.query(table, columns, DatabaseHelper.ID_COL + "=?",
            new String[]{String.valueOf(id)}, null, null, null);

    try {
        c.moveToFirst();
        return c.getString(c.getColumnIndexOrThrow(DatabaseHelper.FILE_COL));
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
 
Example 5
Source File: AsyncNodeEntityFactory.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void populateEntitySet(SQLiteDatabase db, String sqlStatement, String[] args) {
    //TODO: This will _only_ query up to about a meg of data, which is an un-great limitation.
    //Should probably split this up SQL LIMIT based looped
    //For reference the current limitation is about 10k rows with 1 field each.
    Cursor walker = db.rawQuery(sqlStatement, args);
    while (walker.moveToNext()) {
        String entityId = walker.getString(walker.getColumnIndex("entity_key"));
        String cacheId = walker.getString(walker.getColumnIndex("cache_key"));
        String val = walker.getString(walker.getColumnIndex("value"));
        if (this.mEntitySet.containsKey(entityId)) {
            this.mEntitySet.get(entityId).setSortData(cacheId, val);
        }
    }
    walker.close();
}
 
Example 6
Source File: EntityStorageCache.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
public String retrieveCacheValue(String entityKey, String cacheKey) {
    String whereClause = String.format("%s = ? AND %s = ? AND %s = ? AND %s = ?", COL_APP_ID, COL_CACHE_NAME, COL_ENTITY_KEY, COL_CACHE_KEY);

    Cursor c = db.query(TABLE_NAME, new String[]{COL_VALUE}, whereClause, new String[]{mAppId, mCacheName, entityKey, cacheKey}, null, null, null);
    try {
        if (c.moveToNext()) {
            return c.getString(0);
        } else {
            return null;
        }
    } finally {
        c.close();
    }
}
 
Example 7
Source File: AndroidCaseIndexTable.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
public HashMap<Integer,Vector<Pair<String, String>>> getCaseIndexMap() {
    String[] projection = new String[] {COL_CASE_RECORD_ID, COL_INDEX_TARGET, COL_INDEX_RELATIONSHIP};
    HashMap<Integer,Vector<Pair<String, String>>> caseIndexMap = new HashMap<>();
    Cursor c = db.query(TABLE_NAME, projection, null ,null, null, null, null);

    int recordColumn = c.getColumnIndexOrThrow(COL_CASE_RECORD_ID);
    int targetColumn = c.getColumnIndexOrThrow(COL_INDEX_TARGET);
    int relationshipColumn = c.getColumnIndexOrThrow(COL_INDEX_RELATIONSHIP);

    try {
        c.moveToFirst();
        while (!c.isAfterLast()) {
            int caseRecordId = c.getInt(recordColumn);
            String targetCase = c.getString(targetColumn);
            String relationship = c.getString(relationshipColumn);

            c.moveToNext();

            Pair<String, String> index  = new Pair<> (targetCase, relationship);

            Vector<Pair<String, String>> indexList;
            if (!caseIndexMap.containsKey(caseRecordId)) {
                indexList = new Vector<>();
            } else {
                indexList = caseIndexMap.get(caseRecordId);
            }
            indexList.add(index);
            caseIndexMap.put(caseRecordId, indexList);
        }

        return caseIndexMap;
    } finally {
        c.close();
    }
}
 
Example 8
Source File: AndroidCaseIndexTable.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
public int loadIntoIndexTable(HashMap<String, Vector<Integer>> indexCache, String indexName) {
    int resultsReturned = 0;
    String[] args = new String[]{indexName};
    if (SqlStorage.STORAGE_OUTPUT_DEBUG) {
        String query = String.format("SELECT %s,%s %s FROM %s where %s = '%s'", COL_CASE_RECORD_ID, COL_INDEX_NAME, COL_INDEX_TARGET, TABLE_NAME, COL_INDEX_NAME, indexName);
        DbUtil.explainSql(db, query, null);
    }

    Cursor c = db.query(TABLE_NAME, new String[]{COL_CASE_RECORD_ID, COL_INDEX_NAME, COL_INDEX_TARGET},COL_INDEX_NAME + " = ?", args, null, null, null);

    try {
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                resultsReturned++;
                int id = c.getInt(c.getColumnIndexOrThrow(COL_CASE_RECORD_ID));
                String target = c.getString(c.getColumnIndexOrThrow(COL_INDEX_TARGET));

                String cacheID = indexName + "|" + target;
                Vector<Integer> cache;
                if (indexCache.containsKey(cacheID)){
                    cache = indexCache.get(cacheID);
                } else {
                    cache = new Vector<>();
                }
                cache.add(id);
                indexCache.put(cacheID, cache);
                c.moveToNext();
            }
        }

        return resultsReturned;
    } finally {
        if (c != null) {
            c.close();
        }
    }

}