projects
/
mongodb-experiments.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
06edf78
)
added command-line options
master
author
Dobrica Pavlinusic
<dpavlin@rot13.org>
Fri, 29 Jan 2010 22:33:02 +0000
(23:33 +0100)
committer
Dobrica Pavlinusic
<dpavlin@rot13.org>
Fri, 29 Jan 2010 22:33:02 +0000
(23:33 +0100)
dbi2mongo.pl
patch
|
blob
|
history
diff --git
a/dbi2mongo.pl
b/dbi2mongo.pl
index
2c432ad
..
7644a4a
100755
(executable)
--- a/
dbi2mongo.pl
+++ b/
dbi2mongo.pl
@@
-1,27
+1,32
@@
#!/usr/bin/perl -w
sub BEGIN {
#!/usr/bin/perl -w
sub BEGIN {
-$ENV{DBI_AUTOPROXY}='dbi:Gofer:transport=stream;url=ssh:dpavlin@koha.ffzg.hr';
+
#
$ENV{DBI_AUTOPROXY}='dbi:Gofer:transport=stream;url=ssh:dpavlin@koha.ffzg.hr';
}
use strict;
use DBI;
use MongoDB;
use Data::Dump qw/dump/;
}
use strict;
use DBI;
use MongoDB;
use Data::Dump qw/dump/;
+use Getopt::Long;
-$|++;
+my $debug = 0;
+my $drop = 0;
+my $limit = 10000;
-my $debug = @ARGV ? 1 : 0;
+GetOptions(
+ 'debug!' => \$debug,
+ 'drop!' => \$drop,
+ 'limit=i' => \$limit,
+) || die $!;
our ( $dbi, $user, $password ) = ( "DBI:mysql:database=test" );
our ( $dbi, $user, $password ) = ( "DBI:mysql:database=test" );
-our ( $database, $collection ) = ( '
test', 'test
' );
+our ( $database, $collection ) = ( '
', '
' );
our ( $table, $pk ) = ( 'biblio' => 'biblionumber' );
our ( $table2, $fk ) = ( 'biblioitems' => 'biblionumber' );
our ( $table, $pk ) = ( 'biblio' => 'biblionumber' );
our ( $table2, $fk ) = ( 'biblioitems' => 'biblionumber' );
-my $limit = 10000;
-my $join_limit = 10000;
-
-require 'config.pl';
+my $config = shift @ARGV || die "usage: $0 config.pl\n";
+require $config;
warn "# $dbi $user -> $database $collection $table.$pk<->$table2.$fk\n";
warn "# $dbi $user -> $database $collection $table.$pk<->$table2.$fk\n";
@@
-33,7
+38,7
@@
my $dbh = DBI->connect($dbi,$user,$password, {
# mysql_enable_utf8 => 1,
});
# mysql_enable_utf8 => 1,
});
-$db->drop if $d
ebug
;
+$db->drop if $d
rop
;
# db.items.find().sort({_id:-1}).limit(1);
my $last = $coll->query()->sort({ '_id' => -1 })->limit(1)->next;
# db.items.find().sort({_id:-1}).limit(1);
my $last = $coll->query()->sort({ '_id' => -1 })->limit(1)->next;
@@
-85,7
+90,7
@@
sub join_table {
from $table2
where $fk > ?
order by $fk asc
from $table2
where $fk > ?
order by $fk asc
- limit $
join_
limit
+ limit $limit
offset $join_offset
});
print STDERR " $table2:$join_offset ";
offset $join_offset
});
print STDERR " $table2:$join_offset ";
@@
-97,8
+102,8
@@
sub join_table {
our $row_join;
sub fetch_row_join {
$row_join = $sth_join->fetchrow_hashref();
our $row_join;
sub fetch_row_join {
$row_join = $sth_join->fetchrow_hashref();
- if ( ! $row_join && $sth_join->rows == $
join_
limit ) {
- $join_offset += $
join_
limit;
+ if ( ! $row_join && $sth_join->rows == $limit ) {
+ $join_offset += $limit;
join_table;
$row_join = $sth_join->fetchrow_hashref();
}
join_table;
$row_join = $sth_join->fetchrow_hashref();
}