]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/src/extras/import/drain-batgirl-intransit.pl
import fixups
[Evergreen.git] / Evergreen / src / extras / import / drain-batgirl-intransit.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_transit;
11 CREATE TABLE legacy_transit (destination_lib text, owning_lib text, starting_lib text, transit_date timestamptz, transit_reason text, cat_key int, call_key int, item_key int, hold_key int);
12 COPY legacy_transit (destination_lib, owning_lib, starting_lib, transit_date, transit_reason, cat_key, call_key, item_key, hold_key) FROM STDIN;
13 SQL
14
15 warn "going for the data...";
16
17 my $sth = $dbh->prepare("select CAT_KEY, CALL_KEY, ITEM_KEY, HOLD_KEY, DESTINATION_LIB, OWNING_LIB, STARTING_LIB, concat(substring(TRANSIT_DATE,1,8),'T',substring(TRANSIT_DATE,9,4)) AS TRANSIT_DATE, TRANSIT_REASON from INTRANSIT");
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/destination_lib owning_lib starting_lib transit_date transit_reason cat_key call_key item_key hold_key/;
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