SocketAPI: Use new class SqlQuery to cache the sql queries.

This results in better handling of the BUSY condition through SqlQuery.