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
const_cast is evil - can there be a way to avoid it?