You are here

function dba_describe_table in Database Administration 7

Same name and namespace in other branches
  1. 5 dba.module \dba_describe_table()

DESCRIBE table. FIXME: The tableselect is broken.

1 call to dba_describe_table()
dba_describe_tables in ./dba.admin.inc
Describe selected tables.

File

./dba.admin.inc, line 558

Code

function dba_describe_table($table) {
  static $pager_element = 0;
  $describe = dba_invoke_driver_specific('describe_table', $table);
  $count = 0;
  $header = array();
  $fields = array();
  $options = array();
  while ($row = $describe
    ->fetchAssoc()) {
    if (!$count) {
      $sort = 0;
      foreach ($row as $key => $value) {
        $fields[$key] = $key;
        $header[$key] = array(
          'data' => "{$key}",
          'field' => "{$key}",
        );
        if (!$sort++) {
          $header[$key]['sort'] = 'desc';
        }
      }
    }
    foreach ($fields as $field) {
      $options[$count][$field] = check_plain($row[$field]);
    }
    $count++;
  }
  $form[$table]['rows'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('The !table table has no fields.', array(
      '!table' => $table,
    )),
  );
  $form[$table]['pager'] = array(
    '#markup' => theme('pager', array(
      'tags' => NULL,
      'element' => $pager_element,
    )),
  );
  $pager_element++;
  return $form;
}