Reorganized database logic code

Moved all selects into one method in a switch to eliminate some
redundant code.