Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count() on \Dibi\Fluent with offset does not work #196

Open
paranoiq opened this issue Nov 18, 2015 · 4 comments
Open

count() on \Dibi\Fluent with offset does not work #196

paranoiq opened this issue Nov 18, 2015 · 4 comments

Comments

@paranoiq
Copy link
Contributor

the offset is applied on the outer query instead of on the inner query. Fluent generates SQL code such as:

SELECT COUNT(*) 
FROM ( 
    SELECT * 
    FROM `table` 
) `data` 
LIMIT 25 
OFFSET 25

(with MySqliDriver)

@dg
Copy link
Owner

dg commented Nov 18, 2015

Why?

@paranoiq
Copy link
Contributor Author

i am not sure

query exported from Fluent:

'SELECT COUNT(*) FROM (%ex', $this->_export(), ') [data]'

where _export() is:

array (14)
0 => "%lmt %ofs" (9)
1 => 25
2 => 25
3 => "SELECT" (6)
4 => "*"
5 => "FROM" (4)
6 => "%n" (2)
7 => "table" (17)
8 => "WHERE" (5)
9 => "active = %b" (11)
10 => FALSE
11 => "ORDER BY" (8)
12 => "%n" (2)
13 => "title" (5)

is in Connection translated into:

"SELECT COUNT(*) FROM (   SELECT * FROM `table` WHERE active = 0 ORDER BY `title` ) `data` LIMIT 25 OFFSET 25"

it doesn't make sense since Translator is cloned when empty :/

@dg
Copy link
Owner

dg commented Nov 18, 2015

Hmmm, it is due to c26201c.

Workaround is to use 'SELECT COUNT(*) FROM (', $fluent, ') [data]'.

@dg
Copy link
Owner

dg commented Nov 18, 2015

Problem is that translator is NOT cloned when you use %ex, see

} elseif ($mod === 'ex') { // array expansion
.

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

No branches or pull requests

2 participants