Commit a9cc50bb authored by Leo Gordon's avatar Leo Gordon
Browse files

Protect generate_graph.pl in table-drawing mode from printing too many rows...

Protect generate_graph.pl in table-drawing mode from printing too many rows (by setting a limit in JSON config)
parent c0d882a2
......@@ -69,7 +69,7 @@
"DisplayStats" : "barchart", # show analysis statistics using "barchart", "text" or "" (don't show statistics)
"DisplayJobs" : 0, # if nonzero, represents the max number of jobs to show in each analysis node
"DisplayData" : 0,
"DisplayData" : 0, # if nonzero, represents the max number of data rows to show in each table node
"DisplayDetails" : 1,
"DisplayStretched" : 0,
......
......@@ -157,6 +157,8 @@ sub fetch_all {
# in case $constraint contains any kind of JOIN (regular, LEFT, RIGHT, etc) do not put WHERE in front:
if($constraint=~/\bJOIN\b/i) {
$sql = 'SELECT ' . join(', ', map { "$table_name.$_" } keys %{$self->column_set()}) . " FROM $table_name $constraint";
} elsif($constraint=~/^LIMIT|ORDER|GROUP/) {
$sql .= ' '.$constraint;
} else {
$sql .= ' WHERE '.$constraint;
}
......
......@@ -452,15 +452,20 @@ sub _add_table_node {
my ($self, $table_node, $table_name) = @_;
my $node_fontname = $self->config_get('Node', 'Table', 'Font');
my (@column_names, $columns, $table_data);
my (@column_names, $columns, $table_data, $data_limit, $hit_limit);
if( $self->config_get('DisplayData') ) {
if( $data_limit = $self->config_get('DisplayData') ) {
my $adaptor = $self->dba->get_NakedTableAdaptor();
$adaptor->table_name( $table_name );
@column_names = sort keys %{$adaptor->column_set};
$columns = scalar(@column_names);
$table_data = $adaptor->fetch_all( );
$table_data = $adaptor->fetch_all( 'LIMIT '.($data_limit+1) );
if(scalar(@$table_data)>$data_limit) {
pop @$table_data;
$hit_limit = 1;
}
}
my $table_label = '<<table border="0" cellborder="0" cellspacing="0" cellpadding="1"><tr><td colspan="'.($columns||1).'">'.$table_name.'</td></tr>';
......@@ -471,6 +476,9 @@ sub _add_table_node {
foreach my $row (@$table_data) {
$table_label .= '<tr>'.join('', map { qq{<td>$_</td>} } @{$row}{@column_names}).'</tr>';
}
if($hit_limit) {
$table_label .= qq{<tr><td colspan="$columns">[ more data ]</td></tr>};
}
}
$table_label .= '</table>>';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment