Trying to do the same as here, with Postgres:
http://codeutopia.net/blog/2011/02/19/using-spatial-data-in-doctrine-2/
I have a problem with the "convertToDatabaseValue" function (see here : http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#custom-mapping-types)
My Custom Type :
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class PointType extends Type
{
const POINT = 'point';
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'POINT';
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return new Point($value[0],$value[1]);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return "'".$value->getLongitude().','.$value->getLatitude()."'";
}
public function getName()
{
return self::POINT;
}
}
Manualy, I can insert this Point with following SQL :
INSERT INTO points (pointtype,name,score) VALUES ('2.43145,42.84214',"My Place",3241)
But doctrine DBAL, creates following code :
'INSERT INTO points (pointtype,name,score) VALUES (?,?,?)' with params ["'2.43145,42.84214'","My Place",3241]
-> My Point is interpreted as a string ...
Can I avoid that ?
CAUTION: I don't want to use PostGIS, juste native Points from PostgreSQL
It is because you need to return just string and Doctrine will automatically wrap it with quotes. Try this code:
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return $value->getLongitude().','.$value->getLatitude();
}
It will generate you next SQL query:
INSERT INTO points (pointtype,name,score) VALUES ("2.43145,42.84214","My Place",3241)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With