Avoid fatal errors

This commit is contained in:
Jakub Vrana 2010-10-13 17:53:59 +02:00
parent d2e49b1dc8
commit b0d637b638
20 changed files with 164 additions and 221 deletions

View file

@ -122,8 +122,7 @@ if ($_POST) {
list($row["partition_by"], $row["partitions"], $row["partition"]) = $result->fetch_row();
$row["partition_names"] = array();
$row["partition_values"] = array();
$result = $connection->query("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $from AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION");
while ($row1 = $result->fetch_assoc()) {
foreach (get_rows("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $from AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION") as $row1) {
$row["partition_names"][] = $row1["PARTITION_NAME"];
$row["partition_values"][] = $row1["PARTITION_DESCRIPTION"];
}

View file

@ -141,11 +141,11 @@ if ($_GET["ns"] !== "") {
if (support("event")) {
echo "<h3>" . lang('Events') . "</h3>\n";
$result = $connection->query("SHOW EVENTS");
if ($result && $result->num_rows) {
$rows = get_rows("SHOW EVENTS");
if ($rows) {
echo "<table cellspacing='0'>\n";
echo "<thead><tr><th>" . lang('Name') . "<td>" . lang('Schedule') . "<td>" . lang('Start') . "<td>" . lang('End') . "</thead>\n";
while ($row = $result->fetch_assoc()) {
foreach ($rows as $row) {
echo "<tr>";
echo '<th><a href="' . h(ME) . 'event=' . urlencode($row["Name"]) . '">' . h($row["Name"]) . "</a>";
echo "<td>" . ($row["Execute at"] ? lang('At given time') . "<td>" . $row["Execute at"] : lang('Every') . " " . $row["Interval value"] . " " . $row["Interval field"] . "<td>$row[Starts]");

View file

@ -294,8 +294,7 @@ if (isset($_GET["mssql"])) {
function table_status($name = "") {
global $connection;
$return = array();
$result = $connection->query("SELECT name AS Name, type_desc AS Engine FROM sys.all_objects WHERE schema_id = SCHEMA_ID(" . $connection->quote(get_schema()) . ") AND type IN ('S', 'U', 'V')" . ($name != "" ? " AND name = " . $connection->quote($name) : ""));
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SELECT name AS Name, type_desc AS Engine FROM sys.all_objects WHERE schema_id = SCHEMA_ID(" . $connection->quote(get_schema()) . ") AND type IN ('S', 'U', 'V')" . ($name != "" ? " AND name = " . $connection->quote($name) : "")) as $row) {
if ($name != "") {
return $row;
}
@ -315,14 +314,13 @@ if (isset($_GET["mssql"])) {
function fields($table, $hidden = false) {
global $connection;
$return = array();
$result = $connection->query("SELECT c.*, t.name type, d.definition [default]
foreach (get_rows("SELECT c.*, t.name type, d.definition [default]
FROM sys.all_columns c
JOIN sys.all_objects o ON c.object_id = o.object_id
JOIN sys.types t ON c.user_type_id = t.user_type_id
LEFT JOIN sys.default_constraints d ON c.default_object_id = d.parent_column_id
WHERE o.schema_id = SCHEMA_ID(" . $connection->quote(get_schema()) . ") AND o.type IN ('S', 'U', 'V') AND o.name = " . $connection->quote($table)
);
while ($row = $result->fetch_assoc()) {
) as $row) {
$type = $row["type"];
$length = (ereg("char|binary", $type) ? $row["max_length"] : ($type == "decimal" ? "$row[precision],$row[scale]" : ""));
$return[$row["name"]] = array(
@ -506,9 +504,8 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
function foreign_keys($table) {
global $connection;
$result = $connection->query("EXEC sp_fkeys @fktable_name = " . $connection->quote($table));
$return = array();
while ($row = $result->fetch_assoc()) {
foreach (get_rows("EXEC sp_fkeys @fktable_name = " . $connection->quote($table)) as $row) {
$foreign_key = &$return[$row["FK_NAME"]];
$foreign_key["table"] = $row["PKTABLE_NAME"];
$foreign_key["source"][] = $row["FKCOLUMN_NAME"];
@ -535,7 +532,7 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
function trigger($name) {
global $connection;
$result = $connection->query("SELECT s.name [Trigger],
$rows = get_rows("SELECT s.name [Trigger],
CASE WHEN OBJECTPROPERTY(s.id, 'ExecIsInsertTrigger') = 1 THEN 'INSERT' WHEN OBJECTPROPERTY(s.id, 'ExecIsUpdateTrigger') = 1 THEN 'UPDATE' WHEN OBJECTPROPERTY(s.id, 'ExecIsDeleteTrigger') = 1 THEN 'DELETE' END [Event],
CASE WHEN OBJECTPROPERTY(s.id, 'ExecIsInsteadOfTrigger') = 1 THEN 'INSTEAD OF' ELSE 'AFTER' END [Timing],
c.text
@ -543,22 +540,23 @@ FROM sysobjects s
JOIN syscomments c ON s.id = c.id
WHERE s.xtype = 'TR' AND s.name = " . $connection->quote($name)
); // triggers are not schema-scoped
$row = $result->fetch_assoc();
$row["Statement"] = preg_replace('~^.+\\s+AS\\s+~isU', '', $row["text"]); //! identifiers, comments
return $row;
$return = reset($rows);
if ($return) {
$return["Statement"] = preg_replace('~^.+\\s+AS\\s+~isU', '', $return["text"]); //! identifiers, comments
}
return $return;
}
function triggers($table) {
global $connection;
$return = array();
$result = $connection->query("SELECT sys1.name,
foreach (get_rows("SELECT sys1.name,
CASE WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsertTrigger') = 1 THEN 'INSERT' WHEN OBJECTPROPERTY(sys1.id, 'ExecIsUpdateTrigger') = 1 THEN 'UPDATE' WHEN OBJECTPROPERTY(sys1.id, 'ExecIsDeleteTrigger') = 1 THEN 'DELETE' END [Event],
CASE WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsteadOfTrigger') = 1 THEN 'INSTEAD OF' ELSE 'AFTER' END [Timing]
FROM sysobjects sys1
JOIN sysobjects sys2 ON sys1.parent_obj = sys2.id
WHERE sys1.xtype = 'TR' AND sys2.name = " . $connection->quote($table)
); // triggers are not schema-scoped
while ($row = $result->fetch_assoc()) {
) as $row) { // triggers are not schema-scoped
$return[$row["name"]] = array($row["Timing"], $row["Event"]);
}
return $return;

View file

@ -307,10 +307,8 @@ if (!defined("DRIVER")) {
* @return array
*/
function engines() {
global $connection;
$return = array();
$result = $connection->query("SHOW ENGINES");
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SHOW ENGINES") as $row) {
if (ereg("YES|DEFAULT", $row["Support"])) {
$return[] = $row["Engine"];
}
@ -353,8 +351,7 @@ if (!defined("DRIVER")) {
function table_status($name = "") {
global $connection;
$return = array();
$result = $connection->query("SHOW TABLE STATUS" . ($name != "" ? " LIKE " . $connection->quote(addcslashes($name, "%_")) : ""));
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SHOW TABLE STATUS" . ($name != "" ? " LIKE " . $connection->quote(addcslashes($name, "%_")) : "")) as $row) {
if ($row["Engine"] == "InnoDB") {
// ignore internal comment, unnecessary since MySQL 5.1.21
$row["Comment"] = preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["Comment"]);
@ -392,28 +389,24 @@ if (!defined("DRIVER")) {
* @return array array($name => array("field" => , "full_type" => , "type" => , "length" => , "unsigned" => , "default" => , "null" => , "auto_increment" => , "on_update" => , "collation" => , "privileges" => , "comment" => , "primary" => ))
*/
function fields($table, $hidden = false) {
global $connection;
$return = array();
$result = $connection->query("SHOW FULL COLUMNS FROM " . table($table));
if ($result) {
while ($row = $result->fetch_assoc()) {
preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
$return[$row["Field"]] = array(
"field" => $row["Field"],
"full_type" => $row["Type"],
"type" => $match[1],
"length" => $match[2],
"unsigned" => ltrim($match[3] . $match[4]),
"default" => ($row["Default"] != "" || ereg("char", $match[1]) ? $row["Default"] : null),
"null" => ($row["Null"] == "YES"),
"auto_increment" => ($row["Extra"] == "auto_increment"),
"on_update" => (eregi('^on update (.+)', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
"collation" => $row["Collation"],
"privileges" => array_flip(explode(",", $row["Privileges"])),
"comment" => $row["Comment"],
"primary" => ($row["Key"] == "PRI"),
);
}
foreach (get_rows("SHOW FULL COLUMNS FROM " . table($table)) as $row) {
preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
$return[$row["Field"]] = array(
"field" => $row["Field"],
"full_type" => $row["Type"],
"type" => $match[1],
"length" => $match[2],
"unsigned" => ltrim($match[3] . $match[4]),
"default" => ($row["Default"] != "" || ereg("char", $match[1]) ? $row["Default"] : null),
"null" => ($row["Null"] == "YES"),
"auto_increment" => ($row["Extra"] == "auto_increment"),
"on_update" => (eregi('^on update (.+)', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
"collation" => $row["Collation"],
"privileges" => array_flip(explode(",", $row["Privileges"])),
"comment" => $row["Comment"],
"primary" => ($row["Key"] == "PRI"),
);
}
return $return;
}
@ -429,13 +422,10 @@ if (!defined("DRIVER")) {
$connection2 = $connection;
}
$return = array();
$result = $connection2->query("SHOW INDEX FROM " . table($table));
if ($result) {
while ($row = $result->fetch_assoc()) {
$return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
$return[$row["Key_name"]]["columns"][] = $row["Column_name"];
$return[$row["Key_name"]]["lengths"][] = $row["Sub_part"];
}
foreach (get_rows("SHOW INDEX FROM " . table($table), $connection2) as $row) {
$return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
$return[$row["Key_name"]]["columns"][] = $row["Column_name"];
$return[$row["Key_name"]]["lengths"][] = $row["Sub_part"];
}
return $return;
}
@ -480,10 +470,8 @@ if (!defined("DRIVER")) {
* @return array
*/
function collations() {
global $connection;
$return = array();
$result = $connection->query("SHOW COLLATION");
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SHOW COLLATION") as $row) {
$return[$row["Charset"]][] = $row["Collation"];
}
ksort($return);
@ -544,7 +532,6 @@ if (!defined("DRIVER")) {
* @return bool
*/
function rename_database($name, $collation) {
global $connection;
if (create_database($name, $collation)) {
//! move triggers
$rename = array();
@ -673,8 +660,8 @@ if (!defined("DRIVER")) {
*/
function trigger($name) {
global $connection;
$result = $connection->query("SHOW TRIGGERS WHERE `Trigger` = " . $connection->quote($name));
return $result->fetch_assoc();
$rows = get_rows("SHOW TRIGGERS WHERE `Trigger` = " . $connection->quote($name));
return reset($rows);
}
/** Get defined triggers
@ -684,8 +671,7 @@ if (!defined("DRIVER")) {
function triggers($table) {
global $connection;
$return = array();
$result = $connection->query("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($table, "%_")));
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($table, "%_"))) as $row) {
$return[$row["Trigger"]] = array($row["Timing"], $row["Event"]);
}
return $return;
@ -740,12 +726,7 @@ if (!defined("DRIVER")) {
function routines() {
global $connection;
$return = array();
$result = $connection->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $connection->quote(DB));
while ($row = $result->fetch_assoc()) {
$return[] = $row;
}
return $return;
return get_rows("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $connection->quote(DB));
}
/** Begin transaction
@ -861,13 +842,10 @@ if (!defined("DRIVER")) {
*/
function trigger_sql($table, $style) {
global $connection;
$result = $connection->query("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($table, "%_")));
$return = "";
if ($result->num_rows) {
while ($row = $result->fetch_assoc()) {
$return .= "\n" . ($style == 'CREATE+ALTER' ? "DROP TRIGGER IF EXISTS " . idf_escape($row["Trigger"]) . ";;\n" : "")
. "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . table($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
}
foreach (get_rows("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($table, "%_"))) as $row) {
$return .= "\n" . ($style == 'CREATE+ALTER' ? "DROP TRIGGER IF EXISTS " . idf_escape($row["Trigger"]) . ";;\n" : "")
. "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . table($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
}
return $return;
}

View file

@ -189,10 +189,9 @@ UNION SELECT view_name, 'view' FROM user_views"
global $connection;
$return = array();
$search = $connection->quote($name);
$result = $connection->query('SELECT table_name "Name", \'table\' "Engine" FROM all_tables WHERE tablespace_name = ' . $connection->quote(DB) . ($name != "" ? " AND table_name = $search" : "") . "
foreach (get_rows('SELECT table_name "Name", \'table\' "Engine" FROM all_tables WHERE tablespace_name = ' . $connection->quote(DB) . ($name != "" ? " AND table_name = $search" : "") . "
UNION SELECT view_name, 'view' FROM user_views" . ($name != "" ? " WHERE view_name = $search" : "")
);
while ($row = $result->fetch_assoc()) {
) as $row) {
if ($name != "") {
return $row;
}
@ -212,28 +211,25 @@ UNION SELECT view_name, 'view' FROM user_views" . ($name != "" ? " WHERE view_na
function fields($table, $hidden = false) {
global $connection;
$return = array();
$result = $connection->query("SELECT * FROM all_tab_columns WHERE table_name = " . $connection->quote($table) . " ORDER BY column_id");
if ($result) {
while ($row = $result->fetch_assoc()) {
$type = $row["DATA_TYPE"];
$length = "$row[DATA_PRECISION],$row[DATA_SCALE]";
if ($length == ",") {
$length = $row["DATA_LENGTH"];
} //! int
$return[$row["COLUMN_NAME"]] = array(
"field" => $row["COLUMN_NAME"],
"full_type" => $type . ($length ? "($length)" : ""),
"type" => strtolower($type),
"length" => $length,
"default" => $row["DATA_DEFAULT"],
"null" => ($row["NULLABLE"] == "Y"),
//! "auto_increment" => false,
//! "collation" => $row["CHARACTER_SET_NAME"],
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
//! "comment" => $row["Comment"],
//! "primary" => ($row["Key"] == "PRI"),
);
}
foreach (get_rows("SELECT * FROM all_tab_columns WHERE table_name = " . $connection->quote($table) . " ORDER BY column_id") as $row) {
$type = $row["DATA_TYPE"];
$length = "$row[DATA_PRECISION],$row[DATA_SCALE]";
if ($length == ",") {
$length = $row["DATA_LENGTH"];
} //! int
$return[$row["COLUMN_NAME"]] = array(
"field" => $row["COLUMN_NAME"],
"full_type" => $type . ($length ? "($length)" : ""),
"type" => strtolower($type),
"length" => $length,
"default" => $row["DATA_DEFAULT"],
"null" => ($row["NULLABLE"] == "Y"),
//! "auto_increment" => false,
//! "collation" => $row["CHARACTER_SET_NAME"],
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
//! "comment" => $row["Comment"],
//! "primary" => ($row["Key"] == "PRI"),
);
}
return $return;
}
@ -244,8 +240,8 @@ UNION SELECT view_name, 'view' FROM user_views" . ($name != "" ? " WHERE view_na
function view($name) {
global $connection;
$result = $connection->query('SELECT text "select" FROM user_views WHERE view_name = ' . $connection->quote($name));
return $result->fetch_assoc();
$rows = get_rows('SELECT text "select" FROM user_views WHERE view_name = ' . $connection->quote($name));
return reset($rows);
}
function collations() {
@ -338,13 +334,8 @@ UNION SELECT view_name, 'view' FROM user_views" . ($name != "" ? " WHERE view_na
}
function show_status() {
global $connection;
$return = array();
$result = $connection->query('SELECT * FROM v$instance');
foreach ($result->fetch_assoc() as $key => $val) {
$return[$key] = $val;
}
return $return;
$rows = get_rows('SELECT * FROM v$instance');
return reset($rows);
}
function support($feature) {

View file

@ -190,7 +190,6 @@ if (isset($_GET["pgsql"])) {
}
function tables_list() {
global $connection;
return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema() ORDER BY table_name");
}
@ -201,13 +200,12 @@ if (isset($_GET["pgsql"])) {
function table_status($name = "") {
global $connection;
$return = array();
$result = $connection->query("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN '' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_total_relation_size(oid) - pg_relation_size(oid) AS \"Index_length\", obj_description(oid, 'pg_class') AS \"Comment\"
foreach (get_rows("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN '' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_total_relation_size(oid) - pg_relation_size(oid) AS \"Index_length\", obj_description(oid, 'pg_class') AS \"Comment\"
FROM pg_class
WHERE relkind IN ('r','v')
AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())"
. ($name != "" ? " AND relname = " . $connection->quote($name) : "")
); //! Index_length, Auto_increment
while ($row = $result->fetch_assoc()) {
) as $row) { //! Index_length, Auto_increment
$return[$row["Name"]] = $row;
}
return ($name != "" ? $return[$name] : $return);
@ -224,7 +222,7 @@ AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema(
function fields($table, $hidden = false) {
global $connection;
$return = array();
$result = $connection->query("SELECT a.attname AS field, format_type(a.atttypid, a.atttypmod) AS full_type, d.adsrc AS default, a.attnotnull, col_description(c.oid, a.attnum) AS comment
foreach (get_rows("SELECT a.attname AS field, format_type(a.atttypid, a.atttypmod) AS full_type, d.adsrc AS default, a.attnotnull, col_description(c.oid, a.attnum) AS comment
FROM pg_class c
JOIN pg_namespace n ON c.relnamespace = n.oid
JOIN pg_attribute a ON c.oid = a.attrelid
@ -234,18 +232,15 @@ AND n.nspname = current_schema()
AND NOT a.attisdropped
" . ($hidden ? "" : "AND a.attnum > 0") . "
ORDER BY a.attnum < 0, a.attnum"
);
if ($result) {
while ($row = $result->fetch_assoc()) {
//! collation, primary
ereg('(.*)(\\((.*)\\))?', $row["full_type"], $match);
list(, $row["type"], , $row["length"]) = $match;
$row["full_type"] = $row["type"] . ($row["length"] ? "($row[length])" : "");
$row["null"] = ($row["attnotnull"] == "f");
$row["auto_increment"] = eregi("^nextval\\(", $row["default"]);
$row["privileges"] = array("insert" => 1, "select" => 1, "update" => 1);
$return[$row["field"]] = $row;
}
) as $row) {
//! collation, primary
ereg('(.*)(\\((.*)\\))?', $row["full_type"], $match);
list(, $row["type"], , $row["length"]) = $match;
$row["full_type"] = $row["type"] . ($row["length"] ? "($row[length])" : "");
$row["null"] = ($row["attnotnull"] == "f");
$row["auto_increment"] = eregi("^nextval\\(", $row["default"]);
$row["privileges"] = array("insert" => 1, "select" => 1, "update" => 1);
$return[$row["field"]] = $row;
}
return $return;
}
@ -258,8 +253,7 @@ ORDER BY a.attnum < 0, a.attnum"
$return = array();
$table_oid = $connection2->result("SELECT oid FROM pg_class WHERE relname = " . $connection2->quote($table));
$columns = get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $table_oid AND attnum > 0", $connection2);
$result = $connection2->query("SELECT relname, indisunique, indisprimary, indkey FROM pg_index i, pg_class ci WHERE i.indrelid = $table_oid AND ci.oid = i.indexrelid");
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SELECT relname, indisunique, indisprimary, indkey FROM pg_index i, pg_class ci WHERE i.indrelid = $table_oid AND ci.oid = i.indexrelid") as $row) {
$return[$row["relname"]]["type"] = ($row["indisprimary"] == "t" ? "PRIMARY" : ($row["indisunique"] == "t" ? "UNIQUE" : "INDEX"));
$return[$row["relname"]]["columns"] = array();
foreach (explode(" ", $row["indkey"]) as $indkey) {
@ -273,13 +267,12 @@ ORDER BY a.attnum < 0, a.attnum"
function foreign_keys($table) {
global $connection;
$return = array();
$result = $connection->query("SELECT tc.constraint_name, kcu.column_name, rc.update_rule AS on_update, rc.delete_rule AS on_delete, ccu.table_name AS table, ccu.column_name AS ref
foreach (get_rows("SELECT tc.constraint_name, kcu.column_name, rc.update_rule AS on_update, rc.delete_rule AS on_delete, ccu.table_name AS table, ccu.column_name AS ref
FROM information_schema.table_constraints tc
LEFT JOIN information_schema.key_column_usage kcu USING (constraint_catalog, constraint_schema, constraint_name)
LEFT JOIN information_schema.referential_constraints rc USING (constraint_catalog, constraint_schema, constraint_name)
LEFT JOIN information_schema.constraint_column_usage ccu ON rc.unique_constraint_catalog = ccu.constraint_catalog AND rc.unique_constraint_schema = ccu.constraint_schema AND rc.unique_constraint_name = ccu.constraint_name
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->quote($table)); //! there can be more unique_constraint_name
while ($row = $result->fetch_assoc()) {
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->quote($table)) as $row) { //! there can be more unique_constraint_name
$foreign_key = &$return[$row["constraint_name"]];
if (!$foreign_key) {
$foreign_key = $row;
@ -438,15 +431,14 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
function trigger($name) {
global $connection;
$result = $connection->query('SELECT trigger_name AS "Trigger", condition_timing AS "Timing", event_manipulation AS "Event", \'FOR EACH \' || action_orientation AS "Type", action_statement AS "Statement" FROM information_schema.triggers WHERE event_object_table = ' . $connection->quote($_GET["trigger"]) . ' AND trigger_name = ' . $connection->quote($name));
return $result->fetch_assoc();
$rows = get_rows('SELECT trigger_name AS "Trigger", condition_timing AS "Timing", event_manipulation AS "Event", \'FOR EACH \' || action_orientation AS "Type", action_statement AS "Statement" FROM information_schema.triggers WHERE event_object_table = ' . $connection->quote($_GET["trigger"]) . ' AND trigger_name = ' . $connection->quote($name));
return reset($rows);
}
function triggers($table) {
global $connection;
$return = array();
$result = $connection->query("SELECT * FROM information_schema.triggers WHERE event_object_table = " . $connection->quote($table));
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SELECT * FROM information_schema.triggers WHERE event_object_table = " . $connection->quote($table)) as $row) {
$return[$row["trigger_name"]] = array($row["condition_timing"], $row["event_manipulation"]);
}
return $return;

View file

@ -251,16 +251,12 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
function table_status($name = "") {
global $connection;
$return = array();
$result = $connection->query("SELECT name AS Name, type AS Engine FROM sqlite_master WHERE type IN ('table', 'view')" . ($name != "" ? " AND name = " . $connection->quote($name) : ""));
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SELECT name AS Name, type AS Engine FROM sqlite_master WHERE type IN ('table', 'view')" . ($name != "" ? " AND name = " . $connection->quote($name) : "")) as $row) {
$row["Auto_increment"] = "";
$return[$row["Name"]] = $row;
}
$result = $connection->query("SELECT * FROM sqlite_sequence");
if ($result) {
while ($row = $result->fetch_assoc()) {
$return[$row["name"]]["Auto_increment"] = $row["seq"];
}
foreach (get_rows("SELECT * FROM sqlite_sequence") as $row) {
$return[$row["name"]]["Auto_increment"] = $row["seq"];
}
return ($name != "" ? $return[$name] : $return);
}
@ -275,30 +271,25 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
}
function fields($table, $hidden = false) {
global $connection;
$return = array();
$result = $connection->query("PRAGMA table_info(" . table($table) . ")");
if (is_object($result)) {
while ($row = $result->fetch_assoc()) {
$type = strtolower($row["type"]);
$default = $row["dflt_value"];
$return[$row["name"]] = array(
"field" => $row["name"],
"type" => (eregi("int", $type) ? "integer" : (eregi("char|clob|text", $type) ? "text" : (eregi("blob", $type) ? "blob" : (eregi("real|floa|doub", $type) ? "real" : "numeric")))),
"full_type" => $type,
"default" => (ereg("'(.*)'", $default, $match) ? str_replace("''", "'", $match[1]) : ($default == "NULL" ? null : $default)),
"null" => !$row["notnull"],
"auto_increment" => eregi('^integer$', $type) && $row["pk"], //! possible false positive
"privileges" => array("select" => 1, "insert" => 1, "update" => 1),
"primary" => $row["pk"],
);
}
foreach (get_rows("PRAGMA table_info(" . table($table) . ")") as $row) {
$type = strtolower($row["type"]);
$default = $row["dflt_value"];
$return[$row["name"]] = array(
"field" => $row["name"],
"type" => (eregi("int", $type) ? "integer" : (eregi("char|clob|text", $type) ? "text" : (eregi("blob", $type) ? "blob" : (eregi("real|floa|doub", $type) ? "real" : "numeric")))),
"full_type" => $type,
"default" => (ereg("'(.*)'", $default, $match) ? str_replace("''", "'", $match[1]) : ($default == "NULL" ? null : $default)),
"null" => !$row["notnull"],
"auto_increment" => eregi('^integer$', $type) && $row["pk"], //! possible false positive
"privileges" => array("select" => 1, "insert" => 1, "update" => 1),
"primary" => $row["pk"],
);
}
return $return;
}
function indexes($table, $connection2 = null) {
global $connection;
$return = array();
$primary = array();
foreach (fields($table) as $field) {
@ -309,34 +300,26 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
if ($primary) {
$return[""] = array("type" => "PRIMARY", "columns" => $primary, "lengths" => array());
}
$result = $connection->query("PRAGMA index_list(" . table($table) . ")");
if (is_object($result)) {
while ($row = $result->fetch_assoc()) {
$return[$row["name"]]["type"] = ($row["unique"] ? "UNIQUE" : "INDEX");
$return[$row["name"]]["lengths"] = array();
$result1 = $connection->query("PRAGMA index_info(" . idf_escape($row["name"]) . ")");
while ($row1 = $result1->fetch_assoc()) {
$return[$row["name"]]["columns"][] = $row1["name"];
}
foreach (get_rows("PRAGMA index_list(" . table($table) . ")") as $row) {
$return[$row["name"]]["type"] = ($row["unique"] ? "UNIQUE" : "INDEX");
$return[$row["name"]]["lengths"] = array();
foreach (get_rows("PRAGMA index_info(" . idf_escape($row["name"]) . ")") as $row1) {
$return[$row["name"]]["columns"][] = $row1["name"];
}
}
return $return;
}
function foreign_keys($table) {
global $connection;
$return = array();
$result = $connection->query("PRAGMA foreign_key_list(" . table($table) . ")");
if (is_object($result)) {
while ($row = $result->fetch_assoc()) {
$foreign_key = &$return[$row["id"]];
//! idf_unescape in SQLite2
if (!$foreign_key) {
$foreign_key = $row;
}
$foreign_key["source"][] = $row["from"];
$foreign_key["target"][] = $row["to"];
foreach (get_rows("PRAGMA foreign_key_list(" . table($table) . ")") as $row) {
$foreign_key = &$return[$row["id"]];
//! idf_unescape in SQLite2
if (!$foreign_key) {
$foreign_key = $row;
}
$foreign_key["source"][] = $row["from"];
$foreign_key["target"][] = $row["to"];
}
return $return;
}
@ -461,8 +444,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
function triggers($table) {
global $connection;
$return = array();
$result = $connection->query("SELECT * FROM sqlite_master WHERE type = 'trigger' AND tbl_name = " . $connection->quote($table));
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SELECT * FROM sqlite_master WHERE type = 'trigger' AND tbl_name = " . $connection->quote($table)) as $row) {
preg_match('~^CREATE\\s+TRIGGER\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*([a-z]+)\\s*([a-z]+)~i', $row["sql"], $match);
$return[$row["name"]] = array($match[1], $match[2]);
}

View file

@ -125,8 +125,7 @@ CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
FETCH tables INTO _table_name, _engine, _table_collation, _table_comment;
IF NOT done THEN
CASE _table_name";
$result = $connection->query($query);
while ($row = $result->fetch_assoc()) {
foreach (get_rows($query) as $row) {
$comment = $connection->quote($row["ENGINE"] == "InnoDB" ? preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["TABLE_COMMENT"]) : $row["TABLE_COMMENT"]);
echo "
WHEN " . $connection->quote($row["TABLE_NAME"]) . " THEN

View file

@ -58,11 +58,8 @@ if ($_POST["save"]) {
}
$row = array();
if ($select) {
$result = $connection->query("SELECT" . limit(implode(", ", $select) . " FROM " . table($TABLE), " WHERE $where", (isset($_GET["select"]) ? 2 : 1)));
$row = $result->fetch_assoc();
if (isset($_GET["select"]) && $result->fetch_assoc()) {
$row = null;
}
$rows = get_rows("SELECT" . limit(implode(", ", $select) . " FROM " . table($TABLE), " WHERE $where", (isset($_GET["select"]) ? 2 : 1)));
$row = (isset($_GET["select"]) && count($rows) != 1 ? null : reset($rows));
}
}
?>

View file

@ -30,8 +30,8 @@ $row = array();
if ($_POST) {
$row = $_POST;
} elseif ($EVENT != "") {
$result = $connection->query("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = " . $connection->quote(DB) . " AND EVENT_NAME = " . $connection->quote($EVENT));
$row = $result->fetch_assoc();
$rows = get_rows("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = " . $connection->quote(DB) . " AND EVENT_NAME = " . $connection->quote($EVENT));
$row = reset($rows);
}
?>

View file

@ -36,7 +36,7 @@ class Adminer {
* @return null
*/
function loginForm() {
global $drivers, $possible_drivers;
global $drivers;
?>
<table cellspacing="0">
<tr><th><?php echo lang('System'); ?><td><?php echo html_select("driver", $drivers, DRIVER); ?>

View file

@ -1,6 +1,6 @@
<?php
function connect_error() {
global $connection, $VERSION, $token, $error, $drivers;
global $connection, $token, $error, $drivers;
$databases = array();
if (DB != "") {
page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), true);

View file

@ -7,7 +7,7 @@
* @return null
*/
function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
global $LANG, $VERSION, $HTTPS, $adminer, $connection, $drivers;
global $LANG, $HTTPS, $adminer, $connection, $drivers;
header("Content-Type: text/html; charset=utf-8");
header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox NoScript plugin
$title_all = $title . ($title2 != "" ? ": " . h($title2) : "");

View file

@ -115,7 +115,7 @@ function textarea($name, $value, $rows = 10, $cols = 80) {
* @return null
*/
function edit_type($key, $field, $collations, $foreign_keys = array()) {
global $structured_types, $types, $unsigned, $inout, $on_actions;
global $structured_types, $types, $unsigned, $on_actions;
?>
<td><select name="<?php echo $key; ?>[type]" class="type" onfocus="lastType = selectValue(this);" onchange="editingTypeChange(this);"><?php echo optionlist((!$field["type"] || isset($types[$field["type"]]) ? array() : array($field["type"])) + $structured_types + ($foreign_keys ? array(lang('Foreign keys') => $foreign_keys) : array()), $field["type"]); ?></select>
<td><input name="<?php echo $key; ?>[length]" value="<?php echo h($field["length"]); ?>" size="3" onfocus="editingLengthFocus(this);"><td><?php

View file

@ -41,9 +41,8 @@ CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
DECLARE done, set_after bool DEFAULT 0;
DECLARE add_columns text DEFAULT '";
$fields = array();
$result = $connection->query($query);
$after = "";
while ($row = $result->fetch_assoc()) {
foreach (get_rows($query) as $row) {
$default = $row["COLUMN_DEFAULT"];
$row["default"] = (isset($default) ? $connection->quote($default) : "NULL");
$row["after"] = $connection->quote($after); //! rgt AFTER lft, lft AFTER id doesn't work

View file

@ -184,6 +184,25 @@ function get_key_vals($query, $connection2 = null) {
return $return;
}
/** Get all rows of result
* @param string
* @return array associative
*/
function get_rows($query, $connection2 = null) {
global $connection;
if (!is_object($connection2)) {
$connection2 = $connection;
}
$return = array();
$result = $connection2->query($query);
if (is_object($result)) { // can return true
while ($row = $result->fetch_assoc()) {
$return[] = $row;
}
}
return $return;
}
/** Find unique identifier of a row
* @param array
* @param array result of indexes()

View file

@ -15,8 +15,7 @@ page_header(lang('Process list'), $error);
<form action="" method="post">
<table cellspacing="0" onclick="tableClick(event);" class="nowrap">
<?php
$result = $connection->query("SHOW FULL PROCESSLIST");
for ($i=0; $row = $result->fetch_assoc(); $i++) {
foreach (get_rows("SHOW FULL PROCESSLIST") as $i => $row) {
if (!$i) {
echo "<thead><tr lang='en'><th>&nbsp;<th>" . implode("<th>", array_keys($row)) . "</thead>\n";
}

View file

@ -1,8 +1,7 @@
<?php
$USER = $_GET["user"];
$privileges = array("" => array("All privileges" => ""));
$result = $connection->query("SHOW PRIVILEGES");
while ($row = $result->fetch_assoc()) {
foreach (get_rows("SHOW PRIVILEGES") as $row) {
foreach (explode(",", ($row["Privilege"] == "Grant option" ? "" : $row["Context"])) as $context) {
$privileges[$context][$row["Privilege"]] = $row["Comment"];
}

View file

@ -63,25 +63,22 @@ document.getElementById('username').focus();
function backwardKeys($table, $tableName) {
global $connection;
$return = array();
$result = $connection->query("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
foreach (get_rows("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
FROM information_schema.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = " . $connection->quote($this->database()) . "
AND REFERENCED_TABLE_SCHEMA = " . $connection->quote($this->database()) . "
AND REFERENCED_TABLE_NAME = " . $connection->quote($table) . "
ORDER BY ORDINAL_POSITION");
if ($result) { //! requires MySQL 5
while ($row = $result->fetch_assoc()) {
$return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
}
foreach ($return as $key => $val) {
$name = $this->tableName(table_status($key));
if ($name != "") {
$search = preg_quote($tableName);
$separator = "(:|\\s*-)?\\s+";
$return[$key]["name"] = (preg_match("(^$search$separator(.+)|^(.+?)$separator$search\$)", $name, $match) ? $match[2] . $match[3] : $name);
} else {
unset($return[$key]);
}
ORDER BY ORDINAL_POSITION") as $row) { //! requires MySQL 5
$return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
}
foreach ($return as $key => $val) {
$name = $this->tableName(table_status($key));
if ($name != "") {
$search = preg_quote($tableName);
$separator = "(:|\\s*-)?\\s+";
$return[$key]["name"] = (preg_match("(^$search$separator(.+)|^(.+?)$separator$search\$)", $name, $match) ? $match[2] . $match[3] : $name);
} else {
unset($return[$key]);
}
}
return $return;
@ -340,7 +337,6 @@ ORDER BY ORDINAL_POSITION");
}
function selectEmailProcess($where, $foreignKeys) {
global $connection;
if ($_POST["email_append"]) {
return true;
}
@ -351,15 +347,11 @@ ORDER BY ORDINAL_POSITION");
$subject = $_POST["email_subject"];
$message = $_POST["email_message"];
preg_match_all('~\\{\\$([a-z0-9_]+)\\}~i', "$subject.$message", $matches); // allows {$name} in subject or message
$result = $connection->query("SELECT DISTINCT $field" . ($matches[1] ? ", " . implode(", ", array_map('idf_escape', array_unique($matches[1]))) : "") . " FROM " . idf_escape($_GET["select"])
$rows = get_rows("SELECT DISTINCT $field" . ($matches[1] ? ", " . implode(", ", array_map('idf_escape', array_unique($matches[1]))) : "") . " FROM " . idf_escape($_GET["select"])
. " WHERE $field IS NOT NULL AND $field != ''"
. ($where ? " AND " . implode(" AND ", $where) : "")
. ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . "))")
);
$rows = array();
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
$fields = fields($_GET["select"]);
foreach ($this->rowDescriptions($rows, $foreignKeys) as $row) {
$replace = array('{\\' => '{'); // allow literal {$name}
@ -491,7 +483,6 @@ ORDER BY ORDINAL_POSITION");
}
function _foreignKeyOptions($table, $column) {
global $connection;
$foreignKeys = column_foreign_keys($table);
foreach ((array) $foreignKeys[$column] as $foreignKey) {
if (count($foreignKey["source"]) == 1) {

2
externals/jush vendored

@ -1 +1 @@
Subproject commit 4b1295210511e175f243172fd7ff493d180d07f3
Subproject commit d9a8b6d1ddaacde4cefbae05b770b0917be4ac4a