-->
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.  [ 4 posts ] 
Author Message
 Post subject: Get HQL parameter info from parser?
PostPosted: Mon Apr 17, 2006 6:10 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
I'm building my own "HQL Query Analyzer" and an HqlObjectDataSource class and corresponding designer for use in Visual Studio. So, given an arbitrary HQL query string, I would like to determine the names and types of the query parameters. E.g. if my query string is

Code:
SELECT ...
FROM SomeEntity e
WHERE e.Property1 = :foo
AND e.Property2 = :bar


I would like to call some NHibernate method that returns an instance of NHibernate.Engine.QueryParameters that defines "foo" and "bar". In the returned QueryParameters.NamedParameters, the Value in each NHibernate.Engine.TypedValue would be a uninitialized (or otherwise meaningless), but that's fine, all I care about is getting the Name and Type properties for each parameter.

Internally, NHibernate needs to determine this parameter information when it executes queries. The question is, does NHibernate properly break out this parsing task to an API method I can call? And if so, what is that call? I'm looking in the NHibernate.Hql namespace, and see a QueryTranslator object which takes a query string. I also see various Parser classes in this namespace. However, nothing jumps out at me as the method or property to call to get this query parameter information for a given query string ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 12:18 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You could try getting at the SqlString object that is generated by the QueryTranslator. An SqlString is a list of parts, each part either of type String or Parameter, with Parameter objects having name and type.

The type of Parameters is a database type though (SqlType, not IType).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 3:32 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
No, that wouldn't do it, I need the HQL parameters, not the SQL parameters. I can hack together a parsing method to pull out the named parameters from an HQL query string, that's no big deal -- the real problem is how to determine the "required" NHibernate.Type.IType for each parameter. Doesn't NHibernate do that somewhere when it executes HQL queries with named parameters -- i.e. how does it determine if a parameter value can or cannot be assigned?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 4:20 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
No, it actually doesn't determine the type anywhere - you are required to supply the type along with the parameter value and NHibernate relies on that supplied type.


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