laminas / laminas-db

Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations
https://docs.laminas.dev/laminas-db/
BSD 3-Clause "New" or "Revised" License
122 stars 69 forks source link

PHP 8.0: vsprintf() fails for SQL query #178

Closed FabianRahm closed 3 years ago

FabianRahm commented 3 years ago

Bug Report

Q A
Version(s) 2.11.3

Summary

Using SQL with the TableGateway pattern and a closure with a join on another table fails on the GROUP BY clause while strict types are enabled in PHP 8.0. The identical code runs flawlessly in the latest PHP 7.4.

Current behavior

File:

/vendor/laminas/laminas-db/src/Sql/AbstractSql.php:256

Message:

vsprintf(): Argument #2 ($values) must be of type array, string given

Stack trace:

#0 /vendor/laminas/laminas-db/src/Sql/AbstractSql.php(256): vsprintf()
#1 /vendor/laminas/laminas-db/src/Sql/AbstractSql.php(71): Laminas\Db\Sql\AbstractSql->createSqlFromSpecificationAndParameters()
#2 /vendor/laminas/laminas-db/src/Sql/AbstractPreparableSql.php(33): Laminas\Db\Sql\AbstractSql->buildSqlString()
#3 /vendor/laminas/laminas-db/src/Sql/Platform/Platform.php(102): Laminas\Db\Sql\AbstractPreparableSql->prepareStatement()
#4 /vendor/laminas/laminas-db/src/Sql/Sql.php(139): Laminas\Db\Sql\Platform\Platform->prepareStatement()
#5 /vendor/laminas/laminas-db/src/TableGateway/AbstractTableGateway.php(238): Laminas\Db\Sql\Sql->prepareStatementForSqlObject()
#6 /vendor/laminas/laminas-db/src/TableGateway/AbstractTableGateway.php(207): Laminas\Db\TableGateway\AbstractTableGateway->executeSelect()
#7 /vendor/laminas/laminas-db/src/TableGateway/AbstractTableGateway.php(195): Laminas\Db\TableGateway\AbstractTableGateway->selectWith()

How to reproduce

/**
 * @return ResultSetInterface
 * @throws Exception
 */
public function fetchAircraftTypesInArticles() : ResultSetInterface
{
    return $this->tableGateway->select(function (Select $select) {
        $select->join(
            'articles',
            'articles.acftType = acfttypes.type',
            [],
            'inner'
        );

        $select->group('articles.acftType');
        $select->order('acfttypes.manufacturer ASC, acfttypes.model ASC');
    });
}

Expected behavior

The query is executed without an exception.

alpenbytes commented 3 years ago

PR #177

alpenbytes commented 3 years ago

To be more precise: This issue also occurs when not in strict_mode and with a Select as simple as the following.

return $this->getSql()->select()
->group(['id']); // or just as string 'id'

This breaks the script with the TypeError as shown in the first post. Did temporarly apply the fix from PR 177 as now I can upgrade to PHP 8.

Grundik commented 3 years ago

Are there any progress on this? This is annoying bug with trivial fix, blocking migration to PHP 8.0.

MatyCZ commented 3 years ago

@boesing @samsonasik Is it possible to release this fix as new patch version?

Ocramius commented 3 years ago

laminas/laminas-db does not declare itself compatible with PHP 8 yet: https://github.com/laminas/laminas-db/blob/d2d2606f253d41bb2f44c591f5cfedc576dd86ea/composer.json#L32

In order to fix this correctly, we should address #174 first.