PropelBundle icon indicating copy to clipboard operation
PropelBundle copied to clipboard

Dumping fixtures fails when the table is called 'match'

Open istaveren opened this issue 13 years ago • 5 comments

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?

istaveren avatar Mar 11 '12 20:03 istaveren

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().

willdurand avatar Mar 11 '12 21:03 willdurand

I committed it in 'my' fork https://github.com/istaveren/PropelBundle/commit/bc5c365d8924958ae2f138f6bf323be96db3a3d Still to do, update unit test.

istaveren avatar Mar 14 '12 07:03 istaveren

@istaveren seems good, can you write some unit tests now?

willdurand avatar Apr 23 '12 13:04 willdurand

Ok, I will add the tests.

istaveren avatar Apr 24 '12 06:04 istaveren

Awesome! Thank you

willdurand avatar Apr 24 '12 06:04 willdurand