Sunday, 17 June 2007

Hacking the Adobe Lightroom Database (lrdb)

On Windows Vista I use EXT2-IFS to mount my home directory, which Windows does not natively support. As my home directory lives underneath the /home mountpoint, I accessed my files via N:\lewiz, as opposed to just N:\ if I were to mount via Samba.

While this all worked very well, I now wanted to use my Lightroom database in my Windows XP VMware image. No problem, I thought, I'd just import the database and all would be well.

As it turned out, Lightroom really didn't seem to like this. All of my folders turned red, I couldn't access the photos and Lightroom went off doing some checking stuff that really didn't interest me.

I attempted to tell Lightroom where my root images directory was, but I didn't have much luck. A little frustrated, I decided to open the database file in vim and do a global search and replace on the offchance. Upon opening the file, I spotted that the lrdb file used by Lightroom is actually a SQLite database.

Impressed, I did some poking and discovered that filename and path data really only exists in two tables: Adobe_imageFiles and AgFolderTagInfo.

As I had no Internet at the time, I had to call Vlad to find out what the SQLite string concatenation function was, but in no time at all I had four SQL queries that I applied to (a copy of) my database:
update Adobe_imageFiles set absolutePath = 'N:' || substr(absolutePath, 9, 9999999);

update Adobe_imageFiles set robustRepresentation = 'WN:' || substr(robustRepresentation, 10, 9999999);

update AgFolderTagInfo set absolutePath = 'N:' || substr(absolutePath, 9, 99999) where absolutePath like '%lewiz%';

update AgFolderTagInfo set robustRepresentation = 'WN:' || substr(robustRepresentation, 10, 99999);

This replaced 'N:\lewiz\...' with 'N:\...' in the appropriate tables.

Import the database into Lightroom, and Voila! My images all work.

That said, Lightroom does appear to be bitching about being unable to write metadata to the files.

This is probably a very stupid thing to do with your Lightroom database, I do not recommend that you try it. I expect that my database will fall apart shortly. In fact, I have this weird feeling that some Lightroom dev is going to pop along, read what I've done, and double over laughing at my stupidity.

Ah, well.

1 comment:

  1. On second thoughts, it turns out that I'd failed to make my Samba share writable from my VMware image.

    Once I fixed this the metadata write errors went away and I have been successful in exporting a photo :)