4 #$ENV{DBI_AUTOPROXY}='dbi:Gofer:transport=stream;url=ssh:dpavlin@koha.ffzg.hr';
10 use Data::Dump qw/dump/;
23 our ( $dbi, $user, $password ) = ( "DBI:mysql:database=test" );
24 our ( $database, $collection ) = ( '', '' );
25 our ( $table, $pk ) = ( 'biblio' => 'biblionumber' );
26 our ( $table2, $fk ) = ( 'biblioitems' => 'biblionumber' );
28 my $config = shift @ARGV || die "usage: $0 config.pl\n";
31 warn "# $dbi $user -> $database $collection $table.$pk<->$table2.$fk\n";
33 my $conn = MongoDB::Connection->new;
34 my $db = $conn->get_database( $database );
35 my $coll = $db->get_collection( $collection );
36 my $dbh = DBI->connect($dbi,$user,$password, {
38 # mysql_enable_utf8 => 1,
43 # db.items.find().sort({_id:-1}).limit(1);
44 my $last = $coll->query()->sort({ '_id' => -1 })->limit(1)->next;
46 my $last_id = $last->{_id} || 0;
48 print "import $table.$pk > $last_id from $dbi\n";
55 $sth = $dbh->prepare(qq{
66 print STDERR " $table:$offset ";
67 $sth->execute( $last_id );
68 # warn "# $table columns ",dump( $sth->{NAME} ) if $offset == 0;
69 print STDERR " join ", $sth->rows, " rows ";
74 $row = $sth->fetchrow_hashref();
75 if ( ! $row && $sth->rows == $limit ) {
78 $row = $sth->fetchrow_hashref();
87 $sth_join = $dbh->prepare(qq{
96 print STDERR " $table2:$join_offset ";
97 $sth_join->execute( $last_id );
98 # warn "# $table2 columns ",dump( $sth_join->{NAME} ) if $join_offset = 0;
99 print STDERR " join ",$sth_join->rows, " rows ";
104 $row_join = $sth_join->fetchrow_hashref();
105 if ( ! $row_join && $sth_join->rows == $limit ) {
106 $join_offset += $limit;
108 $row_join = $sth_join->fetchrow_hashref();
115 map { $row->{$_} * 1 } grep { defined $row->{$_} && $row->{$_} =~ /^\d+$/ } keys %$row;
123 while (my $row = fetch_row() ) {
125 while ( $row_join && $row_join->{$fk} < $row->{$pk} ) {
129 while ( $row_join && $row_join->{$fk} == $row->{$pk} ) {
130 push @{ $row->{ $table2 } }, guess_types($row_join);
135 $coll->insert( guess_types($row) );