Enum MySQL datatype [message #27] |
Thu, 11 May 2006 04:04 |
johandewit
Messages: 25 Registered: May 2006 Location: Belgium
|
Junior Member |
|
|
Hi,
There is support for this datatype, but looking at the examples, it isn't used anywere. Instead the enum type replaced by a dropdown list generated buy the function getLanguageArray();
i'm using the enum type in those cases where processing depends on the value.
Eg. An amployee database. People can have different states like
These states are assigned to some action type, like active or inactive. Depending on the action type, there will be a different processing of the record.
state action
working active
retired inactive
ill inactive
resigned inactive
Eg. Inactive people cannot get a pay raise while active do.
The states will be defined in <sybsystem>text/en/language_array.inc, while the different actions are defined in the database using the enum type.
My common sense tells me for both the state and action, one should use drop down list. The state optionlist is retreived from the text file using the getlanguageArray() function, while the action option list is retreived from the database using the getEnum() method.
Only problem I encountered is that when using the enum type, the validaeField() function always returned an error which makes the Insert/Update impossible.
Following diff solved thois problem, but I don't know if this is the desired enum type validation.
The index value as retreived from the dropdown is replaced with the value. No real validation is done, but since dropdown lists are used, I don't think this is really needed.
Is it a good thing if we encounter an enum type, the optionlist and dropdown input type should be used by default ? In the <specific>.table.class, we should not repeat this for every enum type. If the enum field is required (not NULL), and has a default value, this should be selected with the 'inser' mode. Otherwise the value from the database should be selected. Only if the enum field is optional, an empty line should be added to the optionlist.
Right know, I have always two empty lines in the 'new' screen. Even if I remove the empty line from the optionlist.
I'm willing to give it a try to implement the enum type behavour as described above if this is the desired behaviour.
Greetings
Johan
|
|
|
Re: Enum MySQL datatype [message #29 is a reply to message #27] |
Thu, 11 May 2006 04:55 |
AJM
Messages: 2363 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
Your use of the enum datatype is non-standard. You can define a list of values for 'state' as in:
ENUM('working','retired','ill','resigned') which is equivalent to array(0 => 'working', 1 => 'retired', 2 => 'ill', 3 => 'resigned'). The text values are displayed on the screen in a dropdown list (or even a radio group) but it is the numeric values which are actually stored in the database.
I you try to define a list of values for 'action' as in:
ENUM('active','inactive','inactive','inactive') this would be ridiculous as you have repeating values, so does the value 'inactive' equate to the number 1, 2 or 3?
Trying to store both the 'state' and 'action' in a single field is quite wrong IMHO. 'State' is what you should be displaying to the user, but the correlation between 'state' and 'action' should be done separately.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|