@@ -105,9 +105,9 @@ public function getTables(): array
105105
106106 while ($ row = $ rows ->fetch ()) {
107107 $ tables [] = [
108- 'name ' => $ row ['TABLE_SCHEMA ' ] . '. ' . $ row ['TABLE_NAME ' ],
108+ 'name ' => ( string ) $ row ['TABLE_SCHEMA ' ] . '. ' . ( string ) $ row ['TABLE_NAME ' ],
109109 'view ' => ($ row ['TABLE_TYPE ' ] ?? null ) === 'VIEW ' ,
110- 'comment ' => $ row ['comment ' ] ?? '' ,
110+ 'comment ' => ( string ) ( $ row ['comment ' ] ?? '' ) ,
111111 ];
112112 }
113113
@@ -168,28 +168,30 @@ public function getIndexes(string $table): array
168168
169169 $ rows = $ this ->connection ->query (<<<'X'
170170 SELECT
171- name_index = ind.name,
172- id_column = ic.index_column_id,
173- name_column = col.name,
174- ind.is_unique,
175- ind.is_primary_key
171+ ind.name AS name,
172+ col.name AS [column],
173+ ind.is_unique,
174+ ind.is_primary_key
176175 FROM
177176 sys.indexes ind
178- INNER JOIN sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id
179- INNER JOIN sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id
177+ INNER JOIN sys.index_columns ic ON ind.object_id = ic.object_id AND ind.index_id = ic.index_id
178+ INNER JOIN sys.columns col ON ic.object_id = col.object_id AND ic.column_id = col.column_id
180179 INNER JOIN sys.tables t ON ind.object_id = t.object_id
181180 WHERE
182- t.name = ?
181+ t.name = ?
183182 ORDER BY
184- t.name, ind.name, ind.index_id , ic.index_column_id
183+ ind.name, ic.index_column_id
185184 X, $ table_name );
186185
187186 while ($ row = $ rows ->fetch ()) {
188- $ id = $ row ['name_index ' ];
189- $ indexes [$ id ]['name ' ] = $ id ;
190- $ indexes [$ id ]['unique ' ] = $ row ['is_unique ' ] !== 'False ' ;
191- $ indexes [$ id ]['primary ' ] = $ row ['is_primary_key ' ] !== 'False ' ;
192- $ indexes [$ id ]['columns ' ][$ row ['id_column ' ] - 1 ] = $ row ['name_column ' ];
187+ $ id = (string ) $ row ['name ' ];
188+ $ indexes [$ id ] ??= [
189+ 'name ' => $ id ,
190+ 'unique ' => $ row ['is_unique ' ] !== 'False ' ,
191+ 'primary ' => $ row ['is_primary_key ' ] !== 'False ' ,
192+ 'columns ' => [],
193+ ];
194+ $ indexes [$ id ]['columns ' ][] = (string ) $ row ['column ' ];
193195 }
194196
195197 return array_values ($ indexes );
@@ -203,10 +205,10 @@ public function getForeignKeys(string $table): array
203205
204206 $ rows = $ this ->connection ->query (<<<'X'
205207 SELECT
206- obj.name AS [fk_name] ,
207- col1.name AS [column] ,
208- tab2.name AS [referenced_table ],
209- col2.name AS [referenced_column ]
208+ obj.name AS name ,
209+ col1.name AS local ,
210+ tab2.name AS [table ],
211+ col2.name AS [foreign ]
210212 FROM
211213 sys.foreign_key_columns fkc
212214 INNER JOIN sys.objects obj
@@ -220,20 +222,21 @@ public function getForeignKeys(string $table): array
220222 INNER JOIN sys.tables tab2
221223 ON tab2.object_id = fkc.referenced_object_id
222224 INNER JOIN sys.columns col2
223- ON col2.column_id = referenced_column_id AND col2.object_id = tab2.object_id
225+ ON col2.column_id = referenced_column_id AND col2.object_id = tab2.object_id
224226 WHERE
225227 tab1.name = ?
226228 X, $ table_name );
227229
228- $ id = 0 ;
229230 while ($ row = $ rows ->fetch ()) {
230- $ keys [$ id ]['name ' ] = $ row ['fk_name ' ];
231- $ keys [$ id ]['local ' ] = $ row ['column ' ];
232- $ keys [$ id ]['table ' ] = $ table_schema . '. ' . $ row ['referenced_table ' ];
233- $ keys [$ id ++]['foreign ' ] = $ row ['referenced_column ' ];
231+ $ keys [] = [
232+ 'name ' => (string ) $ row ['name ' ],
233+ 'local ' => (string ) $ row ['local ' ],
234+ 'table ' => $ table_schema . '. ' . $ row ['table ' ],
235+ 'foreign ' => (string ) $ row ['foreign ' ],
236+ ];
234237 }
235238
236- return array_values ( $ keys) ;
239+ return $ keys ;
237240 }
238241
239242
0 commit comments