#!/bin/ksh
#
# $Revision: 1.2 $ $Date: 2009/09/24 17:06:39 $
# $Source: /home/vogelke/notebook/2008/0813/firefox-sqlite/RCS/ffdump,v $
# $Host: sys7.com $
# $UUID: d8910d68-bb20-32d5-92a0-8d48d99558f8 $
#
#<ffdump: dump Firefox history.
#
# The place_id column of the moz_historyvisits table corresponds to the
# id column of the moz_places table.
#
# The visit_date column keeps time in PRTime format, a 64-bit integer
# representing the number of microseconds since midnight (00:00:00)
# 1 January 1970 Coordinated Universal Time (UTC).
#
# PRTime format can easily be converted into CTime format by truncating
# everything after the 11th digit.

PATH=/usr/local/bin:/usr/sfw/bin:/opt/sfw/bin:/bin:/usr/bin
export PATH
umask 027

# Can't read the database if Firefox is running, so copy it.
dbfile="/tmp/places$$"
. $HOME/.envrc.sh

case "$MOZILLA_HISTORY" in
    "") echo "MOZILLA_HISTORY not set"; exit 1 ;;
    *)  cp $MOZILLA_HISTORY $dbfile ;;
esac

cat << EndSQL | sqlite $dbfile
SELECT moz_historyvisits.visit_date, moz_places.url
    FROM moz_places, moz_historyvisits
    WHERE moz_places.id = moz_historyvisits.place_id;
EndSQL

rm $dbfile
exit 0

