Writing User-Defined Functions

Updated: April 19, 2023

QDB allows you to write your own functions for manipulating data. The QDB library includes several data structures and functions useful for defining custom functionality, while the SQLite API provides methods that your custom code can call to access arguments or set results.

You can write two types of user-defined functions for QDB to use: scalar or aggregate functions (which transform data), or collation routines (which order/sort data). Scalar functions are invoked using the SELECT SQL statement, while collation routines are invoked using the COLLATE clause. An example of a built-in scalar function is ABS(), while BINARY() is an example of a built-in collation routine.

To make your functions usable to QDB, you need to compile them into a DLL. You then tell QDB to load the DLL by setting the Collation or Function options in the database configuration object, for each required function.