List:Internals« Previous MessageNext Message »
From:Michael Widenius Date:January 16 2001 2:24pm
Subject:Information on UDF return type for long strings
View as plain text  
Hi!

>>>>> "Sebastien" == Sebastien Lemieux <lemieuxs@stripped>
> writes:

Sebastien> Hi,
Sebastien> I need to write a UDF that returns a long string (typically around
Sebastien> 5000 char).  The current mechanism (I'm using dynamically linked
Sebastien> object on linux RH 7.0) seems to be limited to 256 characters, even
Sebastien> tho initid->max_length is assigned 16777215 which is the
args-> lengths[0] returned in the _init for my source string.  Here is
Sebastien> my current code:

Sebastien> {
Sebastien> int count = 0;
Sebastien> const char *seq = args->args[0];
Sebastien> unsigned long len = args->lengths[0];
Sebastien> for (int i = 0; i < len; ++i) {
Sebastien> if (seq[i] == 'A') count++;
Sebastien> // result[i] = seq[i];
Sebastien> }
Sebastien> sprintf (result, "%u - %d - %u", len, count, initid->max_length);
Sebastien> *length = strlen (result);

Sebastien> return result;
Sebastien> }

Sebastien> If the commented line is executed, the code crashes the server for
Sebastien> strings longer than 256.

Sebastien> How can I return strings longer than 256?
Sebastien> Why is args->lengths[0] returning such a huge number when the longest
Sebastien> string passed is around 5000 characters?

Sebastien> Thanks,

Sebastien> P.S: My subscription to this list seems like it is not processed yet.
Sebastien> Would you CC any answer/comment to my 'from' address...


How to do allocate longer strings is described in the manual section:
'UDF Calling Sequences';  Check the information about the 'ptr' slot
in UDF_INIT.

I have now added the following information to the manual to make this
a bit clearer:

For functions that returns a string you can in most cases store the
result in the buffer 'result' supplied to you.  This buffer is 256
character big.  If you need to return a longer string, you need to
allocate this with `malloc()' in your `xxx_init()' function or your
`xxx()' function and free it in your `xxx_deinit()' function.  You can
store the allocated memory in the `ptr' slot in the `UDF_INIT'
structure for reuse by future `xxx()' calls.

Regards,
Monty
Thread
Information on UDF return type for long stringsSebastien Lemieux15 Jan
  • Re: Information on UDF return type for long stringsSinisa Milivojevic16 Jan
  • Information on UDF return type for long stringsMichael Widenius16 Jan
  • Re: Information on UDF return type for long stringsSebastien Lemieux16 Jan