REALbasic Built in Database Tutorial Part 1
REALbasic comes with build in support for the REALsql database which is basically a single user version of SQLite. This is ideal for use as a local cache for preferences information, window settings etc. It is also useful for so much more.
In this, the first of a series of tutorial posts I will present ideas and code for utilising the database from within REALbasic. I don’t suggest this is the only way or the best way - but it works and works well.
When writing database applications I try and support multiple databases. To ensure that the code for each is optimised to that particular database I generally design this as follows:
First I setup a property that tells me which database I have chosen to work with. For the purposes of this tutorial we will setup this property against the Application and refer to it as App.pDatabase.
I also setup a pair of modules:
mDBWhich
mDBSQLite
When a database access is required, for example a ‘Save’ button is pressed on a Form, the simplified sequence of events looks like this:
Form
mDBWhich.SaveCustomer(parameters)
mDBWhich.SaveCustomer
Select Case App.pDatabase
Case ‘SQLite’
mDBSQlite.SaveCustomer(parameters)
Case’Oracle’
.
.
.
End Select
One advantage of this method is that your form knows nothing about your database so if and when you decide to add support for an additional database to your application it is necessary only to add additional switching to the mDBWhich module and create a new module for your new database. There is no need for your GUI to be altered.
We’ll see some real examples of this in action in later posts, but for know bear it in mind but don’t worry about it. All will become clear. In the next post I will show you how to create a database, populate it with tables and indexes and populate them with some default data. All ‘on the fly’ from REALbasic.
Any feedback, good, bad, indifferent and also any suggestions for what you would like to see covered - leave a comment or drop me an email to stevecholerton@mac.com
RSS Feed: http://feeds2.feedburner.com/Lonelyhacker


