
Omore2ac
Novice
May 18, 2011, 12:33 PM
Post #1 of 6
(463 views)
|
|
@arrays and DBI
|
Can't Post
|
|
Hey all, I recently tried writing the values of an @arrays into a database via a $STH. my $sth = $dbh->do(qq{INSERT INTO station (@station_head) VALUES (@station_data)}); Doing this, I get the following error: "DBD::SQLite::db do failed: near ")": syntax error at tableparser5.plx line 125 (#the line above), <> line 468. DBD::SQLite::db do failed: near ")": syntax error at tableparser5.plx line 125, <> line 468." I've tried multiple ways of writing the statement without avial. I have verified that my @array holds the information required. So I am assuming that this - that is writing the values of the array - cannot be done. So I tried another solution. my $sth = $dbh->do(qq{INSERT INTO station ($station_head[0..$#station_head]) VALUES ($station_data[0..$#station_data])}); This fails as well with the following errors: "Argument "" isn't numeric in array element at tableparser5.plx line 125, <> line 468. Use of uninitialized value within @station_head in concatenation (.) or string at tableparser5.plx line 125, <> line 468." Now my question is: How exactly can I write the info in my @array into a database? The objective is to iterate through my %pair, on each iteration, push those values to @station_head and @station_data, then write that as a whole to the database instead of writing to the database on each iteration. Code Relevant for Understanding is posted below: for (\$row_count ){ my @cords = ($j.$row_count.$idx); my ($cords) = @cords; my @hash_pair; my @station_data; my @station_head; my %pair = ( # long and unnecessary information); while (@hash_pair = (each(%pair))){ if ($hash_pair[1] == $cords){ warn "[$hash_pair[0]] => ($cell)\n"; push (@station_head, $hash_pair[0]); push (@station_data, $cell); # print "[","^","-",@station_head,"-","^","]"; #print " "; # print "[","^","-",@station_data,"-","^","]","\n"; } my $sth = $dbh->do(qq{INSERT INTO station (@station_head) VALUES (@station_data)}); Thanks for any help!
|