DbDumpCommand::getFieldOrder

protected DbDumpCommand::getFieldOrder(Connection $connection, $table)

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.

File

core/lib/Drupal/Core/Command/DbDumpCommand.php, line 345

Class

DbDumpCommand
Provides a command to dump the current database to a script.

Namespace

Drupal\Core\Command

Code

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`
    WHERE (`TABLE_SCHEMA` = '" . $connection_info['database'] . "')
    AND (`TABLE_NAME` = '{" . $table . "}') AND (`COLUMN_KEY` = 'PRI')
    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;
}
doc_Drupal
2016-10-29 09:01:08
Comments
Leave a Comment

Please login to continue.