/** * rasqal_query_results_write: * @iostr: #raptor_iostream to write the query to * @results: #rasqal_query_results query results format * @name: format name (or NULL) * @mime_type: format mime type (or NULL) * @format_uri: #raptor_uri describing the format to write (or NULL for default) * @base_uri: #raptor_uri base URI of the output format * * Write the query results to an iostream in a format. * * This uses the #rasqal_query_results_formatter class and the * rasqal_query_results_formatter_write() method to perform the * formatting. * * 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 names, mime_types and URIs at run time. * * Return value: non-0 on failure **/ int rasqal_query_results_write(raptor_iostream *iostr, rasqal_query_results* results, const char *name, const char *mime_type, raptor_uri *format_uri, raptor_uri *base_uri) { rasqal_query_results_formatter *formatter; int status; RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(iostr, raptor_iostream, 1); RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(results, rasqal_query_results, 1); if(results->failed) return 1; formatter = rasqal_new_query_results_formatter(results->world, name, mime_type, format_uri); if(!formatter) return 1; status = rasqal_query_results_formatter_write(iostr, formatter, results, base_uri); rasqal_free_query_results_formatter(formatter); return status; }
static int librdf_query_rasqal_results_formatter_write(raptor_iostream *iostr, librdf_query_results_formatter* qrf, librdf_query_results* query_results, librdf_uri *base_uri) { librdf_query *query=query_results->query; librdf_query_rasqal_context *context=(librdf_query_rasqal_context*)query->context; return rasqal_query_results_formatter_write(iostr, qrf->formatter, context->results, (raptor_uri*)base_uri); }
static int print_formatted_query_results(rasqal_world* world, rasqal_query_results* results, raptor_world* raptor_world_ptr, FILE* output, const char* result_format, raptor_uri* base_uri, int quiet) { raptor_iostream *iostr; rasqal_query_results_formatter* results_formatter; int rc = 0; results_formatter = rasqal_new_query_results_formatter(world, result_format, NULL, NULL); if(!results_formatter) { fprintf(stderr, "%s: Invalid bindings result format `%s'\n", program, result_format); rc = 1; goto tidy; } iostr = raptor_new_iostream_to_file_handle(raptor_world_ptr, output); if(!iostr) { rasqal_free_query_results_formatter(results_formatter); rc = 1; goto tidy; } rc = rasqal_query_results_formatter_write(iostr, results_formatter, results, base_uri); raptor_free_iostream(iostr); rasqal_free_query_results_formatter(results_formatter); tidy: if(rc) fprintf(stderr, "%s: Formatting query results failed\n", program); return rc; }