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 |
} |
} |
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, $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 |
|
param('order_by', $columns[0] . ' desc'); |
103 |
|
} else { |
104 |
|
$group_by = param('group_by'); |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
if ( param('where_operator') && length( param('where_value') ) > 0 ) { |
if ( param('where_operator') && length( param('where_value') ) > 0 ) { |
109 |
my $where_value = param('where_value'); |
my $where_value = param('where_value'); |
110 |
push @where_parts, param('where_column') . ' ' . param('where_operator') . " ?\t$where_value"; |
push @where_parts, param('where_column') . ' ' . param('where_operator') . " ?\t$where_value"; |
111 |
param('where_value',''); |
param('where_value',''); |
112 |
} |
} |
113 |
|
|
114 |
|
|
115 |
my $c = join(',', @columns); |
my $c = join(',', @columns); |
116 |
|
|
117 |
my $sql = "select $c from $table"; |
my $sql = "select $c from $table"; |
127 |
$sql .= ' where ' . join(' and ', @w); |
$sql .= ' where ' . join(' and ', @w); |
128 |
} |
} |
129 |
|
|
130 |
|
|
131 |
|
$sql .= ' group by ' . $group_by if $group_by; |
132 |
$sql .= ' order by ' . param('order_by') if param('order_by'); |
$sql .= ' order by ' . param('order_by') if param('order_by'); |
133 |
$sql .= ' limit ? offset ?'; |
$sql .= ' limit ? offset ?'; |
134 |
|
|
135 |
push @data, ( $limit, $offset ); |
push @data, ( $limit, $offset ); |
136 |
|
|
137 |
|
my $sql_html = $sql; |
138 |
|
{ |
139 |
|
my @d = @data; |
140 |
|
$sql_html =~ s{\?}{dump( shift @d )}ge; |
141 |
|
} |
142 |
|
print qq|<code id="status">$sql_html<br>\n\r\n\r|; |
143 |
|
|
144 |
my $t = time(); |
my $t = time(); |
145 |
|
|
146 |
my $sth = $dbh->prepare( $sql ); |
my $sth = $dbh->prepare( $sql ); |
149 |
|
|
150 |
$t = time() - $t; |
$t = time() - $t; |
151 |
|
|
152 |
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>|; |
|
153 |
|
|
154 |
|
|
155 |
@columns = @{ $sth->{NAME} }; |
@columns = @{ $sth->{NAME} } if $#columns == 0 && $columns[0] eq '*'; |
156 |
|
|
157 |
print qq|<table id="results">|; |
print qq|<table id="results">|; |
158 |
|
|
190 |
, popup_menu( -name => 'where_operator', -values => [ 'not like', 'like', '!=', '=' ]) |
, popup_menu( -name => 'where_operator', -values => [ 'not like', 'like', '!=', '=' ]) |
191 |
, textfield( -name => 'where_value' ) |
, textfield( -name => 'where_value' ) |
192 |
|
|
193 |
|
, qq|<label for=group_by>group by</label>| |
194 |
|
, textfield( -name => 'group_by' ) |
195 |
|
, submit( -name => 'add_group_by' ) |
196 |
|
|
197 |
, qq|<label for=order_by>order by</label>| |
, qq|<label for=order_by>order by</label>| |
198 |
, textfield( -name => 'order_by' ) |
, textfield( -name => 'order_by' ) |
199 |
|
|