git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@65 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-06 13:03:13 +00:00
parent 4e620135ed
commit ffcea8b587
4 changed files with 190 additions and 157 deletions

View file

@ -16,19 +16,29 @@ function dump($db) {
}
}
echo "CREATE DATABASE IF NOT EXISTS " . idf_escape($db) . ";\n";
$result = mysql_query("SHOW CREATE DATABASE " . idf_escape($db));
if ($result) {
echo mysql_result($result, 0) . ";\n";
mysql_free_result($result);
}
echo "USE " . idf_escape($db) . ";\n";
echo "SET CHARACTER SET utf8;\n\n";
$result = mysql_query("SHOW TABLES");
while ($row = mysql_fetch_row($result)) {
echo mysql_result(mysql_query("SHOW CREATE TABLE " . idf_escape($row[0])), 0, 1) . ";\n";
$result1 = mysql_query("SHOW CREATE TABLE " . idf_escape($row[0]));
if ($result1) {
echo mysql_result($result1, 0, 1) . ";\n";
mysql_free_result($result1);
$result1 = mysql_query("SELECT * FROM " . idf_escape($row[0])); //! except views //! enum and set as numbers
if ($result1) {
while ($row1 = mysql_fetch_row($result1)) {
echo "INSERT INTO " . idf_escape($row[0]) . " VALUES ('" . implode("', '", array_map('mysql_real_escape_string', $row1)) . "');\n";
}
mysql_free_result($result1);
}
echo "\n";
}
}
mysql_free_result($result);
$result = mysql_query("SHOW TRIGGERS");
@ -36,6 +46,7 @@ function dump($db) {
echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];\n\n"; //! delimiter
}
mysql_free_result($result);
echo "\n\n";
echo implode("", (array) $routines[$db]);
}

View file

@ -32,6 +32,7 @@ function optionlist($options, $selected = array(), $not_vals = false) {
function fields($table) {
$return = array();
$result = mysql_query("SHOW FULL COLUMNS FROM " . idf_escape($table));
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
preg_match('~^([^(]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
$return[$row["Field"]] = array(
@ -43,9 +44,11 @@ function fields($table) {
"null" => ($row["Null"] != "NO"),
"extra" => $row["Extra"],
"collation" => $row["Collation"],
"privileges" => explode(",", $row["Privileges"]),
);
}
mysql_free_result($result);
}
return $return;
}
@ -63,13 +66,17 @@ function indexes($table) {
function foreign_keys($table) {
static $pattern = '~`((?:[^`]*|``)+)`~';
$return = array();
$create_table = mysql_result(mysql_query("SHOW CREATE TABLE " . idf_escape($table)), 0, 1);
$result = mysql_query("SHOW CREATE TABLE " . idf_escape($table));
if ($result) {
$create_table = mysql_result($result, 0, 1);
mysql_free_result($result);
preg_match_all('~FOREIGN KEY \\((.+)\\) REFERENCES (?:`(.+)`\\.)?`(.+)` \\((.+)\\)~', $create_table, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
preg_match_all($pattern, $match[1], $source);
preg_match_all($pattern, $match[4], $target);
$return[] = array(idf_unescape($match[2]), idf_unescape($match[3]), array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1]));
}
}
return $return;
}

View file

@ -1,8 +1,18 @@
<?php
$indexes = indexes($_GET["select"]);
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]));
echo '<p><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . "</a></p>\n";
$fields = fields($_GET["select"]);
$columns = array();
foreach ($fields as $key => $field) {
if (in_array("select", $field["privileges"])) {
$columns[] = $key;
}
}
if (!$columns) {
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . mysql_error()) . ".</p>\n";
} else {
echo "<form action='' id='form'>\n<fieldset><legend>" . lang('Search') . "</legend>\n";
if (strlen($_GET["server"])) {
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
@ -12,7 +22,6 @@ echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["sele
echo "\n";
$where = array();
$columns = array_keys(fields($_GET["select"]));
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IS NULL");
$i = 0;
foreach ((array) $_GET["where"] as $val) {
@ -67,11 +76,12 @@ echo "<fieldset><legend>" . lang('Action') . "</legend><div><input type='submit'
echo "</form>\n";
echo "<div style='clear: left; margin-bottom: 1em;'></div>\n";
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . " OFFSET " . ($limit * $_GET["page"]) : ""));
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0); // space for mysql.trace_mode
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS " . implode(", ", array_map('idf_escape', $columns)) . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . " OFFSET " . ($limit * $_GET["page"]) : ""));
if (!mysql_num_rows($result)) {
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
} else {
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0); // space for mysql.trace_mode
$indexes = indexes($_GET["select"]);
$foreign_keys = array();
foreach (foreign_keys($_GET["select"]) as $foreign_key) {
foreach ($foreign_key[2] as $val) {
@ -133,3 +143,4 @@ if (!mysql_num_rows($result)) {
}
}
mysql_free_result($result);
}

View file

@ -2,6 +2,9 @@
page_header(lang('Table') . ": " . htmlspecialchars($_GET["table"]));
$result = mysql_query("SHOW COLUMNS FROM " . idf_escape($_GET["table"]));
if (!$result) {
echo "<p class='error'>" . lang('Unable to show the table definition') . ": " . mysql_error() . ".</p>\n";
} else {
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr><th>" . htmlspecialchars($row["Field"]) . "</th><td>$row[Type]" . ($row["Null"] == "NO" ? "" : " <i>NULL</i>") . "</td></tr>\n";
@ -31,6 +34,7 @@ if ($foreign_keys) {
}
echo "</table>\n";
}
}
if (mysql_get_server_info() >= 5) {
$result = mysql_query("SHOW TRIGGERS LIKE '" . mysql_real_escape_string($_GET["table"]) . "'");