Commit 62b9d584 authored by alexpott's avatar alexpott

Issue #2297993 by cilefen, marthinal, ivanjaros: Fixed MySQL column and table...

Issue #2297993 by cilefen, marthinal, ivanjaros: Fixed MySQL column and table comments are not truncated properly.
parent e4242c47
......@@ -13,6 +13,7 @@
use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\Core\Database\SchemaObjectDoesNotExistException;
use Drupal\Core\Database\Schema as DatabaseSchema;
use Drupal\Component\Utility\Unicode;
/**
* @addtogroup schemaapi
......@@ -492,7 +493,7 @@ public function prepareComment($comment, $length = NULL) {
// Truncate comment to maximum comment length.
if (isset($length)) {
// Add table prefixes before truncating.
$comment = substr($this->connection->prefixTables($comment), 0, $length);
$comment = Unicode::truncate($this->connection->prefixTables($comment), $length, TRUE, TRUE);
}
return $this->connection->quote($comment);
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Database\SchemaObjectDoesNotExistException;
use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\simpletest\KernelTestBase;
use Drupal\Component\Utility\Unicode;
/**
* Tests table creation and modification via the schema API.
......@@ -30,7 +31,7 @@ class SchemaTest extends KernelTestBase {
function testSchema() {
// Try creating a table.
$table_specification = array(
'description' => 'Schema table description.',
'description' => 'Schema table description may contain "quotes" and could be long—very long indeed.',
'fields' => array(
'id' => array(
'type' => 'int',
......@@ -39,7 +40,7 @@ function testSchema() {
'test_field' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'Schema column description.',
'description' => 'Schema table description may contain "quotes" and could be long—very long indeed. There could be "multiple quoted regions".',
),
'test_field_string' => array(
'type' => 'varchar',
......@@ -212,6 +213,11 @@ function tryInsert($table = 'test_table') {
function checkSchemaComment($description, $table, $column = NULL) {
if (method_exists(Database::getConnection()->schema(), 'getComment')) {
$comment = Database::getConnection()->schema()->getComment($table, $column);
// The schema comment truncation for mysql is different.
if (Database::getConnection()->databaseType() == 'mysql') {
$max_length = $column ? 255 : 60;
$description = Unicode::truncate($description, $max_length, TRUE, TRUE);
}
$this->assertEqual($comment, $description, 'The comment matches the schema description.');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment