I have used previously the following actions in my REST controllers without any issues:
public function actionTest($param1, $param2, ...)
{
$dataProvider = new SqlDataProvider([
'sql' => "LONG_AND_COMPLEX_SQL_HERE",
'params' => [':bind1' => $param1, ':bind2' => $param2, ... ],
]);
return $dataProvider;
}
Fetched data was returned without any problems.
After the following commit: https://github.com/yiisoft/yii2/commit/79f16b149239c0d1314102999a2fc8353ee8cb0b#diff-ae590364dfa0d2f31362d9cc86726fc1
I started getting
SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
exception, because the introduced totalCount fallback does not consider 'params' at all.
Seems it was coded for too narrow case.
| Q | A
| ---------------- | ---
| Yii version | 2.0.12
| PHP version | 5.5.3
| Operating system | Mac OS X
@samdark @SamMousa
Hmm, looking into it.
Okay, the error is obvious now... You have both SQL and params and for count I simply ignore params...
@SamMousa do you have to submit a PR?
Yes, I'm working on it now, expect < 20 mins :)
I'm having an issue with the test case; it does not fail when it should because it uses sqlite....
@xloading I have created a PR for the fix, as a workaround you could supply the total count manually!
Thanks a lot Sam!
I will test it tonight and let you know the results.
PR #14047 is merged. Thank you
Most helpful comment
@xloading I have created a PR for the fix, as a workaround you could supply the total count manually!