Clean up StoreSchemaDefinitionTest
This commit is contained in:
parent
83951c087e
commit
ac6a1ea213
1 changed files with 13 additions and 12 deletions
|
@ -297,15 +297,13 @@ public class StoreSchemaDefinitionTest {
|
||||||
|
|
||||||
private List<String> objectsInDatabase(SQLiteDatabase db, String type) {
|
private List<String> objectsInDatabase(SQLiteDatabase db, String type) {
|
||||||
List<String> databaseObjects = new ArrayList<>();
|
List<String> databaseObjects = new ArrayList<>();
|
||||||
Cursor cursor = db.rawQuery("SELECT sql FROM sqlite_master WHERE type = ? AND sql IS NOT NULL", new String[] { type });
|
Cursor cursor = db.rawQuery("SELECT sql FROM sqlite_master WHERE type = ? AND sql IS NOT NULL",
|
||||||
|
new String[] { type });
|
||||||
try {
|
try {
|
||||||
if (cursor.moveToFirst()) {
|
while (cursor.moveToNext()) {
|
||||||
while (!cursor.isAfterLast()) {
|
String sql = cursor.getString(cursor.getColumnIndex("sql"));
|
||||||
String sql = cursor.getString(cursor.getColumnIndex("sql"));
|
String resortedSql = "table".equals(type) ? sortTableColumns(sql) : sql;
|
||||||
String resortedSql = "table".equals(type) ? sortTableColumns(sql) : sql;
|
databaseObjects.add(resortedSql);
|
||||||
databaseObjects.add(resortedSql);
|
|
||||||
cursor.moveToNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
@ -316,10 +314,13 @@ public class StoreSchemaDefinitionTest {
|
||||||
|
|
||||||
private String sortTableColumns(String sql) {
|
private String sortTableColumns(String sql) {
|
||||||
int positionOfColumnDefinitions = sql.indexOf('(');
|
int positionOfColumnDefinitions = sql.indexOf('(');
|
||||||
String colsStr = sql.substring(positionOfColumnDefinitions+1, sql.length()-1);
|
String columnDefinitionsSql = sql.substring(positionOfColumnDefinitions + 1, sql.length() - 1);
|
||||||
String[] cols = colsStr.split(" *, *(?![^\\(]*\\))");
|
String[] columnDefinitions = columnDefinitionsSql.split(" *, *(?![^(]*\\))");
|
||||||
Arrays.sort(cols);
|
Arrays.sort(columnDefinitions);
|
||||||
return sql.substring(0, positionOfColumnDefinitions+1) + TextUtils.join(", ", cols) + ")";
|
|
||||||
|
String sqlPrefix = sql.substring(0, positionOfColumnDefinitions + 1);
|
||||||
|
String sortedColumnDefinitionsSql = TextUtils.join(", ", columnDefinitions);
|
||||||
|
return sqlPrefix + sortedColumnDefinitionsSql + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertMessageWithSubject(SQLiteDatabase database, String subject) {
|
private void insertMessageWithSubject(SQLiteDatabase database, String subject) {
|
||||||
|
|
Loading…
Reference in a new issue