diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 708926548..2e02ea470 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -1906,18 +1906,9 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool switch ($type) { case Database::VAR_STRING: // $size = $size * 4; // Convert utf8mb4 size to bytes - if ($size > 16777215) { + if ($size > $this->getMaxIndexLength()) { return 'LONGTEXT'; } - - if ($size > 65535) { - return 'MEDIUMTEXT'; - } - - if ($size > $this->getMaxVarcharLength()) { - return 'TEXT'; - } - return "VARCHAR({$size})"; case Database::VAR_INTEGER: // We don't support zerofill: https://stackoverflow.com/a/5634147/2299554 diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index 31bc7e6a3..c3ce9b31c 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -1574,7 +1574,8 @@ public function getHostname(): string */ public function getMaxVarcharLength(): int { - return 16381; // Floor value for Postgres:16383 | MySQL:16381 | MariaDB:16382 + // Floor value for Postgres:16383 | MySQL:16381 | MariaDB:16382 + return $this->getMaxIndexLength(); } /** diff --git a/tests/e2e/Adapter/Scopes/AttributeTests.php b/tests/e2e/Adapter/Scopes/AttributeTests.php index fa401db2a..7500d38ff 100644 --- a/tests/e2e/Adapter/Scopes/AttributeTests.php +++ b/tests/e2e/Adapter/Scopes/AttributeTests.php @@ -950,28 +950,19 @@ public function testExceptionWidthLimit(): void } $attributes = []; - - $attributes[] = new Document([ - '$id' => ID::custom('varchar_16000'), - 'type' => Database::VAR_STRING, - 'size' => 16000, - 'required' => true, - 'default' => null, - 'signed' => true, - 'array' => false, - 'filters' => [], - ]); - - $attributes[] = new Document([ - '$id' => ID::custom('varchar_200'), - 'type' => Database::VAR_STRING, - 'size' => 200, - 'required' => true, - 'default' => null, - 'signed' => true, - 'array' => false, - 'filters' => [], - ]); + $limit = (int)($database->getAdapter()->getDocumentSizeLimit() / (200 * 4)); + for ($i = 0; $i < $limit; $i++) { + $attributes[] = new Document([ + '$id' => ID::unique(), + 'type' => Database::VAR_STRING, + 'size' => 200, + 'required' => true, + 'default' => null, + 'signed' => true, + 'array' => false, + 'filters' => [], + ]); + } try { $database->createCollection("attributes_row_size", $attributes); diff --git a/tests/e2e/Adapter/Scopes/CollectionTests.php b/tests/e2e/Adapter/Scopes/CollectionTests.php index 731525f81..119078e9c 100644 --- a/tests/e2e/Adapter/Scopes/CollectionTests.php +++ b/tests/e2e/Adapter/Scopes/CollectionTests.php @@ -543,9 +543,9 @@ public function testSchemaAttributes(): void $attribute = $attributes['story']; $this->assertEquals('story', $attribute['$id']); - $this->assertEquals('text', $attribute['dataType']); - $this->assertEquals('text', $attribute['columnType']); - $this->assertEquals('65535', $attribute['characterMaximumLength']); + $this->assertEquals('longtext', $attribute['dataType']); + $this->assertEquals('longtext', $attribute['columnType']); + $this->assertEquals('4294967295', $attribute['characterMaximumLength']); $attribute = $attributes['string_list']; $this->assertEquals('string_list', $attribute['$id']); @@ -586,8 +586,11 @@ public function testRowSizeToLarge(): void $collection_1 = $database->createCollection('row_size_1'); $collection_2 = $database->createCollection('row_size_2'); - $this->assertEquals(true, $database->createAttribute($collection_1->getId(), 'attr_1', Database::VAR_STRING, 16000, true)); + $limit = (int)($database->getAdapter()->getDocumentSizeLimit() / (200 * 4)) - 1; + for ($i = 0; $i < $limit; $i++) { + $this->assertEquals(true, $database->createAttribute($collection_1->getId(), 'attr_1_'.$i, Database::VAR_STRING, 200, true)); + } try { $database->createAttribute($collection_1->getId(), 'attr_2', Database::VAR_STRING, Database::LENGTH_KEY, true); $this->fail('Failed to throw exception');