No Description
MicroCheapFx 4e436745ef Merging origin/master 10 months ago
include Working with setup.ch 10 months ago
src Working with setup.ch 10 months ago
test Working with setup.ch 10 months ago
.gitignore Working with setup.ch 10 months ago
.gitignore.orig Merging origin/master 10 months ago
CMakeLists.txt Working with setup.ch 10 months ago
README.md Working with setup.ch 10 months ago
hello.so Working with setup.ch 10 months ago
setup.sh First commit 10 months ago

README.md

Writing a simple UDF for mariadb

This is a simple demo to show maridb UDF mechanisms.

Preparation

In order to follow this tutorial, you’ll need the following tools:

  • GCC
  • Mariadb or even MySQL
  • CMake (not mandatory)

What it will do

This UDF doesn’t do a real killer feature. It just return a “Hello” message to mariadb. But it is simple enough to understand how it works.

MariaDB [(none)]> SELECT hello('John Doe');
+-------------------+
| hello('John Doe') |
+-------------------+
| Hello John Doe!   |
+-------------------+
1 row in set (0.00 sec)

Few explanations before starting

User Defined Functions are stored in dynamical shared libraries (.so files) and are sets of functions adding new possibilities to mariadb engine.

With them, you’ll be able to process data with C execution fuzzing speed or even be able to communicate with the rest of your operating system.

What is essential to understand is that they are external to mariadb. So in order to communicate with the engine, they need to communicate in a standard way with a predefined set of variables and functions.

Also, as they are only shared libraries, you won’t be able to debug them within mariadb. In order to fix that, we’ll write a little program in C, mocking mariadb engine. This program will also be a good unit testing set.

Let’s get into it…

Mariadb and UDF communication

UDF structure

hello_init()

hello()

hello_deinit()

UDF_ARGS and UDF_INIT structures

UDF_INIT

UDF_ARGS

External links