MCPcopy Create free account
hub / github.com/M66B/FairEmail / readIndex

Method readIndex

app/src/main/java/androidx/room/TableInfo.java:309–346  ·  view source on GitHub ↗

@return null if we cannot read the index due to older sqlite implementations.

(SupportSQLiteDatabase database, String name, boolean unique)

Source from the content-addressed store, hash-verified

307 * @return null if we cannot read the index due to older sqlite implementations.
308 */
309 @Nullable
310 private static Index readIndex(SupportSQLiteDatabase database, String name, boolean unique) {
311 Cursor cursor = database.query("PRAGMA index_xinfo(`" + name + "`)");
312 try {
313 final int seqnoColumnIndex = cursor.getColumnIndex("seqno");
314 final int cidColumnIndex = cursor.getColumnIndex("cid");
315 final int nameColumnIndex = cursor.getColumnIndex("name");
316 final int descColumnIndex = cursor.getColumnIndex("desc");
317 if (seqnoColumnIndex == -1 || cidColumnIndex == -1
318 || nameColumnIndex == -1 || descColumnIndex == -1) {
319 // we cannot read them so better not validate any index.
320 return null;
321 }
322 final TreeMap<Integer, String> columnsMap = new TreeMap<>();
323 final TreeMap<Integer, String> ordersMap = new TreeMap<>();
324
325 while (cursor.moveToNext()) {
326 int cid = cursor.getInt(cidColumnIndex);
327 if (cid < 0) {
328 // Ignore SQLite row ID
329 continue;
330 }
331 int seq = cursor.getInt(seqnoColumnIndex);
332 String columnName = cursor.getString(nameColumnIndex);
333 String order = cursor.getInt(descColumnIndex) > 0 ? "DESC" : "ASC";
334
335 columnsMap.put(seq, columnName);
336 ordersMap.put(seq, order);
337 }
338 final List<String> columns = new ArrayList<>(columnsMap.size());
339 columns.addAll(columnsMap.values());
340 final List<String> orders = new ArrayList<>(ordersMap.size());
341 orders.addAll(ordersMap.values());
342 return new Index(name, unique, columns, orders);
343 } finally {
344 cursor.close();
345 }
346 }
347
348 /**
349 * Holds the information about a database column.

Callers 1

readIndicesMethod · 0.95

Calls 9

moveToNextMethod · 0.80
addAllMethod · 0.80
sizeMethod · 0.65
queryMethod · 0.45
getColumnIndexMethod · 0.45
getIntMethod · 0.45
getStringMethod · 0.45
putMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected