Beispiel #1
0
/**
 * rasqal_query_results_read:
 * @iostr: #raptor_iostream to read the query from
 * @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 read (or NULL for default)
 * @base_uri: #raptor_uri base URI of the input format
 *
 * Read the query results from an iostream in a format.
 * 
 * This uses the #rasqal_query_results_formatter class
 * and the rasqal_query_results_formatter_read() method
 * to perform the formatting. 
 *
 * See rasqal_world_get_query_results_format_description() for
 * obtaining the supported format URIs at run time.
 *
 * Return value: non-0 on failure
 **/
int
rasqal_query_results_read(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_read(results->world, iostr, formatter,
                                               results, base_uri);

  rasqal_free_query_results_formatter(formatter);
  return status;
}
Beispiel #2
0
/**
 * rasqal_new_service:
 * @world: rasqal_world object
 * @service_uri: sparql protocol service URI
 * @query_string: query string (or NULL)
 * @data_graphs: sequence of #rasqal_data_graph graphs for service
 *
 * Constructor - create a new rasqal protocol service object.
 *
 * Create a structure to execute a sparql protocol service at
 * @service_uri running the query @query_string and returning
 * a sparql result set.
 *
 * All arguments are copied by the service object
 *
 * Return value: a new #rasqal_query object or NULL on failure
 */
rasqal_service*
rasqal_new_service(rasqal_world* world, raptor_uri* service_uri,
                   const char* query_string,
                   raptor_sequence* data_graphs)
{
  rasqal_service* svc;
  size_t len = 0;
  
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, NULL);
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(service_uri, raptor_uri, NULL);
  
  svc = (rasqal_service*)RASQAL_CALLOC(rasqal_service, 1, sizeof(*svc));
  if(!svc)
    return NULL;
  
  svc->world = world;
  svc->service_uri = raptor_uri_copy(service_uri);

  if(query_string) {
    len = strlen(query_string);
    svc->query_string = RASQAL_MALLOC(cstring, len + 1);
    if(!svc->query_string) {
      rasqal_free_service(svc);
      return NULL;
    }
  
    memcpy(svc->query_string, query_string, len + 1);
  }
  svc->query_string_len = len;

  if(data_graphs) {
    int i;
    rasqal_data_graph* dg;
    
#ifdef HAVE_RAPTOR2_API
    svc->data_graphs = raptor_new_sequence((raptor_data_free_handler)rasqal_free_data_graph,
                                           NULL);

#else
    svc->data_graphs = raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_data_graph,
                                           NULL);
#endif
    if(!svc->data_graphs) {
      rasqal_free_service(svc);
      return NULL;
    }

    for(i = 0;
        (dg = (rasqal_data_graph*)raptor_sequence_get_at(data_graphs, i));
        i++) {
      raptor_sequence_push(svc->data_graphs,
                           rasqal_new_data_graph_from_data_graph(dg));
    }
  }
  
  return svc;
}
Beispiel #3
0
/**
 * rasqal_query_results_formatter_write:
 * @iostr: #raptor_iostream to write the query to
 * @formatter: #rasqal_query_results_formatter object
 * @results: #rasqal_query_results query results format
 * @base_uri: #raptor_uri base URI of the output format (or NULL)
 *
 * Write the query results using the given formatter to an iostream
 *
 * Note that after calling this method, the query results will be
 * empty and rasqal_query_results_finished() will return true (non-0)
 * 
 * See rasqal_query_results_formats_enumerate() to get the
 * list of syntax URIs and their description. 
 *
 * Return value: non-0 on failure
 **/
int
rasqal_query_results_formatter_write(raptor_iostream *iostr,
                                     rasqal_query_results_formatter* formatter,
                                     rasqal_query_results* results,
                                     raptor_uri *base_uri)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(iostr, raptor_iostream, 1);
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(formatter, rasqal_query_results_formatter, 1);
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(results, rasqal_query_results, 1);

  if(!formatter->factory->writer)
     return 1;
  return formatter->factory->writer(iostr, results, base_uri);
}
Beispiel #4
0
/**
 * rasqal_new_data_graph_from_uri:
 * @world: rasqal_world object
 * @uri: source URI
 * @name_uri: name of graph (or NULL)
 * @flags: %RASQAL_DATA_GRAPH_NAMED or %RASQAL_DATA_GRAPH_BACKGROUND
 * @format_type: MIME Type of data format at @uri (or NULL)
 * @format_name: Raptor parser Name of data format at @uri (or NULL)
 * @format_uri: URI of data format at @uri (or NULL)
 * 
 * Constructor - create a new #rasqal_data_graph.
 * 
 * The name_uri is only used when the flags are %RASQAL_DATA_GRAPH_NAMED.
 * 
 * Return value: a new #rasqal_data_graph or NULL on failure.
 **/
