]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/src/extras/import/drain-batgirl-charge.pl
sanity checking
[Evergreen.git] / Evergreen / src / extras / import / drain-batgirl-charge.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5
6 my $dbh = DBI->connect('DBI:mysql:database=reports;host=batgirl.gsu.edu','miker','poopie');
7
8 print <<SQL;
9
10 DROP TABLE legacy_charge;
11 CREATE TABLE legacy_charge (charge_date text, due_date text, renewal_date text, charge_key1 int, charge_key2 int, charge_key3 int, charge_key4 int, user_key int, overdue bool, library text, claim_return_date text);
12 COPY legacy_charge (charge_date, due_date, renewal_date, charge_key1, charge_key2, charge_key3, charge_key4, user_key, overdue, library, claim_return_date) FROM STDIN;
13 SQL
14
15 warn "going for the data...";
16
17 my $sth = $dbh->prepare('select * from CHARGE');
18 $sth->execute;
19
20 warn "got it, writing file...";
21
22 while (my $cn = $sth->fetchrow_hashref) {
23         my @data = map { $$cn{uc($_)} } qw/charge_date due_date renewal_date charge_key1 charge_key2 charge_key3 charge_key4 user_key overdue library claim_return_date/;
24         for (@data) {
25                 if (defined($_)) {
26                         s/\\/\\\\/go;
27                         s/\t/ /go;
28                 } else {
29                         $_ = '\N';
30                 }
31         }
32         print join("\t", @data) . "\n";
33 }
34
35 print "\\.\n";
36
37