Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 198 lines (188 sloc) 9.676 kB
97123b6 Separate db.inc.php
jakubvrana authored
1 <?php
328c7a7 Move and drop views
jakubvrana authored
2 $tables_views = array_merge((array) $_POST["tables"], (array) $_POST["views"]);
3
db07325 Search in all tables
jakubvrana authored
4 if ($tables_views && !$error && !$_POST["search"]) {
97123b6 Separate db.inc.php
jakubvrana authored
5 $result = true;
6 $message = "";
741b19b @vrana Copy tables (bug #3158027)
authored
7 if ($jush == "sql" && count($_POST["tables"]) > 1 && ($_POST["drop"] || $_POST["truncate"] || $_POST["copy"])) {
c8c4be7 Admit setting of foreign_key_checks
jakubvrana authored
8 queries("SET foreign_key_checks = 0"); // allows to truncate or drop several tables at once
f5fbdf9 Disable foreign_key_checks only with several tables
jakubvrana authored
9 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
10 if ($_POST["truncate"]) {
11 if ($_POST["tables"]) {
12 $result = truncate_tables($_POST["tables"]);
97123b6 Separate db.inc.php
jakubvrana authored
13 }
06ce682 Display number of manipulated rows in JS confirm
jakubvrana authored
14 $message = lang('Tables have been truncated.');
3f5b683 Reintegrate sqlite branch
jakubvrana authored
15 } elseif ($_POST["move"]) {
44d572e @vrana Driver specific move tables
authored
16 $result = move_tables((array) $_POST["tables"], (array) $_POST["views"], $_POST["target"]);
97123b6 Separate db.inc.php
jakubvrana authored
17 $message = lang('Tables have been moved.');
741b19b @vrana Copy tables (bug #3158027)
authored
18 } elseif ($_POST["copy"]) {
19 $result = copy_tables((array) $_POST["tables"], (array) $_POST["views"], $_POST["target"]);
20 $message = lang('Tables have been copied.');
3f5b683 Reintegrate sqlite branch
jakubvrana authored
21 } elseif ($_POST["drop"]) {
22 if ($_POST["views"]) {
23 $result = drop_views($_POST["views"]);
24 }
25 if ($result && $_POST["tables"]) {
26 $result = drop_tables($_POST["tables"]);
27 }
28 $message = lang('Tables have been dropped.');
4cc29e0 @vrana Vacuum for PostgreSQL
authored
29 } elseif ($jush != "sql") {
30 $result = ($jush == "sqlite"
31 ? queries("VACUUM")
32 : apply_queries("VACUUM" . ($_POST["optimize"] ? "" : " ANALYZE"), $_POST["tables"])
33 );
c6c4855 SQLite: vacuum
Jakub Vrana authored
34 $message = lang('Tables have been optimized.');
3f5b683 Reintegrate sqlite branch
jakubvrana authored
35 } elseif ($_POST["tables"] && ($result = queries(($_POST["optimize"] ? "OPTIMIZE" : ($_POST["check"] ? "CHECK" : ($_POST["repair"] ? "REPAIR" : "ANALYZE"))) . " TABLE " . implode(", ", array_map('idf_escape', $_POST["tables"]))))) {
36 while ($row = $result->fetch_assoc()) {
7d64e03 Bold table names in message (bug #2990383)
jakubvrana authored
37 $message .= "<b>" . h($row["Table"]) . "</b>: " . h($row["Msg_text"]) . "<br>";
97123b6 Separate db.inc.php
jakubvrana authored
38 }
39 }
dbdd40a Introduce queries_redirect function
jakubvrana authored
40 queries_redirect(substr(ME, 0, -1), $message, $result);
97123b6 Separate db.inc.php
jakubvrana authored
41 }
42
6420c58 Schema support for PostgreSQL
jakubvrana authored
43 page_header(($_GET["ns"] == "" ? lang('Database') . ": " . h(DB) : lang('Schema') . ": " . h($_GET["ns"])), $error, true);
7416164 @vrana Homepage customization
authored
44
45 if ($adminer->homepage()) {
46 if ($_GET["ns"] !== "") {
47 echo "<h3>" . lang('Tables and views') . "</h3>\n";
48 $tables_list = tables_list();
49 if (!$tables_list) {
50 echo "<p class='message'>" . lang('No tables.') . "\n";
51 } else {
52 echo "<form action='' method='post'>\n";
53 echo "<p>" . lang('Search data in tables') . ": <input name='query' value='" . h($_POST["query"]) . "'> <input type='submit' name='search' value='" . lang('Search') . "'>\n";
54 if ($_POST["search"] && $_POST["query"] != "") {
55 search_tables();
56 }
023b62a @vrana Highlight checked rows
authored
57 echo "<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);'>\n";
b358a2d @vrana Link titles (http://forum.zdrojak.root.cz/index.php?topic=185.msg1540…
authored
58 echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^(tables|views)\[/);">';
59 echo '<th>' . lang('Table');
60 echo '<td>' . lang('Engine');
61 echo '<td>' . lang('Collation');
62 echo '<td>' . lang('Data Length');
63 echo '<td>' . lang('Index Length');
64 echo '<td>' . lang('Data Free');
65 echo '<td>' . lang('Auto Increment');
66 echo '<td>' . lang('Rows');
67 echo (support("comment") ? '<td>' . lang('Comment') : '');
68 echo "</thead>\n";
7416164 @vrana Homepage customization
authored
69 foreach ($tables_list as $name => $type) {
6591d48 @vrana Replace isset($var) by $var !== null
authored
70 $view = ($type !== null && !eregi("table", $type));
7416164 @vrana Homepage customization
authored
71 echo '<tr' . odd() . '><td>' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');");
b358a2d @vrana Link titles (http://forum.zdrojak.root.cz/index.php?topic=185.msg1540…
authored
72 echo '<th><a href="' . h(ME) . 'table=' . urlencode($name) . '" title="' . lang('Show structure') . '">' . h($name) . '</a>';
7416164 @vrana Homepage customization
authored
73 if ($view) {
b358a2d @vrana Link titles (http://forum.zdrojak.root.cz/index.php?topic=185.msg1540…
authored
74 echo '<td colspan="6"><a href="' . h(ME) . "view=" . urlencode($name) . '" title="' . lang('Alter view') . '">' . lang('View') . '</a>';
75 echo '<td align="right"><a href="' . h(ME) . "select=" . urlencode($name) . '" title="' . lang('Select data') . '">?</a>';
7416164 @vrana Homepage customization
authored
76 } else {
b358a2d @vrana Link titles (http://forum.zdrojak.root.cz/index.php?topic=185.msg1540…
authored
77 foreach (array(
78 "Engine" => array(),
79 "Collation" => array(),
80 "Data_length" => array("create", lang('Alter table')),
81 "Index_length" => array("indexes", lang('Alter indexes')),
82 "Data_free" => array("edit", lang('New item')),
83 "Auto_increment" => array("auto_increment=1&create", lang('Alter table')),
84 "Rows" => array("select", lang('Select data')),
85 ) as $key => $link) {
86 echo ($link ? "<td align='right'><a href='" . h(ME . "$link[0]=") . urlencode($name) . "' id='$key-" . h($name) . "' title='$link[1]'>?</a>" : "<td id='$key-" . h($name) . "'>&nbsp;");
7416164 @vrana Homepage customization
authored
87 }
6420c58 Schema support for PostgreSQL
jakubvrana authored
88 }
7416164 @vrana Homepage customization
authored
89 echo (support("comment") ? "<td id='Comment-" . h($name) . "'>&nbsp;" : "");
3f5b683 Reintegrate sqlite branch
jakubvrana authored
90 }
7416164 @vrana Homepage customization
authored
91 echo "<tr><td>&nbsp;<th>" . lang('%d in total', count($tables_list));
1a0369a @vrana Display default engine only in MySQL (thanks to Honza Krakora)
authored
92 echo "<td>" . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : "");
7416164 @vrana Homepage customization
authored
93 echo "<td>" . nbsp(db_collation(DB, collations()));
94 foreach (array("Data_length", "Index_length", "Data_free") as $key) {
95 echo "<td align='right' id='sum-$key'>&nbsp;";
6420c58 Schema support for PostgreSQL
jakubvrana authored
96 }
7416164 @vrana Homepage customization
authored
97 echo "</table>\n";
023b62a @vrana Highlight checked rows
authored
98 echo "<script type='text/javascript'>tableCheck();</script>\n";
7416164 @vrana Homepage customization
authored
99 if (!information_schema(DB)) {
4cc29e0 @vrana Vacuum for PostgreSQL
authored
100 echo "<p>" . (ereg('^(sql|sqlite|pgsql)$', $jush)
c6c4855 SQLite: vacuum
Jakub Vrana authored
101 ? ($jush != "sqlite" ? "<input type='submit' value='" . lang('Analyze') . "'> " : "")
102 . "<input type='submit' name='optimize' value='" . lang('Optimize') . "'> " : ""
f498219 @vrana Remove eventStop() used by AJAXification in past
authored
103 ) . ($jush == "sql" ? "<input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate') . "'" . confirm("formChecked(this, /tables/)") . "> <input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /tables|views/)") . ">\n";
c7f1a63 @vrana Extensible list of databases
authored
104 $databases = (support("scheme") ? schemas() : $adminer->databases());
7416164 @vrana Homepage customization
authored
105 if (count($databases) != 1 && $jush != "sqlite") {
106 $db = (isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB));
ca4de55 @vrana Whitespace
authored
107 echo "<p>" . lang('Move to other database') . ": ";
108 echo ($databases ? html_select("target", $databases, $db) : '<input name="target" value="' . h($db) . '">');
f498219 @vrana Remove eventStop() used by AJAXification in past
authored
109 echo " <input type='submit' name='move' value='" . lang('Move') . "'>";
110 echo (support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "'>" : "");
741b19b @vrana Copy tables (bug #3158027)
authored
111 echo "\n";
7416164 @vrana Homepage customization
authored
112 }
740ae10 @vrana Don't send incomplete forms
authored
113 echo "<input type='hidden' name='token' value='$token'>\n";
7416164 @vrana Homepage customization
authored
114 }
115 echo "</form>\n";
116 }
117
118 echo '<p><a href="' . h(ME) . 'create=">' . lang('Create table') . "</a>\n";
119 if (support("view")) {
120 echo '<a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored
121 }
122
7416164 @vrana Homepage customization
authored
123 if (support("routine")) {
124 echo "<h3>" . lang('Routines') . "</h3>\n";
125 $routines = routines();
126 if ($routines) {
127 echo "<table cellspacing='0'>\n";
128 echo '<thead><tr><th>' . lang('Name') . '<td>' . lang('Type') . '<td>' . lang('Return type') . "<td>&nbsp;</thead>\n";
129 odd('');
130 foreach ($routines as $row) {
131 echo '<tr' . odd() . '>';
955e6b4 @vrana PostgreSQL supports only functions
authored
132 echo '<th><a href="' . h(ME) . ($row["ROUTINE_TYPE"] != "PROCEDURE" ? 'callf=' : 'call=') . urlencode($row["ROUTINE_NAME"]) . '">' . h($row["ROUTINE_NAME"]) . '</a>';
7416164 @vrana Homepage customization
authored
133 echo '<td>' . h($row["ROUTINE_TYPE"]);
134 echo '<td>' . h($row["DTD_IDENTIFIER"]);
955e6b4 @vrana PostgreSQL supports only functions
authored
135 echo '<td><a href="' . h(ME) . ($row["ROUTINE_TYPE"] != "PROCEDURE" ? 'function=' : 'procedure=') . urlencode($row["ROUTINE_NAME"]) . '">' . lang('Alter') . "</a>";
7416164 @vrana Homepage customization
authored
136 }
137 echo "</table>\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored
138 }
955e6b4 @vrana PostgreSQL supports only functions
authored
139 echo '<p>' . (support("procedure") ? '<a href="' . h(ME) . 'procedure=">' . lang('Create procedure') . '</a> ' : '') . '<a href="' . h(ME) . 'function=">' . lang('Create function') . "</a>\n";
97123b6 Separate db.inc.php
jakubvrana authored
140 }
7416164 @vrana Homepage customization
authored
141
142 if (support("sequence")) {
143 echo "<h3>" . lang('Sequences') . "</h3>\n";
144 $sequences = get_vals("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema()");
145 if ($sequences) {
146 echo "<table cellspacing='0'>\n";
147 echo "<thead><tr><th>" . lang('Name') . "</thead>\n";
148 odd('');
149 foreach ($sequences as $val) {
150 echo "<tr" . odd() . "><th><a href='" . h(ME) . "sequence=" . urlencode($val) . "'>" . h($val) . "</a>\n";
151 }
152 echo "</table>\n";
f2d21d2 @vrana Sequences
authored
153 }
7416164 @vrana Homepage customization
authored
154 echo "<p><a href='" . h(ME) . "sequence='>" . lang('Create sequence') . "</a>\n";
f2d21d2 @vrana Sequences
authored
155 }
7416164 @vrana Homepage customization
authored
156
157 if (support("type")) {
158 echo "<h3>" . lang('User types') . "</h3>\n";
159 $types = types();
160 if ($types) {
161 echo "<table cellspacing='0'>\n";
162 echo "<thead><tr><th>" . lang('Name') . "</thead>\n";
163 odd('');
164 foreach ($types as $val) {
165 echo "<tr" . odd() . "><th><a href='" . h(ME) . "type=" . urlencode($val) . "'>" . h($val) . "</a>\n";
166 }
167 echo "</table>\n";
3308856 @vrana User types support for PostgreSQL
authored
168 }
7416164 @vrana Homepage customization
authored
169 echo "<p><a href='" . h(ME) . "type='>" . lang('Create type') . "</a>\n";
3308856 @vrana User types support for PostgreSQL
authored
170 }
7416164 @vrana Homepage customization
authored
171
172 if (support("event")) {
173 echo "<h3>" . lang('Events') . "</h3>\n";
174 $rows = get_rows("SHOW EVENTS");
175 if ($rows) {
176 echo "<table cellspacing='0'>\n";
177 echo "<thead><tr><th>" . lang('Name') . "<td>" . lang('Schedule') . "<td>" . lang('Start') . "<td>" . lang('End') . "</thead>\n";
178 foreach ($rows as $row) {
179 echo "<tr>";
180 echo '<th><a href="' . h(ME) . 'event=' . urlencode($row["Name"]) . '">' . h($row["Name"]) . "</a>";
181 echo "<td>" . ($row["Execute at"] ? lang('At given time') . "<td>" . $row["Execute at"] : lang('Every') . " " . $row["Interval value"] . " " . $row["Interval field"] . "<td>$row[Starts]");
182 echo "<td>$row[Ends]";
183 }
184 echo "</table>\n";
06595f9 @vrana Inform about disabled event_scheduler (http://forum.zdrojak.cz/?topic…
authored
185 $event_scheduler = $connection->result("SELECT @@event_scheduler");
186 if ($event_scheduler && $event_scheduler != "ON") {
187 echo "<p class='error'><code class='jush-sqlset'>event_scheduler</code>: " . h($event_scheduler) . "\n";
188 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
189 }
7416164 @vrana Homepage customization
authored
190 echo '<p><a href="' . h(ME) . 'event=">' . lang('Create event') . "</a>\n";
191 }
192
193 if ($tables_list) {
194 echo "<script type='text/javascript'>ajaxSetHtml('" . js_escape(ME) . "script=db');</script>\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored
195 }
09327ef @vrana Don't download script with no tables
authored
196 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
197 }
Something went wrong with that request. Please try again.