[AH-258] Cleaned up sql handling