[redland-dev] Problem with repeat queries
Richard Newman
r.newman at reading.ac.uk
Mon Sep 6 18:12:09 BST 2004
Hi,
I'm having a little confusion implementing refreshing on queries
(i.e. running them again). I think I've narrowed it down to an example
case (see below). This is running against 0.9.18 on Mac OS X 10.3.5,
latest GCC.
Essentially, running a query a second time returns NULL, even
immediately after the first's success, or before using the results, and
regardless of whether the results have been freed. Also,
librdf_new_query_from_query throws up an error:
-----
librdf fatal - rdf_query.c:254:librdf_new_query_from_query: fatal
error: clone not implemented for query factor
Abort trap
-----
(the 'y' on 'factory' is in the code, but not printed!)
So it seems that to do repeat queries it is necessary to construct a
new query object from strings each time.
My questions, then:
1. Have I found a bug?
2. If not, could you please advise how best to work around this
behaviour? What am I missing?
3. Alternatively, is there a way to 'refresh' a query result object?
(IIRC it does keep track of its query...?)
3. Bonus question: is there any news on implementing optional query
parameters, in RDQL or otherwise? They'd be mighty handy!
Thanks in advance for any help offered.
Kind regards,
Richard Newman
School of Systems Engineering
University of Reading
-- EXAMPLE --------
-- Compile with "gcc -o main -x c -I(include dir) -L(lib dir) -lrdf
main.c" ---
#include <redland.h>
#include <stdio.h>
#define QUERY "SELECT ?first WHERE \
(?first, rdf:type, rss:item) USING \
rdf FOR <http://www.w3.org/1999/02/22-rdf-syntax-ns#>, \
rss FOR <http://purl.org/rss/1.0/item>"
int main(int argc, char **argv) {
librdf_statement *s = NULL;
librdf_world *world = NULL;
librdf_storage *storage = NULL;
librdf_model *model = NULL;
librdf_query *query = NULL;
librdf_query *secondQuery = NULL;
librdf_query_results *results = NULL;
// Setup.
world = librdf_new_world();
librdf_world_open(world);
librdf_init_statement(world);
storage = librdf_new_storage(world, "memory", "Red", NULL);
model = librdf_new_model(world, storage, NULL);
// Add some statements.
s = librdf_new_statement_from_nodes(world,
librdf_new_node_from_uri_string(world,
"http://example.com/item1"),
librdf_new_node_from_uri_string(world,
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
librdf_new_node_from_uri_string(world,
"http://purl.org/rss/1.0/item"));
librdf_model_add_statement(model, s);
librdf_free_statement(s);
// Query.
query = librdf_new_query(world, "rdql", NULL, QUERY);
if (query) {
// EXECUTE FIRST TIME.
results = librdf_model_query_execute(model, query);
}
if (results) {
printf("Results returned.\n");
// SAME BEHAVIOUR WITH OR WITHOUT NEXT LINE, SO THERE'S NO HIDDEN
'FREE'.
librdf_free_query_results(results);
// EXECUTE SECOND TIME --- FAILS (returns NULL).
results = librdf_model_query_execute(model, query);
results ? printf("Success!\n") : printf("Failure!\n");
// TRY DUPLICATING QUERY... FAILURE.
secondQuery = librdf_new_query_from_query(query);
}
// Don't bother clearing up.
return 0;
}
More information about the redland-dev
mailing list