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 » SqlArray::SetDistinct()
SqlArray::SetDistinct() [message #7410] Wed, 27 December 2006 23:45 Go to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
I'd like to propose to add method SetDistinct() to SqlArray.

It can be easily implemented.

private:
bool distinct;

public:
SqlArray& SetDistinct(bool flag = true) { distinct = flag; return *this; }



Fixes for SqlArray::AppendQuery().

SqlSet select_cols;
select_cols = (distinct ? Distinct(cols) : cols);
if(IsNull(count))
sql * ::Select(select_cols).From(table).Where(wh).OrderBy(orderby) ;
else
sql * ::Select(select_cols).From(table).Where(wh).OrderBy(orderby) .Limit(count).Offset(offset);


Actually, it is a little bit inconvenient to have an SQL statement incorporated into SqlArray. It limits you by letting to use only one table and forces to reimplement all SQL-building API.

I hope I'm not very boring.



Regards,
Novo
Re: SqlArray::SetDistinct() [message #7411 is a reply to message #7410] Wed, 27 December 2006 23:52 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Novo wrote on Wed, 27 December 2006 17:45

I'd like to propose to add method SetDistinct() to SqlArray.

Actually, it is a little bit inconvenient to have an SQL statement incorporated into SqlArray. It limits you by letting to use only one table and forces to reimplement all SQL-building API.



Exactly. That is why it is often better to use plain ArrayCtrl Smile

In other words, SqlArray is designed to allow editing data. Distinct breaks this. If you need distinct, you most likely do not want to use SqlArray in the first place.

Using ArrayCtrl for SQL is trivial and very common in SQL apps. Note that you can even use ArrayCtrl as "master" and bind SqlArrays as details.

Mirek
Re: SqlArray::SetDistinct() [message #7480 is a reply to message #7411] Sun, 31 December 2006 05:19 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Thank you!

I got the idea. Just two remarks:

1) DISTINCT doesn’t break editing of data. You just need to add a list of columns from DISTINCT to a WHERE part. DISTINCT breaks master-detail relationship.

2) Instead of building an SQL statement in place you can analyze an already build statement and retrieve a list of columns to select and a FROM part. You already have a tree, which represents an SQL statement. You do not have to parse anything. You are a lucky man!

Happy New Year !!!


Regards,
Novo
Re: SqlArray::SetDistinct() [message #7483 is a reply to message #7480] Sun, 31 December 2006 09:23 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Novo wrote on Sat, 30 December 2006 23:19

Thank you!

I got the idea. Just two remarks:

1) DISTINCT doesn�t break editing of data. You just need to add a list of columns from DISTINCT to a WHERE part. DISTINCT breaks master-detail relationship.



I guess you are right. Anyway, IME distinct is useful for selecting single column only, correct? I just somehow fail to see scenario / data model where distinct would be useful with SqlArray. OTOH, it is true that I have mostly self-learned most of data model design Smile (Means: I am quite interested about the real world example of distinct with SqlArray).

Quote:


You already have a tree, which represents an SQL statement. You do not have to parse anything.



Well, in fact, I do not have a tree, I considered that too expensive.

Mirek
Previous Topic: SqlArray::Join when a foreign key has more than one field
Next Topic: SqlArray Limit and Offset
Goto Forum:
  


Current Time: Mon Apr 29 06:58:00 CEST 2024

Total time taken to generate the page: 0.04768 seconds