数据库更新故障修复

pull/16/head
包尔俊 1 month ago
parent 737eb15e02
commit 2a5a3163dd

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1768961338889</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

@ -56,9 +56,9 @@ dependencies {
// "exclude" to listOf("")
// )))
//修改为如下代码:
implementation(files("D:\\college\\studying\\studying\\2025.09\\SE\\android\\client\\lib\\httpclient-osgi-4.5.14.jar"))
implementation(files("D:\\college\\studying\\studying\\2025.09\\SE\\android\\client\\lib\\httpclient-win-4.5.14.jar"))
implementation(files("D:\\college\\studying\\studying\\2025.09\\SE\\android\\client\\lib\\httpcore-4.4.16.jar"))
implementation(files("D:\\ke\\software_enginering\\httpcomponents-client-4.5.14-bin\\lib\\httpclient-osgi-4.5.14.jar"))
implementation(files("D:\\ke\\software_enginering\\httpcomponents-client-4.5.14-bin\\lib\\httpclient-win-4.5.14.jar"))
implementation(files("D:\\ke\\software_enginering\\httpcomponents-client-4.5.14-bin\\lib\\httpcore-4.4.16.jar"))
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)

@ -511,36 +511,51 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
boolean reCreateTriggers = false;
boolean skipV2 = false;
// 从V1升级到V2包括V2到V3
if (oldVersion == 1) {
upgradeToV2(db);
skipV2 = true; // this upgrade including the upgrade from v2 to v3
oldVersion++;
}
// 从V2升级到V3
if (oldVersion == 2 && !skipV2) {
upgradeToV3(db);
reCreateTriggers = true;
oldVersion++;
}
// 从V3升级到V4
if (oldVersion == 3) {
upgradeToV4(db);
oldVersion++;
}
// 从V4升级到V5
if (oldVersion == 4) {
upgradeToV5(db);
oldVersion++;
}
// 从V5升级到V6
if (oldVersion == 5) {
upgradeToV6(db);
oldVersion++;
// 使用 while 循环逐步升级到目标版本
while (oldVersion < newVersion) {
switch (oldVersion) {
case 1:
// 从V1升级到V2包括V2到V3
upgradeToV2(db);
skipV2 = true;
oldVersion = 2;
break;
case 2:
// 从V2升级到V3如果未被V2升级包含
if (!skipV2) {
upgradeToV3(db);
reCreateTriggers = true;
}
oldVersion = 3;
break;
case 3:
// 从V3升级到V4
upgradeToV4(db);
oldVersion = 4;
break;
case 4:
// 从V4升级到V5
upgradeToV5(db);
oldVersion = 5;
break;
case 5:
// 从V5升级到V6仅在需要时
if (newVersion > 5) {
upgradeToV6(db);
}
oldVersion = 6;
break;
default:
// 如果遇到未知版本,直接跳到目标版本
Log.w(TAG, "Unknown database version: " + oldVersion + ", skipping to " + newVersion);
oldVersion = newVersion;
break;
}
}
// 如果需要,重新创建触发器
@ -552,7 +567,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
// 检查升级是否成功
if (oldVersion != newVersion) {
throw new IllegalStateException("Upgrade notes database to version " + newVersion
+ "fails");
+ " fails. Current version: " + oldVersion);
}
}

Loading…
Cancel
Save