DDC-3319: Get the converted value in convertToDatabaseValueSQL() #4102

Open
opened 2026-01-22 14:35:14 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 23, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user benjamin:

I have a use case where it would be useful to get the value being converted in the convertToDatabaseValueSQL() method, not just in convertToDatabaseValue().

Take the following mapping for a Geometry type:

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        return $value->asBinary();
    }

    public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
    {
        return sprintf('ST_GeomFromWkb(%s, %s)', $sqlExpr, 4326);
    }

In GIS-enabled databases, ST_GeomFromWkb() takes two parameters: the WKB binary representation of the geometry, and an integer representing the SRID (coordinate system) of the geometry, in this example the hardcoded value 4326.

I would be nice to have access to the value being converted in the convertToDatabaseValueSQL() as well, to be able to get the SRID from the geometry object itself, and replace the above code with something like:

    public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform, $value)
    {
        return sprintf('ST_GeomFromWkb(%s, %s)', $sqlExpr, $value->srid());
    }

I don't think there is currently a technical way to do this (please correct me if I'm wrong).

Could we find a BC way to pass the value being converted to the convertToDatabaseValueSQL() method to add support for this use case?

Originally created by @doctrinebot on GitHub (Sep 23, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user benjamin: I have a use case where it would be useful to get the value being converted in the convertToDatabaseValueSQL() method, not just in convertToDatabaseValue(). Take the following mapping for a Geometry type: ``` public function convertToDatabaseValue($value, AbstractPlatform $platform) { return $value->asBinary(); } public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) { return sprintf('ST_GeomFromWkb(%s, %s)', $sqlExpr, 4326); } ``` In GIS-enabled databases, ST_GeomFromWkb() takes two parameters: the WKB binary representation of the geometry, and an integer representing the SRID (coordinate system) of the geometry, in this example the hardcoded value 4326. I would be nice to have access to the value being converted in the convertToDatabaseValueSQL() as well, to be able to get the SRID from the geometry object itself, and replace the above code with something like: ``` public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform, $value) { return sprintf('ST_GeomFromWkb(%s, %s)', $sqlExpr, $value->srid()); } ``` I don't think there is currently a technical way to do this (please correct me if I'm wrong). Could we find a BC way to pass the value being converted to the convertToDatabaseValueSQL() method to add support for this use case?
admin added the Bug label 2026-01-22 14:35:14 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 25, 2015):

Comment created by nasumilu:

The use case which you described above would be a great addition to the convertToDatabaseValueSQL()* or in the convertToDatabaseValue() be able to return an array of values which could be used in the *convertToDatabaseValueSQL().

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        return array('geometry' => $value->asBinary(), 'srid'=>$value->getSRID());
    }

    public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
    {
        return sprintf('ST_GeomFromWkb(%s, %s)', ':geometry', ':srid');
    }
@doctrinebot commented on GitHub (Jan 25, 2015): Comment created by nasumilu: The use case which you described above would be a great addition to the **convertToDatabaseValueSQL()\* or in the _convertToDatabaseValue()_ be able to return an array of values which could be used in the *convertToDatabaseValueSQL()**. ``` public function convertToDatabaseValue($value, AbstractPlatform $platform) { return array('geometry' => $value->asBinary(), 'srid'=>$value->getSRID()); } public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) { return sprintf('ST_GeomFromWkb(%s, %s)', ':geometry', ':srid'); } ```
Author
Owner

@doctrinebot commented on GitHub (Jan 25, 2015):

Comment created by benjamin:

[~nasumilu] It's an interesting idea, it would work as well, although I think it might be much more complicated to implement!

@doctrinebot commented on GitHub (Jan 25, 2015): Comment created by benjamin: [~nasumilu] It's an interesting idea, it would work as well, although I think it might be much more complicated to implement!
Author
Owner

@doctrinebot commented on GitHub (Feb 1, 2015):

Comment created by agopaul:

It there a workaround for this? I'm probably going to use a native query.

My use case is pretty common among Postgres full-text users: I need to insert a record
using the ts_vector() function with both parameters, eg: ts_vector('english', 'This is a test'),
and both parameters has to be passed on record creation.

@doctrinebot commented on GitHub (Feb 1, 2015): Comment created by agopaul: It there a workaround for this? I'm probably going to use a native query. My use case is pretty common among Postgres full-text users: I need to insert a record using the ts_vector() function with both parameters, eg: ts_vector('english', 'This is a test'), and both parameters has to be passed on record creation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4102