Returns the SQL snippet used to declare a BINARY/VARBINARY column type.

@param mixed[] $field The column definition.

@return string
12286
public function getBinaryTypeDeclarationSQL(array $field)
    {
        if (! isset($field['length'])) {
            $field['length'] = $this->getBinaryDefaultLength();
        }

        $fixed = $field['fixed'] ?? false;

        $maxLength = $this->getBinaryMaxLength();

        if ($field['length'] > $maxLength) {
            if ($maxLength > 0) {
                @trigger_error(sprintf(
                    'Binary field length %d is greater than supported by the platform (%d). Reduce the field length or use a BLOB field instead.',
                    $field['length'],
                    $maxLength
                ), E_USER_DEPRECATED);
            }

            return $this->getBlobTypeDeclarationSQL($field);
        }

        return $this->getBinaryTypeDeclarationSQLSnippet($field['length'], $fixed);
    }
1357842
public static function finagleVarcharFieldTypeForIndexListing($field, $data) {
   	if (empty($field['persist_wash'])) {
            return $data;
        }
    
        if (strtolower($field['persist_wash']) == "url") {
            $prefacedURL = self::prefaceURLwithHTTP($data);
            return '<a href="'.$prefacedURL.'" target="_blank">'.$data.'</a>';
        }

        return $data;
    }
170244
private function getValues(array $field)
    {
        if ($field['type'] !== 'select') {
            return null;
        }
        $field = Bag::from($field);

        // Get the appropriate values
        return is_string($field->get('values', [])) ? $this->getEntityValues($field) : $this->getYamlValues($field);
    }
592706
private function parseField( SimpleXMLElement $field )
    {
        return ezcDbSchema::createNewField(
            (string) $field->type,
            isset( $field->length ) ? (string) $field->length : false,
            isset( $field->notnull ) ? ((string) $field->notnull == 'true' || (string) $field->notnull == '1' ? true : false ) : false,
            isset( $field->default ) ? (string) $field->default : null,
            isset( $field->autoincrement ) ? ((string) $field->autoincrement == 'true' || (string) $field->autoincrement == '1' ? true : false ) : false,
            isset( $field->unsigned ) ? ((string) $field->unsigned == 'true' || (string) $field->unsigned == '1' ? true : false ) : false
        );
    }
959844
public function getDefaultValueDeclarationSQL($field)
    {
        if (! isset($field['default'])) {
            return empty($field['notnull']) ? ' DEFAULT NULL' : '';
        }

        $default = $field['default'];

        if (! isset($field['type'])) {
            return " DEFAULT '" . $default . "'";
        }

        $type = $field['type'];

        if ($type instanceof Types\PhpIntegerMappingType) {
            return ' DEFAULT ' . $default;
        }

        if ($type instanceof Types\PhpDateTimeMappingType && $default === $this->getCurrentTimestampSQL()) {
            return ' DEFAULT ' . $this->getCurrentTimestampSQL();
        }

        if ($type instanceof Types\TimeType && $default === $this->getCurrentTimeSQL()) {
            return ' DEFAULT ' . $this->getCurrentTimeSQL();
        }

        if ($type instanceof Types\DateType && $default === $this->getCurrentDateSQL()) {
            return ' DEFAULT ' . $this->getCurrentDateSQL();
        }

        if ($type instanceof Types\BooleanType) {
            return " DEFAULT '" . $this->convertBooleans($default) . "'";
        }

        return ' DEFAULT ' . $this->quoteStringLiteral($default);
    }
763272
protected function parseColumnType(Field $field, array $attributes)
    {
        $type = Type::retrieveTypeObject(strtolower($attributes['type']));
        
        $type->setLength(isset($attributes['length']) ? (integer) $attributes['length'] : 0);
        $type->setPrecision(isset($attributes['precision']) ? (integer) $attributes['precision'] : 0);
        
        switch (true) {
            case $type instanceof EnumType:
                $enumeration = explode(',', $attributes['enum']);
                $enumeration = array_map('trim', $enumeration);
                
                $type->setExtra($enumeration);
                break;
            
            case $type instanceof DatetimeType:
                if (isset($attributes['format'])) {
                    $type->setExtra(['format' => $attributes['format'],]);
                }
                break;
            
            case $type instanceof SimpleArrayType:
                if (isset($attributes['separator'])) {
                    $type->setExtra(['separator' => $attributes['separator'],]);
                }
                break;
            
            default:
                break;
        }
        
        $field->setType($type);
        
        return $this;
    }
