public static function deriveFieldLength(array $dataTypeInfo): ?int
  {
    switch ($dataTypeInfo['data_type'])
    {
      case 'tinyint':
      case 'smallint':
      case 'mediumint':
      case 'int':
      case 'bigint':
      case 'float':
      case 'double':
        $ret = $dataTypeInfo['numeric_precision'];
        break;

      case 'decimal':
        $ret = $dataTypeInfo['numeric_precision'];
        if ($dataTypeInfo['numeric_scale']>0) $ret += 1;
        break;

      case 'char':
      case 'varchar':
      case 'binary':
      case 'varbinary':
      case 'tinytext':
      case 'text':
      case 'mediumtext':
      case 'longtext':
      case 'tinyblob':
      case 'blob':
      case 'mediumblob':
      case 'longblob':
      case 'bit':
        $ret = $dataTypeInfo['character_maximum_length'];
        break;

      case 'timestamp':
        $ret = 16;
        break;

      case 'year':
        $ret = 4;
        break;

      case 'time':
        $ret = 8;
        break;

      case 'date':
        $ret = 10;
        break;

      case 'datetime':
        $ret = 16;
        break;

      case 'enum':
      case 'set':
        // We don't assign a width to column with type enum and set.
        $ret = null;
        break;

      default:
        throw new FallenException('data type', $dataTypeInfo['data_type']);
    }

    return $ret;
  }
public static function deriveFieldLength(array $dataTypeInfo): ?int
  {
    switch ($dataTypeInfo['data_type'])
    {
      case 'tinyint':
      case 'smallint':
      case 'mediumint':
      case 'int':
      case 'bigint':
      case 'float':
      case 'double':
        $ret = $dataTypeInfo['numeric_precision'];
        break;

      case 'decimal':
        $ret = $dataTypeInfo['numeric_precision'];
        if ($dataTypeInfo['numeric_scale']>0) $ret += 1;
        break;

      case 'char':
      case 'varchar':
      case 'binary':
      case 'varbinary':
      case 'tinytext':
      case 'text':
      case 'mediumtext':
      case 'longtext':
      case 'tinyblob':
      case 'blob':
      case 'mediumblob':
      case 'longblob':
      case 'bit':
        $ret = $dataTypeInfo['character_maximum_length'];
        break;

      case 'timestamp':
        $ret = 16;
        break;

      case 'year':
        $ret = 4;
        break;

      case 'time':
        $ret = 8;
        break;

      case 'date':
        $ret = 10;
        break;

      case 'datetime':
        $ret = 16;
        break;

      case 'enum':
      case 'set':
        // We don't assign a width to column with type enum and set.
        $ret = null;
        break;

      default:
        throw new FallenException('data type', $dataTypeInfo['data_type']);
    }

    return $ret;
  }
public static function deriveFieldLength ( array $ dataTypeInfo ) : ? int { switch ( $ dataTypeInfo [ 'data_type' ] ) { case 'tinyint' : case 'smallint' : case 'mediumint' : case 'int' : case 'bigint' : case 'float' : case 'double' : $ ret = $ dataTypeInfo [ 'numeric_precision' ] ; break ; case 'decimal' : $ ret = $ dataTypeInfo [ 'numeric_precision' ] ; if ( $ dataTypeInfo [ 'numeric_scale' ] > 0 ) $ ret += 1 ; break ; case 'char' : case 'varchar' : case 'binary' : case 'varbinary' : case 'tinytext' : case 'text' : case 'mediumtext' : case 'longtext' : case 'tinyblob' : case 'blob' : case 'mediumblob' : case 'longblob' : case 'bit' : $ ret = $ dataTypeInfo [ 'character_maximum_length' ] ; break ; case 'timestamp' : $ ret = 16 ; break ; case 'year' : $ ret = 4 ; break ; case 'time' : $ ret = 8 ; break ; case 'date' : $ ret = 10 ; break ; case 'datetime' : $ ret = 16 ; break ; case 'enum' : case 'set' : // We don't assign a width to column with type enum and set. $ ret = null ; break ; default : throw new FallenException ( 'data type' , $ dataTypeInfo [ 'data_type' ] ) ; } return $ ret ; }
Returns the widths of a field based on a MySQL data type.

@param array $dataTypeInfo Metadata of the column on which the field is based.

@return int|null
Returns the widths of a field based on a MySQL data type .