From 1de3d85574568b8eef769dc5d16af879b920b65f 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 --- C4/Context.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index b65e645fa9..282c54fabd 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -400,6 +400,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; } @@ -788,7 +789,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 { @@ -796,7 +796,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"; } @@ -866,9 +866,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