Table of Contents

Editor: SQLite Databases

SQLite Databases

SQLite is a software library that provides a relational database management system. The lite in SQLite means lightweight in terms of setup, database administration, and required resources. SQLite does not require a separate server process or system to operate (serverless); it allows accessing the database using a nonstandard variant of the SQL query language. It’s a popular local/client storage choice due to its simplicity and easy setup.

The Unreal Engine natively does not have Blueprint functions to read and write to SQLite files. However, Nominal has provided helper functions to work with SQLite Database files. This document will demonstrate how to read and write SQLite Database files. An overview of the Nominal Systems SQLite Database functions is below.

Untitled

The Demo_SQLite_TMTC demo will be a practical example in this guide.


Opening and closing an SQL Database

To Open a SQLite Database, the SQLite Open function is used by passing in the full path to the file. If the database file doesn’t exist, the SQLite Open function will create one with the specified file name at the defined path.

Note

The Path Utilities functions provided by Unreal can be used to get the path to select folders within the U Project that can then be appended to allow for limited relative pathing. These functions include Get Project Content Directory, Get Project Directory and Get Project Saved Directory.

The return of the SQLite Open function can then be stored as a variable for ease of use within Blueprints. The SQLite Close function is used to Close an Open SQLite Database file. It is recommended that the SQLite Close function is called on Event End Play for each Database File to ensure that the files are closed at the end of a simulation as a safety net.


Reading and Writing Data to an SQL Database

Once an SQLite database file has been opened or created, data is written or read from tables. An SQLite Database Table is a structured data set within the file that can be accessed. To create an SQLite Table, the SQLite Create Table function is used with the name of the Table and an array of the Column Names passed in. A single SQLite Database File can contain multiple SQLite Tables of different names; individual tables can also be deleted with the SQLite Delete Table function. The following example is creating a table of Magnetometer data for export.

Untitled

Columns can be manually added with the SQLite Add Column and deleted with the SQLite Delete Column functions. The SQLite Select Column function returns the first-row entry of a specific column that matches the specified condition; if no condition is set, the first-row entry of the column is returned. The SQLite Select Record performs a similar function but produces the first-row entry for select columns. Records within the SQLite Database Table can also be manually inserted and deleted with the SQLite Insert Record and SQLite Delete Record functions.

The SQLite Query provides the functionality of general SQLite Database Queries and will return a string array dependent on the configured query.


SQL Database Utilities

Nominal Systems have also provided a series of SQLite Database File utilities or helper functions that provide the following functionality:

  • SQLite Column Names returns an array of each column name in an SQLite Table.
  • SQLite Column Types returns an array of each of the column types in the SQL Database Table.
  • SQLite Count Table Rows returns the number of rows in the specified Table.