RFE #422243: Functions depending on MySQL field type.

This commit is contained in:
Garvin Hicking
2003-03-12 14:42:27 +00:00
parent c0e9a2a685
commit 388deede35
5 changed files with 191 additions and 4 deletions

View File

@@ -6,6 +6,13 @@ $Id$
$Source$ $Source$
2003-03-12 Garvin Hicking <me@supergarv.de> 2003-03-12 Garvin Hicking <me@supergarv.de>
* tbl_change.php3, config.inc.php3, libraries/config_import.lib.php3,
libraries/common.lib.php3: RFE #422243 - Definition of which MySQL functions
map to which MySQL field type and in the dropdown of the function list first
display the fitting functions, and then for compatibility reasons the rest of
the functions.
TODO: I don't know if I chose the correct mapping for all types. Please correct
config_import.lib.php3 and config.inc.php3 if therer are any mismappings.
* sql.php3, tbl_alter.php3, tbl_move_copy.php3, tbl_properties_structure.php3, * sql.php3, tbl_alter.php3, tbl_move_copy.php3, tbl_properties_structure.php3,
tbl_rename.php3, libraries/relation.lib.php3: tbl_rename.php3, libraries/relation.lib.php3:
Bugfix #579256 / RFE #577328 : Automatic update of relations, Bugfix #579256 / RFE #577328 : Automatic update of relations,

View File

@@ -543,6 +543,78 @@ if ($cfg['ShowFunctionFields']) {
'WEEKDAY', 'WEEKDAY',
'CONCAT' 'CONCAT'
); );
// Which column types will be mapped to which Group?
$cfg['RestricColumnTypes'] = array(
'VARCHAR' => 'FUNC_CHAR',
'TINYINT' => 'FUNC_NUMBER',
'TEXT' => 'FUNC_CHAR',
'DATE' => 'FUNC_DATE',
'SMALLINT' => 'FUNC_NUMBER',
'MEDIUMINT' => 'FUNC_NUMBER',
'INT' => 'FUNC_NUMBER',
'BIGINT' => 'FUNC_NUMBER',
'FLOAT' => 'FUNC_NUMBER',
'DOUBLE' => 'FUNC_NUMBER',
'DECIMAL' => 'FUNC_NUMBER',
'DATETIME' => 'FUNC_DATE',
'TIMESTAMP' => 'FUNC_DATE',
'TIME' => 'FUNC_DATE',
'YEAR' => 'FUNC_DATE',
'CHAR' => 'FUNC_CHAR',
'TINYBLOB' => 'FUNC_CHAR',
'TINYTEXT' => 'FUNC_CHAR',
'BLOB' => 'FUNC_CHAR',
'MEDIUMBLOB' => 'FUNC_CHAR',
'MEDIUMTEXT' => 'FUNC_CHAR',
'LONGBLOB' => 'FUNC_CHAR',
'LONGTEXT' => 'FUNC_CHAR',
'ENUM' => '',
'SET' => ''
);
// Map above defined groups to any function
$cfg['RestricFunctions'] = array(
'FUNC_CHAR' => array(
'ASCII',
'CHAR',
'SOUNDEX',
'LCASE',
'UCASE',
'PASSWORD',
'MD5',
'ENCRYPT',
'LAST_INSERT_ID',
'USER',
'CONCAT'
),
'FUNC_DATE' => array(
'NOW',
'CURDATE',
'CURTIME',
'FROM_DAYS',
'FROM_UNIXTIME',
'PERIOD_ADD',
'PERIOD_DIFF',
'TO_DAYS',
'UNIX_TIMESTAMP',
'WEEKDAY'
),
'FUNC_NUMBER' => array(
'ASCII',
'CHAR',
'MD5',
'ENCRYPT',
'RAND',
'LAST_INSERT_ID',
'COUNT',
'AVG',
'SUM'
)
);
} // end if } // end if

View File

@@ -138,7 +138,7 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
* Includes compatibility code for older config.inc.php3 revisions * Includes compatibility code for older config.inc.php3 revisions
* if necessary * if necessary
*/ */
if (!isset($cfg['FileRevision']) || (int) substr($cfg['FileRevision'], 13, 3) < 167) { if (!isset($cfg['FileRevision']) || (int) substr($cfg['FileRevision'], 13, 3) < 168) {
include('./libraries/config_import.lib.php3'); include('./libraries/config_import.lib.php3');
} }

View File

