Showing posts with label UDF. Show all posts
Showing posts with label UDF. Show all posts

Sunday, October 25, 2015

A MySQL UDF written in Go

I was wondering if it is possible to write a MySQL User Defined Function (UDF) in Go.  
So I tried and I got a very basic UDF working.
mysql> SELECT udf_fileexists_go("/etc/hosts");
+---------------------------------+
| udf_fileexists_go("/etc/hosts") |
+---------------------------------+
|                               1 |
+---------------------------------+
1 row in set (0.00 sec)

mysql> SELECT udf_fileexists_go("/nonexistend");
+-----------------------------------+
| udf_fileexists_go("/nonexistend") |
+-----------------------------------+
|                                 0 |
+-----------------------------------+
1 row in set (0.00 sec)

This is nowhere near production quality, so be careful.

The code is here:https://github.com/dveeden/udf_fileexists_go/blob/master/udf_fileexists_go.go.

Tuesday, July 5, 2011

Working with IP's in MySQL and MariaDB - Part 2

Use DNS directly from your database

mysql> SELECT lookup('localhost');
+---------------------+
| lookup('localhost') |
+---------------------+
| 127.0.0.1           |
+---------------------+
1 row in set (0.00 sec)

mysql> SELECT reverse_lookup('127.0.0.1');
+-----------------------------+
| reverse_lookup('127.0.0.1') |
+-----------------------------+
| localhost                   |
+-----------------------------+
1 row in set (0.00 sec)

This is how you install these functions.
  1. Build udf_example.so which is in your mysql source. (make udf_example.so)
  2. Copy the udf_example.so file from your build directory to your plugin_dir.
  3. Create the lookup and reverse_lookup functions
mysql> CREATE FUNCTION lookup RETURNS STRING SONAME 'udf_example.so';
Query OK, 0 rows affected (0.00 sec) 
mysql> CREATE FUNCTION reverse_lookup RETURNS STRING SONAME 'udf_example.so';
Query OK, 0 rows affected (0.00 sec)

I've created a feature request for IPv6 support to these functions.