rasqal_data_graph*
rasqal_new_data_graph_from_uri(rasqal_world* world, raptor_uri* uri,
                               raptor_uri* name_uri, int flags,
                               const char* format_type,
                               const char* format_name,
                               raptor_uri* format_uri)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, NULL);
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(uri, raptor_uri, NULL);

  return rasqal_new_data_graph_common(world,
                                      uri,
                                      /* iostr */ NULL, /* base URI */ NULL,
                                      name_uri, flags,
                                      format_type, format_name, format_uri);
}
Beispiel #5
0
static unsigned char*
rasqal_raptor_get_genid(rasqal_world* world, const unsigned char* base,
                        int counter)
{
    int tmpcounter;
    size_t length;
    unsigned char *buffer;

    RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, NULL);

    /* This is read-only and thread safe */
    if(counter < 0)
        counter= world->genid_counter++;

    length = strlen(RASQAL_GOOD_CAST(const char*, base)) + 2;  /* base + (int) + "\0" */
    tmpcounter = counter;
    while(tmpcounter /= 10)
        length++;

    buffer = RASQAL_MALLOC(unsigned char*, length);
    if(!buffer)
        return NULL;

    sprintf(RASQAL_GOOD_CAST(char*, buffer), "%s%d", base, counter);
    return buffer;
}
/*
 * rasqal_projection_get_variables_sequence:
 * @projection: #rasqal_projection object
 *
 * INTERNAL - Get variables inside a projection
 * 
 **/
raptor_sequence*
rasqal_projection_get_variables_sequence(rasqal_projection* projection)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(projection, rasqal_projection, NULL);
  
  return projection->variables;
}
Beispiel #7
0
/**
 * rasqal_language_name_check:
 * @world: rasqal_world object
 * @name: the query language name
 *
 * Check name of a query language.
 *
 * Return value: non 0 if name is a known query language
 */
int
rasqal_language_name_check(rasqal_world* world, const char *name)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, 0);

  return (rasqal_get_query_language_factory(world, name, NULL) != NULL);
}
Beispiel #8
0
/**
 * rasqal_languages_enumerate:
 * @world: rasqal_world object
 * @counter: index into the list of syntaxes
 * @name: pointer to store the name of the syntax (or NULL)
 * @label: pointer to store syntax readable label (or NULL)
 * @uri_string: pointer to store syntax URI string (or NULL)
 *
 * @deprecated: Use rasqal_world_get_query_language_description() instead.
 *
 * Get information on query languages.
 * 
 * Return value: non 0 on failure of if counter is out of range
 **/
int
rasqal_languages_enumerate(rasqal_world *world,
                           unsigned int counter,
                           const char **name, const char **label,
                           const unsigned char **uri_string)
{
  rasqal_query_language_factory *factory;

  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, 1);
  if(!name && !label && !uri_string)
    return 1;
  
  /* for compatibility with old API that does not call this - FIXME Remove V2 */
  rasqal_world_open(world);
  
  factory = (rasqal_query_language_factory*)raptor_sequence_get_at(world->query_languages, counter);
  if(!factory)
    return 1;

  if(name)
    *name = factory->desc.names[0];

  if(label)
    *label = factory->desc.label;

  if(uri_string && factory->desc.uri_strings)
    *uri_string = RASQAL_GOOD_CAST(const unsigned char*, factory->desc.uri_strings[0]);

  return 0;
}
Beispiel #9
0
/**
 * rasqal_new_query_results_formatter2:
 * @world: rasqal_world object
 * @name: the query results format name (or NULL)
 * @mime_type: the query results format mime type (or NULL)
 * @format_uri: #raptor_uri query results format uri (or NULL)
 *
 * Constructor - create a new rasqal_query_results_formatter for an identified format.
 *
 * A query results format can be found by name, mime type or URI, all
 * of which are optional.  If multiple fields are given, the first
 * match is given that matches the name, URI, mime_type in that
 * order.  The default query results format will be used if all are
 * format identifying fields are NULL.
 *
 * rasqal_query_results_formats_enumerate() returns information on
 * the known query results names, labels, mime types and URIs.
 *
 * Return value: a new #rasqal_query_results_formatter object or NULL on failure
 */
