データベース全体にクエリを実行し、元の並べ替え順序を維持してから、各行を反復処理します。何かが空の場合は、上記の値で更新します。
編集:ここでこれに似たものでそれを行うかもしれません:
SQLiteDatabase db = SQLiteDatabase.openDatabase("myDb.db", null, SQLiteDatabase.OPEN_READWRITE);
Cursor c = db.query("table", null, null, null, null, null, "the column that defines the sort order");
if (c != null) {
int columnCount = c.getColumnCount();
String[] lastValues = new String[columnCount];
while (c.moveToNext()) {
ContentValues cv = new ContentValues();
for (int i = 0; i < columnCount; i++) {
String value = c.getString(i);
if (TextUtils.isEmpty(value)) {
// if that happens on first column you are screwed anyways.
cv.put(c.getColumnName(i), lastValues[i]);
} else {
lastValues[i] = value;
}
// we need to save some id here
}
if (cv.size() > 0) {
// use the id here
db.update("table", cv, "column=?", new String[] { "id" });
}
}
c.close();
}
ただし、Excel を使用してデータベースを修正することをお勧めします。その方が簡単で、上記のコードを理解する必要はありません。