wrote in
news: oups.com:
> 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?
I am not sure what you intend to do because your explanation is fairly
convoluted.
Here is the documentation for bind_columns:
bind_columns
$rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind);
Calls bind_col for each column of the SELECT statement. The
bind_columns method will die if the number of references does
not match the number of fields.
For maximum portability between drivers, bind_columns() should be
called after execute() and not before.
From above:
> and I used the following statement to bind the columns:
>
> $sth->bind_columns( undef, eval{$cols_for_bind});
What do you think the first undef should do?
Why not put each of the references in an array, and use that?
Please do review the posting guidelines for information on how to help
yourself, and help others help you.
Sinan
--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html