Auto-free result-set

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1026 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2009-08-27 07:33:29 +00:00
parent 4e19d6e034
commit cca05e3d26
21 changed files with 3 additions and 46 deletions

View file

@ -88,7 +88,6 @@ while ($row = $result->fetch_assoc()) {
$engines[] = $row["Engine"];
}
}
$result->free();
$row = array(
"Engine" => $_COOKIE["adminer_engine"],
@ -116,7 +115,6 @@ if ($_POST) {
$from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . $dbh->quote($_GET["db"]) . " AND TABLE_NAME = " . $dbh->quote($_GET["create"]);
$result = $dbh->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");
list($row["partition_by"], $row["partitions"], $row["partition"]) = $result->fetch_row();
$result->free();
$row["partition_names"] = array();
$row["partition_values"] = array();
$result = $dbh->query("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $from AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION");
@ -124,7 +122,6 @@ if ($_POST) {
$row["partition_names"][] = $row1["PARTITION_NAME"];
$row["partition_values"][] = $row1["PARTITION_DESCRIPTION"];
}
$result->free();
$row["partition_names"][] = "";
}
}

View file

@ -24,7 +24,6 @@ if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP c
break;
}
}
$result->free();
if (!$row) {
queries("DROP DATABASE " . idf_escape($_GET["db"]));
}
@ -56,7 +55,6 @@ if ($_POST) {
break;
}
}
$result->free();
} elseif (($result = $dbh->query("SHOW CREATE DATABASE " . idf_escape($_GET["db"])))) {
$create = $dbh->result($result, 1);
if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) {
@ -65,7 +63,6 @@ if ($_POST) {
// default collation
$collate = $collations[$match[1]][0];
}
$result->free();
}
?>

View file

@ -89,7 +89,6 @@ if ($dbh->server_info >= 5) {
}
echo "</table>\n";
}
$result->free();
echo '<p><a href="' . h(ME) . 'procedure=">' . lang('Create procedure') . '</a> <a href="' . h(ME) . 'function=">' . lang('Create function') . "</a>\n";
}
@ -106,6 +105,5 @@ if ($dbh->server_info >= 5.1 && ($result = $dbh->query("SHOW EVENTS"))) {
}
echo "</table>\n";
}
$result->free();
echo '<p><a href="' . h(ME) . 'event=">' . lang('Create event') . "</a>\n";
}

View file

@ -21,7 +21,6 @@ function dump_triggers($table, $style) {
}
echo "\nDELIMITER ;\n";
}
$result->free();
}
}
@ -44,7 +43,6 @@ if ($_POST) {
}
$create = $dbh->result($result, 1);
echo ($style == "CREATE+ALTER" ? preg_replace('~^CREATE DATABASE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n";
$result->free();
}
if ($style && $_POST["format"] != "csv") {
echo "USE " . idf_escape($db) . ";\n\n";
@ -56,7 +54,6 @@ if ($_POST) {
$out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
. $dbh->result($dbh->query("SHOW CREATE $routine " . idf_escape($row["Name"])), 2) . ";;\n\n";
}
$result->free();
}
}
if ($dbh->server_info >= 5.1) {
@ -65,7 +62,6 @@ if ($_POST) {
$out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
. $dbh->result($dbh->query("SHOW CREATE EVENT " . idf_escape($row["Name"])), 3) . ";;\n\n";
}
$result->free();
}
echo ($out ? "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n" : "");
}
@ -130,7 +126,6 @@ while ($row = $result->fetch_assoc()) {
ALTER TABLE " . idf_escape($row["TABLE_NAME"]) . " ENGINE=$row[ENGINE] COLLATE=$row[TABLE_COLLATION] COMMENT=$comment;
END IF" : "BEGIN END") . ";";
}
$result->free();
?>
ELSE

View file

@ -57,7 +57,6 @@ if ($_POST["save"]) {
if ($select) {
$result = $dbh->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE $where " . (isset($_GET["select"]) ? "HAVING COUNT(*) = 1" : "LIMIT 1"));
$row = $result->fetch_assoc();
$result->free();
}
}
?>

