Report errors in get_rows()
This commit is contained in:
parent
7e644b4346
commit
96544baf69
|
@ -343,19 +343,16 @@ WHERE o.schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND o.type IN ('S', 'U',
|
||||||
}
|
}
|
||||||
$return = array();
|
$return = array();
|
||||||
// sp_statistics doesn't return information about primary key
|
// 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
|
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.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
|
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)
|
WHERE OBJECT_NAME(indexes.object_id) = " . q($table)
|
||||||
);
|
, $connection2) as $row) {
|
||||||
if ($result) {
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
|
||||||
$return[$row["name"]]["type"] = ($row["is_primary_key"] ? "PRIMARY" : ($row["is_unique"] ? "UNIQUE" : "INDEX"));
|
$return[$row["name"]]["type"] = ($row["is_primary_key"] ? "PRIMARY" : ($row["is_unique"] ? "UNIQUE" : "INDEX"));
|
||||||
$return[$row["name"]]["lengths"] = array();
|
$return[$row["name"]]["lengths"] = array();
|
||||||
$return[$row["name"]]["columns"][$row["key_ordinal"]] = $row["column_name"];
|
$return[$row["name"]]["columns"][$row["key_ordinal"]] = $row["column_name"];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -835,7 +835,7 @@ if (!defined("DRIVER")) {
|
||||||
*/
|
*/
|
||||||
function trigger_sql($table, $style) {
|
function trigger_sql($table, $style) {
|
||||||
$return = "";
|
$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" : "")
|
$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";
|
. "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . table($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ ORDER BY a.attnum < 0, a.attnum"
|
||||||
$return = array();
|
$return = array();
|
||||||
$table_oid = $connection2->result("SELECT oid FROM pg_class WHERE relname = " . q($table));
|
$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);
|
$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"]]["type"] = ($row["indisprimary"] == "t" ? "PRIMARY" : ($row["indisunique"] == "t" ? "UNIQUE" : "INDEX"));
|
||||||
$return[$row["relname"]]["columns"] = array();
|
$return[$row["relname"]]["columns"] = array();
|
||||||
foreach (explode(" ", $row["indkey"]) as $indkey) {
|
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.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.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
|
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"]];
|
$foreign_key = &$return[$row["constraint_name"]];
|
||||||
if (!$foreign_key) {
|
if (!$foreign_key) {
|
||||||
$foreign_key = $row;
|
$foreign_key = $row;
|
||||||
|
|
|
@ -254,7 +254,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
$row["Auto_increment"] = "";
|
$row["Auto_increment"] = "";
|
||||||
$return[$row["Name"]] = $row;
|
$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[$row["name"]]["Auto_increment"] = $row["seq"];
|
||||||
}
|
}
|
||||||
return ($name != "" ? $return[$name] : $return);
|
return ($name != "" ? $return[$name] : $return);
|
||||||
|
|
|
@ -45,27 +45,17 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
|
||||||
$out = "";
|
$out = "";
|
||||||
if ($_POST["routines"]) {
|
if ($_POST["routines"]) {
|
||||||
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
|
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
|
||||||
$result = $connection->query("SHOW $routine STATUS WHERE Db = " . q($db));
|
foreach (get_rows("SHOW $routine STATUS WHERE Db = " . q($db), null, "-- ") as $row) {
|
||||||
if ($result) {
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
|
||||||
$out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
|
$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";
|
. $connection->result("SHOW CREATE $routine " . idf_escape($row["Name"]), 2) . ";;\n\n";
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
echo "-- $connection->error\n\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($_POST["events"]) {
|
if ($_POST["events"]) {
|
||||||
$result = $connection->query("SHOW EVENTS");
|
foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) {
|
||||||
if ($result) {
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
|
||||||
$out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
|
$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";
|
. $connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3) . ";;\n\n";
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
echo "-- $connection->error\n\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($out) {
|
if ($out) {
|
||||||
echo "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n";
|
echo "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n";
|
||||||
|
|
|
@ -135,10 +135,6 @@ function html_select($name, $options, $value = "", $onchange = true) {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// other functions
|
|
||||||
|
|
||||||
/** Get INI boolean value
|
/** Get INI boolean value
|
||||||
* @param string
|
* @param string
|
||||||
* @return bool
|
* @return bool
|
||||||
|
@ -192,7 +188,7 @@ function get_key_vals($query, $connection2 = null) {
|
||||||
* @param string
|
* @param string
|
||||||
* @return array associative
|
* @return array associative
|
||||||
*/
|
*/
|
||||||
function get_rows($query, $connection2 = null) {
|
function get_rows($query, $connection2 = null, $error = "<p class='error'>") {
|
||||||
global $connection;
|
global $connection;
|
||||||
if (!is_object($connection2)) {
|
if (!is_object($connection2)) {
|
||||||
$connection2 = $connection;
|
$connection2 = $connection;
|
||||||
|
@ -203,6 +199,8 @@ function get_rows($query, $connection2 = null) {
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
$return[] = $row;
|
$return[] = $row;
|
||||||
}
|
}
|
||||||
|
} elseif ($error && (headers_sent() || ob_get_level())) {
|
||||||
|
echo $error . error() . "\n";
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ FROM information_schema.KEY_COLUMN_USAGE
|
||||||
WHERE TABLE_SCHEMA = " . q($this->database()) . "
|
WHERE TABLE_SCHEMA = " . q($this->database()) . "
|
||||||
AND REFERENCED_TABLE_SCHEMA = " . q($this->database()) . "
|
AND REFERENCED_TABLE_SCHEMA = " . q($this->database()) . "
|
||||||
AND REFERENCED_TABLE_NAME = " . q($table) . "
|
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"];
|
$return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
|
||||||
}
|
}
|
||||||
foreach ($return as $key => $val) {
|
foreach ($return as $key => $val) {
|
||||||
|
|
Loading…
Reference in a new issue