i use a global property in my app to handle my SQLite-Methods. The Property is called DB and has a type SQLiteDatabase. Now i want to change my OpenDatabase-Method to check first, if there is a MySQL-Connection. If not, load the local SQLite Database.
The best way for me would be to change the Property Type (DB) from SQLiteDatabase to MySQLCommunityServer. But i didn’t get how to change the properties type by code. Is there any chance to do this?
Two key concepts to get you going in the right direction. Casting and ISA.
dim db as Database
db = new sqlitedatabase // valid
db.DatabaseFile = f // not valid
db = new mysqlcommunityserver // valid
db.host = "10.0.0.1" // not valid
Solve those problems by testing the type of object db holds with ISA and then casting to the appropriate type to access the specific properties.
dim db as Database
db = new ???
if db ISA sqlitedatabase then
sqlitedatabase(db).DatabaseFile = f
elseif db ISA mysqlcommunityserver then
mysqlcommunityserver(db).host = "10.0.0.1"
end
first of all thanks for your help and ideas. I managed it a different way. To post code would be a bit much to read, but in simple words i realized to switch between Offline- (SQLite) and Online-Mode (MySql) by using 2 different global properties (SQLiteDB and MySqlDB) and build in some litte if-statements in my db-methods.
Example:
User starts app, we try to connect a MySqlDB, if connect went fine, a property OfflineMode is set to False. This property is checked in all of my database-methods. If connect went wrong, the property OfflineMode is set to True and the database-methods use a local copy (SQLite) of my database instead. We are also implementing a sync-process, so the user can still create datasets when offline.
Hope i can release this app (it will be a CRM, mostly needed by ourselves) in the App Store within the next months.