[DBAL-231] Doctrine\DBAL\SQLParserUtils::getPlaceholderPositions() - regex Created: 05/Mar/12  Updated: 19/Jan/13  Resolved: 14/Mar/12

Status: Resolved
Project: Doctrine DBAL
Component/s: None
Affects Version/s: 2.2
Fix Version/s: 2.3.3
Security Level: All

Type: Bug Priority: Major
Reporter: Ivo Mandalski Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None

Fedora-16, Zend Serve CE, PHP 5.3.5


Running the following SQL (note the named parameter ":account_id"):
SELECT count('*') as cnt FROM feed f INNER JOIN orders_accounts oa ON oa.order_id = f.feed_id INNER JOIN users u ON u.id = f.user_id WHERE oa.account_id = :account_id AND f.feed_type='order' ORDER BY f.create_date DESC

ends up in a thrown exception.
This SQL was generated by using the Query Builder

$qb = $this->_em->getConnection()->createQueryBuilder();
$qb->select('count(\'*\') as cnt');//I know this is bad
$qb->from('feed', 'f');
$qb->innerJoin('f', 'orders_accounts', 'oa', 'oa.order_id = f.feed_id');
$qb->innerJoin('f', 'users', 'u', 'u.id = f.user_id');
$qb->where('oa.account_id = :account_id AND f.feed_type=\'order\'');
$qb->setParameter('account_id', $accountId, \PDO::PARAM_INT);

$stmt = $qb->execute();
$res = $stmt->fetchAll(\PDO::FETCH_COLUMN);

string(82) "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'NULL_id' in 'where clause'"
string(3168) "#0 /var/www/cake_to_zf/library/Doctrine/DBAL/Connection.php(628): PDOStatement->execute()
#1 /var/www/cake_to_zf/library/Doctrine/DBAL/Query/QueryBuilder.php(185): Doctrine\DBAL\Connection->executeQuery('SELECT count('*...', Array, Array)
#2 /var/www/cake_to_zf/library/of/doctrine/SqlQueryBuilderPaginatorAdapter.php(69): Doctrine\DBAL\Query\QueryBuilder->execute()
#3 /var/www/cake_to_zf/library/Zend/Paginator.php(1060): of\doctrine\SqlQueryBuilderPaginatorAdapter->count()

Suggested Fix:

Regex on line 64 in preg_match becomes '#([:a-zA-Z0-9_]


Added was an "_" ...


Comment by Benjamin Eberlei [ 14/Mar/12 ]


Comment by Benjamin Eberlei [ 14/Mar/12 ]

Merged in 2.1.x and 2.2 branches.

Comment by Andrew Vit [ 24/Mar/12 ]

I already fixed this in my reworking of the SqlParserUtils last month. See pull request and confirm that this issue was fixed there, together with other parsing problems:


Comment by Benjamin Eberlei [ 19/Jan/13 ]

Fixed in 2.3.3

Generated at Sat Aug 29 13:16:37 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.