Correctly display column expressions in the table key list

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2021-08-26 16:43:56 +02:00
parent cd4be9ac2c
commit 036f544e7e
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
4 changed files with 36 additions and 6 deletions

View File

@ -254,13 +254,16 @@ class Index
*/
public function addColumn(array $params)
{
if (! isset($params['Column_name'])
|| strlen($params['Column_name']) <= 0
) {
$key = $params['Column_name'] ?? $params['Expression'] ?? '';
if (isset($params['Expression'])) {
// The Expression only does not make the key unique, add a sequence number
$key .= $params['Seq_in_index'];
}
if (strlen($key) <= 0) {
return;
}
$this->columns[$params['Column_name']] = new IndexColumn($params);
$this->columns[$key] = new IndexColumn($params);
}
/**
@ -364,6 +367,7 @@ class Index
if (isset($params['Key_block_size'])) {
$this->keyBlockSize = $params['Key_block_size'];
}
if (! isset($params['Parser'])) {
return;
}

View File

@ -48,6 +48,13 @@ class IndexColumn
*/
private $cardinality = null;
/**
* If the Index uses an expression and not a name
*
* @var string|null
*/
private $expression = null;
/**
* @param array $params an array containing the parameters of the index column
*/
@ -56,6 +63,22 @@ class IndexColumn
$this->set($params);
}
/**
* If the Index has an expression
*/
public function hasExpression(): bool
{
return $this->expression !== null;
}
/**
* The Index expression if it has one
*/
public function getExpression(): ?string
{
return $this->expression;
}
/**
* Sets parameters of the index column
*
@ -80,6 +103,9 @@ class IndexColumn
if (isset($params['Sub_part'])) {
$this->subPart = $params['Sub_part'];
}
if (isset($params['Expression'])) {
$this->expression = $params['Expression'];
}
if (! isset($params['Null'])) {
return;
}

View File

@ -68,7 +68,7 @@
<tr class="noclick">
{% endif %}
<td>
{{ column.getName() }}
{% if column.hasExpression() %}{{ column.getExpression() }}{% else %}{{ column.getName() }}{% endif %}
{% if column.getSubPart() is not empty %}
({{ column.getSubPart() }})
{% endif %}

View File

@ -475,7 +475,7 @@
<tr class="noclick">
{% endif %}
<td>
{{ column.getName() }}
{% if column.hasExpression() %}{{ column.getExpression() }}{% else %}{{ column.getName() }}{% endif %}
{% if column.getSubPart() is not empty %}
({{ column.getSubPart() }})
{% endif %}