src/PDO/SchemaPDOMssql.php
/**
     * Collects the metadata of table columns.
     *
     * @param TableSchema $table the table metadata.
     *
     * @throws Throwable
     *
     * @return bool whether the table exists in the database.
     */
Collects the metadata of table columns.
@param TableSchema $table the table metadata.

@throws Throwable

@return bool whether the table exists in the database.
Collects the metadata of table columns . @param TableSchema $table the table metadata . @throws Throwable @return bool whether the table exists in the database .
protected function findColumns(TableSchema $table): bool
    {
        $columnsTableName = 'INFORMATION_SCHEMA.COLUMNS';
        $whereSql = '[t1].[table_name] = ' . $this->db->getQuoter()->quoteValue($table->getName());
        if ($table->getCatalogName() !== null) {
            $columnsTableName = "{$table->getCatalogName()}.$columnsTableName";
            $whereSql .= " AND [t1].[table_catalog] = '{$table->getCatalogName()}'";
        }
        if ($table->getSchemaName() !== null) {
            $whereSql .= " AND [t1].[table_schema] = '{$table->getSchemaName()}'";
        }
        $columnsTableName = $this->db->getQuoter()->quoteTableName($columnsTableName);
        $sql = <<<SQL
        SELECT
            [t1].[column_name],
            [t1].[is_nullable],
        CASE WHEN [t1].[data_type] IN ('char','varchar','nchar','nvarchar','binary','varbinary') THEN
        CASE WHEN [t1].[character_maximum_length] = NULL OR [t1].[character_maximum_length] = -1 THEN
            [t1].[data_type]
        ELSE
            [t1].[data_type] + '(' + LTRIM(RTRIM(CONVERT(CHAR,[t1].[character_maximum_length]))) + ')'
        END
        ELSE
            [t1].[data_type]
        END AS 'data_type',
        [t1].[column_default],
        COLUMNPROPERTY(OBJECT_ID([t1].[table_schema] + '.' + [t1].[table_name]), [t1].[column_name], 'IsIdentity') AS is_identity,
        (
        SELECT CONVERT(VARCHAR, [t2].[value])
        FROM [sys].[extended_properties] AS [t2]
        WHERE
        [t2].[class] = 1 AND
        [t2].[class_desc] = 'OBJECT_OR_COLUMN' AND
        [t2].[name] = 'MS_Description' AND
        [t2].[major_id] = OBJECT_ID([t1].[TABLE_SCHEMA] + '.' + [t1].[table_name]) AND
        [t2].[minor_id] = COLUMNPROPERTY(OBJECT_ID([t1].[TABLE_SCHEMA] + '.' + [t1].[TABLE_NAME]), [t1].[COLUMN_NAME], 'ColumnID')
        ) as comment
        FROM $columnsTableName AS [t1]
        WHERE $whereSql
        SQL;
        try {
            $columns = $this->db->createCommand($sql)->queryAll();
            if (empty($columns)) {
                return false;
            }
        } catch (Exception $e) {
            return false;
        }
        foreach ($columns as $column) {
            $column = $this->loadColumnSchema($column);
            foreach ($table->getPrimaryKey() as $primaryKey) {
                if (strcasecmp($column->getName(), $primaryKey) === 0) {
                    $column->primaryKey(true);
                    break;
                }
            }
            if ($column->isPrimaryKey() && $column->isAutoIncrement()) {
                $table->sequenceName('');
            }
            $table->columns($column->getName(), $column);
        }
        return true;
    }
protected function findColumns ( TableSchema $ table ) : bool { $ columnsTableName = 'INFORMATION_SCHEMA.COLUMNS' ; $ whereSql = '[t1].[table_name] = ' . $ this -> db -> getQuoter ( ) -> quoteValue ( $ table -> getName ( ) ) ; if ( $ table -> getCatalogName ( ) !== null ) { $ columnsTableName = " { $ table -> getCatalogName ( ) } . $ columnsTableName " ; $ whereSql .= "  AND [t1].[table_catalog] = ' { $ table -> getCatalogName ( ) } ' " ; } if ( $ table -> getSchemaName ( ) !== null ) { $ whereSql .= "  AND [t1].[table_schema] = ' { $ table -> getSchemaName ( ) } ' " ; } $ columnsTableName = $ this -> db -> getQuoter ( ) -> quoteTableName ( $ columnsTableName ) ; $ sql = <<< SQL         SELECT             [t1].[column_name],             [t1].[is_nullable],         CASE WHEN [t1].[data_type] IN ('char','varchar','nchar','nvarchar','binary','varbinary') THEN         CASE WHEN [t1].[character_maximum_length] = NULL OR [t1].[character_maximum_length] = -1 THEN             [t1].[data_type]         ELSE             [t1].[data_type] + '(' + LTRIM(RTRIM(CONVERT(CHAR,[t1].[character_maximum_length]))) + ')'         END         ELSE             [t1].[data_type]         END AS 'data_type',         [t1].[column_default],         COLUMNPROPERTY(OBJECT_ID([t1].[table_schema] + '.' + [t1].[table_name]), [t1].[column_name], 'IsIdentity') AS is_identity,         (         SELECT CONVERT(VARCHAR, [t2].[value])         FROM [sys].[extended_properties] AS [t2]         WHERE         [t2].[class] = 1 AND         [t2].[class_desc] = 'OBJECT_OR_COLUMN' AND         [t2].[name] = 'MS_Description' AND         [t2].[major_id] = OBJECT_ID([t1].[TABLE_SCHEMA] + '.' + [t1].[table_name]) AND         [t2].[minor_id] = COLUMNPROPERTY(OBJECT_ID([t1].[TABLE_SCHEMA] + '.' + [t1].[TABLE_NAME]), [t1].[COLUMN_NAME], 'ColumnID')         ) as comment         FROM  $ columnsTableName  AS [t1]         WHERE  $ whereSql 
        SQL ; try { $ columns = $ this -> db -> createCommand ( $ sql ) -> queryAll ( ) ; if ( empty ( $ columns ) ) { return false ; } } catch ( Exception $ e ) { return false ; } foreach ( $ columns as $ column ) { $ column = $ this -> loadColumnSchema ( $ column ) ; foreach ( $ table -> getPrimaryKey ( ) as $ primaryKey ) { if ( strcasecmp ( $ column -> getName ( ) , $ primaryKey ) === 0 ) { $ column -> primaryKey ( true ) ; break ; } } if ( $ column -> isPrimaryKey ( ) && $ column -> isAutoIncrement ( ) ) { $ table -> sequenceName ( '' ) ; } $ table -> columns ( $ column -> getName ( ) , $ column ) ; } return true ; }
Collects the metadata of table columns.
Collects the metadata of table columns .