Mario R. Sanchez, Ph.D. <mailto:[EMAIL PROTECTED]> wrote:
> i included just a snippet of code to make it simple. its from an
> application i need to build that automatically converts a table into
> xml.
>
> i need to build the bind_column syntax dynamically because i dont
> know 'a priori' how many fields there are in a table. i have a
> routine that creates an array with the fields. now knowing that i
> have n fields i can build a bind for n fields for futher use in a
> select * statement.
>
> if this helps...
>
> so .... why does it not work -- any ideas?
The reason it doesn't work is that you are trying to generate code on
the fly and execute it incorrectly. See 'perldoc -f eval' for more help
with doing this.
However, from what you say above, it is not necessary, which is why the
info above would have been useful in your original message. In fact you
don't actually need bind_columns for what you want to do. See the
following untested example, which assumes RaiseError => 1.
sub dump_table {
my $dbh = shift;
my $table_name = shift;
my $sth = $dbh->prepare("select * from $table_name");
$sth->execute;
my @col_names = @{$sth->{NAME_lc}};
my $id = 0;
print "<$table_name>\n";
while (my @row = $sth->fetchrow_array) {
++$id;
print " <${table_name}_entry id=$id>\n";
foreach my $i (0..$#row) {
print " <$col_names[$i]>$row[$i]</$col_names[$i]>\n";
}
print "</${table_name}_entry>\n";
}
print "</$table_name\n";
}
However, if you really want to use bind columns, add the following after
initialising @col_names.
my @row = ("") x scalar(@col_names);
$sth->bind_columns( \( @row ) );
... and change the 'fetch' to
while ($sth->fetch) {
... that should do the job.
If you look at the doco for bind_columns in 'perldoc DBI' it also shows
how to bind columns to hash values.
HTH
--
Brian Raven
=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the
intended addressee(s). Unauthorised reproduction, disclosure, modification,
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message do not
necessarily reflect those of Atos Euronext Market Solutions.
L'information contenue dans cet e-mail est confidentielle et uniquement
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee.
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail
vous parvient par erreur, nous vous prions de bien vouloir prevenir
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre
systeme. Le contenu de ce message electronique ne represente pas necessairement
la position ou le point de vue d'Atos Euronext Market Solutions.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs