Autocomplete for big foreign keys
This commit is contained in:
parent
daf85306a5
commit
6b4ee48ae8
|
@ -1,2 +1,2 @@
|
||||||
<?php
|
<?php
|
||||||
$VERSION = "3.2.3-dev";
|
$VERSION = "3.3.0-dev";
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
Adminer 3.3.0-dev:
|
||||||
|
Append new index with auto index selection (bug #3282127)
|
||||||
|
Autocomplete for big foreign keys (Editor)
|
||||||
|
Customizable favicon (customization)
|
||||||
|
Method name can return a link (customization)
|
||||||
|
|
||||||
Adminer 3.2.2 (released 2011-03-28):
|
Adminer 3.2.2 (released 2011-03-28):
|
||||||
Fix AJAX history after reload
|
Fix AJAX history after reload
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
|
||||||
}
|
}
|
||||||
foreach ($columns as $name => $desc) {
|
foreach ($columns as $name => $desc) {
|
||||||
$options = $this->_foreignKeyOptions($_GET["select"], $name);
|
$options = $this->_foreignKeyOptions($_GET["select"], $name);
|
||||||
if ($options) {
|
if (is_array($options)) {
|
||||||
if ($fields[$name]["null"]) {
|
if ($fields[$name]["null"]) {
|
||||||
$options[0] = '(' . lang('empty') . ')';
|
$options[0] = '(' . lang('empty') . ')';
|
||||||
}
|
}
|
||||||
|
@ -423,9 +423,12 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
|
||||||
. enum_input("radio", $attrs, $field, ($value || isset($_GET["select"]) ? $value : 0), ($field["null"] ? "" : null))
|
. enum_input("radio", $attrs, $field, ($value || isset($_GET["select"]) ? $value : 0), ($field["null"] ? "" : null))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
$options = $this->_foreignKeyOptions($table, $field["field"]);
|
$options = $this->_foreignKeyOptions($table, $field["field"], $value);
|
||||||
if ($options) {
|
if (isset($options)) {
|
||||||
return "<select$attrs>" . optionlist($options, $value, true) . "</select>";
|
return (is_array($options)
|
||||||
|
? "<select$attrs>" . optionlist($options, $value, true) . "</select>"
|
||||||
|
: "<input value='" . h($value) . "'$attrs class='hidden'><input value='" . h($options) . "' class='jsonly' onkeyup=\"whisper('" . h(ME . "script=complete&source=" . urlencode($table) . "&field=" . urlencode($field["field"])) . "&value=', this);\"><div onclick='return whisperClick(event, this.previousSibling);'></div>"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (like_bool($field)) {
|
if (like_bool($field)) {
|
||||||
return '<input type="checkbox" value="' . h($value ? $value : 1) . '"' . ($value ? ' checked' : '') . "$attrs>";
|
return '<input type="checkbox" value="' . h($value ? $value : 1) . '"' . ($value ? ' checked' : '') . "$attrs>";
|
||||||
|
@ -563,12 +566,16 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _foreignKeyOptions($table, $column) {
|
function _foreignKeyOptions($table, $column, $value = null) {
|
||||||
|
global $connection;
|
||||||
if (list($table, $id, $name) = $this->_foreignColumn(column_foreign_keys($table), $column)) {
|
if (list($table, $id, $name) = $this->_foreignColumn(column_foreign_keys($table), $column)) {
|
||||||
$return = &$this->_values[$table];
|
$return = &$this->_values[$table];
|
||||||
if (!isset($return)) {
|
if (!isset($return)) {
|
||||||
$table_status = table_status($table);
|
$table_status = table_status($table);
|
||||||
$return = ($table_status["Rows"] > 1000 ? array() : array("" => "") + get_key_vals("SELECT $id, $name FROM " . table($table) . " ORDER BY 2"));
|
$return = ($table_status["Rows"] > 1000
|
||||||
|
? (isset($value) ? $connection->result("SELECT $name FROM " . table($table) . " WHERE $id = " . q($value)) : "")
|
||||||
|
: array("" => "") + get_key_vals("SELECT $id, $name FROM " . table($table) . " ORDER BY 2")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@ if (isset($_GET["download"])) {
|
||||||
include "../adminer/edit.inc.php";
|
include "../adminer/edit.inc.php";
|
||||||
} elseif (isset($_GET["select"])) {
|
} elseif (isset($_GET["select"])) {
|
||||||
include "../adminer/select.inc.php";
|
include "../adminer/select.inc.php";
|
||||||
|
} elseif (isset($_GET["script"])) {
|
||||||
|
include "./script.inc.php";
|
||||||
} else {
|
} else {
|
||||||
include "./db.inc.php";
|
include "./db.inc.php";
|
||||||
}
|
}
|
||||||
|
|
12
editor/script.inc.php
Normal file
12
editor/script.inc.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
if (list($table, $id, $name) = $adminer->_foreignColumn(column_foreign_keys($_GET["source"]), $_GET["field"])) {
|
||||||
|
$result = $connection->query("SELECT $id, $name FROM " . table($table) . " WHERE $name LIKE " . q("$_GET[value]%") . " ORDER BY 2 LIMIT 11");
|
||||||
|
for ($i=0; $i < 10 && ($row = $result->fetch_row()); $i++) {
|
||||||
|
echo "<a href='" . h(ME . "edit=" . urlencode($table) . "&where" . urlencode("[" . bracket_escape(idf_unescape($id)) . "]") . "=" . urlencode($row[0])) . "'>" . h($row[1]) . "</a><br>\n";
|
||||||
|
}
|
||||||
|
if ($i == 10) {
|
||||||
|
echo "...\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit; // don't print footer
|
|
@ -5,3 +5,31 @@ function bodyLoad(version) {
|
||||||
onpopstate(history);
|
onpopstate(history);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function whisperClick(event, field) {
|
||||||
|
var el = event.target || event.srcElement;
|
||||||
|
if (/^a$/i.test(el.tagName) && !(event.button || event.ctrlKey || event.shiftKey || event.altKey || event.metaKey)) {
|
||||||
|
field.value = el.firstChild.data;
|
||||||
|
field.previousSibling.value = decodeURIComponent(el.href.replace(/.*=/, ''));
|
||||||
|
field.nextSibling.style.display = 'none';
|
||||||
|
eventStop(event);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function whisper(url, field) {
|
||||||
|
if (field.orig != field.value) {
|
||||||
|
field.orig = field.value;
|
||||||
|
return ajax(url + encodeURIComponent(field.value), function (xmlhttp) {
|
||||||
|
if (xmlhttp.status && field.orig == field.value) {
|
||||||
|
field.nextSibling.innerHTML = xmlhttp.responseText;
|
||||||
|
field.nextSibling.style.display = '';
|
||||||
|
var a = field.nextSibling.firstChild;
|
||||||
|
if (a && a.firstChild.data == field.value) {
|
||||||
|
field.previousSibling.value = decodeURIComponent(a.href.replace(/.*=/, ''));
|
||||||
|
a.style.fontWeight = 'bold';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
1
todo.txt
1
todo.txt
|
@ -21,7 +21,6 @@ Three-state checkbox for boolean searches
|
||||||
JavaScript data validation - columns containing word email, url, ...
|
JavaScript data validation - columns containing word email, url, ...
|
||||||
Joining tables - PRIMARY KEY (table, joining)
|
Joining tables - PRIMARY KEY (table, joining)
|
||||||
Rank, Tree structure
|
Rank, Tree structure
|
||||||
Add whisperer to fields with foreign key to big table
|
|
||||||
|
|
||||||
MySQL:
|
MySQL:
|
||||||
Data longer than max_allowed_packet can be sent by mysqli_stmt_send_long_data()
|
Data longer than max_allowed_packet can be sent by mysqli_stmt_send_long_data()
|
||||||
|
|
Loading…
Reference in a new issue