XQuery & XML DML

Posts   
 
    
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 29-Jan-2007 14:19:42   

I have seen a few old posts: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4577&HighLight=1 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5684&HighLight=1

about using IPredicate to give XQuery (and presumably XML DML), but there hasn't been any discussion after that.

Before I start coding: Is XQuery support planned for a future version? Is XML DML support planned for a future version? Has someone already done it? Why IPredicate and not public class MyXQueryExpression : SD.LLBLGen.Pro.ORMSupportClasses.Expression?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 29-Jan-2007 19:20:42   

simon831 wrote:

I have seen a few old posts: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4577&HighLight=1 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5684&HighLight=1

about using IPredicate to give XQuery (and presumably XML DML), but there hasn't been any discussion after that.

Before I start coding: Is XQuery support planned for a future version?

It was on the list for v2.0 but it was rejected because it was impossible to produce a query without embedding specified values in the direct SQL. I.o.w.: it wasn't possible to produce a query with parameters for the XQuery parts, so it could lead to sql injection attacks. As we are very careful about this, we want to avoid that our code is vulnerable to sql injection attacks at any level so we rejected it.

Is XML DML support planned for a future version?

If it's not doable with parameters, then again it won't be added.

Has someone already done it? Why IPredicate and not public class MyXQueryExpression : SD.LLBLGen.Pro.ORMSupportClasses.Expression?

Predicate classes are used in the where clause so I think the xquery is also used there, as part of the where clause, or do you want to use it elsewhere?

Frans Bouma | Lead developer LLBLGen Pro
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 30-Jan-2007 10:12:25   

I understand why you are so careful about injection. This is something I still need to do though, so I will write something to parse for potential injection.

Otis wrote:

[Predicate classes are used in the where clause so I think the xquery is also used there, as part of the where clause, or do you want to use it elsewhere?

I want to use it in the where clause, but also in the select statement.

Could you point me towards some sample predicate code (and whatever I need for the select part) - Just to get me started.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 30-Jan-2007 11:01:07   

Best place to start is in the ormsupport classes sourcecode which is in the llblgen pro installation folder simple_smile The easiest predicate class is the FieldCompareNullPredicate, so you get an idea how it works and what to call. simple_smile Basicly you derive a class from Predicate and emit the SQL in ToQueryText().

One thing to note: in adapter, the DataAccessAdapter will check which predicate class is passed in and will then request the fields and other elements to inject persistence info. As this is different for each predicate, it had to be done via a switch /case.

This routine is in the generated code, InsertPersistenceInfoObjects(IPredicateExpression expression).

To make it extensible, it calls the OnInsertPersistenceObjects routine, which normally does nothing. If you implement your own XQuery predicate class, you could simply override OnInsertPersistenceObjects in a derived class of DataAccessAdapter and inject the persistence info of the various elements in your XQuery predicate in that routine. You don't have to do the persistence info injection yourself, just use the overloads, like the InsertPersistenceInfoObjects(expression) or other ones.

Frans Bouma | Lead developer LLBLGen Pro
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 30-Jan-2007 11:06:51   

And do I inhertit from Expression to write an XQueryExpression class for the select part?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 30-Jan-2007 11:29:16   

simon831 wrote:

And do I inhertit from Expression to write an XQueryExpression class for the select part?

Not necessarily. All you need to do is implement IExpression. Take a look at DbFunctionCall, Expression and ScalarQueryExpression for examples how to do that in various contexts simple_smile

Frans Bouma | Lead developer LLBLGen Pro