--- Iterator.pm.org Sun Feb 27 10:38:42 2005 +++ Iterator.pm Mon Feb 28 00:40:48 2005 @@ -14,8 +14,38 @@ $PREFETCH; } + +my %driver_cache; + +sub _get_iterator_class { + my $driver = $_[1]->db_Main()->{Driver}->{Name}; + + return $driver_cache{$_[1]}{$driver} if($driver_cache{$_[1]}{$driver}); + + my ($self,$class) = @_; + my $subclass = __PACKAGE__; + + if( $driver eq 'mysql' ){ + $subclass .= '::mysql'; + } + else{ + $subclass .= '::subquery'; + } + + eval qq{require $subclass}; + if($@){ $subclass = __PACKAGE__; } + + $driver_cache{$_[1]}{$driver} = $subclass; + + return $subclass; +} + + sub new { - my($me, $them, $sth, $args) = @_; + my($me, $them, $sth, $args, $unknown) = @_; + my $class = !$unknown ? $me + : $me->_get_iterator_class($them); + bless { _class => $them, _sql => $sth->{Statement}, @@ -25,7 +55,7 @@ _mapper => [], _data => [], _prefetch => $them->iterator_prefetch || $me->PREFETCH, - }, $me; + }, $class; } sub sql { @@ -149,22 +179,13 @@ if $options{prefetch} and $options{prefetch} > 0; $pkg->mk_classdata('iterator_count_type'); - my $iterator_class; + my $iterator_class = __PACKAGE__; + my $driver_unknown = 1; if ($options{driver}) { $iterator_class .= __PACKAGE__ . "::" . $options{driver}; eval qq{require $iterator_class}; $iterator_class = undef if $@; - } - unless ($iterator_class) { - my $dname = $pkg->db_Main->{Driver}->{Name}; - if ($dname eq 'mysql') { - $iterator_class = __PACKAGE__ . '::mysql'; - } - else { - $iterator_class = __PACKAGE__ . '::subquery'; - } - eval qq{require $iterator_class}; - $iterator_class = __PACKAGE__ if $@; + $driver_unknown = 0; } my $statement_check_regexp = $iterator_class->statement_check_regexp; @@ -177,7 +198,7 @@ $sth = $class->$meth(); } - return $iterator_class->new($class, $sth, $args) + return $iterator_class->new($class, $sth, $args, $driver_unknown) if not $plugin_disable and not $class->plugin_iterator_disable and defined wantarray and not wantarray and