denisenkom/pytds — pull request #20 by pdunnigan (2014-01-08 19:34:42+00:00)
Title: pytds timeouts, fixed query timeout that was being ignored

In the pytds/dbapi, _Connection class there are two timeouts in __init__, login_timeout and timeout.

login_timeout should be used to establish the socket connection whereas timeout is for query timeouts.

the following line of existing code overwrites the query_timeout with the login_timeout before can be used.
```
login.query_timeout = login.connect_timeout if login.connect_timeout else login.query_timeout
```
Also the line
```
sock.settimeout(login.query_timeout)
```
was being called before the initial socket connection overriding the connect_timeout (login_timeout). This should be called after the initial login is established for any subsequence calls.

Lastly, the timeout=0 default is incorrect forcing a timeout immediately. As per the python socket library documentation, None is used as opposed to 0 to block forever. Changed this value to None as default.

To test using MSSQL, establish a connection and use the following SQL to test timeouts (this will timeout in the existing code).
```
WAITFOR DELAY '00:01:05'
```