Prepare for SQLite
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1192 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
cc3ae45832
commit
5e01a627f7
|
@ -98,14 +98,6 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
|
||||||
|
|
||||||
page_header((strlen($TABLE) ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), $TABLE);
|
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(
|
$row = array(
|
||||||
"Engine" => $_COOKIE["adminer_engine"],
|
"Engine" => $_COOKIE["adminer_engine"],
|
||||||
"fields" => array(array("field" => "")),
|
"fields" => array(array("field" => "")),
|
||||||
|
@ -148,6 +140,8 @@ $suhosin = floor(extension_loaded("suhosin") ? (min(ini_get("suhosin.request.max
|
||||||
if ($suhosin && count($row["fields"]) > $suhosin) {
|
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";
|
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
|
// case of engine may differ
|
||||||
foreach ($engines as $engine) {
|
foreach ($engines as $engine) {
|
||||||
if (!strcasecmp($engine, $row["Engine"])) {
|
if (!strcasecmp($engine, $row["Engine"])) {
|
||||||
|
@ -160,7 +154,7 @@ foreach ($engines as $engine) {
|
||||||
<form action="" method="post" id="form">
|
<form action="" method="post" id="form">
|
||||||
<p>
|
<p>
|
||||||
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo h($row["name"]); ?>">
|
<?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"]); ?>
|
<?php echo html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]); ?>
|
||||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -22,8 +22,10 @@ if ($_POST && !$error && !isset($_GET["select"])) {
|
||||||
$set = array();
|
$set = array();
|
||||||
foreach ($fields as $name => $field) {
|
foreach ($fields as $name => $field) {
|
||||||
$val = process_input($field);
|
$val = process_input($field);
|
||||||
if ($val !== false || !$update) {
|
if (!$update) {
|
||||||
$set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''");
|
$set[idf_escape($name)] = ($val !== false ? $val : "''");
|
||||||
|
} elseif ($val !== false) {
|
||||||
|
$set[] = "\n" . idf_escape($name) . " = $val";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$set) {
|
if (!$set) {
|
||||||
|
@ -32,7 +34,7 @@ if ($_POST && !$error && !isset($_GET["select"])) {
|
||||||
if ($update) {
|
if ($update) {
|
||||||
query_redirect("UPDATE " . idf_escape($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where\nLIMIT 1", $location, lang('Item has been updated.'));
|
query_redirect("UPDATE " . idf_escape($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where\nLIMIT 1", $location, lang('Item has been updated.'));
|
||||||
} else {
|
} 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.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,8 @@ if ($_POST) {
|
||||||
$row["source"][] = "";
|
$row["source"][] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$source = get_vals("SHOW COLUMNS FROM " . idf_escape($TABLE)); //! no text and blob
|
$source = array_keys(fields($TABLE)); //! no text and blob
|
||||||
$target = ($TABLE === $row["table"] ? $source : get_vals("SHOW COLUMNS FROM " . idf_escape($row["table"])));
|
$target = ($TABLE === $row["table"] ? $source : array_keys(fields($row["table"])));
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
|
|
|
@ -491,7 +491,7 @@ class Adminer {
|
||||||
</form>
|
</form>
|
||||||
<?php
|
<?php
|
||||||
if ($missing != "db" && strlen(DB) && $connection->select_db(DB)) {
|
if ($missing != "db" && strlen(DB) && $connection->select_db(DB)) {
|
||||||
$tables = get_vals("SHOW TABLES");
|
$tables = tables_list();
|
||||||
if (!$tables) {
|
if (!$tables) {
|
||||||
echo "<p class='message'>" . lang('No tables.') . "\n";
|
echo "<p class='message'>" . lang('No tables.') . "\n";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -24,6 +24,15 @@ function idf_unescape($idf) {
|
||||||
return str_replace("``", "`", $idf);
|
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 []
|
/** Escape or unescape string to use inside form []
|
||||||
* @param string
|
* @param string
|
||||||
* @param bool
|
* @param bool
|
||||||
|
@ -155,11 +164,10 @@ function unique_idf($row, $indexes) {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function where($where) {
|
function where($where) {
|
||||||
global $connection;
|
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach ((array) $where["where"] as $key => $val) {
|
foreach ((array) $where["where"] as $key => $val) {
|
||||||
$key = bracket_escape($key, "back");
|
$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) {
|
foreach ((array) $where["null"] as $key) {
|
||||||
$key = bracket_escape($key, "back");
|
$key = bracket_escape($key, "back");
|
||||||
|
|
|
@ -177,6 +177,25 @@ function get_databases($flush = true) {
|
||||||
return $return;
|
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
|
/** Get table status
|
||||||
* @param string
|
* @param string
|
||||||
* @return array
|
* @return array
|
||||||
|
@ -315,15 +334,6 @@ function collations() {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Escape string to use inside ''
|
|
||||||
* @param string
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function escape_string($val) {
|
|
||||||
global $connection;
|
|
||||||
return substr($connection->quote($val), 1, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Find out if database is information_schema
|
/** Find out if database is information_schema
|
||||||
* @param string
|
* @param string
|
||||||
* @return bool
|
* @return bool
|
||||||
|
@ -333,6 +343,15 @@ function information_schema($db) {
|
||||||
return ($connection->server_info >= 5 && $db == "information_schema");
|
return ($connection->server_info >= 5 && $db == "information_schema");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return expression for binary comparison
|
||||||
|
* @param string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function exact_value($val) {
|
||||||
|
global $connection;
|
||||||
|
return "BINARY " . $connection->quote($val);
|
||||||
|
}
|
||||||
|
|
||||||
// value means maximum unsigned length
|
// value means maximum unsigned length
|
||||||
$types = array();
|
$types = array();
|
||||||
$structured_types = array();
|
$structured_types = array();
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
$TABLE = $_GET["table"];
|
$TABLE = $_GET["table"];
|
||||||
$result = $connection->query("SHOW FULL COLUMNS FROM " . idf_escape($TABLE));
|
$fields = fields($TABLE);
|
||||||
if (!$result) {
|
if (!$fields) {
|
||||||
$error = h($connection->error);
|
$error = h($connection->error);
|
||||||
}
|
}
|
||||||
$table_status = ($result ? table_status($TABLE) : array());
|
$table_status = ($fields ? table_status($TABLE) : array());
|
||||||
$is_view = !isset($table_status["Rows"]);
|
$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 : "");
|
$adminer->selectLinks($table_status, $is_view ? null : "");
|
||||||
|
|
||||||
if ($result) {
|
if ($fields) {
|
||||||
echo "<table cellspacing='0'>\n";
|
echo "<table cellspacing='0'>\n";
|
||||||
echo "<thead><tr><th>" . lang('Column') . "<td>" . lang('Type') . "<td>" . lang('Comment') . "</thead>\n";
|
echo "<thead><tr><th>" . lang('Column') . "<td>" . lang('Type') . "<td>" . lang('Comment') . "</thead>\n";
|
||||||
while ($row = $result->fetch_assoc()) {
|
foreach ($fields as $field) {
|
||||||
echo "<tr><th>" . h($row["Field"]);
|
echo "<tr><th>" . h($field["field"]);
|
||||||
echo "<td>" . h($row["Type"]) . ($row["Null"] == "YES" ? " <i>NULL</i>" : "") . ($row["Extra"] == "auto_increment" ? " <i>" . lang('Auto Increment') . "</i>" : "");
|
echo "<td>" . h($field["full_type"]) . ($field["null"] ? " <i>NULL</i>" : "") . ($field["auto_increment"] ? " <i>" . lang('Auto Increment') . "</i>" : "");
|
||||||
echo "<td>" . nbsp($row["Comment"]);
|
echo "<td>" . nbsp($field["comment"]);
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
|
|
|
@ -116,7 +116,7 @@ ORDER BY ORDINAL_POSITION");
|
||||||
// find all used ids
|
// find all used ids
|
||||||
$ids = array();
|
$ids = array();
|
||||||
foreach ($rows as $row) {
|
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
|
// uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow
|
||||||
$descriptions = array();
|
$descriptions = array();
|
||||||
|
|
Loading…
Reference in a new issue