1
0
mirror of https://github.com/vrana/adminer.git synced 2025-09-01 18:32:39 +02:00

MySQL: Do not show 'empty' enum value in strict mode

This commit is contained in:
Peter Knut
2024-09-10 23:34:02 +02:00
parent 2439369143
commit 91d0d8538f
7 changed files with 53 additions and 7 deletions

View File

@@ -630,6 +630,13 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
return array(); return array();
} }
/**
* @return bool
*/
function is_strict_mode() {
return false;
}
function show_status() { function show_status() {
return array(); return array();
} }

View File

@@ -50,7 +50,7 @@ if (!defined("DRIVER")) {
$row = $result->fetch_array(); $row = $result->fetch_array();
return $row[$field]; return $row[$field];
} }
function quote($string) { function quote($string) {
return "'" . $this->escape_string($string) . "'"; return "'" . $this->escape_string($string) . "'";
} }
@@ -305,7 +305,7 @@ if (!defined("DRIVER")) {
} }
return queries($prefix . implode(",\n", $values) . $suffix); return queries($prefix . implode(",\n", $values) . $suffix);
} }
function slowQuery($query, $timeout) { function slowQuery($query, $timeout) {
if (min_version('5.7.8', '10.1.2')) { if (min_version('5.7.8', '10.1.2')) {
if (preg_match('~MariaDB~', $this->_conn->server_info)) { if (preg_match('~MariaDB~', $this->_conn->server_info)) {
@@ -322,7 +322,7 @@ if (!defined("DRIVER")) {
: $idf : $idf
); );
} }
function warnings() { function warnings() {
$result = $this->_conn->query("SHOW WARNINGS"); $result = $this->_conn->query("SHOW WARNINGS");
if ($result && $result->num_rows) { if ($result && $result->num_rows) {
@@ -1056,6 +1056,19 @@ if (!defined("DRIVER")) {
return get_key_vals("SHOW VARIABLES"); return get_key_vals("SHOW VARIABLES");
} }
/**
* @return bool
*/
function is_strict_mode() {
static $strictMode = null;
if ($strictMode === null) {
$strictMode = (bool)preg_match('~STRICT_(TRANS|ALL)_TABLES~', get_key_vals("SHOW VARIABLES LIKE 'sql_mode'")["sql_mode"]);
}
return $strictMode;
}
/** Get process list /** Get process list
* @return array ($row) * @return array ($row)
*/ */

View File

@@ -486,6 +486,13 @@ AND c_src.TABLE_NAME = " . q($table);
return get_key_vals('SELECT name, display_value FROM v$parameter'); return get_key_vals('SELECT name, display_value FROM v$parameter');
} }
/**
* @return bool
*/
function is_strict_mode() {
return false;
}
function process_list() { function process_list() {
return get_rows('SELECT sess.process AS "process", sess.username AS "user", sess.schemaname AS "schema", sess.status AS "status", sess.wait_class AS "wait_class", sess.seconds_in_wait AS "seconds_in_wait", sql.sql_text AS "sql_text", sess.machine AS "machine", sess.port AS "port" return get_rows('SELECT sess.process AS "process", sess.username AS "user", sess.schemaname AS "schema", sess.status AS "status", sess.wait_class AS "wait_class", sess.seconds_in_wait AS "seconds_in_wait", sql.sql_text AS "sql_text", sess.machine AS "machine", sess.port AS "port"
FROM v$session sess LEFT OUTER JOIN v$sql sql FROM v$session sess LEFT OUTER JOIN v$sql sql

View File

@@ -860,6 +860,13 @@ AND typelem = 0"
return get_key_vals("SHOW ALL"); return get_key_vals("SHOW ALL");
} }
/**
* @return bool
*/
function is_strict_mode() {
return false;
}
function process_list() { function process_list() {
return get_rows("SELECT * FROM pg_stat_activity ORDER BY " . (min_version(9.2) ? "pid" : "procpid")); return get_rows("SELECT * FROM pg_stat_activity ORDER BY " . (min_version(9.2) ? "pid" : "procpid"));
} }

View File

@@ -764,6 +764,13 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
return $return; return $return;
} }
/**
* @return bool
*/
function is_strict_mode() {
return false;
}
function show_status() { function show_status() {
$return = array(); $return = array();
foreach (get_vals("PRAGMA compile_options") as $option) { foreach (get_vals("PRAGMA compile_options") as $option) {

View File

@@ -914,13 +914,16 @@ function column_foreign_keys($table) {
*/ */
function enum_input($type, $attrs, $field, $value, $empty = null) { function enum_input($type, $attrs, $field, $value, $empty = null) {
global $adminer; global $adminer;
$return = ($empty !== null && !is_strict_mode() ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === 0) ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" : "");
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches); preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
$return = ($empty !== null ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === 0) ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" : "");
foreach ($matches[1] as $i => $val) { foreach ($matches[1] as $i => $val) {
$val = stripcslashes(str_replace("''", "'", $val)); $val = stripcslashes(str_replace("''", "'", $val));
$checked = (is_int($value) ? $value == $i+1 : (is_array($value) ? in_array($i+1, $value) : $value === $val)); $checked = (is_int($value) ? $value == $i+1 : (is_array($value) ? in_array($i+1, $value) : $value === $val));
$return .= " <label><input type='$type'$attrs value='" . ($i+1) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>'; $return .= " <label><input type='$type'$attrs value='" . ($i+1) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
} }
return $return; return $return;
} }

View File

@@ -7,7 +7,7 @@
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) * @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/ */
class AdminerEnumOption { class AdminerEnumOption {
function editInput($table, $field, $attrs, $value) { function editInput($table, $field, $attrs, $value) {
if ($field["type"] == "enum") { if ($field["type"] == "enum") {
$options = array(); $options = array();
@@ -24,7 +24,9 @@ class AdminerEnumOption {
$selected = ""; $selected = "";
} }
} }
$options[0] = lang('empty'); if (!is_strict_mode()) {
$options[0] = lang('empty');
}
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches); preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
foreach ($matches[1] as $i => $val) { foreach ($matches[1] as $i => $val) {
$val = stripcslashes(str_replace("''", "'", $val)); $val = stripcslashes(str_replace("''", "'", $val));
@@ -36,5 +38,5 @@ class AdminerEnumOption {
return "<select$attrs>" . optionlist($options, (string) $selected, 1) . "</select>"; // 1 - use keys return "<select$attrs>" . optionlist($options, (string) $selected, 1) . "</select>"; // 1 - use keys
} }
} }
} }