I have an application that accesses a database within cubeSQL. I set a global property of type cubeSQL in my App.Open method.
property DB as cubeSQL
This all works fine.
Now I want to give the application the ability of opening a local database instead,
property DB as RealSQLDatabase
BUT… I need the application to be able to open either. As DB is used extensively throughout the application I was wondering if there was a way of defining the property in code rather than in my global module. Something like:
#if UsecubeSQL then
global dim DB as cubeSQL
#else
global dim DB as RealSQLDatabase
#endif
UseSQL is defined as a global elsewhere.
Some help in this would be greatly appreciated.
Simon.
You should be able to just use Database as the object. That said, you may need to cast db to the correct type if there are any API differences (like prepared statesments).
As Greg says, use the superclass instead:
Property DB As Database
Then when the user choose the DB type, create the appropriate instance:
If UseCubeSQL Then
DB = New CubeSQL
Else
DB = New SQLiteDatabase ' replacement for RealSQLDatabase
End If
The only other thing to keep in mind is you’ll have to cast DB to the appropriate type to get at specific methods or properties of CubeSQL or SQLiteDatabase that are not on the Database class. For example:
If DB IsA SQLiteDatabase Then
SQLiteDatabase(DB).DatabaseFile = myDBFile
End If
Thank you all for your comments.
Unfortunately the second DB (local one) is accessed via the MBS SQL Plugin so the commands are different. However, the posts have pointed me in a different direction so I think I can solve the problem now.
Thanks to all.
Simon.