Provide proper function list in Insert dropdowns and proper column types in field type dropdowns (Drizzle)
This commit is contained in:
parent
0266ddd7bd
commit
35843439df
@ -2871,10 +2871,14 @@ function PMA_getSupportedDatatypes($html = false, $selected = '')
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$column_types = PMA_DRIZZLE
|
||||
? $cfg['DrizzleColumnTypes']
|
||||
: $cfg['ColumnTypes'];
|
||||
|
||||
if ($html) {
|
||||
// NOTE: the SELECT tag in not included in this snippet.
|
||||
$retval = '';
|
||||
foreach ($cfg['ColumnTypes'] as $key => $value) {
|
||||
foreach ($column_types as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$retval .= "<optgroup label='" . htmlspecialchars($key) . "'>";
|
||||
foreach ($value as $subkey => $subvalue) {
|
||||
@ -2901,7 +2905,7 @@ function PMA_getSupportedDatatypes($html = false, $selected = '')
|
||||
}
|
||||
} else {
|
||||
$retval = array();
|
||||
foreach ($cfg['ColumnTypes'] as $key => $value) {
|
||||
foreach ($column_types as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $subkey => $subvalue) {
|
||||
if ($subvalue !== '-') {
|
||||
@ -2958,15 +2962,50 @@ function PMA_unsupportedDatatypes() {
|
||||
function PMA_getFunctionsForField($field, $insert_mode)
|
||||
{
|
||||
global $cfg, $analyzed_sql, $data;
|
||||
static $functions, $restrict_functions;
|
||||
|
||||
if (!isset($functions)) {
|
||||
if (PMA_DRIZZLE) {
|
||||
// Remove unavailable functions
|
||||
$functions = array_diff($cfg['Functions'], $cfg['DrizzleRemoveFunctions']);
|
||||
$restrict_functions = $cfg['RestrictFunctions'];
|
||||
unset($restrict_functions['FUNC_SPATIAL']);
|
||||
foreach ($restrict_functions as &$v) {
|
||||
$v = array_diff($v, $cfg['DrizzleRemoveFunctions']);
|
||||
}
|
||||
unset($v);
|
||||
|
||||
// Add new functions
|
||||
$sql = "SELECT upper(plugin_name) f
|
||||
FROM data_dictionary.plugins
|
||||
WHERE plugin_name IN ('" . implode("','", array_keys($cfg['DrizzleAddFunctions'])) . "')
|
||||
AND plugin_type = 'Function'
|
||||
AND is_active";
|
||||
$drizzle_funcs = PMA_DBI_fetch_result($sql, 'f', 'f');
|
||||
$functions = array_merge($functions, $drizzle_funcs);
|
||||
sort($functions);
|
||||
foreach ($drizzle_funcs as $function) {
|
||||
$category = $cfg['DrizzleAddFunctions'][$function];
|
||||
$restrict_functions[$category][] = $function;
|
||||
}
|
||||
foreach ($restrict_functions as &$v) {
|
||||
sort($v);
|
||||
}
|
||||
unset($v);
|
||||
} else {
|
||||
$functions = &$cfg['Functions'];
|
||||
$restrict_functions = &$cfg['RestrictFunctions'];
|
||||
}
|
||||
}
|
||||
|
||||
$selected = '';
|
||||
// Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
|
||||
// or something similar. Then directly look up the entry in the RestrictFunctions array,
|
||||
// which will then reveal the available dropdown options
|
||||
if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
|
||||
&& isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
|
||||
&& isset($restrict_functions[$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
|
||||
$current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
|
||||
$dropdown = $cfg['RestrictFunctions'][$current_func_type];
|
||||
$dropdown = $restrict_functions[$current_func_type];
|
||||
$default_function = $cfg['DefaultFunctions'][$current_func_type];
|
||||
} else {
|
||||
$dropdown = array();
|
||||
@ -2992,7 +3031,7 @@ function PMA_getFunctionsForField($field, $insert_mode)
|
||||
&& $field['Key'] == 'PRI'
|
||||
&& ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')
|
||||
) {
|
||||
$default_function = $cfg['DefaultFunctions']['pk_char36'];
|
||||
$default_function = $cfg['DefaultFunctions']['FUNC_UUID'];
|
||||
}
|
||||
// this is set only when appropriate and is always true
|
||||
if (isset($field['display_binary_as_hex'])) {
|
||||
@ -3015,12 +3054,12 @@ function PMA_getFunctionsForField($field, $insert_mode)
|
||||
// For compatibility's sake, do not let out all other functions. Instead
|
||||
// print a separator (blank) and then show ALL functions which weren't shown
|
||||
// yet.
|
||||
$cnt_functions = count($cfg['Functions']);
|
||||
$cnt_functions = count($functions);
|
||||
for ($j = 0; $j < $cnt_functions; $j++) {
|
||||
if (! isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'true') {
|
||||
if (! isset($dropdown_built[$functions[$j]]) || $dropdown_built[$functions[$j]] != 'true') {
|
||||
// Is current function defined as default?
|
||||
$selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
|
||||
|| (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
|
||||
$selected = ($field['first_timestamp'] && $functions[$j] == $cfg['DefaultFunctions']['first_timestamp'])
|
||||
|| (!$field['first_timestamp'] && $functions[$j] == $default_function)
|
||||
? ' selected="selected"'
|
||||
: '';
|
||||
if ($op_spacing_needed == true) {
|
||||
@ -3030,7 +3069,7 @@ function PMA_getFunctionsForField($field, $insert_mode)
|
||||
}
|
||||
|
||||
$retval .= ' ';
|
||||
$retval .= '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
|
||||
$retval .= '<option' . $selected . '>' . $functions[$j] . '</option>' . "\n";
|
||||
}
|
||||
} // end for
|
||||
|
||||
|
||||
@ -2809,6 +2809,51 @@ $cfg['ColumnTypes'] = array(
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Column types for Drizzle database;
|
||||
* VARCHAR, TINYINT, TEXT and DATE are listed first, based on estimated popularity
|
||||
*
|
||||
* @global array $cfg['ColumnTypesDrizzle']
|
||||
*/
|
||||
$cfg['DrizzleColumnTypes'] = array(
|
||||
// most used
|
||||
'INTEGER',
|
||||
'VARCHAR',
|
||||
'TEXT',
|
||||
'DATE',
|
||||
|
||||
// numeric
|
||||
'NUMERIC' => array(
|
||||
'INTEGER',
|
||||
'BIGINT',
|
||||
'-',
|
||||
'DECIMAL',
|
||||
'DOUBLE',
|
||||
'-',
|
||||
'BOOLEAN',
|
||||
'SERIAL',
|
||||
'UUID',
|
||||
),
|
||||
|
||||
|
||||
// Date/Time
|
||||
'DATE and TIME' => array(
|
||||
'DATE',
|
||||
'DATETIME',
|
||||
'TIMESTAMP',
|
||||
'TIME',
|
||||
),
|
||||
|
||||
// Text
|
||||
'STRING' => array(
|
||||
'VARCHAR',
|
||||
'TEXT',
|
||||
'VARBINARY',
|
||||
'BLOB',
|
||||
'ENUM',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Attributes
|
||||
*
|
||||
@ -2822,6 +2867,15 @@ $cfg['AttributeTypes'] = array(
|
||||
'on update CURRENT_TIMESTAMP',
|
||||
);
|
||||
|
||||
/**
|
||||
* Attributes for Drizzle database
|
||||
*
|
||||
* @global array $cfg['AttributeTypesDrizzle']
|
||||
*/
|
||||
$cfg['DrizzleAttributeTypes'] = array(
|
||||
'',
|
||||
'on update CURRENT_TIMESTAMP',
|
||||
);
|
||||
|
||||
if ($cfg['ShowFunctionFields']) {
|
||||
/**
|
||||
@ -2927,6 +2981,45 @@ if ($cfg['ShowFunctionFields']) {
|
||||
'YEARWEEK',
|
||||
);
|
||||
|
||||
/**
|
||||
* MySQL functions that are unavailable in Drizzle
|
||||
*
|
||||
* @global array $cfg['DrizzleRemoveFunctions']
|
||||
*/
|
||||
$cfg['DrizzleRemoveFunctions'] = array(
|
||||
'BIT_LENGTH',
|
||||
'DES_DECRYPT',
|
||||
'DES_ENCRYPT',
|
||||
'ENCRYPT',
|
||||
'INET_ATON',
|
||||
'INET_NTOA',
|
||||
'OLD_PASSWORD',
|
||||
'PASSWORD',
|
||||
'SEC_TO_TIME',
|
||||
'SHA1',
|
||||
'SOUNDEX', // https://bugs.launchpad.net/drizzle/+bug/804566
|
||||
'SYSDATE',
|
||||
'TIME', // https://bugs.launchpad.net/drizzle/+bug/804571
|
||||
'TIMESTAMP',
|
||||
'TIME_TO_SEC',
|
||||
'UTC_DATE',
|
||||
'UTC_TIME',
|
||||
'WEEK', // same as TIME
|
||||
'WEEKOFYEAR',
|
||||
'YEARWEEK',
|
||||
);
|
||||
|
||||
/**
|
||||
* Drizzle functions that are unavailable in MySQL
|
||||
* This list will be verified by a lookup to data_dictionary.plugins
|
||||
*
|
||||
* @global array $cfg['DrizzleAddFunctions']
|
||||
*/
|
||||
$cfg['DrizzleAddFunctions'] = array(
|
||||
'MYSQL_PASSWORD' => 'FUNC_CHAR',
|
||||
'ROT13' => 'FUNC_CHAR',
|
||||
);
|
||||
|
||||
/**
|
||||
* Which column types will be mapped to which Group?
|
||||
*
|
||||
@ -2937,6 +3030,7 @@ if ($cfg['ShowFunctionFields']) {
|
||||
'SMALLINT' => 'FUNC_NUMBER',
|
||||
'MEDIUMINT' => 'FUNC_NUMBER',
|
||||
'INT' => 'FUNC_NUMBER',
|
||||
'INTEGER' => 'FUNC_NUMBER', // Drizzle
|
||||
'BIGINT' => 'FUNC_NUMBER',
|
||||
'DECIMAL' => 'FUNC_NUMBER',
|
||||
'FLOAT' => 'FUNC_NUMBER',
|
||||
@ -2964,6 +3058,7 @@ if ($cfg['ShowFunctionFields']) {
|
||||
'MEDIUMBLOB' => 'FUNC_CHAR',
|
||||
'BLOB' => 'FUNC_CHAR',
|
||||
'LONGBLOB' => 'FUNC_CHAR',
|
||||
'UUID' => 'FUNC_UUID', // Drizzle
|
||||
'ENUM' => '',
|
||||
'SET' => '',
|
||||
|
||||
@ -2975,7 +3070,6 @@ if ($cfg['ShowFunctionFields']) {
|
||||
'MULTILINESTRING' => 'FUNC_SPATIAL',
|
||||
'MULTIPOLYGON' => 'FUNC_SPATIAL',
|
||||
'GEOMETRYCOLLECTION' => 'FUNC_SPATIAL',
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
@ -3017,9 +3111,13 @@ if ($cfg['ShowFunctionFields']) {
|
||||
'UUID',
|
||||
),
|
||||
|
||||
'FUNC_UUID' => array(
|
||||
'UUID', // Drizzle
|
||||
),
|
||||
|
||||
'FUNC_DATE' => array(
|
||||
'CURDATE',
|
||||
'CURTIME',
|
||||
'CURRENT_DATE',
|
||||
'CURRENT_TIME',
|
||||
'DATE',
|
||||
'FROM_DAYS',
|
||||
'FROM_UNIXTIME',
|
||||
@ -3119,7 +3217,7 @@ if ($cfg['ShowFunctionFields']) {
|
||||
'FUNC_DATE' => '',
|
||||
'FUNC_NUMBER' => '',
|
||||
'first_timestamp' => 'NOW',
|
||||
'pk_char36' => 'UUID',
|
||||
'FUNC_UUID' => 'UUID',
|
||||
);
|
||||
} // end if
|
||||
|
||||
|
||||
@ -464,13 +464,16 @@ for ($i = 0; $i < $num_fields; $i++) {
|
||||
$default_current_timestamp = false;
|
||||
}
|
||||
|
||||
$cnt_attribute_types = count($cfg['AttributeTypes']);
|
||||
$attribute_types = PMA_DRIZZLE
|
||||
? $cfg['DrizzleAttributeTypes']
|
||||
: $cfg['AttributeTypes'];
|
||||
$cnt_attribute_types = count($attribute_types);
|
||||
for ($j = 0; $j < $cnt_attribute_types; $j++) {
|
||||
$content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
|
||||
if (strtoupper($attribute) == strtoupper($cfg['AttributeTypes'][$j])) {
|
||||
$content_cells[$i][$ci] .= ' <option value="'. $attribute_types[$j] . '"';
|
||||
if (strtoupper($attribute) == strtoupper($attribute_types[$j])) {
|
||||
$content_cells[$i][$ci] .= ' selected="selected"';
|
||||
}
|
||||
$content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>';
|
||||
$content_cells[$i][$ci] .= '>' . $attribute_types[$j] . '</option>';
|
||||
}
|
||||
|
||||
$content_cells[$i][$ci] .= '</select>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user