A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.yiiframework.com/doc/api/2.0/yii-db-columnschemabuilder below:

ColumnSchemaBuilder, yii\db\ColumnSchemaBuilder | API Documentation for Yii 2.0

Class yii\db\ColumnSchemaBuilder

ColumnSchemaBuilder helps to define database schema types using a PHP interface.

See yii\db\SchemaBuilderTrait for more detailed description and usage examples.

Property Details

Hide inherited properties

The column after which this column will be added.

SQL string to be appended to column schema definition.

Mapping of abstract column types (keys) to type categories (values).

The CHECK constraint for the column.

The current database connection. It is used mainly to escape strings safely when building the final column schema string.

Default value of the column.

Whether this column is to be inserted at the beginning of the table.

Whether the column is or not nullable. If this is true, a NOT NULL constraint will be added. If this is false, a NULL constraint will be added.

Whether the column values should be unique. If this is true, a UNIQUE constraint will be added.

Whether the column values should be unsigned. If this is true, an UNSIGNED keyword will be added.

Column size or precision definition. This is what goes into the parenthesis after the column type. This can be either a string, an integer or an array. If it is an array, the array values will be joined into a string separated by comma.

The column type definition such as INTEGER, VARCHAR, DATETIME, etc.

Mapping of abstract column types (keys) to type categories (values).

public static array $typeCategoryMap = [
    \
yii\db\Schema::TYPE_PK => self::CATEGORY_PK,
    \
yii\db\Schema::TYPE_UPK => self::CATEGORY_PK,
    \
yii\db\Schema::TYPE_BIGPK => self::CATEGORY_PK,
    \
yii\db\Schema::TYPE_UBIGPK => self::CATEGORY_PK,
    \
yii\db\Schema::TYPE_CHAR => self::CATEGORY_STRING,
    \
yii\db\Schema::TYPE_STRING => self::CATEGORY_STRING,
    \
yii\db\Schema::TYPE_TEXT => self::CATEGORY_STRING,
    \
yii\db\Schema::TYPE_TINYINT => self::CATEGORY_NUMERIC,
    \
yii\db\Schema::TYPE_SMALLINT => self::CATEGORY_NUMERIC,
    \
yii\db\Schema::TYPE_INTEGER => self::CATEGORY_NUMERIC,
    \
yii\db\Schema::TYPE_BIGINT => self::CATEGORY_NUMERIC,
    \
yii\db\Schema::TYPE_FLOAT => self::CATEGORY_NUMERIC,
    \
yii\db\Schema::TYPE_DOUBLE => self::CATEGORY_NUMERIC,
    \
yii\db\Schema::TYPE_DECIMAL => self::CATEGORY_NUMERIC,
    \
yii\db\Schema::TYPE_DATETIME => self::CATEGORY_TIME,
    \
yii\db\Schema::TYPE_TIMESTAMP => self::CATEGORY_TIME,
    \
yii\db\Schema::TYPE_TIME => self::CATEGORY_TIME,
    \
yii\db\Schema::TYPE_DATE => self::CATEGORY_TIME,
    \
yii\db\Schema::TYPE_BINARY => self::CATEGORY_OTHER,
    \
yii\db\Schema::TYPE_BOOLEAN => self::CATEGORY_NUMERIC,
    \
yii\db\Schema::TYPE_MONEY => self::CATEGORY_NUMERIC,
]
Method Details

Hide inherited methods

Defined in: yii\base\BaseObject::__call()

Calls the named method which is not a class method.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

Source code

                public function __call($name, $params)
{
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            

Create a column schema builder instance giving the type and value precision.

Source code

                public function __construct($type, $length = null, $db = null, $config = [])
{
    $this->type = $type;
    $this->length = $length;
    $this->db = $db;
    parent::__construct($config);
}

            

Defined in: yii\base\BaseObject::__get()

Returns the value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $object->property;.

See also __set().

Source code

                public function __get($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter();
    } elseif (method_exists($this, 'set' . $name)) {
        throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
    }
    throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}

            
