/**
 * 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;
}
static void
rasqal_free_groupby_tree_node(rasqal_groupby_tree_node* node)
{
  if(!node)
    return;
  
  if(node->literals)
    raptor_free_sequence(node->literals);
  
  if(node->rows)
    raptor_free_sequence(node->rows);
  
  RASQAL_FREE(rasqal_groupby_tree_node, node);
}
/*
 * rasqal_free_solution_modifier:
 * @sm: #rasqal_solution_modifier object
 *
 * INTERNAL - Free a solution modifier object.
 * 
 **/
void
rasqal_free_solution_modifier(rasqal_solution_modifier* sm)
{
  if(!sm)
    return;
  
  if(sm->order_conditions)
    raptor_free_sequence(sm->order_conditions);
  
  if(sm->group_conditions)
    raptor_free_sequence(sm->group_conditions);
  
  RASQAL_FREE(rasqal_solution_modifier, sm);
}
static int
rasqal_aggregation_rowsource_finish(rasqal_rowsource* rowsource,
                                    void *user_data)
{
  rasqal_aggregation_rowsource_context* con;

  con = (rasqal_aggregation_rowsource_context*)user_data;

  if(con->expr_data) {
    int i;

    for(i = 0; i < con->expr_count; i++) {
      rasqal_agg_expr_data* expr_data = &con->expr_data[i];

      if(expr_data->agg_user_data)
        rasqal_builtin_agg_expression_execute_finish(expr_data->agg_user_data);

      if(expr_data->exprs_seq)
        raptor_free_sequence(expr_data->exprs_seq);

      if(expr_data->expr)
        rasqal_free_expression(expr_data->expr);

      if(expr_data->map)
        rasqal_free_map(expr_data->map);
    }

    RASQAL_FREE(rasqal_agg_expr_data, con->expr_data);
  }
  
  if(con->exprs_seq)
    raptor_free_sequence(con->exprs_seq);

  if(con->vars_seq)
    raptor_free_sequence(con->vars_seq);

  if(con->rowsource)
    rasqal_free_rowsource(con->rowsource);
  
  if(con->saved_row)
    rasqal_free_row(con->saved_row);

  if(con->input_values)
    raptor_free_sequence(con->input_values);

  RASQAL_FREE(rasqal_aggregation_rowsource_context, con);

  return 0;
}
Exemple #5
0
/**
 * rasqal_query_results_execute_and_store_results:
 * @query_results: query results object
 *
 * INTERNAL - Store all query result (rows) immediately
 *
 * Return value: non-0 on failure
 */
static int
rasqal_query_results_execute_and_store_results(rasqal_query_results* query_results)
{
  rasqal_query* query;
  raptor_sequence* seq = NULL;

  query = query_results->query;

  if(query_results->results_sequence)
     raptor_free_sequence(query_results->results_sequence);

  if(query_results->execution_factory->get_all_rows) {
    rasqal_engine_error execution_error = RASQAL_ENGINE_OK;

    seq = query_results->execution_factory->get_all_rows(query_results->execution_data, &execution_error);
    if(execution_error == RASQAL_ENGINE_FAILED)
      query_results->failed = 1;
  }

  query_results->results_sequence = seq;

  if(!seq) {
    query_results->finished = 1;
  } else
    rasqal_query_results_rewind(query_results);

  return query_results->failed;
}
static rasqal_expression*
make_test_expr(rasqal_world* world,
               raptor_sequence* expr_vars_seq,
               rasqal_op op)
{
  if(op == RASQAL_EXPR_MAX ||
     op == RASQAL_EXPR_MIN ||
     op == RASQAL_EXPR_SUM ||
     op == RASQAL_EXPR_AVG ||
     op == RASQAL_EXPR_SAMPLE) {
    rasqal_expression* arg1;

    arg1 = raptor_sequence_delete_at(expr_vars_seq, 0);
    raptor_free_sequence(expr_vars_seq);

    return rasqal_new_aggregate_function_expression(world, op,
                                                    arg1,
                                                    /* params */ NULL, 
                                                    /* flags */ 0);
  }
  
  if(op == RASQAL_EXPR_GROUP_CONCAT) {
    return rasqal_new_group_concat_expression(world, 
                                              /* flags */ 0,
                                              expr_vars_seq,
                                              /* separator */ NULL);
  }

  return NULL;
}
static int
rasqal_rowsequence_rowsource_finish(rasqal_rowsource* rowsource,
                                    void *user_data)
{
  rasqal_rowsequence_rowsource_context* con;

  con = (rasqal_rowsequence_rowsource_context*)user_data;
  if(con->seq)
    raptor_free_sequence(con->seq);
  if(con->vars_seq)
    raptor_free_sequence(con->vars_seq);
  
  RASQAL_FREE(rasqal_rowsequence_rowsource_context, con);

  return 0;
}
Exemple #8
0
/**
 * raptor_free_xml_element:
 * @element: XML Element
 * 
 * Destructor - destroy a raptor_xml_element object.
 **/
