Replace series of if-checks with a switch to make it more extensible and allow for a "default" - namely, the db is not NULL, but also not recognised, which isn't currently handled and so leads to a confusing error (object 'out' not found)