Re: Questions on Fetching with Conditions

"Jerry W. Walker" <[email protected]>
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Hi, Satoru,

For your first question, you might try CountFetcher. You hand it an  
EOFetchSpecification and it will generate and execute the SQL count  
statement for you returning an int result.

You can get it at:

      http://wocode.com/cgi-bin/WebObjects/WOCode.woa/2/wa/ 
ShareCodeItem?itemId=429

Regards,
Jerry

On Mar 2, 2006, at 9:04 AM, Satoru Moriwaki wrote:

> Hi,
>
> I have a couple of questions:
>
> 1) Is there another way to fetch row count without using the raw  
> row SQL or the obj.objects().count() method?
>
> e.g.
>
> String SQL = "select count(class_id) as count from clazz where  
> use_id = 1";
> NSArray objects = EOUtilities.rawRowsForSQL(ec, "Clazz", SQL, null);
> NSDictionary dict = (NSDictionary)objects.objectAtIndex(0);
> String count = dict.objectForKey("COUNT");
>
> or
>
> int count = student.classes().count();
>
> The first one, I have to hard code the SQL.  The second one fetches  
> all of the classes to count.  I do not wish to do that.
>
> 2) Is there another way to fetch "one" (limit 1) to-many  
> relationship entity object sorted by a certain column in ascending/ 
> decending order without using the raw row SQL or having to fetch  
> all of the objects using the obj.objects() and then sort?
>
> e.g.
>
> String SQL = "select * from clazz where user_id = '1' order by  
> registration_date ASC limit 1";
> ....
> ....
> ..
>
> or
>
> NSArray classes = student.classes();
> ...
> .. (and then sort or get the last index of objects or whatever...)
> ..
>
> Thanks!
>
> Satoru
> _______________________________________________
> WebObjects-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/webobjects-dev


--
__ Jerry W. Walker,
    WebObjects Developer/Instructor for High Performance Industrial  
Strength Internet Enabled Systems

     [email protected]
     203 278-4085        office
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.