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

fix DELETE sql query #197

Merged
merged 2 commits into from Sep 2, 2015
Merged

fix DELETE sql query #197

merged 2 commits into from Sep 2, 2015

Conversation

DenysMedvid
Copy link
Contributor

Hello.

Fix for sql error if table name is "order"

  An exception occurred while executing 'DELETE FROM order':                                                                                                                                                         
  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 'order' at line 1  

@kingcrunch
Copy link

This only works for MySQL

@DenysMedvid
Copy link
Contributor Author

Ok, thanks you for quick response.

@kingcrunch
Copy link

Hi @Bucefal

Me again 😄 There should be something like $connection->quoteIdentifier(), which should (you may guess) quote the identifier according the current connection. I cannot proof the correct method names right now though. I should've written this in the first place, but missed that 😶

@DenysMedvid DenysMedvid reopened this Jun 26, 2015
@DenysMedvid
Copy link
Contributor Author

Fix it with quoteIdentifier

guilhermeblanco added a commit that referenced this pull request Sep 2, 2015
@guilhermeblanco guilhermeblanco merged commit a02f0e7 into doctrine:master Sep 2, 2015
@stof
Copy link
Member

stof commented Sep 2, 2015

this change is weird. the table names are already retrieved using getQuotedTableName.

I think the issue is that your ORM mapping was not telling the ORM to use a quoted identifier.

Forcing quoting here causes issues in 2 cases:

  • if the mapping already configures quoting properly, you are not quoting it twice
  • if the identifier is not configured to be quoted, you are now forcing to be quoted, and this changes the behavior of the query, potentially making it use a different table than the one used by the ORM (which would not quote the identifier in this case): http://www.alberton.info/dbms_identifiers_and_case_sensitivity.html#.Veco4bOaClN

@DenysMedvid
Copy link
Contributor Author

I think, better solution is left all as was. Anyway it is a very bad idea use reserved keywords in table names. I revert my "force quote".

@maryo
Copy link

maryo commented Jan 15, 2016

It should also be reverted here since it is a bug. It causes double-quoting. If you want your table to be escaped, use backtics in table name definition like @ORM\Table(name="order"). And in this case, your change quotes it again so it tries to purge using DELETE FROM ""order"" (Postgres example, postgres uses double quotes, not backtics).

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

Successfully merging this pull request may close these issues.

None yet

5 participants