@@ -40,31 +40,30 @@ class Grammar extends BaseGrammar
40
40
protected $ modifiers = ['Nullable ' , 'Default ' , 'GeneratedAs ' , 'Invisible ' , 'Increment ' , 'UseSequence ' ];
41
41
42
42
/**
43
- * Compile the query to determine the tables.
44
- *
45
- * @param $schema
46
- * @return string
43
+ * @inheritDoc
47
44
*/
48
45
public function compileTables ($ schema )
49
46
{
50
47
return implode (' ' , [
51
48
'select ' ,
52
49
implode (', ' , [
53
- 'table_name as name ' ,
50
+ 'table_name as ` name` ' ,
54
51
'table_schema as `schema` ' ,
55
- 'parent_table_name as parent ' ,
52
+ 'parent_table_name as ` parent` ' ,
56
53
]),
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` '
60
62
]);
61
63
}
62
64
63
65
/**
64
- * Compile the query to determine the columns.
65
- *
66
- * @param string $table
67
- * @return string
66
+ * @inheritDoc
68
67
*/
69
68
public function compileColumns ($ schema , $ table )
70
69
{
@@ -76,17 +75,15 @@ public function compileColumns($schema, $table)
76
75
'is_nullable as `nullable` ' ,
77
76
'column_default as `default` ' ,
78
77
]),
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 ' ,
81
82
]);
82
83
}
83
84
84
85
/**
85
- * Compile the query to determine the list of indexes.
86
- *
87
- * @param string|null $schema
88
- * @param $table
89
- * @return string
86
+ * @inheritDoc
90
87
*/
91
88
public function compileIndexes ($ schema , $ table )
92
89
{
@@ -100,18 +97,14 @@ public function compileIndexes($schema, $table)
100
97
]),
101
98
'from information_schema.indexes as i ' ,
102
99
'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 ' ,
106
103
]);
107
104
}
108
105
109
106
/**
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
115
108
*/
116
109
public function compileForeignKeys ($ schema , $ table )
117
110
{
@@ -129,8 +122,8 @@ public function compileForeignKeys($schema, $table)
129
122
'from information_schema.key_column_usage kc ' ,
130
123
'join information_schema.referential_constraints rc on kc.constraint_name = rc.constraint_name ' ,
131
124
'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 ?? '' ),
134
127
'group by kc.constraint_name, cc.table_schema, cc.table_name, rc.update_rule, rc.delete_rule ' ,
135
128
]);
136
129
}
0 commit comments