diff --git a/createv.inc.php b/createv.inc.php index ef6ecaec..ed8754f7 100644 --- a/createv.inc.php +++ b/createv.inc.php @@ -15,7 +15,7 @@ if ($_POST) { $row = $_POST; echo "
" . lang('Unable to operate view') . ": " . htmlspecialchars($error) . "
\n"; } elseif (strlen($_GET["createv"])) { - $row = array("name" => $_GET["createv"], "select" => preg_replace('~^.* AS ~U', '', $mysql->result($mysql->query("SHOW CREATE VIEW " . idf_escape($_GET["createv"])), 1))); + $row = view($_GET["createv"]); } else { $row = array(); } diff --git a/functions.inc.php b/functions.inc.php index 3b48c0cd..f03c53be 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -111,6 +111,11 @@ function foreign_keys($table) { return $return; } +function view($name) { + global $mysql; + return array("name" => $name, "select" => preg_replace('~^(?:[^`]+|`[^`]*`)* AS ~U', '', $mysql->result($mysql->query("SHOW CREATE VIEW " . idf_escape($name)), 1))); +} + function unique_idf($row, $indexes) { foreach ($indexes as $index) { if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") { diff --git a/view.inc.php b/view.inc.php index 77f9c07b..c4d8ec7c 100644 --- a/view.inc.php +++ b/view.inc.php @@ -1,4 +1,5 @@ " . htmlspecialchars(preg_replace('~^.* AS ~U', '', $mysql->result($mysql->query("SHOW CREATE VIEW " . idf_escape($_GET["view"])), 1))) . "\n"; +$view = view($_GET["view"]); +echo "" . htmlspecialchars($view["select"]) . "\n"; echo '\n";