Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle not working on Postgres #173

Open
alexander-schranz opened this issue Aug 8, 2024 · 1 comment
Open

Bundle not working on Postgres #173

alexander-schranz opened this issue Aug 8, 2024 · 1 comment

Comments

@alexander-schranz
Copy link
Member

alexander-schranz commented Aug 8, 2024

Q A
Bug? yes
New Feature? no
Community Bundle Version 2.0@dev: 17e2867
Sulu Version -
Browser Version -

Actual Behavior

The current bundle version is not working on postgres as the SQL errors with:

grafik

Expected Behavior

It should not error.

Steps to Reproduce

What are the steps to reproduce this bug? Please add code examples,
screenshots or links to GitHub repositories that reproduce the problem.

Possible Solutions

<?php

namespace App\Doctrine\Extension\Postgresql;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

class SimilarTo extends FunctionNode
{
    public $value = null;

    public $regexp = null;

    public function parse(Parser $parser): void
    {
        $parser->match(TokenType::T_IDENTIFIER);
        $parser->match(TokenType::T_OPEN_PARENTHESIS);
        $this->value = $parser->StringPrimary();
        $parser->match(TokenType::T_COMMA);
        $this->regexp = $parser->StringExpression();
        $parser->match(TokenType::T_CLOSE_PARENTHESIS);
    }

    public function getSql(SqlWalker $sqlWalker): string
    {
        return '(' . $this->value->dispatch($sqlWalker) . ' SIMILAR TO ' . $this->regexp->dispatch($sqlWalker) . ')';
    }
}
doctrine:
    orm:
        dql:
            string_functions: App\Doctrine\Extension\Postgresql\SimilarTo 
@loalf
Copy link

loalf commented Sep 20, 2024

I can confirm this solution actually works on Postgres but the configuration needs to be amended slightly for Symfony 7.

doctrine:
    orm:
        dql:
            string_functions: 
                REGEXP: App\Doctrine\Extension\Postgresql\SimilarTo 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants