Finalise statements in query().

Leaving statements unfinalised means that new functions can't be registered with
the database handle.