XQuery

Posts   
 
    
Rushmore
User
Posts: 125
Joined: 27-Jan-2005
# Posted on: 15-Nov-2012 17:49:17   

I´ve build a DbFunctionCall, the output shows the following statement

Query: SELECT [AppData].[AppDataId], [AppData].[AppDataName], [AppData].[AppDataXml] FROM [AppData] WHERE ( ( ( (SELECT [AppData].[AppDataXml].value('((/Data1/DataInt)[@p4])[1]','int') AS TEST) = @p2))) Parameter: @p4 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 1. Parameter: @p2 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 567.

The result of the FetchTypedList is empty.

If I copy the output text to the sql management studio, change the @p to it´s related values and hit F5, I got the expected result.

Any idea?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 15-Nov-2012 18:09:27   

Please post the code used to generate this query.

Rushmore
User
Posts: 125
Joined: 27-Jan-2005
# Posted on: 16-Nov-2012 10:35:05   

Here it is:


TlAppDataXmlTestTypedList typedList = new TlAppDataXmlTestTypedList();

IPredicateExpression filter = new PredicateExpression();
filter.Add(new EntityField2("TEST", new DbFunctionCall("(SELECT
[AppData].[AppDataXml].value('((/Data1/DataInt)[{0}])[1]','int') AS TEST)", new object[] {1})) == 567);

using (DataAccessAdapter adapter = new DataAccessAdapter(connectionString))
{
    adapter.FetchTypedList(typedList, filter);
}


Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 16-Nov-2012 10:55:39   

xquery requires values to be in-lined, it can't work with parameters. This is also the reason we don't support it as it allows sql injection. So to make this work, you have to in-line the values you pass to the DBFunctionCall, and not pass them as parameters.

Frans Bouma | Lead developer LLBLGen Pro