bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow monasterians,
I'm returning an array (yes, I know it's really a list) from an subroutine by reference. So far, so good. However, I'm not able to INSERT those returned dereferenced values into my database. This first bit of code returned the bizarre error: unknown column 'actual_value_I'm_trying_to_place' in 'field list' (which is discussed in this node). Much simplified (hope I didn't lose anything):
my $ref = &subroutine( $fee, $fie, $foo, $fum ); $sth = $dbh->prepare ( "INSERT INTO mytable VALUES(?,?,?,?)" ); $sth->execute ( @$ref[0], @$ref[1], @$ref[2], @$ref[3] ) ; sub subroutine { my @ref = @_; ... return (\@ref); }
Data::Dumper is our friend:
print Dumper(@$ref[0], @$ref[1], @$ref[2], @$ref[3]); $VAR1='aaaaaaa'; $VAR2='bbbbbbb'; $VAR3='ccccccc'; $VAR4='ddddddd';
If I hard code it, all is fine:
my @ref = qw( aaaaaaa bbbbbbb cccccccc ddddddd ); $sth->execute ( $ref[0], $ref[1], $ref[2], $ref[3] );
I even tried, unsuccessfully, re-assigning the references to a regular array (desperation):
my @array = ( @$ref[0], @$ref[1], @$ref[2], @$ref[3] ); $sth->execute ($array[0], $array[1], $array[2], $array[3]);
So, my questions: 1) is my original subroutine referenced return okay? 2) is it true that you can't INSERT derefenced values into MySQL? 3) how to I do this without just declaring a big fat global and avoiding the references? As always, thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unable to INSERT dereferenced values into db
by Stevie-O (Friar) on May 25, 2004 at 03:18 UTC | |
by Mr. Muskrat (Canon) on May 25, 2004 at 11:59 UTC | |
|
Re: Unable to INSERT dereferenced values into db
by Somni (Friar) on May 25, 2004 at 03:27 UTC | |
by bradcathey (Prior) on May 26, 2004 at 02:18 UTC | |
by bradcathey (Prior) on May 25, 2004 at 13:42 UTC | |
by Somni (Friar) on May 26, 2004 at 01:55 UTC | |
by bradcathey (Prior) on May 25, 2004 at 13:51 UTC |