rasqal_query_results_formatter*
rasqal_new_query_results_formatter2(rasqal_world* world,
                                    const char *name, 
                                    const char *mime_type,
                                    raptor_uri* format_uri)
{
  rasqal_query_results_format_factory* factory;
  rasqal_query_results_formatter* formatter;
  int flags = 0;

  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, NULL);

  factory = rasqal_get_query_results_formatter_factory(world, name, 
                                                       format_uri, mime_type,
                                                       flags);
  if(!factory)
    return NULL;

  formatter = (rasqal_query_results_formatter*)RASQAL_CALLOC(rasqal_query_results_formatter, 1, sizeof(*formatter));
  if(!formatter)
    return NULL;

  formatter->factory = factory;

  formatter->mime_type = factory->mime_type;
  
  return formatter;
}
Beispiel #10
0
/**
 * rasqal_triple_get_origin:
 * @t: The triple object. 
 * 
 * Get the origin field of a #rasqal_triple.
 * 
 * Return value: The triple origin or NULL.
 **/
rasqal_literal*
rasqal_triple_get_origin(rasqal_triple* t)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(t, rasqal_triple, NULL);

  return t->origin;
}
Beispiel #11
0
/**
 * rasqal_query_results_get_binding_name:
 * @query_results: #rasqal_query_results query_results
 * @offset: offset of binding name into array of known names
 *
 * Get binding name for the current result.
 * 
 * Return value: a pointer to a shared copy of the binding name or NULL on failure
 **/
const unsigned char*
rasqal_query_results_get_binding_name(rasqal_query_results* query_results, 
                                      int offset)
{
  rasqal_variable* v;

  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, NULL);
  
  if(!rasqal_query_results_is_bindings(query_results)) 
    return NULL;
  
  if(query_results->query) {
    /* If there is a query, take variable names from the order in the
     * projection not the order inserted into the variables table.
     */
    v = (rasqal_variable*)raptor_sequence_get_at(query_results->query->selects,
                                                 offset);
  } else 
    v = rasqal_variables_table_get(query_results->vars_table, offset);
  
  if(!v)
    return NULL;
  
  return v->name;
}
Beispiel #12
0
/**
 * rasqal_query_results_get_type:
 * @query_results: #rasqal_query_results object
 *
 * Get query results type
 * 
 * Return value: non-0 if true
 **/
rasqal_query_results_type
rasqal_query_results_get_type(rasqal_query_results* query_results)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, (rasqal_query_results_type)0);

  return query_results->type;
}
Beispiel #13
0
/**
 * rasqal_query_results_is_bindings:
 * @query_results: #rasqal_query_results object
 *
 * Test if rasqal_query_results is variable bindings format.
 * 
 * Return value: non-0 if true
 **/
int
rasqal_query_results_is_bindings(rasqal_query_results* query_results)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, 0);

  return (query_results->type == RASQAL_QUERY_RESULTS_BINDINGS);
}
Beispiel #14
0
/**
 * rasqal_query_results_formatter_get_mime_type:
 * @formatter: #rasqal_query_results_formatter object
 * 
 * Get the mime type of the syntax being formatted.
 * 
 * Return value: a shared mime type string
 **/
const char*
rasqal_query_results_formatter_get_mime_type(rasqal_query_results_formatter *formatter)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(formatter, rasqal_query_results_formatter, NULL);

  return formatter->mime_type;
}
Beispiel #15
0
/**
 * rasqal_query_results_get_query:
 * @query_results: #rasqal_query_results object
 *
 * Get thq query associated with this query result
 * 
 * Return value: shared pointer to query object
 **/
rasqal_query*
rasqal_query_results_get_query(rasqal_query_results* query_results)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, NULL);

  return query_results->query;
}
Beispiel #16
0
/**
 * rasqal_query_results_is_graph:
 * @query_results: #rasqal_query_results object
 *
 * Test if rasqal_query_results is RDF graph format.
 * 
 * Return value: non-0 if true
 **/
