Skip to content

Commit

Permalink
Fix MariaDB binary type
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Mar 5, 2021
1 parent a32f3d9 commit efea562
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Engine/DatabaseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ public function __construct(bool $useProxy)
*/
abstract protected function executeQuery(string $query, array $parameters) : array;

/**
* Returns the syntax required to perform a ST_GeomFromText(), together with placeholders.
*
* This method may be overridden if necessary.
*/
protected function getGeomFromTextSyntax(): string
{
return 'ST_GeomFromText(?, ?)';
}

/**
* Returns the syntax required to perform a ST_GeomFromWKB(), together with placeholders.
*
* This method may be overridden if necessary.
*/
protected function getGeomFromWKBSyntax(): string
{
return 'ST_GeomFromWKB(?, ?)';
}

/**
* Builds and executes a SQL query for a GIS function.
*
Expand All @@ -61,10 +81,10 @@ private function query(string $function, array $parameters, bool $returnsGeometr
foreach ($parameters as $parameter) {
if ($parameter instanceof Geometry) {
if ($parameter->isEmpty()) {
$queryParameters[] = 'ST_GeomFromText(?, ?)';
$queryParameters[] = $this->getGeomFromTextSyntax();
$queryValues[] = new GeometryParameter($parameter, false);
} else {
$queryParameters[] = 'ST_GeomFromWKB(?, ?)';
$queryParameters[] = $this->getGeomFromWKBSyntax();
$queryValues[] = new GeometryParameter($parameter, true);
}
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/Engine/PDOEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,13 @@ protected function executeQuery(string $query, array $parameters) : array

return $result;
}

protected function getGeomFromWKBSyntax(): string
{
if ($this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'mysql') {
return 'ST_GeomFromWKB(_binary ?, ?)';
}

return parent::getGeomFromWKBSyntax();
}
}

0 comments on commit efea562

Please sign in to comment.