I have tryed to update the database script form according to the new forms api: the page shows, but the sql results aren't shown, some more testing needed:
function dba_script($edit = array()) {
$output = '';
if (!empty($edit['dba_script'])) {
unset ($output);
// execute each sql statement individually
foreach (explode(';', $edit['dba_script']) as $sql) {
if (trim($sql) == '')
break;
$result = dba_execute_script($sql);
if ($result && $result != 1 && db_num_rows($result)) {
while ($row = db_fetch_array($result)) {
if (!$header) {
$header = array_keys($row);
}
$rows[] = array_values($row);
}
}
if (!is_null($rows)) {
$output .= 'Result:'.theme('table', $header, $rows);
//$output .= form_group(t('Result'), $group);
//$form[$sql] = array(
// '#type' => 'fieldset',
// '#title' => $sql,
// '#collapsible' => FALSE,
// '#collapsed' => FALSE,
// '#description' => $group
// );
}
unset ($rows);
}
}
if (user_access('dba administer database')) {
//$group = form_textarea(t('Database script'), 'dba_script', $edit['dba_script'], 70, 10, t('Enter the text of your database script. This will be executed directly in your database, so the action can not be undone. Be sure to wrap the table name in {}. For example, if counting the rows in the \'accesslog\' table, you would enter the following simple script: \'SELECT COUNT(*) FROM {accesslog}\'.'));
//$group .= form_submit(t('Execute script'));
//$group .= l(t('Cancel'), 'admin/database');
//$output .= form_group(t('Script'), $group);
$form['script'] = array(
'#type' => 'fieldset',
'#title' => t('Script'),
'#collapsible' => FALSE,
'#collapsed' => FALSE
);
$form['script']['dba_script'] = array(
'#type' => 'textarea',
'#title' => t('Database Script'),
'#description' => t('Enter the text of your database script. This will be executed directly in your database, so the action can not be undone. Be sure to wrap the table name in {}. For example, if counting the rows in the \'accesslog\' table, you would enter the following simple script: \'SELECT COUNT(*) FROM {accesslog}\'.'),
'#default_value' => '',
'#cols' => 70,
'#rows' => 10
);
$form['script']['Execute script'] = array(
'#type' => 'submit',
'#value' => 'Execute script'
);
}
$output .= drupal_get_form( 'admin/database/script', $form);
return $output;
}
Comments
Comment #1
dwwagain, please post patch files, instead of pasting a new copy of a given function. it makes it easier for others to review and test your changes, and makes it easier for dba maintainers to apply your changes.
http://drupal.org/patch
thanks for your help porting DBA to 4.7!
-derek
Comment #2
aam commentedThe implementation in the current cvs version brings the same results, as my attemt to brute force convert the old 4.6 funktion according to the new Forms API. So no need to review the code above. But it is very bad, that there are no query results there: simply try the following SQL, there are no results or data:
Comment #3
dwwthe current behavior in HEAD is identical to that in DRUPAL-4-6 branch. DBA never tried to show you the results of all the queries in your script. if you want that behavior, it's a (normal) feature request, not a critical bug. regardless, it's not relevant to porting to 4.7.x, so i'm marking this as won't fix.