Java Code Examples for net.sqlcipher.Cursor#isAfterLast()
The following examples show how to use
net.sqlcipher.Cursor#isAfterLast() .
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 |
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 |
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: AndroidCaseIndexTable.java From commcare-android with Apache License 2.0 | 5 votes |
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(); } } }
Example 4
Source File: HybridFileBackedSqlHelpers.java From commcare-android with Apache License 2.0 | 5 votes |
/** * 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(); } }