Conversation
Added a new method on the Zend\Db\Sql\Select object to perform a DISTINCT Select.
… the unit tests Also added a distinct unit test
@@ -91,6 +93,11 @@ class Select extends AbstractSql implements SqlInterface, PreparableSqlInterface | |||
protected $prefixColumnsWithTable = true; | |||
|
|||
/** | |||
* @var null|bool | |||
*/ | |||
protected $distinct = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be false by default?
Yes I guess it makes more sense. |
*/ | ||
public function distinct() | ||
{ | ||
$this->distinct = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argument to set to true / false
Because MySQL supports more than that flags I would prefer to implement it as list of flags addable to a select like it was done by propel: Other servers supports at least the |
Well this is probably more correct, however I've tried to replicate the behaviour of Zend_Db_Select of ZF1. MSSQL has also the |
So that "thing" is called a "Set Quantifier", and I think the API should reflect that probably: public function quantifier($quantifier = 'ALL')
{
} quantifiers can be strings (literal expressions), predicates or arrays DISTINCT and ALL are part of SQL92, but I don't think we should make a list as most server implementations will have their own. Usage would look like: $select->quantifier('DISTINCT');
or for sql server, for example:
$select->quantifier(array('TOP ?' => 10)); Thoughts? |
@ralphschindler If this isn't in conflict with limit it looks good to me. $select->quantifier(array('TOP ?' => 10));
$select->limit(500);
// = ?
|
From a dialect/sql parser standpoint, there is no conflict. Now, for Sql Server, I can't promise the engine won't barf when it tries to build a query plan. Also, limit/offset is a sensitive subject on Sql Server specifically with regards to whatever version you're using. Sql Server got limit/offset support in Denali (latest version). using |
@twmobius @marc-mabe and @ralphschindler Can the three of you come up with a plan of action, please? It looks like a different direction needs to be taken, but the solution is also getting quite out-of-date with master; we either need to move forward or close... |
Sorry for taking too long to respond, but I've been really busy lately. |
I started tackling with this and first of, I see that there is a problem with having a Predicate\Expression to supply quantifiers like 'TOP %d'. The processExpression method quotes the values in an expression resulting in TOP [10] instead of the Literal TOP 10 that Sql Server expects. Also to my understanding ALL | DISTINCT are mutually exclusive, therefore there shouldn't be any need for multiple quantifiers. (array as parameter) |
@twmobius, I think all quantifiers are mutually exclusive, no? I will work up a PR for this. |
@ralphschindler Well I've looked up transact-sql and you could have |
Ok, to start, lets go with a single quantifier, let me take a stab at this. |
Please see the implementation in #3682 |
I've added DISTINCT on Zend\Db\Sql\Select as a new method to support queries like 'SELECT DISTINCT * FROM foo'
Also updated the unit tests to pass after the changes and added a new test for the DISTINCT feature.
This fixes partially #2509