in reply to 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 that would have a different $SQL string for each table in the database?... my $SQL = <<SQL; Select * from $table SQL $dbh->{LongReadLen} = 65500; my $sth = $dbh->prepare($SQL) || die $dbh->errstr; $sth->execute(); my $colNames = $sth->{'NAME'}; my $nColumns = $sth->{'NUM_OF_FIELDS'}; my $colString; for my $colName ( @$colNames ) { $colString .= "\n\t$colName,"; } chop($colString); print <<DOIT; OPTIONS (ROWS=1) LOAD DATA INFILE * REPLACE INTO TABLE $table FIELDS TERMINATED BY '|' TRAILING NULLCOLS ( DOIT print "$colString\n"; print<<DOIT; ) BEGINDATA DOIT while ( my @r = $sth->fetchrow_array ) { print join ( '|', map ( $_ , trim( @r )) ); print "\n"; } $sth->finish || die; $dbh->disconnect; ...
Or would you choose to access the database twice, once to do your describe table (which BTW is not portable to other DBMSs) and a second time to get the data from the table? Why not just access the database once?# can't use select * so ... if ( $table eq "MY_FIRST_TABLE" ) { $SQL = "select blah_1, blah_2 from MY_FIRST_TABLE"; } elsif ( $table eq "MY_2ND_TABLE" ) { $SQL = "select another_col, dob from MY_2ND_TABLE"; } ...
| Plankton: 1% Evil, 99% Hot Gas. |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: selecting again from a mysql database
by hardburn (Abbot) on Nov 25, 2003 at 20:51 UTC | |
by Plankton (Vicar) on Nov 25, 2003 at 21:01 UTC | |
|