icskevin has asked for the wisdom of the Perl Monks concerning the following question:
To get the field names from the .dbf table. I then massage# Create new Xbase object using the file name passed in my $table = new XBase "$dbfFileName" or die XBase->errstr; # Get field names in the table my @fieldNames = $table->field_names;
This works great mainly because I can pass the string to# Create a select statement to get this data from the table my $selectStatement = "SELECT "; $selectStatement .= join(', ',@fieldNames) ; # Add fields seperate +d by commas $selectStatement .= " FROM ./POIS.dbf"; # Add the dbf file print "$selectStatement\n\n\n" if $debugFlag; # Get handle by opening the .dbf file which has POI info in it my $dbh = DBI->connect("DBI:XBase:$directory") or die $DBI::errstr +; my $sth = $dbh->prepare(" $selectStatement ") or die $DBI::errstr; $sth->execute() or die $sth->errstr(0);
Our hope is to be able to read the column names from# Walk through results set one row at a time while ( my (@row) = $sth->fetchrow_array()) { my $LINK_ID = $row[0]; my $POI_ID = $row[1]; my $FAC_TYPE = $row[2]; my $POI_NAME = $row[3]; my $POI_LANGCD = $row[4]; my $POI_NMTYPE = $row[5]; my $POI_ST_NUM = $row[6]; ..... my $ACTION_COD = $row[26]; my $COMMENTS = $row[27]; my $POSITION_ = $row[28]; my $TEST_ID = $row[29];
To create something resembling this where Imy $localValues = "my \$"; $localValues .= join(', $',@fieldNames) ; # print "$localValues\n" if $debugFlag;
but the string I have created which looks likewhile ( my ($localValues) = $sth->fetchrow_array())
is not cutting it because I can't get it tomy $LINK_ID, $POI_ID, $FAC_TYPE, .... $TEST_ID
Any suggestions on how I can create this list of scalarswhile ( my (my $LINK_ID, $POI_ID, $FAC_TYPE, .... $TEST_ID) = $sth->f +etchrow_array())
Hope I've explained this well enough,my $prepStatement = <<TO_END_SQL_STATEMENT; insert into ORACLE_TABLE ( LINK_ID, POI_ID, ...... TEST_ID ) values ( '$LINK_ID', $POI_ID, ..... , $TEST_ID' ) TO_END_SQL_STATEMENT
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Syntax for list of scalars to be populated by fetchrow_array() ?
by imp (Priest) on Aug 22, 2006 at 19:12 UTC | |
|
Re: Syntax for list of scalars to be populated by fetchrow_array() ?
by dirving (Friar) on Aug 22, 2006 at 20:44 UTC |