|
Lines 1090-1137
sub create_non_existing_group_and_subgroup {
Link Here
|
| 1090 |
} |
1090 |
} |
| 1091 |
} |
1091 |
} |
| 1092 |
|
1092 |
|
| 1093 |
# pass $sth and sql_params, get back an executable query |
|
|
| 1094 |
sub get_prepped_report { |
| 1095 |
my ($sql, $param_names, $sql_params ) = @_; |
| 1096 |
|
| 1097 |
# First we split out the placeholders |
| 1098 |
# This part of the code supports using [[ table.field | alias ]] in the |
| 1099 |
# query and replaces it by table.field AS alias. Not sure why we would |
| 1100 |
# need it if we can type the latter (which is simpler)? |
| 1101 |
my @split = split /\[\[|\]\]/,$sql; |
| 1102 |
my $headers; |
| 1103 |
for(my $i=0;$i<$#split/2;$i++){ #The placeholders are always the odd elements of the array |
| 1104 |
my ($type,$name) = split /\|/,$split[$i*2+1]; # We split them on '|' |
| 1105 |
$headers->{$name} = $type; # Store as a lookup for the template |
| 1106 |
$headers->{$name} =~ s/^\w*\.//; # strip the table name just as in $sth->{NAME} array |
| 1107 |
$split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g; #Quote any special characters so we can replace the placeholders |
| 1108 |
$name = C4::Context->dbh->quote($name); |
| 1109 |
$sql =~ s/\[\[$split[$i*2+1]\]\]/$type AS $name/; # Remove placeholders from SQL |
| 1110 |
} |
| 1111 |
|
| 1112 |
my %lookup; |
| 1113 |
@lookup{@$param_names} = @$sql_params; |
| 1114 |
@split = split /<<|>>/,$sql; |
| 1115 |
my @tmpl_parameters; |
| 1116 |
for(my $i=0;$i<$#split/2;$i++) { |
| 1117 |
my $quoted = @$param_names ? $lookup{ $split[$i*2+1] } : @$sql_params[$i]; |
| 1118 |
# if there are special regexp chars, we must \ them |
| 1119 |
$split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g; |
| 1120 |
if ($split[$i*2+1] =~ /\|\s*date\s*$/) { |
| 1121 |
$quoted = output_pref({ dt => dt_from_string($quoted), dateformat => 'iso', dateonly => 1 }) if $quoted; |
| 1122 |
} |
| 1123 |
unless( $split[$i*2+1] =~ /\|\s*list\s*$/ && $quoted ){ |
| 1124 |
$quoted = C4::Context->dbh->quote($quoted); |
| 1125 |
} else { |
| 1126 |
my @list = split /\n/, $quoted; |
| 1127 |
my @quoted_list; |
| 1128 |
foreach my $item ( @list ){ |
| 1129 |
$item =~ s/\r//; |
| 1130 |
push @quoted_list, C4::Context->dbh->quote($item); |
| 1131 |
} |
| 1132 |
$quoted="(".join(",",@quoted_list).")"; |
| 1133 |
} |
| 1134 |
$sql =~ s/<<$split[$i*2+1]>>/$quoted/; |
| 1135 |
} |
| 1136 |
return $sql,$headers; |
| 1137 |
} |
| 1138 |
- |