Lines 97-105
environment variable to the pathname of a configuration file to use.
Link Here
|
97 |
# file (/etc/koha/koha-conf.xml). |
97 |
# file (/etc/koha/koha-conf.xml). |
98 |
# dbh |
98 |
# dbh |
99 |
# A handle to the appropriate database for this context. |
99 |
# A handle to the appropriate database for this context. |
100 |
# dbh_stack |
|
|
101 |
# Used by &set_dbh and &restore_dbh to hold other database |
102 |
# handles for this context. |
103 |
# Zconn |
100 |
# Zconn |
104 |
# A connection object for the Zebra server |
101 |
# A connection object for the Zebra server |
105 |
|
102 |
|
Lines 602-615
Returns a database handle connected to the Koha database for the
Link Here
|
602 |
current context. If no connection has yet been made, this method |
599 |
current context. If no connection has yet been made, this method |
603 |
creates one, and connects to the database. |
600 |
creates one, and connects to the database. |
604 |
|
601 |
|
605 |
This database handle is cached for future use: if you call |
|
|
606 |
C<C4::Context-E<gt>dbh> twice, you will get the same handle both |
607 |
times. If you need a second database handle, use C<&new_dbh> and |
608 |
possibly C<&set_dbh>. |
609 |
|
610 |
=cut |
602 |
=cut |
611 |
|
603 |
|
612 |
#' |
|
|
613 |
sub dbh |
604 |
sub dbh |
614 |
{ |
605 |
{ |
615 |
my $self = shift; |
606 |
my $self = shift; |
Lines 643-700
sub new_dbh
Link Here
|
643 |
return &dbh({ new => 1 }); |
634 |
return &dbh({ new => 1 }); |
644 |
} |
635 |
} |
645 |
|
636 |
|
646 |
=head2 set_dbh |
|
|
647 |
|
648 |
$my_dbh = C4::Connect->new_dbh; |
649 |
C4::Connect->set_dbh($my_dbh); |
650 |
... |
651 |
C4::Connect->restore_dbh; |
652 |
|
653 |
C<&set_dbh> saves the current database handle on a stack, then sets |
654 |
the current database handle to C<$my_dbh>. |
655 |
|
656 |
C<$my_dbh> is assumed to be a good database handle. |
657 |
|
658 |
=cut |
659 |
|
660 |
#' |
661 |
sub set_dbh |
662 |
{ |
663 |
my $self = shift; |
664 |
my $new_dbh = shift; |
665 |
|
666 |
# Save the current database handle on the handle stack. |
667 |
# We assume that $new_dbh is all good: if the caller wants to |
668 |
# screw himself by passing an invalid handle, that's fine by |
669 |
# us. |
670 |
push @{$context->{"dbh_stack"}}, $context->{"dbh"}; |
671 |
$context->{"dbh"} = $new_dbh; |
672 |
} |
673 |
|
674 |
=head2 restore_dbh |
675 |
|
676 |
C4::Context->restore_dbh; |
677 |
|
678 |
Restores the database handle saved by an earlier call to |
679 |
C<C4::Context-E<gt>set_dbh>. |
680 |
|
681 |
=cut |
682 |
|
683 |
#' |
684 |
sub restore_dbh |
685 |
{ |
686 |
my $self = shift; |
687 |
|
688 |
if ($#{$context->{"dbh_stack"}} < 0) |
689 |
{ |
690 |
# Stack underflow |
691 |
die "DBH stack underflow"; |
692 |
} |
693 |
|
694 |
# Pop the old database handle and set it. |
695 |
$context->{"dbh"} = pop @{$context->{"dbh_stack"}}; |
696 |
} |
697 |
|
698 |
=head2 userenv |
637 |
=head2 userenv |
699 |
|
638 |
|
700 |
C4::Context->userenv; |
639 |
C4::Context->userenv; |
701 |
- |
|
|