function systeminfo_display_database_table_structure in System Information 6.2
Same name and namespace in other branches
- 5.2 systeminfo.module \systeminfo_display_database_table_structure()
- 6 systeminfo.module \systeminfo_display_database_table_structure()
1 string reference to 'systeminfo_display_database_table_structure'
- systeminfo_menu in ./
systeminfo.module - Implementation of hook_menu().
File
- ./
systeminfo.module, line 909 - Displays information about the Drupal installation and system environment.
Code
function systeminfo_display_database_table_structure() {
global $db_url;
$connection = arg(5);
$table_name = arg(6);
if (!$connection || !$table_name) {
drupal_goto('admin/reports/systeminfo/database');
}
$databases = !is_array($db_url) ? array(
'default' => $db_url,
) : $db_url;
if (!isset($databases[$connection])) {
drupal_goto('admin/reports/systeminfo/database');
}
$database = $databases[$connection];
$db = parse_url($database);
$database_name = substr($db['path'], 1);
$header = array();
$rows = array();
db_set_active($connection);
if ($db['scheme'] == 'mysql' || $db['scheme'] == 'mysqli') {
$result = db_query("DESCRIBE " . db_escape_string($table_name));
}
elseif ($db['scheme'] == 'pgsql') {
$schema_name = db_result(db_query("SELECT schemaname FROM pg_catalog.pg_tables WHERE tablename = '%s' AND schemaname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')", $table_name));
$schema_name = $schema_name ? $schema_name : 'public';
$result = db_query("SELECT a.attname AS field, pg_catalog.format_type(a.atttypid, a.atttypmod) AS type, CASE a.attnotnull WHEN a.attnotnull IS NULL THEN 'YES' ELSE 'NO' END AS null, adef.adsrc AS default\n FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef ON a.attrelid = adef.adrelid AND a.attnum = adef.adnum LEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid\n WHERE a.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname = '%s' AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = '%s')) AND a.attnum > 0 AND NOT a.attisdropped \n ORDER BY a.attnum", $table_name, $schema_name);
}
while ($row = db_fetch_array($result)) {
if (!$header) {
$header = array_keys($row);
}
$row_data = array();
foreach ($row as $data) {
$row_data[] = !is_null($data) ? $data : theme('placeholder', t('NULL'));
}
$rows[] = $row_data;
}
db_set_active();
drupal_set_title(t('Structure of %databasename-tablename', array(
'%databasename-tablename' => $database_name . '.' . $table_name,
)));
$output = '<p>' . t('View <a href="@content-table">content of %tablename</a>.', array(
'@content-table' => url('admin/reports/systeminfo/database/content/' . $connection . '/' . $table_name),
'%tablename' => $table_name,
)) . '</p>';
$output .= theme('table', $header, $rows, array(
'class' => 'systeminfo',
));
return $output;
}