[bdbxml] Beginners question with Perl

Peter Hickman <[email protected]>
Newsgroups gmane.comp.db.dbxml.general
Message-ID <[email protected]>
I am trying to get the Perl interface up and running and have modified 
the simpleQuery.pl code from the distribution to try and get it to 
process a query that works when I use the dbxml utility. I am running 
the code in the same directory as the data and this is the error I get.

[Bible]$ ./simpleQuery.pl
Exercising query 'for $collection in 
collection("/Users/peterhickman/Work/Bible/books.dbxml")/collection 
return <link class="collectiontitle" title="{$collection/@title/text()}" 
idref="{$collection/@id/text()}" />'
[1] Error: XML Indexer: Fatal Parse error in document at line, 2, char 
53. Parser message: An exception occurred! Type:RuntimeException, 
Message:Could not open external entity '{0}' in ./simpleQuery.pl, line 14
[Bible]$

Line 14 is the "my $results = $theMgr->query($query);" line in doQuery. 
I have done a ref() on $theMgr and it appears to be an object of the 
correct type, XmlManager. I have looked in /tmp and there are several 
__db.00{1-5} files and a massive, unreadable, log.0000000001 file. Any 
ideas about what the error is supposed to convey or what I might do to 
investigate it further?

Thanks.

#!/usr/bin/perl -w

use strict;
use warnings;

use Sleepycat::DbXml 'simple';

sub doQuery($$) {
    my ( $theMgr, $query ) = @_;

    eval {
        print "Exercising query '$query'\n";

        my $results = $theMgr->query($query);
        my $value;
        while ( $results->next($value) ) {
            print "$value\n";
        }

        print $results->size() . " objects returned for expression 
'$query'\n";
    };

    if ( my $e = catch std::exception ) {
        warn "[1] " . $e->what() . "\n";
        exit(-1);
    }
    elsif ($@) {
        warn "[2] $@ \n";
        exit(-1);
    }
}

sub create_manager {
    my ($path2DbEnv) = @_;

    my $env = new DbEnv(0);
    $env->set_cachesize( 0, 64 * 1024, 1 );
    $env->open( $path2DbEnv, Db::DB_INIT_MPOOL | Db::DB_CREATE | 
Db::DB_INIT_LOCK | Db::DB_INIT_LOG | Db::DB_INIT_TXN );
    my $theMgr = new XmlManager($env);

    if ( my $e = catch std::exception ) {
        warn "Create Manager failed\n";
        warn $e->what() . "\n";
        exit(-1);
    }
    elsif ($@) {
        warn "Create Manager failed\n";
        warn $@;
        exit(-1);
    }

    return $theMgr;
}

sub create_container {
    my ( $theMgr, $theContainer ) = @_;

    my $containerTxn = $theMgr->createTransaction();
    my $container = $theMgr->openContainer( $containerTxn, $theContainer );
    $containerTxn->commit();

    if ( my $e = catch std::exception ) {
        warn "Create Container failed\n";
        warn $e->what() . "\n";
        exit(-1);
    }
    elsif ($@) {
        warn "Create Container failed\n";
        warn $@;
        exit(-1);
    }

    return $container;
}

my $path2DbEnv   = "/tmp/";
my $theContainer = "/Users/peterhickman/Work/Bible/books.dbxml";
my $theQuery     = 'for $collection in 
collection("/Users/peterhickman/Work/Bible/books.dbxml")/collection 
return <link class="collectiontitle" title="{$collection/@title/text()}" 
idref="{$collection/@id/text()}" />';

my $theMgr = create_manager($path2DbEnv);
my $container = create_container( $theMgr, $theContainer );
doQuery( $theMgr, $theQuery );



------------------------------------------
To remove yourself from this list, send an
email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.