Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 1 addition & 10 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
35 changes: 13 additions & 22 deletions tests/e2e/Adapter/Scopes/AttributeTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions tests/e2e/Adapter/Scopes/CollectionTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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');
Expand Down