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

Michael Higgins linux at evolone.org
Tue Jan 15 17:52:36 GMT 2008


On Tue, 15 Jan 2008 09:35:17 -0800
Michael Higgins <linux at evolone.org> wrote:

> On Tue, 15 Jan 2008 09:01:49 -0800
> Marc Mims <marc at questright.com> wrote:
> [snip]
> > 
> > I think Michael is using
> > DBIx::Class::Storage::ODBC::Microsoft_SQL_Server, which doesn't
> > provide build_datetime_parser---yet.  I need to add that. Actually,
> > DBI::MSSQL and DBI::ODBC::Microsoft_SQL_Server need to be unified,
> > but I hesitate to do that without assistance from someone actually
> > using DBI::MSSQL so we can ensure the unified code works on both the
> > DBD::ODBC and DBD::Sybase layers.
> > 
> > Micheal, make a local copy of Microsoft_SQL_Server and copy the
> > build_date_time_parser method from DBI::MSSQL into it.  If that
> > works as expected, then I'll add it Microsoft_SQL_Server and commit
> > it.
> 
> Added 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.%3N' );
> }
> 

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

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? 

Cheers,

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



More information about the DBIx-Class mailing list