Properly select database name if it's defined
Merge pull request #77 from ss23/fix_database_defined

Properly select database name if it's defined