@@ -40,31 +40,30 @@ class Grammar extends BaseGrammar
4040 protected $ modifiers = ['Nullable ' , 'Default ' , 'GeneratedAs ' , 'Invisible ' , 'Increment ' , 'UseSequence ' ];
4141
4242 /**
43- * Compile the query to determine the tables.
44- *
45- * @param $schema
46- * @return string
43+ * @inheritDoc
4744 */
4845 public function compileTables ($ schema )
4946 {
5047 return implode (' ' , [
5148 'select ' ,
5249 implode (', ' , [
53- 'table_name as name ' ,
50+ 'table_name as ` name` ' ,
5451 'table_schema as `schema` ' ,
55- 'parent_table_name as parent ' ,
52+ 'parent_table_name as ` parent` ' ,
5653 ]),
57- 'from information_schema.tables ' ,
58- 'where table_type = \'BASE TABLE \'' ,
59- 'and table_schema = \'\'' ,
54+ 'from `information_schema`.`tables` ' ,
55+ 'where `table_type` = \'BASE TABLE \'' ,
56+ (match (true ) {
57+ is_array ($ schema ) => 'and `table_schema` in ( ' . $ this ->quoteString ($ schema ) . ') ' ,
58+ !is_null ($ schema ) => 'and `table_schema` = ' . $ this ->quoteString ($ schema ),
59+ default => '' ,
60+ }),
61+ 'order by `table_schema`, `table_name` '
6062 ]);
6163 }
6264
6365 /**
64- * Compile the query to determine the columns.
65- *
66- * @param string $table
67- * @return string
66+ * @inheritDoc
6867 */
6968 public function compileColumns ($ schema , $ table )
7069 {
@@ -76,17 +75,15 @@ public function compileColumns($schema, $table)
7675 'is_nullable as `nullable` ' ,
7776 'column_default as `default` ' ,
7877 ]),
79- 'from information_schema.columns ' ,
80- 'where table_name = ' . $ this ->quoteString ($ table ),
78+ 'from `information_schema`.`columns` ' ,
79+ 'where `table_name` = ' . $ this ->quoteString ($ table ),
80+ 'and table_schema = ' . $ this ->quoteString ($ schema ?? '' ),
81+ 'order by `ordinal_position` asc ' ,
8182 ]);
8283 }
8384
8485 /**
85- * Compile the query to determine the list of indexes.
86- *
87- * @param string|null $schema
88- * @param $table
89- * @return string
86+ * @inheritDoc
9087 */
9188 public function compileIndexes ($ schema , $ table )
9289 {
@@ -100,18 +97,14 @@ public function compileIndexes($schema, $table)
10097 ]),
10198 'from information_schema.indexes as i ' ,
10299 'join information_schema.index_columns as c on i.table_schema = c.table_schema and i.table_name = c.table_name and i.index_name = c.index_name ' ,
103- 'where i.table_schema = ' . $ this ->quoteString ('' ),
104- 'and i.table_name = ' . $ this ->quoteString ($ table ),
105- 'group by i.index_name, i.index_type, i.is_unique ' ,
100+ 'where i.table_name = ' . $ this ->quoteString ($ table ),
101+ 'and i.table_schema = ' . $ this ->quoteString ($ schema ?? '' ),
102+ 'group by i.index_name, i.index_type, i.is_unique, i.table_schema ' ,
106103 ]);
107104 }
108105
109106 /**
110- * Compile the query to determine the list of foreign keys.
111- *
112- * @param string|null $schema
113- * @param $table
114- * @return string
107+ * @inheritDoc
115108 */
116109 public function compileForeignKeys ($ schema , $ table )
117110 {
@@ -129,8 +122,8 @@ public function compileForeignKeys($schema, $table)
129122 'from information_schema.key_column_usage kc ' ,
130123 'join information_schema.referential_constraints rc on kc.constraint_name = rc.constraint_name ' ,
131124 'join information_schema.constraint_column_usage cc on kc.constraint_name = cc.constraint_name ' ,
132- 'where kc.table_schema = "" ' ,
133- 'and kc.table_name = ' . $ this ->quoteString ($ table ),
125+ 'where kc.table_name = ' . $ this -> quoteString ( $ table ) ,
126+ 'and kc.table_schema = ' . $ this ->quoteString ($ schema ?? '' ),
134127 'group by kc.constraint_name, cc.table_schema, cc.table_name, rc.update_rule, rc.delete_rule ' ,
135128 ]);
136129 }
0 commit comments