--- index.cgi 2009/04/13 17:55:51 2 +++ index.cgi 2009/04/18 12:13:40 18 @@ -11,17 +11,40 @@ our $dsn = 'DBI:Pg:dbname=syslog'; our $user = 'dpavlin'; +our $table = 'log'; +our $limit = 1000; require 'config.pl' if -e 'config.pl'; +$table = param('table') || $table; my @columns = param('columns'); @columns = ('*') unless @columns; -my $table = param('table') || 'log'; -my $limit = param('limit') || 1000; +$limit = param('limit') || $limit; my $offset = param('offset') || 0; my @where_parts = param('where_parts'); +my $dbh = DBI->connect( $dsn, $user, '', { RaiseError => 1 } ) || die $DBI::errstr; + +if ( my $group_by = param('add_group_by') ) { + my $sth = $dbh->prepare(qq{ + select $group_by,count($group_by) + from $table + group by $group_by + order by count($group_by) desc + limit 10 + }); + $sth->execute; + print header, qq|
count | $group_by |
---|---|
$c | $n |
$sql_html
\n\r\n\r|;
+
my $t = time();
my $sth = $dbh->prepare( $sql );
@@ -118,13 +106,17 @@
$t = time() - $t;
-my $sql_html = $sql;
-$sql_html =~ s{\?}{dump( shift @data )}ge;
-
-print qq|$sql_html
|, $sth->rows, qq| rows in $t s
|;
+print $sth->rows, qq| rows in $t s
|;
+#my @types = map { scalar $dbh->type_info($_)->{TYPE_NAME} } @{ $sth->{TYPE} };
+my $types = dump( $sth->{TYPE} );
+print qq{
+
+};
-@columns = @{ $sth->{NAME} };
+@columns = @{ $sth->{NAME} } if $#columns == 0 && $columns[0] eq '*';
print qq|