• Модуль: perfmon
  • Путь к файлу: ~/bitrix/modules/perfmon/lib/sql/column.php
  • Класс: BitrixPerfmonSqlColumn
  • Вызов: Column::getLength
public function getLength($charWidth, $maxLength = null)
{
	$length = $maxLength ?? intval($this->length);
	static $fixed = [
		'INT' => 4,
		'INTEGER' => 4,
		'TINYINT' => 1,
		'FLOAT' => 4,
		'DOUBLE' => 8,
		'BIGINT' => 8,
		'SMALLINT' => 2,
		'MEDIUMINT' => 3,
		'TIMESTAMP' => 4,
		'DATETIME' => 8,
		'YEAR' => 1,
		'DATE' => 3,
		'TIME' => 3,
		'NUMERIC' => 4, //up to
		'NUMBER' => 4, //up to
		'DECIMAL' => 4, //up to
		'ENUM' => 2, //up to
		'SET' => 8, //up to
		'BOOLEAN' => 1,
	];
	if (isset($fixed[$this->type]))
	{
		return $fixed[$this->type];
	}
	if ($this->type == 'BINARY')
	{
		return $length;
	}
	if ($this->type == 'VARBINARY')
	{
		return $length + ($length > 255 ? 2 : 1);
	}
	if ($this->type == 'TINYBLOB' || $this->type == 'TINYTEXT')
	{
		return ($length ?: pow(2, 8)) + 1;
	}
	if ($this->type == 'BLOB' || $this->type == 'TEXT')
	{
		return ($length ?: pow(2, 16)) + 2;
	}
	if ($this->type == 'MEDIUMBLOB' || $this->type == 'MEDIUMTEXT')
	{
		return ($length ?: pow(2, 24)) + 3;
	}
	if ($this->type == 'LONGBLOB' || $this->type == 'LONGTEXT')
	{
		return ($length ?: pow(2, 32)) + 3;
	}
	if ($this->type == 'CHAR')
	{
		return $length * $charWidth;
	}
	if ($this->type == 'VARCHAR')
	{
		return ($length * $charWidth) + ($length > 255 ? 2 : 1);
	}
	throw new NotSupportedException("column type [".$this->type."].");
}