How to know wether there is a table in my database or not?
I am using Realm datebase. Now I have problem in knowing there is a table in my database?
Well if you're missing any tables, the Realm migration will run, and you'll need to add it to the schema.
If you didn't increment the schema version number and define a migration, and you didn't set deleteIfMigrationNeeded, then it'll give you an exception that'll tell you that you have a missing table.
Well if you're missing any tables, the Realm migration will run, and you'll need to add it to the schema.
If you didn't increment the schema version number and define a migration, and you didn't set deleteIfMigrationNeeded, then it'll give you an exception that'll tell you that you have a missing table. @Zhuinden Thank you. Maybe I didn`t describe my problem well. Then allow me describe its details. I use table A in a component, but when I package this component separately, table A may not exist and is not created, I need to know wether it exsist or not to decide which action I should take.
Well, if you add the table with a @RealmModule and it's not there, then it will trigger a migration.
@Zhuinden I think this has nothing to do with the old and new versions of realm, so it does not need to be migrated
@Zhuinden This is method of other database , I find it on the Intenet.
select count(*) from all_tables where table_name='TABLENAME';
Okay, technically you can check if Realm has a table with a given name using
val dynamicRealm = DynamicRealm.getInstance(realmConfiguration)
val schema = dynamicRealm.schema
val hasTable = schema.get("MyTableName") != null
...
dynamicRealm.close()
@Zhuinden Thank you very much, I will try it.
Closed as question seems to have been answered.