-->
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: Flexible HQL execution method
PostPosted: Tue Nov 29, 2005 8:03 am 
Hi all,

I'm trying to code a method that could execute any (or almost) HQL query, but I'm not really advanced in C#. :(

that would give something like that:

Code:
      public void Delete(string query, object[] parameters, object[] values)
      {
         ITransaction tx = null;
         try
         {

            //query = "from table name where columnName1 = :columnValue1 , columnName2 = :columnValue2 , ..."


            //here loop through the array and produce a string formated as follow:
            //stringparameternames = "parameter1 " + "," + "parameter2 " + "," ...

            //same here for their values:
            //stringparametervalues = "value1 " + "," + "value2 " + "," ...


            tx = _session.BeginTransaction();
            _session.Delete(query, stringparameternames, stringparametervalues);
            tx.Commit();
         }
         catch (Exception ex)
         {
            if (tx!=null) tx.Rollback();
            throw;
         }         
      }


Would that work and would that be "safe"?

Other then that, is it possible to safely make that even more flexible?

Thx a lot for your attention, advices and help.

Pierre


Top
  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 8:12 am 
If somebody could tell me what does _session.Delete (or _session.*) returns I could use that info as well :)


Top
  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 10:44 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
You are basically wrapping ISession.Delete(), so I don't see anything wrong here (Don't concatenate the parameters!!!)

You can find all the information about the API in NHibernate API Reference (or better: in the source code :wink: )

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 9:40 am 
thx KPixel.

I'm still wondering how to write a HQL query with several parameters. For example in the following example how do I add the firstname?

Code:
_session.Delete("from TblEmployee where employee_lName = :Id", lname, NHibernate.NHibernateUtil.String);


Top
  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 9:26 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Here, you should write:
Code:
_session.Delete("from TblEmployee where employee_lName = ?", lname, NHibernate.NHibernateUtil.String);

As you aren't using named parameters.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


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.