CC: | BRAD [...] cpan.org |
Subject: | [patch] Oracle/Sybase support |
G'day, when using DateTime::Format::DBI for Sybase or Oracle handles the
call to new() fails - neither of DateTime::Format::Sybase and
DateTime::Format::Oracle returns an object.
The attached patch modifies new() to return the names of the modules for
DateTime::Format::Sybase and DateTime::Format::Oracle rather than trying
to instantiate an object. It works around the problem, however a more
robust solution may be to have new() instantiate a DateTime::Format::DBI
object and provide methods that will call the corresponding subs in the
appropriate module - what do you think?
Cheers
Brad
Subject: | datetime-format-dbi.orasyb.patch |
diff -rupN DateTime-Format-DBI-0.035/lib/DateTime/Format/DBI.pm DateTime-Format-DBI-0.035-patched//lib/DateTime/Format/DBI.pm
--- DateTime-Format-DBI-0.035/lib/DateTime/Format/DBI.pm 2010-08-01 15:49:36.000000000 +0100
+++ DateTime-Format-DBI-0.035-patched//lib/DateTime/Format/DBI.pm 2010-09-24 16:28:21.000000000 +0100
@@ -1,4 +1,5 @@
package DateTime::Format::DBI;
+
# $Id: DBI.pm 4451 2010-08-01 14:49:22Z cfaerber $
use strict;
@@ -12,6 +13,7 @@ $VERSION = '0.035';
$VERSION = eval { $VERSION };
our %db_to_parser = (
+
# lowercase for case-insensitivity!
'mysql' => 'DateTime::Format::MySQL',
'pg' => 'DateTime::Format::Pg',
@@ -26,18 +28,22 @@ sub new {
my ($name,$dbh) = @_;
UNIVERSAL::isa($dbh,'DBI::db') || croak('Not a DBI handle.');
-# my $dbtype = $dbh->{Driver}->{Name};
- my @dbtypes = eval { DBI::_dbtype_names($dbh) };
- my $dbtype = shift @dbtypes;
+ my $dbtype = $dbh->{Driver}->{Name};
+# my @dbtypes = eval { DBI::_dbtype_names($dbh) };
+# my $dbtype = shift @dbtypes;
my $pclass = $db_to_parser{lc $dbtype};
$pclass || croak("Unsupported database driver '".$dbtype."'");
+ eval "use $pclass;";
- my $parser = eval "use $pclass; $pclass->new();";
-
- $parser || croak("Cannot load $pclass");
-
- return $parser;
+ # Oracle and Sybase use a static class for DateTime::Format.
+ if ( lc $dbtype eq 'oracle' || lc $dbtype eq 'sybase' ) {
+ return $pclass;
+ }
+ else {
+ return $pclass->new()
+ || croak("Cannot load $pclass");
+ }
}
=head1 NAME