page_header((strlen($TABLE) ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), $TABLE);
-$engines = array();
-$result = $connection->query("SHOW ENGINES");
-while ($row = $result->fetch_assoc()) {
- if (ereg("YES|DEFAULT", $row["Support"])) {
- $engines[] = $row["Engine"];
- }
-}
-
$row = array(
"Engine" => $_COOKIE["adminer_engine"],
"fields" => array(array("field" => "")),
if ($suhosin && count($row["fields"]) > $suhosin) {
echo "<p class='error'>" . h(lang('Maximum number of allowed fields exceeded. Please increase %s and %s.', 'suhosin.post.max_vars', 'suhosin.request.max_vars')) . "\n";
}
+
+$engines = engines();
// case of engine may differ
foreach ($engines as $engine) {
if (!strcasecmp($engine, $row["Engine"])) {
<form action="" method="post" id="form">
<p>
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo h($row["name"]); ?>">
-<?php echo html_select("Engine", array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]); ?>
+<?php echo ($engines ? html_select("Engine", array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) : ""); ?>
<?php echo html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]); ?>
<input type="submit" value="<?php echo lang('Save'); ?>">
</p>
$set = array();
foreach ($fields as $name => $field) {
$val = process_input($field);
- if ($val !== false || !$update) {
- $set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''");
+ if (!$update) {
+ $set[idf_escape($name)] = ($val !== false ? $val : "''");
+ } elseif ($val !== false) {
+ $set[] = "\n" . idf_escape($name) . " = $val";
}
}
if (!$set) {
if ($update) {
query_redirect("UPDATE " . idf_escape($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where\nLIMIT 1", $location, lang('Item has been updated.'));
} else {
- query_redirect("INSERT INTO " . idf_escape($TABLE) . " SET" . implode(",", $set), $location, lang('Item has been inserted.'));
+ query_redirect("INSERT INTO " . idf_escape($TABLE) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")", $location, lang('Item has been inserted.'));
}
}
$row["source"][] = "";
}
-$source = get_vals("SHOW COLUMNS FROM " . idf_escape($TABLE)); //! no text and blob
-$target = ($TABLE === $row["table"] ? $source : get_vals("SHOW COLUMNS FROM " . idf_escape($row["table"])));
+$source = array_keys(fields($TABLE)); //! no text and blob
+$target = ($TABLE === $row["table"] ? $source : array_keys(fields($row["table"])));
?>
<form action="" method="post">
</form>
<?php
if ($missing != "db" && strlen(DB) && $connection->select_db(DB)) {
- $tables = get_vals("SHOW TABLES");
+ $tables = tables_list();
if (!$tables) {
echo "<p class='message'>" . lang('No tables.') . "\n";
} else {
return str_replace("``", "`", $idf);
}
+/** Escape string to use inside ''
+* @param string
+* @return string
+*/
+function escape_string($val) {
+ global $connection;
+ return substr($connection->quote($val), 1, -1);
+}
+
/** Escape or unescape string to use inside form []
* @param string
* @param bool
* @return string
*/
function where($where) {
- global $connection;
$return = array();
foreach ((array) $where["where"] as $key => $val) {
$key = bracket_escape($key, "back");
- $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = BINARY " . $connection->quote($val); //! enum and set, columns looking like functions
+ $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = " . exact_value($val); //! enum and set, columns looking like functions
}
foreach ((array) $where["null"] as $key) {
$key = bracket_escape($key, "back");
return $return;
}
+function engines() {
+ global $connection;
+ $return = array();
+ $result = $connection->query("SHOW ENGINES");
+ while ($row = $result->fetch_assoc()) {
+ if (ereg("YES|DEFAULT", $row["Support"])) {
+ $return[] = $row["Engine"];
+ }
+ }
+ return $return;
+}
+
+/** Get tables list
+* @return array
+*/
+function tables_list() {
+ return get_vals("SHOW TABLES");
+}
+
/** Get table status
* @param string
* @return array
return $return;
}
-/** Escape string to use inside ''
+/** Find out if database is information_schema
* @param string
-* @return string
+* @return bool
*/
-function escape_string($val) {
+function information_schema($db) {
global $connection;
- return substr($connection->quote($val), 1, -1);
+ return ($connection->server_info >= 5 && $db == "information_schema");
}
-/** Find out if database is information_schema
+/** Return expression for binary comparison
* @param string
-* @return bool
+* @return string
*/
-function information_schema($db) {
+function exact_value($val) {
global $connection;
- return ($connection->server_info >= 5 && $db == "information_schema");
+ return "BINARY " . $connection->quote($val);
}
// value means maximum unsigned length
<?php
$TABLE = $_GET["table"];
-$result = $connection->query("SHOW FULL COLUMNS FROM " . idf_escape($TABLE));
-if (!$result) {
+$fields = fields($TABLE);
+if (!$fields) {
$error = h($connection->error);
}
-$table_status = ($result ? table_status($TABLE) : array());
+$table_status = ($fields ? table_status($TABLE) : array());
$is_view = !isset($table_status["Rows"]);
-page_header(($result && $is_view ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
+page_header(($fields && $is_view ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
$adminer->selectLinks($table_status, $is_view ? null : "");
-if ($result) {
+if ($fields) {
echo "<table cellspacing='0'>\n";
echo "<thead><tr><th>" . lang('Column') . "<td>" . lang('Type') . "<td>" . lang('Comment') . "</thead>\n";
- while ($row = $result->fetch_assoc()) {
- echo "<tr><th>" . h($row["Field"]);
- echo "<td>" . h($row["Type"]) . ($row["Null"] == "YES" ? " <i>NULL</i>" : "") . ($row["Extra"] == "auto_increment" ? " <i>" . lang('Auto Increment') . "</i>" : "");
- echo "<td>" . nbsp($row["Comment"]);
+ foreach ($fields as $field) {
+ echo "<tr><th>" . h($field["field"]);
+ echo "<td>" . h($field["full_type"]) . ($field["null"] ? " <i>NULL</i>" : "") . ($field["auto_increment"] ? " <i>" . lang('Auto Increment') . "</i>" : "");
+ echo "<td>" . nbsp($field["comment"]);
echo "\n";
}
echo "</table>\n";
// find all used ids
$ids = array();
foreach ($rows as $row) {
- $ids[$row[$key]] = "BINARY " . $connection->quote($row[$key]);
+ $ids[$row[$key]] = exact_value($row[$key]);
}
// uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow
$descriptions = array();