From: Brandon L. Black Date: Sun, 23 Jul 2006 16:18:32 +0000 (+0000) Subject: infect the storage subdrivers X-Git-Tag: v0.08010~43^2~40^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a9f32dbced12b2b6c4f8b8a7aa142d5922350830;p=dbsrgits%2FDBIx-Class.git infect the storage subdrivers --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 87f84e6..ed69f43 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1147,7 +1147,7 @@ sub build_datetime_parser { return $type; } -sub DESTROY { shift->disconnect } +sub DESTROY { shift->_dbh(undef) } 1; diff --git a/lib/DBIx/Class/Storage/DBI/DB2.pm b/lib/DBIx/Class/Storage/DBI/DB2.pm index 8e867e0..ebe1067 100644 --- a/lib/DBIx/Class/Storage/DBI/DB2.pm +++ b/lib/DBIx/Class/Storage/DBI/DB2.pm @@ -11,8 +11,7 @@ sub last_insert_id { my ($self) = @_; - my $dbh = $self->_dbh; - my $sth = $dbh->prepare_cached("VALUES(IDENTITY_VAL_LOCAL())", {}, 3); + my $sth = $self->dbh_do(sub { shift->prepare_cached("VALUES(IDENTITY_VAL_LOCAL())", {}, 3) }); $sth->execute(); my @res = $sth->fetchrow_array(); diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index e355ce9..6634c59 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -6,7 +6,9 @@ use warnings; use base qw/DBIx::Class::Storage::DBI/; sub last_insert_id { - my( $id ) = $_[0]->_dbh->selectrow_array('SELECT @@IDENTITY' ); + my $self = shift; + my ($id) = + $self->dbh_do( sub { shift->selectrow_array('SELECT @@IDENTITY' ) } ); return $id; } diff --git a/lib/DBIx/Class/Storage/DBI/NoBindVars.pm b/lib/DBIx/Class/Storage/DBI/NoBindVars.pm index 73c7b43..b8684fd 100644 --- a/lib/DBIx/Class/Storage/DBI/NoBindVars.pm +++ b/lib/DBIx/Class/Storage/DBI/NoBindVars.pm @@ -15,7 +15,7 @@ sub _execute { } while(my $bvar = shift @bind) { - $bvar = $self->dbh->quote($bvar); + $bvar = $self->_dbh->quote($bvar); $sql =~ s/\?/$bvar/; } diff --git a/lib/DBIx/Class/Storage/DBI/ODBC.pm b/lib/DBIx/Class/Storage/DBI/ODBC.pm index f33100c..42466ef 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC.pm @@ -7,7 +7,7 @@ use base qw/DBIx::Class::Storage::DBI/; sub _rebless { my ($self) = @_; - my $dbh = $self->_dbh; + my $dbh = $self->dbh; my $dbtype = eval { $dbh->get_info(17) }; unless ( $@ ) { # Translate the backend name into a perl identifier diff --git a/lib/DBIx/Class/Storage/DBI/ODBC/DB2_400_SQL.pm b/lib/DBIx/Class/Storage/DBI/ODBC/DB2_400_SQL.pm index c39a622..e84c087 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/DB2_400_SQL.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/DB2_400_SQL.pm @@ -8,28 +8,29 @@ sub last_insert_id { my ($self) = @_; - my $dbh = $self->_dbh; + $self->dbh_do(sub { + my $dbh = shift; - # get the schema/table separator: - # '.' when SQL naming is active - # '/' when system naming is active - my $sep = $dbh->get_info(41); - my $sth = $dbh->prepare_cached( - "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM${sep}SYSDUMMY1", {}, 3); - $sth->execute(); + # get the schema/table separator: + # '.' when SQL naming is active + # '/' when system naming is active + my $sep = $dbh->get_info(41); + my $sth = $dbh->prepare_cached( + "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM${sep}SYSDUMMY1", {}, 3); + $sth->execute(); - my @res = $sth->fetchrow_array(); + my @res = $sth->fetchrow_array(); - return @res ? $res[0] : undef; + return @res ? $res[0] : undef; + }); } sub _sql_maker_opts { my ($self) = @_; - return { - limit_dialect => 'FetchFirst', - name_sep => $self->_dbh->get_info(41) - }; + $self->dbh_do(sub { + { limit_dialect => 'FetchFirst', name_sep => shift->get_info(41) } + }); } 1; diff --git a/lib/DBIx/Class/Storage/DBI/Oracle.pm b/lib/DBIx/Class/Storage/DBI/Oracle.pm index cd5449b..9c979ee 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle.pm @@ -13,7 +13,7 @@ sub last_insert_id { my ($self,$source,$col) = @_; my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col)); my $sql = "SELECT " . $seq . ".currval FROM DUAL"; - my ($id) = $self->_dbh->selectrow_array($sql); + my ($id) = $self->dbh_do(sub { shift->selectrow_array($sql) }); return $id; } @@ -21,21 +21,24 @@ sub get_autoinc_seq { my ($self,$source,$col) = @_; # look up the correct sequence automatically - my $dbh = $self->_dbh; my $sql = q{ SELECT trigger_body FROM ALL_TRIGGERS t WHERE t.table_name = ? AND t.triggering_event = 'INSERT' AND t.status = 'ENABLED' }; - # trigger_body is a LONG - $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024); - my $sth = $dbh->prepare($sql); - $sth->execute( uc($source->name) ); - while (my ($insert_trigger) = $sth->fetchrow_array) { - return uc($1) if $insert_trigger =~ m!(\w+)\.nextval!i; # col name goes here??? - } - croak "Unable to find a sequence INSERT trigger on table '" . $source->name . "'."; + + $self->dbh_do(sub { + my $dbh = shift; + # trigger_body is a LONG + $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024); + my $sth = $dbh->prepare($sql); + $sth->execute( uc($source->name) ); + while (my ($insert_trigger) = $sth->fetchrow_array) { + return uc($1) if $insert_trigger =~ m!(\w+)\.nextval!i; # col name goes here??? + } + croak "Unable to find a sequence INSERT trigger on table '" . $source->name . "'."; + }); } 1; diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index e211c05..f17831c 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -16,25 +16,29 @@ warn "DBD::Pg 1.49 is strongly recommended" sub last_insert_id { my ($self,$source,$col) = @_; my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col)); - $self->_dbh->last_insert_id(undef,undef,undef,undef, {sequence => $seq}); + $self->dbh_do(sub { shift->last_insert_id(undef,undef,undef,undef, {sequence => $seq}) } ); } sub get_autoinc_seq { my ($self,$source,$col) = @_; my @pri = $source->primary_columns; - my $dbh = $self->_dbh; 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_hashref; - if (defined $info->{COLUMN_DEF} and $info->{COLUMN_DEF} =~ - /^nextval\(+'([^']+)'::(?:text|regclass)\)/) - { - my $seq = $1; - return $seq =~ /\./ ? $seq : $info->{TABLE_SCHEM} . "." . $seq; # may need to strip quotes -- see if this works + + $self->dbh_do(sub { + my $dbh = shift; + while (my $col = shift @pri) { + my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_hashref; + if (defined $info->{COLUMN_DEF} and $info->{COLUMN_DEF} =~ + /^nextval\(+'([^']+)'::(?:text|regclass)\)/) + { + my $seq = $1; + return $seq =~ /\./ ? $seq : $info->{TABLE_SCHEM} . "." . $seq; # may need to strip quotes -- see if this works + } } - } + return; + }); } sub sqlt_type { diff --git a/lib/DBIx/Class/Storage/DBI/SQLite.pm b/lib/DBIx/Class/Storage/DBI/SQLite.pm index 091b5e7..ccf82d5 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::MultiDistinctEmulation/; sub last_insert_id { - return $_[0]->dbh->func('last_insert_rowid'); + shift->dbh_do(sub { shift->func('last_insert_rowid') }); } 1; diff --git a/lib/DBIx/Class/Storage/DBI/mysql.pm b/lib/DBIx/Class/Storage/DBI/mysql.pm index 8c14b1b..2f1114b 100644 --- a/lib/DBIx/Class/Storage/DBI/mysql.pm +++ b/lib/DBIx/Class/Storage/DBI/mysql.pm @@ -8,7 +8,7 @@ use base qw/DBIx::Class::Storage::DBI/; # __PACKAGE__->load_components(qw/PK::Auto/); sub last_insert_id { - return $_[0]->_dbh->{mysql_insertid}; + return shift->dbh_do(sub { shift->{mysql_insertid} } ); } sub sqlt_type {