-->
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.  [ 2 posts ] 
Author Message
 Post subject: BUG - comma-dot-comma-dot problem
PostPosted: Fri Jan 16, 2009 4:11 pm 
Newbie

Joined: Fri Jan 16, 2009 3:43 pm
Posts: 1
I'm using an Oracle database with NHibernate and am getting a very odd exception when I perform an HQL query. The code in question is as follows:


Code:
private static List<ParticipantHdo> GetParticipantsByName(ISession p_nHibSession, string p_name1, string p_name2) {
         List<ParticipantHdo> hdoList = new List<ParticipantHdo>();

         if (!String.IsNullOrEmpty(p_name1)) {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(" from ParticipantHdo as p where p.Name1 = '{0}' ", p_name1.Replace("\'", "\'\'"));

            if (!String.IsNullOrEmpty(p_name2)) {
               sql.AppendFormat(" and p.Name2 = '{0}' ", p_name2.Replace("\'", "\'\'"));
            }

            IList<ParticipantHdo> rawResults = p_nHibSession.CreateQuery(sql.ToString()).List<ParticipantHdo>();
            foreach (ParticipantHdo hdo in rawResults)
               hdoList.Add(hdo);
         }

         return hdoList;
      }



The problem only occurs when the "p_name1" parameter contains a string that has a comma, followed by a dot, followed by a comma, followed by another dot, with any number of characters between them. For example, some problematic strings would be:

Code:
     ",.,."
     ",        .     ,      ."
     "This, is. also a, problem."


These seems to be an NHibernate bug.
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 18, 2009 4:39 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Try to pass the string as parameter to the query:

Code:
from ParticipantHdo as p where p.Name1 = :name

p_nHibSession.CreateQuery(sql.ToString())
    .SetParameter("name", p_name1)
    .List<ParticipantHdo>();

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.