Support for Oracle connect by / start with

Posts   
 
    
YvesVD
User
Posts: 177
Joined: 19-Oct-2006
# Posted on: 14-Sep-2009 10:37:00   

Is it possible to fetch entities with a query that looks like this (chained list of records) :

select * from TFK_LOGGING_ACTIVITY a start with a.logging_action_id = 6574 connect by prior a.id = a.parent_activity_id

If yes a sample would be great.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Sep-2009 12:15:57   

You can use a dataReader, and stop reading when the condition is met (prior a.id = a.parent_activity_id).

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 14-Sep-2009 19:24:10   

Will look into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 15-Sep-2009 11:18:45   

there's no support for this, but you can do this I think through a custom Predicate class. So define your own class derived from Predicate and write it according to the other predicate classes, and define for the instancetype a value that's not in the PredicateType enum, e.g. 100

Your custom predicate should emit SQL like in your example, so the fragment start with a.logging_action_id = 6574 connect by prior a.id = a.parent_activity_id, in the form of: START WITH {0} = {1} CONNECT BY PRIOR {2} = {3}

your predicate's ctor then has to accept 3 fields, and you should obtain field names similar to for example FieldCompareValue does. This is straight forward, please examine the sourcecode of the other FieldCompare predicate classes in the runtime lib. Your class has to be able to store the 3 fields and 3 IFieldPersistenceInfo objects, one for each field.

You can also make things a bit simpler, by using two predicates to build this predicate, e.g. use a FieldCompareValue predicate for the START WITH part and a FieldCompareExpression predicate for the CONNECT BY PRIOR part simple_smile

As a last step, you've to add a partial class to DataAccessAdapter and override OnInsertPersistenceObjects(predicate). In that override you've to check for the InstanceType property on the predicate passed in (you can peek what to do/ how to do that in the generated code, the method InsertPersistenceInfoObjects in DataAccessAdapter), and when you've determined it's indeed your predicate, you've to insert the IFieldPersistenceInfo for the three fields so when the ToQueryText call comes you know what the tables etc. are.

If you use the two sub predicates route, all you've to do is simply call InsertPersistenceInfoObjects by passing the two predicates and it will be taken care of. Be aware that when you use the sub-predicate route, you've to set their DatabaseSpecificCreator property to the same value as your predicates' as they otherwise can't create SQL.

Frans Bouma | Lead developer LLBLGen Pro