From 402ac1c9aa0b5bb5120ee8f6d8e62298a7a14223 Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Mon, 28 Mar 2011 13:45:40 +0200 Subject: [PATCH] Privatize _sth --- Changes | 2 ++ lib/DBIx/Class/CDBICompat/ImaDBI.pm | 2 +- lib/DBIx/Class/Storage/DBI.pm | 12 ++++++++---- lib/DBIx/Class/Storage/DBI/Replicated.pm | 4 +++- t/storage/disable_sth_caching.t | 6 +++--- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Changes b/Changes index ae28dcb5b..922bd92a1 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,8 @@ Revision history for DBIx::Class - Both the ::ODBC and ::ADO dispatchers now warn if a rdbms-specific driver is not found for this connection before falling back to plain ::Storage::DBI + - ::Storage::DBI::sth was mistakenly marked/documented as public, + privatize and warn on deprecated use * Fixes - Fix ::Storage::DBI::* MRO problems on 5.8.x perls diff --git a/lib/DBIx/Class/CDBICompat/ImaDBI.pm b/lib/DBIx/Class/CDBICompat/ImaDBI.pm index 49fc1e01c..15a125d30 100644 --- a/lib/DBIx/Class/CDBICompat/ImaDBI.pm +++ b/lib/DBIx/Class/CDBICompat/ImaDBI.pm @@ -86,7 +86,7 @@ sub set_sql { sub { my $sql = $sql; my $class = shift; - return $class->storage->sth($class->transform_sql($sql, @_)); + return $class->storage->_sth($class->transform_sql($sql, @_)); }; if ($sql =~ /select/i) { my $search_name = "search_${name}"; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index fccbedcd9..189f4fb61 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -16,7 +16,6 @@ use Try::Tiny; use overload (); use namespace::clean; - # default cursor class, overridable in connect_info attributes __PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::Cursor'); @@ -799,7 +798,7 @@ sub dbh_do { # This is basically a blend of dbh_do above and DBIx::Class::Storage::txn_do. # It also informs dbh_do to bypass itself while under the direction of txn_do, -# via $self->{_in_dbh_do} (this saves some redundant eval and errorcheck, etc) +# via $self->{_in_dbh_do} (this saves some redundant eval and errorcheck, etc) sub txn_do { my $self = shift; my $coderef = shift; @@ -1639,7 +1638,7 @@ sub _dbh_execute { $self->_query_start( $sql, @$bind ); - my $sth = $self->sth($sql,$op); + my $sth = $self->_sth($sql,$op); my $placeholder_index = 1; @@ -1850,7 +1849,7 @@ sub insert_bulk { my $guard = $self->txn_scope_guard; $self->_query_start( $sql, @$bind ? [ dummy => '__BULK_INSERT__' ] : () ); - my $sth = $self->sth($sql); + my $sth = $self->_sth($sql); my $rv = do { if (@$bind) { #@bind = map { ref $_ ? ''.$_ : $_ } @bind; # stringify args @@ -2316,6 +2315,11 @@ sub _dbh_sth { } sub sth { + carp_unique 'sth was mistakenly marked/documented as public, stop calling it (will be removed before DBIC v0.09)'; + shift->_sth(@_); +} + +sub _sth { my ($self, $sql) = @_; $self->dbh_do('_dbh_sth', $sql); # retry over disconnects } diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 04a06282d..0523bb754 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -268,7 +268,6 @@ my $method_dispatch = { txn_commit txn_rollback txn_scope_guard - sth deploy with_deferred_fk_checks dbh_do @@ -322,6 +321,7 @@ my $method_dispatch = { _resolve_aliastypes_from_select_args _execute _do_query + _sth _dbh_sth _dbh_execute /], @@ -357,6 +357,8 @@ my $method_dispatch = { _is_lob_type _is_binary_lob_type _is_text_lob_type + + sth /,( # the capability framework # not sure if CMOP->initialize does evil things to DBIC::S::DBI, fix if a problem diff --git a/t/storage/disable_sth_caching.t b/t/storage/disable_sth_caching.t index 860651a4b..c32f8c724 100644 --- a/t/storage/disable_sth_caching.t +++ b/t/storage/disable_sth_caching.t @@ -10,10 +10,10 @@ plan tests => 2; # Set up the "usual" sqlite for DBICTest my $schema = DBICTest->init_schema; -my $sth_one = $schema->storage->sth('SELECT 42'); -my $sth_two = $schema->storage->sth('SELECT 42'); +my $sth_one = $schema->storage->_sth('SELECT 42'); +my $sth_two = $schema->storage->_sth('SELECT 42'); $schema->storage->disable_sth_caching(1); -my $sth_three = $schema->storage->sth('SELECT 42'); +my $sth_three = $schema->storage->_sth('SELECT 42'); ok($sth_one == $sth_two, "statement caching works"); ok($sth_two != $sth_three, "disabling statement caching works");