protected function DbDumpCommand::getFieldOrder in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Command/DbDumpCommand.php \Drupal\Core\Command\DbDumpCommand::getFieldOrder()
Gets field ordering for a given table.
Parameters
\Drupal\Core\Database\Connection $connection: The database connection to use.
string $table: The table name.
Return value
string The order string to append to the query.
1 call to DbDumpCommand::getFieldOrder()
- DbDumpCommand::getTableData in core/
lib/ Drupal/ Core/ Command/ DbDumpCommand.php - Gets all data from a given table.
File
- core/
lib/ Drupal/ Core/ Command/ DbDumpCommand.php, line 350 - Contains \Drupal\Core\Command\DbDumpCommand.
Class
- DbDumpCommand
- Provides a command to dump the current database to a script.
Namespace
Drupal\Core\CommandCode
protected function getFieldOrder(Connection $connection, $table) {
// @todo this is MySQL only since there are no Database API functions for
// table column data.
// @todo this code is duplicated in `core/scripts/migrate-db.sh`.
$connection_info = $connection
->getConnectionOptions();
// Order by primary keys.
$order = '';
$query = "SELECT `COLUMN_NAME` FROM `information_schema`.`COLUMNS`\n WHERE (`TABLE_SCHEMA` = '" . $connection_info['database'] . "')\n AND (`TABLE_NAME` = '{" . $table . "}') AND (`COLUMN_KEY` = 'PRI')\n ORDER BY COLUMN_NAME";
$results = $connection
->query($query);
while (($row = $results
->fetchAssoc()) !== FALSE) {
$order .= $row['COLUMN_NAME'] . ', ';
}
if (!empty($order)) {
$order = ' ORDER BY ' . rtrim($order, ', ');
}
return $order;
}