View file

@ -31,7 +31,6 @@ if ($_POST) {
} elseif (strlen($_GET["event"])) {
$result = $dbh->query("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = " . $dbh->quote($_GET["db"]) . " AND EVENT_NAME = " . $dbh->quote($_GET["event"]));
$row = $result->fetch_assoc();
$result->free();
}
?>

View file

@ -449,7 +449,6 @@ class Adminer {
echo '<a href="' . h(ME) . 'table=' . urlencode($row[0]) . '">' . $this->tableName(array("Name" => $row[0])) . "</a><br>\n"; //! Adminer::tableName may work with full table status
}
}
$result->free();
}
echo '<p><a href="' . h(ME) . 'create=">' . lang('Create new table') . "</a>\n";
}

View file

@ -13,7 +13,6 @@ function dump_table($table, $style, $is_view = false) {
echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . idf_escape($table) . ";\n";
}
$create = $dbh->result($result, 1);
$result->free();
echo ($style != "CREATE+ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n";
}
if ($style == "CREATE+ALTER" && !$is_view) {
@ -48,7 +47,6 @@ CREATE PROCEDURE adminer_alter () BEGIN
$fields[] = $row;
$after = $row["COLUMN_NAME"];
}
$result->free();
?>';
DECLARE columns CURSOR FOR <?php echo $query; ?>;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
@ -142,7 +140,6 @@ function dump_data($table, $style, $select = "") {
if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $result->num_rows) {
echo ";\n";
}
$result->free();
}
}
}

View file

@ -51,7 +51,6 @@ function get_vals($query, $column = 0) {
while ($row = $result->fetch_row()) {
$return[] = $row[$column];
}
$result->free();
}
return $return;
}
@ -245,7 +244,6 @@ function select($result, $dbh2 = null) {
}
echo "</table>\n";
}
$result->free();
}
function is_utf8($val) {

View file

@ -118,8 +118,8 @@ if (extension_loaded("mysqli")) {
return $row;
}
function free() {
return mysql_free_result($this->_result);
function __destruct() {
mysql_free_result($this->_result);
}
}
@ -176,7 +176,6 @@ function table_status($name = "") {
}
$return[$row["Name"]] = $row;
}
$result->free();
return (strlen($name) ? $return[$name] : $return);
}
@ -213,7 +212,6 @@ function fields($table) {
"primary" => ($row["Key"] == "PRI"),
);
}
$result->free();
}
return $return;
}
@ -231,7 +229,6 @@ function indexes($table, $dbh2 = null) {
$return[$row["Key_name"]]["columns"][$row["Seq_in_index"]] = $row["Column_name"];
$return[$row["Key_name"]]["lengths"][$row["Seq_in_index"]] = $row["Sub_part"];
}
$result->free();
}
return $return;
}
@ -243,7 +240,6 @@ function foreign_keys($table) {
$result = $dbh->query("SHOW CREATE TABLE " . idf_escape($table));
if ($result) {
$create_table = $dbh->result($result, 1);
$result->free();
preg_match_all("~CONSTRAINT `($pattern)` FOREIGN KEY \\(((?:`$pattern`,? ?)+)\\) REFERENCES `($pattern)`(?:\\.`($pattern)`)? \\(((?:`$pattern`,? ?)+)\\)(?: ON DELETE (" . implode("|", $on_actions) . "))?(?: ON UPDATE (" . implode("|", $on_actions) . "))?~", $create_table, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
preg_match_all("~`($pattern)`~", $match[2], $source);
@ -273,7 +269,6 @@ function collations() {
while ($row = $result->fetch_assoc()) {
$return[$row["Charset"]][] = $row["Collation"];
}
$result->free();
ksort($return);
foreach ($return as $key => $val) {
sort($return[$key]);

View file

@ -78,9 +78,5 @@ if (extension_loaded('pdo')) {
$row->charsetnr = (in_array("blob", $row->flags) ? 63 : 0);
return $row;
}
function free() {
// $this->__destruct() is not callable
}
}
}

View file

@ -22,4 +22,3 @@ while ($row = $result->fetch_assoc()) {
echo '<tr' . odd() . '><td><a href="' . h(ME . 'user=' . urlencode($row["User"]) . '&host=' . urlencode($row["Host"])) . '">' . lang('edit') . '</a><td>' . h($row["User"]) . "<td>" . h($row["Host"]) . "\n";
}
echo "</table>\n";
$result->free();

View file

@ -22,7 +22,6 @@ for ($i=0; $row = $result->fetch_assoc(); $i++) {
}
echo "<tr" . odd() . "><td><input type='checkbox' name='kill[]' value='$row[Id]'><td>" . implode("<td>", array_map('nbsp', $row)) . "\n";
}
$result->free();
?>
</table>
<p>

View file

@ -182,7 +182,6 @@ if (!$columns) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
$result->free();
// use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
$found_rows = (intval($limit) && $group && count($group) < count($select)
? $dbh->result($dbh->query(" SELECT FOUND_ROWS()")) // space to allow mysql.trace_mode

View file

@ -71,6 +71,7 @@ if (!$error && $_POST) {
}
echo "<p class='message'>" . lang('Query executed OK, %d row(s) affected.', $dbh->affected_rows) . "\n";
}
unset($result); // free resultset
} while ($dbh->next_result());
}
$query = substr($query, $offset);

