Re: Preferred way for fetching with given SQL select statement?
Re: Preferred way for fetching with given SQL select statement?
- Subject: Re: Preferred way for fetching with given SQL select statement?
- From: Fabian Peters <email@hidden>
- Date: Fri, 25 Sep 2015 08:32:26 +0200
Maybe ERXSQLQueryWithBindingsUtilities could be useful here. You'd still have to parse the binding values, but at least you'd get to keep the SQL.
Fabian
> Am 25.09.2015 um 00:48 schrieb Chuck Hill <email@hidden>:
>
> The challenge is going to be "In addition these statements are
> parameterized with ? so they can be precompiled and then used with
> different query values²
>
> You might be able to parse and rewrite those as EOQualifierVariables and
> then use qualifier.qualiferWithBindings, but you are going to have to know
> the bindings for each statement. That all might be as much work as making
> proper EOQualifiers.
>
> Chuck
>
> On 2015-09-24, 11:48 AM,
> "webobjects-dev-bounces+chill=email@hidden on behalf of
> Johann Werner" <webobjects-dev-bounces+chill=email@hidden
> on behalf of email@hidden> wrote:
>
>> Hi Markus,
>>
>> I did not clearly understand what you are exactly trying to achieve. If
>> you just need to run the vendor specific SQL to get a list of primary
>> keys that you can then use to fetch the EOs you want you could do
>> something like
>>
>>
>> EOEditingContext ec = ERXEC.newEditingContext();
>> EOEntity entity = ERXEOAccessUtilities.entityNamed(MyEntity.ENTITY_NAME);
>> EODatabaseContext context =
>> EODatabaseContext.registeredDatabaseContextForModel(entity.model(), ec);
>> EOSQLExpressionFactory factory =
>> context.database().adaptor().expressionFactory();
>> EOSQLExpression expression = factory.expressionForString("SELECT Š");
>> NSArray<NSDictionary> rawRows =
>> ERXEOAccessUtilities.rawRowsForSQLExpression(ec, entity.model().name(),
>> expression);
>> NSArray<Integer> idList = rawRows.valueForKey("id³);
>> NSArray<MyEntity> result = MyEntity.fetchMyEntities(ec, ERXQ.in("id",
>> idList), null);
>>
>>
>> Otherwise if you need more than that and need to fetch EOs but have to
>> use your own SQL instead of the generated one by EOF you probably can do
>> this by using the hints dictionary of a fetch specification. Something
>> like
>>
>>
>> EOEditingContext ec = ERXEC.newEditingContext();
>> ERXFetchSpecification<MyEntity> fs = new
>> ERXFetchSpecification<>(MyEntity.ENTITY_NAME);
>> NSDictionary<String, String> hints = new NSDictionary<>("SELECT Š" ,
>> EODatabaseContext.CustomQueryExpressionHintKey);
>> fs.setHints(hints);
>> NSArray<MyEntity> result = fs.fetchObjects(ec);
>>
>>
>> Though I never used that sort of logic but you could experiment with
>> that. All code above is written by peeking at the API documentation with
>> extremely wild guesses included‹so no guarantees that it is correct or
>> complete. Use at your own risk ;-)
>>
>> jw
>>
>>
>>> Am 24.09.2015 um 16:22 schrieb Markus Ruggiero
>>> <email@hidden>:
>>>
>>> Folks,
>>>
>>> What is the preferred way to fetch EOs when you have a db vendor
>>> specific "select id from ... where ....." statement?
>>>
>>> I need to interface with a legacy system where I have to incorporate
>>> the functionality of an external java tool into a Wonder app. This
>>> external tool executes raw SQL select statements which it reads from a
>>> file. All the statements are in the form given above and return a list
>>> of primary key values (single column fortunately). The tool then
>>> iterates through that list and does whatever it has to do (issuing tons
>>> of more raw sql). My problem is that these select statements are rather
>>> complex and there are many of them. It is just not feasible to replace
>>> those with proper EOQualifiers. In addition these statements are
>>> parameterized with ? so they can be precompiled and then used with
>>> different query values. However everything can be done with standard EOs
>>> as soon as I have those corresponding to the returned list of ids.
>>>
>>> Thanks a lot
>>> ---markus‹
>>
>>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden