hopefully finally fix prepared statements unlike the maintainer's "fix"

Fix #665.

Note that this hasn't been tested much, but it seems obviously correct based on http://www.postgresql.org/docs/9.3/static/protocol-flow.html

It would be a good idea to write test cases.