Re: mysql default value

2009-03-19 Thread Larry Meadors
On Wed, Mar 18, 2009 at 9:47 PM, Kengkaj Sathianpantarit wrote: > Interesting, thanks. > > However, I think it's a bit ugly. And what about if we want to insert null > value? > You can't: `status` VARCHAR(20) NOT NULL DEFAULT 'ready', But I do agree, it is kind of ugly. ;-) I wonder if

Re: mysql default value

2009-03-19 Thread Alin Popa
Sounds like what I need it, Thanks. 2009/3/18 Iwao AVE! : > Hi Alin, > > How about using or ? > > >  INSERT INTO vjobs ( >  name, status >   >   description >   >  ) VALUES ( >  #name#, #status# >   >   #description# >   >  ) > > > I haven't tested this, but it should work. > > Regards, > Iwao

Re: mysql default value

2009-03-18 Thread Kengkaj Sathianpantarit
Interesting, thanks. However, I think it's a bit ugly. And what about if we want to insert null value? Kengkaj 2009/3/18 Iwao AVE! > Hi Alin, > > How about using or ? > > > INSERT INTO vjobs ( > name, status > > description > > ) VALUES ( > #name#, #status# > > #description# >

Re: mysql default value

2009-03-18 Thread Iwao AVE!
Hi Alin, How about using or ? INSERT INTO vjobs ( name, status description ) VALUES ( #name#, #status# #description# ) I haven't tested this, but it should work. Regards, Iwao on 09.3.18 9:42 PM Alin Popa said the following: > Thanks Nicholoz, > > This is what I've

Re: mysql default value

2009-03-18 Thread Nicholoz Koka Kiknadze
I do not like idea of keeping defaults both in database and application. If I have a not nullable database field with some default value, besides setting default value in database I use 'before insert' table trigger that checks if supplied value is NULL and sets it to the desired value. Well, I b

Re: mysql default value

2009-03-18 Thread Kengkaj Sathianpantarit
I think it would be better to put initialize code in constructor, putting checking code in getter will make unnecessary checking every time the getter is called. Kengkaj On Wed, Mar 18, 2009 at 8:00 PM, Alex Sherwin wrote: > What I ususally do: > > > public String getStatus() { > return null ==

Re: mysql default value

2009-03-18 Thread Alex Sherwin
What I ususally do: public String getStatus() { return null == status ? "Some Default Value" : status; } Alin Popa wrote: Thanks Nicholoz, This is what I've done. And I also have a facade that will abstract for the user, the insert actions. I thought that ibatis knows how to handle this, or

Re: mysql default value

2009-03-18 Thread Alin Popa
Thanks Nicholoz, This is what I've done. And I also have a facade that will abstract for the user, the insert actions. I thought that ibatis knows how to handle this, or have a trick for it. On Wed, Mar 18, 2009 at 10:51 AM, Nicholoz Koka Kiknadze wrote: >> Why don't you just exclude this field

Re: mysql default value

2009-03-18 Thread Nicholoz Koka Kiknadze
> Why don't you just exclude this field in the ? INSERT INTO vjobs(name, description) VALUES (#name#,#description#) GL IMO because sometimes one need to insert NULL values too. So why don't you add another insert statement to your xml that will omit the status field? On Wed, Mar 18, 2009 a

Re: mysql default value

2009-03-18 Thread Kengkaj Sathianpantarit
However, I think that default value is good in the case that we don't need to specify value in INSERT command. Why don't you just exclude this field in the ? For , I think that we should specify value explicitly in the model, error from database is correct behavior in case the field has null value

Re: mysql default value

2009-03-18 Thread Kengkaj Sathianpantarit
Sorry, I thought iBATIS should support this behavior. You can solve this problem easily by specify default value in Java class. public class Example { private String status; ... public Example() { this.status = "ready"; } ... } On Wed, Mar 18, 2009 at 3:06 PM, Alin Popa wr

Re: mysql default value

2009-03-18 Thread Alin Popa
Thanks Kengkaj, But from what I read it seems that nullValue is used to substitute value with a database NULL. The thing is that I'm not allowed to use null since field is "NOT NULL". On Wed, Mar 18, 2009 at 6:00 AM, Kengkaj Sathianpantarit wrote: > Use null value replacement feature, read user

Re: mysql default value

2009-03-17 Thread Kengkaj Sathianpantarit
Use null value replacement feature, read user manual. Kengkaj On Tue, Mar 17, 2009 at 10:37 PM, Alin Popa wrote: > Hi, > > I have the following db table (MySQL): > > CREATE TABLE `examples`( >`id` SERIAL PRIMARY KEY, >`name` VARCHAR(255), >`status` VARCHAR(20) NOT NULL D

mysql default value

2009-03-17 Thread Alin Popa
Hi, I have the following db table (MySQL): CREATE TABLE `examples`(        `id` SERIAL PRIMARY KEY,        `name` VARCHAR(255),        `status` VARCHAR(20) NOT NULL DEFAULT 'ready',        `description` TEXT ) ENGINE=innodb DEFAULT CHARSET utf8 DEFAULT COLLATE utf8_bin; Using ibatis sql-map I'm