+drop table if exists cited;
+
create table cited (
id serial,
- au text not null,
- cited text not null
+ cited_au text not null,
+ from_au text not null
+);
+
+drop table if exists authors;
+
+create table authors (
+ id serial,
+ au text not null
);
-create index cited_au on cited(au);
-create index cited_cited on cited(cited);
+-- create index cited_au on cited(au);
+-- create index cited_cited on cited(cited);
foreach my $cr ( rec_array 'CR' ) {
+ if ( ! $cr->{author} ) {
+ warn "# cr ",dump( $cr );
+ next;
+ }
foreach my $au ( rec_array 'AU' ) {
- row(
- cited => $cr->{author},
- au => $au,
+ row( 'cited',
+ cited_au => $cr->{author},
+ from_au => $au,
);
+ row( 'authors', au => $au );
}
}
$log->info($self->dsn);
- $self->{_rows} = [];
+ $self->{_rows} = {};
+ $self->{_sth} = {};
$self->{_dbh} = DBI->connect( $self->dsn, $self->user, $self->passwd, { RaiseError => 1 } );
$id = $self->input . '-' . $id if $self->input;
- my @rows = @{ $ds->{_rows} };
- foreach my $row ( @rows ) {
+ foreach my $table ( keys %{ $ds->{_rows} } ) {
- my @cols = sort keys %$row;
+ my @rows = @{ $ds->{_rows}->{$table} };
+ foreach my $row ( @rows ) {
- my $sql = join( ''
- , 'insert into '
- , ( $self->table || $self->input || 'webpac2' )
- . ' (' . join(',', @cols), ')'
- , ' values ('
- , join(',', map { '?' } 0 .. $#cols )
- , ')'
- );
- warn "# SQL: $sql\n";
- my $sth = $self->{_dbh}->prepare( $sql );
+ my @cols = sort keys %$row;
- warn "# row ",dump( $row );
- $sth->execute( map { $row->{$_} } @cols );
- }
+ my $sth_id = $table . ':' . join(',',@cols);
+
+ my $sth
+ = $self->{_sth}->{$sth_id}
+ ;
+
+ if ( ! $sth ) {
+
+ my $sql = join( ''
+ , 'insert into '
+ , $table
+ . ' (' . join(',', @cols), ')'
+ , ' values ('
+ , join(',', map { '?' } 0 .. $#cols )
+ , ')'
+ );
+
+ $log->debug( "SQL $sth_id: $sql" );
- push @{ $self->{_rows} }, $_ foreach @rows;
+ $sth
+ = $self->{_sth}->{$sth_id}
+ = $self->{_dbh}->prepare( $sql )
+ ;
+ };
+
+ $log->debug( "row $table ", sub { dump( $row ) } );
+ $sth->execute( map { $row->{$_} } @cols );
+
+ push @{ $self->{_rows}->{$table} }, $_ foreach @rows;
+
+ }
+ }
return 1;
}