Navigation Menu

Skip to content

Commit

Permalink
Driver specific view detection
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed May 27, 2010
1 parent fe3d395 commit da6f1f8
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion adminer/db.inc.php
Expand Up @@ -165,7 +165,7 @@
foreach ($table_status as $row) {
$id = addcslashes($row["Name"], "\\'/");
echo "setHtml('Comment-$id', '" . nbsp($row["Comment"]) . "');\n";
if (!eregi("view", $row["Engine"])) {
if (!is_view($row)) {
foreach (array("Engine", "Collation") as $key) {
echo "setHtml('$key-$id', '" . nbsp($row[$key]) . "');\n";
}
Expand Down
4 changes: 4 additions & 0 deletions adminer/drivers/mssql.inc.php
Expand Up @@ -304,6 +304,10 @@ function table_status($name = "") {
return $return;
}

function is_view($table_status) {
return $table_status["Engine"] == "VIEW";
}

function fk_support($table_status) {
return true;
}
Expand Down
9 changes: 8 additions & 1 deletion adminer/drivers/mysql.inc.php
Expand Up @@ -359,7 +359,6 @@ function table_status($name = "") {
$row["Comment"] = preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["Comment"]);
}
if (!isset($row["Rows"])) {
$row["Engine"] = "VIEW";
$row["Comment"] = "";
}
if ($name != "") {
Expand All @@ -370,6 +369,14 @@ function table_status($name = "") {
return $return;
}

/** Find out whether the identifier is view
* @param array
* @return bool
*/
function is_view($table_status) {
return !isset($table_status["Rows"]);
}

/** Check if table supports foreign keys
* @param array result of table_status
* @return bool
Expand Down
4 changes: 4 additions & 0 deletions adminer/drivers/oracle.inc.php
Expand Up @@ -202,6 +202,10 @@ function table_status($name = "") {
return $return;
}

function is_view($table_status) {
return $table_status["Engine"] == "view";
}

function fk_support($table_status) {
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions adminer/drivers/pgsql.inc.php
Expand Up @@ -213,6 +213,10 @@ function table_status($name = "") {
return ($name != "" ? $return[$name] : $return);
}

function is_view($table_status) {
return $table_status["Engine"] == "view";
}

function fk_support($table_status) {
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions adminer/drivers/sqlite.inc.php
Expand Up @@ -262,6 +262,10 @@ function table_status($name = "") {
return ($name != "" ? $return[$name] : $return);
}

function is_view($table_status) {
return $table_status["Engine"] == "view";
}

function fk_support($table_status) {
global $connection;
return !$connection->result("SELECT sqlite_compileoption_used('OMIT_FOREIGN_KEY')");
Expand Down
4 changes: 2 additions & 2 deletions adminer/dump.inc.php
Expand Up @@ -72,7 +72,7 @@
$table = (DB == "" || in_array($row["Name"], (array) $_POST["tables"]));
$data = (DB == "" || in_array($row["Name"], (array) $_POST["data"]));
if ($table || $data) {
if (isset($row["Engine"])) {
if (!is_view($row)) {
if ($ext == "tar") {
ob_start();
}
Expand Down Expand Up @@ -197,7 +197,7 @@
$prefix = ereg_replace("_.*", "", $name);
$checked = ($TABLE == "" || $TABLE == (substr($TABLE, -1) == "%" ? "$prefix%" : $name)); //! % may be part of table name
$print = "<tr><td>" . checkbox("tables[]", $name, $checked, $name, "formUncheck('check-tables');");
if (eregi("view", $row["Engine"])) {
if (is_view($row)) {
$views .= "$print\n";
} else {
echo "$print<td align='right'><label>" . ($row["Engine"] == "InnoDB" && $row["Rows"] ? "~ " : "") . $row["Rows"] . checkbox("data[]", $name, $checked, "", "formUncheck('check-data');") . "</label>\n";
Expand Down
2 changes: 1 addition & 1 deletion adminer/include/adminer.inc.php
Expand Up @@ -86,7 +86,7 @@ function fieldName($field, $order = 0) {
function selectLinks($tableStatus, $set = "") {
echo '<p class="tabs">';
$links = array("select" => lang('Select data'), "table" => lang('Show structure'));
if (eregi("view", $tableStatus["Engine"])) {
if (is_view($tableStatus)) {
$links["view"] = lang('Alter view');
} else {
$links["create"] = lang('Alter table');
Expand Down
4 changes: 2 additions & 2 deletions adminer/table.inc.php
Expand Up @@ -6,7 +6,7 @@
}
$table_status = ($fields ? table_status($TABLE) : array());

page_header(($fields && $table_status["Engine"] == "VIEW" ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
page_header(($fields && is_view($table_status) ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
$adminer->selectLinks($table_status);

if ($fields) {
Expand All @@ -20,7 +20,7 @@
}
echo "</table>\n";

if ($table_status["Engine"] != "VIEW") {
if (is_view($table_status)) {
echo "<h3>" . lang('Indexes') . "</h3>\n";
$indexes = indexes($TABLE);
if ($indexes) {
Expand Down

0 comments on commit da6f1f8

Please sign in to comment.