## section-query_results_formatter

section-query_results_formatter

## Functions

int | rasqal_query_results_formats_check ()
int | rasqal_query_results_formats_check2 ()
rasqal_query_results_formatter * | rasqal_new_query_results_formatter ()
rasqal_query_results_formatter * | rasqal_new_query_results_formatter_for_content ()
void | rasqal_free_query_results_formatter ()
int | rasqal_query_results_formatter_read ()
int | rasqal_query_results_formatter_write ()

## Types and Values

typedef | rasqal_query_results_formatter
enum | rasqal_query_results_format_flags

## Description

## Functions

### rasqal_query_results_formats_check ()

    int
    rasqal_query_results_formats_check (rasqal_world *world,
                                        const char *name,
                                        raptor_uri *uri,
                                        const char *mime_type,
                                        int flags);

`rasqal_query_results_formats_check` is deprecated and should not be used in newly-written code.

Check if a query results formatter exists for the requested format.

`Deprecated` : use `rasqal_query_results_formats_check2()` since the implementation of this function returned an inverted boolean result.

#### Parameters

world | rasqal_world object |
name | the query results format name (or NULL) |
uri | raptor_uri query results format uri (or NULL) |
mime_type | mime type name |
flags | bitmask of flags to signify that format is needed for reading (RASQAL_QUERY_RESULTS_FORMAT_FLAG_READER ) or writing ( RASQAL_QUERY_RESULTS_FORMAT_FLAG_WRITER ) |

#### Returns

0 if a formatter exists.

### rasqal_query_results_formats_check2 ()

    int
    rasqal_query_results_formats_check2 (rasqal_world *world,
                                         const char *name,
                                         raptor_uri *uri,
                                         const char *mime_type,
                                         int flags);

Check if a query results formatter exists for the requested format.

#### Parameters

world | rasqal_world object |
name | the query results format name (or NULL) |
uri | raptor_uri query results format uri (or NULL) |
mime_type | mime type name |
flags | bitmask of flags to signify that format is needed for reading (RASQAL_QUERY_RESULTS_FORMAT_FLAG_READER ) or writing ( RASQAL_QUERY_RESULTS_FORMAT_FLAG_WRITER ) |

#### Returns

non-0 if a formatter exists.

### rasqal_new_query_results_formatter ()

    rasqal_query_results_formatter *
    rasqal_new_query_results_formatter (rasqal_world *world,
                                        const char *name,
                                        const char *mime_type,
                                        raptor_uri *format_uri);

Constructor - create a new rasqal_query_results_formatter for an identified format.

A query results format can be found by name, mime type or URI, all of which are optional. If multiple fields are given, the first match is given that matches the name, URI, mime_type in that order. The default query results format will be used if all are format identifying fields are NULL.

See `rasqal_world_get_query_results_format_description()` for obtaining the supported format URIs at run time.

#### Parameters

world | rasqal_world object |
name | the query results format name (or NULL) |
mime_type | the query results format mime type (or NULL) |
format_uri | raptor_uri query results format uri (or NULL) |

#### Returns

a new rasqal_query_results_formatter object or NULL on failure

### rasqal_new_query_results_formatter_for_content ()

    rasqal_query_results_formatter *
    rasqal_new_query_results_formatter_for_content
                                   (rasqal_world *world,
                                    raptor_uri *uri,
                                    const char *mime_type,
                                    const char *buffer,
                                    size_t len,
                                    const unsigned char *identifier);

Constructor - create a new queryresults formatter for an identified format.

Uses `rasqal_world_guess_query_results_format_name()` to find a query results formatter by scoring recognition of the syntax by a block of characters, the content identifier or a mime type. The content identifier is typically a filename or URI or some other identifier.

#### Parameters

world | world object |
uri | URI identifying the syntax (or NULL) |
mime_type | mime type identifying the content (or NULL) |
buffer | buffer of content to guess (or NULL) |
len | length of buffer |
identifier | identifier of content (or NULL) |

#### Returns

a new rasqal_query_results_formatter object or NULL on failure

### rasqal_free_query_results_formatter ()

    void
    rasqal_free_query_results_formatter (rasqal_query_results_formatter *formatter);

Destructor - destroy a rasqal_query_results_formatter object.

#### Parameters

formatter | rasqal_query_results_formatter object |

### rasqal_query_results_formatter_read ()

    int
    rasqal_query_results_formatter_read (rasqal_world *world,
                                         raptor_iostream *iostr,
                                         rasqal_query_results_formatter *formatter,
                                         rasqal_query_results *results,
                                         raptor_uri *base_uri);

Read the query results using the given formatter from an iostream

See `rasqal_world_get_query_results_format_description()` for obtaining the supported format URIs at run time.

#### Parameters

world | rasqal world object |
iostr | raptor_iostream to read the query from |
formatter | rasqal_query_results_formatter object |
results | rasqal_query_results query results format |
base_uri | raptor_uri base URI of the input format |

#### Returns

non-0 on failure

### rasqal_query_results_formatter_write ()

    int
    rasqal_query_results_formatter_write (raptor_iostream *iostr,
                                          rasqal_query_results_formatter *formatter,
                                          rasqal_query_results *results,
                                          raptor_uri *base_uri);

Write the query results using the given formatter to an iostream

Note that after calling this method, the query results will be empty and `rasqal_query_results_finished()` will return true (non-0)

See `rasqal_world_get_query_results_format_description()` for obtaining the supported format URIs at run time.

#### Parameters

iostr | raptor_iostream to write the query to |
formatter | rasqal_query_results_formatter object |
results | rasqal_query_results query results format |
base_uri | raptor_uri base URI of the output format (or NULL) |

#### Returns

non-0 on failure

## Types and Values

### rasqal_query_results_formatter

    rasqal_graph_query_results_formatter* query_results_formatter;

Rasqal query results formatter class.

### enum rasqal_query_results_format_flags

Bitflags for `rasqal_query_results_formats_check()` to find formats with features.

#### Members

RASQAL_QUERY_RESULTS_FORMAT_FLAG_READER | format can be read. |
RASQAL_QUERY_RESULTS_FORMAT_FLAG_WRITER | format can be written. |