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

Michael Higgins linux at evolone.org
Tue Jan 15 16:19:37 GMT 2008


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 = shift;
  my $type = "DateTime::Format::Strptime";
  eval "use ${type}";
  $self->throw_exception("Couldn't load ${type}: $@") if $@;
  return $type->new( pattern => '%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 => '%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 => {accessor=>'order_date',data_type =>
'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. 

-- 
 |\  /|        |   |          ~ ~  
 | \/ |        |---|          `|` ?
 |    |ichael  |   |iggins    \^ /
 michael.higgins[at]evolone[dot]org



More information about the DBIx-Class mailing list