DBD::AnyData hangs when exporting XML

Discussion in 'Perl Misc' started by KomsBomb@hotmail.com, Jun 21, 2007.

  1. Guest

    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.
     
    , Jun 21, 2007
    #1
    1. Advertising

  2. Guest

    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
     
    , Jun 21, 2007
    #2
    1. Advertising

  3. Guest

    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.
     
    , Jun 22, 2007
    #3
  4. Guest

    wrote:
    > 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
     
    , Jun 22, 2007
    #4
  5. Guest

    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
     
    , Jun 22, 2007
    #5
  6. Guest

    On Jun 23, 12:14 am, 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.
     
    , Jun 23, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Federico Bari

    XML, DBI::AnyData and mySQL

    Federico Bari, Jan 28, 2004, in forum: XML
    Replies:
    0
    Views:
    389
    Federico Bari
    Jan 28, 2004
  2. Andrew Crook

    DBD::CSV questions and is there a DBD::XML?

    Andrew Crook, Sep 2, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    188
    Andrew Crook
    Sep 11, 2003
  3. Federico Bari

    XML, DBI::AnyData and mySQL

    Federico Bari, Jan 27, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    144
    Federico Bari
    Jan 27, 2004
  4. Mike Solomon

    DBD::mysqlPP v DBD::mysql

    Mike Solomon, Feb 16, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    258
    James Willmore
    Feb 16, 2004
  5. Jim Cochrane
    Replies:
    0
    Views:
    132
    Jim Cochrane
    Aug 25, 2007
Loading...

Share This Page