Prevent invalid database names

Close #843
add a missing import