static int rasqal_aggregation_rowsource_ensure_variables(rasqal_rowsource* rowsource, void *user_data) { rasqal_aggregation_rowsource_context* con; int offset; int i; con = (rasqal_aggregation_rowsource_context*)user_data; if(rasqal_rowsource_ensure_variables(con->rowsource)) return 1; rowsource->size = 0; if(rasqal_rowsource_copy_variables(rowsource, con->rowsource)) return 1; con->input_values_count = rowsource->size; for(i = 0; i < con->expr_count; i++) { rasqal_agg_expr_data* expr_data = &con->expr_data[i]; offset = rasqal_rowsource_add_variable(rowsource, expr_data->variable); if(offset < 0) return 1; } return 0; }
/** * rasqal_rowsource_copy_variables: * @dest_rowsource: destination rowsource to copy into * @src_rowsource: source rowsource to copy from * * INTERNAL - Copy a variables projection from one rowsource to another * * This adds new variables from @src_rowsource to the * @dest_rowsource, it does not add duplicates. * * Return value: 0 on success, non-0 on failure **/ int rasqal_rowsource_copy_variables(rasqal_rowsource *dest_rowsource, rasqal_rowsource *src_rowsource) { int i; for(i = 0; i < src_rowsource->size; i++) { rasqal_variable* v; v = rasqal_rowsource_get_variable_by_offset(src_rowsource, i); if(rasqal_rowsource_add_variable(dest_rowsource, v) < 0) return 1; } return 0; }
static int rasqal_graph_rowsource_ensure_variables(rasqal_rowsource* rowsource, void *user_data) { rasqal_graph_rowsource_context* con; con = (rasqal_graph_rowsource_context*)user_data; rasqal_rowsource_ensure_variables(con->rowsource); rowsource->size = 0; /* Put GRAPH variable first in result row */ rasqal_rowsource_add_variable(rowsource, con->var); rasqal_rowsource_copy_variables(rowsource, con->rowsource); return 0; }
static int rasqal_join_rowsource_ensure_variables(rasqal_rowsource* rowsource, void *user_data) { rasqal_join_rowsource_context* con; int map_size; int i; con = (rasqal_join_rowsource_context*)user_data; if(rasqal_rowsource_ensure_variables(con->left)) return 1; if(rasqal_rowsource_ensure_variables(con->right)) return 1; map_size = rasqal_rowsource_get_size(con->right); con->right_map = RASQAL_MALLOC(int*, RASQAL_GOOD_CAST(size_t, sizeof(int) * RASQAL_GOOD_CAST(size_t, map_size))); if(!con->right_map) return 1; rowsource->size = 0; /* copy in variables from left rowsource */ if(rasqal_rowsource_copy_variables(rowsource, con->left)) return 1; /* add any new variables not already seen from right rowsource */ for(i = 0; i < map_size; i++) { rasqal_variable* v; int offset; v = rasqal_rowsource_get_variable_by_offset(con->right, i); if(!v) break; offset = rasqal_rowsource_add_variable(rowsource, v); if(offset < 0) return 1; con->right_map[i] = offset; } return 0; }
/** * rasqal_rowsource_copy_variables: * @dest_rowsource: destination rowsource to copy into * @src_rowsource: source rowsource to copy from * * INTERNAL - Copy a variables projection from one rowsource to another * * This adds new variables from @src_rowsource to the * @dest_rowsource, it does not add duplicates. * * Return value: 0 on success, non-0 on failure **/ int rasqal_rowsource_copy_variables(rasqal_rowsource *dest_rowsource, rasqal_rowsource *src_rowsource) { int i; for(i = 0; i < src_rowsource->size; i++) { rasqal_variable* v; v = rasqal_rowsource_get_variable_by_offset(src_rowsource, i); if(!v) { RASQAL_DEBUG5("%s src rowsource %p failed to return variable at offset %d, size %d\n", src_rowsource->handler->name, src_rowsource, i, src_rowsource->size); return 1; } if(rasqal_rowsource_add_variable(dest_rowsource, v) < 0) return 1; } return 0; }
static int rasqal_rowsequence_rowsource_ensure_variables(rasqal_rowsource* rowsource, void *user_data) { rasqal_rowsequence_rowsource_context* con; int i; con = (rasqal_rowsequence_rowsource_context*)user_data; rowsource->size = 0; for(i = 0; i < raptor_sequence_size(con->vars_seq); i++) { rasqal_variable* v; v = (rasqal_variable*)raptor_sequence_get_at(con->vars_seq, i); rasqal_rowsource_add_variable(rowsource, v); } raptor_free_sequence(con->vars_seq); con->vars_seq = NULL; return 0; }
static void rasqal_sparql_xml_sax2_start_element_handler(void *user_data, raptor_xml_element *xml_element) { rasqal_rowsource_sparql_xml_context* con; int i; raptor_qname* name; rasqal_sparql_xml_read_state state=STATE_unknown; int attr_count; con=(rasqal_rowsource_sparql_xml_context*)user_data; name=raptor_xml_element_get_name(xml_element); for(i=STATE_first; i <= STATE_last; i++) { if(!strcmp((const char*)raptor_qname_get_local_name(name), sparql_xml_element_names[i])) { state=(rasqal_sparql_xml_read_state)i; con->state=state; } } if(state == STATE_unknown) { fprintf(stderr, "UNKNOWN element %s\n", raptor_qname_get_local_name(name)); con->failed++; } #ifdef TRACE_XML if(con->trace) { pad(stderr, con->depth); fprintf(stderr, "Element %s (%d)\n", raptor_qname_get_local_name(name), state); } #endif attr_count=raptor_xml_element_get_attributes_count(xml_element); con->name=NULL; con->datatype=NULL; con->language=NULL; if(attr_count > 0) { raptor_qname** attrs=raptor_xml_element_get_attributes(xml_element); for(i=0; i < attr_count; i++) { #ifdef TRACE_XML if(con->trace) { pad(stderr, con->depth+1); fprintf(stderr, "Attribute %s='%s'\n", raptor_qname_get_local_name(attrs[i]), raptor_qname_get_value(attrs[i])); } #endif if(!strcmp((const char*)raptor_qname_get_local_name(attrs[i]), "name")) con->name=(const char*)raptor_qname_get_counted_value(attrs[i], &con->name_length); else if(!strcmp((const char*)raptor_qname_get_local_name(attrs[i]), "datatype")) con->datatype=(const char*)raptor_qname_get_value(attrs[i]); } } if(raptor_xml_element_get_language(xml_element)) { con->language=(const char*)raptor_xml_element_get_language(xml_element); #ifdef TRACE_XML if(con->trace) { pad(stderr, con->depth+1); fprintf(stderr, "xml:lang '%s'\n", con->language); } #endif } switch(state) { case STATE_variable: if(con->name) { unsigned char* var_name; rasqal_variable *v; var_name = (unsigned char*)RASQAL_MALLOC(cstring, con->name_length+1); memcpy(var_name, con->name, con->name_length + 1); v = rasqal_variables_table_add(con->vars_table, RASQAL_VARIABLE_TYPE_NORMAL, var_name, NULL); if(v) rasqal_rowsource_add_variable(con->rowsource, v); } break; case STATE_result: if(1) { con->row = rasqal_new_row(con->rowsource); RASQAL_DEBUG2("Made new row %d\n", con->offset); con->offset++; } break; case STATE_binding: con->result_offset = rasqal_rowsource_get_variable_offset_by_name(con->rowsource, (const unsigned char*)con->name); break; case STATE_sparql: case STATE_head: case STATE_results: case STATE_literal: case STATE_bnode: case STATE_uri: case STATE_unknown: default: break; } con->depth++; }