void
raptor_free_xml_element(raptor_xml_element *element)
{
  unsigned int i;

  if(!element)
    return;

  for(i = 0; i < element->attribute_count; i++)
    if(element->attributes[i])
      raptor_free_qname(element->attributes[i]);

  if(element->attributes)
    RAPTOR_FREE(raptor_qname_array, element->attributes);

  if(element->content_cdata_sb)
    raptor_free_stringbuffer(element->content_cdata_sb);

  if(element->base_uri)
    raptor_free_uri(element->base_uri);

  if(element->xml_language)
    RAPTOR_FREE(char*, element->xml_language);

  raptor_free_qname(element->name);

  if(element->declared_nspaces)
    raptor_free_sequence(element->declared_nspaces);

  RAPTOR_FREE(raptor_element, element);
}
Exemple #9
0
/*
 * raptor_serializers_finish - delete all the registered serializers
 */
void
raptor_serializers_finish(raptor_world* world)
{
  if(world->serializers) {
    raptor_free_sequence(world->serializers);
    world->serializers = NULL;
  }
}
Exemple #10
0
void
rasqal_finish_result_formats(rasqal_world* world)
{
  if(world->query_results_formats) {
    raptor_free_sequence(world->query_results_formats);
    world->query_results_formats = NULL;
  }
}
Exemple #11
0
/*
 * rasqal_delete_query_language_factories - helper function to delete all the registered query language factories
 */
static void
rasqal_delete_query_language_factories(rasqal_world *world)
{
  if(world->query_languages) {
    raptor_free_sequence(world->query_languages);
    world->query_languages = NULL;
  }
}
Exemple #12
0
/*
 * rasqal_free_update_operation:
 * @update: update operation
 *
 * INTERNAL - Destructor - Free update operation
 *
 */
void
rasqal_free_update_operation(rasqal_update_operation *update)
{
  if(!update)
    return;
  
  if(update->graph_uri)
    raptor_free_uri(update->graph_uri);
  if(update->document_uri)
    raptor_free_uri(update->document_uri);
  if(update->insert_templates)
    raptor_free_sequence(update->insert_templates);
  if(update->delete_templates)
    raptor_free_sequence(update->delete_templates);
  if(update->where)
    rasqal_free_graph_pattern(update->where);

  RASQAL_FREE(update_operation, update);
}
static void
raptor_free_avltree(raptor_avltree* tree)
{
  if(!tree)
    return;
  
  if(tree->seq)
    raptor_free_sequence(tree->seq);
  RASQAL_FREE(avltree, tree);
}
Exemple #14
0
/**
 * rasqal_free_rowsource:
 * @rowsource: rowsource object
 *
 * INTERNAL - Destructor - destroy an rowsource.
 **/
void
rasqal_free_rowsource(rasqal_rowsource *rowsource)
{
    if(!rowsource)
        return;

    if(rowsource->handler->finish)
        rowsource->handler->finish(rowsource, rowsource->user_data);

    if(rowsource->vars_table)
        rasqal_free_variables_table(rowsource->vars_table);

    if(rowsource->variables_sequence)
        raptor_free_sequence(rowsource->variables_sequence);

    if(rowsource->rows_sequence)
        raptor_free_sequence(rowsource->rows_sequence);

    RASQAL_FREE(rasqal_rowsource, rowsource);
}
Exemple #15
0
/**
 * librdf_finish_serializer:
 * @world: redland world object
 *
 * INTERNAL - Terminate the serializer module.
 *
 **/
