omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
251 stars 113 forks source link

With doctrine/orm 3.1: Error: Expected Doctrine\ORM\Query\TokenType::T_FROM, got '.' #335

Open knallcharge opened 3 months ago

knallcharge commented 3 months ago

Hi,

I tried updating my project to use doctrine/orm 3.1 today (from 2) and now I'm getting the following error:

"[Syntax Error] line 0, col 20: Error: Expected Doctrine\ORM\Query\TokenType::T_FROM, got '.'"

The datatable I'm using is pretty straightforward, this is my code:

$dataTable = $dataTableFactory->create()
                              ->add('id', NumberColumn::class)
                              ->add('created', DateTimeColumn::class, ['format' => 'd. M Y H:i:s', 'searchable' => false])
                              ->add('fileName', TextColumn::class)
                              ->add('filePath', TextColumn::class, ['visible' => false])
                              ->add('uploader', TextColumn::class, ['field' => 'uploader.loginName'])
                              ->add('mimeType', TextColumn::class)
                              ->add(
                                  'fileSize',
                                  NumberColumn::class,
                                  [
                                      'render' => static fn($value, $context) => Binary::bytes($value)->format('/2'),
                                  ]
                              )
                              ->add('Link', TwigColumn::class, ['template' => 'tables/link.html.twig'])
                              ->addOrderBy('id', DataTable::SORT_DESCENDING)
                              ->createAdapter(ORMAdapter::class, [
                                  'entity' => Image::class,
                              ])
                              ->handleRequest($request);

I have tried to remove one column after the other to check whether that makes a difference, but it doesn't.

This is the full stacktrace:

Doctrine\ORM\Query\QueryException: [Syntax Error] line 0, col 20: Error: Expected Doctrine\ORM\Query\TokenType::T_FROM, got '.'


  at (...)\vendor\doctrine\orm\src\Query\QueryException.php:23
  at Doctrine\ORM\Query\QueryException::syntaxError('line 0, col 20: Error: Expected Doctrine\\ORM\\Query\\TokenType::T_FROM, got \'.\'', object(QueryException))
     ((...)\vendor\doctrine\orm\src\Query\Parser.php:396)
  at Doctrine\ORM\Query\Parser->syntaxError('Doctrine\\ORM\\Query\\TokenType::T_FROM')
     ((...)\vendor\doctrine\orm\src\Query\Parser.php:273)
  at Doctrine\ORM\Query\Parser->match(object(TokenType))
     ((...)\vendor\doctrine\orm\src\Query\Parser.php:1180)
  at Doctrine\ORM\Query\Parser->FromClause()
     ((...)\vendor\doctrine\orm\src\Query\Parser.php:769)
  at Doctrine\ORM\Query\Parser->SelectStatement()
     ((...)\vendor\doctrine\orm\src\Query\Parser.php:740)
  at Doctrine\ORM\Query\Parser->QueryLanguage()
     ((...)\vendor\doctrine\orm\src\Query\Parser.php:221)
  at Doctrine\ORM\Query\Parser->getAST()
     ((...)\vendor\doctrine\orm\src\Query\Parser.php:309)
  at Doctrine\ORM\Query\Parser->parse()
     ((...)\vendor\doctrine\orm\src\Query.php:236)
  at Doctrine\ORM\Query->parse()
     ((...)\vendor\doctrine\orm\src\Query.php:183)
  at Doctrine\ORM\Query->getResultSetMapping()
     ((...)\vendor\doctrine\orm\src\AbstractQuery.php:863)
  at Doctrine\ORM\AbstractQuery->toIterable(array(), 1)
     ((...)\vendor\doctrine\orm\src\Query.php:594)
  at Doctrine\ORM\Query->toIterable(array(), 1)
     ((...)\vendor\omines\datatables-bundle\src\Adapter\Doctrine\ORMAdapter.php:191)
  at Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter->getResults(object(Query))
     ((...)\vendor\omines\datatables-bundle\src\Adapter\AbstractAdapter.php:44)
  at Omines\DataTablesBundle\Adapter\AbstractAdapter->getData(object(DataTableState))
     ((...)\vendor\omines\datatables-bundle\src\DataTable.php:317)
  at Omines\DataTablesBundle\DataTable->getResultSet()
     ((...)\vendor\omines\datatables-bundle\src\DataTable.php:276)
  at Omines\DataTablesBundle\DataTable->getResponse()
     ((...)\src\Controller\IndexController.php:88)
  at App\Controller\IndexController->gallery(object(Request), object(DataTableFactory))
     ((...)\vendor\symfony\http-kernel\HttpKernel.php:178)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     ((...)\vendor\symfony\http-kernel\HttpKernel.php:76)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     ((...)\vendor\symfony\http-kernel\Kernel.php:185)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     ((...)\vendor\symfony\runtime\Runner\Symfony\HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     ((...)\vendor\autoload_runtime.php:29)
  at require_once('(...)\\vendor\\autoload_runtime.php')
     ((...)\public\index.php:6)

I tried to downgrade doctrine/orm to 3.0 but the error remains.

curry684 commented 3 months ago

We're using the bundle ourselves on several projects with ORM 3.1 so no clue why your is special.

I would recommend dumping the constructed DQL at or around ((...)\vendor\omines\datatables-bundle\src\Adapter\Doctrine\ORMAdapter.php:191 to further debug what's happening here, it should be pretty clear from there.

knallcharge commented 3 months ago

Thanks for getting back! I found the cause - my bad, forgot to mention that I'm using SQL Server not mySQL and obviously SQL Server is not compatible with the partial-syntax this bundle is creating.

This would be a fix that works with SQL Server: Replace $qb->addSelect('partial ' . $key . '.{' . implode(',', $value) . '}'); in AutomaticQueryBuilder (line 139) with $qb->addSelect($key); but that will of course remove the "partial"-part from the query which may lead to huge resultsets with big tables when you only need some columns ... don't know if that's a good idea, even though it would work for my use case but it may lead to problems for others, what do you think?

curry684 commented 3 months ago

@shades684 mentioned the PARTIAL is technically obsolete as we iterate through cursors where available by default. I think we can just remove it, it's being deprecated in Doctrine as a whole.

https://github.com/doctrine/orm/issues/8471

curry684 commented 3 months ago

It should be noted that the test suite currently does trigger this error when ORM 3.0+ is installed.

Parking this issue until https://github.com/doctrine/orm/issues/8471 is resolved, if they do reintroduce it in 3.2 we might as well keep it in (removing our partial logic is not trivial).

For now consider ORM 3.0/3.1 unsupported.

github-actions[bot] commented 1 month ago

Stale issue message

curry684 commented 1 month ago

Wake. 3.2 didn't get this yet but it's still intended to return in Doctrine.