Dumping fixtures fails when the table is called 'match'
How to reproduce
Create a table called match.
Dump the data with app/console propel:fixtures:dump
It fails with the following error.
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match' at line 1
This is caused because match is some reserved word by mysql.
Proposed fix:
--- a/DataFixtures/Dumper/AbstractDataDumper.php
+++ b/DataFixtures/Dumper/AbstractDataDumper.php
@@ -104,11 +104,11 @@ abstract class AbstractDataDumper extends AbstractDataHandler implements DataDum
} else {
$in = array();
foreach ($tableMap->getColumns() as $column) {
- $in[] = strtolower($column->getName());
+ $in[] = "`".strtolower($column->getName())."`";
}
$stmt = $this
->con
- ->query(sprintf('SELECT %s FROM %s', implode(',', $in), constant(constant($tableName.'::PEER').'::TABLE_NAME')));
+ ->query(sprintf('SELECT %s FROM `%s`', implode(', ', $in), constant(constant($tableName.'::PEER').'::TABLE_NAME')));
$resultsSets[] = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
Please note, the second one fixes it. But I think it is a good idea to do the same for the column names ;-).
Should I forked it and fix it and adding a unit test for it?
It's a little more complicated than that.
Quoting depends on the platform in use, so you need to rely on the quote() or quoteIdentifier() methods from the PropelPlatformInterface#quote().
I committed it in 'my' fork https://github.com/istaveren/PropelBundle/commit/bc5c365d8924958ae2f138f6bf323be96db3a3d Still to do, update unit test.
@istaveren seems good, can you write some unit tests now?
Ok, I will add the tests.
Awesome! Thank you