public boolean __isset ( $name ) $name string

The property name or the event name

return boolean

Whether the named property is set (not null).

Source code

                public function __isset($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter() !== null;
    }
    return false;
}

            

Defined in: yii\base\BaseObject::__set()

Sets value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $object->property = $value;.

See also __get().

Source code

                public function __set($name, $value)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter($value);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
    } else {
        throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
    }
}

            

Builds the full string for the column's schema.

Source code

                public function __toString()
{
    switch ($this->getTypeCategory()) {
        case self::CATEGORY_PK:
            $format = '{type}{check}{comment}{append}';
            break;
        default:
            $format = '{type}{length}{notnull}{unique}{default}{check}{comment}{append}';
    }
    return $this->buildCompleteString($format);
}

            

Defined in: yii\base\BaseObject::__unset()

Sets an object property to null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($object->property).

Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.

See also https://www.php.net/manual/en/function.unset.php.

Source code

                public function __unset($name)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter(null);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
    }
}

            

Adds an AFTER constraint to the column.

Note: MySQL, Oracle and Cubrid support only.

public $this after ( $after ) $after string

The column after which $this column will be added.

Source code

                public function after($after)
{
    $this->after = $after;
    return $this;
}

            

Specify additional SQL to be appended to column definition.

Position modifiers will be appended after column definition in databases that support them.

Source code

                public function append($sql)
{
    $this->append = $sql;
    return $this;
}

            

Builds the after constraint for the column. Defaults to unsupported.

Source code

                protected function buildAfterString()
{
    return '';
}

            

Builds the custom string that's appended to column definition.

Source code

                protected function buildAppendString()
{
    return $this->append !== null ? ' ' . $this->append : '';
}

            

Builds the check constraint for the column.

Source code

                protected function buildCheckString()
{
    return $this->check !== null ? " CHECK ({$this->check})" : '';
}

            

Returns the complete column definition from input format.

Source code

                protected function buildCompleteString($format)
{
    $placeholderValues = [
        '{type}' => $this->type,
        '{length}' => $this->buildLengthString(),
        '{unsigned}' => $this->buildUnsignedString(),
        '{notnull}' => $this->buildNotNullString(),
        '{unique}' => $this->buildUniqueString(),
        '{default}' => $this->buildDefaultString(),
        '{check}' => $this->buildCheckString(),
        '{comment}' => $this->buildCommentString(),
        '{pos}' => $this->isFirst ? $this->buildFirstString() : $this->buildAfterString(),
        '{append}' => $this->buildAppendString(),
    ];
    return strtr($format, $placeholderValues);
}

            

Builds the default value specification for the column.

Source code

                protected function buildDefaultString()
{
    $defaultValue = $this->buildDefaultValue();
    if ($defaultValue === null) {
        return '';
    }
    return ' DEFAULT ' . $defaultValue;
}

            

Return the default value for the column.

Source code

                protected function buildDefaultValue()
{
    if ($this->default === null) {
        return $this->isNotNull === false ? 'NULL' : null;
    }
    switch (gettype($this->default)) {
        case 'double':
            
            $defaultValue = StringHelper::floatToString($this->default);
            break;
        case 'boolean':
            $defaultValue = $this->default ? 'TRUE' : 'FALSE';
            break;
        case 'integer':
        case 'object':
            $defaultValue = (string) $this->default;
            break;
        default:
            $defaultValue = "'{$this->default}'";
    }
    return $defaultValue;
}

            

Builds the first constraint for the column. Defaults to unsupported.

Source code

                protected function buildFirstString()
{
    return '';
}

            

Builds the length/precision part of the column.

Source code

                protected function buildLengthString()
{
    if ($this->length === null || $this->length === []) {
        return '';
    }
    if (is_array($this->length)) {
        $this->length = implode(',', $this->length);
    }
    return "({$this->length})";
}

            

