我正在嘗試爲mysql編寫一個自定義的propercase用戶定義函數,所以我以http://www.mysqludf.org/index.php的str_ucwords函數爲例構建了自己的函數。propercase mysql udf
my_bool str_ucwords_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
/* make sure user has provided exactly one string argument */
if (args->arg_count != 1 || args->arg_type[0] != STRING_RESULT || args->args[0] == NULL)
{
strcpy(message,"str_ucwords requires one string argument");
return 1;
}
/* str_ucwords() will not be returning null */
initid->maybe_null=0;
return 0;
}
char *str_ucwords(UDF_INIT *initid, UDF_ARGS *args,
char *result, unsigned long *res_length,
char *null_value, char *error)
{
int i;
int new_word = 0;
// copy the argument string into result
strncpy(result, args->args[0], args->lengths[0]);
*res_length = args->lengths[0];
// capitalize the first character of each word in the string
for (i = 0; i < *res_length; i++)
{
if (my_isalpha(&my_charset_latin1, result[i]))
{
if (!new_word)
{
new_word = 1;
result[i] = my_toupper(&my_charset_latin1, result[i]);
}
}
else
{
new_word = 0;
}
}
return result;
}
,如果我嘗試select str_ucwords("test string");
但如果我嘗試從數據庫中像select str_ucwords(name) from name;
選擇一個領域我什麼也沒有返回這工作得很好。
我該如何改變這個函數,使它能夠從數據庫的字段中提取數據?
我已經嘗試從init函數中刪除args->arg_type[0] != STRING_RESULT
。