How to enforce an ENUM ?

This is a discussion on How to enforce an ENUM ? within the MySQL Database forums, part of the Database Forums category; I have a table with an ENUM row. If I insert a new row (using PHP5, MySQL5 and PDO for ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-14-2007
Pugi!
 
Posts: n/a
Default How to enforce an ENUM ?

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!

Reply With Quote
  #2 (permalink)  
Old 09-14-2007
Peter H. Coffin
 
Posts: n/a
Default Re: How to enforce an ENUM ?

["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
Reply With Quote
  #3 (permalink)  
Old 09-14-2007
ZeldorBlat
 
Posts: n/a
Default Re: How to enforce an ENUM ?

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/en/constraint-enum.html>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:02 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0