Prepare statement just before execution

This should avoid unneeded database connection when just running the console.