On 8/19/16 9:56 AM, Tim Bunce wrote:
On Fri, Aug 19, 2016 at 09:30:32AM -0400, Nigel Horne wrote:
Ron,
I've started working on a DBD::XML driver, and the first pass is looking
good.  I'm doing this because of the demise of DBD::AnyData, and
DBD::AnyData2 isn't ready yet, so until it is I wanted XML support.

Before I go any further, is anyone else working on something similar or
is there something already out there?  I don't want to re-invent the
wheel.
It sounds vaguely like my
https://metacpan.org/release/DBIx-Admin-BackupRestore.
Excellent, thanks so much for the pointer.  I'll take a look and see.

Apart from one change I need to make in terms of column names, I'm pretty
much ready to start working on a 0.01 CPAN release.  It's read-only, but
that's all I need.  How do I set about requesting driver registration, or is
this mentioning enough?
Probably :)

But I wonder about the name. "DBD::XML" seems to be a bold name,
implying that it's _the_ DBI interface for data stored in XML files.
Of course the same kind of issue applies to many other drivers,
so it's not a major concern, but does seem worth dicussing.

I'm more than happy to entertain other names if you have any suggestions.

So, here's the example I've started with to get the code basic interface going and tested. The code I have works with this trivial example.

data/person.xml:

<?xml version="1.0" encoding="US-ASCII"?>
<table>
    <row id="1">
        <name>Nigel Horne</name>
        <email>n...@bandsman.co.uk</email>
    </row>
    <row id="2">
        <name>A N Other</name>
        <email>nob...@example.com</email>
    </row>
</table>

bin/xml:

#!/usr/bin/env perl

use warnings;
use strict;
use autodie qw(:all);

use Data::Dumper;

use FindBin qw($Bin);
use lib "$Bin/../lib";
use DBD::XML;

print "Test 1 - import from file\n";
my $dbh = DBI->connect('dbi:XML(RaiseError => 1):');
$dbh->func('person', 'XML', "$Bin/../data/person.xml", 'ad_import'); # to be replaced with xml_import once the driver has been registered

my $sth = $dbh->prepare("SELECT * FROM person");
$sth->execute();

while (my $href = $sth->fetchrow_hashref()) {
    my $d = Data::Dumper->new([$href]);
    print "got data:\n", $d->Dump();
}

print "Test 2 - import from string\n";
$dbh = DBI->connect('dbi:XML(RaiseError => 1):');
$dbh->func('person2', 'XML', [<DATA>], 'ad_import');

$sth = $dbh->prepare("Select email FROM person2 WHERE name = 'Nigel Horne'");

$sth->execute();

while (my $href = $sth->fetchrow_hashref()) {
    my $d = Data::Dumper->new([$href]);
    print "got data:\n", $d->Dump();
}

__DATA__
<?xml version="1.0" encoding="US-ASCII"?>
<table>
    <row id="1">
        <name>Nigel Horne</name>
        <email>n...@concert-bands.co.uk</email>
    </row>
    <row id="2">
        <name>A N Other</name>
        <email>someb...@example.com</email>
    </row>
</table>

Tim.
-Nigel

--
Nigel Horne
Conductor: Rockville Brass Band, Washington Metropolitan GSO
@nigelhorne | fb/nigel.horne | bandsman.co.uk | concert-bands.co.uk | 
www.nigelhorne.com

Unless it's for my eyes only, please use "reply all"


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to