Literal SQL expressions with Doctrine

Adds an item that is to be returned in the query result. This should only be used for literal SQL expressions as no quoting/escaping of any kind will be performed on the items.

Example with calculating distance:

/**
 * @var QueryBuilder $queryBuilder
 */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('my_table_name');
$queryBuilder->addSelectLiteral('( 3959 * acos(cos(radians(' . $this->lat . '))' .
            '* cos( radians( ' . $this->dbLatitude . ' ) )' .
            '* cos( radians( ' . $this->dbLongitude . ' )' .
            '- radians(' . $this->long . ') )' .
            '+ sin( radians(' . $this->lat . ') )' .
            '* sin( radians( ' . $this->dbLatitude . ' ) ) ) ) as ' . $asName);

Be the first to comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.