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

Re: SQL?


  • Subject: Re: SQL?
  • From: Sacha Michel Mallais <email@hidden>
  • Date: Wed, 8 Feb 2006 16:45:27 -0800

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@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: SQL?
      • From: Guido Neitzer <email@hidden>
    • Re: SQL?
      • From: "Jerry W. Walker" <email@hidden>
References: 
 >SQL? (From: Jim Wong <email@hidden>)

  • Prev by Date: Re: SQL?
  • Next by Date: QueryBindings, Datasource and/or FetchSpecifications
  • Previous by thread: Re: SQL?
  • Next by thread: Re: SQL?
  • Index(es):
    • Date
    • Thread