def GenerateQueryUsingSession(self, criteria, target_id, for_stats=False):
        query = self.db.session.query(models.Transaction).filter_by(
            target_id=target_id)
        # If transaction search is being done
        if criteria.get('search', None):
            if criteria.get('url', None):
                if isinstance(criteria.get('url'), list):
                    criteria['url'] = criteria['url'][0]
                query = query.filter(models.Transaction.url.like(
                    '%' + criteria['url'] + '%'))
            if criteria.get('method', None):
                if isinstance(criteria.get('method'), list):
                    criteria['method'] = criteria['method'][0]
                query = query.filter(models.Transaction.method.like(
                    '%' + criteria.get('method') + '%'))
            if criteria.get('data', None):
                if isinstance(criteria.get('data'), list):
                    criteria['data'] = criteria['data'][0]
                query = query.filter(models.Transaction.data.like(
                    '%' + criteria.get('data') + '%'))
            if criteria.get('raw_request', None):
                if isinstance(criteria.get('raw_request'), list):
                    criteria['raw_request'] = criteria['raw_request'][0]
                query = query.filter(models.Transaction.raw_request.like(
                    '%' + criteria.get('raw_request') + '%'))
            if criteria.get('response_status', None):
                if isinstance(criteria.get('response_status'), list):
                    criteria['response_status'] = criteria['response_status'][0]
                query = query.filter(models.Transaction.response_status.like(
                    '%' + criteria.get('response_status') + '%'))
            if criteria.get('response_headers', None):
                if isinstance(criteria.get('response_headers'), list):
                    criteria['response_headers'] = criteria['response_headers'][0]
                query = query.filter(models.Transaction.response_headers.like(
                    '%' + criteria.get('response_headers') + '%'))
            if criteria.get('response_body', None):
                if isinstance(criteria.get('response_body'), list):
                    criteria['response_body'] = criteria['response_body'][0]
                query = query.filter(
                    models.Transaction.binary_response == False,
                    models.Transaction.response_body.like(
                        '%' + criteria.get('response_body') + '%'))
        else:  # If transaction filter is being done
            if criteria.get('url', None):
                if isinstance(criteria.get('url'), (str, unicode)):
                    query = query.filter_by(url=criteria['url'])
                if isinstance(criteria.get('url'), list):
                    query = query.filter(
                        models.Transaction.url.in_(criteria.get('url')))
            if criteria.get('method', None):
                if isinstance(criteria.get('method'), (str, unicode)):
                    query = query.filter_by(method=criteria['method'])
                if isinstance(criteria.get('method'), list):
                    query = query.filter(
                        models.Transaction.method.in_(criteria.get('method')))
            if criteria.get('data', None):
                if isinstance(criteria.get('data'), (str, unicode)):
                    query = query.filter_by(data=criteria['data'])
                if isinstance(criteria.get('data'), list):
                    query = query.filter(models.Transaction.data.in_(criteria.get('data')))
        # For the following section doesn't matter if filter/search because
        # it doesn't make sense to search in a boolean column :P
        if criteria.get('scope', None):
            if isinstance(criteria.get('scope'), list):
                criteria['scope'] = criteria['scope'][0]
            query = query.filter_by(scope=self.config.ConvertStrToBool(criteria['scope']))
        if criteria.get('binary_response', None):
            if isinstance(criteria.get('binary_response'), list):
                criteria['binary_response'] = criteria['binary_response'][0]
            query = query.filter_by(binary_response=self.config.ConvertStrToBool(criteria['binary_response']))
        if not for_stats:  # query for stats shouldn't have limit and offset
            try:
                query.order_by(models.Transaction.local_timestamp)
                if criteria.get('offset', None):
                    if isinstance(criteria.get('offset'), list):
                        criteria['offset'] = int(criteria['offset'][0])
                    if criteria['offset'] >= 0:
                        query = query.offset(criteria['offset'])
                if criteria.get('limit', None):
                    if isinstance(criteria.get('limit'), list):
                        criteria['limit'] = int(criteria['limit'][0])
                    if criteria['limit'] >= 0:
                        query = query.limit(criteria['limit'])
                else:  # It is too dangerous without a limit argument
                    query.limit(10)  # Default limit value is 10
            except __HOLE__:
                raise InvalidParameterType(
                    "Invalid parameter type for transaction db")
        return(query)
dataset/ETHPy150Open owtf/owtf/framework/db/transaction_manager.py/TransactionManager.GenerateQueryUsingSession