From 033d4c04472b6d63ad0869c7f5686ffa432e9708 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 10 Mar 2014 22:48:03 +0000 Subject: [PATCH] Bug 10611: (follow-up) cache DBMS driver code in context object Rather than use a package-level variable, use an object-level one. Signed-off-by: Galen Charlton (cherry picked from commit 7d39b3c72ea2422b09e3411bef974d87aecdabf9) Signed-off-by: Fridolin Somers Conflicts: C4/Context.pm Signed-off-by: Kyle M Hall (cherry picked from commit 1de3d85574568b8eef769dc5d16af879b920b65f) --- C4/Context.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index d991bacd4f..fe7b6e69c2 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -401,6 +401,7 @@ sub new { $self->{tz} = undef; # local timezone object bless $self, $class; + $self->{db_driver} = db_scheme2dbi($self->config('db_scheme')); # cache database driver return $self; } @@ -782,7 +783,6 @@ sub _new_Zconn { # Internal helper function (not a method!). This creates a new # database connection from the data given in the current context, and # returns it. -our $db_driver = 'mysql'; sub _new_dbh { @@ -790,7 +790,7 @@ sub _new_dbh ## correct name for db_scheme my $db_driver; if ($context->config("db_scheme")){ - $db_driver=db_scheme2dbi($context->config("db_scheme")); + $db_driver=$context->{db_driver}; }else{ $db_driver="mysql"; } @@ -860,9 +860,9 @@ sub dbh my $sth; unless ( $params->{new} ) { - if ( defined $db_driver && $db_driver eq 'mysql' && $context->{"dbh"} ) { + if ( defined($context->{db_driver}) && $context->{db_driver} eq 'mysql' && $context->{"dbh"} ) { return $context->{"dbh"}; - } elsif ( defined $db_driver && defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { + } elsif ( defined($context->{"dbh"}) && $context->{"dbh"}->ping() ) { return $context->{"dbh"}; } } -- 2.39.5