diff options
author | unknown <monty@donna.mysql.com> | 2001-02-03 18:00:29 +0200 |
---|---|---|
committer | unknown <monty@donna.mysql.com> | 2001-02-03 18:00:29 +0200 |
commit | 37aa09b19bba4f411b43be78cbc46b6a5f0aee95 (patch) | |
tree | b01406ccbcbde61bdde5e643977c7f0fa76dc098 /sql/udf_example.cc | |
parent | 605c330184df49dc7e1187e88a038156d1799ce6 (diff) | |
download | mariadb-git-37aa09b19bba4f411b43be78cbc46b6a5f0aee95.tar.gz |
Workaround for bug in thread library in Unixware 7
Fixed bug in GROUP BY on ELT()
Added SEQUENCE() to UDF examples
BUILD/FINISH.sh:
Avoid error message if tmp exists
Docs/manual.texi:
Cleaned up bug reporting section
mysys/my_init.c:
Workaround for bug in thread library in Unixware 7
readline/input.c:
Portability fix
scripts/mysql_install_db.sh:
Made host, user and db field binary
sql/item_func.h:
Fixed bug in GROUP BY on ELT()
sql/item_strfunc.cc:
Fixed bug in GROUP BY on ELT()
sql/share/Makefile.am:
Don't automaticly checkout SCCS files
sql/sql_select.cc:
Cleanups
sql/udf_example.cc:
Added SEQUENCE() to UDF examples.
Diffstat (limited to 'sql/udf_example.cc')
-rw-r--r-- | sql/udf_example.cc | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/sql/udf_example.cc b/sql/udf_example.cc index 9d94006b281..bf3aa3d0074 100644 --- a/sql/udf_example.cc +++ b/sql/udf_example.cc @@ -56,11 +56,13 @@ ** ** Function 'myfunc_int' returns summary length of all its arguments. ** +** Function 'sequence' returns an sequence starting from a certain number +** ** On the end is a couple of functions that converts hostnames to ip and ** vice versa. ** ** A dynamicly loadable file should be compiled sharable -** (something like: gcc -shared -o udf_example.so myfunc.cc). +** (something like: gcc -shared -o my_func.so myfunc.cc). ** You can easily get all switches right by doing: ** cd sql ; make udf_example.o ** Take the compile line that make writes, remove the '-c' near the end of @@ -74,6 +76,7 @@ ** CREATE FUNCTION metaphon RETURNS STRING SONAME "udf_example.so"; ** CREATE FUNCTION myfunc_double RETURNS REAL SONAME "udf_example.so"; ** CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "udf_example.so"; +** CREATE FUNCTION sequence RETURNS INTEGER SONAME "udf_example.so"; ** 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"; @@ -121,6 +124,10 @@ double myfunc_double(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); longlong myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); +my_bool sequence_init(UDF_INIT *initid, UDF_ARGS *args, char *message); + void sequence_deinit(UDF_INIT *initid); +long long sequence(UDF_INIT *initid, UDF_ARGS *args, char *is_null, + char *error); } @@ -535,6 +542,8 @@ double myfunc_double(UDF_INIT *initid, UDF_ARGS *args, char *is_null, ** This function should return the result as a long long ***************************************************************************/ +/* This function returns the sum of all arguments */ + long long myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) { @@ -559,6 +568,50 @@ long long myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, } +/* + Simple example of how to get a sequences starting from the first argument + or 1 if no arguments have been given +*/ + +my_bool sequence_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + if (args->arg_count > 1) + { + strmov(message,"This function takes none or 1 argument"); + return 1; + } + if (args->arg_count) + args->arg_type[0]= INT_RESULT; // Force argument to int + + if (!(initid->ptr=(char*) malloc(sizeof(longlong)))) + { + strmov(message,"Couldn't allocate memory"); + return 1; + } + bzero(initid->ptr,sizeof(longlong)); + // Fool MySQL to think that this function is a constant + // This will ensure that MySQL only evalutes the function + // when the rows are sent to the client and not before any ORDER BY + // clauses + initid->const_item=1; + return 0; +} + +void sequence_deinit(UDF_INIT *initid) +{ + if (initid->ptr) + free(initid->ptr); +} + +long long sequence(UDF_INIT *initid, UDF_ARGS *args, char *is_null, + char *error) +{ + ulonglong val=0; + if (args->arg_count) + val= *((long long*) args->args[0]); + return ++ *((longlong*) initid->ptr) + val; +} + /**************************************************************************** ** Some functions that handles IP and hostname conversions ** The orignal function was from Zeev Suraski. |