/[tokyocabinet-toys]/sql-tsv.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 /sql-tsv.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations)
Wed Jul 22 08:16:48 2009 UTC (9 years, 10 months ago) by dpavlin
File MIME type: text/plain
File size: 779 byte(s)
dump SQL database using perl's DBI to tsv for Tokyo Cabinet

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use DBI;
7 use Data::Dump qw/dump/;
8
9 my $dsn = 'DBI:Pg:dbname=blogs';
10 my $sql = 'select * from mt_entry';
11
12 $dsn = 'DBI:mysql:dbname=reblog';
13 $sql = qq{
14 select title,link as url, xml as body,unix_timestamp(timestamp) as mtime from items
15 };
16
17 warn "# dsn = $dsn";
18 my $dbh = DBI->connect( $dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr;
19 #$dbh->do( qq{ set client_encoding='utf-8' } );
20
21 warn "# sql $sql";
22 my $sth = $dbh->prepare( $sql );
23 $sth->execute();
24
25 my $i = 1;
26
27 while ( my $row = $sth->fetchrow_hashref ) {
28
29 # warn "# row = ",dump( $row );
30
31 my $rec = $i++;
32 foreach ( keys %$row ) {
33 my $d = $row->{$_};
34 next unless defined $d;
35
36 $d =~ s{</?\w+>}{ }gs;
37 $d =~ s/\s+/ /gs;
38
39 $rec .= "\t$_\t$d";
40
41 }
42
43 print "$rec\n";
44 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26