remove session from WebGUI::SQL
This commit is contained in:
parent
4959bfc979
commit
1f201260ba
4 changed files with 10 additions and 42 deletions
|
|
@ -240,7 +240,7 @@ sub db {
|
|||
else {
|
||||
my ($scheme, $driver, $attr_string, $attr_hash, $driver_dsn) = DBI->parse_dsn($dsn);
|
||||
if ($driver) {
|
||||
my $dbh = WebGUI::SQL->connect($self->session,$dsn,$username,$identifier,$parameters);
|
||||
my $dbh = WebGUI::SQL->connect($dsn,$username,$identifier,$parameters);
|
||||
unless (defined $dbh) {
|
||||
$self->session->log->warn("Cannot connect to DatabaseLink [".$self->getId."]");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,9 @@ use Tie::IxHash ();
|
|||
use Text::CSV_XS ();
|
||||
use WebGUI::SQL::ResultSet ();
|
||||
use WebGUI::Exception;
|
||||
use Scalar::Util ();
|
||||
use WebGUI::GUID;
|
||||
use Try::Tiny;
|
||||
use namespace::clean;
|
||||
use Scalar::Util qw( weaken );
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -37,7 +36,7 @@ Package for interfacing with SQL databases. This package implements Perl DBI fun
|
|||
|
||||
use WebGUI::SQL;
|
||||
|
||||
$db = WebGUI::SQL->connect($session,$dsn, $user, $pass);
|
||||
$db = WebGUI::SQL->connect($dsn, $user, $pass);
|
||||
$db->disconnect;
|
||||
|
||||
$sth = $db->prepare($sql);
|
||||
|
|
@ -75,14 +74,10 @@ our @ISA = qw(DBI);
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 connect ( session, dsn, user, pass )
|
||||
=head2 connect ( dsn, user, pass )
|
||||
|
||||
Constructor. Connects to the database using DBI.
|
||||
|
||||
=head2 session
|
||||
|
||||
A reference to the active WebGUI::Session object.
|
||||
|
||||
=head2 dsn
|
||||
|
||||
The Database Service Name of the database you wish to connect to. It looks like 'DBI:mysql:dbname;host=localhost'.
|
||||
|
|
@ -99,13 +94,9 @@ The password to use to connect to the database defined by dsn.
|
|||
|
||||
sub connect {
|
||||
my $class = shift;
|
||||
my $session;
|
||||
my $dsn;
|
||||
my $user;
|
||||
my $pass;
|
||||
if (ref $_[0] && $_[0]->isa('WebGUI::Session')) {
|
||||
$session = shift;
|
||||
}
|
||||
if (ref $_[0] && $_[0]->isa('WebGUI::Config')) {
|
||||
my $config = shift;
|
||||
$dsn = $config->get('dsn');
|
||||
|
|
@ -148,10 +139,6 @@ sub connect {
|
|||
unless (defined $dbh) {
|
||||
die "Couldn't connect to database: $dsn : $DBI::errstr";
|
||||
}
|
||||
if ($session) {
|
||||
$dbh->session($session);
|
||||
}
|
||||
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
|
|
@ -658,8 +645,7 @@ sub quickCSV {
|
|||
|
||||
while (my @data = $sth->array) {
|
||||
if ( ! $csv->combine(@data) ) {
|
||||
$self->session->log->error( "Problem creating CSV row: " . $csv->error_diag );
|
||||
return undef;
|
||||
WebGUI::Error->throw( "Problem creating CSV row: " . $csv->error_diag );
|
||||
}
|
||||
$output .= $csv->string();
|
||||
}
|
||||
|
|
@ -846,24 +832,6 @@ sub read {
|
|||
return $sth;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
Returns a reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
$self->{private_webgui_session} = shift;
|
||||
Scalar::Util::weaken $self->{private_webgui_session};
|
||||
}
|
||||
return $self->{private_webgui_session};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 setRow ( table, key, data [ ,id ] )
|
||||
|
|
@ -894,7 +862,7 @@ sub setRow {
|
|||
my $key = $self->quote_identifier($keyColumn);
|
||||
|
||||
if ($data->{$keyColumn} eq 'new' || $id) {
|
||||
$id ||= $self->session->id->generate;
|
||||
$id ||= WebGUI::GUID->generate;
|
||||
$data->{$keyColumn} = $id;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -244,11 +244,11 @@ sub db {
|
|||
my $self = shift;
|
||||
my $skipFatal = shift;
|
||||
unless (exists $self->{_db}) {
|
||||
my $db = WebGUI::SQL->connect($self,$self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"));
|
||||
my $db = WebGUI::SQL->connect($self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"));
|
||||
if (!defined $db && defined $self->config->get("failoverdb")) {
|
||||
$self->log->warn("Main DB down, resorting to using failover.");
|
||||
my $failover = $self->config->get("failoverdb");
|
||||
$db = WebGUI::SQL->connect($self,$failover->{dsn}, $failover->{user}, $failover->{password});
|
||||
$db = WebGUI::SQL->connect($failover->{dsn}, $failover->{user}, $failover->{password});
|
||||
}
|
||||
if (defined $db) {
|
||||
$self->{_db} = $db;
|
||||
|
|
@ -286,7 +286,7 @@ sub dbSlave {
|
|||
}
|
||||
if (scalar @slaves > 0) {
|
||||
my $slave = $slaves[rand @slaves];
|
||||
$self->{_slave} = WebGUI::SQL->connect($self, $slave->{dsn},$slave->{user},$slave->{pass});
|
||||
$self->{_slave} = WebGUI::SQL->connect($slave->{dsn},$slave->{user},$slave->{pass});
|
||||
}
|
||||
}
|
||||
if (!exists $self->{_slave}) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue