Removed awful code duplications, since currently the only thing different between MySQL and SQLite is the way to open connection.