Skip to content

Commit 7cfc312

Browse files
authored
Merge branch 'main' into joins8
2 parents f9e4269 + 8227f57 commit 7cfc312

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/Database/Database.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ class Database
6868
public const VAR_LINESTRING = 'linestring';
6969
public const VAR_POLYGON = 'polygon';
7070

71+
// All string types
72+
public const STRING_TYPES = [
73+
self::VAR_STRING,
74+
self::VAR_VARCHAR,
75+
self::VAR_TEXT,
76+
self::VAR_MEDIUMTEXT,
77+
self::VAR_LONGTEXT,
78+
];
79+
7180
// All spatial types
7281
public const SPATIAL_TYPES = [
7382
self::VAR_POINT,
@@ -1687,7 +1696,7 @@ public function createCollection(string $id, array $attributes = [], array $inde
16871696
/**
16881697
* mysql does not save length in collection when length = attributes size
16891698
*/
1690-
if ($collectionAttribute->getAttribute('type') === Database::VAR_STRING) {
1699+
if (in_array($collectionAttribute->getAttribute('type'), self::STRING_TYPES)) {
16911700
if (!empty($lengths[$i]) && $lengths[$i] === $collectionAttribute->getAttribute('size') && $this->adapter->getMaxIndexLength() > 0) {
16921701
$lengths[$i] = null;
16931702
}
@@ -4482,7 +4491,7 @@ public function createIndex(string $collection, string $id, string $type, array
44824491
/**
44834492
* mysql does not save length in collection when length = attributes size
44844493
*/
4485-
if ($attributeType === self::VAR_STRING) {
4494+
if (in_array($attributeType, self::STRING_TYPES)) {
44864495
if (!empty($lengths[$i]) && $lengths[$i] === $collectionAttribute->getAttribute('size') && $this->adapter->getMaxIndexLength() > 0) {
44874496
$lengths[$i] = null;
44884497
}

src/Database/Validator/Operator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private function validateOperatorForAttribute(
402402

403403
break;
404404
case DatabaseOperator::TYPE_STRING_CONCAT:
405-
if ($type !== Database::VAR_STRING || $isArray) {
405+
if (!in_array($type, Database::STRING_TYPES) || $isArray) {
406406
$this->message = "Cannot apply {$method} operator to non-string field '{$operator->getAttribute()}'";
407407
return false;
408408
}
@@ -412,7 +412,7 @@ private function validateOperatorForAttribute(
412412
return false;
413413
}
414414

415-
if ($this->currentDocument !== null && $type === Database::VAR_STRING) {
415+
if ($this->currentDocument !== null && in_array($type, Database::STRING_TYPES)) {
416416
$currentString = $this->currentDocument->getAttribute($operator->getAttribute()) ?? '';
417417
$concatValue = $values[0];
418418
$predictedLength = strlen($currentString) + strlen($concatValue);
@@ -430,7 +430,7 @@ private function validateOperatorForAttribute(
430430
break;
431431
case DatabaseOperator::TYPE_STRING_REPLACE:
432432
// Replace only works on string types
433-
if ($type !== Database::VAR_STRING) {
433+
if (!in_array($type, Database::STRING_TYPES)) {
434434
$this->message = "Cannot apply {$method} operator to non-string field '{$operator->getAttribute()}'";
435435
return false;
436436
}

0 commit comments

Comments
 (0)