DBD::AnyData hangs when exporting XML

K

KomsBomb

Perl 5.8.0
Newest DBD::AnyData and AnyData just downloaded from CPAN.
When export a test database to xml, the script hangs and seems
it's in a dead loop.


********My Code start*************
use strict;
use warnings;
use DBI;

my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):');
my ($table, $format, $file, $flags) = (
'test', 'XML', 'cars.csv', { col_names => 'make,model,year' }
);
$dbh->do("CREATE TABLE test (id TEXT,phrase TEXT)");
$dbh->do("INSERT INTO test VALUES (1,'foonadfjlsdj')");
$dbh->do("INSERT INTO test VALUES (2,'bar')");
$dbh->func( $table, $format, $file, 'ad_export'); #hangs here
********My Code end*************


By doing more investigation, I found where it hangs,

In package AnyData (note not the DBD::AnyData), line 639, in sub
adConvert, there is a line
" @cols = @{ shift @{ $source_data } };"
When I execute step by step there, the program hangs at that line.

Any one got such problem? Is it a bug in Perl?
How to solve it?

PS: I've also tested CSV format and it's OK. No any problem.
 
X

xhoster

Perl 5.8.0
Newest DBD::AnyData and AnyData just downloaded from CPAN.
When export a test database to xml, the script hangs and seems
it's in a dead loop.

********My Code start*************
use strict;
use warnings;
use DBI;

my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):');
my ($table, $format, $file, $flags) = (
'test', 'XML', 'cars.csv', { col_names => 'make,model,year' }
);
$dbh->do("CREATE TABLE test (id TEXT,phrase TEXT)");
$dbh->do("INSERT INTO test VALUES (1,'foonadfjlsdj')");
$dbh->do("INSERT INTO test VALUES (2,'bar')");
$dbh->func( $table, $format, $file, 'ad_export'); #hangs here
********My Code end*************

By doing more investigation, I found where it hangs,

In package AnyData (note not the DBD::AnyData), line 639, in sub
adConvert, there is a line
" @cols = @{ shift @{ $source_data } };"
When I execute step by step there, the program hangs at that line.

I've run strace on this program. It appears to be opening two handles onto
the file cars.csv, and trying to obtain a exclusive lock on each of those
handles, leading to a self-deadlock. The very last instruction executed is
a flock, so I don't think you've identified the correct line for the
freezing point.

Xho
 
K

KomsBomb

I've run strace on this program. It appears to be opening two handles onto
the file cars.csv, and trying to obtain a exclusive lock on each of those
handles, leading to a self-deadlock. The very last instruction executed is
a flock, so I don't think you've identified the correct line for the
freezing point.

Thank you for the reply.

I found the solution by let 'func' return the XML content rather than
write to a file directly by omitting the $file parameter,

my $s = $dbh->func( $table, $format, 'ad_export');
print $s;

I've tried the test script in DBD::AnyData, it also hangs when writing
to file. Maybe it's a Perl's quirk a bug in those packages.

Off topic: what do you mean "strace"? Is it one Linux utility?
I only use Windows and I have no idea of it.
I also found a STrace package in Perl, but I don't know how to use it.
 
X

xhoster

Thank you for the reply.

I found the solution by let 'func' return the XML content rather than
write to a file directly by omitting the $file parameter,

my $s = $dbh->func( $table, $format, 'ad_export');
print $s;

I've tried the test script in DBD::AnyData, it also hangs when writing
to file. Maybe it's a Perl's quirk a bug in those packages.

It is almost surely not a bug in perl itself, but rather it does seem to be
a bug in the AnyData module. So it is a bug in a module written in Perl,
but is not a bug in perl. You could contact the maintainers of AnyData
about it. I tried to dig into it myself, but
Off topic: what do you mean "strace"? Is it one Linux utility?

Yes, it is a linux utility. If you strace a program, it will print out all
of the system calls made by that program. On some other systems
(Solaris?), the same feature is called truss. I don't know what, if
anything, Windows has to support that functionality.
I only use Windows and I have no idea of it.
I also found a STrace package in Perl, but I don't know how to use it.

Thanks for pointing that out. I hadn't known of it before and I'll look
into it.

Xho
 
X

xhoster

I've run strace on this program. It appears to be opening two handles
onto the file cars.csv, and trying to obtain a exclusive lock on each of
those handles, leading to a self-deadlock. The very last instruction
executed is a flock, so I don't think you've identified the correct line
for the freezing point.

I've found the problem in AnyData/Format/XML.pm, around line 876:

#$self->{twig}->print;
#z if ( ( $storage and $file and !($file eq $storage->{file_name}) )
#z or ( $storage and $file and !$storage->{fh} )
if ( ( $storage and $file )
) {
$storage->{file_name} = $file;
close $storage->{fh} if $storage->{fh}; ### Just added by Me
$storage->{fh} = $storage->open_local_file($file,'o');
}

$storage->{fh} already holds a locked filehandle, so trying to obtain
a new filehandle and lock it (which open_local_file does) deadlocks.

I initially tried just to undef $storage->{fh}, but that didn't work.
Apparently, this handle is held somewhere besides just in $storage, so
I had to go with close rather than undef.

I must say that this adventure didn't make me terribly eager to use AnyData
in my own programs.

Xho
 
K

KomsBomb

It is almost surely not a bug in perl itself, but rather it does seem to be
a bug in the AnyData module. So it is a bug in a module written in Perl,
but is not a bug in perl. You could contact the maintainers of AnyData
about it. I tried to dig into it myself, but

I must clear that I love Perl but I have to allow my lover has some
bugs in it. LOL.
I'm very glad to hear it's not a bug in Perl. :)

Thanks for pointing that out. I hadn't known of it before and I'll look
into it.


I guess the package STrace is a little same with that Linux utility
but it's cross platform. I can't confirm that because I almost didn't
use Linux.
I've found the problem in AnyData/Format/XML.pm, around line 876:

#$self->{twig}->print;
#z if ( ( $storage and $file and !($file eq $storage->{file_name}) )
#z or ( $storage and $file and !$storage->{fh} )
if ( ( $storage and $file )
) {
$storage->{file_name} = $file;
close $storage->{fh} if $storage->{fh}; ### Just added by Me
$storage->{fh} = $storage->open_local_file($file,'o');
}

$storage->{fh} already holds a locked filehandle, so trying to obtain
a new filehandle and lock it (which open_local_file does) deadlocks.

I add that line like you did. OK, no dead lock again, but the output
is wrong like "XML::Twig=HASH(0x1d24544)".

I must say that this adventure didn't make me terribly eager to use AnyData
in my own programs.

What I'm doing is a utility for myself. So if AnyData will work for
me,
(e.g, by exporting to a string rather than to a file), I will still
use
it.

Whatever, thank you very much for your patient and your time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top