]> git.joonet.de Git - adminer.git/commitdiff
Report errors in get_rows()
authorJakub Vrana <jakub@vrana.cz>
Wed, 13 Oct 2010 16:59:15 +0000 (18:59 +0200)
committerJakub Vrana <jakub@vrana.cz>
Wed, 13 Oct 2010 17:00:48 +0000 (19:00 +0200)
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/dump.inc.php
adminer/include/functions.inc.php
editor/include/adminer.inc.php

index 5f0dce394131da47bded09a7386fd30bb367177a..3dde8f827ae8ebb0657b1cf651bc4de1b3d08ba4 100644 (file)
@@ -343,18 +343,15 @@ WHERE o.schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND o.type IN ('S', 'U',
                }
                $return = array();
                // sp_statistics doesn't return information about primary key
-               $result = $connection2->query("SELECT indexes.name, key_ordinal, is_unique, is_primary_key, columns.name AS column_name
+               foreach (get_rows("SELECT indexes.name, key_ordinal, is_unique, is_primary_key, columns.name AS column_name
 FROM sys.indexes
 INNER JOIN sys.index_columns ON indexes.object_id = index_columns.object_id AND indexes.index_id = index_columns.index_id
 INNER JOIN sys.columns ON index_columns.object_id = columns.object_id AND index_columns.column_id = columns.column_id
 WHERE OBJECT_NAME(indexes.object_id) = " . q($table)
-               );
-               if ($result) {
-                       while ($row = $result->fetch_assoc()) {
-                               $return[$row["name"]]["type"] = ($row["is_primary_key"] ? "PRIMARY" : ($row["is_unique"] ? "UNIQUE" : "INDEX"));
-                               $return[$row["name"]]["lengths"] = array();
-                               $return[$row["name"]]["columns"][$row["key_ordinal"]] = $row["column_name"];
-                       }
+               , $connection2) as $row) {
+                       $return[$row["name"]]["type"] = ($row["is_primary_key"] ? "PRIMARY" : ($row["is_unique"] ? "UNIQUE" : "INDEX"));
+                       $return[$row["name"]]["lengths"] = array();
+                       $return[$row["name"]]["columns"][$row["key_ordinal"]] = $row["column_name"];
                }
                return $return;
        }
index 52614eca72e733189d2d103736610441e6cc2b59..f88735a7ca4f26abebc7cdbabd20301e2e498872 100644 (file)
@@ -835,7 +835,7 @@ if (!defined("DRIVER")) {
        */
        function trigger_sql($table, $style) {
                $return = "";
-               foreach (get_rows("SHOW TRIGGERS LIKE " . q(addcslashes($table, "%_"))) as $row) {
+               foreach (get_rows("SHOW TRIGGERS LIKE " . q(addcslashes($table, "%_")), null, "-- ") 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";
                }
index 38d484e4d91f3fa9e6c075dcf8e95e8ebc3eb311..6398aa4593772ebc3c5c64c52df82e0b30932e85 100644 (file)
@@ -251,7 +251,7 @@ ORDER BY a.attnum < 0, a.attnum"
                $return = array();
                $table_oid = $connection2->result("SELECT oid FROM pg_class WHERE relname = " . q($table));
                $columns = get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $table_oid AND attnum > 0", $connection2);
-               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) {
+               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", $connection2) 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) {
@@ -269,7 +269,8 @@ 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 = " . q($table)) as $row) { //! there can be more unique_constraint_name
+WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . q($table) //! there can be more unique_constraint_name
+                       ) as $row) {
                        $foreign_key = &$return[$row["constraint_name"]];
                        if (!$foreign_key) {
                                $foreign_key = $row;
index 6faa565e14fd6e7bfdcac22c64fbbae419e91f58..89ce2f15e98de46c335a868576042692b562988c 100644 (file)
@@ -254,7 +254,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                        $row["Auto_increment"] = "";
                        $return[$row["Name"]] = $row;
                }
-               foreach (get_rows("SELECT * FROM sqlite_sequence") as $row) {
+               foreach (get_rows("SELECT * FROM sqlite_sequence", null, "") as $row) {
                        $return[$row["name"]]["Auto_increment"] = $row["seq"];
                }
                return ($name != "" ? $return[$name] : $return);
index be2a1603360e8e40d8a119ea6101bb67c8296f5b..8004b7199f879aeb61106f25df98b1390713f552 100644 (file)
@@ -45,26 +45,16 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
                                $out = "";
                                if ($_POST["routines"]) {
                                        foreach (array("FUNCTION", "PROCEDURE") as $routine) {
-                                               $result = $connection->query("SHOW $routine STATUS WHERE Db = " . q($db));
-                                               if ($result) {
-                                                       while ($row = $result->fetch_assoc()) {
-                                                               $out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
-                                                               . $connection->result("SHOW CREATE $routine " . idf_escape($row["Name"]), 2) . ";;\n\n";
-                                                       }
-                                               } else {
-                                                       echo "-- $connection->error\n\n";
+                                               foreach (get_rows("SHOW $routine STATUS WHERE Db = " . q($db), null, "-- ") as $row) {
+                                                       $out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
+                                                       . $connection->result("SHOW CREATE $routine " . idf_escape($row["Name"]), 2) . ";;\n\n";
                                                }
                                        }
                                }
                                if ($_POST["events"]) {
-                                       $result = $connection->query("SHOW EVENTS");
-                                       if ($result) {
-                                               while ($row = $result->fetch_assoc()) {
-                                                       $out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
-                                                       . $connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3) . ";;\n\n";
-                                               }
-                                       } else {
-                                               echo "-- $connection->error\n\n";
+                                       foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) {
+                                               $out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
+                                               . $connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3) . ";;\n\n";
                                        }
                                }
                                if ($out) {
index 9903b0e6350f102130e74c6700726637a708589b..efa47981ed4b7ee82952e93e7f20214cd0bb8a55 100644 (file)
@@ -135,10 +135,6 @@ function html_select($name, $options, $value = "", $onchange = true) {
        return $return;
 }
 
-
-
-// other functions
-
 /** Get INI boolean value
 * @param string
 * @return bool
@@ -192,7 +188,7 @@ function get_key_vals($query, $connection2 = null) {
 * @param string
 * @return array associative
 */
-function get_rows($query, $connection2 = null) {
+function get_rows($query, $connection2 = null, $error = "<p class='error'>") {
        global $connection;
        if (!is_object($connection2)) {
                $connection2 = $connection;
@@ -203,6 +199,8 @@ function get_rows($query, $connection2 = null) {
                while ($row = $result->fetch_assoc()) {
                        $return[] = $row;
                }
+       } elseif ($error && (headers_sent() || ob_get_level())) {
+               echo $error . error() . "\n";
        }
        return $return;
 }
index d32a6573305e3b7cf892e4f4ed96f6e858d777a3..965caaf34692a0c18e235a2fd55d019429a21cee 100644 (file)
@@ -67,7 +67,7 @@ FROM information_schema.KEY_COLUMN_USAGE
 WHERE TABLE_SCHEMA = " . q($this->database()) . "
 AND REFERENCED_TABLE_SCHEMA = " . q($this->database()) . "
 AND REFERENCED_TABLE_NAME = " . q($table) . "
-ORDER BY ORDINAL_POSITION") as $row) { //! requires MySQL 5
+ORDER BY ORDINAL_POSITION", null, "") 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) {