Bug #46241 Using output of select as argument for UDF is seen as NULL by the UDF
Submitted: 16 Jul 2009 19:45 Modified: 17 Aug 2009 5:28
Reporter: Patrick Galbraith Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: User-defined functions ( UDF ) Severity:S2 (Serious)
Version: OS:Linux (ubunutu 9.x, AWS AMI)
Assigned to: CPU Architecture:Any
Tags: 5.4.2-beta

[16 Jul 2009 19:45] Patrick Galbraith
Description:
Hi!

I have a problem with using the output of a select statement as an argument to a UDF I wrote.

5.4:

mysql> select * from sch;
+------+
| name |
+------+
| test | 
+------+
1 row in set (0.00 sec)

mysql> select db_bytes(name) from sch;
ERROR 1123 (HY000): Can't initialize function 'db_bytes';  ERROR: the schema name is empty!
mysql> select version();
+------------+
| version()  |
+------------+
| 5.4.2-beta | 
+------------+

5.0

mysql> select name from sch;
+------+
| name |
+------+
| test | 
+------+
1 row in set (0.00 sec)

mysql> select name, db_bytes('test') from sch;
+------+------------------+
| name | db_bytes('test') |
+------+------------------+
| test | 475459           | 
+------+------------------+
1 row in set (0.01 sec)

mysql> select version();
+------------------------+
| version()              |
+------------------------+
| 5.0.51a-3ubuntu5.4-log | 
+------------------------+

How to repeat:
you could probably write any UDF. Put this in the init function, otherwise you will get a segfault.

if (args->args[0] == NULL)
  {
    strncpy(message, " ERROR: the schema name is empty!", MYSQL_ERRMSG_SIZE);
    return 1;
  }
[16 Jul 2009 21:33] Patrick Galbraith
Ok, I spoke too soon. In haste, I checked 5.0 incorrectly. Same problem in 5.0
[17 Jul 2009 5:28] Sveta Smirnova
Thank you for the report.

Please provide example UDF showing the problem.
[17 Aug 2009 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".