def _import_results(self, mapping, result_file, conn):
    sf_header = [name.strip('"') for name in result_file.readline().strip().decode('utf-8').split(',')]
    columns = []
    lookup_keys = []
    for sf in sf_header:
        if (sf == 'Records not found for this query'):
            return
        if sf:
            column = mapping.get('fields', {}).get(sf)
            if (not column):
                lookup = mapping.get('lookups', {}).get(sf, {})
                if lookup:
                    lookup_keys.append(sf)
                    column = get_lookup_key_field(lookup, sf)
            if column:
                columns.append(column)
    if (not columns):
        return
    record_type = mapping.get('record_type')
    if record_type:
        columns.append('record_type')
    processor = log_progress(process_incoming_rows(result_file, record_type), self.logger)
    data_file = IteratorBytesIO(processor)
    if mapping['oid_as_pk']:
        self._sql_bulk_insert_from_csv(conn, mapping['table'], columns, data_file)
    else:
        with tempfile.TemporaryFile('w+b') as f_values:
            with tempfile.TemporaryFile('w+b') as f_ids:
                (data_file_values, data_file_ids) = self._split_batch_csv(data_file, f_values, f_ids)
                self._sql_bulk_insert_from_csv(conn, mapping['table'], columns, data_file_values)
                self._sql_bulk_insert_from_csv(conn, mapping['sf_id_table'], ['sf_id'], data_file_ids)
    self.session.commit()
    if (lookup_keys and (not mapping['oid_as_pk'])):
        self._convert_lookups_to_id(mapping, lookup_keys)
def _import_results(self, mapping, result_file, conn):
    sf_header = [name.strip('"') for name in result_file.readline().strip().decode('utf-8').split(',')]
    columns = []
    lookup_keys = []
    for sf in sf_header:
        if (sf == 'Records not found for this query'):
            return
        if sf:
            column = mapping.get('fields', {}).get(sf)
            if (not column):
                lookup = mapping.get('lookups', {}).get(sf, {})
                if lookup:
                    lookup_keys.append(sf)
                    column = get_lookup_key_field(lookup, sf)
            if column:
                columns.append(column)
    if (not columns):
        return
    record_type = mapping.get('record_type')
    if record_type:
        columns.append('record_type')
    processor = log_progress(process_incoming_rows(result_file, record_type), self.logger)
    data_file = IteratorBytesIO(processor)
    if mapping['oid_as_pk']:
        self._sql_bulk_insert_from_csv(conn, mapping['table'], columns, data_file)
    else:
        with tempfile.TemporaryFile('w+b') as f_values:
            with tempfile.TemporaryFile('w+b') as f_ids:
                (data_file_values, data_file_ids) = self._split_batch_csv(data_file, f_values, f_ids)
                self._sql_bulk_insert_from_csv(conn, mapping['table'], columns, data_file_values)
                self._sql_bulk_insert_from_csv(conn, mapping['sf_id_table'], ['sf_id'], data_file_ids)
    self.session.commit()
    if (lookup_keys and (not mapping['oid_as_pk'])):
        self._convert_lookups_to_id(mapping, lookup_keys)