Bug #61513 Trying to create a function, testing select statement that uses current_user()
Submitted: 14 Jun 2011 15:43 Modified: 16 Jul 2011 12:30
Reporter: Michael Krause Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:5.0.77 OS:Linux
Assigned to: CPU Architecture:Any

[14 Jun 2011 15:43] Michael Krause
Description:
This is my first MySQL function... trying to figure it out.

CREATE FUNCTION HSCRoleFromID () RETURNS VARCHAR(20)
READS SQL DATA
BEGIN
DECLARE r VARCHAR(45)
SELECT UserRole INTO r FROM membership.HSCUsers WHERE membership.UserName = CURRENT_USER();
RETURN r;
END

How to repeat:
execute the following statement:

SELECT UserRole FROM membership.HSCUsers WHERE membership.UserName = CURRENT_USER();
[14 Jun 2011 15:53] Valeriy Kravchuk
What is the problem/error message that you get as a result? How it is related to MySQL Workbench?
[16 Jun 2011 11:35] Michael Krause
I found an error in my statement... no FROM clause but I'm still having a problem.   I'm getting error code 1064 for the statement below:

CREATE FUNCTION HSCGETRoleFromID () RETURNS varchar(25)
READS SQL DATA
BEGIN
DECLARE vrole varchar(25);
SELECT UserRole INTO vRole FROM membership.HSCUsers WHERE CONCAT(UserName,'@%') = CURRENT_USER();
RETURN vrole;
END
[16 Jun 2011 12:30] Valeriy Kravchuk
I see no problems to create this function in current server version:

macbook-pro:5.1 openxs$ bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.59-debug Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> delimiter //
mysql> CREATE FUNCTION HSCGETRoleFromID () RETURNS varchar(25)
    -> READS SQL DATA
    -> BEGIN
    -> DECLARE vrole varchar(25);
    -> SELECT UserRole INTO vRole FROM membership.HSCUsers WHERE CONCAT(UserName,'@%') =
    -> CURRENT_USER();
    -> RETURN vrole;
    -> END//
Query OK, 0 rows affected (0.15 sec)

So, please, check with some recent version, 5.0.92 at least.
[16 Jul 2011 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".