Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > DBD::AnyData hangs when exporting XML

Reply
Thread Tools

DBD::AnyData hangs when exporting XML

 
 
KomsBomb@hotmail.com
Guest
Posts: n/a
 
      06-21-2007
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.

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      06-21-2007
wrote:
> 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

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
KomsBomb@hotmail.com
Guest
Posts: n/a
 
      06-22-2007
xhos...@gmail.com wrote:
>
> 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.

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      06-22-2007
wrote:
> xhos...@gmail.com wrote:
> >
> > 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.


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

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      06-22-2007
wrote:
> wrote:
> > 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.


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

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
KomsBomb@hotmail.com
Guest
Posts: n/a
 
      06-23-2007
On Jun 23, 12:14 am, xhos...@gmail.com wrote:
>
> 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.


> > 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.



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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Gem hangs => TCPSocket.write hangs Tim Shadel Ruby 1 07-24-2005 06:11 AM
Exporting to Word Doc using Microsoft Office Html and XML Vimal ASP .Net 0 10-14-2004 01:32 PM
Exporting relational data to xml using java Amol XML 0 04-16-2004 03:45 PM
Clear hangs up - & hangs up - & hangs up Sue Bilstein NZ Computing 26 03-07-2004 01:33 AM



Advertisments