ColumnSchema
API reference › yii › db › mssql › ColumnSchema
Represents the metadata of a column in a Microsoft SQL Server database table.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$allowNull | bool | Whether this column can be null. Default: false. | yii\ |
$autoIncrement | bool | Whether this column is auto-incremental Default: false. | yii\ |
$comment | string| | Comment of this column. Default: null. | yii\ |
$dbType | string | The DB type of this column. Default: ''. | yii\ |
$defaultValue | mixed | Default value of this column Default: null. | yii\ |
$enumValues | array| | Enumerable values. Default: null. | yii\ |
$isComputed | bool | Whether this column is a computed column Default: false. Available since 2.0.39. | ColumnSchema |
$isPrimaryKey | bool| | Whether this column is a primary key Default: null. | yii\ |
$name | string | Name of this column (without quotes). Default: ''. | yii\ |
$outputColumnDeclaration read-only | string | SQL type declaration. | ColumnSchema |
$phpType | string | The PHP type of this column. Default: ''. | yii\ |
$precision | int| | Precision of the column data, if it is numeric. Default: null. | yii\ |
$scale | int| | Scale of the column data, if it is numeric. Default: null. | yii\ |
$size | int| | Display size of the column. Default: null. | yii\ |
$type | string | Abstract type of this column. Default: ''. | yii\ |
$unsigned | bool | Whether this column is unsigned. Default: false. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
dbTypecast() | Renders a rowversion/timestamp value as an 8-byte binary literal (0x...) for WHERE comparisons, and converts varbinary strings to CONVERT(VARBINARY(MAX), 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\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
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\ |
phpTypecast() | Converts the input value according to $phpType after retrieval from the database. | ColumnSchema |
typecast() protected | Converts the input value according to $phpType after retrieval from the database. | yii\ |
Method details
Section titled “Method details”dbTypecast()
Section titled “dbTypecast() ”public function dbTypecast(mixed $value): mixedRenders 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
| Parameter | Type | Description |
|---|---|---|
$value | mixed |
Returns
mixed
See also
defaultPhpTypecast()
Section titled “defaultPhpTypecast() ”public function defaultPhpTypecast(mixed $value): mixedConverts a MSSQL column default value to its PHP representation.
Recognizes the literal formats stored in sys.default_constraints.definition and typecasts only those:
NULLor any parenthesized form such as(NULL)tonull.- Quoted strings (
('value')/(N'value'), any parenthesis depth) to the unquoted value with doubled quotes unescaped, delegated tophpTypecast(). - Parenthesized signed, decimal, or scientific numerics (
((0)),((-5)),((1.0e+005))) delegated tophpTypecast(). - Binary literals (
(0x...)) to their byte string viahex2bin().
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
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Default value in MSSQL column_default format. |
Returns
mixed: Converted value.
Since
2.0.24
getOutputColumnDeclaration()
Section titled “getOutputColumnDeclaration() ”public function getOutputColumnDeclaration(): stringReturns 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.
isRowVersion()
Section titled “isRowVersion() ”public function isRowVersion(): boolReturns whether this column is a SQL Server rowversion (legacy synonym timestamp) auto-versioning column.
Returns
bool
See also
phpTypecast()
Section titled “phpTypecast() ”public function phpTypecast(mixed $value): mixedConverts 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
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Input value |
Returns
mixed: Converted value