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

Marc Mims marc at questright.com
Tue Jan 15 18:24:38 GMT 2008


* Michael Higgins <linux at evolone.org> [080115 10:10]:
> Followup to that, if it helps... when I REMOVE that sub, I get this:
> 
> Invalid date format: 2008-01-14 00:00:00.000 at /usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/InflateColumn/DateTime.pm line 76
>         DBIx::Class::InflateColumn::DateTime::__ANON__('2008-01-14 00:00:00.000', 'TrexDB::DATA=HASH(0x8a1f41c)') called at /usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/InflateColumn.pm line 94
>         DBIx::Class::InflateColumn::_inflated_column('TrexDB::DATA=HASH(0x8a1f41c)', 'Ship Date', '2008-01-14 00:00:00.000') called at /usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/InflateColumn.pm line 127
>         DBIx::Class::InflateColumn::get_inflated_column('TrexDB::DATA=HASH(0x8a1f41c)', 'Ship Date') called at /usr/lib/perl5/vendor_perl/5.8.8/Class/Accessor/Grouped.pm line 161
>         Class::Accessor::Grouped::__ANON__('TrexDB::DATA=HASH(0x8a1f41c)') called at furn_man_check.pl line 45

Yes.  That helps.  It indicates that your dates aren't in the format
that the DBI::MSSQL method we copied expects.  I don't know if that's
the result of TDS ODBC, or if that's due to some option set in your SQL
Server.

You should be able to change the pattern in sub build_datetime_parser
(in Microsoft_SQL_Server) to: "%Y-%m-%d %H:%M:%S.%3N".  (That is, if I
read the DateTime::Format::Strptime docs correctly---you may need to
experiment a bit.)

Until we know whether MSSQL *always* returns dates in this fromat via
ODBC, or it is a local configuration issue, we shouldn't commit that
change to DBI::ODBC::Microsoft_SQL_Server.  Hopefully, you can provide
some detail on that?

> I found this sub:
> 
> sub _rebless {
>     my ($self) = @_;
> 
>     my $dbh = $self->dbh;
>     my $dbtype = eval { $dbh->get_info(17) };
>     unless ( $@ ) {
>         # Translate the backend name into a perl identifier
>         $dbtype =~ s/\W/_/gi;
>         my $class = "DBIx::Class::Storage::DBI::ODBC::${dbtype}";
>         eval "require $class";
>         bless $self, $class unless $@;
>     }
> }
> 
> in ODBC.pm... does THAT matter in any way? 

Yes.  When DBIC detects an ODBC backend, via the connection string
'dbi:ODBC:...', it calls this method which reblesses to the appropriate
ODBC subclass, if any.  In your case, Microsoft_SQL_Server.

	-Marc



More information about the DBIx-Class mailing list