• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Preferred way for fetching with given SQL select statement?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Preferred way for fetching with given SQL select statement?


  • Subject: Re: Preferred way for fetching with given SQL select statement?
  • From: Samuel Pelletier <email@hidden>
  • Date: Thu, 24 Sep 2015 18:30:13 -0400

Hi,

For raw row fetches, there is a shorter way:

EOEditingContext ec = ERXEC.newEditingContext();
NSArray<NSDictionary> rawRows = EOUtilities.rawRowsForSQL(ec, "YourModelName", sql));
...

Samuel


> Le 2015-09-24 à 14:48, Johann Werner <email@hidden> a écrit :
>
> 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


References: 
 >Preferred way for fetching with given SQL select statement? (From: Markus Ruggiero <email@hidden>)

  • Prev by Date: Preferred way for fetching with given SQL select statement?
  • Next by Date: Re: AjaxFlickrBatchNavigation
  • Previous by thread: Preferred way for fetching with given SQL select statement?
  • Next by thread: Re: Preferred way for fetching with given SQL select statement?
  • Index(es):
    • Date
    • Thread