Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 317603

Summary: CREATE FUNCTION StoredFunction_In (...) RETURN ... doesn't work with MySQL 5.1.39
Product: z_Archived Reporter: Yiping Zhao <yiping.zhao>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: andrei.ilitchev
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
The patch. none

Description Yiping Zhao CLA 2010-06-22 11:18:07 EDT
We build stored function as following in testSetup() of org.eclipse.persistence.testing.tests.jpa.jpql.JUnitJPQLComplexTestSuite, it worked with Oracle database, but failed with MySQL 5.1.10. The stored function generated by EclipseLink is:

CREATE FUNCTION StoredFunction_In (P_IN BIGINT) RETURN BIGINT
BEGIN 
RETURN P_IN * 1000; 
END

The reason it failed on MySQL, because the return syntax for create function in MySQL is RETURNS, not RETURN. So the correct statement on MySQL will be:

CREATE FUNCTION StoredFunction_In (P_IN BIGINT) RETURNS BIGINT
BEGIN 
RETURN P_IN * 1000; 
END

The error message for the failure on MySQL is:

all: CREATE FUNCTION StoredFunction_In (
	P_IN BIGINT)
	 RETURN  BIGINT

BEGIN 
RETURN P_IN * 1000; 
END
Query: DataModifyQuery(sql=&quot;CREATE FUNCTION StoredFunction_In (
	P_IN BIGINT)
	 RETURN  BIGINT

BEGIN 
RETURN P_IN * 1000; 
END&quot;)" type="org.eclipse.persistence.exceptions.DatabaseException">Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.qualifier): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &apos;RETURN  BIGINT

BEGIN 
RETURN P_IN * 1000; 
END&apos; at line 3
Error Code: 1064
Call: CREATE FUNCTION StoredFunction_In (
	P_IN BIGINT)
	 RETURN  BIGINT

BEGIN 
RETURN P_IN * 1000; 
END
Comment 1 Yiping Zhao CLA 2010-06-22 11:21:38 EDT
The jdbc driver version is: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.10
Comment 2 Andrei Ilitchev CLA 2010-06-23 15:37:05 EDT
Created attachment 172546 [details]
The patch.

Return key word in stored function definition is now printed by the platform - RETURN by default, RETURNS on MySQLPlatform.
Comment 3 Andrei Ilitchev CLA 2010-06-23 16:00:39 EDT
Checked into trunk, 2.1.1 pending.
Comment 4 Andrei Ilitchev CLA 2010-06-24 14:39:15 EDT
Checked into 2.1.1
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:14:43 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:23:25 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink