Reset prepared statement between query lists on shutdown

Failing to do so results in a segfault when multiple database flushes are required at shutdown.