develooper Front page | perl.beginners | Postings from February 2002

Perl DBI - using parameters

Thread Next
From:
McElwee, Shane
Date:
February 1, 2002 09:14
Subject:
Perl DBI - using parameters
Message ID:
BD898E20FCD1D51181D300B0D049A6142825BE@kendall-ex2.kendall.akamai.com
Hi,

This is my first effort at perl scripting so forgive my innocence. What I am
trying to do is extract schema and data info from a proprietary database
into flat files, format those files and import the data and schema into an
Oracle database. 

The initial part of this is capturing the table names into an array and then
using that array to query the database and dump the results to flat files.
Where I'm having trouble is in using a bound parameter in the sql statement.
If I use a table name directly it works without a problem but when I
parameterise it I get a Parse Error.

foreach $i (@table_arr){
      $content = $i;
#     print ("table name is:  $i \n");
      open( CONTENT, ">$content" ) || die "Can't open file $content";
      my $sth = $dbh->prepare("select * from ?");
      $sth->bind_param(1, $i);

      my $row;

      $sth->execute or die "Can't execute SQL statement: ", $sth->errstr(),
"\n";
      $row = $sth->dump_results(80, "\n", ':',\*CONTENT);
     }

Any ideas where I could be going wrong?

Cheers

Shane

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About