- fix: 7.4 Editing SQL Form seems to break site ...?

This commit is contained in:
JT Smith 2007-03-09 05:38:44 +00:00
parent 3c7bfb6595
commit 172985e2a0
6 changed files with 33 additions and 43 deletions

View file

@ -137,14 +137,12 @@ sub db {
$self->{_dbh} = $self->session->db;
return $self->{_dbh};
} elsif ($dsn =~ /\DBI\:\w+\:\w+/i) {
eval{
$self->{_dbh} = WebGUI::SQL->connect($self->session,$dsn,$username,$identifier);
};
if ($@) {
$self->session->errorHandler->warn("DatabaseLink [".$self->getId."] ".$@);
} else {
return $self->{_dbh};
my $dbh = WebGUI::SQL->connect($self->session,$dsn,$username,$identifier);
unless (defined $dbh) {
$self->session->errorHandler->arn("Cannot connect to DatabaseLink [".$self->getId."]");
}
$self->{_dbh} = $dbh;
return $self->{_dbh};
} else {
$self->session->errorHandler->warn("DatabaseLink [".$self->getId."] The DSN specified is of an improper format.");
}

View file

@ -317,12 +317,10 @@ sub connect {
my $user = shift;
my $pass = shift;
my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError=>0,AutoCommit=>1 });
unless (defined $dbh) {
$session->setDbNotAvailable;
$session->errorHandler->fatal("Couldn't connect to database.");
$session->errorHandler->error("Couldn't connect to database: $dsn");
return undef;
}
if ( $dsn =~ /Oracle/ || $dsn =~ /ODBC/ ) { # Set specific attributes for long Oracle and ODBC DSNs
$dbh->{LongReadLen} = 512 * 1024;
$dbh->{LongTruncOk} = 1;

View file

@ -117,7 +117,7 @@ Cleans up a WebGUI session information from memory and disconnects from any reso
sub close {
my $self = shift;
$self->db->disconnect unless $self->dbNotAvailable;
$self->db->disconnect if (exists $self->{_db});
# Kill circular references. The literal list is so that the order
# can be explicitly shuffled as necessary.
@ -158,16 +158,32 @@ sub datetime {
#-------------------------------------------------------------------
=head2 db ( )
=head2 db ( [ skipFatal ] )
Returns a WebGUI::SQL object, which is connected to the WebGUI database.
=head3 skipFatal
If set to true, we won't throw a fatal error, just return undef.
=cut
sub db {
my $self = shift;
my $skipFatal = shift;
unless (exists $self->{_db}) {
$self->{_db} = WebGUI::SQL->connect($self,$self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"));
my $db = WebGUI::SQL->connect($self,$self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"));
if (defined $db) {
$self->{_db} = $db;
}
else {
if ($skipFatal) {
return undef
}
else {
$self->errorHandler->fatal("Couldn't connect to WebGUI database, and can't continue without it.");
}
}
}
return $self->{_db};
}
@ -618,28 +634,4 @@ sub var {
return $self->{_var};
}
#-------------------------------------------------------------------
=head2 setDbNotAvailable ( )
Sets a flag for this session indicating that database accesses are known to be probably broken and should not be performed.
=cut
sub setDbNotAvailable {
my $self = shift;
$self->{_dbNotAvailable} = 1;
}
=head2 dbNotAvailable ( )
Returns true iff there is an error condition such that no database accesses should be attempted for this session whatsoever.
=cut
sub dbNotAvailable {
my $self = shift;
return $self->{_dbNotAvailable};
}
1;

View file

@ -609,7 +609,7 @@ Returns the timezone for this user, in DateTime::TimeZone format. Checks to mak
sub getTimeZone {
my $self = shift;
return 'America/Chicago' if $self->session->dbNotAvailable;
return 'America/Chicago' unless defined $self->session->db(1);
return $self->session->user->{_timeZone} if $self->session->user->{_timeZone};
my @zones = @{DateTime::TimeZone::all_names()};
my $zone = $self->session->user->profileField('timeZone');

View file

@ -208,15 +208,17 @@ sub fatal {
$self->getLogger->debug("Stack trace for FATAL ".$message."\n".$self->getStackTrace());
$self->session->http->sendHeader if ($self->session->request);
if ($self->session->dbNotAvailable) {
if (! defined $self->session->db(1)) {
# We can't even _determine_ whether we can show the debug text. Punt.
$self->session->output->print("<h1>Fatal Internal Error</h1>");
} elsif ($self->canShowDebug()) {
}
elsif ($self->canShowDebug()) {
$self->session->output->print("<h1>WebGUI Fatal Error</h1><p>Something unexpected happened that caused this system to fault.</p>\n",1);
$self->session->output->print("<p>".$message."</p>\n",1);
$self->session->output->print($self->getStackTrace(), 1);
$self->session->output->print($self->showDebug(),1);
} else {
}
else {
# NOTE: You can't internationalize this because with some types of errors that would cause an infinite loop.
$self->session->output->print("<h1>Problem With Request</h1>
We have encountered a problem with your request. Please use your back button and try again.

View file

@ -247,7 +247,7 @@ Generates and sends HTTP headers for a response.
sub sendHeader {
my $self = shift;
return undef if ($self->{_http}{noHeader});
return $self->_sendMinimalHeader if $self->session->dbNotAvailable;
return $self->_sendMinimalHeader unless defined $self->session->db(1);
my ($request, $datetime, $config, $var) = $self->session->quick(qw(request datetime config var));
return undef unless $request;