I have in my database a coloumn say agent which can have enum values (‘G’,’Y’,’M’) where G= google Y= yahoo M= msn
how should i map the output coming from my function i.e google as G in my code so that database recognise it and saves it??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think the easiest way is to get the int representation of the enum value. Enums are numbers in the background, so it’s usually easy to cast an enum member to a number and vice versa.
You can write a converter class for the best flexibility. You can process the enum value and generate a string, or get a string and return an enum member. You can do this in a simple if-then-else or switch-case structure.
If you are using .NET (C#), be aware that you can pass any number as a parameter even you specify an enum, so an else or a default branch is a must in case of conversion.
If you are using PHP, here is an example:
You will get 1 for red, 3 for yellow. If you want to use a string: