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

Add support for nested query in field params #300

Merged
merged 14 commits into from
Apr 5, 2018

Conversation

tptrixtop
Copy link
Contributor

@tptrixtop tptrixtop commented Jan 19, 2018

Sorry, previous request was incorrect.

This one is correct.
Add support for multi limit in nested queries;
That fix need for nested queries inside field parameters;

In previous thread was mentioned that this is fix for that issue: #262

Fix bug for nested queries inside field parameters;

Add support for multi limit in nested queries;
That fix need for nested queries inside field parameters;
Add support for nested query in field params;
@michalbundyra
Copy link
Member

@tptrixtop as @froschdesign mentioned before in #299 (comment) can you add test case for it, please?

@tptrixtop
Copy link
Contributor Author

sure, i will add test for that case

@tptrixtop
Copy link
Contributor Author

tptrixtop commented Jan 19, 2018

I have added tests for that case.
And 1 more fix for the same issue with offset param in nested queries;

Copy link
Member

@michalbundyra michalbundyra left a comment

Choose a reason for hiding this comment

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

Please use camelCase variable names instead of underscode_separated.

What about test case suggested in #262:
autowp@95efe84
Is it a valid case? Maybe it's worth to add it here?

@@ -50,7 +50,8 @@ protected function processLimit(
return;
}
if ($parameterContainer) {
$parameterContainer->offsetSet('limit', $this->limit, ParameterContainer::TYPE_INTEGER);
$param_prefix = $this->processInfo['paramPrefix'];
Copy link
Member

Choose a reason for hiding this comment

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

Please use camelCase variable names instead of underscore_separated style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, i think case with 1 query is valid, i will add it)

@tptrixtop
Copy link
Contributor Author

Done. I have added test for single nested query ( few limit case #262 ).
Variable renamed from underscore to camel case.

Copy link
Member

@michalbundyra michalbundyra left a comment

Choose a reason for hiding this comment

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

In general it looks good for me, I would just change offset to be different in nested and main query, to make sure nothing is mixed there.

Do we have this issue only in Mysql SelectDecorator or maybe we have similar issue also on other platforms?

->columns([
'res' => $nestedSelect0,
])
->limit('10')->offset('5');
Copy link
Member

Choose a reason for hiding this comment

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

I would set here different offset, now we have the same as in the nested query, and it's possible that something is getting mixed, so to make it clear I would change the value.

->columns([
'res' => $nestedSelect0,
])
->limit('10')->offset('5');
Copy link
Member

Choose a reason for hiding this comment

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

Another question also here: why these values are passed as strings, not as integers?

'res' => $nestedSelect0,
'res0' => $nestedSelect1
])
->limit('10')->offset('5');
Copy link
Member

Choose a reason for hiding this comment

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

Also here, I would change the offset, to be different than in nested queries.

@tptrixtop
Copy link
Contributor Author

I have remove extra quotes and change offset & limit.

I did not check it for other platforms. Only for MySQL.
I will try to check it for other platforms)

@tptrixtop
Copy link
Contributor Author

tptrixtop commented Jan 20, 2018

Done.
Limit & Offset are working in Oracle, MS SQL & IbmDb2.

Only additional fix needed in Sqlite. I have fixed it & added test for that & committed;

}

return [$this->offset];
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd just to note that these methods are exactly the same as in:

protected function processLimit(
PlatformInterface $platform,
DriverInterface $driver = null,
ParameterContainer $parameterContainer = null
) {
if ($this->limit === null && $this->offset !== null) {
return [''];
}
if ($this->limit === null) {
return;
}
if ($parameterContainer) {
$paramPrefix = $this->processInfo['paramPrefix'];
$parameterContainer->offsetSet($paramPrefix . 'limit', $this->limit, ParameterContainer::TYPE_INTEGER);
return [$driver->formatParameterName('limit')];
}
return [$this->limit];
}
protected function processOffset(
PlatformInterface $platform,
DriverInterface $driver = null,
ParameterContainer $parameterContainer = null
) {
if ($this->offset === null) {
return;
}
if ($parameterContainer) {
$paramPrefix = $this->processInfo['paramPrefix'];
$parameterContainer->offsetSet($paramPrefix . 'offset', $this->offset, ParameterContainer::TYPE_INTEGER);
return [$driver->formatParameterName('offset')];
}
return [$this->offset];
}

and the difference with parent class Select is to not quote offset and limit values.
I think it's fine, for MySQL it was added in that commit: 91bfba7

Copy link
Member

@michalbundyra michalbundyra left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Great job @tptrixtop !

@froschdesign tests are provided now, and the fix looks good to me.

ping @ezimuel

@ezimuel ezimuel merged commit 684d9e3 into zendframework:master Apr 5, 2018
@ezimuel
Copy link
Contributor

ezimuel commented Apr 5, 2018

@tptrixtop thanks!

@tptrixtop
Copy link
Contributor Author

My pleasure, sir)

@froschdesign froschdesign added this to the 2.9.3 milestone Apr 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants