Skip to content

Commit ab3a235

Browse files
Refactor spatial query handling and improve error messages in database adapters
1 parent 158e7c1 commit ab3a235

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/Database/Adapter/MariaDB.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,15 +1355,15 @@ public function deleteDocument(string $collection, string $id): bool
13551355
/**
13561356
* Handle distance spatial queries
13571357
*
1358-
* @param string $spatialAttributeType
13591358
* @param Query $query
13601359
* @param array<string, mixed> $binds
13611360
* @param string $attribute
1361+
* @param string $type
13621362
* @param string $alias
13631363
* @param string $placeholder
13641364
* @return string
13651365
*/
1366-
protected function handleDistanceSpatialQueries(string $spatialAttributeType, Query $query, array &$binds, string $attribute, string $alias, string $placeholder): string
1366+
protected function handleDistanceSpatialQueries(Query $query, array &$binds, string $attribute, string $type, string $alias, string $placeholder): string
13671367
{
13681368
$distanceParams = $query->getValues()[0];
13691369
$wkt = $this->convertArrayToWKT($distanceParams[0]);
@@ -1391,7 +1391,7 @@ protected function handleDistanceSpatialQueries(string $spatialAttributeType, Qu
13911391

13921392
if ($useMeters) {
13931393
$wktType = $this->getSpatialTypeFromWKT($wkt);
1394-
$attrType = strtolower($spatialAttributeType);
1394+
$attrType = strtolower($type);
13951395
if ($wktType != Database::VAR_POINT || $attrType != Database::VAR_POINT) {
13961396
throw new DatabaseException('Distance in meters is not supported between '.$attrType . ' and '. $wktType);
13971397
}
@@ -1426,7 +1426,7 @@ protected function handleSpatialQueries(string $type, Query $query, array &$bind
14261426
case Query::TYPE_DISTANCE_NOT_EQUAL:
14271427
case Query::TYPE_DISTANCE_GREATER_THAN:
14281428
case Query::TYPE_DISTANCE_LESS_THAN:
1429-
return $this->handleDistanceSpatialQueries($type, $query, $binds, $attribute, $alias, $placeholder);
1429+
return $this->handleDistanceSpatialQueries($query, $binds, $attribute, $type, $alias, $placeholder);
14301430

14311431
case Query::TYPE_INTERSECTS:
14321432
$binds[":{$placeholder}_0"] = $this->convertArrayToWKT($query->getValues()[0]);

src/Database/Adapter/MySQL.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ public function getSizeOfCollectionOnDisk(string $collection): int
8282
/**
8383
* Handle distance spatial queries
8484
*
85-
* @param string $spatialAttributeType
8685
* @param Query $query
8786
* @param array<string, mixed> $binds
8887
* @param string $attribute
88+
* @param string $type
8989
* @param string $alias
9090
* @param string $placeholder
9191
* @return string
9292
*/
93-
protected function handleDistanceSpatialQueries(string $spatialAttributeType, Query $query, array &$binds, string $attribute, string $alias, string $placeholder): string
93+
protected function handleDistanceSpatialQueries(Query $query, array &$binds, string $attribute, string $type, string $alias, string $placeholder): string
9494
{
9595
$distanceParams = $query->getValues()[0];
9696
$binds[":{$placeholder}_0"] = $this->convertArrayToWKT($distanceParams[0]);

src/Database/Adapter/SQL.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@ public function getSpatialTypeFromWKT(string $wkt): string
26632663
$wkt = trim($wkt);
26642664
$pos = strpos($wkt, '(');
26652665
if ($pos === false) {
2666-
throw new Exception("Not a valid spatialtype");
2666+
throw new DatabaseException("Invalid spatial type");
26672667
}
26682668
return strtolower(trim(substr($wkt, 0, $pos)));
26692669
}

src/Database/Validator/Spatial.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function getType(): string
144144
return self::TYPE_ARRAY;
145145
}
146146

147-
public function getSptialType(): string
147+
public function getSpatialType(): string
148148
{
149149
return $this->spatialType;
150150
}

0 commit comments

Comments
 (0)