Skip to content

unexpected syntax error #175

@staabm

Description

@staabm

refs composer/packagist#1232

    public function getDependents(string $name, int $offset = 0, int $limit = 15, string $orderBy = 'name', ?int $type = null)
    {
        $orderByField = 'p.name ASC';
        $join = '';
        if ($orderBy === 'downloads') {
            $orderByField = 'd.total DESC';
            $join = 'LEFT JOIN download d ON d.id = p.id AND d.type = '.Download::TYPE_PACKAGE;
        } else {
            $orderBy = 'name';
        }

        $args = ['name' => $name];
        $typeFilter = '';
        if (null !== $type) {
            $typeFilter = ' AND type = :type';
            $args['type'] = $type;
        }

        $sql = 'SELECT p.id, p.name, p.description, p.language, p.abandoned, p.replacementPackage
            FROM package p INNER JOIN (
                SELECT DISTINCT package_id FROM dependent WHERE packageName = :name'.$typeFilter.'
            ) x ON x.package_id = p.id '.$join.' ORDER BY '.$orderByField.' LIMIT '.((int)$limit).' OFFSET '.((int)$offset);

        return $this->getEntityManager()->getConnection()->fetchAllAssociative($sql, $args);
    }

leads to

Query error: You have an error in your SQL syntax; check the manual    
         that corresponds to your MySQL/MariaDB server version for the right    
         syntax to use near 'LIMIT 0' at line 4                                 
                                                                                
         Simulated query: SELECT p.id, p.name, p.description, p.language,       
         p.abandoned, p.replacementPackage                                      
                     FROM package p INNER JOIN (                                
                         SELECT DISTINCT package_id FROM dependent WHERE        
         packageName = '1' AND type = '1'                                       
                     ) x ON x.package_id = p.id LEFT JOIN download d ON d.id =  
         p.id AND d.type = 1 ORDER BY p.name ASC LIMIT 1 OFFSET 1 LIMIT 0       
         (1064).     

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions