\'InnoDB\', t.DATA_FREE, 0)) AS SCHEMA_DATA_FREE'; } $sql .= ' FROM `information_schema`.SCHEMATA s '; if ($forceStats) { $sql .= ' LEFT JOIN `information_schema`.TABLES t ON BINARY t.TABLE_SCHEMA = BINARY s.SCHEMA_NAME'; } $sql .= $sqlWhereSchema . ' GROUP BY BINARY s.SCHEMA_NAME, s.DEFAULT_COLLATION_NAME' . ' ORDER BY '; if ($sortBy === 'SCHEMA_NAME' || $sortBy === 'DEFAULT_COLLATION_NAME') { $sql .= 'BINARY '; } $sql .= Util::backquote($sortBy) . ' ' . $sortOrder . $limit; $sql .= ') a'; return $sql; } public static function getInformationSchemaColumnsFullRequest( string|null $escapedDatabase, string|null $escapedTable, string|null $escapedColumn, ): string { $sqlWheres = []; // get columns information from information_schema if ($escapedDatabase !== null) { $sqlWheres[] = '`TABLE_SCHEMA` = ' . $escapedDatabase . ' '; } if ($escapedTable !== null) { $sqlWheres[] = '`TABLE_NAME` = ' . $escapedTable . ' '; } if ($escapedColumn !== null) { $sqlWheres[] = '`COLUMN_NAME` = ' . $escapedColumn . ' '; } // for PMA bc: // `[SCHEMA_FIELD_NAME]` AS `[SHOW_FULL_COLUMNS_FIELD_NAME]` $sql = 'SELECT *,' . ' `COLUMN_NAME` AS `Field`,' . ' `COLUMN_TYPE` AS `Type`,' . ' `COLLATION_NAME` AS `Collation`,' . ' `IS_NULLABLE` AS `Null`,' . ' `COLUMN_KEY` AS `Key`,' . ' `COLUMN_DEFAULT` AS `Default`,' . ' `EXTRA` AS `Extra`,' . ' `PRIVILEGES` AS `Privileges`,' . ' `COLUMN_COMMENT` AS `Comment`' . ' FROM `information_schema`.`COLUMNS`'; if ($sqlWheres !== []) { $sql .= "\n" . ' WHERE ' . implode(' AND ', $sqlWheres); } return $sql; } /** @return string[] */ public static function getInformationSchemaColumns( string|null $database, string|null $table, string|null $column, ): array { $arrayKeys = []; if ($database === null) { $arrayKeys[] = 'TABLE_SCHEMA'; } if ($table === null) { $arrayKeys[] = 'TABLE_NAME'; } if ($column === null) { $arrayKeys[] = 'COLUMN_NAME'; } return $arrayKeys; } /** * Function to get sql query for renaming the index using SQL RENAME INDEX Syntax */ public static function getSqlQueryForIndexRename( string $dbName, string $tableName, string $oldIndexName, string $newIndexName, ): string { return sprintf( 'ALTER TABLE %s.%s RENAME INDEX %s TO %s;', Util::backquote($dbName), Util::backquote($tableName), Util::backquote($oldIndexName), Util::backquote($newIndexName), ); } /** * Function to get sql query to re-order the table */ public static function getQueryForReorderingTable( string $table, string $orderField, string|null $order, ): string { return 'ALTER TABLE ' . Util::backquote($table) . ' ORDER BY ' . Util::backquote($orderField) . ($order === 'desc' ? ' DESC;' : ' ASC;'); } /** * Function to get sql query to partition the table * * @param string[] $partitionNames */ public static function getQueryForPartitioningTable( string $table, string $partitionOperation, array $partitionNames, ): string { $sqlQuery = 'ALTER TABLE ' . Util::backquote($table) . ' ' . $partitionOperation . ' PARTITION '; if ($partitionOperation === 'COALESCE') { return $sqlQuery . count($partitionNames); } return $sqlQuery . implode(', ', $partitionNames) . ';'; } /** @param string[] $selectedColumns */ public static function getAddIndexSql(string $indexType, string $table, array $selectedColumns): string { $columnsSql = implode(', ', array_map(Util::backquote(...), $selectedColumns)); return 'ALTER TABLE ' . Util::backquote($table) . ' ADD ' . $indexType . '(' . $columnsSql . ');'; } /** * Builds the SQL insert query * * @param bool $isInsertIgnore $_POST['submit_type'] === 'insertignore' * @param string[] $queryFields column names array * @param string[] $valueSets array of query values */ public static function buildInsertSqlQuery( string $table, bool $isInsertIgnore, array $queryFields, array $valueSets, ): string { return ($isInsertIgnore ? 'INSERT IGNORE ' : 'INSERT ') . 'INTO ' . Util::backquote($table) . ' (' . implode(', ', $queryFields) . ') VALUES (' . implode('), (', $valueSets) . ')'; } }