Skip to content

Commit

Permalink
Fix on issue to add parenthesis with function with no parameters and …
Browse files Browse the repository at this point in the history
…wrong use of PERFORM in cursor declaration. Thanks to hdeadman for the report.
  • Loading branch information
dalibot committed Jan 9, 2015
1 parent fb497fa commit 93afe5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
21 changes: 12 additions & 9 deletions lib/Ora2Pg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3464,10 +3464,10 @@ LANGUAGE plpgsql ;
foreach my $f (sort keys %infos) {
next if (!$f);
$self->{idxcomment} = 0;
my %comments = $self->_remove_comments(\$infos{$f});
$total_size_no_comment += (length($infos{$f}) - (17 * $self->{idxcomment}));
my ($cost, %cost_detail) = Ora2Pg::PLSQL::estimate_cost($infos{$f});
$self->_restore_comments(\$infos{$f}, \%comments);
my %comments = $self->_remove_comments(\$infos{$f}{name});
$total_size_no_comment += (length($infos{$f}{name}) - (17 * $self->{idxcomment}));
my ($cost, %cost_detail) = Ora2Pg::PLSQL::estimate_cost($infos{$f}{name});
$self->_restore_comments(\$infos{$f}{name}, \%comments);
$cost += $Ora2Pg::PLSQL::OBJECT_SCORE{'FUNCTION'};
$self->logit("Function $f estimated cost: $cost\n", 1);
$cost_value += $cost;
Expand Down Expand Up @@ -7558,7 +7558,7 @@ sub _convert_function
my $tmp = $4;
if ( $tmp =~ /^\s+IS\s+/m ) {
$func_declare = $tmp . ' ' . $func_args . ' ' . $func_declare;
$func_args = '';
$func_args = '()';
} else {
$func_before .= "\n$tmp" if ($func_args);
}
Expand Down Expand Up @@ -8733,7 +8733,7 @@ sub _show_infos
foreach my $f (sort keys %infos) {
next if (!$f);
if ($self->{estimate_cost}) {
my ($cost, %cost_detail) = Ora2Pg::PLSQL::estimate_cost($infos{$f});
my ($cost, %cost_detail) = Ora2Pg::PLSQL::estimate_cost($infos{$f}{name});
$report_info{'Objects'}{$typ}{'cost_value'} += $cost;
$report_info{'Objects'}{$typ}{'detail'} .= "\L$f: $cost\E\n";
$report_info{full_function_details}{"\L$f\E"}{count} = $cost;
Expand Down Expand Up @@ -9606,8 +9606,9 @@ sub _lookup_package
my @functions = $self->_extract_functions($content);
foreach my $f (@functions) {
next if (!$f);
my $func_name = $self->_lookup_function($f, $pname);
$infos{"$pname.$func_name"} = $f if ($func_name);
my ($func_name, $func_type) = $self->_lookup_function($f, $pname);
$infos{"$pname.$func_name"}{name} = $f if ($func_name);
$infos{"$pname.$func_name"}{type} = $func_type if ($func_type);
}
}

Expand All @@ -9630,15 +9631,17 @@ sub _lookup_function
my %fct_infos = ();

my $func_name = '';
my $func_type = '';

# Split data into declarative and code part
my ($func_declare, $func_code) = split(/\bBEGIN\b/i,$plsql,2);
if ( $func_declare =~ s/(.*?)\b(FUNCTION|PROCEDURE)[\s\t]+([^\s\t\(]+)[\s\t]*(\([^\)]*\)|[\s\t]*)//is ) {
$fct_type = uc($2);
$func_name = $3;
$func_name =~ s/"//g;
}

return $func_name;
return ($func_name, $func_type);
}

####
Expand Down
5 changes: 2 additions & 3 deletions lib/Ora2Pg/PLSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,9 @@ sub plsql_to_plpgsql

# SELECT without INTO should be PERFORM. Exclude select of view when prefixed with AS ot IS
if ( ($export_type ne 'QUERY') && ($export_type ne 'VIEW') ) {
$str =~ s/([\s\t\n\r]+)(?<!AS|IS)([\s\t\n\r]+)SELECT((?![^;]+\bINTO\b)[^;]+;)/$1$2PERFORM$3/isg;
$str =~ s/\b(AS|IS|FOR|)([\s\t\n\r]+)PERFORM/$1$2SELECT/isg;
$str =~ s/(\([\s\t\n\r]*)PERFORM/$1SELECT/isg;
$str =~ s/(\s+)(?<!AS|IS)(\s+)SELECT((?![^;]+\bINTO\b)[^;]+;)/$1$2PERFORM$3/isg;
$str =~ s/SELECT((?![^;]+\bINTO\b)[^;]+;)/PERFORM$1/isg;
$str =~ s/\b(AS|IS|FOR|\()(\s+)PERFORM/$1$2SELECT/isg;
}

# Change nextval on sequence
Expand Down

0 comments on commit 93afe5d

Please sign in to comment.