Move code from message handler to separate methods

Like this the methods can be called directly and also the message handler is now much cleaner.
Access type needs to be specified when getting the connection
Tell the tile existence checking function that it is being called from a thread

So that it gets a separate connection and does not needlessly strain Sqlite
thread safeness.