Getting started accessing databases

Whether you have never worked with a database or are a seasoned professional, building applications that communicate with a database is easy in Xojo.

Database Beginners

If you're entirely new to databases or specifically SQL databases, you'll want to learn the basic database terminology and then understanding how to connect to a database and how to add, update and delete rows.

Creating a database

If you don't already have a database to which you wish to connect, you'll need to create one. Creating a database is not something that Xojo does and it very much depends on which database you are using. TablePlus makes it easy to create databases for all the database engines that Xojo supports and runs on Linux, macOS, Windows and even iOS.

Connecting to a database

The easiest way to connect to a database is using the DatabaseConnection object as this requires no code. You can also connect to a database via code using the Connect method of the Database class.

Making all or nothing updates to a database

Database engines allow you to make changes to multiple rows including adding new rows and deleting others and decide afterwards whether or not you wish to keep these changes or discard them. This is accomplished through something called a Transaction.

Next steps

Once you understand the basics, have created a database and have a connection to your database, the next step is to start using it in your project. Some additional items to explore are:

Item

Description

DBKit

A set of classes that make it easy to build database applications.

MySQLCommunityServer

The class used to access a database on a MySQL and MariaDB database servers.

ODBCDatabase

The class used to access a database via an ODBC driver. This will allow you to connect to databases that Xojo does not natively support.

PostgreSQLDatabase

The class used to access a database on a PostgreSQL database server.

SQLiteDatabase

The class used to access a SQLite database.

Database

The parent class of all the provided database classes.

Tip

If you need to host a database on the Internet, Xojo Cloud provides support for MySQL, PostgresSQL and SQlite.

More Resources

There are videos available that explain details about specific database engines.

Example projects

There are several database example projects included with Xojo. Choose File > New Project, click on Examples in the New Project dialog box and then explore the Databases folder.