#!/bin/sh
#   This file is part of the KDE project
#   Copyright (C) 2004-2005 Jaroslaw Staniek <js@iidea.pl>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public
#   License as published by the Free Software Foundation; either
#   version 2 of the License, or (at your option) any later version.

# Performs migration from SQLite2 format to SQLite3 format
# usage: ksqlite2to3 <sqlite2-db-file>

if test $# -lt 1 ; then
	echo "usage: ksqlite2to3 <sqlite2-db-file>"
	exit 1
fi

basename=`basename $0`
temp=`mktemp -q "$basename"-XXXXXX 2> /dev/null || date +%y%m%d%H%M2`
dbfile=$1
dir=`dirname $dbfile`

ksqlite2 $dbfile .quit 2> /dev/null
if test $? -ne 0 ; then
	echo "This file is not in SQLite2 format"
	rm -f "$dir/$temp"
	exit 1
fi

ksqlite2 -verbose-dump $dbfile .dump | ksqlite "$dir/$temp"
if test $? -ne 0 ; then
	echo "Error during converting"
	rm -f "$dir/$temp"
	exit 2
fi

mv "$dir/$temp" $dbfile 2> /dev/null || exit 3

