7 our $koha_dsn = 'dbi:oursql:dbname=koha';
8 our $koha_user = 'kohaadmin';
11 our $geo_dsn = 'dbi:Pg:dbname=koha';
15 our $opts = { RaiseError => 1 }; #, AutoCommit => 0, pg_enable_utf8 => 1, oursql_enable_utf8 => 1 };
17 require '/srv/koha-config.pl';
19 my $k_dbh = DBI->connect($koha_dsn, $koha_user, $koha_passwd, $opts) || die $DBI::errstr;
20 my $g_dbh = DBI->connect($geo_dsn, $geo_user, $geo_passwd, $opts) || die $DBI::errstr;
23 my ( $table, $pk ) = @_;
25 warn "# clean $table";
26 $g_dbh->do( "delete from $table" );
30 my $sql = "select * from $table order by $pk";
32 warn "# import $table";
36 my $sth = $k_dbh->prepare( "$sql limit 1000 offset $offset" );
37 print STDERR "$table [$offset] ";
40 $offset = 0 if ! $sth->rows; # exit
42 my @cols = @{ $sth->{NAME_lc} };
43 my $sql_insert = "insert into $table (" . join(',',@cols) . ") values (" . join(',', map { '?' } @cols ) . ")";
44 my $sth_insert = $g_dbh->prepare( $sql_insert );
46 while( my $row = $sth->fetchrow_arrayref ) {
47 eval { $sth_insert->execute( @$row ) };
49 print STDERR "$offset " if $offset % 100 == 0;
57 fetch_table 'biblio' => 'biblionumber' ;
58 fetch_table 'biblioitems' => 'biblioitemnumber' ;