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 |
my $edit = Jifty->web->current_user->role('edit'); |
17 |
warn $edit ? 'edit mode for SQL' : 'student mode'; |
18 |
|
19 |
#use Data::Dump qw/dump/; |
20 |
#warn "q = ", dump( $q ); |
21 |
|
22 |
</%init> |
23 |
|
24 |
% if ($sth) { |
25 |
|
26 |
<table class="sql-result-table" cellpadding="3" cellspacing="0" border="1"> |
27 |
|
28 |
<tr> |
29 |
% foreach my $col ( @{ $sth->{'NAME'} } ) { |
30 |
<th><% $col %></th> |
31 |
% } |
32 |
</tr> |
33 |
|
34 |
% my $rows = 0; |
35 |
% while ( my @row = $sth->fetchrow_array() ) { |
36 |
% last if (++$rows > $max_rows); |
37 |
<tr> |
38 |
% foreach my $v ( @row ) { |
39 |
<td><% defined($v) ? $v : 'NULL' %></td> |
40 |
% } |
41 |
</tr> |
42 |
% } |
43 |
|
44 |
</table> |
45 |
|
46 |
% if ($sth->rows > $max_rows) { |
47 |
<div class="note"> |
48 |
Query produced more than <% $max_rows %> rows, try adding <tt>LIMIT</tt> and |
49 |
<tt>OFFSET</tt> to see another part of results. |
50 |
</div> |
51 |
% } |
52 |
|
53 |
|
54 |
% } # if $sth |