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

Dave Beckett dave.beckett at bristol.ac.uk
Fri Aug 13 10:33:17 BST 2004


On Fri, 13 Aug 2004 05:02:30 +0200, René Puls <kianga at gmail.com> wrote:

...

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

Mea culpa.

The example code in the documentation for the Query class in perl is
wrong (it is correct in the QueryResults example).

What I had:
	for (my $i=0; $i < $results->count(); $i++) {
correct:
	for (my $i=0; $i < $results->bindings_count(); $i++) {

There are two counts managed by the results object.
  $results->count() is the number of sets of variable bindings seen.
  $results->bindings_count is the number of variable bindings
    - this is constant once $results is created.

I made the change above and get the correct answers:

results, count=1
x => [http://foo/4]
results, count=2
x => [http://foo/3]
results, count=3
x => [http://foo/2]
results, count=4
x => [http://foo/1]

Things go wrong at result #2, when an attempt to fetch variable #2
doesn't work, i.e $results->binding_name(2) is undef since there is
only one variable '?x'.

If you are a Perl-head, you are probably thinking QueryResults could
be made into a perl tied array and then all you'd need were
 while(my $result=$query->execute)
but there are issues with only allowing forward movment in the array,
and it should also be used with redland streams and iterators.  I'm
not currently working on this.

(This approach is used in the python API).

Dave



More information about the redland-dev mailing list