Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » OrderBy Descending missing
OrderBy Descending missing [message #21048] Tue, 28 April 2009 19:25 Go to next message
phirox is currently offline  phirox
Messages: 49
Registered: December 2007
Member
I found this previous topic about the same thing. But it says there is a descending() function, I could find no such thing. So I just added the suggested OrderByDesc() function.

In Sqlexp.h:
SqlSelect& OrderByDesc(const SqlSet& columnset);
SqlSelect& OrderByDesc(SqlVal a)                      { return OrderByDesc(SqlSet(a)); }
SqlSelect& OrderByDesc(SqlVal a, SqlVal b)            { return OrderByDesc(SqlSet(a, b)); }
SqlSelect& OrderByDesc(SqlVal a, SqlVal b, SqlVal c)  { return OrderByDesc(SqlSet(a, b, c)); }


And in SqlStatement.cpp
SqlSelect& SqlSelect::OrderByDesc(const SqlSet& set) {
	if(!set.IsEmpty())
		text << " order by " << ~set << " desc";
	return *this;
}

[Updated on: Wed, 29 April 2009 10:04]

Report message to a moderator

Re: OrderBy Descending missing [with fix] [message #21049 is a reply to message #21048] Tue, 28 April 2009 19:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
phirox wrote on Tue, 28 April 2009 13:25

I found this previous topic about the same thing. But it says there is a descending() function, I could find no such thing. So I just added the suggested OrderByDesc() function.

In Sqlexp.h:
SqlSelect& OrderByDesc(const SqlSet& columnset);
SqlSelect& OrderByDesc(SqlVal a)                      { return OrderByDesc(SqlSet(a)); }
SqlSelect& OrderByDesc(SqlVal a, SqlVal b)            { return OrderByDesc(SqlSet(a, b)); }
SqlSelect& OrderByDesc(SqlVal a, SqlVal b, SqlVal c)  { return OrderByDesc(SqlSet(a, b, c)); }


And in SqlStatement.cpp
SqlSelect& SqlSelect::OrderByDesc(const SqlSet& set) {
	if(!set.IsEmpty())
		text << " order by " << ~set << " desc";
	return *this;
}




Well, this is taken from the code I am working on now:

	sql * Select(ROK, CISLO).From(STIZNOST).OrderBy(Descending(ROK), CISLO);


As argument of OrderBy is set, function is must...

Mirek
Re: OrderBy Descending missing [with fix] [message #21052 is a reply to message #21049] Tue, 28 April 2009 21:33 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Actually, I prefer OrderByDesc and SelectDistinct. The main reson is you can't write
Select(Disctinct(ID, NAME, AGE))

instead one must write
Select(Disctinct(SqlSet(ID, NAME, AGE)))

And what I like
SelectDisctinct(ID, NAME, AGE) //or
SelectUnique(ID, NAME, AGE)

Same story with Descending.
We could provide __Expand(SelectDistinct). Same should be done with OrderBy (OrderByDesc) and GroupBy. Now only three args can be passed.
Re: OrderBy Descending missing [with fix] [message #21053 is a reply to message #21052] Tue, 28 April 2009 21:36 Go to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Ok, I changed my mind regarding OrderByDesc. I forgot one can mix ascedning with descending..
Previous Topic: sql example with 2 table needed
Next Topic: sqlite3 get number of occurrences
Goto Forum:
  


Current Time: Fri Mar 29 05:57:25 CET 2024

Total time taken to generate the page: 0.01316 seconds