Invalid syntax error when INSERTing into a table that contains a column named "order". I guess this is happening because order is an SQL keyword. Enclosing the column name in backticks (`) should solve the issue
Basically, enclose the column name in backticks, or make it configurable in case you're working with a SQL database that doesn't recognise this character.
Example of broken query:
INSERT INTO `test_table` (order, label) VALUES ('0', 'test_value');
Fixed query:
INSERT INTO `test_table` (`order`, `label`) VALUES ('0', 'test_value');
Last edit: Simone 2015-01-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As you mentioned, I also think we need to make make the column name "quotes" configurable. I hesitate to commit this simple change without it!
Do you have time and interest to complete this change? e.g.:
- make a test class for this
- make a config for the "column name quotes" (default to nothing as is now)
- implement the change
I hope you are able to!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Jeff, this is embarassing but looking at the code I realised there is already a configuration option for this: DatabaseConfig.PROPERTY_ESCAPE_PATTERN
There's also a test case for it: InsertOperationIT.testExecuteWithEscapedNames()
I suppose we can close this ticket :)
Thank you
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Do you have tests that show the issue and code changes that fix it?
Part of the test class:
The dataset contains entries for a table that has a column named "order". Changing the column to "timestamp" in our database fixed the issue.
Code for TestConnectionFactory
The following change to org.dbunit.operation.InsertOperation should fix it.
In the method
Change the line
to
Basically, enclose the column name in backticks, or make it configurable in case you're working with a SQL database that doesn't recognise this character.
Example of broken query:
INSERT INTO `test_table` (order, label) VALUES ('0', 'test_value');
Fixed query:
INSERT INTO `test_table` (`order`, `label`) VALUES ('0', 'test_value');
Last edit: Simone 2015-01-07
Thanks for the info.
Which DB are you using?
As you mentioned, I also think we need to make make the column name "quotes" configurable. I hesitate to commit this simple change without it!
Do you have time and interest to complete this change? e.g.:
- make a test class for this
- make a config for the "column name quotes" (default to nothing as is now)
- implement the change
I hope you are able to!
Hi Jeff, this is embarassing but looking at the code I realised there is already a configuration option for this: DatabaseConfig.PROPERTY_ESCAPE_PATTERN
There's also a test case for it: InsertOperationIT.testExecuteWithEscapedNames()
I suppose we can close this ticket :)
Thank you
Haha, embarrassing for two of us!
Feature already exists.