summaryrefslogtreecommitdiff
path: root/sql/udf_example.cc
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2003-09-13 17:47:59 +0300
committerunknown <bell@sanja.is.com.ua>2003-09-13 17:47:59 +0300
commit07e372cd6b3a89d301fc44b5359fac01e285aa76 (patch)
treea3c9c07d2cdb16d8472b0fd27ea2edbe9f55cfe3 /sql/udf_example.cc
parent55e776d14565ea6ee9841612069c24f6b8a3023c (diff)
downloadmariadb-git-07e372cd6b3a89d301fc44b5359fac01e285aa76.tar.gz
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)
Diffstat (limited to 'sql/udf_example.cc')
-rw-r--r--sql/udf_example.cc48
1 files changed, 47 insertions, 1 deletions
diff --git a/sql/udf_example.cc b/sql/udf_example.cc
index 7f4417bf8fe..54901003c7a 100644
--- a/sql/udf_example.cc
+++ b/sql/udf_example.cc
@@ -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 */