LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-28-2010, 04:25 PM   #1
4play
LQ Newbie
 
Registered: Oct 2003
Location: london
Distribution: Centos
Posts: 27

Rep: Reputation: 15
propercase mysql udf


I am trying to write a custom propercase user defined function for mysql so i took the str_ucwords function from http://www.mysqludf.org/index.php as an example to build my own.

Code:
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;
}
This works fine if I try select str_ucwords("test string"); but if I try to select a fields from a database like select str_ucwords(name) from name; I get nothing returned.

How do I change this function so it allows me to pull data from fields on the database?

I have already tried removing args->arg_type[0] != STRING_RESULT from the init function.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't mount UDF Disks in CentOS - UDF-fs: No fileset found spoovy Linux - Desktop 4 05-29-2010 12:06 PM
Getting MySQL UDF to work on FC3 AMD64 jasonmccaul Linux - General 1 01-18-2005 04:31 AM
DVD ....udf?? munkie_poo Mandriva 10 07-28-2004 04:06 AM
Udf Cd Rw Linux_Native Linux - General 4 01-03-2002 06:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration