in reply to Re: Re: Re: Re: selecting again from a mysql database
in thread selecting again from a mysql database

Would your solution to this be have huge if/elsif statement . . .

No, I'd put the columns I wanted for each table in an HoA:

my %COLUMNS = ( MY_FIRST_TABLE => [ qw( blah_1 blah_2 ) ], MY_2ND_TABLE => [ qw( another_col dob ) ], . . . ); # $table defined elsewhere my $SQL = 'SELECT ' . join(',', @{ $COLUMNS{$table} }) . " FROM $table +";

Clean, efficient, no SELECT *.

Update: Added some missing whitespace in the SQL generated.

. . . describe table (which BTW is not portable to other DBMSs) . . .

MySQL's describe table isn't, but DBI's column_info method is. (Though I wouldn't use that particular solution).

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: selecting again from a mysql database
by Plankton (Vicar) on Nov 25, 2003 at 21:01 UTC
    This would not work ... if a column is added to a table you have update your script because it breaks. You would have to modify your script even it some added a table. This might be acceptable for tiny databases of a few tables, but what about large databases with hundereds of tables?

    Plankton: 1% Evil, 99% Hot Gas.
    A reply falls below the community's threshold of quality. You may see it by logging in.