/[A3C]/lib/A3C/Action/StrixSQL.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/A3C/Action/StrixSQL.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 162 - (hide annotations)
Sun Jun 15 17:47:39 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 1624 byte(s)
added encoding to A3C::SQL so we can connect to databases which doesn't
have default UTF-8 encoding (like strix doesn't)
1 dpavlin 161 use strict;
2     use warnings;
3    
4     =head1 NAME
5    
6     A3C::Action::StrixSQL
7    
8     =cut
9    
10     package A3C::Action::StrixSQL;
11     use base qw/A3C::Action Jifty::Action/;
12    
13     use DBI;
14     use Data::Dump qw/dump/;
15    
16     use Jifty::Param::Schema;
17     use Jifty::Action schema {
18    
19     param strix =>
20     label is _('Strix site'),
21     available are defer {
22     my $coll = Jifty->app_class('Model','StrixSiteCollection')->new;
23     $coll->unlimit;
24     $coll->order_by( column => 'site' );
25     [{
26     display_from => '_site_name',
27     value_from => 'site',
28     collection => $coll,
29     }];
30     },
31     render as 'Select';
32    
33     param sql =>
34     label is _('SQL query'),
35     render as 'Textarea';
36    
37     };
38    
39     sub sticky_on_success { 1 }
40     sub sticky_on_failure { 1 }
41    
42     =head2 take_action
43    
44     =cut
45    
46     sub take_action {
47     my $self = shift;
48    
49     return unless ( $self->result->success );
50    
51     my $config = Jifty->config->app('strix') or die "need strix config";
52     my $database = $config->{database} or die "no strix.database in config";
53    
54     Jifty->log->debug("using config ", dump( $database ));
55    
56     my $dsn =
57     'DBI:Pg:dbname=' . $self->argument_value('strix') .
58     ';host=' . $database->{host} .
59     ';port=' . $database->{port};
60    
61     Jifty->log->info("psql ", $self->argument_value('strix'), " [$dsn] ", $self->argument_value('sql'));
62    
63     my $dbh = DBI->connect( $dsn, $database->{user}, $database->{passwd} ) or die $DBI::errstr;
64    
65     my $sql = A3C::SQL->new({
66     query => $self->argument_value('sql'),
67     dbh => $dbh,
68 dpavlin 162 encoding => 'iso-8859-2',
69 dpavlin 161 });
70    
71     if ( $sql->count ) {
72     $self->result->content( 'sql' => $sql );
73     $self->result->message( _('Got %1 rows', $sql->count) );
74     } else {
75     $self->result->error( _('No results') );
76     }
77    
78     }
79    
80     1;
81    

  ViewVC Help
Powered by ViewVC 1.1.26