Improvements to SQL classes

 * Moved SQL into Query and QueryBuilder
 * Add query result cache