List:MySQL and Java« Previous MessageNext Message »
From:Charles Zhao Date:May 29 2003 9:09pm
Subject:RE: Enum Type...
View as plain text  
I had a similar question like this.  So if you insert an illegal value
into a ENUM column, it will be automatically set to ""?  That's not good
for me.  I was hoping if it's illegal value then the db should give me
an error msg and reject the record.

-----Original Message-----
From: Nick Scholtz [mailto:nick@stripped] 
Sent: Thursday, May 29, 2003 1:57 PM
To: harsh
Cc: java@stripped
Subject: Re: Enum Type...


I don't know if you're having specific issues with java/JDBC relating to
the ENUM type but I can try to explain the basics.

Sample table:

create table test_enum (column1 ENUM('string1','string2'));

Using the ENUM:

insert into test_enum(column1) values(null);

insert into test_enum(column1) values('string1');

insert into test_enum(column1) values('string2');

select * from test_enum;

should get you this:


mysql> select * from test_enum;
+---------+
| column1 |
+---------+
| NULL    |
| string1 |
| string2 |
+---------+
3 rows in set (0.00 sec)


You can also insert an empty string, and if you insert a value that is
not allowed it will be stored as an empty string:

insert into test_enum(column1) values('string3');

mysql> select * from test_enum;
+---------+
| column1 |
+---------+
| NULL    |
| string1 |
| string2 |
|         |
+---------+
4 rows in set (0.00 sec)


You can also try and get fancy and enter a number that corresponds to
the string.

In this case

NUMBER -- Column Value
NULL --> NULL
   0 --> ''
   1 --> 'string1'
   2 --> 'string2'

so you could do the following:

delete from test_enum;  (to clear the table)

insert into test_enum(column1) values(0);
insert into test_enum(column1) values(1);
insert into test_enum(column1) values(2);

mysql> select * from test_enum;
+---------+
| column1 |
+---------+
|         |
| string1 |
| string2 |
+---------+
3 rows in set (0.00 sec)

Does that make it clear?


harsh wrote:
> 
> Hi i need some help in how to store and retrieve data
> from the ENUM type of mysql,i.e i want to keep an
> array of strings in ENUM type,i didn't understand the
> mysql ENUM quite clearly(lack of proper documentation)
> will someone make it clear ??
> 
> thanks
> with regards
> ----------------------------------------------------------------------
> --------
> harsh
> http://www.cse.iitb.ac.in/~harsh
>
------------------------------------------------------------------------
------
> 
> --
> MySQL Java Mailing List
> For list archives: http://lists.mysql.com/java
> To unsubscribe:    http://lists.mysql.com/java?unsub=1

-- 
Nick Scholtz
Planetary Data Systems

-- 
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:
http://lists.mysql.com/java?unsub=1

Thread
Enum Type...harsh29 May
  • Re: Enum Type...Nick Scholtz29 May
    • Re: Enum Type...harsh30 May
      • Re: Enum Type...Mark Matthews30 May
RE: Enum Type...Charles Zhao29 May
  • Re: Enum Type...Mark Matthews29 May
RE: Enum Type...Charles Zhao30 May
Re: Enum Type...Eric Raymond1 Jun