/* lib_mysqludf_udf - a library for reporting internals from the udf interface. This is intended primarily for debugging purposes and discovery of undocumented behaviour Copyright (C) 2007 Roland Bouman web: http://www.xcdsql.org/MySQL/UDF/ email: mysqludfs@gmail.com This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32) #define DLLEXP __declspec(dllexport) #else #define DLLEXP #endif #ifdef STANDARD #include #include #include #ifdef __WIN__ typedef unsigned __int64 ulonglong; typedef __int64 longlong; #else typedef unsigned long long ulonglong; typedef long long longlong; #endif /*__WIN__*/ #else #include #include #endif #include #include #include #include #include #ifdef HAVE_DLOPEN #ifdef __cplusplus extern "C" { #endif #define LIBVERSION "lib_mysqludf_sys version 0.0.2" DLLEXP my_bool lib_mysqludf_udf_info_init( UDF_INIT *initid , UDF_ARGS *args , char *message ); DLLEXP void lib_mysqludf_udf_info_deinit( UDF_INIT *initid ); DLLEXP char* lib_mysqludf_udf_info( UDF_INIT *initid , UDF_ARGS *args , char* result , unsigned long* length , char *is_null , char *error ); /* * udf_arg_count * * return the value of UDF_ARGS->arg_count * */ DLLEXP my_bool udf_arg_count_init( UDF_INIT *initid , UDF_ARGS *args , char *message ); DLLEXP void udf_arg_count_deinit( UDF_INIT *initid ); DLLEXP long long udf_arg_count( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ); /* * udf_arg_type * * return the value of UDF_ARGS->arg_type[0] * */ DLLEXP my_bool udf_arg_type_init( UDF_INIT *initid , UDF_ARGS *args , char *message ); DLLEXP void udf_arg_type_deinit( UDF_INIT *initid ); DLLEXP long long udf_arg_type( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ); /* * udf_arg_value * * return the value of UDF_ARGS->args[0] * */ DLLEXP my_bool udf_arg_value_init( UDF_INIT *initid , UDF_ARGS *args , char *message ); DLLEXP void udf_arg_value_deinit( UDF_INIT *initid ); DLLEXP char* udf_arg_value( UDF_INIT *initid , UDF_ARGS *args , char* result , unsigned long *length , char *is_null , char *error ); /* * udf_arg_length * * return the value of UDF_ARGS->lengths[0] * */ DLLEXP my_bool udf_arg_value_length_init( UDF_INIT *initid , UDF_ARGS *args , char *message ); DLLEXP void udf_arg_value_length_deinit( UDF_INIT *initid ); DLLEXP long long udf_arg_value_length( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ); /* * udf_arg_maybe_null * * return the value of UDF_ARGS->maybe_null[0] * */ DLLEXP my_bool udf_arg_maybe_null_init( UDF_INIT *initid , UDF_ARGS *args , char *message ); DLLEXP void udf_arg_maybe_null_deinit( UDF_INIT *initid ); DLLEXP long long udf_arg_maybe_null( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ); /* * udf_arg_attribute * * return the value of UDF_ARGS->attributes[0] * */ DLLEXP my_bool udf_arg_attribute_init( UDF_INIT *initid , UDF_ARGS *args , char *message ); DLLEXP void udf_arg_attribute_deinit( UDF_INIT *initid ); DLLEXP char* udf_arg_attribute( UDF_INIT *initid , UDF_ARGS *args , char* result , unsigned long *length , char *is_null , char *error ); /* * udf_arg_attribute_length * * return the value of UDF_ARGS->attribute_lengths[0] * */ DLLEXP my_bool udf_arg_attribute_length_init( UDF_INIT *initid , UDF_ARGS *args , char *message ); DLLEXP void udf_arg_attribute_length_deinit( UDF_INIT *initid ); DLLEXP long long udf_arg_attribute_length( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ); /* * udf_init_error * * raise an error in the init function * */ DLLEXP my_bool udf_init_error_init( UDF_INIT *initid , UDF_ARGS *args , char *message ); DLLEXP void udf_init_error_deinit( UDF_INIT *initid ); DLLEXP long long udf_init_error( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ); #ifdef __cplusplus } #endif /** * lib_mysqludf_udf_info */ my_bool lib_mysqludf_udf_info_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ my_bool status; if(args->arg_count!=0){ strcpy( message , "No arguments allowed (udf: lib_mysqludf_udf_info)" ); status = 1; } else { status = 0; } return status; } void lib_mysqludf_udf_info_deinit( UDF_INIT *initid ){ } char* lib_mysqludf_udf_info( UDF_INIT *initid , UDF_ARGS *args , char* result , unsigned long* length , char *is_null , char *error ){ strcpy(result,LIBVERSION); *length = strlen(LIBVERSION); return result; } /* * udf_arg_count * * return the value of UDF_ARGS->arg_count * */ my_bool udf_arg_count_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ return 0; } void udf_arg_count_deinit( UDF_INIT *initid ){ } long long udf_arg_count( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ){ return args->arg_count; } /* * udf_arg_type * * return the value of UDF_ARGS->arg_type[0] * */ my_bool udf_arg_type_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ my_bool status; if(args->arg_count!=1){ strcpy( message , "Expect exactly 1 argument (udf: udf_arg_type)" ); status = 1; } else { status = 0; } return status; } void udf_arg_type_deinit( UDF_INIT *initid ){ } long long udf_arg_type( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ){ return args->arg_type[0]; } /* * udf_arg_value * * return the value of UDF_ARGS->args[0] * */ my_bool udf_arg_value_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ my_bool status; if(args->arg_count!=1){ strcpy( message , "Expect exactly 1 argument (udf: udf_arg_value)" ); status = 1; } else { args->arg_type[0] = STRING_RESULT; status = 0; } return status; } void udf_arg_value_deinit( UDF_INIT *initid ){ } char* udf_arg_value( UDF_INIT *initid , UDF_ARGS *args , char* result , unsigned long *length , char *is_null , char *error ){ *length = args->lengths[0]; return args->args[0]; } /* * udf_arg_length * * return the value of UDF_ARGS->lengths[0] * */ my_bool udf_arg_value_length_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ my_bool status; if(args->arg_count!=1){ strcpy( message , "Expect exactly 1 argument (udf: udf_arg_length)" ); status = 1; } else { status = 0; } return status; } void udf_arg_value_length_deinit( UDF_INIT *initid ){ } long long udf_arg_value_length( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ){ return args->lengths[0]; } /* * udf_arg_maybe_null * * return the value of UDF_ARGS->maybe_null[0] * */ my_bool udf_arg_maybe_null_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ my_bool status; if(args->arg_count!=1){ strcpy( message , "Expect exactly 1 argument (udf: udf_arg_maybe_null)" ); status = 1; } else { status = 0; } return status; } void udf_arg_maybe_null_deinit( UDF_INIT *initid ){ } long long udf_arg_maybe_null( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ){ return args->maybe_null[0]; } /* * udf_arg_attribute * * return the value of UDF_ARGS->attributes[0] * */ my_bool udf_arg_attribute_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ my_bool status; if(args->arg_count!=1){ strcpy( message , "Expect exactly 1 argument (udf: udf_arg_attribute)" ); status = 1; } else { status = 0; } return status; } void udf_arg_attribute_deinit( UDF_INIT *initid ){ } char* udf_arg_attribute( UDF_INIT *initid , UDF_ARGS *args , char* result , unsigned long *length , char *is_null , char *error ){ *length = args->attribute_lengths[0]; return args->attributes[0]; } /* * udf_arg_attribute_length * * return the value of UDF_ARGS->attribute_lengths[0] * */ my_bool udf_arg_attribute_length_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ my_bool status; if(args->arg_count!=1){ strcpy( message , "Expect exactly 1 argument (udf: udf_arg_attribute_length)" ); status = 1; } else { status = 0; } return status; } void udf_arg_attribute_length_deinit( UDF_INIT *initid ){ } long long udf_arg_attribute_length( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ){ return args->attribute_lengths[0]; } /* * udf_init_error * * raise an error in the init function * */ my_bool udf_init_error_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ char *msg; int unsigned msg_length; if(args->arg_count==0){ msg = ""; msg_length = 0; } else { args->arg_type[0] = STRING_RESULT; msg = args->args[0]; msg_length = args->lengths[0]>255?255:args->lengths[0]; } memcpy( message , msg , msg_length ); message[msg_length] = '\0'; return 1; } void udf_init_error_deinit( UDF_INIT *initid ){ } long long udf_init_error( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ){ return 0; } #endif /* HAVE_DLOPEN */