Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIS extension for Doctrine 2

I want to write a GIS (geospatial data) extension for my Doctrine 2 project.

I know how to write simple custom functions and types. In order to accommodate the MySQL special storage format, I need to use some SQL function (GeomFromWKB() and AsBinary()) when retrieving/storing data.

I can't find a place where I tell Doctrine 2 this. As I see it, the convertToPHPValue() and convertToDatabaseValue() methods are not the right place.

like image 491
Tom Avatar asked Dec 03 '11 13:12

Tom


2 Answers

If you want to call SQL function in doctrine2 you can do it be Expression Func but this will works only with DQL.

Here you have example that will tell you how to use DATE_DIFF function that is not included in doctrine.

$qb = $repository->createQueryBuilder('l');
$qb->expr()->lte(new Doctrine\ORM\Query\Expr\Func('DATE_DIFF',array('lo.start_date', 'CURRENT_DATE()')),'0');
like image 85
Norbert Orzechowicz Avatar answered Oct 06 '22 20:10

Norbert Orzechowicz


What I found out so far: According to the IRC channel, convertToPHPValueSQL() and convertToDatabaseValueSQL() will be part of the next release, and will offer the functionality required. Once that is available, defining a CustomType is fairly straightforward.

like image 44
Tom Avatar answered Oct 06 '22 21:10

Tom