On Fri, 20 Sep 2002 13:36:36 -0700 (PDT) Avik <[EMAIL PROTECTED]> wrote:
> --- Ronald J Kimball <[EMAIL PROTECTED]> wrote:
> > On Fri, Sep 20, 2002 at 03:44:31PM +0100, Tim Bunce wrote:
> >
> > > I need to be able to list all the tables in a connected database,
> > > then for each table list of columns. I tried to use your table_info(),
> > > column_info(), interface but it returns 'DBI::st=HASH(...blah...)'.
> > > Trying to output that reference to Data::Dumper returns
> > > $VAR1 = bless({}, DBI::st)
> >
> > As documented, these methods return statement handles, on which you call
> > fetch methods to get the actual info.
> >
> > For example:
> >
> > my $sth = $dbh->table_info();
> >
> > while (my(@info) = $sth->fetchrow_array()) {
> > print join("\t", @info), "\n";
> > }
> >
> > Ronald
>
> What about column_info()?
>
> #!D:\Perl\Bin\perl.exe
> use warnings;
> use strict;
> use DBI;
> use Data::Dumper;
>
> #print DBI->VERSION;
> my $dbh = DBI->connect("DBI:mysql:database=avik") or die $DBI::errstr;
> my $sth = $dbh->column_info();
> while (my(@info) = $sth->fetchrow_array()) {
> print join("\t", @info), "\n";
> }
>
> $dbh->disconnect;
>
> Gave me this output:
>
> Can't call method "fetchrow_array" on an undefined value at dbi1.pl line 10.
> Database handle destroyed without explicit disconnect.
It appears that the call to column_info() failed. If you were checking for
errors there, you'd probably know a lot more about what went wrong. In the
fine manual (perldoc DBI), it shows several arguments that you did not
provide. The exact meanings of each argument are not described because
they are database dependent. If in doubt, you can use the appropriate
wildcard expression for your database in each.
> I can't understand what's written in the documentation. The language seems to
> be pretty obscure. Please help me to create a script that lists tables and
> their columns, maybe I'll figure it out from now on.
If you can suggest better wording, we would be most grateful.
In an ActivePerl installation, you can also read the fine manual by
following "Start Menu" -> "Programs" -> "ActivePerl" -> "Documentation".
The frame on the left includes links for all installed modules, including
DBI and DBD::mysql in your case.
--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.