DDC-3443: Doctrine Custom Type always converted as string, when not wanted #4245

Closed
opened 2026-01-22 14:38:03 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 9, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user Alsatian:

Hello,

trying to define a Custom Type in my Symfony2 application, I can't find how to write the convertToDatabaseValue function for working with native points in PostgreSQL (!= PostGIS extension).

Wished syntax :
'SELECT [...] FROM Addresses t0 WHERE t0.location = ?' with params ['(2.352,48.857)']

I use this convertToDatabaseValue function :

    public function convertToDatabaseValue($value, AbstractPlatform $platform) {
        if (!$value) return;

        return "'(".$value->getX().','.$value->getY().")'";
    }

DQL, creates this SQL query :

'SELECT [...] FROM Addresses t0 WHERE t0.location = ?' with params ["'(2.352,48.857)'"]

-> Double quotes are automatically added, the parameter is interpreted as string.

I don't know if it is a bug or if I am doing anything wrong ?

Thank you.

Originally created by @doctrinebot on GitHub (Dec 9, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user Alsatian: Hello, trying to define a Custom Type in my Symfony2 application, I can't find how to write the convertToDatabaseValue function for working with native points in PostgreSQL (!= PostGIS extension). Wished syntax : `'SELECT [...] FROM Addresses t0 WHERE t0.location = ?' with params ['(2.352,48.857)']` I use this convertToDatabaseValue function : ``` public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (!$value) return; return "'(".$value->getX().','.$value->getY().")'"; } ``` DQL, creates this SQL query : `'SELECT [...] FROM Addresses t0 WHERE t0.location = ?' with params ["'(2.352,48.857)'"]` -> Double quotes are automatically added, the parameter is interpreted as string. I don't know if it is a bug or if I am doing anything wrong ? Thank you.
admin added the Bug label 2026-01-22 14:38:03 +01:00
admin closed this issue 2026-01-22 14:38:03 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 10, 2014):

Comment created by @ocramius:

Please check http://doctrine-orm.readthedocs.org/en/latest/cookbook/advanced-field-value-conversion-using-custom-mapping-types.html and compare it with your codebase.

@doctrinebot commented on GitHub (Dec 10, 2014): Comment created by @ocramius: Please check http://doctrine-orm.readthedocs.org/en/latest/cookbook/advanced-field-value-conversion-using-custom-mapping-types.html and compare it with your codebase.
Author
Owner

@doctrinebot commented on GitHub (Dec 10, 2014):

Comment created by Alsatian:

As I understand, the function convertToDatabaseValue build the format from the value into "with params (############)"

But it does always put double quotes so that my value becomes a string.

convertToDatabaseValueSQL build the format before, at the placeholder and here, I don't want to change anything.

I tried also

getBindingType(){
return \PDO::PARAM_NULL;
}

Hoping that were going to remove the quotes, but it doesn't.

Any suggestion ?

@doctrinebot commented on GitHub (Dec 10, 2014): Comment created by Alsatian: As I understand, the function convertToDatabaseValue build the format from the value into "with params (############)" But it does always put double quotes so that my value becomes a string. convertToDatabaseValueSQL build the format before, at the placeholder and here, I don't want to change anything. I tried also getBindingType(){ return \PDO::PARAM_NULL; } Hoping that were going to remove the quotes, but it doesn't. Any suggestion ?
Author
Owner

@doctrinebot commented on GitHub (Dec 12, 2014):

Comment created by @deeky666:

Not sure but I think the double quotes are just added for the debug output. What would be the native SQL that you expect?
I think you will have to define \PDO::PARAM_STRING as binding type and remove the single quotes around your database value:

public function convertToDatabaseValue($value, AbstractPlatform $platform) {
    if (!$value) return;

    return "(".$value->getX().','.$value->getY().")";
}
@doctrinebot commented on GitHub (Dec 12, 2014): Comment created by @deeky666: Not sure but I think the double quotes are just added for the debug output. What would be the native SQL that you expect? I think you will have to define \PDO::PARAM_STRING as binding type and remove the single quotes around your database value: ``` public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (!$value) return; return "(".$value->getX().','.$value->getY().")"; } ```
Author
Owner

@doctrinebot commented on GitHub (Dec 19, 2014):

Comment created by Alsatian:

OK it is working without parenthesis ...

Thank you for your help .

@doctrinebot commented on GitHub (Dec 19, 2014): Comment created by Alsatian: OK it is working without parenthesis ... Thank you for your help .
Author
Owner

@doctrinebot commented on GitHub (Dec 19, 2014):

Comment created by Alsatian:

There were no problem, wrong syntax in my custom Typ ...

@doctrinebot commented on GitHub (Dec 19, 2014): Comment created by Alsatian: There were no problem, wrong syntax in my custom Typ ...
Author
Owner

@doctrinebot commented on GitHub (Dec 19, 2014):

Issue was closed with resolution "Won't Fix"

@doctrinebot commented on GitHub (Dec 19, 2014): Issue was closed with resolution "Won't Fix"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4245