Re: Whats the recommended way for cross-object information inquiry?
Re: Whats the recommended way for cross-object information inquiry?
- Subject: Re: Whats the recommended way for cross-object information inquiry?
- From: Jonathan Rochkind <email@hidden>
- Date: Tue, 9 Mar 2004 17:23:27 -0600
Counting rows, I know how to do with straight qualifiers (for a fetch
spec that will return raw rows). The "GROUP BY"----I don't think
there's any way to do it.
Now, even if you do give up and construct the SQL by hand, you can
get all the column and table names from the EOModel if you want.
That would be the best compromise, when you really do need to write
raw SQL.
EOEntity personEntity = EOUtilities.entityNamed( ec , "Person"); //or whatever
String tableName = personEntity.externalName();
EOAttribute yearAtt = personEntity.attributeNamed( "year" );
String columnName = yearAtt.externalName();
StringBuffer rawSQL = new StringBuffer();
rawSQL.append("SELECT ").
rawSQL.append( columName ).append(", count(*) FROM ");
rawSQL.append( tableName ).append(" GROUP BY
").append(columnName).append(" ORDER BY ").append(columnName);
You get the idea. When you really are best served by writing your
own SQL----at least get the column and table names from the model, so
if you change them in the model your code is still good. It's not
hard. If you change to a different database that doesn't support the
SQL you want... then you're still out of luck, of course. But
sometimes you really do intentionally want to use SQL that may not
work in all databases---because it does the job with the one you've
got, much more efficiently than anything else could.
--Jonathan
At 4:57 PM -0600 3/9/04, Jonathan 'Wolf' Rentzsch wrote:
Jonathan Rochkind, email@hidden, wrote:
Yeah, but in this case... did you see the SQL he wanted to use? I'm
not sure there's any good way to get that SQL out of a
qualifier/fetch spec. If there is.... then someone suggest it!
It was:
SELECT YEAR, count(*) FROM PERSONS_TABLE GROUP BY YEAR ORDER BY
YEAR;
Ah, good point. I missed the counting and 'GROUP BY'.
Project WONDER has some GROUP BY support (see ERXToManyQualifier and
DynaReporter). I don't know if this is a complete fit as I haven't needed
it myself.
If you just want to count rows instead of returning them, that requires
some nonobvious code:
<http://www.omnigroup.com/mailman/archive/webobjects-dev/2002-April/022359.
html>
| Jonathan 'Wolf' Rentzsch http://rentzsch.com
| Red Shed Software http://redshed.net
| "better" necessarily means "different"
_______________________________________________
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.