Extracts the default value for the column.
The value is typecasted to correct PHP type.

@param ColumnSchema $field
@param mixed        $defaultValue the default value obtained from metadata
183641
public function extractDefault(ColumnSchema $field, $defaultValue)
    {
        if (strncmp($field->dbType, 'bit', 3) === 0) {
            $field->defaultValue = bindec(trim($defaultValue, 'b\''));
        } else {
            parent::extractDefault($field, $defaultValue);
        }
    }
1136109
protected function prepareDefaultValue(Column $column)
    {
        $typeMapper = $this->getDataType();

        $default = $column->getDefault();

        if (!$column->getAllowNull() && $default === null && !$column->isPrimary()) {
            $default = $typeMapper::getDefaultValue($column->getType());

            $column->defaultValue($default);
        }

        return $column;
    }
195801
public function read_default_value(Schema $field_schema, $default_value)
    {
        switch ($field_schema->type()) {
            case Schema::NULL_TYPE:
                return null;
            case Schema::BOOLEAN_TYPE:
                return $default_value;
            case Schema::INT_TYPE:
            case Schema::LONG_TYPE:
                return (int)$default_value;
            case Schema::FLOAT_TYPE:
            case Schema::DOUBLE_TYPE:
                return (float)$default_value;
            case Schema::STRING_TYPE:
            case Schema::BYTES_TYPE:
                return $default_value;
            case Schema::ARRAY_SCHEMA:
                $array = array();
                foreach ($default_value as $json_val) {
                    $val = $this->read_default_value($field_schema->items(), $json_val);
                    $array [] = $val;
                }
                return $array;
            case Schema::MAP_SCHEMA:
                $map = array();
                foreach ($default_value as $key => $json_val)
                    $map[$key] = $this->read_default_value($field_schema->values(),
                        $json_val);
                return $map;
            case Schema::UNION_SCHEMA:
                return $this->read_default_value($field_schema->schema_by_index(0),
                    $default_value);
            case Schema::ENUM_SCHEMA:
            case Schema::FIXED_SCHEMA:
                return $default_value;
            case Schema::RECORD_SCHEMA:
                $record = array();
                foreach ($field_schema->fields() as $field) {
                    $field_name = $field->name();
                    if (!$json_val = $default_value[$field_name])
                        $json_val = $field->default_value();

                    $record[$field_name] = $this->read_default_value($field->type(),
                        $json_val);
                }
                return $record;
            default:
                throw new Exception(sprintf('Unknown type: %s', $field_schema->type()));
        }
    }
1128318
public function setDefaultValue($defaultValue)
    {
        if (!$defaultValue instanceof ColumnDefaultValue) {
            $defaultValue = new ColumnDefaultValue($defaultValue, ColumnDefaultValue::TYPE_VALUE);
        }

        $this->domain->setDefaultValue($defaultValue);
    }
1155265
protected function getFieldValue($field)
    {
        if (is_string($field)) {
            if (!isset($this->allFields[$field])) {
                throw new ApplicationException(Lang::get(
                    'backend::lang.form.missing_definition',
                    compact('field')
                ));
            }

            $field = $this->allFields[$field];
        }

        $defaultValue = !$this->model->exists
            ? $field->getDefaultFromData($this->data)
            : null;

        return $field->getValueFromData(
            $this->data, 
            is_string($defaultValue) ? trans($defaultValue) : $defaultValue
        );
    }
1223321
function Value($field, $trim = true)
    {
        $result = Request::IsPost() ? Request::PostData($field) : $this->DefaultValue($field);
        if ($trim)
        {
            return trim($result);
        }
        return $result;
    }
142551
protected function _setFieldData($fieldName, $fieldValue, $dataType = Field::T_TEXT)
    {
        $longFieldName = $this->_getFieldLongName($fieldName);
        //$sLongFieldName = $this->_sCoreTable . "__" . strtolower($sFieldName);

        // doing this because in lazy loaded lists on first load it is harmful to have initialised fields but not yet set
        // situation: only first article is loaded fully for "select oxid from oxarticles"
        //if ($this->_blUseLazyLoading && !isset($this->$sLongFieldName))
        //    return;


        //in non lazy loading case we just add a field and do not care about it more
        if (!$this->_blUseLazyLoading
            && !$this->isPropertyLoaded($longFieldName)
        ) {
            $fieldsList = $this->_getAllFields(true);
            if (isset($fieldsList[strtolower($fieldName)])) {
                $this->_addField($fieldName, $this->_getFieldStatus($fieldName));
            }
        }
        // if we have a double field we replace "," with "." in case somebody enters it in european format
        $isPropertyLoaded = $this->isPropertyLoaded($longFieldName);
        if ($isPropertyLoaded
            && isset($this->$longFieldName->fldtype)
            && $this->$longFieldName->fldtype == 'double'
        ) {
            $fieldValue = str_replace(',', '.', $fieldValue);
        }

        // isset is REQUIRED here not to use getter
        if ($isPropertyLoaded
            && is_object($this->$longFieldName)
        ) {
            $this->$longFieldName->setValue($fieldValue, $dataType);
        } else {
            $this->$longFieldName = new Field($fieldValue, $dataType);
        }
    }
