in reply to Replacement for/working version of CGI::App::Plugin::BREAD ???

More Info / SHOW COLUMNS ISSUE

I realize this might be considered a "new topic," and as such, should be its own entry, but since I am working through the task described in the initial message, I thought it would be good to at least start this message here.

So... while plugging away at my own solution, I have found an issue with trying to execute either a "DESCRIBE $table" or "SHOW COLUMNS FROM $table" command. Here is an extracted snippet of code:

my $rval = ''; my $sth2 = $dbh->prepare("SHOW COLUMNS FROM $table"); $sth2->execute() or die 'execute failed'; if ( $sth2->err ) { $rval = 'error: [' . $sth2->errstr . ']'; } else { # the "while" line is #151 from the error message... while ( my @arr = $sth2->fetchrow_arrayref() ) { $rval .= '[' . join('|', @arr ) . ']'; } }

At this point, I am simply trying to gather ANYTHING from the command, so, yes, $rval will not have anything truly meaningful in this example.

What I am getting is an unending stream of:

[Tue Jun 18 10:48:43 2013] [error] [client 10.22.50.24] DBD::mysql::st fetchrow_arrayref failed: fetch() without execute() at /var/www/cgi-bin/CaMS2/TableEdit.pm line 151., referer: http://10.22.50.14/CaMS2/index.cgi

I don't need to know how to get a list of column names -- I already have that working. I want "the rest of the story" -- the Type, Null, and Default columns for sure.

mysql> show columns from cmsParms; +--------+-----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-----------+------+-----+---------+-------+ | pKey | char(100) | NO | PRI | NULL | | | pValue | text | NO | | NULL | | +--------+-----------+------+-----+---------+-------+ 2 rows in set (0.01 sec)

So that's my current issue. I'm currently hacking at it. When I get a solution, I'll post it here. If, however, anyone has already crossed this bridge, and can toss me some hints/tips/tricks/etc, I would greatly appreciate it!!!

Lee Crites
lee@critesclan.com

Replies are listed 'Best First'.
Re^2: Replacement for/working version of CGI::App::Plugin::BREAD ???
by poj (Abbot) on Jun 18, 2013 at 16:44 UTC
    Correction ;
    #my @arr = $sth2->fetchrow_arrayref() my @arr = $sth2->fetchrow_array()
    poj

      Thanks for the tip. I found an obscure reference to fetchrow_arrayref where the person was getting the same error I was, but couldn't figure out why. The reply was something to the effect that fetchrow_arrayref has "issues," and to not use it.

      So I changed it to fetchrow_hashref (which is the version I normally used, anyway). I did the copy/paste routine with the code I was using until I figured out what it was really doing.

      Anyway, what I discovered is that:

      my $sth2 = $dbh->prepare("SHOW FULL COLUMNS IN ?") or die 'pre +pare failed'; $sth2->execute($table) or die 'execute failed [' . $sth2->err +. '] [' . $sth2->errstr . ']';

      dies with a syntax error. And that:

      my $sth2 = $dbh->prepare("SHOW FULL COLUMNS IN $table") or die + 'prepare failed'; $sth2->execute() or die 'execute failed [' . $sth2->err . '] [ +' . $sth2->errstr . ']';

      does not die, but also does not return any rows of data.

      Lee Crites
      lee@critesclan.com

        No, you can't use a placeholder for a table name - see recent node DBI order by clause and placeholders.

        This works for me on MySQL
        $dbh->prepare("SHOW FULL COLUMNS IN $table")
        How are you retrieving records ?
        poj