I'm creating an application on Android using SQLite and I need to get a list of tables with a specific column like:
SELECT table_name FROM sqlite_master WHERE table_column_map = 'imagem'
Is it possible to do this?
I'm creating an application on Android using SQLite and I need to get a list of tables with a specific column like:
SELECT table_name FROM sqlite_master WHERE table_column_map = 'imagem'
Is it possible to do this?
I ended up building this function to solve my problem:
public ArrayList<Object> getTablesWhereColumns(String[] columns) {
ArrayList<Object> tables = getTables();
ArrayList<Object> requestedTables = new ArrayList<Object>();
for (Object table : tables){
Cursor cursor = mDatabase.rawQuery("SELECT * FROM "+table.toString()+" LIMIT 1", null);
String[] columnNames = cursor.getColumnNames();
for (String columnName : columnNames) {
if (Arrays.asList(columns).contains(columnName)) {
requestedTables.add(table.toString());
break;
}
}
}
return requestedTables;
}
Usage:
ArrayList<Object> tables = crud.getTablesWhereColumns(new String[]{"image", "video", "video_image"});