From: David Kamholz Date: Fri, 10 Feb 2006 12:11:06 +0000 (+0000) Subject: PK::Auto fixes in branch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=34470972fbb715106e4990bab61871498dae979f;p=dbsrgits%2FDBIx-Class-Historic.git PK::Auto fixes in branch --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 1f67826..51e5329 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -264,10 +264,8 @@ sub _populate_dbh { my @info = @{$self->connect_info || []}; $self->_dbh($self->_connect(@info)); my $driver = $self->_dbh->{Driver}->{Name}; - eval qq{ -require DBIx::Class::Storage::DBI::${driver}; - }; - if(!$@) { + eval "require DBIx::Class::Storage::DBI::${driver}"; + unless ($@) { bless $self, "DBIx::Class::Storage::DBI::${driver}"; } # if on-connect sql statements are given execute them diff --git a/lib/DBIx/Class/Storage/DBI/Oracle.pm b/lib/DBIx/Class/Storage/DBI/Oracle.pm index b979f79..73859c5 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle.pm @@ -11,18 +11,19 @@ use base qw/DBIx::Class::Storage::DBI/; sub last_insert_id { my ($self, $source) = shift; - $self->get_autoinc_seq($source) unless $self->{_autoinc_seq}; - my $sql = "SELECT " . $self->{_autoinc_seq} . ".currval FROM DUAL"; + $self->get_autoinc_seq($source) unless $source->{_autoinc_seq}; + my $sql = "SELECT " . $source->{_autoinc_seq} . ".currval FROM DUAL"; my ($id) = $self->_dbh->selectrow_array($sql); return $id; } sub get_autoinc_seq { - my ($self, $source) = shift; + my ($self, $source) = @_; # return the user-defined sequence if known - if ($source->sequence) { - return $self->{_autoinc_seq} = $source->sequence; + my $result_class = $source->result_class; + if ($result_class->can('sequence') and $result_class->sequence) { + return ($source->{_autoinc_seq} = $result_class->sequence); } # look up the correct sequence automatically @@ -39,10 +40,10 @@ sub get_autoinc_seq { $sth->execute( uc($source->name) ); while (my ($insert_trigger) = $sth->fetchrow_array) { if ($insert_trigger =~ m!(\w+)\.nextval!i ) { - $self->{_autoinc_seq} = uc($1); + $source->{_autoinc_seq} = uc($1); } } - unless ($self->{_autoinc_seq}) { + unless ($source->{_autoinc_seq}) { croak "Unable to find a sequence INSERT trigger on table '" . $self->_table_name . "'."; } } diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index 88d401b..f8de9d4 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -9,29 +9,31 @@ use base qw/DBIx::Class::Storage::DBI/; sub last_insert_id { my ($self, $source) = @_; - $self->get_autoinc_seq unless $self->{_autoinc_seq}; + $self->get_autoinc_seq($source) unless $source->{_autoinc_seq}; $self->_dbh->last_insert_id(undef,undef,undef,undef, - {sequence=>$self->{_autoinc_seq}}); + {sequence => $source->{_autoinc_seq}}); } sub get_autoinc_seq { - my $self = shift; + my ($self,$source) = @_; # return the user-defined sequence if known - if ($source->sequence) { - return $self->{_autoinc_seq} = $source->sequence; + my $result_class = $source->result_class; + if ($result_class->can('sequence') and $result_class->sequence) { + return ($source->{_autoinc_seq} = $result_class->sequence); } my @pri = $source->primary_columns; my $dbh = $self->_dbh; - my ($schema,$table) = $source->name =~ /^(.+)\.(.+)$/ ? ($1,$2) : (undef,$sou -rce->table); + my ($schema,$table) = $source->name =~ /^(.+)\.(.+)$/ ? ($1,$2) + : (undef,$source->name); while (my $col = shift @pri) { my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_arrayref; if (defined $info->[12] and $info->[12] =~ /^nextval\('"?([^"']+)"?'::(?:text|regclass)\)/) { - $self->{_autoinc_seq} = $1; + warn "setting autoinc_seq on $source to $1"; + $source->{_autoinc_seq} = $1; last; } } diff --git a/lib/DBIx/Class/Storage/DBI/SQLite.pm b/lib/DBIx/Class/Storage/DBI/SQLite.pm index d5b9c62..e6175b5 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLite.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLite.pm @@ -6,7 +6,7 @@ use warnings; use base qw/DBIx::Class::Storage::DBI/; sub last_insert_id { - return $self->dbh->func('last_insert_rowid'); + return $_[0]->dbh->func('last_insert_rowid'); } 1;