Add support for query execution timeout

A new "statement_timeout" setting bails out if execution of a query hangs for more than the given number of milliseconds. The mechanism does not make use of the STATEMENT_TIMEOUT postgresql setting but rather implements a timeout on the client side, to deal with hangs due to (for example) a pgbouncer in the middle or whatever other pooler queue.

When timeout is reached the code simply closes the connection and throws an exception.

Addresses #632. Review welcome (the setting could maybe be called "query_timeout" to not confuse it with the postgresql setting)

\cc @springmeyer, @artemp, @abonnasseau
This all looks quite complicated. It may need to be but I would feel more comfortable with this change if it did not impact the current code and this custom code path was only enabled if the user provides a query timeout. From the diff it looks like this complex code is invoked no matter what or am I reading it wrong?