From 99ca8bcf6cf52e29faa91501a356052046435bfd Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 15 Aug 2002 00:46:19 +0000 Subject: [PATCH] Added an SQL macro derived from cmarcant's SQL macro and the SQL Report. --- lib/WebGUI/Macro/SQL.pm | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/WebGUI/Macro/SQL.pm diff --git a/lib/WebGUI/Macro/SQL.pm b/lib/WebGUI/Macro/SQL.pm new file mode 100644 index 000000000..93f89c0bd --- /dev/null +++ b/lib/WebGUI/Macro/SQL.pm @@ -0,0 +1,46 @@ +package WebGUI::Macro::SQL; + +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2002 Plain Black Software. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use strict; +use WebGUI::Macro; +use WebGUI::Session; +use WebGUI::SQL; + +sub _replacement { + my ($output, @data, $rownum, $temp); + my ($statement, $format) = WebGUI::Macro::getParams(shift); + my $result = eval { + my $sth = WebGUI::SQL->new($statement,$session{dbh}); + while (@data = $sth->array) { + $temp = $format; + $temp =~ s/\^(\d+)\;/$data[$1]/g; + $rownum++; + $temp =~ s/\^rownum\;/$rownum/g; + $output .= $temp; + } + $sth->finish; + }; + if ($@) { + return '

SQL Macro Failed: '.$@.'

'; + } else { + return $output; + } +} + +sub process { + my $output = shift; + $output =~ s/\^SQL\((.*?)\)\;/_replacement($1)/ges; + return $output; +} + +1; +