diff options
Diffstat (limited to 'sql/udf_example.cc')
-rw-r--r-- | sql/udf_example.cc | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/sql/udf_example.cc b/sql/udf_example.cc index a91db5ee1cc..176ddeb10a3 100644 --- a/sql/udf_example.cc +++ b/sql/udf_example.cc @@ -1,15 +1,15 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - +/* Copyright (C) 2002 MySQL AB + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -61,7 +61,7 @@ ** On the end is a couple of functions that converts hostnames to ip and ** vice versa. ** -** A dynamicly loadable file should be compiled sharable +** A dynamicly loadable file should be compiled shared. ** (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 @@ -69,6 +69,8 @@ ** the line and add -shared -o udf_example.so to the end of the compile line. ** The resulting library (udf_example.so) should be copied to some dir ** searched by ld. (/usr/lib ?) +** If you are using gcc, then you should be able to create the udf_example.so +** by simply doing 'make udf_example.so'. ** ** After the library is made one must notify mysqld about the new ** functions with the commands: @@ -109,8 +111,15 @@ #ifdef STANDARD #include <stdio.h> #include <string.h> +#ifdef __WIN__ +typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */ +typedef __int64 longlong; #else -#include <global.h> +typedef unsigned long long ulonglong; +typedef long long longlong; +#endif /*__WIN__*/ +#else +#include <my_global.h> #include <my_sys.h> #endif #include <mysql.h> @@ -133,7 +142,7 @@ 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, +longlong sequence(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); my_bool avgcost_init( UDF_INIT* initid, UDF_ARGS* args, char* message ); void avgcost_deinit( UDF_INIT* initid ); @@ -271,7 +280,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, * characters and converting to uppercase. *-------------------------------------------------------*/ - for ( n = ntrans + 1, n_end = ntrans + sizeof(ntrans)-2; + for (n = ntrans + 1, n_end = ntrans + sizeof(ntrans)-2; word != w_end && n < n_end; word++ ) if ( isalpha ( *word )) *n++ = toupper ( *word ); @@ -324,7 +333,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, KSflag = 0; /* state flag for KS translation */ - for ( metaph_end = result + MAXMETAPH, n_start = n; + for (metaph_end = result + MAXMETAPH, n_start = n; n <= n_end && result < metaph_end; n++ ) { @@ -402,7 +411,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, n[2] != 'G' ) ? (char)'J' : (char)'K'; else - if( n[1] == 'H' && + if ( n[1] == 'H' && !NOGHTOF( *( n - 3 )) && *( n - 4 ) != 'H') *result++ = 'F'; @@ -440,7 +449,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, case 'T': /* TIO, TIA = X ("sh" sound) */ /* TH = 0, ("th" sound ) */ - if( *( n + 1 ) == 'I' && ( n[2] == 'O' + if ( *( n + 1 ) == 'I' && ( n[2] == 'O' || n[2] == 'A') ) *result++ = 'X'; else @@ -556,10 +565,10 @@ double myfunc_double(UDF_INIT *initid, UDF_ARGS *args, char *is_null, /* This function returns the sum of all arguments */ -long long myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, +longlong myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) { - long long val = 0; + longlong val = 0; for (uint i = 0; i < args->arg_count; i++) { if (args->args[i] == NULL) @@ -569,10 +578,10 @@ long long myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, val += args->lengths[i]; break; case INT_RESULT: // Add numbers - val += *((long long*) args->args[i]); + val += *((longlong*) args->args[i]); break; - case REAL_RESULT: // Add numers as long long - val += (long long) *((double*) args->args[i]); + case REAL_RESULT: // Add numers as longlong + val += (longlong) *((double*) args->args[i]); break; } } @@ -615,12 +624,12 @@ void sequence_deinit(UDF_INIT *initid) free(initid->ptr); } -long long sequence(UDF_INIT *initid, UDF_ARGS *args, char *is_null, +longlong 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]); + val= *((longlong*) args->args[0]); return ++ *((longlong*) initid->ptr) + val; } @@ -741,10 +750,10 @@ char *reverse_lookup(UDF_INIT *initid, UDF_ARGS *args, char *result, return 0; } sprintf(result,"%d.%d.%d.%d", - (int) *((long long*) args->args[0]), - (int) *((long long*) args->args[1]), - (int) *((long long*) args->args[2]), - (int) *((long long*) args->args[3])); + (int) *((longlong*) args->args[0]), + (int) *((longlong*) args->args[1]), + (int) *((longlong*) args->args[2]), + (int) *((longlong*) args->args[3])); } else { // string argument @@ -793,9 +802,9 @@ char *reverse_lookup(UDF_INIT *initid, UDF_ARGS *args, char *result, struct avgcost_data { - unsigned long long count; - long long totalquantity; - double totalprice; + ulonglong count; + longlong totalquantity; + double totalprice; }; @@ -869,8 +878,8 @@ avgcost_add( UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* message ) if (args->args[0] && args->args[1]) { struct avgcost_data* data = (struct avgcost_data*)initid->ptr; - long long quantity = *((long long*)args->args[0]); - long long newquantity = data->totalquantity + quantity; + longlong quantity = *((longlong*)args->args[0]); + longlong newquantity = data->totalquantity + quantity; double price = *((double*)args->args[1]); data->count++; |