Ich versuche, eine benutzerdefinierte Eigenschaftsfunktion für mysql zu schreiben, also nahm ich die str_ucwords Funktion von http://www.mysqludf.org/index.php als ein Beispiel, um mein eigenes zu erstellen.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;
}
Dies funktioniert gut, wenn ich select str_ucwords("test string");
versuchen, aber wenn ich versuche, ein Feld aus einer Datenbank wie select str_ucwords(name) from name;
auszuwählen ich nichts zurückgegeben.
Wie kann ich diese Funktion ändern, damit ich Daten aus Feldern in der Datenbank abrufen kann?
Ich habe bereits versucht, args->arg_type[0] != STRING_RESULT
von der Init-Funktion zu entfernen.