[Dbix-class] Inserting empty string into DATETIME field in MySQL

Alexander Hartmaier alexander.hartmaier at t-systems.at
Tue Oct 11 13:34:54 GMT 2011


This will also replace a false value with undef.
You should better write:
$value = undef if $value eq '';

Am 2011-10-10 22:25, schrieb Peter Wood:
> Thanks! That worked. I just added...
>
>       $value = undef if ! $value;
>
> ...before I ran the insert/update, and it correctly inserted a null string.
>
> -----Original Message-----
> From: Ben Tilly<btilly at gmail.com>
> Reply-To: "DBIx::Class user and developer list"
> <dbix-class at lists.scsys.co.uk>
> Date: Mon, 10 Oct 2011 11:42:56 -0700
> To: "DBIx::Class user and developer list"<dbix-class at lists.scsys.co.uk>
> Subject: Re: [Dbix-class] Inserting empty string into DATETIME field in
> MySQL
>
>> The date you're getting is what you tend to get when MySQL sees that
>> there should be a value but can't parse the result.
>>
>> Try passing in undef instead of an empty string and see if it works right.
>>
>> On Mon, Oct 10, 2011 at 11:30 AM, Peter Wood<pwood at christianbook.com>
>> wrote:
>>> Hello,
>>> I'm trying to insert an empty string into a datetime field in MySQL
>>> version
>>> 5.0.18, using DBIx::Class version 0.08120. This particular field is
>>> defined
>>> like so, within a call to 'add_columns':
>>> __PACKAGE__->add_columns(
>>> ..snip..
>>> "start_date",
>>>    {
>>>      data_type =>  "DATETIME",
>>>      default_value =>  undef,
>>>      is_nullable =>  1,
>>>      size =>  19,
>>>    },
>>> ..snip..
>>> );
>>> If I provide a complete value for start_date (eg 2011-10-10 14:29:27),
>>> everything works fine. However, when I try to set it to the empty string
>>> (''), the value inserted in the database is '0000-00-00 00:00:00'. If I
>>> run
>>> an insert on the command-line mysql client, and provide the empty
>>> string as
>>> the value for that field, it properly sets an empty value in the
>>> database.
>>> Is there something else I should be doing to properly insert an empty
>>> string
>>> into this column?
>>> Thanks,
>>> Peter
>>> _______________________________________________
>>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>>> IRC: irc.perl.org#dbix-class
>>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>>> Searchable Archive:
>>> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>>>
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive:
>> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*



More information about the DBIx-Class mailing list