/[sql-web-session]/index.cgi
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 /index.cgi

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

revision 2 by dpavlin, Mon Apr 13 17:55:51 2009 UTC revision 3 by dpavlin, Mon Apr 13 20:23:55 2009 UTC
# Line 55  $(document).ready( function() { Line 55  $(document).ready( function() {
55    
56                  if ( tag == 'TH' ) {                  if ( tag == 'TH' ) {
57                          console.info('header', column);                          console.info('header', column);
58                          $('form#sql input[name=order_by]').attr('value', where_value);                          $('form#sql input[name=order_by]').attr('value', where_value + ' desc');
59                  } else if ( tag = 'TD' ) {                  } else if ( tag = 'TD' ) {
60                          console.info('column', column, where_operator, where_value);                          console.info('column', column, where_operator, where_value);
61                          $('form#sql input[name=where_value]').attr('value', where_value);                          $('form#sql input[name=where_value]').attr('value', where_value);
62                          $('form#sql select[name=where_column]').attr('options').selectedIndex = col_nr;                          $('form#sql select[name=where_column]').attr('options').selectedIndex = col_nr;
63                            $('form#sql input[name=add_group_by]').attr('value', column).css('display','block');
64                  } else {                  } else {
65                          console.error('unknown click on ', tag, e);                          console.error('unknown click on ', tag, e);
66                  }                  }
# Line 84  $(document).ready( function() { Line 85  $(document).ready( function() {
85  my $dbh = DBI->connect( $dsn, $user, '', { RaiseError => 1 } ) || die $DBI::errstr;  my $dbh = DBI->connect( $dsn, $user, '', { RaiseError => 1 } ) || die $DBI::errstr;
86    
87    
88    my $group_by = param('add_group_by');
89    
90    if ( $group_by ) {
91            @columns = ( "count($group_by)", $group_by );
92            my $g;
93            foreach my $c ( @where_parts, param('order_by'), $group_by ) {
94                    $c =~ s/\s.+$//;
95                    $g->{$c}++ if length($c) > 0;
96            }
97            $group_by = join( ',', keys %$g );
98            print "# $group_by g = ",dump( $g );
99            param('where_value','');
100            param('group_by', $group_by);
101            param('columns', [ @columns ], [ @columns ]);
102    } else {
103            $group_by = param('group_by');
104    }
105            
106    
107  if ( param('where_operator') && length( param('where_value') ) > 0 ) {  if ( param('where_operator') && length( param('where_value') ) > 0 ) {
108          my $where_value = param('where_value');          my $where_value = param('where_value');
109          push @where_parts, param('where_column') . ' ' . param('where_operator') . " ?\t$where_value";          push @where_parts, param('where_column') . ' ' . param('where_operator') . " ?\t$where_value";
110          param('where_value','');          param('where_value','');
111  }  }
112    
113    
114  my $c = join(',', @columns);  my $c = join(',', @columns);
115    
116  my $sql = "select $c from $table";  my $sql = "select $c from $table";
# Line 105  if ( @where_parts ) { Line 126  if ( @where_parts ) {
126          $sql .= ' where ' . join(' and ', @w);          $sql .= ' where ' . join(' and ', @w);
127  }  }
128    
129    
130    $sql .= ' group by ' . $group_by if $group_by;
131  $sql .= ' order by ' . param('order_by') if param('order_by');  $sql .= ' order by ' . param('order_by') if param('order_by');
132  $sql .= ' limit ? offset ?';  $sql .= ' limit ? offset ?';
133    
134  push @data, ( $limit, $offset );  push @data, ( $limit, $offset );
135    
136    my $sql_html = $sql;
137    {
138            my @d = @data;
139            $sql_html =~ s{\?}{dump( shift @d )}ge;
140    }
141    print qq|<code id="status">$sql_html<br>\n\r\n\r|;
142    
143  my $t = time();  my $t = time();
144    
145  my $sth = $dbh->prepare( $sql );  my $sth = $dbh->prepare( $sql );
# Line 118  $sth->execute( @data ); Line 148  $sth->execute( @data );
148    
149  $t = time() - $t;  $t = time() - $t;
150    
151  my $sql_html = $sql;  print $sth->rows, qq| rows in $t s</code>|;
 $sql_html =~ s{\?}{dump( shift @data )}ge;  
   
 print qq|<code id="status">$sql_html<br>|, $sth->rows, qq| rows in $t s</code>|;  
152    
153    
154  @columns = @{ $sth->{NAME} };  @columns = @{ $sth->{NAME} } if $#columns == 0 && $columns[0] eq '*';
155    
156  print qq|<table id="results">|;  print qq|<table id="results">|;
157    
# Line 162  print Line 189  print
189          , popup_menu( -name => 'where_operator', -values => [ 'not like', 'like', '!=', '=' ])          , popup_menu( -name => 'where_operator', -values => [ 'not like', 'like', '!=', '=' ])
190          , textfield( -name => 'where_value' )          , textfield( -name => 'where_value' )
191    
192            , qq|<label for=group_by>group by</label>|
193            , textfield( -name => 'group_by' )
194            , submit( -name => 'add_group_by' )
195    
196          , qq|<label for=order_by>order by</label>|          , qq|<label for=order_by>order by</label>|
197          , textfield( -name => 'order_by' )          , textfield( -name => 'order_by' )
198    

Legend:
Removed from v.2  
changed lines
  Added in v.3

  ViewVC Help
Powered by ViewVC 1.1.26