On Feb 8, 2006, at 4:33 PM, Jim Wong wrote:

Can I use SQL statements in WO to extract certain rows in my entity? Basically I want to filter my entity object for certain rows of data. how to do this?

Yes you can, but you generally don't want to. Take a look at the documentation for EOFetchSpecification. http://developer.apple.com/documentation/WebObjects/Reference/API/com/ webobjects/eocontrol/EOFetchSpecification.html

If you _must_ use SQL (usually only necessary for optimization), then you'll have to do something like this:

        EOModel model = entity.model();
EOSQLExpressionFactory expressionFactory = new EOSQLExpressionFactory(EOAdaptor.adaptorWithModel(model));

EOAdaptorChannel channel = (dbCtxt.availableChannel ()).adaptorChannel();
        EOAdaptorContext adaptorContext = channel.adaptorContext();

        adaptorContext.beginTransaction();

EOSQLExpression expression = expressionFactory.expressionForString("******SQL STATEMENT HERE*******"); NSArray results = (NSArray) EOAdaptorChannelAdditions.resultOfEvaluatingSQLExpression(channel, expression);

        adaptorContext.commitTransaction();

Of course, you can also JDBC directly if you don't need both your feet...


sacha


--
Sacha Michel Mallais             Senior Developer / President
Global Village Consulting Inc.   http://www.global-village.net/
PGP Key ID: 7D757B65             AIM: smallais
ObAd: read "Practical WebObjects" <fnord>
http://www.global-village.net/products/practical_webobjects


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to