@@ -42,15 +42,20 @@ public function listTablesSql($config)
42
42
*/
43
43
public function describeColumnSql ($ tableName , $ config )
44
44
{
45
- $ sql = "SELECT DISTINCT TABLE_SCHEMA AS [schema], COLUMN_NAME AS [name], DATA_TYPE AS [type],
46
- IS_NULLABLE AS [null], COLUMN_DEFAULT AS [default],
47
- CHARACTER_MAXIMUM_LENGTH AS [char_length],
48
- NUMERIC_PRECISION AS [precision],
49
- NUMERIC_SCALE AS [scale],
50
- '' AS [comment], ORDINAL_POSITION AS [ordinal_position]
51
- FROM INFORMATION_SCHEMA.COLUMNS
52
- WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?
53
- ORDER BY ordinal_position " ;
45
+ $ sql = "SELECT DISTINCT
46
+ AC.name AS [name],
47
+ TY.name AS [type],
48
+ AC.max_length AS [char_length],
49
+ AC.precision AS [precision],
50
+ AC.scale AS [scale],
51
+ AC.is_identity AS [autoincrement],
52
+ AC.is_nullable AS [null],
53
+ OBJECT_DEFINITION(AC.default_object_id) AS [default]
54
+ FROM sys.[tables] T
55
+ INNER JOIN sys.[schemas] S ON S.[schema_id] = T.[schema_id]
56
+ INNER JOIN sys.[all_columns] AC ON T.[object_id] = AC.[object_id]
57
+ INNER JOIN sys.[types] TY ON TY.[user_type_id] = AC.[user_type_id]
58
+ WHERE T.[name] = ? AND S.[name] = ? " ;
54
59
55
60
$ schema = empty ($ config ['schema ' ]) ? static ::DEFAULT_SCHEMA_NAME : $ config ['schema ' ];
56
61
return [$ sql , [$ tableName , $ schema ]];
@@ -146,13 +151,15 @@ public function convertColumnDescription(Table $table, $row)
146
151
if (!empty ($ row ['default ' ])) {
147
152
$ row ['default ' ] = trim ($ row ['default ' ], '() ' );
148
153
}
149
-
154
+ if (!empty ($ row ['autoincrement ' ])) {
155
+ $ field ['autoIncrement ' ] = true ;
156
+ }
150
157
if ($ field ['type ' ] === 'boolean ' ) {
151
158
$ row ['default ' ] = (int )$ row ['default ' ];
152
159
}
153
160
154
161
$ field += [
155
- 'null ' => $ row ['null ' ] === 'YES ' ? true : false ,
162
+ 'null ' => $ row ['null ' ] === '1 ' ? true : false ,
156
163
'default ' => $ row ['default ' ],
157
164
];
158
165
$ table ->addColumn ($ row ['name ' ], $ field );
0 commit comments