So, in theory this should be pretty straight forward to do right?  Well
I'm new to UDF's, so how mysql is passing the data to the UDF is a bit of
a mystery.  I'm hoping someone can help me understand this.

I'm selecting data from a BLOB field like this:

                        SELECT payload_time,
                        SUBSTR(BINARY(frame_data),
                        FLOOR(foffset/8)+1,
                        CEIL((flength + (foffset %8 ))/8))
                        FROM RawMajorFrames
                        WHERE raw_major_frame_id=rfid
                        INTO ptime,fdata;

You can see that I'm only taking a portion of the string, but it is still
in raw form.

Now I would like to pass it to my UDF function called toDoubleArray, to
convert each 8 byte section to a double.

I call the function like this: (you can ignore conv_param)
SELECT toDoubleArray(fdata,"%1.3E",conv_param) INTO fdata_string;

Well, I get a Lost Connection when the function is called.
Here is the UDF:

my_bool toDoubleArray_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
  if (args->arg_count != 3)
  {
                strcpy(message,"Wrong arguments to toDouble:  should be
toDoubleArray(blob)");
    return 1;
  }
        initid->max_length = strlen(args->args[0])/8 * 128;
  return 0;

}
char * toDoubleArray(UDF_INIT *initid, UDF_ARGS *args, char *result,
                                unsigned long *length,char *is_null,char *error)
{
        int curr_buf_ptr =0; /* current length of FloatString */
        char * data = args->args[0]; /* just to make it easier to reference the
string */
        char * f = args->args[1];   /* get the format string */
   char format[15];

        sprintf(format,"%s,",f); /* put a comma at the end of format for CSV
format */

        for(int i=0;i<strlen(data);i +=8){
                sprintf(result + curr_buf_ptr,format,*((double *)(data +i)));
                curr_buf_ptr = strlen(result);
        }
        result[curr_buf_ptr -1] = '\0';
        *length = strlen(result);
        return result;
}
This should return a comma delimited list of double values in a string
format (ascii representation).

Like I said, I'm new to UDF's so it is likely I'm not aware of conventions
to follow that are well known to others.

Any help would be great.

David Godsey

> David Godsey wrote:
>
>>>
>>> I know, I know, sounds like something that should be done in the
>>> presentation layer, howerver if possible, I would like to provide
>>> common
>>> data presentation to multiple presentation layers (written in different
>>> languages).
>>>
>>> So is there anyway to return an array in mysql?
>>
> Your aware your doing something stupid and want to do it anyway :-(
>
> Why not return the values from your user defined mysql function as a
> (properly quoted) ,comma seperated list. Since almost every application
> language now has a standard csv file handling library it should be easy
> to use across diverse display technologies.
>
> Urrgh
>
> Nigel
>


Accomplishing the impossible means only that the boss will add it to your
regular duties.

David Godsey


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to