<div dir="ltr"><div>What a hassle. I am glad you managed to restore the data.<br></div>Thank you for sharing the solution. I saved this to my Google Keep just in case.<br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">Best regards, <br>Andrey Goreev</div></div>
<br><div class="gmail_quote">On Wed, Jan 11, 2017 at 11:42 AM, Jim Gomi <span dir="ltr"><<a href="mailto:gomi@mailup.net" target="_blank">gomi@mailup.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have sorted out what the problem was: my digikam4.db database became<br>
corrupted, probably because I restored from an rsync backup, and I<br>
ended up with two entries in digikam4.db for each image.<br>
<br>
For each image, one of the entries had the correct metadata (caption<br>
etc) but didn't know which album the image belonged in.<br>
The other entry associated the image with the correct album, but didn't<br>
have the right metadata.<br>
<br>
I fixed the problem by writing a python code that went through all the<br>
JPG files in my collection, and for each file it found the relevant<br>
entries in the digikam4.db database, extracted the caption, and wrote<br>
it to the file using exiv2.<br>
<br>
Then I deleted the database and restarted digikam.<br>
Digikam read the captions from the metadata of the JPG files and<br>
recreated a correct database.<br>
<br>
In future, I will always configure digikam to store metadata in the JPG<br>
files as well as in the database. <br>
<br>
<br>
<br>
The core elements of the python code are:<br>
<br>
import sqlite3<br>
digikam_home='/where/photos/<wbr>live'<br>
db = sqlite3.connect(os.path.join(<wbr>digikam_home,'digikam4.db'))<br>
cursor = db.cursor()<br>
filename='IMG_2002.JPG' # for example<br>
cursor.execute('''SELECT id FROM Images WHERE name=?''', (filename,))<br>
imageid_tuple_list=cursor.<wbr>fetchall()<br>
<br>
# Now with an imageid one can extract the caption:<br>
imageid=imageid_tuple_list[0][<wbr>0]<br>
cursor.execute('''SELECT comment FROM ImageComments WHERE imageid=?''',<br>
(imageid,))<br>
comment_tuple_list=cursor.<wbr>fetchall()<br>
<br>
<br>
<br>
<br>
<br>
-------- Forwarded Message --------<br>
From: Jim Gomi <<a href="mailto:gomi@mailup.net">gomi@mailup.net</a>><br>
Reply-to: digiKam - Home Manage your photographs as a professional with<br>
the<br>
power of open source <<a href="mailto:digikam-users@kde.org">digikam-users@kde.org</a>><br>
To: <a href="mailto:digikam-users@kde.org">digikam-users@kde.org</a><br>
Subject: captions gone but still exist in digikam4.db<br>
Date: Mon, 26 Dec 2016 00:18:35 +0000<br>
<br>
The captions have disappeared from a bunch of my photos.<br>
<br>
However, when I browse the digikam4.db file using an SQLite browser, I<br>
can still find, in the ImageComments field, the text that was<br>
originally in one of the disappeared captions.<br>
<br>
Does anyone have any suggestions about what might be going on, and how<br>
to get the captions back?<br>
<br>
<br>
<br>
</blockquote></div><br></div>