When the condition on L115 is hit and we are sending a CREATE DATABASE command on L119, the query at L139 may be sent before the database is created and used.

The code for setting up a database should be refactored out into a standalone function.