99use function array_map ;
1010use function count ;
1111use function implode ;
12- use function is_array ;
1312use function sprintf ;
1413
1514/**
1817class Generator
1918{
2019 /**
21- * returns a segment of the SQL WHERE clause regarding table name and type
20+ * returns a segment of the SQL WHERE clause regarding table name
2221 *
23- * @param array|string $escapedTableOrTables table(s)
24- * @param bool $tblIsGroup $table is a table group
25- * @param string|null $tableType whether table or view
22+ * @param bool $tblIsGroup $table is a table group
2623 *
2724 * @return string a segment of the WHERE clause
2825 */
29- public static function getTableCondition (
30- $ escapedTableOrTables ,
31- bool $ tblIsGroup ,
32- ?string $ tableType
26+ public static function getTableNameCondition (
27+ string $ escapedTabletable ,
28+ bool $ tblIsGroup
3329 ): string {
34- // get table information from information_schema
35- if ($ escapedTableOrTables !== [] && $ escapedTableOrTables !== '' ) {
36- $ sqlWhereTable = 'AND t.`TABLE_NAME` ' ;
37- if (is_array ($ escapedTableOrTables )) {
38- $ sqlWhereTable .= Util::getCollateForIS () . ' IN ( \''
39- . implode ('\', \'' , $ escapedTableOrTables )
40- . '\') ' ;
41- } elseif ($ tblIsGroup === true ) {
42- $ sqlWhereTable .= 'LIKE \'' . Util::escapeMysqlWildcards ($ escapedTableOrTables ) . '% \'' ;
43- } else {
44- $ sqlWhereTable .= Util::getCollateForIS () . ' = \'' . $ escapedTableOrTables . '\'' ;
45- }
30+ $ sqlWhereTable = 'AND t.`TABLE_NAME` ' ;
31+ if ($ tblIsGroup === true ) {
32+ $ sqlWhereTable .= 'LIKE ' . $ escapedTabletable . '% ' ;
4633 } else {
47- $ sqlWhereTable = '' ;
34+ $ sqlWhereTable .= Util:: getCollateForIS () . ' = ' . $ escapedTabletable ;
4835 }
4936
37+ return $ sqlWhereTable ;
38+ }
39+
40+ /**
41+ * returns a segment of the SQL WHERE clause regarding table name
42+ *
43+ * @param string[] $escapedTables tables
44+ *
45+ * @return string a segment of the WHERE clause
46+ */
47+ public static function getTableNameConditionForMultiple (array $ escapedTables ): string
48+ {
49+ return 'AND t.`TABLE_NAME` ' . Util::getCollateForIS () . ' IN ( ' . implode (', ' , $ escapedTables ) . ') ' ;
50+ }
51+
52+ /**
53+ * returns a segment of the SQL WHERE clause regarding table type
54+ *
55+ * @param string|null $tableType whether table or view
56+ *
57+ * @return string a segment of the WHERE clause
58+ */
59+ public static function getTableTypeCondition (
60+ ?string $ tableType
61+ ): string {
62+ $ sqlWhereTable = '' ;
63+
5064 if ($ tableType === 'view ' ) {
5165 $ sqlWhereTable .= " AND t.`TABLE_TYPE` NOT IN ('BASE TABLE', 'SYSTEM VERSIONED') " ;
5266 } elseif ($ tableType === 'table ' ) {
@@ -59,12 +73,12 @@ public static function getTableCondition(
5973 /**
6074 * returns the beginning of the SQL statement to fetch the list of tables
6175 *
62- * @param string[] $thisDatabases databases to list
63- * @param string $sqlWhereTable additional condition
76+ * @param string $thisDatabases databases to list
77+ * @param string $sqlWhereTable additional condition
6478 *
6579 * @return string the SQL statement
6680 */
67- public static function getSqlForTablesFull (array $ thisDatabases , string $ sqlWhereTable ): string
81+ public static function getSqlForTablesFull (string $ thisDatabases , string $ sqlWhereTable ): string
6882 {
6983 return 'SELECT *, '
7084 . ' `TABLE_SCHEMA` AS `Db`, '
@@ -90,7 +104,7 @@ public static function getSqlForTablesFull(array $thisDatabases, string $sqlWher
90104 . ' `TABLE_COMMENT` AS `Comment` '
91105 . ' FROM `information_schema`.`TABLES` t '
92106 . ' WHERE `TABLE_SCHEMA` ' . Util::getCollateForIS ()
93- . ' IN ( \'' . implode ( " ', ' " , $ thisDatabases) . '\ ') '
107+ . ' IN ( ' . $ thisDatabases . ') '
94108 . ' ' . $ sqlWhereTable ;
95109 }
96110
0 commit comments