captions gone but still exist in digikam4.db

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

captions gone but still exist in digikam4.db

Jim Gomi
The captions have disappeared from a bunch of my photos.

However, when I browse the digikam4.db file using an SQLite browser, I
can still find, in the ImageComments field, the text that was
originally in one of the disappeared captions.

Does anyone have any suggestions about what might be going on, and how
to get the captions back?



Reply | Threaded
Open this post in threaded view
|

[Fwd: captions gone but still exist in digikam4.db]

Jim Gomi
I have sorted out what the problem was: my digikam4.db database became
corrupted, probably because I restored from an rsync backup, and I
ended up with two entries in digikam4.db for each image.

For each image, one of the entries had the correct metadata (caption
etc) but didn't know which album the image belonged in.
The other entry associated the image with the correct album, but didn't
have the right metadata.

I fixed the problem by writing a python code that went through all the
JPG files in my collection, and for each file it found the relevant
entries in the digikam4.db database, extracted the caption, and wrote
it to the file using exiv2.

Then I deleted the database and restarted digikam.
Digikam read the captions from the metadata of the JPG files and
recreated a correct database.

In future, I will always configure digikam to store metadata in the JPG
files as well as in the database. 



The core elements of the python code are:

import sqlite3
digikam_home='/where/photos/live'
db = sqlite3.connect(os.path.join(digikam_home,'digikam4.db'))
cursor = db.cursor()
filename='IMG_2002.JPG'   # for example
cursor.execute('''SELECT id FROM Images WHERE name=?''', (filename,))
imageid_tuple_list=cursor.fetchall()

# Now with  an imageid one can extract the caption:
imageid=imageid_tuple_list[0][0]
cursor.execute('''SELECT comment FROM ImageComments WHERE imageid=?''',
(imageid,))
comment_tuple_list=cursor.fetchall()





-------- Forwarded Message --------
From: Jim Gomi <[hidden email]>
Reply-to: digiKam - Home Manage your photographs as a professional with
the
 power of open source <[hidden email]>
To: [hidden email]
Subject: captions gone but still exist in digikam4.db
Date: Mon, 26 Dec 2016 00:18:35 +0000

The captions have disappeared from a bunch of my photos.

However, when I browse the digikam4.db file using an SQLite browser, I
can still find, in the ImageComments field, the text that was
originally in one of the disappeared captions.

Does anyone have any suggestions about what might be going on, and how
to get the captions back?



Reply | Threaded
Open this post in threaded view
|

Re: [Fwd: captions gone but still exist in digikam4.db]

AndriusWild
What a hassle. I am glad you managed to restore the data.
Thank you for sharing the solution. I saved this to my Google Keep just in case.

Best regards,
Andrey Goreev

On Wed, Jan 11, 2017 at 11:42 AM, Jim Gomi <[hidden email]> wrote:
I have sorted out what the problem was: my digikam4.db database became
corrupted, probably because I restored from an rsync backup, and I
ended up with two entries in digikam4.db for each image.

For each image, one of the entries had the correct metadata (caption
etc) but didn't know which album the image belonged in.
The other entry associated the image with the correct album, but didn't
have the right metadata.

I fixed the problem by writing a python code that went through all the
JPG files in my collection, and for each file it found the relevant
entries in the digikam4.db database, extracted the caption, and wrote
it to the file using exiv2.

Then I deleted the database and restarted digikam.
Digikam read the captions from the metadata of the JPG files and
recreated a correct database.

In future, I will always configure digikam to store metadata in the JPG
files as well as in the database. 



The core elements of the python code are:

import sqlite3
digikam_home='/where/photos/live'
db = sqlite3.connect(os.path.join(digikam_home,'digikam4.db'))
cursor = db.cursor()
filename='IMG_2002.JPG'   # for example
cursor.execute('''SELECT id FROM Images WHERE name=?''', (filename,))
imageid_tuple_list=cursor.fetchall()

# Now with  an imageid one can extract the caption:
imageid=imageid_tuple_list[0][0]
cursor.execute('''SELECT comment FROM ImageComments WHERE imageid=?''',
(imageid,))
comment_tuple_list=cursor.fetchall()





-------- Forwarded Message --------
From: Jim Gomi <[hidden email]>
Reply-to: digiKam - Home Manage your photographs as a professional with
the
 power of open source <[hidden email]>
To: [hidden email]
Subject: captions gone but still exist in digikam4.db
Date: Mon, 26 Dec 2016 00:18:35 +0000

The captions have disappeared from a bunch of my photos.

However, when I browse the digikam4.db file using an SQLite browser, I
can still find, in the ImageComments field, the text that was
originally in one of the disappeared captions.

Does anyone have any suggestions about what might be going on, and how
to get the captions back?