1 |
#!/usr/local/bin/perl -w |
#!/usr/local/bin/perl -w |
2 |
|
|
3 |
|
# export e-mail adresa za Filipa, |
4 |
|
# Usage: |
5 |
|
# |
6 |
|
# to_csv.pl [yyyy-mm-dd] |
7 |
|
# |
8 |
|
# yyyy-mm-dd ... datum od kojeg se vrši export (datum zadnjeg exporta) |
9 |
|
|
10 |
use DBI; |
use DBI; |
11 |
|
|
12 |
|
my $sql_where; |
13 |
|
|
14 |
|
if (defined($ARGV[0])) { |
15 |
|
$sql_where = " and datum_unesen > '$ARGV[0]'"; |
16 |
|
} |
17 |
|
|
18 |
my $mydbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die $DBI::errstr; |
my $mydbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die $DBI::errstr; |
19 |
$mysth = $mydbh->prepare(" |
$mysth = $mydbh->prepare(" |
20 |
select ime,prezime,alias||'\@pliva.hr' from osobe,e_mail where e_mail.osoba_id=osobe.id |
select ime,prezime,alias||'\@pliva.hr' as email from osobe,e_mail where e_mail.osoba_id=osobe.id $sql_where |
21 |
") || die $mydbh->errstr(); |
") || die $mydbh->errstr(); |
22 |
$mysth->execute() || die $mysth->errstr(); |
$mysth->execute() || die $mysth->errstr(); |
23 |
|
|
24 |
print "#",join("\t",@{ $mysth->{NAME} }),"\n"; |
print "#",join(",",@{ $mysth->{NAME} }),"\n"; |
25 |
while (@myarr = $mysth->fetchrow_array() ) { |
while (@myarr = $mysth->fetchrow_array() ) { |
26 |
print join(",",@myarr),"\n"; |
print join(",",@myarr),"\n"; |
27 |
} |
} |