Refactor api_cspy, sans the query
api_cspy sql query refactor