• 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: select 'top' query??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: select 'top' query??


  • Subject: Re: select 'top' query??
  • From: Art Isbell <email@hidden>
  • Date: Mon, 22 Mar 2004 11:26:12 -1000

On Mar 22, 2004, at 10:03 AM, Jonathan Rochkind wrote:

My DB will accept SQL of the form:

SELECT TOP 100 column1, column2, etc
FROM [etc]

To return just the first 100 records, for instance.

Has anyone figured out a good easy way to get EOF to send a query like this? In a full EO query, not raw rows with hand constructed SQL. None of my usual tricks for customizing SQL apply here. Anyone have any ideas for something relatively easy?

Relatively easy? Ha :-) But I have found EOF to be extremely flexible in doing such things, even with some of the lost flexibility when EOF was moved from Objective-C to Java (Objective-C posing is your long-lost friend :-(


One approach would be to subclass JDBCExpression and add a "useTop" instance variable. Override prepareSelectExpressionWithAttributes(). If its fetch spec argument's hints dictionary contain a "UseTop" key, set useTop to true. Then invoke super's implementation.

Override assembleSelectStatementWithAttributes(). If useTop is true, append " TOP" to assembleSelectStatementWithAttributes()'s "selectString" argument in your invocation of super's implementation whose return value your override will return.

Then in every app that uses your JDBCExpression subclass, you have to remember to send the JDBCAdaptor class object a setExpressionClassName() message.

If that fails, I'd try creating a simple JDBCExpressionFactory subclass that overrides selectStatementForAttributes() which takes a fetch specification as an argument. When you want to use "SELECT TOP", add a "UseTop" key to the fetch spec's hints dictionary. In this selectStatementForAttributes() override, I'd invoke super's implementation. If the fetch spec's hints dictionary doesn't have a "UseTop" key, I'd return what super's invocation returned. But if "UseTop" exists, I'd parse the select statement that super's invocation returned, insert " TOP " after "SELECT", and return this modified "select" statement.

Then you have to make EOF use your JDBCExpressionFactory subclass. I'd try building and installing a simple framework containing a subclass of your DB-specific JDBCPlugin subclass. You'd have to specify this plugin in every eomodel's connection dictionary. In this JDBCPlugin subclass, override expressionFactory() to use the JDBCExpressionFactory subclass you created above.

Aloha,
Art
_______________________________________________
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: 
 >select 'top' query?? (From: Jonathan Rochkind <email@hidden>)

  • Prev by Date: WebObjects Developers Group, New York City
  • Next by Date: RE: select 'top' query??
  • Previous by thread: select 'top' query??
  • Next by thread: Re: select 'top' query??
  • Index(es):
    • Date
    • Thread