-->
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.  [ 1 post ] 
Author Message
 Post subject: Restrictions.ilike does not escape SQL specials - how can I?
PostPosted: Wed Oct 19, 2005 5:46 am 
Newbie

Joined: Thu May 05, 2005 10:36 am
Posts: 13
Location: England
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Name and version of the database you are using: MS SQL Server (2000?)

Using the code below, I have been unable to find the Alias ":@;#[;]", though all others (without the special characters are found without a problem). It appears that hibernate does not escape the parameters provided to Restrictions.iLike(x,y) because I have tried not escaping any characters too, and that doesnt work.


I have read all the other posts on the area, but after trying everything I could think of based on what I could glean from those information sources, I am still without a solution.

Am I missing something fundamental in the API? If so, please point me towards it.

Thankyou for your help.

This is a method which I call to escape the SQL 'special' characters
Code:
CoreEJBLib.escapeSQLSpecials(strReturn) {
  // now replace all "'" with "''"
  strReturn = strInput.replaceAll("'", "''");
  // now replace all "*" with "%" (note it is double escaped cos its a   RegExp)
  strReturn = strReturn.replaceAll("\\*", "%");
  // now replace all "?" with "_" (note it is double escaped cos its a RegExp)
  strReturn = strReturn.replaceAll("\\?", "_");
  strReturn = strReturn.replaceAll("\\[", "\\\\[");
  strReturn = strReturn.replaceAll("\\]", "\\\\]");
  return strReturn;
}

This is the actual query code that I use
Code:
Criteria c = entityManager.getSession().createCriteria(Alias.class);
c.add(Restrictions.ilike("id.desc",
                                  CoreEJBLib.escapeSQLSpecials(
                                     codeToSrchFor),
                                 MatchMode.START));
List<Alias> aliases = c.list();


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

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.