Skip to content

MySQL 8.0 support: prefix AsBinary and GeomFromText with "ST_" #196

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/CrEOF/Spatial/DBAL/Platform/MySql.php
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@

use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
use CrEOF\Spatial\PHP\Types\Geography\GeographyInterface;
use CrEOF\Spatial\DBAL\Types\GeographyType;

/**
* MySql spatial platform
@@ -34,6 +35,22 @@
*/
class MySql extends AbstractPlatform
{
/**
* For Geographic types MySQL follows the WKT specifications and returns (latitude,longitude) while (x,y) / (longitude,latitude) is expected.
*
* Using the following option the preferred axis-order can be indicated.
*
* @var string
*/
const AXIS_ORDER_OPTION = 'axis-order=long-lat';

/**
* Optionally a SRID can be set to be used for Geographic types.
*
* @var int|null
*/
public static $srid;

/**
* Gets the SQL declaration snippet for a field of this type.
*
@@ -58,7 +75,9 @@ public function getSQLDeclaration(array $fieldDeclaration)
*/
public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr)
{
return sprintf('AsBinary(%s)', $sqlExpr);
return $type instanceof GeographyType
? sprintf('ST_AsBinary(%s, "%s")', $sqlExpr, self::AXIS_ORDER_OPTION)
: sprintf('ST_AsBinary(%s)', $sqlExpr);
}

/**
@@ -69,6 +88,9 @@ public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr)
*/
public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr)
{
return sprintf('GeomFromText(%s)', $sqlExpr);
return $type instanceof GeographyType && is_int(self::$srid)
? sprintf('ST_GeomFromText(%s, %d)', $sqlExpr, self::$srid)
: sprintf('ST_GeomFromText(%s)', $sqlExpr);
}

}
37 changes: 37 additions & 0 deletions lib/CrEOF/Spatial/DBAL/Types/Geography/MultiPolygonType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright (C) 2015 Derek J. Lambert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace CrEOF\Spatial\DBAL\Types\Geography;

use CrEOF\Spatial\DBAL\Types\GeographyType;

/**
* Doctrine MULTIPOLYGON type
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license http://dlambert.mit-license.org MIT
*/
class MultiPolygonType extends GeographyType
{

}
42 changes: 42 additions & 0 deletions lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STSRID.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* Copyright (C) 2013 luca capra
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace CrEOF\Spatial\ORM\Query\AST\Functions\MySql;

use CrEOF\Spatial\ORM\Query\AST\Functions\AbstractSpatialDQLFunction;

/**
* ST_SRID DQL function
*
* @author luca capra <luca.capra@create-net.org>
* @license http://dlambert.mit-license.org MIT
*/
class STSRID extends AbstractSpatialDQLFunction {

protected $platforms = array('mysql');
protected $functionName = 'ST_SRID';
protected $minGeomExpr = 1;
protected $maxGeomExpr = 2;

}
37 changes: 37 additions & 0 deletions lib/CrEOF/Spatial/PHP/Types/Geography/MultiPolygon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright (C) 2012 Derek J. Lambert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace CrEOF\Spatial\PHP\Types\Geography;

use CrEOF\Spatial\PHP\Types\AbstractMultiPolygon;

/**
* MultiPolygon object for MULTIPOLYGON geography type
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license http://dlambert.mit-license.org MIT
*/
class MultiPolygon extends AbstractMultiPolygon implements GeographyInterface
{

}