View file

@ -18,7 +18,6 @@ if ($result) {
echo "\n";
}
echo "</table>\n";
$result->free();
echo "<p>";
if ($is_view) {
@ -74,7 +73,6 @@ if ($result) {
}
echo "</table>\n";
}
$result->free();
echo '<p><a href="' . h(ME) . 'trigger=' . urlencode($_GET["table"]) . '">' . lang('Add trigger') . "</a>\n";
}
}

View file

@ -22,7 +22,6 @@ if ($_POST) {
} elseif (strlen($_GET["name"])) {
$result = $dbh->query("SHOW TRIGGERS WHERE `Trigger` = " . $dbh->quote($_GET["name"]));
$row = $result->fetch_assoc();
$result->free();
}
?>

View file

@ -6,7 +6,6 @@ while ($row = $result->fetch_assoc()) {
$privileges[$context][$row["Privilege"]] = $row["Comment"];
}
}
$result->free();
$privileges["Server Admin"] += $privileges["File access on server"];
$privileges["Databases"]["Create routine"] = $privileges["Procedures"]["Create routine"]; // MySQL bug #30305
unset($privileges["Procedures"]["Create routine"]);
@ -55,7 +54,6 @@ if (isset($_GET["host"]) && ($result = $dbh->query("SHOW GRANTS FOR " . $dbh->qu
$old_pass = $match[1];
}
}
$result->free();
}
if ($_POST && !$error) {

View file

@ -8,5 +8,4 @@ while ($row = $result->fetch_assoc()) {
echo "<th><code class='jush-sqlset'>" . h($row["Variable_name"]) . "</code>";
echo "<td>" . nbsp($row["Value"]);
}
$result->free();
echo "</table>\n";

View file

@ -56,7 +56,6 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
while ($row = $result->fetch_assoc()) {
$return[$row["TABLE_NAME"]][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
}
$result->free();
}
return $return;
}
@ -95,7 +94,6 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
while ($row = $result->fetch_row()) {
$descriptions[$row[0]] = $row[1];
}
$result->free();
// use the descriptions
foreach ($rows as $n => $row) {
$return[$n][$key] = $descriptions[$row[$key]];
@ -274,7 +272,6 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
$sent++;
}
}
$result->free();
}
redirect(remove_from_uri(), lang('%d e-mail(s) have been sent.', $sent));
}
@ -306,7 +303,6 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
while ($row = $result->fetch_row()) {
$return[$row[0]] = $row[1];
}
$result->free();
return "<select$attrs>" . optionlist($return, $value, true) . "</select>";
}
}

View file

@ -10,7 +10,6 @@ function dump_data($table, $style, $select = "") {
while ($row = $result->fetch_assoc()) {
dump_csv($row);
}
$result->free();
}
}