in reply to Re^2: Replacement for/working version of CGI::App::Plugin::BREAD ???
in thread Replacement for/working version of CGI::App::Plugin::BREAD ???

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

Replies are listed 'Best First'.
Re^4: Replacement for/working version of CGI::App::Plugin::BREAD ???
by Corion (Patriarch) on Jun 18, 2013 at 18:11 UTC
Re^4: Replacement for/working version of CGI::App::Plugin::BREAD ???
by poj (Abbot) on Jun 18, 2013 at 17:39 UTC

    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

      After working through a number of typos, I am getting closer. I agree, however, that the command works perfectly in MySQL. The issue is translating it to a DBI command. For my test, the MySQL command returns:

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

      From inside my code:

      my $rval = 'rval (' . $table . ')'; my $sth2 = $dbh->prepare("SHOW COLUMNS IN $table where Field=?") or die 'prepare failed'; $sth2->execute( $field ) or die 'execute failed'; if ( $sth2->err ) { $rval .= 'error: [' . $sth2->errmsg . ']'; } else { $rval .= '(' . $sth2->rows . ')'; my ($arr, @arr, %arr, $field); while ( $arr = $sth2->fetchrow_hashref ) { foreach $field ( keys %{ $arr } ) { $rval .= "[".$field.":".$arr->{ $field }."]"; } } } return($rval);

      What now is returned ($rval) is:

      [rval (cmsParms)(1)[Extra:][Type:char(100)][Field:pKey][Default:][Null +:NO][Key:PRI]]

      This is exactly what I expected! Changes I made:

      • I fixed a couple of (important) typos.
      • I added "where Field=?" to the prepare, and $field in the execute, so it only returns the info for the one entry.

      Thanks for your help!

      Lee Crites
      lee@critesclan.com