int
rasqal_query_results_is_graph(rasqal_query_results* query_results)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, 0);

  return (query_results->type == RASQAL_QUERY_RESULTS_GRAPH);
}
Beispiel #17
0
rasqal_variables_table*
rasqal_query_results_get_variables_table(rasqal_query_results* query_results)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, NULL);

  return query_results->vars_table;
}
Beispiel #18
0
/**
 * rasqal_world_set_default_generate_bnodeid_parameters:
 * @world: #rasqal_world object
 * @prefix: prefix string
 * @base: integer base identifier
 *
 * Set default bnodeid generation parameters
 *
 * Sets the parameters for the default algorithm used to generate
 * blank node IDs.  The default algorithm uses both @prefix and @base
 * to generate a new identifier.  The exact identifier generated is
 * not guaranteed to be a strict concatenation of @prefix and @base
 * but will use both parts.
 *
 * For finer control of the generated identifiers, use
 * rasqal_world_set_generate_bnodeid_handler()
 *
 * If prefix is NULL, the default prefix is used (currently "bnodeid")
 * If base is less than 1, it is initialised to 1.
 *
 * Return value: non-0 on failure
 **/
int
rasqal_world_set_default_generate_bnodeid_parameters(rasqal_world* world, 
                                                     char *prefix, int base)
{
  char *prefix_copy = NULL;
  size_t length = 0;

  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, 1);

  if(--base < 0)
    base = 0;

  if(prefix) {
    length = strlen(prefix);
    
    prefix_copy = (char*)RASQAL_MALLOC(cstring, length + 1);
    if(!prefix_copy)
      return 1;
    memcpy(prefix_copy, prefix, length + 1);
  }
  
  if(world->default_generate_bnodeid_handler_prefix)
    RASQAL_FREE(cstring, world->default_generate_bnodeid_handler_prefix);

  world->default_generate_bnodeid_handler_prefix = prefix_copy;
  world->default_generate_bnodeid_handler_prefix_length = length;
  world->default_generate_bnodeid_handler_base = base;

  return 0;
}
Beispiel #19
0
/**
 * rasqal_query_results_is_syntax:
 * @query_results: #rasqal_query_results object
 *
 * Test if the rasqal_query_results is a syntax.
 *
 * Many of the query results may be formatted as a syntax using the
 * #rasqal_query_formatter class however this function returns true
 * if a syntax result was specifically requested.
 * 
 * Return value: non-0 if true
 **/
int
rasqal_query_results_is_syntax(rasqal_query_results* query_results)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, 0);

  return (query_results->type == RASQAL_QUERY_RESULTS_SYNTAX);
}
Beispiel #20
0
/**
 * rasqal_new_solution_modifier:
 * @query: rasqal query
 * @order_conditions: sequence of order condition expressions (or NULL)
 * @group_conditions: sequence of group by condition expressions (or NULL)
 * @having_conditions: sequence of (group by ...) having condition expressions (or NULL)
 * @limit: result limit LIMIT (>=0) or <0 if not given
 * @offset: result offset OFFSET (>=0) or <0 if not given
 *
 * INTERNAL - Create a new solution modifier object.
 * 
 * Return value: a new #rasqal_solution_modifier object or NULL on failure
 **/
rasqal_solution_modifier*
rasqal_new_solution_modifier(rasqal_query* query,
                             raptor_sequence* order_conditions,
                             raptor_sequence* group_conditions,
                             raptor_sequence* having_conditions,
                             int limit,
                             int offset)
{
  rasqal_solution_modifier* sm;

  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query, rasqal_query, NULL);

  sm = (rasqal_solution_modifier*)RASQAL_CALLOC(rasqal_solution_modifier,
                                                1, sizeof(*sm));
  if(!sm)
    return NULL;

  sm->query = query;
  sm->order_conditions = order_conditions;
  sm->group_conditions = group_conditions;
  sm->having_conditions = having_conditions;
  sm->limit = limit;
  sm->offset = offset;

  return sm;
}
Beispiel #21
0
/**
 * rasqal_query_results_get_bindings:
 * @query_results: #rasqal_query_results query_results
 * @names: pointer to an array of binding names (or NULL)
 * @values: pointer to an array of binding value #rasqal_literal (or NULL)
 *
 * Get all binding names, values for current result.
 * 
 * If names is not NULL, it is set to the address of a shared array
 * of names of the bindings (an output parameter).  These names
 * are shared and must not be freed by the caller
 *
 * If values is not NULL, it is set to the address of a shared array
 * of #rasqal_literal* binding values.  These values are shaerd
 * and must not be freed by the caller.
 * 
 * Return value: non-0 if the assignment failed
 **/
