Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: DBD::Anydata

by rongoral (Beadle)
on Nov 17, 2004 at 21:41 UTC ( #408602=note: print w/replies, xml ) Need Help??

in reply to DBD::Anydata


I hope that I am not going to be wasting anyone's time here, however, I have not seen this addressed.

I am trying to implement jZed's DBD::AnyData module to parse a flat file db. My test code is:

#!/usr/bin/perl use strict; use warnings;use CGI::Carp qw(fatalsToBrowser); use DBI; use DBD::AnyData; print qq[content-type: text/html\n\n]; my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); my $table = 'mothers'; my $format = 'Pipe'; my $file = 'databases/mothers.tbl'; my $flags = ''; # The first row holds the field names $dbh->func( $table, $format, $file, $flags, 'ad_catalog'); my $sth = $dbh->prepare("SELECT * FROM mothers WHERE name = 'Sandra'") +; $sth->execute(); while (my $row = $sth->fetch) {print "@$row<br />";} 1;

The "table" consists of one record:

name|age|address|phone Sandra | 46 | 1252 Some St, Anywhere, WI 12345 | 123-456-7890

I was getting some wierd results and so went in and activated the debugging code left in place. Specifically, the code is located at line 529 in the open_table sub as follows:

print join("\n", $format,@$file,$createMode), "\n";

This would return the error -

DBD::AnyData::st execute failed: Can't use string ("databases/mothers.tbl") as an ARRAY ref while "strict refs" in use at DBD/ line 529, <GEN0> line 1.

So, I replaced the print and join statement with the following -

if (ref($file) eq 'ARRAY'){print join("\n", $format, @$file, $createMo +de), "\n";}<br /> else {print join("\n", $format, $file, $createMode), "\n";}

This then allows the printing of $file when it was not an array ref.

As I said, I hope that I have not wasted anyone's time with this. And btw, where is that stand alone version? My host does not have this pm or many of the supporting pms.

Humbly -
Ron Goral

Replies are listed 'Best First'.
Re^2: DBD::Anydata
by jZed (Prior) on Nov 18, 2004 at 19:28 UTC
    Rather than finding out the values with that debug statement, you can use the ad_get_catalog() function to see what values are available for a given table:
    $dbh->func( $table, $format, $datasource, 'ad_catalog'); my $catalog = $dbh->func('ad_get_catalog'); use Data::Dumper; print Dumper $catalog;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://408602]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2023-06-05 00:34 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (22 votes). Check out past polls.