Flush on MariaDB fails to Syntax error #6380

Closed
opened 2026-01-22 15:32:05 +01:00 by admin · 11 comments
Owner

Originally created by @NikoGrano on GitHub (Jan 9, 2020).

Originally assigned to: @lcobucci on GitHub.

Bug Report

Q A
Version 2.7.0
PHP 7.4.1
Database MariaDB 10.4.11
Framework Symfony 4.4

Summary

I am trying to persist entity with to the database. It fails.

Current behaviour

  [PDOException (42000)]                                                                                
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check   
  the manual that corresponds to your MariaDB server version for the right syntax to use near 'index,   
  recorded, type) VALUES (0, '2020-01-09 22:27:32.066694', 'App.Stock.Domai' at line 1 

How to reproduce

I have Entity extending abstract entity.
When trying to do following, I will get mentioned failure.

$this->em = EntityManagerInterface::class;
$entity = new Entity(...)

$this->em->persist($entity);
$this->em->flush();

I do not expect you to fix this, if this is bug with my code, but as I have this code publicly available, it might help you. Repository is available here

Expected behaviour

Entity gets persisted.

Next Steps in debugging

I will be trying to run this under MariaDB 10.3. However, it should not affect this at all and do not wait me while I do it.
Same error under 10.3.21

Originally created by @NikoGrano on GitHub (Jan 9, 2020). Originally assigned to: @lcobucci on GitHub. ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | Version | 2.7.0 | PHP | 7.4.1 | Database | MariaDB 10.4.11 | Framework | Symfony 4.4 #### Summary I am trying to persist entity with to the database. It fails. #### Current behaviour ``` [PDOException (42000)] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'index, recorded, type) VALUES (0, '2020-01-09 22:27:32.066694', 'App.Stock.Domai' at line 1 ``` #### How to reproduce I have [Entity](https://github.com/HouseHold/HouseHold/tree/dev/src/Stock/Domain) extending [abstract entity](https://github.com/HouseHold/HouseHold/blob/dev/src/Core/Infrastructure/Share/Event/Repository/ORM/AbstractEventStoreEntity.php). When trying to do following, I will get mentioned failure. ```php $this->em = EntityManagerInterface::class; $entity = new Entity(...) $this->em->persist($entity); $this->em->flush(); ``` I do not expect you to fix this, if this is bug with my code, but as I have this code publicly available, it might help you. Repository is available [here](https://github.com/HouseHold/HouseHold) #### Expected behaviour Entity gets persisted. ### Next Steps in debugging ~I will be trying to run this under MariaDB 10.3. However, it should not affect this at all and do not wait me while I do it.~ Same error under 10.3.21
admin added the BugInvalid labels 2026-01-22 15:32:05 +01:00
admin closed this issue 2026-01-22 15:32:05 +01:00
Author
Owner

@NikoGrano commented on GitHub (Jan 9, 2020):

Ref https://github.com/doctrine/dbal/issues/3815

@NikoGrano commented on GitHub (Jan 9, 2020): Ref https://github.com/doctrine/dbal/issues/3815
Author
Owner

@NikoGrano commented on GitHub (Jan 10, 2020):

I tried to debug this following way:

  1. I removed everything else from entity except index and ran bin/console doctrine:schema:update --force. This worked fine as it should, but when I try again persist on that Entity, I got this error
In PDOStatement.php line 121:
                                                                                                        
  [PDOException (42000)]                                                                                
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check   
  the manual that corresponds to your MariaDB server version for the right syntax to use near 'index)   
  VALUES (0)' at line 1

But, when I try run query via DB CLI, it works fine.

Query working directly on DB.

INSERT INTO `stock_inventory_events` (`index`) VALUES ('1')

This seems like, either of ORM or DBAL is generating faulty query for the database.

@NikoGrano commented on GitHub (Jan 10, 2020): I tried to debug this following way: 1. I removed everything else from [entity](https://github.com/HouseHold/HouseHold/blob/dev/src/Core/Infrastructure/Share/Event/Repository/ORM/AbstractEventStoreEntity.php) except index and ran `bin/console doctrine:schema:update --force`. This worked fine as it should, but when I try again persist on that Entity, I got this error ``` In PDOStatement.php line 121: [PDOException (42000)] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'index) VALUES (0)' at line 1 ``` But, when I try run query via DB CLI, it works fine. Query working directly on DB. ```sql INSERT INTO `stock_inventory_events` (`index`) VALUES ('1') ``` This seems like, either of ORM or DBAL is generating faulty query for the database.
Author
Owner

@nikophil commented on GitHub (Jan 10, 2020):

i guess index is a reserved word in sql, you have to explicitely escape it in your column declaration in the entity

/** @ORM\Column(name="`index`") */
$index

(notice the wrapping backticks)

@nikophil commented on GitHub (Jan 10, 2020): i guess `index` is a reserved word in sql, you have to explicitely escape it in your column declaration in the entity ```php /** @ORM\Column(name="`index`") */ $index ``` (notice the wrapping backticks)
Author
Owner

@NikoGrano commented on GitHub (Jan 10, 2020):

Yes, it works now. Thank you. (Closing due this is not anymore issue, but needs discussing.)

Shouldn't this be automatically detected by ORM? Like, if field name would map into reserved word it would add backticks automatically?

@NikoGrano commented on GitHub (Jan 10, 2020): Yes, it works now. Thank you. (Closing due this is not anymore issue, but needs discussing.) Shouldn't this be automatically detected by ORM? Like, if field name would map into reserved word it would add backticks automatically?
Author
Owner

@nikophil commented on GitHub (Jan 10, 2020):

i don't know why this is not directly handled, maybe a doctrine expert could answer that, i'm curious as well, i had this problem at some time which is tricky to detect
@Ocramius @alcaeus

@nikophil commented on GitHub (Jan 10, 2020): i don't know why this is not directly handled, maybe a doctrine expert could answer that, i'm curious as well, i had this problem at some time which is tricky to detect @Ocramius @alcaeus
Author
Owner

@NikoGrano commented on GitHub (Jan 12, 2020):

Reopening to gain attention.

@NikoGrano commented on GitHub (Jan 12, 2020): Reopening to gain attention.
Author
Owner

@alcaeus commented on GitHub (Jan 13, 2020):

Sorry, don't use ORM or MariaDB, so I have no clue. There's also no need to go close/reopen issues - just because it's at the top of my notification list doesn't mean I'll get to it any faster.

@alcaeus commented on GitHub (Jan 13, 2020): Sorry, don't use ORM or MariaDB, so I have no clue. There's also no need to go close/reopen issues - just because it's at the top of my notification list doesn't mean I'll get to it any faster.
Author
Owner

@NikoGrano commented on GitHub (Jan 13, 2020):

Related to most of databases anyways, tought it will go past, if you see this as closed. Will be waiting for you reply.

@NikoGrano commented on GitHub (Jan 13, 2020): Related to most of databases anyways, tought it will go past, if you see this as closed. Will be waiting for you reply.
Author
Owner

@lcobucci commented on GitHub (Jan 13, 2020):

This is a documented behaviour of v2.x: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/basic-mapping.html#quoting-reserved-words

Things are changing for new versions but this is what we have for now.

@lcobucci commented on GitHub (Jan 13, 2020): This is a documented behaviour of v2.x: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/basic-mapping.html#quoting-reserved-words Things are changing for new versions but this is what we have for now.
Author
Owner

@NikoGrano commented on GitHub (Jan 13, 2020):

@lcobucci Can you answer to this? So is this going to be fixed in future to be working automatically or can I create PR for it and fix it.

i don't know why this is not directly handled, maybe a doctrine expert could answer that, i'm curious as well, i had this problem at some time which is tricky to detect
@Ocramius @alcaeus

@NikoGrano commented on GitHub (Jan 13, 2020): @lcobucci Can you answer to this? So is this going to be fixed in future to be working automatically or can I create PR for it and fix it. > i don't know why this is not directly handled, maybe a doctrine expert could answer that, i'm curious as well, i had this problem at some time which is tricky to detect > @Ocramius @alcaeus
Author
Owner

@lcobucci commented on GitHub (Jan 13, 2020):

What I meant with "things are changing for new versions" is that it's already implemented for v3.0-dev and won't be ported back on v2.x unless we manage to have BC-compatible implementation.

Not having automatic quoting isn't seen as a bug but a missing feature, so such implementation should come in a minor release (and not a patch). Feel free to send a PR 😁

@lcobucci commented on GitHub (Jan 13, 2020): What I meant with "things are changing for new versions" is that it's already implemented for v3.0-dev and won't be ported back on v2.x unless we manage to have BC-compatible implementation. Not having automatic quoting isn't seen as a bug but a missing feature, so such implementation should come in a minor release (and not a patch). Feel free to send a PR 😁
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6380