cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tony Dahbura <dahb...@aopslab.com>
Subject QUestion with select expressions
Date Tue, 03 May 2011 11:42:44 GMT
I am trying to execute a where clause that includes calling a database function, in this case
SHA2 for mysql. 

My code looks like the following: 
HashMap<String,String> parameters = new HashMap<String,String>(1); 
parameters.put("userid", uid); 
parameters.put("password", pwd); 

Expression expression = Expression.fromString("userid = $userid and password=SHA2('$password',256)");

SelectQuery query = new SelectQuery(Adminuser.class,expression.expWithParameters(parameters));


List values = context.performQuery(query); 

Upon execution I immediately get an error that says: 
Exception in thread "main" org.apache.cayenne.exp.ExpressionException: [v.3.0.1 Aug 25 2010
19:42:04] Encountered " "(" "( "" at line 1, column 35. 
Was expecting one of: 
<EOF> 
"or" ... 
"and" ... 
"+" ... 
"-" ... 
"*" ... 
"/" ... 

at org.apache.cayenne.exp.Expression.fromString(Expression.java:139) 
at trycayenne.validateAdminUserAndPassword(trycayenne.java:121) 
at trycayenne.main(trycayenne.java:24) 
Caused by: org.apache.cayenne.exp.parser.ParseException: Encountered " "(" "( "" at line 1,
column 35. 
Was expecting one of: 
<EOF> 
"or" ... 
"and" ... 
"+" ... 
"-" ... 
"*" ... 
"/" ... 

at org.apache.cayenne.exp.parser.ExpressionParser.generateParseException(ExpressionParser.java:1487)


Is Cayenne not able to pass database function calls in this kind of query? I got it to work
using the SQLTemplate rawSelect and typing the whole select expression into the system, but
was hoping I could use the Expression syntax. 

Should I pass the function name in a different manner? 

Thanks, 
Tony 






Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message