@@ -969,6 +969,77 @@ if (!defined('PMA_CONFIG_IMPORT_LIB_INCLUDED')) {
'CONCAT' 'CONCAT'
); );
} }
// Which column types will be mapped to which Group?
$cfg['RestricColumnTypes'] = array(
'VARCHAR' => 'FUNC_CHAR',
'TINYINT' => 'FUNC_NUMBER',
'TEXT' => 'FUNC_CHAR',
'DATE' => 'FUNC_DATE',
'SMALLINT' => 'FUNC_NUMBER',
'MEDIUMINT' => 'FUNC_NUMBER',
'INT' => 'FUNC_NUMBER',
'BIGINT' => 'FUNC_NUMBER',
'FLOAT' => 'FUNC_NUMBER',
'DOUBLE' => 'FUNC_NUMBER',
'DECIMAL' => 'FUNC_NUMBER',
'DATETIME' => 'FUNC_DATE',
'TIMESTAMP' => 'FUNC_DATE',
'TIME' => 'FUNC_DATE',
'YEAR' => 'FUNC_DATE',
'CHAR' => 'FUNC_CHAR',
'TINYBLOB' => 'FUNC_CHAR',
'TINYTEXT' => 'FUNC_CHAR',
'BLOB' => 'FUNC_CHAR',
'MEDIUMBLOB' => 'FUNC_CHAR',
'MEDIUMTEXT' => 'FUNC_CHAR',
'LONGBLOB' => 'FUNC_CHAR',
'LONGTEXT' => 'FUNC_CHAR',
'ENUM' => '',
'SET' => ''
);
// Map above defined groups to any function
$cfg['RestricFunctions'] = array(
'FUNC_CHAR' => array(
'ASCII',
'CHAR',
'SOUNDEX',
'LCASE',
'UCASE',
'PASSWORD',
'MD5',
'ENCRYPT',
'LAST_INSERT_ID',
'USER',
'CONCAT'
),
'FUNC_DATE' => array(
'NOW',
'CURDATE',
'CURTIME',
'FROM_DAYS',
'FROM_UNIXTIME',
'PERIOD_ADD',
'PERIOD_DIFF',
'TO_DAYS',
'UNIX_TIMESTAMP',
'WEEKDAY'
),
'FUNC_NUMBER' => array(
'ASCII',
'CHAR',
'MD5',
'ENCRYPT',
'RAND',
'LAST_INSERT_ID',
'COUNT',
'AVG',
'SUM'
)
);
} }
if (!isset($cfg['PmaAbsoluteUri_DisableWarning'])) { if (!isset($cfg['PmaAbsoluteUri_DisableWarning'])) {

View File

@@ -334,14 +334,51 @@ for ($i = 0; $i < $fields_cnt; $i++) {
<?php <?php
echo "\n"; echo "\n";
$selected = ''; $selected = '';
for ($j = 0; $j < count($cfg['Functions']); $j++) {
// garvin: Find the current type in the RestricColumnTypes. Will result in 'FUNC_CHAR'
// or something similar. Then directly look up the entry in the RestricFunctions array,
// which will then reveal the available dropdown options
if (isset($cfg['RestricFunctions']) && isset($cfg['RestricColumnTypes']) && isset($cfg['RestricColumnTypes'][strtoupper($row_table_def['True_Type'])]) && isset($cfg['RestricFunctions'][$cfg['RestricColumnTypes'][strtoupper($row_table_def['True_Type'])]])) {
$dropdown = $cfg['RestricFunctions'][$cfg['RestricColumnTypes'][strtoupper($row_table_def['True_Type'])]];
} else {
$dropdown = array();
}
$dropdown_built = array();
$op_spacing_needed = FALSE;
// garvin: loop on the dropdown array and print all available options for that field.
for ($j = 0; $j < count($dropdown); $j++) {
// for default function = NOW() on first timestamp field // for default function = NOW() on first timestamp field
// -- swix/18jul01 // -- swix/18jul01
$selected = ($first_timestamp && $cfg['Functions'][$j] == 'NOW') $selected = ($first_timestamp && $dropdown[$j] == 'NOW')
? ' selected="selected"' ? ' selected="selected"'
: ''; : '';
echo ' '; echo ' ';
echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n"; echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
$dropdown_built[$dropdown[$j]] = 'TRUE';
$op_spacing_needed = TRUE;
}
// garvin: For compatibility's sake, do not let out all other functions. Instead
// print a seperator (blank) and then show ALL functions which weren't shown
// yet.
for ($j = 0; $j < count($cfg['Functions']); $j++) {
if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
// for default function = NOW() on first timestamp field
// -- swix/18jul01
$selected = ($first_timestamp && $cfg['Functions'][$j] == 'NOW')
? ' selected="selected"'
: '';
if ($op_spacing_needed == TRUE) {
echo ' ';
echo '<option value="">--------</option>' . "\n";
$op_spacing_needed = FALSE;
}
echo ' ';
echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
}
} // end for } // end for
unset($selected); unset($selected);
?> ?>