def execute(self, q, args=()):
        """
        Send a query to the Salesforce API.
        """
        # pylint:disable=too-many-branches
        self.rowcount = None
        response = None
        if self.query is None:
            self.execute_select(q, args)
        else:
            response = self.execute_django(q, args)
            if isinstance(response, list):
                return

        # the encoding is detected automatically, e.g. from headers
        if response and response.text:
            # parse_float set to decimal.Decimal to avoid precision errors when
            # converting from the json number to a float and then to a Decimal object
            # on a model's DecimalField. This converts from json number directly
            # to a Decimal object
            data = response.json(parse_float=decimal.Decimal)
            # a SELECT query
            if 'totalSize' in data:
                # SELECT
                self.rowcount = data['totalSize']
            # a successful INSERT query, return after getting PK
            elif('success' in data and 'id' in data):
                self.lastrowid = data['id']
                return
            elif 'compositeResponse' in data:
                # TODO treat error reporting for composite requests
                self.lastrowid = [x['body']['id'] if x['body'] is not None else x['referenceId']
                                  for x in data['compositeResponse']]
                return
            elif data['hasErrors'] is False:
                # it is from Composite Batch request
                # save id from bulk_create even if Django don't use it
                if data['results'] and data['results'][0]['result']:
                    self.lastrowid = [item['result']['id'] for item in data['results']]
                return
            # something we don't recognize
            else:
                raise DatabaseError(data)

            if not q.upper().startswith('SELECT COUNT() FROM'):
                self.first_row = data['records'][0] if data['records'] else None
def execute ( self , q , args = ( ) ) : self . rowcount = None response = None if self . query is None : self . execute_select ( q , args ) else : response = self . execute_django ( q , args ) if isinstance ( response , list ) : return if response and response . text : data = response . json ( parse_float = decimal . Decimal ) if 'totalSize' in data : self . rowcount = data [ 'totalSize' ] elif ( 'success' in data and 'id' in data ) : self . lastrowid = data [ 'id' ] return elif 'compositeResponse' in data : self . lastrowid = [ x [ 'body' ] [ 'id' ] if x [ 'body' ] is not None else x [ 'referenceId' ] for x in data [ 'compositeResponse' ] ] return elif data [ 'hasErrors' ] is False : if data [ 'results' ] and data [ 'results' ] [ 0 ] [ 'result' ] : self . lastrowid = [ item [ 'result' ] [ 'id' ] for item in data [ 'results' ] ] return else : raise DatabaseError ( data ) if not q . upper ( ) . startswith ( 'SELECT COUNT() FROM' ) : self . first_row = data [ 'records' ] [ 0 ] if data [ 'records' ] else None
Send a query to the Salesforce API.