15 $x = Encode::decode('iso8859-1', $x);
24 my ($mdbh, $sdbh, $table) = @_;
25 my $start = [ Time::HiRes::gettimeofday ];
26 my $data = $mdbh->selectall_arrayref("SELECT * FROM $table");
27 my $elapsed = Time::HiRes::tv_interval($start);
28 #printf "MySQL $table time used: $elapsed\n";
30 $start = [ Time::HiRes::gettimeofday ];
31 $sdbh->do("DELETE FROM $table");
32 $sdbh->do("COPY $table FROM STDIN");
34 for my $row (@$data) {
35 $sdbh->pg_putcopydata(join("\t", map { copy_escape($_) } (@$row)) . "\n");
37 $sdbh->pg_putcopyend();
38 $elapsed = Time::HiRes::tv_interval($start);
39 #printf "PostgreSQL $table time used: $elapsed\n";
42 my $mdbh = DBI->connect($config::master_connstr, $config::master_username, $config::master_password)
43 or die "PostgreSQL connect: " . $DBI::errstr;
44 $mdbh->{AutoCommit} = 0;
45 $mdbh->{RaiseError} = 1;
47 my $sdbh = DBI->connect($config::local_connstr, $config::local_username, $config::local_password)
48 or die "PostgreSQL connect: " . $DBI::errstr;
49 $sdbh->{AutoCommit} = 0;
50 $sdbh->{RaiseError} = 1;
52 # For our own enjoyment.
53 sync_table($mdbh, $sdbh, "Fotballbrukere");
54 sync_table($mdbh, $sdbh, "Fotballdeltagere");
55 sync_table($mdbh, $sdbh, "Fotballresultater");
56 sync_table($mdbh, $sdbh, "Fotballserier");
59 sync_table($mdbh, $sdbh, 'Fotballjuks');
60 sync_table($mdbh, $sdbh, 'FotballKaffeklubb');
61 sync_table($mdbh, $sdbh, 'Fotballkommentarer');
62 sync_table($mdbh, $sdbh, 'Fotballkommentartema');
63 sync_table($mdbh, $sdbh, 'FotballLogin');
64 sync_table($mdbh, $sdbh, 'Fotballspraak');
65 sync_table($mdbh, $sdbh, 'Fotballtoppti');
66 sync_table($mdbh, $sdbh, 'Fotballvariabler');
68 $sdbh->do('DELETE FROM last_sync');
69 $sdbh->do('INSERT INTO last_sync VALUES ( CURRENT_TIMESTAMP );');