rasqal_rowsource* rasqal_new_distinct_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource* rowsource) { rasqal_distinct_rowsource_context *con; int flags = 0; if(!world || !query || !rowsource) goto fail; con = (rasqal_distinct_rowsource_context*)RASQAL_CALLOC(rasqal_distinct_rowsource_context, 1, sizeof(rasqal_distinct_rowsource_context)); if(!con) goto fail; con->rowsource = rowsource; return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_distinct_rowsource_handler, query->vars_table, flags); fail: if(rowsource) rasqal_free_rowsource(rowsource); return NULL; }
/** * rasqal_new_graph_rowsource: * @world: world object * @query: query object * @rowsource: input rowsource * @var: graph variable * * INTERNAL - create a new GRAPH rowsource that binds a variable * * The @rowsource becomes owned by the new rowsource * * Return value: new rowsource or NULL on failure */ rasqal_rowsource* rasqal_new_graph_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource* rowsource, rasqal_variable *var) { rasqal_graph_rowsource_context *con; int flags = 0; if(!world || !query || !rowsource || !var) return NULL; con = (rasqal_graph_rowsource_context*)RASQAL_CALLOC(rasqal_graph_rowsource_context, 1, sizeof(rasqal_graph_rowsource_context)); if(!con) return NULL; con->rowsource = rowsource; con->var = var; return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_graph_rowsource_handler, query->vars_table, flags); }
/** * rasqal_new_rowsequence_rowsource: * @world: world object * @query: query object * @vt: variables table * @rows_seq: input sequence of #rasqal_row * @vars_seq: input sequence of #rasqal_variable for all rows in @rows_seq * * INTERNAL - create a new rowsource over a sequence of rows with given variables * * This uses the number of variables in @vt to set the rowsource size * (order size is always 0) and then checks that all the rows in the * sequence are the same. If not, construction fails and NULL is * returned. * * The @rows_seq and @vars_seq become owned by the new rowsource. * * Return value: new rowsource or NULL on failure */ rasqal_rowsource* rasqal_new_rowsequence_rowsource(rasqal_world *world, rasqal_query* query, rasqal_variables_table* vt, raptor_sequence* rows_seq, raptor_sequence* vars_seq) { rasqal_rowsequence_rowsource_context* con; int flags = 0; if(!world || !query || !vt || !rows_seq || !vars_seq) return NULL; if(!raptor_sequence_size(rows_seq) || !raptor_sequence_size(vars_seq)) return NULL; con = RASQAL_CALLOC(rasqal_rowsequence_rowsource_context*, 1, sizeof(*con)); if(!con) return NULL; con->seq = rows_seq; con->vars_seq = vars_seq; return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_rowsequence_rowsource_handler, vt, flags); }
/** * rasqal_new_sort_rowsource: * @world: query world * @query: query results object * @rowsource: input rowsource * @order_seq: order sequence (shared, may be NULL) * @distinct: distinct flag * * INTERNAL - create a SORT over rows from input rowsource * * The @rowsource becomes owned by the new rowsource. * * Return value: new rowsource or NULL on failure */ rasqal_rowsource* rasqal_new_sort_rowsource(rasqal_world *world, rasqal_query *query, rasqal_rowsource *rowsource, raptor_sequence* order_seq, int distinct) { rasqal_sort_rowsource_context *con; int flags = 0; if(!world || !query || !rowsource) goto fail; con = RASQAL_CALLOC(rasqal_sort_rowsource_context*, 1, sizeof(*con)); if(!con) goto fail; con->rowsource = rowsource; con->order_seq = order_seq; con->distinct = distinct; return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_sort_rowsource_handler, query->vars_table, flags); fail: if(rowsource) rasqal_free_rowsource(rowsource); return NULL; }
/** * rasqal_new_service_rowsource: * @world: world object * @query: query object * @service_uri: service URI * @query_string: query to send to service * @data_graphs: sequence of data graphs (or NULL) * @rs_flags: service rowsource flags * * INTERNAL - create a new rowsource that takes rows from a service * * All arguments are copied. * * Return value: new rowsource or NULL on failure */ rasqal_rowsource* rasqal_new_service_rowsource(rasqal_world *world, rasqal_query* query, raptor_uri* service_uri, const unsigned char* query_string, raptor_sequence* data_graphs, unsigned int rs_flags) { rasqal_service_rowsource_context* con = NULL; rasqal_service* svc = NULL; int flags = 0; int silent = (rs_flags & RASQAL_ENGINE_BITFLAG_SILENT); if(!world || !query_string) goto fail; svc = rasqal_new_service(query->world, service_uri, query_string, data_graphs); if(!svc) { if(!silent) goto fail; /* Silent errors so tidy up and return empty rowsource */ RASQAL_FREE(cstring, query_string); if(data_graphs) raptor_free_sequence(data_graphs); return rasqal_new_empty_rowsource(world, query); } con = RASQAL_CALLOC(rasqal_service_rowsource_context*, 1, sizeof(*con)); if(!con) goto fail; con->svc = svc; con->query = query; con->flags = rs_flags; return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_service_rowsource_handler, query->vars_table, flags); fail: if(svc) rasqal_free_service(svc); if(con) RASQAL_FREE(rasqal_service_rowsource_context, con); if(query_string) RASQAL_FREE(cstring, query_string); if(data_graphs) raptor_free_sequence(data_graphs); return NULL; }
/** * rasqal_new_empty_rowsource: * @world: world object * @query: query object * * INTERNAL - create a new EMPTY rowsource that always returns zero rows * * Return value: new rowsource or NULL on failure */ rasqal_rowsource* rasqal_new_empty_rowsource(rasqal_world *world, rasqal_query* query) { rasqal_empty_rowsource_context* con; int flags = 0; if(!world || !query) return NULL; con = RASQAL_CALLOC(rasqal_empty_rowsource_context*, 1, sizeof(*con)); if(!con) return NULL; return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_empty_rowsource_handler, query->vars_table, flags); }
rasqal_rowsource* rasqal_new_groupby_rowsource(rasqal_world *world, rasqal_query* query, rasqal_rowsource* rowsource, raptor_sequence* expr_seq) { rasqal_groupby_rowsource_context* con; int flags = 0; if(!world || !query) return NULL; con = (rasqal_groupby_rowsource_context*)RASQAL_CALLOC(rasqal_groupby_rowsource_context, 1, sizeof(*con)); if(!con) goto fail; con->rowsource = rowsource; con->expr_seq_size = 0; if(expr_seq) { con->expr_seq = rasqal_expression_copy_expression_sequence(expr_seq); if(!con->expr_seq) goto fail; con->expr_seq_size = raptor_sequence_size(expr_seq); } return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_groupby_rowsource_handler, query->vars_table, flags); fail: if(rowsource) rasqal_free_rowsource(rowsource); if(expr_seq) raptor_free_sequence(expr_seq); return NULL; }
/** * rasqal_new_join_rowsource: * @world: world object * @query: query object * @left: input left (first) rowsource * @right: input right (second) rowsource * @join_type: join type * @expr: join expression to filter result rows * * INTERNAL - create a new JOIN over two rowsources * * This uses the number of variables in @vt to set the rowsource size * (order size is always 0) and then checks that all the rows in the * sequence are the same. If not, construction fails and NULL is * returned. * * The @left and @right rowsources become owned by the rowsource. * * Return value: new rowsource or NULL on failure */ rasqal_rowsource* rasqal_new_join_rowsource(rasqal_world *world, rasqal_query* query, rasqal_rowsource* left, rasqal_rowsource* right, rasqal_join_type join_type, rasqal_expression *expr) { rasqal_join_rowsource_context* con; int flags = 0; if(!world || !query || !left || !right) goto fail; /* only left outer join and cross join supported */ if(join_type != RASQAL_JOIN_TYPE_LEFT && join_type != RASQAL_JOIN_TYPE_NATURAL) goto fail; con = RASQAL_CALLOC(rasqal_join_rowsource_context*, 1, sizeof(*con)); if(!con) goto fail; con->left = left; con->right = right; con->join_type = join_type; con->expr = rasqal_new_expression_from_expression(expr); return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_join_rowsource_handler, query->vars_table, flags); fail: if(left) rasqal_free_rowsource(left); if(right) rasqal_free_rowsource(right); return NULL; }
/* * 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_rowsource* rasqal_new_aggregation_rowsource(rasqal_world *world, rasqal_query* query, rasqal_rowsource* rowsource, raptor_sequence* exprs_seq, raptor_sequence* vars_seq) { rasqal_aggregation_rowsource_context* con; int flags = 0; int size; int i; if(!world || !query || !rowsource || !exprs_seq || !vars_seq) goto fail; exprs_seq = rasqal_expression_copy_expression_sequence(exprs_seq); vars_seq = rasqal_variable_copy_variable_sequence(vars_seq); size = raptor_sequence_size(exprs_seq); if(size != raptor_sequence_size(vars_seq)) { RASQAL_DEBUG3("expressions sequence size %d does not match vars sequence size %d\n", size, raptor_sequence_size(vars_seq)); goto fail; } con = (rasqal_aggregation_rowsource_context*)RASQAL_CALLOC(rasqal_aggregation_rowsource_context, 1, sizeof(*con)); if(!con) goto fail; con->rowsource = rowsource; con->exprs_seq = exprs_seq; con->vars_seq = vars_seq; /* allocate per-expr data */ con->expr_count = size; con->expr_data = (rasqal_agg_expr_data*)RASQAL_CALLOC(rasqal_agg_expr_data, sizeof(rasqal_agg_expr_data), size); if(!con->expr_data) goto fail; /* Initialise per-expr data */ for(i = 0; i < size; i++) { rasqal_expression* expr = (rasqal_expression *)raptor_sequence_get_at(exprs_seq, i); rasqal_variable* variable = (rasqal_variable*)raptor_sequence_get_at(vars_seq, i); rasqal_agg_expr_data* expr_data = &con->expr_data[i]; expr_data->expr = rasqal_new_expression_from_expression(expr); expr_data->variable = variable; /* Prepare expression arguments sequence in per-expr data */ if(expr->args) { /* list of #rasqal_expression arguments already in expr * #RASQAL_EXPR_FUNCTION and #RASQAL_EXPR_GROUP_CONCAT */ expr_data->exprs_seq = rasqal_expression_copy_expression_sequence(expr->args); } else { /* single argument */ expr_data->exprs_seq = raptor_new_sequence((raptor_data_free_handler)rasqal_free_expression, (raptor_data_print_handler)rasqal_expression_print); raptor_sequence_push(expr_data->exprs_seq, rasqal_new_expression_from_expression(expr->arg1)); } } return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_aggregation_rowsource_handler, query->vars_table, flags); fail: if(rowsource) rasqal_free_rowsource(rowsource); if(exprs_seq) raptor_free_sequence(exprs_seq); if(vars_seq) raptor_free_sequence(vars_seq); return NULL; }