Getting started accessing databases

These questions are related to working with databases.

What databases does Xojo support?

Xojo has built-in support for these databases:

In addition, you can use ODBC to connect to just about any other type of database, including Access, Firebird, IBM DB2 and more:

How do i get started with databases?

To start learning about working with databases, read the Databases section of the User Guide, which covers database concepts, operations and usage of specific databases. Start here:

If you need more specific hands-on training, here are some videos:

There are several database example projects included with Xojo. Refer to:

  • Examples/API/Databases

  • Examples/Topics/Databases

How do i get the number of rows in a RowSet?

The RowSet.RowCount property can tell you the number of rows in the RowSet for these databases:

This property does not work for other database types.

Alternatively, you can create a SQL SELECT statement to return the number of rows in a query. This is done using the COUNT method. The exact syntax varies by database, but is usually something like this:

SELECT COUNT(*) As RowCount FROM TableName WHERE value1 = x AND value2 = y

With this SELECT statement, you can then check the result in RowSet results:

Var sql As String = "SELECT COUNT(*) AS RowCount FROM Table1 WHERE ID = 1"
Try
  Var rs As RowSet = myDatabase.SelectSQL(sql)
  Var rowCount As Integer = rs.ColumnAt(0).IntegerValue
Catch error As DatabaseException
  MessageBox("DB Error: " + error.Message)
End If

How do i connect to a database server from an iOS app?

iOS apps should not directly connect to database servers like desktop apps do. There are several reasons for this:

  • iOS devices may not have a reliable or fast network connection, making DB server connections unreliable.

  • Maintaining a constant connection to a database server would dramatically reduce battery life.

  • Apple does not include native drivers for database servers with iOS and it is not practical to embed your own.

However, you can still connect to a database server! You just have to do it with a web service. The general concept is that you would create a web service and companion API (using Xojo or another tool) that connects to the database server. The iOS app connects to the web service (using URLConnection). For more information, here are some videos on this topic: