• 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: EOFetchSpecification - sorting by partial date
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOFetchSpecification - sorting by partial date


  • Subject: Re: EOFetchSpecification - sorting by partial date
  • From: Chuck Hill <email@hidden>
  • Date: Mon, 13 Jul 2015 16:38:38 +0000
  • Thread-topic: EOFetchSpecification - sorting by partial date

You could create two read only, columns with a definition that extracts the year and month using SQL functions and use those columns to sort on.

Chuck

On 2015-07-13, 9:36 AM, "Calven Eggert" wrote:

Thanks for the idea.  sorting in memory is the other option I’ve considered, however, was hoping to get the results faster at the database end.

On Jul 13, 2015, at 12:27 PM, Samuel Pelletier <email@hidden> wrote:

Calven,

There is no easy way on the database but you can add a method that returns a formatted string or int and sort in memory on it.

To use an int, you take the date year*100 + month number, for a string a formatter like this "yyyy-MM".

For more readable code, add an ERXKey on your entity class like this:
public static ERXKey<String> YEAR_MONTH = new ERXKey<String>("yearMonth");

and sort like this:
sortedRows = EntityClass.YEAR_MONTH.ascs().sorted(rowsFromDB);

BTW, if you are using the Wonder templates, your sort ordering can be created like this with no strings constants:

orderings = SOURCE.ascInsensitive().then(APPOINTMENT_DATE.ascInsensitive()).then(SITE.ascInsensitive());

Samuel


Le 2015-07-13 à 12:02, Calven Eggert <email@hidden> a écrit :

Hi, All

I have a fetch that sorts records by three columns where one of the columns is a date (timestamp).  Is there a way to sort the date by month & year only?  


Thanks,
Calven

Here is the current fetch:

...
EOSortOrdering sortBySource = new EOSortOrdering("source", EOSortOrdering.CompareCaseInsensitiveAscending);
EOSortOrdering sortByAppt = new EOSortOrdering("appointmentDate", EOSortOrdering.CompareCaseInsensitiveAscending);
    EOSortOrdering sortBySite = new EOSortOrdering(“site", EOSortOrdering.CompareCaseInsensitiveAscending);
    NSMutableArray orderings = new NSMutableArray();
    orderings.addObject(sortBySource);
    orderings.addObject(sortByAppt);
    orderings.addObject(sortBySite);
EOFetchSpecification spec = new EOFetchSpecification(“records", qual, orderings);


_______________________________________________
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



Calven



 _______________________________________________
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

References: 
 >EOFetchSpecification - sorting by partial date (From: Calven Eggert <email@hidden>)
 >Re: EOFetchSpecification - sorting by partial date (From: Samuel Pelletier <email@hidden>)
 >Re: EOFetchSpecification - sorting by partial date (From: Calven Eggert <email@hidden>)

  • Prev by Date: Re: EOFetchSpecification - sorting by partial date
  • Next by Date: Re: EOFetchSpecification - sorting by partial date
  • Previous by thread: Re: EOFetchSpecification - sorting by partial date
  • Next by thread: Re: EOFetchSpecification - sorting by partial date
  • Index(es):
    • Date
    • Thread