Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Paginator\Adapter\DbSelect custom query for count #5518

Closed
wants to merge 2 commits into from

Conversation

snapshotpl
Copy link
Contributor

No description provided.

@ralphschindler
Copy link
Member

Out of curiosity, what's the motivation to make it a constant?

@snapshotpl
Copy link
Contributor Author

Column name from count query need to be always the same. It helps to use this name in own select.

@ralphschindler
Copy link
Member

Oh, I see. So the expectation for providing your own select that will calculate a count is that the custom select would have to return a resultant with that particular column name. Is that right?

@snapshotpl
Copy link
Contributor Author

Exactly! Additionally I can change this to first element of array.

@ralphschindler
Copy link
Member

I like this addition. I'm still thinking about the cross-platform ramifications of not using a column name. What would the code look like? Perhaps:

$result = $statement->execute();
$row = $result->current();
return reset($row);

?

@snapshotpl
Copy link
Contributor Author

Now this adapter building count select in the same way.

@ralphschindler
Copy link
Member

Let me know when you want me to look at this PR. I think I have a couple of modifications to the API I might make. I wouldn't call the new method getSelectCount() because it will either be retrieving a previously set one, or it will always be returning a completely different object based off the original Select. I think I would either check if $this->customSelectCount is set, or call createSelectCount() which would do the making of a Select based of the provided Select.

With the addition of this solution, I think it provides an outlet for these kinds of problems that crop up in edge cases: #4673

Thoughts?

ralphschindler referenced this pull request Nov 27, 2013
First attempt at using subselect to calculate full count
@ralphschindler
Copy link
Member

ping.

@@ -19,6 +19,8 @@
class DbSelect implements AdapterInterface
{

const ROW_COUNT_COLUMN_NAME = 'c';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this upper case; I know for DB2, lowercase will not work here.

@Ocramius
Copy link
Member

@snapshotpl I manually merged the PR in 5fceff3

Please note that I removed the setter and converted it into an additional constructor argument.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants