Skip to content
PHP Ecosystem
Explore

ColumnSchema

API reference › yii › db › mssql › ColumnSchema

classyii\db\mssql\ColumnSchema
Extendsyii\db\ColumnSchema » yii\base\BaseObject
Implementsyii\base\Configurable
Since2.0.23
Sourceframework/db/mssql/ColumnSchema.php

Represents the metadata of a column in a Microsoft SQL Server database table.

PropertyTypeDescriptionDefined by
$allowNullboolWhether this column can be null. Default: false.yii\db\ColumnSchema
$autoIncrementboolWhether this column is auto-incremental Default: false.yii\db\ColumnSchema
$commentstring|nullComment of this column. Default: null.yii\db\ColumnSchema
$dbTypestringThe DB type of this column. Default: ''.yii\db\ColumnSchema
$defaultValuemixedDefault value of this column Default: null.yii\db\ColumnSchema
$enumValuesarray|nullEnumerable values. Default: null.yii\db\ColumnSchema
$isComputedboolWhether this column is a computed column Default: false. Available since 2.0.39.ColumnSchema
$isPrimaryKeybool|nullWhether this column is a primary key Default: null.yii\db\ColumnSchema
$namestringName of this column (without quotes). Default: ''.yii\db\ColumnSchema
$outputColumnDeclaration read-onlystringSQL type declaration.ColumnSchema
$phpTypestringThe PHP type of this column. Default: ''.yii\db\ColumnSchema
$precisionint|nullPrecision of the column data, if it is numeric. Default: null.yii\db\ColumnSchema
$scaleint|nullScale of the column data, if it is numeric. Default: null.yii\db\ColumnSchema
$sizeint|nullDisplay size of the column. Default: null.yii\db\ColumnSchema
$typestringAbstract type of this column. Default: ''.yii\db\ColumnSchema
$unsignedboolWhether this column is unsigned. Default: false.yii\db\ColumnSchema
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\BaseObject
__get()Returns the value of an object property.yii\base\BaseObject
__isset()Checks if a property is set, i.e. defined and not null.yii\base\BaseObject
__set()Sets value of an object property.yii\base\BaseObject
__unset()Sets an object property to null.yii\base\BaseObject
canGetProperty()Returns a value indicating whether a property can be read.yii\base\BaseObject
canSetProperty()Returns a value indicating whether a property can be set.yii\base\BaseObject
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
dbTypecast()Renders a rowversion/timestamp value as an 8-byte binary literal (0x...) for WHERE comparisons, and converts varbinary strings to CONVERT(VARBINARY(MAX), 0x...) expressions to avoid conversion errors.ColumnSchema
defaultPhpTypecast()Converts a MSSQL column default value to its PHP representation.ColumnSchema
getOutputColumnDeclaration()Returns the SQL type declaration for this column inside an OUTPUT clause temp table.ColumnSchema
hasMethod()Returns a value indicating whether a method is defined.yii\base\BaseObject
hasProperty()Returns a value indicating whether a property is defined.yii\base\BaseObject
init()Initializes the object.yii\base\BaseObject
isRowVersion()Returns whether this column is a SQL Server rowversion (legacy synonym timestamp) auto-versioning column.ColumnSchema
isType()Returns whether this column uses the given abstract type.yii\db\ColumnSchema
phpTypecast()Converts the input value according to $phpType after retrieval from the database.ColumnSchema
typecast() protectedConverts the input value according to $phpType after retrieval from the database.yii\db\ColumnSchema
public function dbTypecast(mixed $value): mixed

Renders a rowversion/timestamp value as an 8-byte binary literal (0x...) for WHERE comparisons, and converts varbinary strings to CONVERT(VARBINARY(MAX), 0x...) expressions to avoid conversion errors.

Parameters

ParameterTypeDescription
$valuemixed

Returns

mixed

See also

public function defaultPhpTypecast(mixed $value): mixed

Converts a MSSQL column default value to its PHP representation.

Recognizes the literal formats stored in sys.default_constraints.definition and typecasts only those:

  • NULL or any parenthesized form such as (NULL) to null.
  • Quoted strings (('value') / (N'value'), any parenthesis depth) to the unquoted value with doubled quotes unescaped, delegated to phpTypecast().
  • Parenthesized signed, decimal, or scientific numerics (((0)), ((-5)), ((1.0e+005))) delegated to phpTypecast().
  • Binary literals ((0x...)) to their byte string via hex2bin().

Everything else; function calls such as (getdate()), operator expressions such as ((1)+(2)), or (NEXT VALUE FOR ...) sequences; becomes an executable Expression: the definition is SQL expression text and MSSQL exposes no literal-versus-expression metadata.

Parameters

ParameterTypeDescription
$valuemixedDefault value in MSSQL column_default format.

Returns

mixed: Converted value.

Since

2.0.24

public function getOutputColumnDeclaration(): string

Returns the SQL type declaration for this column inside an OUTPUT clause temp table.

Preserves the reflected declaration for variable-length types (varchar, nvarchar, varbinary), keeps the legacy (MAX) fallback for bare variable-length declarations, appends the declared size for fixed-length types (char, nchar, binary), and maps timestamp to varbinary(8) or binary(8).

Returns

string: SQL type declaration.

public function isRowVersion(): bool

Returns whether this column is a SQL Server rowversion (legacy synonym timestamp) auto-versioning column.

public function phpTypecast(mixed $value): mixed

Converts the input value according to $phpType after retrieval from the database.

Decodes a rowversion/timestamp token to its integer value, and reads varbinary streams into strings.

If the value is null or an Expression, it will not be converted.

Parameters

ParameterTypeDescription
$valuemixedInput value

Returns

mixed: Converted value