Typo3 LTS9学说:如何使用mysql @ -Variables?

问题描述 投票:0回答:1

用mysql @ -variables执行以下typo3 SELECT的正确方法是什么?

$dbConnection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($extensionTable);
$queryBuilder = $dbConnection->createQueryBuilder();

$query = $queryBuilder
->select('extensionTable.*',
'@dist:=ACOS(ROUND(SIN(RADIANS(geo.coord_lat)) * SIN(RADIANS(52.5234743092278))
   + COS(RADIANS(geo.coord_lat)) * COS(RADIANS(52.5234743092278))
   * COS(RADIANS(geo.coord_lon)      - RADIANS(13.4122033308763)),10)) * 6380 AS distance',
'@distgrp:=CASE WHEN @dist <10 THEN 1 WHEN @dist<25 THEN 2 ELSE truncate(((@dist-25)/25)+3, 0) END AS dist_group')
->from('extensionTable  LEFT JOIN geoTable AS geo ON geo.zip=extensionTable.zip')
->where('pid IN (15,16)');

这不起作用,typo3在@dist var之前插入了'。 不良结果为:

SELECT 'extensionTable'.*, '@dist:=... ' AS 'distance';

错误:执行时发生异常...您的SQL语法有错误;

相关主题(解决方案不适用于typo3-doctrine-implementation):How to use mysql variables in doctrine

我希望有人可以帮助我。 :-)(或者我必须使用直接php mysqli()查询。)

mysql variables select doctrine typo3
1个回答
0
投票

您可以防止使用selectLiteral逃逸。

$queryBuilder
  ->select(...)
  ->addSelectLiteral('@dist:=COS(RADIANS(90))')
© www.soinside.com 2019 - 2024. All rights reserved.