Reputation: 19
I have a table called Entity. It has a field with the namespace of an entity like this:
Old\App\Email
which I'm trying to rename to New\App\Email
.
I got this working SQL query to rename all rows in the MySQL Console. It needs 4 \
in the condition and 2 \
in REPLACE
:
UPDATE Entity SET entity_name = REPLACE(entity_name, 'Old\\App', 'New\\App') WHERE entity_name LIKE 'Old\\\\App%';
It was already hard to get it working correctly escaped, but now when trying to add it to a Doctrine Migration.
$this->addSql('update log set entity_name = replace(entity_name, \'Old\', \'New\') where entity_name like \'Old\App%\'');
It's executed without making changes. I assume it is not escaping properly. I have trying all combination of escaping from on to 4 backslashes. And even tried the different combination of quote escaping hoping that this would yield the expected escaping but no row is being changed at all:
$this->addSql('update Entity set entity_name = replace(entity_name, \'Old\', \'New1\') where entity_name like \'Old\App%\'');
$this->addSql('update Entity set entity_name = replace(entity_name, \'Old\', \'New2\') where entity_name like \'Old\\App%\'');
$this->addSql('update Entity set entity_name = replace(entity_name, \'Old\', \'New3\') where entity_name like \'Old\\\App%\'');
$this->addSql('update Entity set entity_name = replace(entity_name, \'Old\', \'New4\') where entity_name like \'Old\\\\App%\'');
$this->addSql('update Entity set entity_name = replace(entity_name, "Old", "New5") where entity_name like "Old\App%"');
$this->addSql('update Entity set entity_name = replace(entity_name, "Old", "New6") where entity_name like "Old\\App%"');
$this->addSql('update Entity set entity_name = replace(entity_name, "Old", "New7") where entity_name like "Old\\\App%"');
$this->addSql('update Entity set entity_name = replace(entity_name, "Old", "New8") where entity_name like "Old\\\\App%"');
Any help from fellow programmers would be appreciated.
Doctrine version is 2.7
Upvotes: 0
Views: 979
Reputation: 19
It's not pretty but it takes 7 or 8 \
in the where clause and 4 in the replace function outside wrapped in double quotes and the search strings with single quotes:
$this->addSql("update Entity set entity_name = replace(entity_name, 'Old\\\\App', 'New\\\\App') where entity_name like 'Old\\\\\\\\App%'");
Upvotes: 1