void
librdf_finish_serializer(librdf_world *world) 
{
  if(world->serializers) {
    raptor_free_sequence(world->serializers);
    world->serializers=NULL;
  }
#ifdef HAVE_RAPTOR_RDF_SERIALIZER
  librdf_serializer_raptor_destructor();
#endif
}
/*
 * rasqal_free_projection:
 * @projection: #rasqal_projection object
 *
 * INTERNAL - Free a projection object.
 * 
 **/
void
rasqal_free_projection(rasqal_projection* projection)
{
  if(!projection)
    return;
  
  if(projection->variables)
    raptor_free_sequence(projection->variables);
  
  RASQAL_FREE(rasqal_projection, projection);
}
Exemple #17
0
/**
 * librdf_parser_raptor_terminate:
 * @context: context
 *
 * Terminate the raptor RDF parser.
 *
 **/
static void
librdf_parser_raptor_terminate(void *context)
{
  librdf_parser_raptor_context* pcontext=(librdf_parser_raptor_context*)context;

  librdf_raptor_free_bnode_hash(pcontext->parser->world);
  
  if(pcontext->stream_context)
    librdf_parser_raptor_serialise_finished(pcontext->stream_context);

  if(pcontext->www)
    raptor_free_www(pcontext->www);

  if(pcontext->rdf_parser)
    raptor_free_parser(pcontext->rdf_parser);

  if(pcontext->nspace_prefixes)
    raptor_free_sequence(pcontext->nspace_prefixes);
  if(pcontext->nspace_uris)
    raptor_free_sequence(pcontext->nspace_uris);
}
Exemple #18
0
void
rasqal_free_formula(rasqal_formula* formula)
{
  if(!formula)
    return;
  
  if(formula->triples)
    raptor_free_sequence(formula->triples);
  if(formula->value)
    rasqal_free_literal(formula->value);
  RASQAL_FREE(rasqal_formula, formula);
}
Exemple #19
0
/**
 * rasqal_free_variables_table:
 * @vt: rasqal variables table
 *
 * Destructor - destroy a new variables table
 */
void
rasqal_free_variables_table(rasqal_variables_table* vt)
{
  if(!vt)
    return;

  if(--vt->usage)
    return;
  
  if(vt->variables)
    RASQAL_FREE(vararray, vt->variables);

  if(vt->anon_variables_sequence)
    raptor_free_sequence(vt->anon_variables_sequence);

  if(vt->variables_sequence)
    raptor_free_sequence(vt->variables_sequence);

  if(vt->variable_names)
    RASQAL_FREE(cstrings, vt->variable_names);

  RASQAL_FREE(rasqal_variables_table, vt);
}
Exemple #20
0
void
raptor_free_abbrev_subject(raptor_abbrev_subject* subject) 
{
  RAPTOR_ASSERT_OBJECT_POINTER_RETURN(subject, raptor_abbrev_subject);
  
  if(subject->node)
    raptor_free_abbrev_node(subject->node);
  
  if(subject->node_type)
    raptor_free_abbrev_node(subject->node_type);
  
  if(subject->properties)
    raptor_free_avltree(subject->properties);
  
  if(subject->list_items)
    raptor_free_sequence(subject->list_items);
  
  RAPTOR_FREE(raptor_subject, subject);
}
Exemple #21
0
void
raptor_free_rss_item(raptor_rss_item* item)
{
  int i;
  for(i = 0; i< RAPTOR_RSS_FIELDS_SIZE; i++) {
    if(item->fields[i])
      raptor_rss_field_free(item->fields[i]);
  }
  if(item->blocks) 
    raptor_free_rss_block(item->blocks);
  if(item->uri)
    raptor_free_uri(item->uri);
  if(item->term)
    raptor_free_term(item->term);
  if(item->triples)
    raptor_free_sequence(item->triples);

  RAPTOR_FREE(raptor_rss_item, item);
}
Exemple #22
0
/**
 * rasqal_free_service:
 * @svc: #rasqal_service object
 * 
 * Destructor - destroy a #rasqal_service object.
 **/
