[Dbix-class] InflateColumn DateTime tricks with MSSQL/Microsoft_SQL_Server

Christopher H. Laco claco at chrislaco.com
Tue Jan 15 16:29:44 GMT 2008


Michael Higgins wrote:
> Folks --
> =

> What I thought would be trivial turns to be burdensome. Probably, it's
> just me, but:
> =

> I've done my best to understand what
> DBIx-Class/lib/DBIx/Class/InflateColumn/DateTime.pm does, yet I can't
> see how it honors the reported storage engine.
> =

> But, if it does, I've tried setting the storage engine to ::DBI::MSSQL
> with no joy.
> =

> There is a new module, ::DBI::ODBC::Microsoft_SQL_Server.pm which
> provides, if I understand it, some overloaded methods to accommodate.
> =

> And, examining ::DBI::MSSQL, I see this:
> =

> sub build_datetime_parser {
>   my $self =3D shift;
>   my $type =3D "DateTime::Format::Strptime";
>   eval "use ${type}";
>   $self->throw_exception("Couldn't load ${type}: $@") if $@;
>   return $type->new( pattern =3D> '%m/%d/%Y %H:%M:%S' );
> }
> =

> And in InflateColumn::DateTime:
> =

> "This module figures out the type
> of DateTime::Format::* class to inflate/deflate with based on the type
> of DBIx::Class::Storage::DBI::*"
> =

> So what am I missing? Why isn't my storage already determined when I
> start my script? Why doesn't setting it explicitly to this module, with
> this subroutine produce a proper parser..??
> =

> Is it possible that this ::DBI::MSSQL sub is honored, but not properly
> coded?        * %N
>            Nanoseconds. For other sub-second values use "%[number]N".
> =

> The error I was getting is: Invalid date format: 2008-01-14 00:00:00.000
> =

> So, maybe this should be: return $type->new( pattern =3D> '%m/%d/%Y
> %H:%M:%S.%N' ); ???
> =

> I've added the sub as above, with the nanosecond string,
> to ::DBI::ODBC::Microsoft_SQL_Server.pm and set it explicitly in my
> script.
> =

> My classes look like =3D> {accessor=3D>'order_date',data_type =3D>
> 'datetime'},
> =

> If I set the storage type in my script, then call ->ensure_connected,
> it deletes the key I set:
> =

> $trex_schema->storage_type('::DBI::ODBC::Microsoft_SQL_Server');
> # $trex_schema->storage->ensure_connected();
> print $trex_schema->storage_type; =

>                       # overwritten to ::DBI using line above
> =

> At any rate, nothing breaks in getting the records, the selects are
> still working (for whatever reason) but now the call to ->mdy('/')
> fails:
> =

> Can't call method "mdy" on an undefined value =

> =

> and a call without ->mdy returns undef.
> =

> Can anyone help figure this out? It seems like it should work as
> advertised without my intervening, but didn't. I've done my best to try
> to root out the problem, and failed.
> =

> Any help appreciated. =

> =


I'm late to the party, but I use this component a lot.
First, is DateTime::Format::MySQL actually installed? (did this thread =

start about MySQL?)


Second, InflateColumn::DateTime inflates db column values into DateTime =

objects. Keep this in mind though, that when you set values using accessors:

     $obj->dtfield(DateTime->new)

When setting as an object, no need to worry. It should DoTheRightThing...

     $obj->dtfield($string)

When setting as a string, you must supply the string in the same format =

as the database you are using, and MySQL, or really SQLite will take =

just about any thing because it's silly, but the MySQL formatter may not =

understand it.

Now, first things second: show us the source of your schema classes, =

where you load this component and declate fields as a datetime type.

-=3DChris


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080115/12=
4ff259/signature.pgp


More information about the DBIx-Class mailing list