File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
kommunicate/src/main/java/io/kommunicate/database Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ import kotlin.Throws
1111object DatabaseMigrationHelper {
1212 private const val TEMP_ENCRYPTED_DB_NAME = " temp_encrypted.db"
1313
14+ // Check if table exists in destination DB
15+ private fun tableExists (db : SQLiteDatabase , tableName : String ): Boolean {
16+ return db.rawQuery(
17+ " SELECT 1 FROM sqlite_master WHERE type='table' AND name=? LIMIT 1" ,
18+ arrayOf(tableName)
19+ ).use { cursor -> cursor.moveToFirst() }
20+ }
21+
1422 @JvmStatic
1523 @Throws(Exception ::class )
1624 fun migrateDatabase (context : Context , dbName : String ) {
@@ -83,6 +91,12 @@ object DatabaseMigrationHelper {
8391 continue
8492 }
8593
94+ // Verifies if table exist
95+ if (tableExists(destinationDb, tableName)) {
96+ println (" Table $tableName already exists in destination DB, skipping creation." )
97+ continue
98+ }
99+
86100 // Copy table schema
87101 val createTableSql = getTableCreateSql(sourceDb, tableName)
88102 destinationDb.execSQL(createTableSql)
You can’t perform that action at this time.
0 commit comments