--- index.cgi 2009/04/14 17:47:44 9 +++ index.cgi 2009/04/14 19:54:56 10 @@ -14,14 +14,35 @@ require 'config.pl' if -e 'config.pl'; +my $table = param('table') || 'log'; my @columns = param('columns'); @columns = ('*') unless @columns; -my $table = param('table') || 'log'; my $limit = param('limit') || 1000; 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||; + while ( my @row = $sth->fetchrow_array ) { + my ( $n, $c ) = @row; + $n = 'NULL' unless defined $n; + print qq||; + } + print qq|
count$group_by
$c$n
|; + exit; +} + print header, q| @@ -32,85 +53,19 @@ - + + - - var column = $('table#results th:nth-child(' + ( col_nr + 1 ) + ')').text(); - var where_operator = '='; - var where_value = window.getSelection().getRangeAt(0).cloneContents().textContent; - if ( where_value.length == 0 ) - where_value = e.originalTarget.textContent; - else - where_value = '%' + where_value + '%'; - - console.debug('click on ', this, e, - e.originalTarget, - column, where_operator, where_value - ); - - if ( tag == 'TH' ) { - console.info('header', column); - $('form#sql input[name=order_by]').attr('value', where_value + ' desc'); - } else if ( tag = 'TD' ) { - console.info('column', column, where_operator, where_value); - $('form#sql input[name=where_value]').attr('value', where_value); - $('form#sql select[name=where_column]').attr('options').selectedIndex = col_nr; - $('form#sql input[name=add_group_by]').attr('value', column).css('display','block'); - } else { - console.error('unknown click on ', tag, e); - } - - $('form#sql').addClass('visible'); - }; - - $('table#results').bind('mouseup', click_on_cell); - - $('#status').bind('click', function() { - $('form#sql').toggleClass('visible'); - }); - - console.info('ready'); -}); - - |; -my $dbh = DBI->connect( $dsn, $user, '', { RaiseError => 1 } ) || die $DBI::errstr; - - -my $group_by = param('add_group_by'); - -if ( $group_by ) { - @columns = ( "count($group_by)", $group_by ); - my $g; - foreach my $c ( @where_parts, $group_by ) { - $c =~ s/\s.+$//; - $g->{$c}++ if length($c) > 0; - } - $group_by = join( ',', keys %$g ); - print "# $group_by g = ",dump( $g ); - param('where_value',''); - param('group_by', $group_by); - param('columns', [ @columns ], [ @columns ]); - param('order_by', $columns[0] . ' desc'); -} else { - $group_by = param('group_by'); -} - +my $group_by = param('group_by'); if ( param('where_operator') && length( param('where_value') ) > 0 ) { my $where_value = param('where_value'); @@ -198,10 +153,16 @@ , popup_menu( -name => 'where_column', -values => [ @columns ] ), , popup_menu( -name => 'where_operator', -values => [ 'not like', 'like', '!=', '=' ]) , textfield( -name => 'where_value' ) + , qq| + + + +
...loading...
+ + | , qq|| , textfield( -name => 'group_by' ) - , submit( -name => 'add_group_by' ) , qq|| , textfield( -name => 'order_by' )