int
rasqal_query_results_get_bindings(rasqal_query_results* query_results,
                                  const unsigned char ***names, 
                                  rasqal_literal ***values)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, 1);

  if(!rasqal_query_results_is_bindings(query_results))
    return 1;
  
  if(names)
    *names = rasqal_variables_table_get_names(query_results->vars_table);
  
  if(values) {
    rasqal_row* row;

    row = rasqal_query_results_get_current_row(query_results);
    if(row)
      *values = row->values;
    else
      query_results->finished = 1;
  }
    
  return 0;
}
Beispiel #22
0
/**
 * rasqal_query_results_is_boolean:
 * @query_results: #rasqal_query_results object
 *
 * Test if rasqal_query_results is boolean format.
 * 
 * Return value: non-0 if true
 **/
int
rasqal_query_results_is_boolean(rasqal_query_results* query_results)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, 0);

  return (query_results->type == RASQAL_QUERY_RESULTS_BOOLEAN);
}
/*
 * rasqal_projection_add_variable:
 * @projection: #rasqal_projection object
 * @var: #rasqal_variable variable
 *
 * INTERNAL - add a binding variable to the projection.
 *
 * Return value: non-0 on failure
 **/
int
rasqal_projection_add_variable(rasqal_projection* projection,
                               rasqal_variable* var)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(projection, rasqal_projection, 1);
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(var, rasqal_variable, 1);

  if(!projection->variables) {
    projection->variables = raptor_new_sequence((raptor_data_free_handler)rasqal_free_variable,
                                                (raptor_data_print_handler)rasqal_variable_print);
    if(!projection->variables)
      return 1;
  }

  var = rasqal_new_variable_from_variable(var);

  return raptor_sequence_push(projection->variables, (void*)var);
}
Beispiel #24
0
/**
 * rasqal_world_reset_now:
 * @world: world
 *
 * Internal - Mark current now value as invalid
 *
 * Intended to be run before starting a query so that the
 * value is recalculated.
 *
 * Return value: non-0 on failure
 */
int
rasqal_world_reset_now(rasqal_world* world)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, 1);

  world->now_set = 0;

  return 0;
}
Beispiel #25
0
/**
 * rasqal_new_query_results_formatter:
 * @world: rasqal_world object
 * @name: the query results format name (or NULL)
 * @format_uri: #raptor_uri query results format uri (or NULL)
 *
 * Constructor - create a new rasqal_query_results_formatter object by identified format.
 *
 * A query results format can be named or identified by a URI, both
 * of which are optional.  The default query results format will be used
 * if both are NULL.  rasqal_query_results_formats_enumerate() returns
 * information on the known query results names, labels and URIs.
 *
 * @Deprecated: Use rasqal_new_query_results_formatter2() with extra
 * mime_type arg.
 *
 * Return value: a new #rasqal_query_results_formatter object or NULL on failure
 */
rasqal_query_results_formatter*
rasqal_new_query_results_formatter(rasqal_world* world,
                                   const char *name, raptor_uri* format_uri)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, NULL);

  return rasqal_new_query_results_formatter2(world, 
                                             name, NULL, format_uri);
}
Beispiel #26
0
/**
 * rasqal_query_results_rewind:
 * @query_results: #rasqal_query_results query_results
 *
 * Rewind stored query results to start
 *
 * This requires rasqal_query_set_store_results() to be called before
 * query execution.
 * 
 * Return value: non-0 if rewinding is not available when results are not stored
 **/
int
rasqal_query_results_rewind(rasqal_query_results* query_results)
{
  int size;
  int limit = -1;
  int offset = -1;
  rasqal_query* query;
  
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, 1);

  if(!query_results->results_sequence)
    return 1;

  size = raptor_sequence_size(query_results->results_sequence);

  /* This may be NULL for a static query result */
  query = query_results->query;

  if(query) {
    /* If the query failed, it remains failed */
    if(query->failed)
      return 1;
    
    limit = rasqal_query_get_limit(query);
    offset = rasqal_query_get_offset(query);
  }
  
  /* reset to first result */
  query_results->finished = (size == 0);
  
  if(query && !limit)
    query_results->finished = 1;
  
  if(!query_results->finished) {
    /* Reset to first result, index-1 into sequence of results */
    query_results->result_count = 0;
    
    /* skip past any OFFSET */
    if(query && offset > 0) {
      query_results->result_count += offset;
      
      if(query_results->result_count >= size)
        query_results->finished = 1;
    }
    
  }

    
  if(query_results->finished)
    query_results->result_count = 0;
  else {
    if(query && query->constructs)
      rasqal_query_results_update_bindings(query_results);
  }

  return 0;
}
Beispiel #27
0
/**
 * rasqal_query_results_add_row:
 * @query_results: query results object
 * @row: query result row
 *
 * Add a query result row to the sequence of result rows
 *
 * Return value: non-0 on failure
 */
