--- index.cgi 2009/04/18 23:21:40 24
+++ index.cgi 2009/12/08 20:08:29 32
@@ -12,9 +12,11 @@
print qq{Content-type: text/html\r\n\r\n};
our $dsn = 'DBI:Pg:dbname=syslog';
+our $database = ''; # if not in $dsn
our $user = 'dpavlin';
our $table = 'log';
our $limit = 1000;
+our $passwd = '';
our $group_by_join = {
feed_id => [ 'feeds', 'id', 'title', 'link', 'timestamp' ],
@@ -30,7 +32,7 @@
my @where_parts = param('where_parts');
-my $dbh = DBI->connect( $dsn, $user, '', { RaiseError => 1 } ) || die $DBI::errstr;
+my $dbh = DBI->connect( $dsn . $database, $user, $passwd, { RaiseError => 1 } ) || die $DBI::errstr;
sub where_from_parts {
return unless @_;
@@ -50,6 +52,13 @@
return @data;
}
+sub sql_html {
+ my @d = @_;
+ my $sql_html = shift @d;
+ $sql_html =~ s{\?}{dump( shift @d )}ge;
+ return $sql_html;
+}
+
if ( my $group_by = param('lookup_col') ) {
my @cols = ( $group_by, "count($group_by)" );
@@ -76,7 +85,7 @@
}, shift @data, # extract where
'group by', join(',', @group_by), qq{
order by count($group_by) desc
- limit 10
+ limit $limit
}
);
@@ -86,21 +95,23 @@
my $sth = $dbh->prepare( $sql );
$sth->execute( @data );
$t = time() - $t;
- print qq|$t
|, join(qq| | |, @cols), qq| |
|;
+ print qq||, sql_html( $sql, @data ), qq||;
+ print qq||, join(qq| | |, @cols), qq| |
|;
while ( my @row = $sth->fetchrow_array ) {
my $n = shift @row;
$n = 'NULL' unless defined $n;
print qq|$n | |, join(qq| | |, @row), qq| |
|;
}
print qq|
|;
- print qq|$sql
|;
+ print $sth->rows, qq| rows in $t s|;
exit;
}
print q|
-
+
+
SQL Web Session
@@ -136,12 +147,7 @@
push @data, ( $limit, $offset );
-my $sql_html = $sql;
-{
- my @d = @data;
- $sql_html =~ s{\?}{dump( shift @d )}ge;
-}
-print qq|$sql_html
\n\r\n\r|;
+print qq||, sql_html( $sql, @data ), qq|
\n|;
my $t = time();