A Code Stub Generator For MySQL and Drizzle Plugins Presentation
A Code Stub Generator For MySQL and Drizzle Plugins Presentation
●
to add functionality not available elsewhere
●
to build upon functionality already available
in a C/C++ library
●
to get better performance by using native
code
Why a code generator?
●
less steep learning curve
●
faster development, focus on actual
functionality
●
API changes can be dealt with in one central
place
●
automate boring tasks
Aspects of building a UDF or Plugin
Build Infrastructure
API Infrastructure
Implementation of actual functionality
Testing
Documentation
Generator Requirements
PHP 5.x
PEAR
( PHP Extension & Application Repository )
PEAR Packages:
CodeGen & CodeGen_MySQL
CodeGen_MySQL_UDF
CodeGen_MySQL_Plugin
CodeGen_Drizzle
Build Infrastructure
<?xml version="1.0"?>
<udf name="dummy">
</udf>
udf-gen dummy.xml
Generated Files
twice
|-- AUTHORS
|-- CMakeLists.txt
|-- ChangeLog
|-- INSTALL
|-- Makefile.am
|-- NEWS
|-- README
|-- configure.ac
|-- twice.c
|-- m4/
| |-- ax_compare_version.m4
| |-- mysql.m4
|-- manual.xml
|-- mysql.m4
|-- tests/
| |-- create_functions.inc
| |-- drop_functions.inc
| |-- r/
| |-- t/
| `-- test.sh
`-- udf_twice.h
A 'real' Example
<?xml version="1.0"?>
<udf name="twice">
<function name="twice"
returns="int">
<param name="val" type="int"/>
<code>
return val * 2;
</code>
</function>
</udf>
Compiling the generated Code
$ udf-gen twice.xml
$ cd example
$ ./configure --with-mysql=...
--libdir=...
$ make
Instaling the generated Function
Install the UDF libary
sudo make install
Register the function
CREATE FUNCTION twice
RETURNS INTEGER
SONAME "twice.so";
Test the function
SELECT twice(3); -- result: 6
Aggregate functions
<test name=”twice”>
<code>
SELECT twice(3);
</code>
<result>
twice(3);
6
</result>
</test>
Invoking the Tests
Both the mysqltest and mysqld binaries
have to be in $PATH
invoke tests with make test
$ PATH=$PATH/usr/local/mysql/bin
$ PATH=$PATH/usr/local/mysql/libexec
$ export PATH
$ make test
*** testing ***
[twice] ok
Packing a Source Release
To pack the generated source for distribution use
either make dist or make distcheck
make dist creates a source tarball
make distcheck creates a source tarball, unpacks it
in a temporary directory and checks that building it
works (e.g. no files left out when packing)
Documentation can be generated using
make html and make pdf
if you have docbook-utils installed
Things not shown here
Author, Copyright and License Information
Library and Header File Dependencies
Adding C/C++ code files
Lex/Flex and Yacc/Bison support
Windows Builds using CMake
DBUG functions
Plugins
allow to extend the server using shared libraries and
well defined registration APIs
currently supported plugin types are
“deamons”
storage engines
fulltext parsers
INFORMATION_SCHEMA tables
Audit
Replication
Authentication
Building a Plugin
first install the plugin library
sudo make install
then for each plugin defined in the library do
INSTALL PLUGIN “plugin_name”
SONAME “plugin_library.so”;
to uninstall use
UNINSTALL PLUGIN;
A Daemon Plugin
<plugin name="daemon_example">
<maintainer>
<name>Hartmut Holzgraefe</name>
<email>hartmut@mysql.com</email>
</maintainer>
<license>GPL</license>
<release>
<version>0.0.1</version>
<date>2008-04-16</date>
<state>alpha</state>
<notes>just an experiment</notes>
</release>
<daemon name="dummy">
<summary>minimal example plugin</summary>
<init>fprintf(stderr, “daemon started\n”);</init>
<deinit>fprintf(stderr, “deamon stopped\n”);</deinit>
</daemon>
</plugin>
Adding server variables
<statusvar
type="int"
name="THE_ANSWER"
init="42"
/>
table->field[FIELD_FOO_INT]->store(23);
table->field[FIELD_FOO_STRING]->store("foobar", 7, system_charset_info);
schema_table_store_record(thd, table);
table->field[FIELD_FOO_INT]->store(42);
table->field[FIELD_FOO_STRING]->store("barfoo", 7, system_charset_info);
schema_table_store_record(thd, table);
dummy_count++;
return 0;
]]>
</code>
</infoschema>
A Fulltext Parser Plugin
<fulltext name="dummy">
<summary>minimal example plugin</summary>
<parser>
<code>
<![CDATA[
char *doc;
int result;
return result;
]]>
</code>
</parser>
</fulltext>
Things not covered (here) ...
Storage engine plugins
Fulltext plugin details
Status variable datatypes and callbacks
Command line options
header file and library dependencies
...
Conclusion
Trac/Wiki
http://codegenerators.php-baustelle.de/
PEAR Packages
http://pear.php.net/package/CodeGen
http://pear.php.net/package/CodeGen_MySQL
http://pear.php.net/package/CodeGen_MySQL_UDF
http://pear.php.net/package/CodeGen_MySQL_Plugin
UDF projects
http://udf-ora.php-baustelle.de/
http://udf-regexp.php-baustelle.de/
...