You are here

function dba_query_form_pre_render in Database Administration 5

1 string reference to 'dba_query_form_pre_render'
dba_query_form in ./dba.module

File

./dba.module, line 798
Allows administrators direct access to their Drupal database. Written by Jeremy Andrews <jeremy@kerneltrap.org>, June 2004. PostgreSQL functionality provided by AAM <aam@ugpl.de> Major security audit, porting, and maintenance by Derek…

Code

function dba_query_form_pre_render($form_id, &$form) {

  // If there are no validation errors and there's already a query,
  // run it and display the results.
  $dba_query = $form['query']['dba_query']['#value'];
  if (!form_get_errors() && !empty($dba_query)) {

    // Execute each sql statement individually.
    $i = 0;
    foreach (explode(';', $dba_query) as $sql) {
      $header = NULL;
      if (trim($sql) == '') {
        break;
      }
      $result = dba_execute_query($sql);
      if ($result && $result != 1 && db_num_rows($result)) {
        while ($row = db_fetch_array($result)) {
          if (!$header) {
            $header = array_map('check_plain', array_keys($row));
          }
          $rows[] = array_map('check_plain', array_values($row));
        }
      }
      if (!empty($rows)) {
        $form['results'][$i] = array(
          '#type' => 'fieldset',
          '#title' => t('Result') . ': ' . theme_placeholder($sql),
        );
        $form['results'][$i]['result'] = array(
          '#value' => theme('table', $header, $rows),
        );
        unset($rows);
      }
      $i++;
    }
    $form['results'] = form_builder('dba_query_form', $form['results']);
  }
}