1046739
protected function &getNestedValueReference($field)
	{
		$field = preg_split('(__([0-9]+)__)', substr($field, 11), -1, PREG_SPLIT_DELIM_CAPTURE);

		if (!isset($this->saveData[$field[0]])) {
			$this->saveData[$field[0]] = array();
		}

		$data =& $this->saveData[$field[0]];

		for ($i = 0; isset($field[$i]); $i += 2) {

			if (isset($field[$i + 1])) {
				if (!isset($data[$field[$i + 1]])) {
					$data[$field[$i + 1]] = array();
				}
				if (!isset($data[$field[$i + 1]][$field[$i + 2]])) {
					$data[$field[$i + 1]][$field[$i + 2]] = array();
				}
				$data =& $data[$field[$i + 1]][$field[$i + 2]];
			}
			else {
				return $data;
			}

		}
	}
1241491
public function getArrayTypeDeclarationSQL(array $field, array $options)
    {
        $type = array_key_exists('type', $options) ? $options['type'] : Type::STRING;
        return 'ARRAY ( ' . Type::getType($type)->getSQLDeclaration($field, $this) . ' )';
    }
437050
public function getCondition(string $field, array $fieldConf): string
    {
        $type = strtolower($fieldConf['type']);
        $unsigned = $fieldConf['unsigned'];

        $integerCast = $this->getIntegerCast($unsigned);

        $condition = "(CASE $field WHEN NULL THEN NULL ELSE :$field END)";

        $typeToCast = [
            'date' => 'DATE',
            'datetime' => 'DATE',
            'time' => 'TIME',
            'smallint' => $integerCast,
            'integer' => $integerCast,
            'bigint' => $integerCast,
            'float' => 'DECIMAL',
            'decimal' => 'DECIMAL',
        ];

        // No cast required
        if (!array_key_exists($type, $typeToCast)) {
            return $condition;
        }

        return "CAST($condition AS {$typeToCast[$type]})";
    }
908980
public function getJsonFieldType($field)
    {
        return isset($this->options['field_type'][$field]) ? $this->options['field_type'][$field] : null;
    }
1147917
public function select(string $fields): QueryBuilderInterface
	{
		// Split fields by comma
		$fieldsArray = explode(',', $fields);
		$fieldsArray = array_map('mb_trim', $fieldsArray);

		// Split on 'As'
		foreach ($fieldsArray as $key => $field)
		{
			if (stripos($field, 'as') !== FALSE)
			{
				$fieldsArray[$key] = preg_split('` as `i', $field);
				$fieldsArray[$key] = array_map('mb_trim', $fieldsArray[$key]);
			}
		}

		// Quote the identifiers
		$safeArray = $this->driver->quoteIdent($fieldsArray);

		unset($fieldsArray);

		// Join the strings back together
		for($i = 0, $c = count($safeArray); $i < $c; $i++)
		{
			if (\is_array($safeArray[$i]))
			{
				$safeArray[$i] = implode(' AS ', $safeArray[$i]);
			}
		}

		$this->state->appendSelectString(implode(', ', $safeArray));

		return $this;
	}
565859
protected function getSqlFields(array $fields)
    {
        $sql = array();
        foreach ($fields as $name => $info) {

            if (strpos($info['type'], 'text') !== false || $info['type'] === 'blob') {
                unset($info['default']);
            }

            $string = "{$info['type']}";

            if (isset($info['length'])) {
                $string .= "({$info['length']})";
            }

            if (!empty($info['not_null'])) {
                $string .= " NOT NULL";
            }

            if (isset($info['default'])) {
                $string .= " DEFAULT '{$info['default']}'";
            }

            if (!empty($info['primary'])) {
                $string .= " PRIMARY KEY";
            }

            if (!empty($info['auto_increment'])) {
                $string .= " /*!40101 AUTO_INCREMENT */"; // SQLite will ignore this comment
            }

            $sql[] = $name . ' ' . trim($string);
        }

        return implode(',', $sql);
    }
1346953
public function value($field) {
        $this->fields = [];
        $this->order("");
        $this->fields($field);
        $this->limit(0, 1);
        $connection = Pool::get(Connection::class);
        try {
            $value = $connection->value($this->getSql(), $this->whereParams(), $this->cache);
            Pool::release($connection);
            return $value;
        } catch (\RuntimeException $e) {
            Pool::release($connection);
            throw $e;
        } catch (\Error $e) {
            Pool::release($connection);
            throw $e;
        }
    }
751798
private static function getBytes(array $fields)
    {
        $bytes = '';
        foreach (\range(-2, -32, 2) as $step) {
            $bytes = \chr(\hexdec(\substr(self::getHex($fields), $step, 2))) . $bytes;
        }

        return $bytes;
    }
