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

Method readForeignKeys

app/src/main/java/androidx/room/TableInfo.java:175–216  ·  view source on GitHub ↗
(SupportSQLiteDatabase database,
            String tableName)

Source from the content-addressed store, hash-verified

173 }
174
175 private static Set<ForeignKey> readForeignKeys(SupportSQLiteDatabase database,
176 String tableName) {
177 Set<ForeignKey> foreignKeys = new HashSet<>();
178 // this seems to return everything in order but it is not documented so better be safe
179 Cursor cursor = database.query("PRAGMA foreign_key_list(`" + tableName + "`)");
180 try {
181 final int idColumnIndex = cursor.getColumnIndex("id");
182 final int seqColumnIndex = cursor.getColumnIndex("seq");
183 final int tableColumnIndex = cursor.getColumnIndex("table");
184 final int onDeleteColumnIndex = cursor.getColumnIndex("on_delete");
185 final int onUpdateColumnIndex = cursor.getColumnIndex("on_update");
186
187 final List<ForeignKeyWithSequence> ordered = readForeignKeyFieldMappings(cursor);
188 final int count = cursor.getCount();
189 for (int position = 0; position < count; position++) {
190 cursor.moveToPosition(position);
191 final int seq = cursor.getInt(seqColumnIndex);
192 if (seq != 0) {
193 continue;
194 }
195 final int id = cursor.getInt(idColumnIndex);
196 List<String> myColumns = new ArrayList<>();
197 List<String> refColumns = new ArrayList<>();
198 for (ForeignKeyWithSequence key : ordered) {
199 if (key.mId == id) {
200 myColumns.add(key.mFrom);
201 refColumns.add(key.mTo);
202 }
203 }
204 foreignKeys.add(new ForeignKey(
205 cursor.getString(tableColumnIndex),
206 cursor.getString(onDeleteColumnIndex),
207 cursor.getString(onUpdateColumnIndex),
208 myColumns,
209 refColumns
210 ));
211 }
212 } finally {
213 cursor.close();
214 }
215 return foreignKeys;
216 }
217
218 private static List<ForeignKeyWithSequence> readForeignKeyFieldMappings(Cursor cursor) {
219 final int idColumnIndex = cursor.getColumnIndex("id");

Callers 1

readMethod · 0.95

Calls 9

moveToPositionMethod · 0.80
getCountMethod · 0.65
queryMethod · 0.45
getColumnIndexMethod · 0.45
getIntMethod · 0.45
addMethod · 0.45
getStringMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected