Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
How to make an regexp request with TYPO3 queryBuilder

I currently have a big list of entries in my TYPO3 Ext that causes the Site to have pretty poor loading times, so i want to split up the Entry list alphabetically. For that I'm using the queryBuilder to select only those entries, that start either with an a, b, c and so on. But im stuck now when it comes to numbers and special chars. I found this: MySQL - If It Starts With A Number Or Special Character which is exactly what I need. But I have no clue how to make an REGEXP in the queryBuilder. Can someone help?

TYPO3 version is 10.4.6

Thanks in advance

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I would suggest to use LIKE to find strings starting with a given character.

Using LIKE

$firstCharacter = 'A';

$q = GeneralUtility::makeInstance(ConnectionPool::class)
       ->getQueryBuilderForTable('mytable');
$q->select('field')
  ->from('mytable')
  ->where(
    $q->expr()->orX(
      $q->expr()->like(
        'field',
        $q->quote(strtolower($firstCharacter) . '%')
      ),
      $q->expr()->like(
        'field',
        $q->quote(strtoupper($firstCharacter) . '%')
      );

upper/lower case could be left out of course if the DBMS is case insensitive.

Using REGEXP

@eliashaeussler gave a good example for that.

While LIKE is supported by Doctrine dbal, REGEXP is not. You would lose cross-DBMS compatiblity. This is probably fine if you target a specific site but should not be used in public extensions of course.

over 4 years ago · Santiago Trujillo Relatório

0

Maybe something like this works for you:

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
$result = $queryBuilder->select('*')
    ->from($tableName)
    ->where(
        $queryBuilder->expr()->comparison(
            $queryBuilder->quoteIdentifier($fieldName),
            'NOT REGEXP',
            $queryBuilder->createNamedParameter('^[[:alpha:]]')
        )
    )
    ->execute()
    ->fetchAll();

This creates a query like this (assuming $tableName = 'foo' and $fieldName = 'baz'):

SELECT `foo`.*
FROM `foo`
WHERE `foo`.`baz` NOT REGEXP '^[[:alpha:]]'

Reference: https://github.com/TYPO3/TYPO3.CMS/blob/10.4/typo3/sysext/core/Classes/Database/Query/Expression/ExpressionBuilder.php#L97-L100

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda