Please keep this on dbi-users.  Others may have something to learn or
contribute.

On Mon, 8 Sep 2003 22:09:57 -0400  "Rozengurtel, Daniel"
<[EMAIL PROTECTED]> wrote:

> The reason i did not want to touch the sql before I call prepare() is
> because the sql is passed to a program in .ini file which my perl
> parses and creates an sql statement. I could basically get each of
> fields in a select statement from ini file into an array and just
> before constructing sql sort it or do whatever I neede to, however
> that involved some additional work on parsing. I did not know that i
> needed to preserve the order of fields in SELECT statemnt, and
> thought I could get away with just outputing the results the way I
> wanted. Well tought luck I guess. 

It's mostly a matter of where it is easiest and clearer.  TMTOWTDI.

> Now you mentioned passing an array instead of hash. I.e once I got my
> fields ordered in @ClnFldArray, I could do this:
> 
>  my $sth = $dbh->prepare_cached($sql) || die $dbh->errstr;
>     $sth->execute;

The problem with just using the array is that it initially doesn't have
the elements needed.  One way to be sure it does is to assign the
$sth->{NAME} array to it, that also makes it a handy source for the
header line.  As long as you keep the \(), bind_columns() will be
passed a list of references to the elements of the array.  The \ is
distributive in that syntax and the array is expanded to a list of its
elements in the parenthesis.

   # After this, @ClnFldsArray has the right number of elements.
   @ClnFldsArray = @{$sth -> {NAME}};
   print OUTPUT join( "|", @ClnFldsArray ), "\n";

>       $sth->bind_columns( \( @ClnFldsArray ) );
> # I am not sure this will work! I think it will consider it as one
> # bind var instead of multiple that needs to be passed.
> # How do you get away with this???

See above.

>  while($sth->fetch) {
> ....
> ....   
>  }#while
> 
> Thanx much for your time Mike.

-- 
Mac :})
** I usually forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

Reply via email to