int
rasqal_query_results_add_row(rasqal_query_results* query_results,
                             rasqal_row* row)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, 1);
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(row, rasqal_row, 1);

  if(!query_results->results_sequence) {
    query_results->results_sequence = raptor_new_sequence((raptor_data_free_handler)rasqal_free_row, (raptor_data_print_handler)rasqal_row_print);
    if(!query_results->results_sequence)
      return 1;
    
    query_results->result_count = 0;
  }

  row->offset = raptor_sequence_size(query_results->results_sequence);

  return raptor_sequence_push(query_results->results_sequence, row);
}
Beispiel #28
0
/**
 * rasqal_world_set_generate_bnodeid_handler:
 * @world: #rasqal_world object
 * @user_data: user data pointer for callback
 * @handler: generate blank ID callback function
 *
 * Set the generate blank node ID handler function
 *
 * Sets the function to generate blank node IDs.
 * The handler is called with a pointer to the rasqal_world, the
 * @user_data pointer and a user_bnodeid which is the value of
 * a user-provided blank node identifier (may be NULL).
 * It can either be returned directly as the generated value when present or
 * modified.  The passed in value must be free()d if it is not used.
 *
 * If handler is NULL, the default method is used
 *
 * Return value: non-0 on failure
 **/
int
rasqal_world_set_generate_bnodeid_handler(rasqal_world* world,
                                          void *user_data,
                                          rasqal_generate_bnodeid_handler handler)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, 1);

  world->generate_bnodeid_handler_user_data = user_data;
  world->generate_bnodeid_handler = handler;

  return 0;  
}
Beispiel #29
0
/**
 * rasqal_query_results_formats_enumerate:
 * @world: rasqal_world object
 * @counter: index into the list of query result syntaxes
 * @name: pointer to store the name of the query result syntax (or NULL)
 * @label: pointer to store query result syntax readable label (or NULL)
 * @uri_string: pointer to store query result syntax URI string (or NULL)
 * @mime_type: pointer to store query result syntax mime type string (or NULL)
 * @flags: pointer to store query result syntax flags (or NULL)
 *
 * Get information on query result syntaxes.
 * 
 * The current list of format names/URI is given below however
 * the results of this function will always return the latest.
 *
 * SPARQL XML Results 2007-06-14 (default format when @counter is 0)
 * name '<literal>xml</literal>' with
 * URIs http://www.w3.org/TR/2006/WD-rdf-sparql-XMLres-20070614/ or
 * http://www.w3.org/2005/sparql-results#
 *
 * JSON name '<literal>json</literal>' and
 * URI http://www.w3.org/2001/sw/DataAccess/json-sparql/
 *
 * Table name '<literal>table</literal>' with no URI.
 *
 * All returned strings are shared and must be copied if needed to be
 * used dynamically.
 * 
 * Return value: non 0 on failure of if counter is out of range
 **/
int
rasqal_query_results_formats_enumerate(rasqal_world* world,
                                       unsigned int counter,
                                       const char **name,
                                       const char **label,
                                       const unsigned char **uri_string,
                                       const char **mime_type,
                                       int *flags)



{
  rasqal_query_results_format_factory *factory;
  int i;
  unsigned int real_counter;
  
  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, 1);

  real_counter = 0;
  for(i = 0; 1; i++) {
    factory = (rasqal_query_results_format_factory*)raptor_sequence_get_at(world->query_results_formats, i);
    if(!factory)
      break;

    if(factory->name) {
      if(real_counter == counter)
        break;
      real_counter++;
    }
  }

  if(!factory)
    return 1;

  if(name)
    *name = factory->name;
  if(label)
    *label = factory->label;
  if(uri_string)
    *uri_string = factory->uri_string;
  if(mime_type)
    *mime_type = factory->mime_type;
  if(flags) {
    *flags = 0;
    if(factory->reader)
      *flags |= RASQAL_QUERY_RESULTS_FORMAT_FLAG_READER;
    if(factory->writer)
      *flags |= RASQAL_QUERY_RESULTS_FORMAT_FLAG_WRITER;
  }
  
  return 0;
}
Beispiel #30
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;
}