1 |
<%args> |
2 |
$sth => undef |
3 |
$q => undef |
4 |
$max_rows => 100 |
5 |
</%args> |
6 |
<%init> |
7 |
|
8 |
my $query = Jifty->web->new_action( |
9 |
class => 'DoSQL', |
10 |
moniker => 'query', |
11 |
); |
12 |
|
13 |
my $result = Jifty->web->response->result('query'); |
14 |
$sth = $result->content('sth') if $result and !defined $sth; |
15 |
|
16 |
#use Data::Dump qw/dump/; |
17 |
#warn "q = ", dump( $q ); |
18 |
|
19 |
</%init> |
20 |
|
21 |
% if ($sth) { |
22 |
|
23 |
<table class="sql-result-table" cellpadding="3" cellspacing="0" border="1"> |
24 |
|
25 |
<tr> |
26 |
% foreach my $col ( @{ $sth->{'NAME'} } ) { |
27 |
<th><% $col %></th> |
28 |
% } |
29 |
</tr> |
30 |
|
31 |
% my $rows = 0; |
32 |
% while ( my @row = $sth->fetchrow_array() ) { |
33 |
% last if (++$rows > $max_rows); |
34 |
<tr> |
35 |
% foreach my $v ( @row ) { |
36 |
<td><% defined($v) ? $v : 'NULL' %></td> |
37 |
% } |
38 |
</tr> |
39 |
% } |
40 |
|
41 |
</table> |
42 |
|
43 |
% if ($sth->rows > $max_rows) { |
44 |
<div class="note"> |
45 |
Query produced more than <% $max_rows %> rows, try adding <tt>LIMIT</tt> and |
46 |
<tt>OFFSET</tt> to see another part of results. |
47 |
</div> |
48 |
% } |
49 |
|
50 |
|
51 |
% } # if $sth |