1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-11 09:04:02 +02:00

Respect numbers in autocomplete

This commit is contained in:
Jakub Vrana
2011-05-05 07:46:36 +02:00
parent dd295df9bd
commit 24e66c2812
3 changed files with 9 additions and 8 deletions

View File

@@ -572,10 +572,10 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
$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 $return = ($table_status["Rows"] > 1000 ? "" : array("" => "") + get_key_vals("SELECT $id, $name FROM " . table($table) . " ORDER BY 2"));
? (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") if (!$return && isset($value)) {
); return $connection->result("SELECT $name FROM " . table($table) . " WHERE $id = " . q($value));
} }
return $return; return $return;
} }

View File

@@ -1,6 +1,6 @@
<?php <?php
if (list($table, $id, $name) = $adminer->_foreignColumn(column_foreign_keys($_GET["source"]), $_GET["field"])) { 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"); $result = $connection->query("SELECT $id, $name FROM " . table($table) . " WHERE " . (ereg('^[0-9]+$', $_GET["value"]) ? "$id = $_GET[value] OR " : "") . "$name LIKE " . q("$_GET[value]%") . " ORDER BY 2 LIMIT 11");
for ($i=0; $i < 10 && ($row = $result->fetch_row()); $i++) { 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"; echo "<a href='" . h(ME . "edit=" . urlencode($table) . "&where" . urlencode("[" . bracket_escape(idf_unescape($id)) . "]") . "=" . urlencode($row[0])) . "'>" . h($row[1]) . "</a><br>\n";
} }

View File

@@ -18,16 +18,17 @@ function whisperClick(event, field) {
} }
function whisper(url, field) { function whisper(url, field) {
if (field.orig != field.value) { if (field.orig != field.value) { // ignore arrows, Shift, ...
field.orig = field.value; field.orig = field.value;
field.previousSibling.value = field.value; // accept number, reject string
return ajax(url + encodeURIComponent(field.value), function (xmlhttp) { return ajax(url + encodeURIComponent(field.value), function (xmlhttp) {
if (xmlhttp.status && field.orig == field.value) { if (xmlhttp.status && field.orig == field.value) { // ignore old responses
field.nextSibling.innerHTML = xmlhttp.responseText; field.nextSibling.innerHTML = xmlhttp.responseText;
field.nextSibling.style.display = ''; field.nextSibling.style.display = '';
var a = field.nextSibling.firstChild; var a = field.nextSibling.firstChild;
if (a && a.firstChild.data == field.value) { if (a && a.firstChild.data == field.value) {
field.previousSibling.value = decodeURIComponent(a.href.replace(/.*=/, '')); field.previousSibling.value = decodeURIComponent(a.href.replace(/.*=/, ''));
a.style.fontWeight = 'bold'; a.className = 'active';
} }
} }
}); });