1185212
private function getFieldCreate($field)
    {
        $res = '';

        switch ($field['type']) {
            case self::FIELD_TYPE_VARCHAR_255:
                // Simple text input
                if (!isset($field['length'])) {
                    $field['length'] = '255';
                }
                $res = '`'. $field['name'] .'` varchar('. $field['length'] .') NULL '.(isset($field['default_value']) ? ' DEFAULT "' . $field['default_value'] . '"' : '').'';
                break;

            case self::FIELD_TYPE_CHAR:
                // Codes
                if (!isset($field['length'])) {
                    dump('Length for "'. $field['name'] .'" required');
                }
                $res = '`'. $field['name'] .'` char('. $field['length'] .') NULL';
                break;

            case self::FIELD_TYPE_TEXT:
                // Large textares
                $res = '`'. $field['name'] .'` text NULL';
                break;

            case 'mediumtext':
                // Large textares
                $res = '`'. $field['name'] .'` mediumtext NULL';
                break;

            case 'int':
                // Digit
                $unsigned = isset($field['unsigned']) && $field['unsigned'];
                if (!isset($field['length'])) {
                    $field['length'] = 11;
                    if ($unsigned) {
                        $field['length'] = 10;
                    }
                }
                $res = '`'. $field['name'] .'` int('. $field['length'] .') '. ($unsigned ? ' unsigned ' : '') . (isset($field['null']) && !$field['null'] ? ' NOT NULL' : ((isset($field['auto_increment']) ? '' : ' DEFAULT "'. (isset($field['default_value']) ? $field['default_value'] : '0') .'"') . ' NULL'));
                break;

            case self::FIELD_TYPE_UNSIGNED_INTEGER:
            case 'ts':
            case 'order':
                // Digit
                $res = '`'. $field['name'] .'` int(10) unsigned NULL DEFAULT "0"';
                break;

            case self::FIELD_TYPE_INDEX:
                $res = '`'. $field['name'] .'` int(10) unsigned DEFAULT "0"';

                // Add index if not exists
                if (!isset($this->table_structure['indexes'][$field['name']])) {
                    $this->table_structure['indexes'][$field['name']] = [
                        'type' => 'key',
                    ];
                }
                break;

            case self::FIELD_TYPE_TRANSLATION:
                // Int index with comment
                $res = '`'. $field['name'] .'` int(10) unsigned NULL DEFAULT "0"';
                $field['comment'] = self::FIELD_TYPE_TRANSLATION;
                break;

            case 'current_timestamp':
                // Dates
                $res = '`'. $field['name'] .'` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP';
                break;

            case 'date':
            case 'datetime':
                // Default : CURRENT_TIMESTAMP
                $res = '`'. $field['name'] .'` datetime NOT NULL';
                break;

            case 'checkbox':
            case 'active':
            case self::FIELD_TYPE_BOOL:
                // True or false, 0 | 1
                $res = '`'. $field['name'] .'` tinyint(1) unsigned NULL DEFAULT "'. (isset($field['default_value']) ? $field['default_value'] : '0') .'"';
                break;

            case self::FIELD_TYPE_FLOAT_DECIMAL:
            case 'decimal': // TODO REMOVE THIS 'decimal'
                // Decimal
                $unsigned = isset($field['unsigned']) && $field['unsigned'];
                if (!isset($field['length'])) {
                    $field['length'] = 8.2;
                }
                // Convert to db format
                $field['length'] = str_replace('.', ',', $field['length']);

                $res = '`'. $field['name'] .'` decimal('. $field['length'] .') '. ($unsigned ? ' unsigned ' : '') .' NULL DEFAULT "0"';
                break;

            case 'enum':
            case 'array':
                if (empty($field['options'])) {
                    dump('Param "options" must be set for field "enum" and have filled elements');
                }

                // If associative array supplied - we need only keys
                if (!isset($field['options'][0])) {
                    $field['options'] = array_keys($field['options']);
                }

                $res = '`'. $field['name'] .'` enum("'. implode('","', $field['options']) .'") NULL '. (isset($field['default_value']) ? ' DEFAULT "' . $field['default_value'] . '"' : '') .'';
                break;

            case 'json':

                $res = '`' . $field['name'] . '` JSON NULL ' . (isset($field['default_value']) ? ' DEFAULT "' . $field['default_value'] . '"' : '') . '';
                break;

            default:
                dump('Type "'. $field['type'] .'" not found in TableStructure');
        }

        if (isset($field['auto_increment'])) {
            $res .= ' AUTO_INCREMENT';
        }

        if (isset($field['comment'])) {
            $res .= ' COMMENT "'. $field['comment'] .'"';
        }

        return $res;
    }
522626
public function column($field)
    {
        $query = clone $this->_queryForWrite();

        return $query->select($field)->execute()->column($field);
    }
1362599
public static function getColumnName($field)
    {
        static::init();
        if (!static::fieldExists($field)) {
            throw new Exception('getColumnName called on nonexisting column: ' . get_called_class().'->'.$field);
        }

        return static::$_classFields[get_called_class()][$field]['columnName'];
    }