/** * rasqal_new_rowsource_from_handler: * @query: query object * @user_data: pointer to context information to pass in to calls * @handler: pointer to handler methods * @vars_table: variables table to use for rows (or NULL) * @flags: 0 (none defined so far) * * Create a new rowsource over a user-defined handler. * * Return value: new #rasqal_rowsource object or NULL on failure **/ rasqal_rowsource* rasqal_new_rowsource_from_handler(rasqal_world* world, rasqal_query* query, void *user_data, const rasqal_rowsource_handler *handler, rasqal_variables_table* vars_table, int flags) { rasqal_rowsource* rowsource; if(!world || !handler) return NULL; if(handler->version < 1 || handler->version > 1) return NULL; rowsource = RASQAL_CALLOC(rasqal_rowsource*, 1, sizeof(*rowsource)); if(!rowsource) { if(handler->finish) handler->finish(NULL, user_data); return NULL; } rowsource->usage = 1; rowsource->world = world; rowsource->query = query; rowsource->user_data = (void*)user_data; rowsource->handler = handler; rowsource->flags = flags; rowsource->size = 0; rowsource->generate_group = 0; if(vars_table) rowsource->vars_table = rasqal_new_variables_table_from_variables_table(vars_table); else rowsource->vars_table = NULL; rowsource->variables_sequence = raptor_new_sequence((raptor_data_free_handler)rasqal_free_variable, (raptor_data_print_handler)rasqal_variable_print); if(!rowsource->variables_sequence) { rasqal_free_rowsource(rowsource); return NULL; } if(rowsource->handler->init && rowsource->handler->init(rowsource, rowsource->user_data)) { RASQAL_DEBUG2("rowsource %s init failed\n", rowsource->handler->name); rasqal_free_rowsource(rowsource); return NULL; } return rowsource; }
/* * rasqal_query_results_getrowsource_sparql_xml: * @world: rasqal world object * @iostr: #raptor_iostream to read the query results from * @base_uri: #raptor_uri base URI of the input format * * Read the fourth version of the SPARQL XML query results format from an * iostream in a format returning a rwosurce - INTERNAL. * * Return value: a new rasqal_rowsource or NULL on failure **/ static rasqal_rowsource* rasqal_query_results_get_rowsource_sparql_xml(rasqal_query_results_formatter* formatter, rasqal_world *world, rasqal_variables_table* vars_table, raptor_iostream *iostr, raptor_uri *base_uri) { rasqal_rowsource_sparql_xml_context* con; con=(rasqal_rowsource_sparql_xml_context*)RASQAL_CALLOC(rasqal_rowsource_sparql_xml_context, 1, sizeof(rasqal_rowsource_sparql_xml_context)); if(!con) return NULL; con->world=world; con->base_uri = base_uri ? raptor_uri_copy(base_uri) : NULL; con->iostr=iostr; con->locator.uri=base_uri; con->sax2 = raptor_new_sax2(world->raptor_world_ptr, &con->locator, con); if(!con->sax2) return NULL; raptor_sax2_set_start_element_handler(con->sax2, rasqal_sparql_xml_sax2_start_element_handler); raptor_sax2_set_characters_handler(con->sax2, rasqal_sparql_xml_sax2_characters_handler); raptor_sax2_set_end_element_handler(con->sax2, rasqal_sparql_xml_sax2_end_element_handler); con->results_sequence = raptor_new_sequence((raptor_data_free_handler)rasqal_free_row, (raptor_data_print_handler)rasqal_row_print); con->vars_table = rasqal_new_variables_table_from_variables_table(vars_table); return rasqal_new_rowsource_from_handler(world, NULL, con, &rasqal_rowsource_sparql_xml_handler, con->vars_table, 0); }
/** * rasqal_new_query_results: * @world: rasqal world object * @query: query object (or NULL) * @type: query results (expected) type * @vars_table: variables table * * Create a new query results set * * The @query may be NULL for result set objects that are standalone * and not attached to any particular query * * Return value: a new query result object or NULL on failure **/ rasqal_query_results* rasqal_new_query_results(rasqal_world* world, rasqal_query* query, rasqal_query_results_type type, rasqal_variables_table* vars_table) { rasqal_query_results* query_results; RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, NULL); RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(vars_table, rasqal_variables_table, NULL); query_results = (rasqal_query_results*)RASQAL_CALLOC(rasqal_query_results, 1, sizeof(*query_results)); if(!query_results) return NULL; query_results->world = world; query_results->type = type; query_results->finished = 0; query_results->executed = 0; query_results->failed = 0; query_results->query = query; query_results->result_count = 0; query_results->execution_data = NULL; query_results->row = NULL; query_results->ask_result = -1; query_results->store_results = 0; query_results->current_triple_result = -1; /* initialize static query_results->result_triple */ raptor_statement_init(&query_results->result_triple, world->raptor_world_ptr); query_results->triple = NULL; query_results->results_sequence = NULL; query_results->size = 0; query_results->vars_table = rasqal_new_variables_table_from_variables_table(vars_table); return query_results; }