1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

new UDF arguments interface (WL#1017) (SCRUM)

include/mysql_com.h:
  new UDF arguments interface
sql/item.cc:
  added lenghth name foe item (to avoid strlen() call)
sql/item.h:
  added lenghth name foe item (to avoid strlen() call)
sql/item_func.cc:
  new UDF arguments
sql/sql_parse.cc:
  fixed problem with UDF in 5.0
sql/sql_yacc.yy:
  new syntax of UDF arguments
sql/udf_example.cc:
  new UDF example (stupid function to test parameters)
tests/udf_test.res:
  new UDF example (stupid function to test parameters)
tests/udf_test:
  new UDF example (stupid function to test parameters)
This commit is contained in:
unknown
2003-09-13 17:47:59 +03:00
parent 55e776d145
commit 07e372cd6b
9 changed files with 134 additions and 14 deletions

View File

@ -56,7 +56,9 @@
**
** Function 'myfunc_int' returns summary length of all its arguments.
**
** Function 'sequence' returns an sequence starting from a certain number
** Function 'sequence' returns an sequence starting from a certain number.
**
** Function 'myfunc_argument_name' returns name of argument.
**
** On the end is a couple of functions that converts hostnames to ip and
** vice versa.
@ -82,6 +84,7 @@
** CREATE FUNCTION lookup RETURNS STRING SONAME "udf_example.so";
** CREATE FUNCTION reverse_lookup RETURNS STRING SONAME "udf_example.so";
** CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME "udf_example.so";
** CREATE FUNCTION myfunc_argument_name RETURNS STRING SONAME "udf_example.so";
**
** After this the functions will work exactly like native MySQL functions.
** Functions should be created only once.
@ -94,6 +97,7 @@
** DROP FUNCTION lookup;
** DROP FUNCTION reverse_lookup;
** DROP FUNCTION avgcost;
** DROP FUNCTION myfunc_argument_name;
**
** The CREATE FUNCTION and DROP FUNCTION update the func@mysql table. All
** Active function will be reloaded on every restart of server
@ -975,4 +979,46 @@ avgcost( UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* error )
return data->totalprice/double(data->totalquantity);
}
extern "C" {
my_bool myfunc_argument_name_init(UDF_INIT *initid, UDF_ARGS *args,
char *message);
void myfunc_argument_name_deinit(UDF_INIT *initid);
char *myfunc_argument_name(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *length, char *null_value,
char *error);
}
my_bool myfunc_argument_name_init(UDF_INIT *initid, UDF_ARGS *args,
char *message)
{
if (args->arg_count != 1)
{
strmov(message,"myfunc_argument_name_init accepts only one argument");
return 1;
}
initid->max_length= args->attribute_lengths[0];
initid->maybe_null= 1;
initid->const_item= 1;
return 0;
}
void myfunc_argument_name_deinit(UDF_INIT *initid) {}
char *myfunc_argument_name(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *length, char *null_value,
char *error)
{
if (!args->attributes[0])
{
null_value= 0;
return 0;
}
(*length)--; // space for ending \0 (for debugging purposes)
if (*length > args->attribute_lengths[0])
*length= args->attribute_lengths[0];
memcpy(result, args->attributes[0], *length);
result[*length]= 0;
return result;
}
#endif /* HAVE_DLOPEN */