User-defined functions are compiled as shared object files and then added to and removed from the MySQL server dynamically. I hacked up a small test to demonstrate their implementation, although I'll only show you the results here.

CREATE TABLE u ( username varchar(20) );
INSERT INTO u VALUES ('jpm');
SELECT * FROM u;
+----------+
| username |
+----------+
| jpm      |
+----------+

So far, nothing special, but now for something completely different:

CREATE FUNCTION ldapcn RETURNS STRING SONAME 'libudf_jp2.so';

The CREATE FUNCTION loads the shared object file into the server's address space, where it remains available until the function is dropped from the data dictionary.

SELECT username, LDAPCN(username) AS cn FROM u;
+----------+---------------+
| username | cn            |
+----------+---------------+
| jpm      | Jan-Piet Mens |
+----------+---------------+

During the SELECT, MySQL invokes my UDF, passing it the string argument, and I go off and search for the user in an LDAP directory tree, returning the user's Common Name as the function's value. That in turn is the result of the function which MySQL uses. Powerful. More on MySQL UDF.

Flattr this
LDAP, MySQL, and Database :: 23 Nov 2007 :: e-mail

Comments

blog comments powered by Disqus