1 | <?php |
||
36 | trait MySQLiByDanielGPqueries |
||
37 | { |
||
38 | |||
39 | private function sCleanParameters(&$parameters) |
||
51 | |||
52 | /** |
||
53 | * Internal function to manage concatenation for filters |
||
54 | * |
||
55 | * @param type $filterValue |
||
56 | * @return string |
||
57 | */ |
||
58 | private function sGlueFilterValueIntoWhereString($filterValue) |
||
65 | |||
66 | private function sGlueFilterValueIntoWhereStringFinal($filterValue) |
||
82 | |||
83 | /** |
||
84 | * Internal function to concatenate filters |
||
85 | * |
||
86 | * @param array $filters |
||
87 | * @return type |
||
88 | */ |
||
89 | private function sGlueFiltersIntoWhereArrayFilter($filters) |
||
93 | |||
94 | /** |
||
95 | * Internal function to manage the filters passed to the query |
||
96 | * |
||
97 | * @param array $filterArray |
||
98 | * @param string $tableToApplyFilterTo |
||
99 | * @return string |
||
100 | */ |
||
101 | private function sManageDynamicFilters($filterArray = null, $tableToApplyFilterTo = '') |
||
112 | |||
113 | private function sManageDynamicFiltersFinal($filters) |
||
121 | |||
122 | /** |
||
123 | * Query to list Databases |
||
124 | * |
||
125 | * @param type $excludeSystemDbs |
||
126 | * @return type |
||
127 | */ |
||
128 | protected function sQueryMySqlActiveDatabases($excludeSystemDbs = true) |
||
129 | { |
||
130 | $sDBs = 'WHERE ' |
||
131 | . '`SCHEMA_NAME` NOT IN ("' |
||
132 | . implode('", "', ['information_schema', 'mysql', 'performance_schema', 'sys']) . '") '; |
||
133 | return 'SELECT ' |
||
134 | . '`SCHEMA_NAME` As `Db`, `DEFAULT_CHARACTER_SET_NAME` AS `DbCharset`, ' |
||
135 | . '`DEFAULT_COLLATION_NAME` AS `DbCollation` ' |
||
136 | . 'FROM `information_schema`.`SCHEMATA` ' |
||
137 | . ($excludeSystemDbs ? $sDBs : '') |
||
138 | . 'GROUP BY `SCHEMA_NAME`;'; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Query to list MySQL engines |
||
143 | * |
||
144 | * @param string $onlyActiveOnes |
||
145 | * @return type |
||
146 | */ |
||
147 | protected function sQueryMySqlActiveEngines($onlyActiveOnes = true) |
||
148 | { |
||
149 | return 'SELECT ' |
||
150 | . '`ENGINE` AS `Engine`, `SUPPORT` AS `Support`, `COMMENT` AS `Comment` ' |
||
151 | . 'FROM `information_schema`.`ENGINES` ' |
||
152 | . ($onlyActiveOnes ? 'WHERE (`SUPPORT` IN ("DEFAULT", "YES")) ' : '') |
||
153 | . 'GROUP BY `ENGINE`;'; |
||
154 | } |
||
155 | |||
156 | protected function sQueryMySqlColumns($filterArray = null) |
||
157 | { |
||
158 | return 'SELECT ' |
||
159 | . '`C`.`TABLE_SCHEMA`, ' |
||
160 | . $this->sQueryMySqlColumnsColumns() . ' ' |
||
161 | . 'FROM `information_schema`.`COLUMNS` `C` ' |
||
162 | . 'LEFT JOIN `information_schema`.`KEY_COLUMN_USAGE` `KCU` ON ((' . implode(') AND (', [ |
||
163 | '`C`.`TABLE_SCHEMA` = `KCU`.`TABLE_SCHEMA`', |
||
164 | '`C`.`TABLE_NAME` = `KCU`.`TABLE_NAME`', |
||
165 | '`C`.`COLUMN_NAME` = `KCU`.`COLUMN_NAME`', |
||
166 | ]) . ')) ' |
||
167 | . $this->sManageDynamicFilters($filterArray, 'C') |
||
168 | . 'GROUP BY `C`.`TABLE_SCHEMA`, `C`.`TABLE_NAME`, `C`.`COLUMN_NAME` ' |
||
169 | . 'ORDER BY `C`.`TABLE_SCHEMA`, `C`.`TABLE_NAME`, `C`.`ORDINAL_POSITION`;'; |
||
170 | } |
||
171 | |||
172 | protected function sQueryMySqlColumnsColumns() |
||
180 | |||
181 | protected function sQueryGenericSelectKeyValue($parameters) |
||
193 | |||
194 | /** |
||
195 | * Query to list Global Variables |
||
196 | * |
||
197 | * @return string |
||
198 | */ |
||
199 | protected function sQueryMySqlGlobalVariables() |
||
203 | |||
204 | /** |
||
205 | * Query |
||
206 | * |
||
207 | * @param array $filterArray |
||
208 | * @return string |
||
209 | */ |
||
210 | protected function sQueryMySqlIndexes($filterArray = null) |
||
211 | { |
||
212 | return 'SELECT ' |
||
213 | . '`KCU`.`CONSTRAINT_SCHEMA`, ' |
||
214 | . $this->sQueryMySqlIndexesColumns() . ' ' |
||
215 | . 'FROM `information_schema`.`KEY_COLUMN_USAGE` `KCU` ' |
||
216 | . 'INNER JOIN `information_schema`.`COLUMNS` `C` ON ((' . implode(') AND (', [ |
||
217 | '`C`.`TABLE_SCHEMA` = `KCU`.`TABLE_SCHEMA`', |
||
218 | '`C`.`TABLE_NAME` = `KCU`.`TABLE_NAME`', |
||
219 | '`C`.`COLUMN_NAME` = `KCU`.`COLUMN_NAME`', |
||
220 | ]) . ')) ' |
||
221 | . 'LEFT JOIN `information_schema`.`REFERENTIAL_CONSTRAINTS` `RC` ON ((' . implode(') AND (', [ |
||
222 | '`KCU`.`CONSTRAINT_SCHEMA` = `RC`.`CONSTRAINT_SCHEMA`', |
||
223 | '`KCU`.`CONSTRAINT_NAME` = `RC`.`CONSTRAINT_NAME`', |
||
224 | ]) . ')) ' |
||
225 | . $this->sManageDynamicFilters($filterArray, 'KCU') |
||
226 | . 'ORDER BY `KCU`.`TABLE_SCHEMA`, `KCU`.`TABLE_NAME`' |
||
227 | . $this->xtraSoring($filterArray, 'COLUMN_NAME') . ';'; |
||
228 | } |
||
229 | |||
230 | protected function sQueryMySqlIndexesColumns() |
||
238 | |||
239 | /** |
||
240 | * The MySQL server time |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | protected function sQueryMySqlServerTime() |
||
248 | |||
249 | private function sQueryMySqlStatisticPattern($tblName, $lnkDbCol, $adtnlCol = null, $adtnlFltr = null) |
||
250 | { |
||
251 | $tblAls = substr($tblName, 0, 1); |
||
257 | |||
258 | protected function sQueryMySqlStatistics($filterArray = null) |
||
274 | |||
275 | /** |
||
276 | * Query to get list of tables |
||
277 | * |
||
278 | * @param type $filterArray |
||
279 | * @return string |
||
280 | */ |
||
281 | protected function sQueryMySqlTables($filterArray = null) |
||
292 | |||
293 | /** |
||
294 | * Get all the row details from a table based on given filter |
||
295 | * |
||
296 | * @param array $parameters |
||
297 | * @return string |
||
298 | */ |
||
299 | protected function sQueryRowsFromTable($parameters) |
||
306 | |||
307 | protected function sQueryToDeleteSingleIdentifier($parameters) |
||
314 | |||
315 | private function xtraSoring($filterArray, $filterValueToDecide) |
||
332 | } |
||
333 |