M
minjie
Hello,
I'm using DBI to retrieve data from a DB2 database for each column in a
table (for a web application). The columns are not statically declared
beforehand but composed dynamically into a scalar variable
$cols_for_bind, using the following sub routine:
sub columns_for_binding
{
my ($arr_ref, $prefix) = @_;
foreach (@{$arr_ref})
{
#print "in columns_for_binding func: $_\n\n";
$cols_for_bind .= "\\\$" . "$prefix" . $_ . ", ";
}
$cols_for_bind = substr($cols_for_bind, 0, length($cols_for_bind) -
2);
}
$arr_ref contains a list of column names for a table that I retrieved
from the database, and after executing the above routine, the value in
$cols_for_bind can be as follows, for example:
$col_for_bind = "\$mod_num, \$inst_num, \$param_name, \$from_value,
\$to_value, \$modified_date";
and I used the following statement to bind the columns:
$sth->bind_columns( undef, eval{$cols_for_bind});
I was hoping to "spell out" the 6 columns before bind_columns()
function is actually executed. But I kept getting the following error:
[Mon May 23 15:40:27 2005] [error] [client xx.x.x.xxx] bind_columns
called with 1 refs when 6 needed. at
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/DBI.pm line
1705.
so bind_columns() still treats eval{$cols_for_bind} as one parameter.
How should I go about for what I intend to do?
Thanks for any help.
I'm using DBI to retrieve data from a DB2 database for each column in a
table (for a web application). The columns are not statically declared
beforehand but composed dynamically into a scalar variable
$cols_for_bind, using the following sub routine:
sub columns_for_binding
{
my ($arr_ref, $prefix) = @_;
foreach (@{$arr_ref})
{
#print "in columns_for_binding func: $_\n\n";
$cols_for_bind .= "\\\$" . "$prefix" . $_ . ", ";
}
$cols_for_bind = substr($cols_for_bind, 0, length($cols_for_bind) -
2);
}
$arr_ref contains a list of column names for a table that I retrieved
from the database, and after executing the above routine, the value in
$cols_for_bind can be as follows, for example:
$col_for_bind = "\$mod_num, \$inst_num, \$param_name, \$from_value,
\$to_value, \$modified_date";
and I used the following statement to bind the columns:
$sth->bind_columns( undef, eval{$cols_for_bind});
I was hoping to "spell out" the 6 columns before bind_columns()
function is actually executed. But I kept getting the following error:
[Mon May 23 15:40:27 2005] [error] [client xx.x.x.xxx] bind_columns
called with 1 refs when 6 needed. at
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/DBI.pm line
1705.
so bind_columns() still treats eval{$cols_for_bind} as one parameter.
How should I go about for what I intend to do?
Thanks for any help.