[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2697) Can't use := for variable assignment within a SQL-Statement

Eduardo Simioni (JIRA) noreply at atlassian.com
Fri Nov 14 09:40:16 EST 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=31713#action_31713 ] 

Eduardo Simioni commented on HHH-2697:
--------------------------------------

Variables in MySQL are the only way to write Analytic queries. Not being able to execute these queries with Hibernate is sad.
But worse is realizing that this bug is open for almost a year an a half and nobody from Hibernate team seem to care about.

> Can't use := for variable assignment within a SQL-Statement
> -----------------------------------------------------------
>
>                 Key: HHH-2697
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2697
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.2.4.sp1
>         Environment: MySQL Datasource, Hibernate 3.2.4.sp1
>            Reporter: Benjamin Gniza
>            Priority: Minor
>
> i found a kind of bug in org.hibernate.engine.query.ParameterParser.java:
> I have an exotic mysql-statement where I want to use mysql variables.
> VERY SIMPLE example:
> SET @pos=0;
> SELECT @pos:=@pos+1 FROM TABLE;
> Steps to reproduce:
> Session s = sessionFactory.openSession();
> s.createSQLQuery("SET @pos=0").executeUpdate();
> SQLQuery qry = s.createSQLQuery("select @pos:=@pos from SomeTable");
> List lst = qry.list();
> Exception:
> org.hibernate.QueryException: Space is not allowed after parameter prefix ':' 'SELECT @pos:=@pos+1 FROM TABLE'
> 	at org.hibernate.engine.query.ParameterParser.parse(ParameterParser.java:68)
> 	...
> 	...
> Suggested fix:
> ParameterParser Lines 62 to 73:
> 				if (c == ':' && (indx + 1 >= stringLength || sqlString.charAt(indx + 1) != '=')) {
> 					// named parameter
> 					int right = StringHelper.firstIndexOfChar( sqlString, ParserHelper.HQL_SEPARATORS, indx + 1 );
> 					int chopLocation = right < 0 ? sqlString.length() : right;
> 					String param = sqlString.substring( indx + 1, chopLocation );
> 					if ( StringHelper.isEmpty( param ) ) {
> 						throw new QueryException("Space is not allowed after parameter prefix ':' '"
> 								+ sqlString + "'");
> 					}
> 					recognizer.namedParameter( param, indx );
> 					indx = chopLocation - 1;
> 				}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list