[set page_title][L]Direct SQL Query[/L][/set] [set ui_class]Admin[/set] [set page_banner][L]Direct SQL Query[/L][/set] [set page_perm]super[/set] [set help_name]table.direct_sql[/set] [set icon_name]icon_config.gif[/set] [seti ui_body_extra][/seti] @_UI_STD_HEAD_@ [tmp is_super][if-mm super]1[/if-mm][/tmp] [calc] delete $CGI->{list}; delete $CGI->{html}; $Scratch->{message} = ''; delete $Scratch->{update_message}; if ($CGI->{clear_query_buffer}) { delete $Session->{x_query_buffer}; return; } unless ($sql = $CGI->{sql}) { $CGI->{sql} = "select * from $CGI->{mv_data_table}" if $CGI->{mv_data_table}; return; } my $extra = ''; $sql =~ s/^\s+//; $sql =~ s/\s+$//; if($sql =~ /^select\s+.*?\s+from\s+(\w+)/i) { $CGI->{mv_data_table} = $1; delete $CGI->{rc}; delete $CGI->{list}; if($CGI->{output_action} eq 'download') { $CGI->{download} = 1; } $CGI->{html} = 1; # $Scratch->{message} = qq{ # Rows selected by query: #

> $sql

# }; } else { if($sql =~ /^update\s+(\w+)/i) { $Scratch->{update_message} = 'UPDATED'; } elsif($sql =~ /^delete\s+from\s+(\w+)/i) { $Scratch->{update_message} = 'DELETED'; } elsif($sql =~ /^insert\s+into\s+(\w+)/i) { $Scratch->{update_message} = 'INSERTED'; } else { $Scratch->{update_message} = 'UNKNOWN OPERATION'; } my $flagtab = $1; if($Scratch->{is_super}) { $Tag->flag( { type => 'write', table => $flagtab }); } else { $extra = "(May fail on write-controlled table, not admin superuser)"; } $CGI->{rc} = 1; delete $CGI->{html}; $CGI->{list} = 1; # $Scratch->{message} = qq{ # Rows updated by query: #

> $sql

# }; } $Scratch->{message} =~ s/\r?\n/
/g; $Scratch->{message} =~ s/\r/
/g; $Scratch->{message} =~ s/
/
\n/g; $Scratch->{message} .= $extra; my $qb = $Session->{x_query_buffer} ||= []; my $prev = $qb->[0] ? $qb->[0][0] : ''; unshift @$qb, [$sql] unless $sql eq $prev; return; [/calc] [if cgi mv_data_table] [page href=__UI_BASE__/flex_select form=auto mv_data_table="[cgi mv_data_table]" ]Return to [cgi mv_data_table] edit [/if] [form-session-id]

[L]Display[/L] [L]Download[/L]
[cgi sql] | [loop list=` my $tmp = $Session->{x_query_buffer}; return [$tmp] if $tmp; return; ` ml=10] [list] [loop-increment] [loop-code] [/list] [/loop]
Base table |

> [scratchd message]

[if cgi download] [deliver interpolate=1][query table="[cgi mv_data_table]" st=db list=1 sql=`$sql` ml="[cgi limit]" ][sql-sub line_proc] shift; my $row = shift; my $out = ''; if(! $t_header_done++) { my $o = shift; $out .= join "\t", @{$o->{mv_return_fields}}; $out .= "\n"; } for(@$row) { s/\r?\n/\r/g; s/\t/ /g; } $out .= join "\t", @$row; $out .= "\n"; [/sql-sub][sql-exec line_proc][/sql-exec][/query][/deliver] [elsif cgi html] [query table="[cgi mv_data_table]" st=db row-count="[cgi row-count]" html=1 sql=`$sql` ml="[cgi limit]" ] [/query] [/elsif] [elsif cgi list] [query table="[cgi mv_data_table]" row-count="[cgi row-count]" st=db list=1 ml="[cgi limit]" sql=`$sql` ]
[scratchd update_message] | [sql-code]
[/query] [/elsif] [/if]

@_UI_STD_FOOTER_@