The rants and ravings of a Mac developer

Ah, Language, isn't it wonderful. If you're not a programmer

Well I’ve spent a good part of the day reading the MySQL manual pages for Language support… and I’ve got to say, life would be so much simpler if everyone only wrote, spoke and used English… I know that’s not a very global attitude, but really, when you get into things like multilingual support (i.e., Unicode) in applications, programming languages, databases, web browsers its a wonder that anything works at all!

This basically comes into play, when importing, exporting or displaying data across different systems that use different character sets. For example reading data from database (stored in latin1 for example) and them manipulating it in PHP (defaults to cp1251, I believe) and then displaying in in a user’s web browser (using utf8). Not only do you have to worry is the character that I want available in the character set that my programming language uses, but now you have to make sure you translate it properly when reading and outputting it. Not only are there all these different character sets, but no two applications/databases/programing languages refer to them by the same name! Talk about impossible tasks!

Not only are there different characters in different languages, but there are differences how the characters in each language are sorted - this is referred to as a collating sequence. For instance in Spanish an ‘ñ’ (n-tilde) sorts between the ‘n’ and ‘0’ characters. And if using traditional spanish, there’s a ‘ch’ character that sorts in between ‘c’ and ‘d’, like wise with the character ‘ll’, its in between ‘l’ and ‘m’.  And it gets worse for other languages such as Swedish/Finish.

This issue also affects the comparison of characters and doing database searches… like is ‘Ano’ equal to ‘Año’ (2nd character is a n-tilde)? Other examples (not sure these will show up correctly in this post) are ‘ß’ is ‘technically’ equal to ‘ss’, but some programming languages/database may say its equal to ‘s’ (I don’t even know what ‘ß’ is for). And look at these other ones, ‘Ä’ = ‘A’, ‘Ö’ = ‘O’ and ‘Ü’ = ‘U’!

Woe is me… and here UTF was supposed to be the holy grail. Remember, “There is no silver bullet.”

Finding the original photo file in the iPhoto Library database

Using iPhoto’s SQLite3 database you can get the relative path to the original photo in the iPhoto library for any image in the sqPhotoInfo table. To do so you must join from the sqPhotoInfo table to the sqFileImage table and finally to the sqFileInfo table.

select pi.primaryKey, pi.archiveFilename, fl.relativepath
from SqPhotoInfo as pi
join SqFileImage as fi on pi.primaryKey = fi.photoKey
join sqFileInfo  as fl on fl.primaryKey = fi.sqFileInfo
where fl.relativePath like 'Originals%'
 

Date Format used in iPhotoMain.db database

Not sure how many of you know that iPhoto uses SQLite3 as its database engine. You can access the database files by right clicking on ~/username/Pictures/iPhoto Library and selecting Show Package Contents. Once you have displayed the package, the SQLite3 datbase files are:

  • iPhotoMain.db
  • iPhotoAux.db
  • face.db
  • face_blob.db

The main database file, as you might have guessed, is the iPhotoMain.db file. In Terminal, you can open the file by changing to the directory of iPhoto Library package, e.g.:

cd /Users/gskluzacek/Pictures/iPhoto\ Library
 

Then execute the following

sqlite3 iPhotoMain.db
 

One of the initial problems that I faced was when reading date fields, like the photoDate field on the sqPhotoInfo table. After some experimenting, I determined that the date is stored as a FLOAT which represents the number of days since midnight Jan 1st 2000. To convert this to a Julian Day value, you need to add the Julian Day of 1/1/2000 - then you can use the datetime() function to convert this to a more human readable format. For example:

select primaryKey, 
datetime(photoDate +  julianday('2000-01-01 00:00:00')) as photoDate,
archiveFilename from SqPhotoInfo order by archiveFilename desc;
 

Hopes this saves someone a couple of hours, I googled all over and couldn’t find this info.

IMG_0949: 

iMac Unboxing
IMG_0949:

iMac Unboxing


IMG_0950: 

iMac Unboxing
IMG_0950:

iMac Unboxing


IMG_0951: 

iMac Unboxing
IMG_0951:

iMac Unboxing


IMG_0952: 

iMac Unboxing
IMG_0952:

iMac Unboxing


IMG_0953: 

iMac Unboxing
IMG_0953:

iMac Unboxing