When I generate SQL automatically from the datadictionary, I normally use an
array to hold the column values:

   # $dbh -> {RaiseError} = 1;
   $sth -> execute;
   my @sTitle = @{$sth -> {'NAME'}};
   my @sCol  = ();
   $sth -> bind_columns( \( @sCol[0 .. $#sTitle] ) );
   while ( $sth -> fetch ) {
   . . .

I use \(), because sometimes I mix multiple scalars and array slices in the
bind_columns() call.

--
Mac :})
** I normally forward private database questions to the DBI mail lists. **
Give a hobbit a fish and he'll eat fish for a day.
Give a hobbit a ring and he'll eat fish for an age.
----- Original Message -----
From: "Steve Howard" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 07, 2001 7:16 PM
Subject: Reusable code for binding columns.


> Does anyone have any ideas on how to make this work:
>
> I write a lot of scripts to do migrations. I try to make as much of my
code
> reusable as possible. Straight table copies are no problem after I query
the
> system tables to get the table, and column names, and build something
like:
>
> INSERT INTO $ini->{targetdb}..$table ($columnlist) SELECT $columnlist FROM
> $ini->{sourcedb}..$table
>
> My problem comes with finding a way to build reusable code for a
subroutine
> to deal with tables that will not go straight across. The obstacle is in
> this statement:
>
> $row = $select->bind_columns(undef, \$column1, \$column2......
>
> Again, I can get the column names by querying the system catalogs.  I
don't
> necessarily have to bind them by anything resembling their column name, I
> only need a way to reference them. So once I get the number of columns
into
> the script, how can I then assign variable, or hash key names so that I
can
> build a bind_columns statement that can work?
>
> I may be just too close to this to see something obvious - whatever the
> case, I would greatly appreciate any ideas that will help with this.



Reply via email to