Builds the not null constraint for the column.

Source code

                protected function buildNotNullString()
{
    if ($this->isNotNull === true) {
        return ' NOT NULL';
    } elseif ($this->isNotNull === false) {
        return ' NULL';
    }
    return '';
}

            

Builds the unique constraint for the column.

Source code

                protected function buildUniqueString()
{
    return $this->isUnique ? ' UNIQUE' : '';
}

            

Builds the unsigned string for column. Defaults to unsupported.

Source code

                protected function buildUnsignedString()
{
    return '';
}

            

Defined in: yii\base\BaseObject::canGetProperty()

Returns a value indicating whether a property can be read.

A property is readable if:

See also canSetProperty().

Source code

                public function canGetProperty($name, $checkVars = true)
{
    return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}

            

Defined in: yii\base\BaseObject::canSetProperty()

Returns a value indicating whether a property can be set.

A property is writable if:

See also canGetProperty().

public boolean canSetProperty ( $name, $checkVars true ) $name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property can be written

Source code

                public function canSetProperty($name, $checkVars = true)
{
    return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}

            

Sets a CHECK constraint for the column.

public $this check ( $check ) $check string

The SQL of the CHECK constraint to be added.

Source code

                public function check($check)
{
    $this->check = $check;
    return $this;
}

            

Deprecated since 2.0.14. On PHP >=5.5, use ::class instead.

Source code

                public static function className()
{
    return get_called_class();
}

            

Specify the default SQL expression for the column.

Source code

                public function defaultExpression($default)
{
    $this->default = new Expression($default);
    return $this;
}

            

Specify the default value for the column.

Source code

                public function defaultValue($default)
{
    if ($default === null) {
        $this->null();
    }
    $this->default = $default;
    return $this;
}

            

Adds an FIRST constraint to the column.

Note: MySQL, Oracle and Cubrid support only.

Source code

                public function first()
{
    $this->isFirst = true;
    return $this;
}

            

Source code

                public function getCategoryMap()
{
    return static::$typeCategoryMap;
}

            

Returns the category of the column type.

Source code

                protected function getTypeCategory()
{
    return isset($this->categoryMap[$this->type]) ? $this->categoryMap[$this->type] : null;
}

            

Defined in: yii\base\BaseObject::hasMethod()

Returns a value indicating whether a method is defined.

The default implementation is a call to php function method_exists(). You may override this method when you implemented the php magic method __call().

Source code

                public function hasMethod($name)
{
    return method_exists($this, $name);
}

            

Defined in: yii\base\BaseObject::hasProperty()

Returns a value indicating whether a property is defined.

A property is defined if:

See also:

public boolean hasProperty ( $name, $checkVars true ) $name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property is defined

Source code

                public function hasProperty($name, $checkVars = true)
{
    return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}

            

Defined in: yii\base\BaseObject::init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

Source code

                public function init()
{
}

            

Adds a NOT NULL constraint to the column.

Source code

                public function notNull()
{
    $this->isNotNull = true;
    return $this;
}

            

Adds a NULL constraint to the column.

Source code

                public function null()
{
    $this->isNotNull = false;
    return $this;
}

            
public void setCategoryMap ( $categoryMap ) $categoryMap array

Mapping of abstract column types (keys) to type categories (values).

Source code

                public function setCategoryMap($categoryMap)
{
    static::$typeCategoryMap = $categoryMap;
}

            

Adds a UNIQUE constraint to the column.

Source code

                public function unique()
{
    $this->isUnique = true;
    return $this;
}

            

Marks column as unsigned.

Source code

                public function unsigned()
{
    switch ($this->type) {
        case Schema::TYPE_PK:
            $this->type = Schema::TYPE_UPK;
            break;
        case Schema::TYPE_BIGPK:
            $this->type = Schema::TYPE_UBIGPK;
            break;
    }
    $this->isUnsigned = true;
    return $this;
}

            

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4