From: Matt S Trout Date: Fri, 20 Jan 2006 00:18:53 +0000 (+0000) Subject: Moved to prepare_cached for everything, using $f_active and some additional tricks... X-Git-Tag: v0.05005~117^2~38 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cb5f2eeaf536e93839c858bc02da9573e926e4f2;p=dbsrgits%2FDBIx-Class.git Moved to prepare_cached for everything, using $f_active and some additional tricks I got help from Tim Bunce on --- diff --git a/Build.PL b/Build.PL index 9a288b8..7fac43b 100644 --- a/Build.PL +++ b/Build.PL @@ -7,7 +7,7 @@ my %arguments = ( module_name => 'DBIx::Class', requires => { 'Data::Page' => 2.00, - 'DBI' => 0, + 'DBI' => 1.40, 'UNIVERSAL::require' => 0, 'Scalar::Util' => 0, 'SQL::Abstract' => 1.20, diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 3d79dca..f034863 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -167,7 +167,7 @@ Does C, for all column values at once. sub get_columns { my $self = shift; - return return %{$self->{_column_data}}; + return %{$self->{_column_data}}; } =head2 get_dirty_columns diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 67c04a5..c9db108 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -8,7 +8,7 @@ use DBIx::Class::Storage::DBI::Cursor; BEGIN { -package DBIC::SQL::Abstract; # Temporary. Merge upstream. +package DBIC::SQL::Abstract; # Would merge upstream, but nate doesn't reply :( use base qw/SQL::Abstract::Limit/; @@ -280,8 +280,7 @@ sub _select { sub select { my $self = shift; my ($ident, $select, $condition, $attrs) = @_; - my ($rv, $sth, @bind) = $self->_select(@_); - return $self->cursor->new($sth, \@bind, $attrs); + return $self->cursor->new($self, \@_, $attrs); } sub select_single { @@ -291,7 +290,7 @@ sub select_single { } sub sth { - my ($self, $sql, $op) = @_; + my ($self, $sql) = @_; # 3 is the if_active parameter which avoids active sth re-use return $self->dbh->prepare_cached($sql, {}, 3); } diff --git a/lib/DBIx/Class/Storage/DBI/Cursor.pm b/lib/DBIx/Class/Storage/DBI/Cursor.pm index 67476c7..41b3da5 100644 --- a/lib/DBIx/Class/Storage/DBI/Cursor.pm +++ b/lib/DBIx/Class/Storage/DBI/Cursor.pm @@ -6,51 +6,57 @@ use strict; use warnings; sub new { - my ($it_class, $sth, $args, $attrs) = @_; + my ($class, $storage, $args, $attrs) = @_; #use Data::Dumper; warn Dumper(@_); - $it_class = ref $it_class if ref $it_class; + $class = ref $class if ref $class; my $new = { - sth => $sth, + storage => $storage, args => $args, pos => 0, attrs => $attrs }; - return bless ($new, $it_class); + return bless ($new, $class); } sub next { my ($self) = @_; - return if $self->{attrs}{rows} - && $self->{pos} >= $self->{attrs}{rows}; # + $self->{attrs}{offset}); - my $sth = $self->{sth}; - unless ($self->{live_sth}) { - $sth->execute(@{$self->{args} || []}); + if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) { + delete $self->{sth}; + $self->{done} = 1; + } + return if $self->{done}; + unless ($self->{sth}) { + $self->{sth} = ($self->{storage}->_select(@{$self->{args}}))[1]; if ($self->{attrs}{software_limit}) { if (my $offset = $self->{attrs}{offset}) { - $sth->fetch for 1 .. $offset; + $self->{sth}->fetch for 1 .. $offset; } } - $self->{live_sth} = 1; } - my @row = $sth->fetchrow_array; - $self->{pos}++ if @row; + my @row = $self->{sth}->fetchrow_array; + if (@row) { + $self->{pos}++; + } else { + delete $self->{sth}; + $self->{done} = 1; + } return @row; } sub all { my ($self) = @_; return $self->SUPER::all if $self->{attrs}{rows}; - my $sth = $self->{sth}; - $sth->finish if $sth->{Active}; - $sth->execute(@{$self->{args} || []}); - delete $self->{live_sth}; + $self->{sth}->finish if $self->{sth}->{Active}; + delete $self->{sth}; + my ($rv, $sth) = $self->{storage}->_select(@{$self->{args}}); return @{$sth->fetchall_arrayref}; } sub reset { my ($self) = @_; $self->{sth}->finish if $self->{sth}->{Active}; + delete $self->{sth}; $self->{pos} = 0; - $self->{live_sth} = 0; + delete $self->{done}; return $self; }