/[A3C]/data/stats/sql2json.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /data/stats/sql2json.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 246 - (show annotations)
Mon Oct 13 12:30:59 2008 UTC (15 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 688 byte(s)
convertor from SQL query to JSON for Exhibit

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use DBI;
7 use Data::Dump qw/dump/;
8 use JSON::XS;
9
10 my $debug = 0;
11 my $dsn = 'DBI:Pg:dbname=a3c';
12
13 my $dbh = DBI->connect($dsn,"","", { 'RaiseError' => '1' }) || die $DBI::errstr;
14 $dbh->do( qq{ set client_encoding='utf-8' } );
15
16 my $json = JSON::XS->new;
17 $json->utf8( 1 );
18 $json->pretty( 1 );
19
20 my $sth = $dbh->prepare( 'select * from stats.instance_organization' );
21 $sth->execute();
22
23
24 my @items;
25
26 while (my $row = $sth->fetchrow_hashref ) {
27 warn "# row = ",dump( $row ) if $debug;
28
29 foreach my $col ( keys %$row ) {
30 delete $row->{$col} unless defined $row->{$col};
31 }
32
33 push @items, $row;
34 }
35
36 print $json->encode(
37 {
38 items => [ @items ],
39 }
40 );

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26