Guarantee table export order is valid.

This commit is contained in:
Greyson Parrelli
2022-11-16 13:21:33 -05:00
committed by Alex Hart
parent 7c60c32918
commit cf00995b6f
3 changed files with 262 additions and 18 deletions

View File

@@ -33,6 +33,17 @@ object SqlUtil {
return tables
}
/**
* Given a table, this will return a set of tables that it has a foreign key dependency on.
*/
@JvmStatic
fun getForeignKeyDependencies(db: SupportSQLiteDatabase, table: String): Set<String> {
return db.query("PRAGMA foreign_key_list($table)")
.readToSet{ cursor ->
cursor.requireNonNullString("table")
}
}
@JvmStatic
fun isEmpty(db: SupportSQLiteDatabase, table: String): Boolean {
db.query("SELECT COUNT(*) FROM $table", null).use { cursor ->