823041
private function parseString(FieldBuilder $field, $value = '')
    {
        return (empty($value) && isset($field['default'])) ? $field['default'] : $value;
    }
133957
public String getString(String columnName, String defaultValue) {
        int index = getColumnIndex(columnName);
        if (isValidIndex(index)) {
            return getString(index);
        } else {
            return defaultValue;
        }
    }
316484
static void checkDefaultValueIsLegal(Field field,
                                                              List<Message> messages,
                                                              String name) {
        if(field == null) {
            throw new IllegalArgumentException("Field must be non-null. Name=" + name);
        }

        if(field.defaultValue() != null) {
            // Get the type schema. If this is a UNION, the default must be of
            // the leading type
            Schema fieldSchema = field.schema();
            if(fieldSchema.getType() == Schema.Type.UNION) {
                fieldSchema = fieldSchema.getTypes().get(0);
            }

            // Get the default value
            JsonNode defaultJson = field.defaultValue();

            String expectedVal = checkDefaultJson(defaultJson, field.schema());

            if(expectedVal != null) {
                messages.add(new Message(Level.ERROR, "Illegal default value for field " + name
                                                      + ". The default must be of type "
                                                      + expectedVal + "."));
            }
        }
    }
1115261
public function prepareDefaultValue(ScalarField $field)
    {
        $default_value = $field->getDefaultValue();

        if ($default_value === null) {
            return 'NULL';
        }

        if ($field instanceof DateField || $field instanceof DateTimeField) {
            $timestamp = is_int($default_value) ? $default_value : strtotime($default_value);

            if ($field instanceof DateTimeField) {
                return $this->getConnection()->escapeValue(date('Y-m-d H:i:s', $timestamp));
            } else {
                return $this->getConnection()->escapeValue(date('Y-m-d', $timestamp));
            }
        }

        return $this->getConnection()->escapeValue($default_value);
    }
1369785
protected function extractDefault($defaultValue)
	{
		if(strncmp($this->dbType,'bit',3)===0)
			$this->defaultValue=bindec(trim($defaultValue,'b\''));
		elseif(($this->dbType==='timestamp' || $this->dbType==='datetime')  && ($defaultValue==='CURRENT_TIMESTAMP' || $defaultValue==='current_timestamp()'))
			$this->defaultValue=null;
		else
			parent::extractDefault($defaultValue);
	}
445085
protected function parseValue(FieldBuilder $field, $value = null)
    {
        $parsedValue = null;

        // No data found, define a default by field type.
        switch ($field->getFieldType())
        {

            case 'checkbox':
            case 'checkboxes': // @todo remove this checkboxes statement for next major update.
            case 'radio':
            case 'select':
            case 'collection':

                $parsedValue = $this->parseArrayable($field, $value);
                break;

            case 'infinite':

                // Check for the registered fields and their default value if one.
                $parsedValue = $this->parseInfinite($field, $value);
                break;

            // Text
            // Textarea
            // Password
            // Media
            // Editor
            default:
                $parsedValue = $this->parseString($field, $value);
        }

        return $parsedValue;
    }
726381
public function fetchColumn($field = '')
    {
        $opts = $this->options;
        
        if ($field) {
            $opts['field'] = $field;
        }
        
        $sql = QueryBuilder::optionsToSql($opts);        
        $colValue = $this->getDb()->getColumn($sql);
        
        return $colValue;
    }
1083296
public function getHeader(string $header, string $defaultValue = null)
    {
        $header = strtolower($header);
        if (isset($this->headers[$header])) {
            return $this->headers[$header];
        }
        return $defaultValue;
    }
44267
public function queryValue(string $sql, string $column, $default = null)
    {
        $result = $default;
        if ($row = $this->query($sql)->fetch(PDO::FETCH_ASSOC)) {
            $result = $row[$column];
        }

        return $result;
    }
954778
private function typeChangeBreaksDefaultValue(ColumnDiff $columnDiff) : bool
    {
        if (! $columnDiff->fromColumn) {
            return $columnDiff->hasChanged('type');
        }

        $oldTypeIsNumeric = $this->isNumericType($columnDiff->fromColumn->getType());
        $newTypeIsNumeric = $this->isNumericType($columnDiff->column->getType());

        // default should not be changed when switching between numeric types and the default comes from a sequence
        return $columnDiff->hasChanged('type')
            && ! ($oldTypeIsNumeric && $newTypeIsNumeric && $columnDiff->column->getAutoincrement());
    }