From 655bbd893916dca3e4c27da27f76a50aec9740de Mon Sep 17 00:00:00 2001
From: tj <1378534974@qq.com>
Date: 星期四, 27 二月 2025 17:11:01 +0800
Subject: [PATCH] 1
---
app/src/main/java/com/example/firstapp/database/AppDatabase.kt | 51 +++++++++++++++++++++++++++++++++++++--------------
1 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/app/src/main/java/com/example/firstapp/database/AppDatabase.kt b/app/src/main/java/com/example/firstapp/database/AppDatabase.kt
index 42a1399..2251240 100644
--- a/app/src/main/java/com/example/firstapp/database/AppDatabase.kt
+++ b/app/src/main/java/com/example/firstapp/database/AppDatabase.kt
@@ -8,9 +8,13 @@
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.example.firstapp.database.dao.CodeDao
+import com.example.firstapp.database.dao.KeywordDao
import com.example.firstapp.database.dao.MsgDao
+import com.example.firstapp.database.dao.ReminderDao
import com.example.firstapp.database.entity.Code
+import com.example.firstapp.database.entity.KeywordEntity
import com.example.firstapp.database.entity.Msg
+import com.example.firstapp.database.entity.Reminder
import com.example.firstapp.utils.DATABASE_NAME
import com.example.firstapp.utils.SettingUtils
import com.example.firstapp.utils.TAG_LIST
@@ -20,15 +24,16 @@
@Database(
- entities = [ Msg::class, Code::class],
-// views = [LogsDetail::class],
- version = 19,
+ entities = [ Msg::class, Code::class, KeywordEntity::class, Reminder::class],
+ version = 20,
exportSchema = false
)
@TypeConverters(ConvertersDate::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun msgDao(): MsgDao
abstract fun codeDao(): CodeDao
+ abstract fun keywordDao(): KeywordDao
+ abstract fun reminderDao(): ReminderDao
companion object {
@Volatile
@@ -81,21 +86,39 @@
//database.execSQL("Create table Msg as Select id,type,`from`,content,(case when sim_info like 'SIM1%' then '0' when sim_info like 'SIM2%' then '1' else '-1' end) as sim_slot,sim_info,sub_id,time from Logs where 1 = 1")
database.execSQL(
"""
-CREATE TABLE "Msg" (
- "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- "type" TEXT NOT NULL DEFAULT 'sms',
- "from" TEXT NOT NULL DEFAULT '',
- "content" TEXT NOT NULL DEFAULT '',
- "sim_slot" INTEGER NOT NULL DEFAULT -1,
- "sim_info" TEXT NOT NULL DEFAULT '',
- "sub_id" INTEGER NOT NULL DEFAULT 0,
- "time" INTEGER NOT NULL
-)
-""".trimIndent()
+ CREATE TABLE "Msg" (
+ "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ "type" TEXT NOT NULL DEFAULT 'sms',
+ "from" TEXT NOT NULL DEFAULT '',
+ "content" TEXT NOT NULL DEFAULT '',
+ "sim_slot" INTEGER NOT NULL DEFAULT -1,
+ "sim_info" TEXT NOT NULL DEFAULT '',
+ "sub_id" INTEGER NOT NULL DEFAULT 0,
+ "time" INTEGER NOT NULL
+ )
+ """.trimIndent()
)
database.execSQL("CREATE UNIQUE INDEX \"index_Msg_id\" ON \"Msg\" ( \"id\" ASC)")
+ // 新增 KeywordEntity 表的创建逻辑
+ database.execSQL("""
+ CREATE TABLE IF NOT EXISTS `keywords` (
+ `id` INTEGER PRIMARY KEY AUTOINCREMENT,
+ `keyword` TEXT NOT NULL,
+ `type` TEXT NOT NULL,
+ `isEnabled` INTEGER NOT NULL
+ )
+ """)
+// database.execSQL("""
+// CREATE TABLE IF NOT EXISTS `reminders` (
+// id INTEGER PRIMARY KEY AUTOINCREMENT,
+// type TEXT NOT NULL,
+// nickname TEXT NOT NULL,
+// keywords TEXT NOT NULL,
+// );
+// """)
+
}
}
--
Gitblit v1.9.3