- $dbh->do('UPDATE images SET width=?, height=?, date=? WHERE id=?',
- undef, $width, $height, $datetime, $id)
- or die "Couldn't update width/height in SQL: $!";
+ {
+ local $dbh->{AutoCommit} = 0;
+
+ # EXIF information
+ $dbh->do('DELETE FROM exif_info WHERE image=?',
+ undef, $id)
+ or die "Couldn't delete old EXIF information in SQL: $!";
+
+ my $q = $dbh->prepare('INSERT INTO exif_info (image,key,value) VALUES (?,?,?)')
+ or die "Couldn't prepare inserting EXIF information: $!";
+
+ for my $key (keys %$info) {
+ next if ref $info->{$key};
+ $q->execute($id, $key, guess_charset($info->{$key}))
+ or die "Couldn't insert EXIF information in database: $!";
+ }
+
+ # Model/Lens
+ my $model = $exiftool->GetValue('Model', 'PrintConv');
+ my $lens = $exiftool->GetValue('Lens', 'PrintConv');
+ $lens = $exiftool->GetValue('LensSpec', 'PrintConv') if (!defined($lens));
+
+ $model =~ s/^\s*//;
+ $model =~ s/\s*$//;
+ $model = undef if (length($model) == 0);
+
+ $lens =~ s/^\s*//;
+ $lens =~ s/\s*$//;
+ $lens = undef if (length($lens) == 0);
+
+ # Now update the main table with the information we've got
+ $dbh->do('UPDATE images SET width=?, height=?, date=?, model=?, lens=? WHERE id=?',
+ undef, $width, $height, $datetime, $model, $lens, $id)
+ or die "Couldn't update width/height in SQL: $!";
+
+ # Tags
+ my @tags = $exiftool->GetValue('Keywords', 'ValueConv');
+ $dbh->do('DELETE FROM tags WHERE image=?',
+ undef, $id)
+ or die "Couldn't delete old tag information in SQL: $!";
+
+ $q = $dbh->prepare('INSERT INTO tags (image,tag) VALUES (?,?)')
+ or die "Couldn't prepare inserting tag information: $!";
+
+
+ for my $tag (@tags) {
+ $q->execute($id, guess_charset($tag))
+ or die "Couldn't insert tag information in database: $!";
+ }