Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » Enum MySQL datatype
Enum MySQL datatype [message #27] Thu, 11 May 2006 04:04 Go to next message
johandewit is currently offline  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 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
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.


Re: Enum MySQL datatype [message #30 is a reply to message #29] Thu, 11 May 2006 07:57 Go to previous messageGo to next message
johandewit is currently offline  johandewit
Messages: 25
Registered: May 2006
Location: Belgium
Junior Member
I didn't explain it too well I guess.
And it seems this is what you rty to make clear to me:

I have a table users and a table status.

Every user has at least one status. This could be eg

transfered to other site
retired
resigned
fired
working

This states have certain actions bound to them.

active
non-active

An active user has a different processing than non-active.
It is in the status table we have the enum field for action.

In this case we only have enum('active','non-active')
Since we need to write a different piece of code for each action, the use of the enum type in this case seems appropriate.





Re: Enum MySQL datatype [message #31 is a reply to message #30] Thu, 11 May 2006 08:23 Go to previous message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
You can have an ENUM field for status, and an ENUM field for action, but it is not possible to have a single ENUM field which combines both status and action.

Next Topic: //DebugBreak();
Goto Forum:
  


Current Time: Fri Apr 19 02:58:58 EDT 2024

Total time taken to generate the page: 0.01133 seconds