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

Method readIndices

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

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

(SupportSQLiteDatabase database, String tableName)

Source from the content-addressed store, hash-verified

271 * @return null if we cannot read the indices due to older sqlite implementations.
272 */
273 @Nullable
274 private static Set<Index> readIndices(SupportSQLiteDatabase database, String tableName) {
275 Cursor cursor = database.query("PRAGMA index_list(`" + tableName + "`)");
276 try {
277 final int nameColumnIndex = cursor.getColumnIndex("name");
278 final int originColumnIndex = cursor.getColumnIndex("origin");
279 final int uniqueIndex = cursor.getColumnIndex("unique");
280 if (nameColumnIndex == -1 || originColumnIndex == -1 || uniqueIndex == -1) {
281 // we cannot read them so better not validate any index.
282 return null;
283 }
284 HashSet<Index> indices = new HashSet<>();
285 while (cursor.moveToNext()) {
286 String origin = cursor.getString(originColumnIndex);
287 if (!"c".equals(origin)) {
288 // Ignore auto-created indices
289 continue;
290 }
291 String name = cursor.getString(nameColumnIndex);
292 boolean unique = cursor.getInt(uniqueIndex) == 1;
293 Index index = readIndex(database, name, unique);
294 if (index == null) {
295 // we cannot read it properly so better not read it
296 return null;
297 }
298 indices.add(index);
299 }
300 return indices;
301 } finally {
302 cursor.close();
303 }
304 }
305
306 /**
307 * @return null if we cannot read the index due to older sqlite implementations.

Callers 1

readMethod · 0.95

Calls 9

readIndexMethod · 0.95
moveToNextMethod · 0.80
queryMethod · 0.45
getColumnIndexMethod · 0.45
getStringMethod · 0.45
equalsMethod · 0.45
getIntMethod · 0.45
addMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected