Working with Databases
From Xojo Documentation
These questions are related to working with databases.
Contents
What databases does Xojo support?
Xojo has built-in support for these databases:
- SQLite
- PostgreSQL
- MySQL (or MariaDB)
- Oracle
- Microsoft SQL Server
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:
- Using SQLite
- SQLite
- PostgreSQL
- Designing Delightful Databases
- Connecting to Databases
- Database Development
There are several database example projects included with Xojo. Refer to this folder:
- Examples/Databases
How do I get the number of rows in a RecordSet?
The RecordSet.RecordCount property can tell you the number of rows in the RecordSet for these databases:
- SQLiteDatabase
- PostgreSQLDatabase
- OracleDatabase
- ODBCDatabase (depends on the database driver you are using)
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 RecordSet results:
Dim rs As RecordSet = myDatabase.SQLSelect(sql)
If rs <> Nil And Not myDatabase.Error Then
Dim rowCount As Integer = rs.IdxField(1).IntegerValue
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 apps connects to the web service (using Xojo.Net.HTTPSocket). For more information, here are some videos on this topic: