Really fix database upgrade
This commit is contained in:
parent
891a581329
commit
571a79cc1d
@ -37,8 +37,8 @@ android {
|
|||||||
applicationId "sushi.hardcore.droidfs"
|
applicationId "sushi.hardcore.droidfs"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 32
|
targetSdkVersion 32
|
||||||
versionCode 34
|
versionCode 35
|
||||||
versionName "2.1.1"
|
versionName "2.1.2"
|
||||||
|
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
|
abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
|
||||||
|
@ -9,7 +9,6 @@ import android.util.Log
|
|||||||
import sushi.hardcore.droidfs.filesystems.EncryptedVolume
|
import sushi.hardcore.droidfs.filesystems.EncryptedVolume
|
||||||
import sushi.hardcore.droidfs.util.PathUtils
|
import sushi.hardcore.droidfs.util.PathUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.UUID
|
|
||||||
|
|
||||||
class VolumeDatabase(private val context: Context): SQLiteOpenHelper(context, Constants.VOLUME_DATABASE_NAME, null, 6) {
|
class VolumeDatabase(private val context: Context): SQLiteOpenHelper(context, Constants.VOLUME_DATABASE_NAME, null, 6) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -102,17 +101,23 @@ class VolumeDatabase(private val context: Context): SQLiteOpenHelper(context, Co
|
|||||||
volumeNames[i++] = cursor.getString(0)
|
volumeNames[i++] = cursor.getString(0)
|
||||||
}
|
}
|
||||||
cursor.close()
|
cursor.close()
|
||||||
db.execSQL("ALTER TABLE $TABLE_NAME RENAME TO OLD;")
|
if (volumeNames.isEmpty()) {
|
||||||
createTable(db)
|
db.execSQL("DROP TABLE $TABLE_NAME;")
|
||||||
val uuidsValues = volumeNames.indices.joinToString(", ") { "('${VolumeData.newUuid()}', ?)" }
|
createTable(db)
|
||||||
// add uuids to old data
|
} else {
|
||||||
db.execSQL(
|
db.execSQL("ALTER TABLE $TABLE_NAME RENAME TO OLD;")
|
||||||
"INSERT INTO $TABLE_NAME " +
|
createTable(db)
|
||||||
"WITH uuids($COLUMN_UUID, $COLUMN_NAME) AS (VALUES $uuidsValues) " +
|
val uuidsValues = volumeNames.indices.joinToString(", ") { "('${VolumeData.newUuid()}', ?)" }
|
||||||
"SELECT * FROM OLD NATURAL JOIN uuids;",
|
// add uuids to old data
|
||||||
volumeNames
|
db.execSQL(
|
||||||
)
|
"INSERT INTO $TABLE_NAME " +
|
||||||
db.execSQL("DROP TABLE OLD;")
|
"WITH uuids($COLUMN_UUID, $COLUMN_NAME) AS (VALUES $uuidsValues) " +
|
||||||
|
"SELECT $COLUMN_UUID, OLD.$COLUMN_NAME, $COLUMN_HIDDEN, $COLUMN_TYPE, $COLUMN_HASH, $COLUMN_IV " +
|
||||||
|
"FROM OLD JOIN uuids ON OLD.name = uuids.name;",
|
||||||
|
volumeNames
|
||||||
|
)
|
||||||
|
db.execSQL("DROP TABLE OLD;")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
fastlane/metadata/android/en-US/changelogs/35.txt
Normal file
1
fastlane/metadata/android/en-US/changelogs/35.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
- Really fix database upgrade crash
|
Loading…
Reference in New Issue
Block a user