Better import

This basically rewrites the SQL import code but also improves the CSV import a bit.


By the way, the CSV import is kind of broken, not my fault though: Importing data sets the DB to dirty (as before and as expected) even though the changes are actually already written to the DB...