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

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
  • Comment on Re^4: Replacement for/working version of CGI::App::Plugin::BREAD ???
  • Download Code

Replies are listed 'Best First'.
Re^5: Replacement for/working version of CGI::App::Plugin::BREAD ???
by lee_crites (Scribe) on Jun 18, 2013 at 18:33 UTC

    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