5 use Data::Dump qw/dump/;
9 my $f = DBI->connect("dbi:SQLite:dbname=knjiznica.sqlite","","", { RaiseError => 1, AutoCommit => 0 }) || die $DBI::errstr;
10 $f->{sqlite_unicode} = 1;
11 my $k = DBI->connect("dbi:mysql:database=koha_fer","","", { RaiseError => 1, AutoCommit => 0, mysql_enable_utf8 => 1 }) || die $DBI::errstr;
15 my ($t, $k, $v, $s, $default ) = @_;
18 if ( exists $lookup->{$key} ) {
19 $hash = $lookup->{$key};
21 warn "# select $k,$v from $t";
22 my $sth = $f->prepare( "select $k,$v from $t" );
24 while (my $row = $sth->fetchrow_hashref() ) {
25 $hash->{ $row->{$k} } = $row->{$v};
27 $lookup->{$key} = $hash;
30 return unless length $s > 1;
31 if ( ! exists $lookup->{$key}->{$s} ) {
32 warn "ERROR: no $s in $key\n";
35 $lookup->{$key}->{$s};
41 my ( $table, $row ) = @_;
42 $insert->{$table} ||= $k->prepare(
43 "insert into $table ("
44 . join(',', keys %$row)
46 . join(',', map { '?' } keys %$row )
49 $insert->{$table}->execute( values %$row );
50 warn "# inserted ", dump $row;
56 my $sth = $f->prepare($sql);
61 while (my $row = $sth->fetchrow_hashref ) {
65 # poor man's (sqlite) outer join
66 $row->{'country'} = lookup('drzava', 'ozn_drzava', 'naz_drzava', $row->{'country'}, $row->{contry} );
67 $row->{'city'} = lookup('mjesto', 'post_ozn', 'naz_mjesto', $row->{'city'}, $row->{city} );
69 $row->{'B_country'} = lookup('drzava', 'ozn_drzava', 'naz_drzava', $row->{'B_country'}, $row->{B_country} );
70 $row->{'B_city'} = lookup('mjesto', 'post_ozn', 'naz_mjesto', $row->{'B_city'}, $row->{B_city} );
72 $row->{'email'} = lookup('clanost', 'ozn_vrclan||ozn_clan', 'email', $row->{'cardnumber'}, undef);
73 $row->{'emailpro'} = lookup('clanost', 'ozn_vrclan||ozn_clan', 'email_k', $row->{'cardnumber'}, undef);
75 foreach my $c ( grep { /date/ } keys %$row ) {
76 $row->{$c} =~ s/(\d\d)\.(\d\d)\.(\d\d\d\d)/$3-$2-$1/;
79 $row->{sex} =~ s/\x{17D}/F/;
81 $row->{city} ||= '?'; # not null
83 insert 'borrowers' => $row;
89 delete from borrowers where borrowernumber > 57
96 'S' || mbr_stud as cardnumber,
98 ime_stud as firstname,
99 djevprezime as othernames,
101 dat_rodj as dateofbirth,
104 ozn_drzava_preb as country,
105 post_ozn_preb as zipcode,
106 post_ozn_preb as city,
108 ozn_drzava_stan as B_country,
109 post_ozn_stan as B_zipcode,
110 post_ozn_stan as B_city,
111 adr_stan as B_address,
113 dat_prava_do as dateexpiry
122 'D' || sif_djel as cardnumber,
123 ime_djel as firstname,
124 prez_djel as surname,
125 ozn_titula as title, -- FIXME
126 -- sif_orgjed (REF orgjed) as B_address,
127 -- sif_strsp_djel as ??,
128 tel_djel as phonepro,
129 dat_prekid_ro as dateexpiry,
132 ozn_drzava as country,
144 'O' || mbr_clan as cardnumber,
145 ime_clan as firstname,
146 prez_clan as surname,
147 ozn_titula as title, -- ?
148 zvanje_clan as borrowernotes, -- ?
149 -- krat_poduz (REF poduz) as B_address,
150 tel_poduz as B_phone,
152 ozn_drzava as country,