/[SQLSession]/trunk/share/web/templates/sql
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/share/web/templates/sql

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/share/web/templates/sql.html revision 12 by dpavlin, Sun Dec 3 00:12:25 2006 UTC trunk/share/web/templates/sql revision 45 by dpavlin, Sun Jan 21 12:19:58 2007 UTC
# Line 1  Line 1 
1  <%args>  <%args>
 $page => 1  
2  $sth => undef  $sth => undef
3    
4    $sql_query => undef
5    $name => undef
6    $database => undef
7    
8    $max_rows => 100
9    
10  </%args>  </%args>
11  <%init>  <%init>
12    
13  my $action = Jifty->web->new_action(  my $execute_sql = Jifty->web->new_action(
14          class => 'DoSQL',          class => 'DoSQL',
15          moniker => 'execute_sql',          moniker => 'execute_sql',
16  );  );
# Line 12  my $action = Jifty->web->new_action( Line 18  my $action = Jifty->web->new_action(
18  my $result = Jifty->web->response->result('execute_sql');  my $result = Jifty->web->response->result('execute_sql');
19  $sth = $result->content('sth') if $result and !defined $sth;  $sth = $result->content('sth') if $result and !defined $sth;
20    
21    my $edit = Jifty->web->current_user->role('edit');
22    warn $edit ? 'edit mode for SQL' : 'student mode';
23    
24  </%init>  </%init>
25    
26  <&| /_elements/wrapper, title => "Try out SQL query" &>  <&| /_elements/wrapper, title => "Try out SQL query" &>
27  <% Jifty->web->form->start() %>  <% Jifty->web->form->start() %>
28  <% $action->form_field('sql_query') %>  <% $execute_sql->form_field('sql_query',
29  <% $action->form_field('database') %>          default_value => $sql_query,
30  <% Jifty->web->form->submit( label => 'Try it!' ) %>          cols => 80,
31  <% Jifty->web->form->end() %>          rows => 12,
32  </&>  ) %>
33    % if ( $edit ) {
34    <% $execute_sql->form_field('database', default_value => $database ) %>
35    % } else {
36    
37    <!-- hidden database -->
38    <% $execute_sql->hidden('database', $database ) %>
39    
40    % }
41    <div class="submit_button">
42    <% $execute_sql->button( label => 'Try it!' ) %>
43    
44    
45  % if ( defined($sth) ) {  % if ( defined($sth) ) {
46    
47    % if ( $edit ) {
48    
49    % warn "save SQL: ", $execute_sql->argument_value('sql_query');
50    
51    <% Jifty->web->link(
52            label => 'Save',
53            onclick => {
54                    region => 'save_query',
55                    replace_with => '/save',
56                    args => {
57                            sql_query => $execute_sql->argument_value('sql_query'),
58                            database => $execute_sql->argument_value('database'),
59                    },
60                    refresh_self => 1,
61                    toggle => 1,
62            },
63            as_button => 1,
64    ) %>
65    
66    </div><!-- submit_button edit -->
67    
68    <% Jifty->web->region(
69            name => 'save_query',
70    ) %>
71    
72    % } else {
73    
74    </div><!-- submit_button no edit -->
75    
76    % }
77    
78    <% Jifty->web->form->end() %>
79    
80  <table cellpadding="3" cellspacing="0" border="1">  <table cellpadding="3" cellspacing="0" border="1">
81    
82  <tr>  <tr>
# Line 32  $sth = $result->content('sth') if $resul Line 85  $sth = $result->content('sth') if $resul
85  % }  % }
86  </tr>  </tr>
87    
88    % my $rows = 0;
89  % while ( my @row = $sth->fetchrow_array() ) {  % while ( my @row = $sth->fetchrow_array() ) {
90    %       last if (++$rows > $max_rows);
91  <tr>  <tr>
92  %       foreach my $v ( @row ) {  %       foreach my $v ( @row ) {
93  <td><% defined($v) ? $v : 'NULL' %></td>  <td><% defined($v) ? $v : 'NULL' %></td>
# Line 42  $sth = $result->content('sth') if $resul Line 97  $sth = $result->content('sth') if $resul
97    
98  </table>  </table>
99    
100    % if ($sth->rows > $max_rows) {
101    <div class="note">
102    Query produced more than <% $max_rows %> rows, try adding <tt>LIMIT</tt> and
103    <tt>OFFSET</tt> to see another part of results.
104    </div>
105    % }
106    
107    % } else {
108    
109    </div><!-- submit_button no query -->
110    <% Jifty->web->form->end() %>
111    
112  % }  % }
113    
114    <% Jifty->web->return( label => "Go back" ) %>
115    
116    </&>
117    

Legend:
Removed from v.12  
changed lines
  Added in v.45

  ViewVC Help
Powered by ViewVC 1.1.26