This repository contains an example of a C User-Defined Function (UDF) for MariaDB. The UDF takes a string as input and returns a string as output.
string_udf.c
: The C source file for the UDF.Makefile
: The makefile to compile the UDF into a shared library.string_udf.sql
: The SQL script to create the UDF in MariaDB.Dockerfile
: The Dockerfile to build an image with MariaDB and compile the UDF.
- MariaDB installed and running.
- GCC compiler and Make utility installed.
- Create the Shared Library:
Place
string_udf.c
,Makefile
, andstring_udf.sql
in the same directory. Run the following command to compile the UDF:make sudo make install
-
Connect to MariaDB Database: Use
mysql
or another MariaDB client to connect to your database. -
Create the UDF: Execute the following SQL command to create the UDF:
CREATE FUNCTION string_udf RETURNS STRING SONAME 'string_udf.so';
- Test the UDF:
Verify that your UDF is working by calling the function in SQL. Run:
This should return
SELECT string_udf('Hello, World!');
Hello, World!
if the UDF is functioning correctly.
This project is licensed under the MIT License - see the LICENSE file for details.