void
rasqal_free_service(rasqal_service* svc)
{
  if(!svc)
    return;
  
  if(svc->service_uri)
    raptor_free_uri(svc->service_uri);

  if(svc->query_string)
    RASQAL_FREE(cstring, svc->query_string);

  if(svc->data_graphs)
    raptor_free_sequence(svc->data_graphs);
  
  rasqal_service_set_www(svc, NULL);

  RASQAL_FREE(rasqal_service, svc);
}
Exemple #23
0
/**
 * rasqal_free_query_results:
 * @query_results: #rasqal_query_results object
 *
 * Destructor - destroy a rasqal_query_results.
 *
 **/
void
rasqal_free_query_results(rasqal_query_results* query_results)
{
  rasqal_query* query;

  if(!query_results)
    return;

  query = query_results->query;

  if(query_results->executed) {
    if(query_results->execution_factory->execute_finish) {
      rasqal_engine_error execution_error = RASQAL_ENGINE_OK;

      query_results->execution_factory->execute_finish(query_results->execution_data, &execution_error);
      /* ignoring failure of execute_finish */
    }
  }

  if(query_results->execution_data)
    RASQAL_FREE(rasqal_engine_execution_data, query_results->execution_data);

  if(query_results->row)
    rasqal_free_row(query_results->row);

  if(query_results->results_sequence)
    raptor_free_sequence(query_results->results_sequence);

  /* free terms owned by static query_results->result_triple */
  raptor_free_statement(&query_results->result_triple);

  if(query_results->triple)
    rasqal_free_triple(query_results->triple);

  if(query_results->vars_table)
    rasqal_free_variables_table(query_results->vars_table);

  if(query)
    rasqal_query_remove_query_result(query, query_results);

  RASQAL_FREE(rasqal_query_results, query_results);
}
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;
}
Exemple #25
0
void
raptor_free_abbrev_subject(raptor_abbrev_subject* subject) 
{
  if(subject) {
    if(subject->node)
      raptor_free_abbrev_node(subject->node);
    
    if(subject->node_type)
      raptor_free_abbrev_node(subject->node_type);
    
    if(subject->properties)
      raptor_free_avltree(subject->properties);

    if(subject->list_items)
      raptor_free_sequence(subject->list_items);

    RAPTOR_FREE(raptor_subject, subject);
  }
  
}
Exemple #26
0
void
manifest_free_test_result(manifest_test_result* result)
{
  int i;

  if(!result)
    return;

  if(result->details)
    free(result->details);

  if(result->log)
    free(result->log);

  for(i = 0; i < STATE_LAST; i++) {
    if(result->states[i])
      raptor_free_sequence(result->states[i]);
  }

  free(result);
}
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 int
rasqal_groupby_rowsource_finish(rasqal_rowsource* rowsource, void *user_data)
{
  rasqal_groupby_rowsource_context* con;
  con = (rasqal_groupby_rowsource_context*)user_data;

  if(con->rowsource)
    rasqal_free_rowsource(con->rowsource);
  
  if(con->expr_seq)
    raptor_free_sequence(con->expr_seq);
  
  if(con->tree)
    raptor_free_avltree(con->tree);
  
  if(con->group_iterator)
    raptor_free_avltree_iterator(con->group_iterator);

  RASQAL_FREE(rasqal_groupby_rowsource_context, con);

  return 0;
}
Exemple #29
0
static int
rasqal_rowsource_sparql_xml_finish(rasqal_rowsource* rowsource, void *user_data)
{
  rasqal_rowsource_sparql_xml_context* con;

  con=(rasqal_rowsource_sparql_xml_context*)user_data;

  if(con->base_uri)
    raptor_free_uri(con->base_uri);

  if(con->sax2)
    raptor_free_sax2(con->sax2);

  if(con->results_sequence)
    raptor_free_sequence(con->results_sequence);

  if(con->vars_table)
    rasqal_free_variables_table(con->vars_table);

  RASQAL_FREE(rasqal_rowsource_sparql_xml_context, con);

  return 0;
}
Exemple #30
0
void
slv2_values_free(SLV2Values list)
{
	if (list)
		raptor_free_sequence(list);
}