Yii2: SQLDataProvider is broken after the fix for #13883

Created on 25 Apr 2017  路  9Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

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;
    }

What is the expected result?

Fetched data was returned without any problems.

What do you get instead?

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.

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.12
| PHP version | 5.5.3
| Operating system | Mac OS X

bug

Most helpful comment

@xloading I have created a PR for the fix, as a workaround you could supply the total count manually!

All 9 comments

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nokimaro picture nokimaro  路  3Comments

MUTOgen picture MUTOgen  路  3Comments

sobit picture sobit  路  3Comments

psfpro picture psfpro  路  3Comments

jpodpro picture jpodpro  路  3Comments