JonathanAquino.11106565-opCBI309nnGakBO8gow8eQ@public.gmane.org
2005-May-24 05:45 UTC
Storing empty string vs. null in database
Will rails store blank form elements as empty strings or null in the database? I''m guessing empty strings ... but isn''t it considered "poor form" to have empty strings in the database, rather than nulls?
I think from the way HTTP (forms) works, blank form fields *is* empty strings. Its not even correct for any framework to auto null fields. You''ll have to do your own, same everywhere. For Rails, set the desired attribute as nil then they''ll be saved as NULL in database. disclaimer: rails newbie. correct me if i''m wrong. On 24 May 2005 05:45:02 -0000, JonathanAquino.11106565-opCBI309nnGakBO8gow8eQ@public.gmane.org <JonathanAquino.11106565-opCBI309nnGakBO8gow8eQ@public.gmane.org> wrote:> Will rails store blank form elements as empty strings or null in the database? > > I''m guessing empty strings ... but isn''t it considered "poor form" to have > empty strings in the database, rather than nulls? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- choonkeat @ http://blog.yanime.org/ this email is: [ ] bloggable [ x ] ask first [ ] private
On May 23, 2005, at 10:45 PM, JonathanAquino.11106565-opCBI309nnGakBO8gow8eQ@public.gmane.org wrote:> Will rails store blank form elements as empty strings or null in > the database? > I''m guessing empty strings ... but isn''t it considered "poor form" > to have > empty strings in the database, rather than nulls?Empty strings are converted to nil if assigned to a numeric column but are otherwise untouched. jeremy
On Tuesday 24 May 2005 01:45 am, JonathanAquino.11106565-opCBI309nnGakBO8gow8eQ@public.gmane.org wrote:> but isn''t it considered "poor form" to have > empty strings in the database, rather than nulls?[Eyes bugged out!]. What? 1) some databases leave you no choice, but 2) The absences of data (NULL) is not-the-same as "a zero length string". You can''t generalize this type of thing, but I think its generally a bad thing to try to consider these things equal. David
On 5/24/05, David Corbin <dcorbin-wmGZ+vDKSyrZJqsBc5GL+g@public.gmane.org> wrote:> On Tuesday 24 May 2005 01:45 am, JonathanAquino.11106565-opCBI309nnGakBO8gow8eQ@public.gmane.org wrote: > > but isn''t it considered "poor form" to have > > empty strings in the database, rather than nulls? > > [Eyes bugged out!]. What? 1) some databases leave you no choice, but 2) The > absences of data (NULL) is not-the-same as "a zero length string". > > You can''t generalize this type of thing, but I think its generally a bad thing > to try to consider these things equal.There''s some oracle configuration option that maps '''' to null automatically. It was the most painful ''feature'' I ever found in that abomination. But yes, '''' and nil are *not* the same thing.> David > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
On Tuesday 24 May 2005 06:30 am, Michael Koziarski wrote:> There''s some oracle configuration option that maps '''' to null > automatically. It was the most painful ''feature'' I ever found in that > abomination. But yes, '''' and nil are *not* the same thing.It''s an option and can be disabled? That''s good news.
On 5/24/05, David Corbin <dcorbin-wmGZ+vDKSyrZJqsBc5GL+g@public.gmane.org> wrote:> On Tuesday 24 May 2005 06:30 am, Michael Koziarski wrote: > > > There''s some oracle configuration option that maps '''' to null > > automatically. It was the most painful ''feature'' I ever found in that > > abomination. But yes, '''' and nil are *not* the same thing. > > It''s an option and can be disabled? That''s good news.Yes, unless your DBA considers it a feature .... ;) -- Cheers Koz
Unless it''s Oracle *:)
On Tuesday, May 24, 2005, 8:24:16 PM, David wrote:> On Tuesday 24 May 2005 01:45 am, > JonathanAquino.11106565-opCBI309nnGakBO8gow8eQ@public.gmane.org wrote: >> but isn''t it considered "poor form" to have >> empty strings in the database, rather than nulls?> [Eyes bugged out!]. What? 1) some databases leave you no choice, but 2) The > absences of data (NULL) is not-the-same as "a zero length string".> You can''t generalize this type of thing, but I think its generally a bad thing > to try to consider these things equal.I think it''s bad form to just dump form values into the database. The controller/model is responsible for putting stuff in the DB, and the form is in the view. So yeah, do it if it''s simple, but don''t complain about the results :) You could easily write a method that works on any model object which converts "" to nil if that''s what''s wanted. Cheers, Gavin