Skip to content

Commit

Permalink
Item12029: database parameter needs improved error handling Item12030…
Browse files Browse the repository at this point in the history
…: error handling can cause recursive calls to SQL macro

git-svn-id: http://svn.foswiki.org/trunk/SqlPlugin@15256 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KipLubliner authored and KipLubliner committed Aug 3, 2012
1 parent beaf2f7 commit 4bd858b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/Foswiki/Plugins/SqlPlugin/Core.pm
Expand Up @@ -32,6 +32,7 @@ use constant DEBUG => 0; # toggle me
###############################################################################
sub writeDebug {
print STDERR "- SqlPlugin::Core - $_[0]\n" if DEBUG;
# Foswiki::Func::writeDebug("SqlPlugin::Core", $_[0]);
}

##############################################################################
Expand Down Expand Up @@ -68,6 +69,7 @@ sub finish {
##############################################################################
sub inlineError {
my $msg = shift;
$msg =~ s/\%/%/g;

return "<noautolink><span class='foswikiAlert'>ERROR: $msg </span></noautolink>";
}
Expand Down Expand Up @@ -98,9 +100,9 @@ sub handleExecute {
sub handleSQL {
my ($session, $params, $theTopic, $theWeb) = @_;

#writeDebug("called handleSQL()");

my $theDatabase = $params->{database} || $defaultDatabase;
my $theDatabase = exists $params->{database}
? $params->{database}
: $defaultDatabase;
my $theId = $params->{id};
my $theQuery = $params->{_DEFAULT} || $params->{query};
my $theParams = $params->{params} || '';
Expand All @@ -112,6 +114,8 @@ sub handleSQL {
$theQuery = entityDecode($theQuery);
}

#writeDebug("called handleSQL(" . $theQuery . ")");

my @bindVals = split '\s*,\s*', $theParams;

my $connection = $connections{$theDatabase};
Expand Down Expand Up @@ -155,7 +159,7 @@ sub handleSQL {

} catch Error::Simple with {
my $msg = shift->{-text};
#$msg =~ s/ at .*?$//gs;
$msg =~ s/ at .*?$//gs;
$result = inlineError($msg);
};

Expand Down

0 comments on commit 4bd858b

Please sign in to comment.