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
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
$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 . "'.";
}
}
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;
}
}
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;