Digikam database

20160130 jean AT huens.be

intro

Distributor ID:	Ubuntu
Description: Ubuntu 14.04.3 LTS
Release: 14.04
Codename: trusty


digikam 4:4.14.0-trusty~ppa1 amd64

DB Organisation:

The digikam database is sqlite format.
It contains a table AlbumRoots used to locate de database(s) and pictures;

On a correctly working system it looks like:

$ sqlite3 ~/Pictures/digikam4.db 
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
AlbumRoots ImageHistory ImageTagProperties Tags
Albums ImageInformation ImageTags TagsTree
DownloadHistory ImageMetadata Images VideoMetadata
ImageComments ImagePositions Searches
ImageCopyright ImageProperties Settings
ImageHaarMatrix ImageRelations TagProperties
sqlite> .schema AlbumRoots
CREATE TABLE AlbumRoots
(id INTEGER PRIMARY KEY,
label TEXT,
status INTEGER NOT NULL,
type INTEGER NOT NULL,
identifier TEXT,
specificPath TEXT,
UNIQUE(identifier, specificPath));
CREATE TRIGGER delete_albumroot DELETE ON AlbumRoots
BEGIN
DELETE FROM Albums
WHERE Albums.albumRoot = OLD.id;
END;
sqlite> select * from AlbumRoots;
1||0|1|volumeid:?uuid=1a87f605-16e3-46f2-b973-37fe2b414561|/home/lucienne/Pictures
sqlite>

One (as root) can look at the devices and its UUID:

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.8T 0 disk
├─sda1 8:1 0 145.1G 0 part /
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 8.8G 0 part [SWAP]
└─sda6 8:6 0 1.7T 0 part /home/lucienne
sr0 11:0 1 1024M 0 rom

# blkid
/dev/sda1: UUID="1a87f605-16e3-46f2-b973-37fe2b414561" TYPE="ext4"
/dev/sda5: UUID="a605a0e2-f440-407c-8de3-7872b366a8d1" TYPE="swap"
/dev/sda6: UUID="a343aead-ce3b-431e-8b49-da2a358c3a9b" TYPE="ext4"

The (for me) amazing point is that the UUID of the / partition  (/dev/sda1) is combined with a Path /home/lucienne/Pictures
which is on the /sda6 partition...

Cause of database corruption.

When switching to a new machine  using a backup of the digikam files, we did encounter two problems:

1) The disks UUID's did change.
2) The location of the Picture files and Digikam DB got changed.

This seems related to

Bug 175923 - digikam uses wrong album root path/wrong disk uuid


$ sqlite3 ~/Backup_digikam/digikam4.db.2015120323
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from AlbumRoots;
1||0|1|volumeid:?uuid=7199951a-fea7-4d70-ad7d-6dbeff318ee5|/lucienne/Pictures

At startup digikam produces a screen :
startup message

This is rather confusing, moreover digikam seems to work at the first but some features are missing
(e.g.  comments added tot pictures,  print assistant, ....0

Workaround

  1. make a backup of your digikam4.db
  2. when digikam is not running, use sqlite3 to edit correct the AlbumRoots table :
    $ sqlite3 digikam4.db
    ...
    sqlite> select * from AlbumRoots;
    1||0|1|volumeid:?uuid=7199951a-fea7-4d70-ad7d-6dbeff318ee5|/lucienne/Pictures
    sqlite> UPDATE AlbumRoots SET specificPath='/home/lucienne/Pictures' where specificPath='/lucienne/Pictures';
    sqlite> select * from AlbumRoots;
    1||0|1|volumeid:?uuid=7199951a-fea7-4d70-ad7d-6dbeff318ee5|/home/lucienne/Pictures
    sqlite> .exit
  3. Start digikam. Now it will detect the UUID is not correct, but /home/lucienne/Pictures exits.
    And it suggests to correct this problem.
    Start_with_correct_path
  4. Digikam can cope with changing UUIDs but only if the location of the database/albums  remains correct.

  5. If you prefer to edit UUID in sql take into account that special chars in the string must be escaped by  single quotes :
    sqlite> UPDATE AlbumRoots SET identifier='?uuid=8c178eec-e410-4346-85c1-0fe9db3336f9' WHERE identifier='?uuid=8c178eec-e410-4346-85c1-0fe9db3336f8';