[redland-dev] Perl Redland::Query returns strange results

René Puls kianga at gmail.com
Fri Aug 13 04:02:30 BST 2004


Hi,

the subject isn't very specific, but it's the best I can describe it. :-)

Here is an example script:

--- cut here ---

#!/usr/bin/perl -w

use RDF::Redland;

my $storage=new RDF::Redland::Storage("hashes", "test", 
                                      "new='yes',hash-type='memory'");
my $model=new RDF::Redland::Model($storage, "");
my $parser=new RDF::Redland::Parser("ntriples");

my $string = q{
<http://foo/1> <http://rdf#type> <http://example.com/someType> .
<http://foo/2> <http://rdf#type> <http://example.com/someType> .
<http://foo/3> <http://rdf#type> <http://example.com/someType> .
<http://foo/4> <http://rdf#type> <http://example.com/someType> .
};

my $uri = new RDF::Redland::URI("http://foo/");
$parser->parse_string_into_model($string, $uri, $model);

my $query=new RDF::Redland::Query(q{
SELECT ?x 
WHERE (?x, <http://rdf#type>, <http://example.com/someType>)
});

my $results = $model->query_execute($query);
#my $results = $query->execute($model);

while(!$results->finished) {
	print "results, count=" . $results->count() . "\n";
	for (my $i=0; $i < $results->count(); $i++) {
		my $name=$results->binding_name($i);
		my $value=$results->binding_value($i);
		print "$name => " . $value->as_string . "\n";
		# ... do something with the results
	}
	$results->next_result;
}

--- cut here ---

... and this is the output:

results, count=1
x => [http://foo/4]
results, count=2
x => [http://foo/3]
Use of uninitialized value in concatenation (.) or string at query.pl line 33.
Can't call method "as_string" on an undefined value at query.pl line 33.

(How can the bindings count be 2 when I have only one variable in the query?)

When I run the same query on the same data with the roquet tool, I get
the expected results:

$ roqet -q query.rdql
result: [x=uri<http://foo/1>]
result: [x=uri<http://foo/2>]
result: [x=uri<http://foo/3>]
result: [x=uri<http://foo/4>]

I can reproduce this both on OS X 10.3.5 and on OpenBSD 3.5 with the latest
Redland release 0.9.18 and bindings 0.9.18.1.

René



More information about the redland-dev mailing list