Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am using DBD::CSV and fetchrow_hashref and not getting results. In my example below, the variables $Cposition and $Cyear have already had values assigned.
Here is my database handler:
my $dbh = DBI->connect(qq{DBI:CSV:csv_eol="\n";csv_sep_char=\\~}); $dbh->{'csv_tables'}->{'JPDObj'} = {'file' => 'data/objectives-cqdc.tx +t','col_names' => ["Obj","PosNbr","Year","Div","AVP","Dept","SDescr", +"Major","Methods","Results","Accompl","JanUp","LDescr","Changes","Cha +rs","Goals","Budget","CFObj"]}; $dbh->{'RaiseError'} = 1; $@ = ''; my $query = "SELECT Obj,SDescr,Major,Year,LDescr FROM JPDObj WHERE Pos +Nbr = '$Cposition' AND Year = '$Cyear'"; my $sth = $dbh->prepare($query); $sth->execute(); my $found_results = 0; my $count = 0; my $Obj; my $PosNbr; my $Year; my $Div; my $AVP; my $Dept; my $SDescr; my $Major; my $Methods; my $Results; my $Accompl; my $JanUpd; my $LDescr; my $CFObj; while (my $row = $sth->fetchrow_hashref) { $found_results = 1; $count=$count+1; #SETUP VARIABLES $Obj=$row->{'Obj'}; $Year = $row->{'Year'}; $SDescr = $row->{'SDescr'}; $Major = $row->{'Major'}; $LDescr = $row->{'LDescr'}; my $Nyear = $nextYear + 1; $CFObj=$row->{'CFObj'}; if ($found_results) { # some output code here } }
It yields no results despite this record being in the file:
20140000020~00001576~2014~"testdata"~"testdata"~"testdata"~-~0~-~"Inse +rted on December 10, 2013"~-~-~-~-~20000000001~20130000001~1~-
And it should find results based on the second and third fields. Permissions on all files are correct and nothing comes across in my error log.
-Jacvivs
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD::CSV and fetchrow_hashref not working
by rnewsham (Curate) on Dec 11, 2013 at 15:43 UTC | |
|
Re: DBD::CSV and fetchrow_hashref not working
by tangent (Parson) on Dec 11, 2013 at 16:33 UTC | |
by Anonymous Monk on Dec 11, 2013 at 20:45 UTC | |
by tangent (Parson) on Dec 11, 2013 at 21:13 UTC | |
by Anonymous Monk on Dec 11, 2013 at 21:18 UTC | |
|
Re: DBD::CSV and fetchrow_hashref not working
by Tux (Canon) on Dec 12, 2013 at 08:08 UTC |