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

TranslationWalker CAST fails for a string fieldMapping type on MySQL #1011

Closed
tamabe opened this issue Mar 13, 2014 · 10 comments
Closed

TranslationWalker CAST fails for a string fieldMapping type on MySQL #1011

tamabe opened this issue Mar 13, 2014 · 10 comments

Comments

@tamabe
Copy link

tamabe commented Mar 13, 2014

TreeWalker creates the following query

SELECT c0_.id AS id0, CAST(t1_.content AS VARCHAR(255)) AS name3 FROM countries c0_ LEFT JOIN ext_translations t1_ ON t1_.locale = 'en_EN' AND t1_.field = 'name' AND t1_.object_class = 'Country' AND t1_.foreign_key = c0_.id ORDER BY CAST(t1_.content AS VARCHAR(255)) ASC

But casting of a translated field fails for string type on MySQL with

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 'VARCHAR(255)) AS name3 FROM countries c0_ LEFT JOIN ext_translations t1_ ON t1_.' at line 1

as casting to a VARCHAR type is not possible in MySQL https://dev.mysql.com/doc/refman/5.5/en/cast-functions.html#function_convert

fieldMapping gives:

Array ( [fieldName] => name,
        [type] => string,
        [scale] => 0,
        [length] => 255,
        [unique] => ,
        [nullable] => ,
        [precision] => 0 ,
        [columnName] => name ) 
@0s1r1s
Copy link

0s1r1s commented Mar 18, 2014

Same problem for me.
Since this commit for a universal typecast:
l3pp4rd@30d7c09

@10257
Copy link

10257 commented Mar 18, 2014

Same problem here, pull request #999 seams to cause problem in TranslationWalker with Mysql plateform.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Mar 18, 2014

will need to have a look, thanks for noting on that

@ghost
Copy link

ghost commented Mar 19, 2014

Regarding the documentation of MySQL http://dev.mysql.com/doc/refman/5.6/en/cast-functions.html#function_cast
the type should be CHAR instead of VARCHAR in the line : https://github.com/l3pp4rd/DoctrineExtensions/blob/master/lib/Gedmo/Translatable/Query/TreeWalker/TranslationWalker.php#L322

When I run the request generated from the TreeWalker with CHAR it works fine !

I'm sure it is not a beautiful solution but I replaced the line 322 by :

$substituteField = 'CAST(' . $substituteField . ' AS ' . str_replace("VARCHAR","CHAR",$type->getSQLDeclaration($fieldMapping, $this->platform)) . ')';

And it works fine.

@Venzon
Copy link

Venzon commented Mar 24, 2014

seems that i have related issue
#1024
casting to longtext fails on my mysql server
can we fix this broken merge please

@Venzon
Copy link

Venzon commented Mar 25, 2014

@kr0hmy @Egyptos @0s1r1s @tamabe
need to test new changes
#1025

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Mar 25, 2014

I will also check it when I can, the sad thing we have tests only on sqlite. on 3.0.0 branch there are tests made for 3 types of database. Maybe will need to move parts slowly from 3.0.0 and start by integrating parts, which does not have BC changes.

@ghost
Copy link

ghost commented Mar 25, 2014

It's working fine for me on Mysql. Thanks

@10257
Copy link

10257 commented Mar 25, 2014

Working fine for me too. Thanks!

@Venzon
Copy link

Venzon commented Mar 25, 2014

works for me

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

No branches or pull requests

6 participants