Hello Mike,

Thanx much for a nice example it definitely worked for me. However I also
succeeded (by gish and by gosh I guess) to achieve what I needed in this
following way:
# print header record
if ($sort_flg eq "Y")
  {print OUTFILE join('|',sort @ClnFldsArray)."\n"; }
else
  {print OUTFILE join('|',@ClnFldsArray)."\n"; }

my %row;
my      $sth = $dbh->prepare_cached($sql) || die $dbh->errstr;
        $sth->execute;
        $sth->bind_columns( \( @[EMAIL PROTECTED] ));
while($sth->fetch) {
 if ($sort_flg eq "Y")
        { print OUTFILE map("$row{$_}|", sort @ClnFldsArray), "\n";     }
 else
        { print OUTFILE map("$row{$_}|", @ClnFldsArray), "\n";  }
}#while


# Using hash, was useful to me, since I was able to get into any HASH
element looping
# thru sorted/not sorted array of predefined fields. Something that I was
not able to achieve when I started this email. I am still puzzled as to why
it worked!!!

Anyway, thanx much for your time and help. 
This has really been educating. 

Daniel



-----Original Message-----
From: Michael A Chase [mailto:[EMAIL PROTECTED]
Sent: Monday, September 08, 2003 11:53 PM
To: dbi-users; Rozengurtel, Daniel
Subject: Re: bind columns behavior


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.


____________________________________________________________________

IMPORTANT NOTICES: 
          This message is intended only for the addressee. Please notify the
sender by e-mail if you are not the intended recipient. If you are not the
intended recipient, you may not copy, disclose, or distribute this message
or its contents to any other person and any such actions may be unlawful.
 
         Banc of America Securities LLC("BAS") does not accept time
sensitive, action-oriented messages or transaction orders, including orders
to purchase or sell securities, via e-mail.

         BAS reserves the right to monitor and review the content of all
messages sent to or from this e-mail address. Messages sent to or from this
e-mail address may be stored on the BAS e-mail system.
__________________________________________________________________

Reply via email to