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

Dumping fixtures fails when the table is called 'match' #125

Closed
istaveren opened this issue Mar 11, 2012 · 5 comments
Closed

Dumping fixtures fails when the table is called 'match' #125

istaveren opened this issue Mar 11, 2012 · 5 comments

Comments

@istaveren
Copy link

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?

@willdurand
Copy link

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

@istaveren
Copy link
Author

I committed it in 'my' fork istaveren@bc5c365
Still to do, update unit test.

@willdurand
Copy link

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

@istaveren
Copy link
Author

Ok, I will add the tests.

@willdurand
Copy link

Awesome! Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants