My project can be upgraded by the user from SQLite to CubeSQL. I use db as Database as a property of the app and instantiate it as either SQLiteDatabase or CubeSQL. LastRowID is a method of both SQLite and Cube, but I cannot figure out how to subclass Database to include the LastRowID method.
You can’t subclass database like that. Instead you’ll need to cast it to the appropriate type to get LastRowID.
Dim lastID As Integer
If App.DB IsA SQLiteDatabase Then
lastID = SQLiteDatabase(App.DB).LastRowID
ElseIf App.DB IsA CubeSQLDatabase Then
lastID = CubeSQLDatabase(App.DB).LastRowID
End If
Take the above and put it in an extends method in a module:
Function LastRowID(Extends DB as Database) As Integer
If DB IsA SQLiteDatabase Then
Return SQLiteDatabase(DB).LastRowID
ElseIf DB IsA CubeSQLDatabase Then
Return CubeSQLDatabase(DB).LastRowID
Else
'raise an exception
End If
End Function
Now you can use
X = theDatabase.LastRowID