Skip to content

Using Firebird with Xojo

Firebird is a completely free (cost and license), cross-platform database with some interesting features.

Although Xojo does not have a native plugin for connecting to Firebird, you can use the ODBC plugin in conjunction with the Firebird ODBC drivers to use Firebird with Xojo.

Firebird can be used two ways, as a database server or as an embedded database. This shows you how to use both using Firebird running on Windows.

Connect to the Server

Once you download and install Firebird (which took me about a minute on Windows 10 using the default settings), you can then get the ODBC drivers, which have to be downloaded separately. Note, there are only ODBC drivers available for Windows and Linux on the Firebird site. You can find updated drivers (not free, but they have a 30-day trial), including ones for Mac from devart.

After installing the ODBC drivers, you can go to the ODBC Control Panel and add a data source by selecting the Firebird/Interbase driver from the list.

ODBCServerSettings.png

For the DSN name, I used “FirebirdServerTest”.

I used this value for the Database property:

10.0.1.16:C:Program FilesFirebirdFirebird_2_5examplesempbuildemployee.fdb

Use “SYSDBA” for the Database Account and “masterkey” as the password. You don’t need to change any other settings.

Use the “Test connection” button in the window to verify that you can connect.

Connect Directly to a Database File

If you did not already install the ODBC drivers from above, you will need to do so now. After installing the ODBC drivers, you can go to the ODBC Control Panel and add a data source by selecting the Firebird/Interbase driver from the list.

ODBCEmbeddedTest.png

For the DSN name, I used “FirebirdEmbeddedTest”.

Firebird includes a sample database, which was located here on my Windows installation:

C:\Program Files\Firebird\Firebird_3_0\examples\empbuild\EMPLOYEE.FDB

I copied this file to the Desktop. Use “SYSDBA” for the Database Account and “masterkey” as the password. Click the “Test Connection” button to verify that everything is correct. If so, you are now ready to connect using Xojo.

Connecting Using Xojo

Now that you have created your ODBC DSN entries, you can use this with the Xojo ODBC plugin to connect to the database. The code to do this is similar to most Xojo database code. I’m going to have a single method that is used to connect using the specified DSN. This method is called ConnectToFirebird(dsn As String):

Dim db As New ODBCDatabase
db.DataSource = dsn

If db.Connect Then  ListBox1.DeleteAllRows
  Dim sql As String = "SELECT emp_no, full_name, job_code, job_country FROM employee;" Dim rs As RecordSet  rs = db.SQLSelect(sql)

  If rs <> Nil And Not db.Error Then
    While Not rs.EOF
      ListBox1.AddRow(rs.Field("full_name").StringValue)
      rs.MoveNext
    Wend
   rs.Close
  End If
End If

This method connects to the sample database and adds all the names in the employee table to a ListBox. You can call this method and supply the name of the DSN to use to connect.

Add a button to test the embedded connection and add this code to its Action event handler:

ConnectToFirebird("FirebirdEmbeddedTest")

Now add a button to test the server connection and add this code to its Action event handler:

ConnectToFirebird("FirebirdServerTest")

Run the app and click the buttons to see the ListBox get populated.

FirebirdExample

Learning More

Now that you know how to use Firebird, you can spend some time with its documentation to learn more about it.

Download the Firebird project.