Fix closing of prepared queries.
Fix test.