12 |
print qq{Content-type: text/html\r\n\r\n}; |
print qq{Content-type: text/html\r\n\r\n}; |
13 |
|
|
14 |
our $dsn = 'DBI:Pg:dbname=syslog'; |
our $dsn = 'DBI:Pg:dbname=syslog'; |
15 |
|
our $database = ''; # if not in $dsn |
16 |
our $user = 'dpavlin'; |
our $user = 'dpavlin'; |
17 |
our $table = 'log'; |
our $table = 'log'; |
18 |
our $limit = 1000; |
our $limit = 1000; |
19 |
|
our $passwd = ''; |
20 |
|
|
21 |
our $group_by_join = { |
our $group_by_join = { |
22 |
feed_id => [ 'feeds', 'id', 'title', 'link', 'timestamp' ], |
feed_id => [ 'feeds', 'id', 'title', 'link', 'timestamp' ], |
32 |
|
|
33 |
my @where_parts = param('where_parts'); |
my @where_parts = param('where_parts'); |
34 |
|
|
35 |
my $dbh = DBI->connect( $dsn, $user, '', { RaiseError => 1 } ) || die $DBI::errstr; |
my $dbh = DBI->connect( $dsn . $database, $user, $passwd, { RaiseError => 1 } ) || die $DBI::errstr; |
36 |
|
|
37 |
sub where_from_parts { |
sub where_from_parts { |
38 |
return unless @_; |
return unless @_; |
52 |
return @data; |
return @data; |
53 |
} |
} |
54 |
|
|
55 |
|
sub sql_html { |
56 |
|
my @d = @_; |
57 |
|
my $sql_html = shift @d; |
58 |
|
$sql_html =~ s{\?}{dump( shift @d )}ge; |
59 |
|
return $sql_html; |
60 |
|
} |
61 |
|
|
62 |
if ( my $group_by = param('lookup_col') ) { |
if ( my $group_by = param('lookup_col') ) { |
63 |
|
|
64 |
my @cols = ( $group_by, "count($group_by)" ); |
my @cols = ( $group_by, "count($group_by)" ); |
95 |
my $sth = $dbh->prepare( $sql ); |
my $sth = $dbh->prepare( $sql ); |
96 |
$sth->execute( @data ); |
$sth->execute( @data ); |
97 |
$t = time() - $t; |
$t = time() - $t; |
98 |
print qq|$t<table><tr><th>|, join(qq|</th><th>|, @cols), qq|</th></tr>|; |
print qq|<code>|, sql_html( $sql, @data ), qq|<code>|; |
99 |
|
print qq|<table><tr><th>|, join(qq|</th><th>|, @cols), qq|</th></tr>|; |
100 |
while ( my @row = $sth->fetchrow_array ) { |
while ( my @row = $sth->fetchrow_array ) { |
101 |
my $n = shift @row; |
my $n = shift @row; |
102 |
$n = 'NULL' unless defined $n; |
$n = 'NULL' unless defined $n; |
103 |
print qq|<tr><td><a href="#">$n</a></td><td>|, join(qq|</td><td>|, @row), qq|</td></tr>|; |
print qq|<tr><td><a href="#">$n</a></td><td>|, join(qq|</td><td>|, @row), qq|</td></tr>|; |
104 |
} |
} |
105 |
print qq|</table>|; |
print qq|</table>|; |
106 |
print qq|<code>$sql</code>|; |
print $sth->rows, qq| rows in $t s|; |
107 |
exit; |
exit; |
108 |
} |
} |
109 |
|
|
110 |
print q| |
print q| |
111 |
|
<!DOCTYPE html> |
112 |
<html> |
<html> |
113 |
<head> |
<head> |
114 |
|
<meta charset="utf-8"> |
115 |
<title>SQL Web Session</title> |
<title>SQL Web Session</title> |
116 |
<link rel="stylesheet" type="text/css" href="style.css"> |
<link rel="stylesheet" type="text/css" href="style.css"> |
117 |
<!-- http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js --> |
<!-- http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js --> |
147 |
|
|
148 |
push @data, ( $limit, $offset ); |
push @data, ( $limit, $offset ); |
149 |
|
|
150 |
my $sql_html = $sql; |
print qq|<code id="status">|, sql_html( $sql, @data ), qq|<br>\n|; |
|
{ |
|
|
my @d = @data; |
|
|
$sql_html =~ s{\?}{dump( shift @d )}ge; |
|
|
} |
|
|
print qq|<code id="status">$sql_html<br>\n\r\n\r|; |
|
151 |
|
|
152 |
my $t = time(); |
my $t = time(); |
153 |
|
|