• 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: EOFetchSpecification with SQL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOFetchSpecification with SQL


  • Subject: Re: EOFetchSpecification with SQL
  • From: Jonathan Rochkind <email@hidden>
  • Date: Wed, 20 Aug 2003 10:36:02 -0500

At 01:22 PM 8/20/2003 +0300, Alex Blaj wrote:
Hello again,

Is there any way to create a fetchSpecification using a String that contains
the SELECT statement for that fetchSpec?

Well, yes, you CAN specify the entire raw SQL for a fetch specification. If the fetch spec is fetching full EOs, you've got to make sure to have all the columns included in your entity, in the right order. If the fetch spec is just fetching raw rows, you can do what you want (but might as well use EOUtilities.rawRowsForSQL instead).


EOFetchSpecification spec; //assume exists
String sqlQuery; //assume exists

NSMutableDictionary hints = new NSMutableDictionary();
hints.setObjectForKey( sqlQuery, EODatabaseContext.CustomQueryExpressionHintKey);


spec.setHints( hints );
====

Now, just because you CAN do this doesn't mean you really should. From a maintainability standpoint, from the design goal of seperate layers, it's really undesirable to have raw SQL hardcoded into your app. If you find yourself doing this in all but the most rare and unusual circumstances---either you are doing something wrong, or EOF may not be a good tool for you.

If you just want to manually write the "WHERE" part of the SQL query, not the entire query, you can do that with the EOSQLQualifier instead---the same caveats apply.

Or, if I declared a new fetchSpecification, it there a way to set its bindings
so that it corresponds to my SELECT (String) statement.

Not sure what you mean.

I'm using a query like this: (SELECT ...) INTERSECT (SELECT ...).

Ah, that INTERSECT is going to be tricky. I can't think of a good way to get EOF to generate a query with that kind of INTERSECT in it. You could just give up and fetch both seperate querries into memory, and then do the intersect in memory with NSSet/NSMutableSet. If the data isn't prohibitively large.


Or, if I use the rawRowsForSQL method, is there a "nice" way of getting the
results as I would get them from objectsWithFetchSpecification (instead of
creating an array of objects and set all their attributes to what I got from
rawRowsForSQL)?

If you use rawRowsForSQL, it will just return raw rows---not EOs. You can turn these raw rows into EOs later, as long as they contain primary key information (see EOUtilities.faultForRawRow and EOUtilities.objectForRawRow ), but the operation to turn the raw row into an EO may require another round trip to the db---in some cases one round trip per row, but this can be made more efficient sometimes.


If you use an EOFetchSpecification, as I explained above, you _can_ specify the raw SQL yourself. If you want actual EOs to be returned, you've got to make sure the right columns are returned in the right order. If you later add columns in EOModeler, it may break your hard coded SQL, which is another reason to avoid it.

Hope this helps,
--Jonathan


Thanks,
Alex.


===================================================================Lettrix bv,
P.O. Box 5, 6980 AA Doesburg,
The Netherlands -- Tel: +31 313 478 000,
Fax: +31 313 478 080 -- Check our website at:
http://www.lettrix.com
===================================================================Disclaimer
:
The information contained in this communication is confidential and
may be legally privileged. It is intended solely for the use of the
individual or entity to whom it is addressed and others authorised to
receive it. If you are not the intended recipient you are hereby
notified that any disclosure, copying, distribution or taking any
action in reliance on the contents of this information is strictly
prohibited and may be unlawful. Lettrix B.V. is neither liable for
the proper and complete transmission of the information contained in
this communication nor for any delay in its receipt.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >EOFetchSpecification with SQL (From: "Alex Blaj" <email@hidden>)

  • Prev by Date: Re: how to generate multiple aliases in a SELECT
  • Next by Date: Re: Mapping multiple EOs to one table
  • Previous by thread: Re: EOFetchSpecification with SQL
  • Next by thread: Re: EOFetchSpecification with SQL
  • Index(es):
    • Date
    • Thread