Discussion:
Add new function to mysql source code
(too old to reply)
Dushyantha Widanagamage
2009-10-18 05:41:28 UTC
Permalink
I want to add a new function to mysql.

For example

select function(parameter 1,parameter 2,...)
From table 1,table 2..
where criteria1,criteria2...

Can please anyone tell me how to do it?

Also if there is free refernces associated with this please tell me.

thanks in advance.
Gordon Burditt
2009-10-18 21:18:13 UTC
Permalink
Post by Dushyantha Widanagamage
I want to add a new function to mysql.
For example
select function(parameter 1,parameter 2,...)
From table 1,table 2..
where criteria1,criteria2...
What is this supposed to mean? Especially wierd is the comma operator
in the WHERE clause.
Post by Dushyantha Widanagamage
Can please anyone tell me how to do it?
Dushyantha Widanagamage
2009-10-19 04:29:16 UTC
Permalink
Post by Dushyantha Widanagamage
I want to add a new function to mysql.
For example
select function(parameter 1,parameter 2,...)
From table 1,table 2..
where criteria1,criteria2...
What is this supposed to mean?  Especially wierd is the comma operator
in the WHERE clause.
Post by Dushyantha Widanagamage
Can please anyone tell me how to do it?
I want to add a new function to mysql.

An example of query given as follows.

select route(7.00,9.00.)
From routeTable
where id="UA17"

I want to implement function route to mysql source code and want to
use it in sql script as shown above.

Please reply
Thanks.
Gordon Burditt
2009-10-19 05:16:55 UTC
Permalink
Post by Dushyantha Widanagamage
An example of query given as follows.
select route(7.00,9.00.)
From routeTable
where id="UA17"
I want to implement function route to mysql source code and want to
use it in sql script as shown above.
There are 3 ways to do this:
(1) Define a stored function written in SQL query language.
(2) Define a user-defined function (UDF) as a plugin which will be
loaded by the server at runtime.
(3) Add a native function into mysqld itself.

Section 21 of the MySQL 5.1 Reference Manual is "Extending MySQL".
For other versions, the section number may change.

(1) If it's awkward to do what you want in SQL, this may not be the
best method.
(2) allows you to use C or other languages for the plugin, without the
inconvenience of recompiling mysqld each time. You do need to
use CREATE FUNCTION to register the plugin.
(3) avoids the need to install other files besides mysqld itself.

This section describes how to write user-defined-functions (2) and
how to add native functions (3). For (1), see the section titled
"Stored Programs and Views".

At one time I tried doing this to add a few simple functions that were
better expressed in C, related to determining if two IP addresses
were in the same subnet. It was fairly straightforward.
Dushyantha Widanagamage
2009-10-23 05:06:25 UTC
Permalink
I want to implement a new function and I want to use in sql scripts. An example is given below.
select route(7.00,9.00.)
From routeTable
where id="UA17"
Here route function includes very heavy mathematical computation. So I will be needing a programming lanuage like C or C++ for processing.
To do this either I have to write a plugin or native functions to mysql.
I have read the following section MySQL 5.1 Reference Manual "Extending MySQL". But it does not include a full explanation how to add a plugin or > to implement native functions. Also it does not explain how to use existing functions and data structures.
So can anybody set of ebooks tutorials, or a document, which explains how to add plugin or to implement native functions in mysql.
Optionally it would be nice if those references and they are free and they are written explicitly to explain how to write native functions or a plugin.
If you have done simple work please be kind enough to send me explaining how you have done it.
Thanks in advance.

Loading...