4 use lib '/openils/lib/perl5/';
7 use OpenSRF::EX qw/:try/;
8 use OpenSRF::Utils::SettingsClient;
9 use OpenILS::Utils::Fieldmapper;
13 use Time::HiRes qw/time/;
17 my ($config, $output, @auto, @order) =
18 ('/openils/conf/bootstrap.conf');
21 'config=s' => \$config,
22 'output=s' => \$output,
23 'autoprimary=s' => \@auto,
30 OpenSRF::System->bootstrap_client( config_file => $config );
31 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
35 while ( my $rec = <> ) {
40 $row = JSON->JSON2perl($rec);
43 warn "\n\n !!! Error : $e \n\n at or around line $count\n";
47 my $class = $row->class_name;
48 my $hint = $row->json_hint;
50 if (!$lineset{$hint}) {
52 my @cols = $row->real_fields;
53 if (grep { $_ eq $hint} @auto) {
54 @cols = grep { $_ ne $class->Identity } @cols;
58 { table => $class->Table,
63 push @{ $lineset{$hint} }, [map { $row->$_ } @{ $fieldcache{$hint}{fields} }];
65 if (!($count % 500)) {
66 print STDERR "\r$count\t". $count / (time - $starttime);
72 print STDERR "\nWriting file ...\n";
74 $output = '&STDOUT' unless ($output);
75 $output = FileHandle->new(">$output") if ($output);
77 binmode($output,'utf8');
79 $output->print("SET CLIENT_ENCODING TO 'UNICODE';\n\n");
82 my $fields = join(',', @{ $fieldcache{$h}{fields} });
83 $output->print( "COPY $fieldcache{$h}{table} ($fields) FROM STDIN;\n" );
85 for my $line (@{ $lineset{$h} }) {
98 if ($h eq 'bre' and $fieldcache{$h}{fields}[$x] eq 'quality') {
104 $output->print( join("\t", @data)."\n" );
107 $output->print('\.'."\n\n");