-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: changing wildcard characters
PostPosted: Sun Mar 16, 2008 11:18 am 
Beginner
Beginner

Joined: Sat Apr 07, 2007 4:42 pm
Posts: 24
Hi,

is it possible to change the wildcard characters or are % and _ hard coded?

I would like to use * and ? but I do not want to change all the queries.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 11:30 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I assume you are talking HQL or JPA QL here in which case this is probably the wrong forum. Hibernate Search is really about the combination of Hibernate and Lucene.

Nevertheless, Hibernate's LIKE operator allows wildcard searches via the symbols % and _. This is in accordance with the SQL standard. As far as I know there is no easy way to change to change the wildcard symbols. Also remember, even if you could write your queries with * and ?, once the SQL query will be executed the symbols would have to be replaced again with % respectively _ since this is what the database will expect.

What is your actual usecase? Why do you want to change the query syntax?

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 11:49 am 
Beginner
Beginner

Joined: Sat Apr 07, 2007 4:42 pm
Posts: 24
Well the reason is simple:

Users normally know * and ?, but not % and _.

the EQL is:

select foo from bar where test like ?1

The value for parameter 1 is given by the user in an input mask.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 1:04 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Maybe you should parse/validate the user specified query string? For the user you can expose "*" and "?" which you then map to the appropriate queries. This would also give an additional level security for malicious SQL injection.

Alternatively you could consider using Hibernate Search. Hibernate Search is build on Lucene which uses "*" and "?" (and many more) meta characters and has an extensive query parser. Of course it really depends on your usecase.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 5:27 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The spec allows you to define the escape character through ESCAPE but that is pretty much all you can do. Otherwise, you need to parse the user provided character string.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.