Borrow the sqlite3 code from moneta changing where necessary