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

The following examples show how to use net.sqlcipher.Cursor#getColumnIndexOrThrow() . 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 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 2
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 3
Source File: HybridFileBackedSqlHelpers.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
/**
 * Remove files in the orphaned file table. Files are added to this table
 * when file-backed db transactions fail, leaving the file on the
 * filesystem.
 *
 * Order of operations expects filenames to be globally unique.
 */
public static void removeOrphanedFiles(SQLiteDatabase db) {
    Cursor cur = db.query(DbUtil.orphanFileTableName, new String[]{DatabaseHelper.FILE_COL}, null, null, null, null, null);
    ArrayList<String> files = new ArrayList<>();
    try {
        if (cur.getCount() > 0) {
            cur.moveToFirst();
            int fileColIndex = cur.getColumnIndexOrThrow(DatabaseHelper.FILE_COL);
            while (!cur.isAfterLast()) {
                files.add(cur.getString(fileColIndex));
                cur.moveToNext();
            }
        }
    } finally {
        if (cur != null) {
            cur.close();
        }
    }

    removeFiles(files);

    db.beginTransaction();
    try {
        db.delete(DbUtil.orphanFileTableName, null, null);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}