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; +