For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > September 2007 > How to enforce an ENUM ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to enforce an ENUM ?
Pugi!

2007-09-14, 8:01 am

I have a table with an ENUM row.
If I insert a new row (using PHP5, MySQL5 and PDO for database
connections) with a value that is not in the ENUM list, no error, no
warning, no exception ... The row is inserted but the field where
normally one of the values of the ENUM list should be is empty even if
it is NOT NULL.

How can I enforce the ENUM ?

Pugi!

ZeldorBlat

2007-09-14, 7:02 pm

On Sep 14, 6:50 am, Pugi! <pugin...@gmail.com> wrote:
> I have a table with an ENUM row.
> If I insert a new row (using PHP5, MySQL5 and PDO for database
> connections) with a value that is not in the ENUM list, no error, no
> warning, no exception ... The row is inserted but the field where
> normally one of the values of the ENUM list should be is empty even if
> it is NOT NULL.
>
> How can I enforce the ENUM ?
>
> Pugi!


I looked in the manual for you and found this information:

<http://dev.mysql.com/doc/refman/5.0...raint-enum.html>

Peter H. Coffin

2007-09-14, 7:02 pm

["Followup-To:" header set to comp.databases.mysql.]
On Fri, 14 Sep 2007 03:50:08 -0700, Pugi! wrote:
> I have a table with an ENUM row.
> If I insert a new row (using PHP5, MySQL5 and PDO for database
> connections) with a value that is not in the ENUM list, no error, no
> warning, no exception ... The row is inserted but the field where
> normally one of the values of the ENUM list should be is empty even if
> it is NOT NULL.
>
> How can I enforce the ENUM ?


List the acceptable values in another table. Add a foreign key
constraint to your table and column referring to that list of values.
It's up to you to decide what you want to do with the values in the main
data table when you alter or delete the entry in the list of values
table: nothing, follow the alteration, delete the records with that
value, etc.

--
6. I will not gloat over my enemies' predicament before killing them.
--Peter Anspach's list of things to do as an Evil Overlord
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com