Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make table data and indexes sizes human readable #13

Closed
wants to merge 3 commits into from

4 participants

@mhujer

Before (icons are there because of theme I'm using):
Before

After:
After

@vrana
Owner

I prefer the longer form because then I can see which tables are big at the first sight.

@vrana vrana closed this
@fnkr

+1 for mhujer

@fnkr

I just wrote this userscript that formats the sizes (automatically selects best format (Byte, KB, MB, GB, TB)): https://ge1.me/userscript-adminerhumanreadablesizes

Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 6, 2012
  1. @lm

    Don't quote bit type in export

    lm authored committed
Commits on Feb 1, 2012
  1. @mhujer
  2. @mhujer

    Make the formating more clever

    mhujer authored
This page is out of date. Refresh to see the latest.
View
2  adminer/include/adminer.inc.php
@@ -659,7 +659,7 @@ function dumpData($table, $style, $query) {
$insert = "INSERT INTO " . table($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
}
foreach ($row as $key => $val) {
- $row[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : q($val)) : "NULL"); //! columns looking like functions
+ $row[$key] = (isset($val) ? (ereg('int|float|double|decimal|bit', $fields[$key]["type"]) ? $val : q($val)) : "NULL"); //! columns looking like functions
}
$s = implode(",\t", $row);
if ($style == "INSERT+UPDATE") {
View
25 adminer/include/functions.inc.php
@@ -882,3 +882,28 @@ function is_url($string) {
$domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component //! IDN
return (preg_match("~^(https?)://($domain?\\.)+$domain(:\\d+)?(/.*)?(\\?.*)?(#.*)?\$~i", $string, $match) ? strtolower($match[1]) : ""); //! restrict path, query and fragment characters
}
+
+/** Makes size in bytes human readable
+* @param int|float
+* @return string Formated size
+*/
+function format_size($size) {
+ if ($size >= 1073741824) {
+ $size = $size / 1073741824;
+ $unit = 'GB';
+ } else if ($size >= 1048576) {
+ $size = $size / 1048576;
+ $unit = 'MB';
+ } else if ($size >= 1024) {
+ $size = $size / 1024;
+ $unit = 'KB';
+ } else {
+ $size = $size;
+ $unit = 'B';
+ }
+ if (round($size) != $size) {
+ return number_format($size, 2, '.', lang(',')) . ' ' . $unit;
+ } else {
+ return number_format($size, 0, '.', lang(',')) . ' ' . $unit;
+ }
+}
View
8 adminer/script.inc.php
@@ -12,7 +12,11 @@
}
foreach ($sums + array("Auto_increment" => 0, "Rows" => 0) as $key => $val) {
if ($table_status[$key] != "") {
- $val = number_format($table_status[$key], 0, '.', lang(','));
+ if (isset($sums[$key])) {
+ $val = format_size($table_status[$key]);
+ } else {
+ $val = number_format($table_status[$key], 0, '.', lang(','));
+ }
json_row("$key-$id", ($key == "Rows" && $table_status["Engine"] == "InnoDB" && $val ? "~ $val" : $val));
if (isset($sums[$key])) {
$sums[$key] += ($table_status["Engine"] != "InnoDB" || $key != "Data_free" ? $table_status[$key] : 0);
@@ -24,7 +28,7 @@
}
}
foreach ($sums as $key => $val) {
- json_row("sum-$key", number_format($val, 0, '.', lang(',')));
+ json_row("sum-$key", format_size($val));
}
json_row("");
} else { // connect
View
1  changes.txt
@@ -6,6 +6,7 @@ SET DEFAULT foreign key action
Trim table and column names (bug #3405309)
Error message with no response from server in AJAX
Esc to cancel AJAX request
+Don't quote bit type in export
Ability to disable export (customization)
MySQL: set autocommit after connect
PostgreSQL: fix alter foreign key
Something went wrong with that request. Please try again.