Working with Databases
From Xojo Documentation
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:
- Using SQLite
- Designing Delightful Databases
- Connecting to Databases
- Database Development
There are several database example projects included with Xojo. Refer to this folder:
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:
- 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 RowSet results:
Var rs As RowSet = myDatabase.SelectSQL(sql)
Var rowCount As Integer = rs.ColumnAt(0).IntegerValue
Catch error As DatabaseException
MessageBox("DB Error: " + error.Message)
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 URLConnection). For more information, here are some videos on this topic: