Hi Sandy_Bio_Perl,
I think that the problem isn't with the IS NOT NULL, but rather with the division on the column with the null value. Here's something I scratched together that works. Note the IFNULL in your SQL statement, as well as csv_null => 1 in the connection parameters:
#!/usr/bin/perl use strict; use warnings; use DBI; sub RunSqlSearch; my $spreadsheet = 'newCsv.csv'; my $query = "SELECT sid,genotype, dnabl, dnatw12 " . "FROM $spreadsheet " . "WHERE genotype = 'a' " . "AND (IFNULL(dnatw12,0)/dnabl)<0.5 " . "AND dnatw12 IS NOT NULL " ; my ($queryResult) = RunSqlSearch($query); print "Your query $query returned the following result:\n$queryResult\ +n"; sub RunSqlSearch($){ my $query = $_[0]; # error check # if ($query eq ""){die "From runSqlQuery2 - No value entered for $ +query $!\n";} # Connect to the database, (the directory containing our csv file( +s)) my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_dir => ".", f_encoding => "utf-8", csv_eol => "\n", csv_null => 1, RaiseError => 1, }) or die $DBI::errstr; # Output using sql query # my $sth = $dbh->prepare($query); $sth->execute; my @row; my $queryResult=""; while (@row = $sth->fetchrow_array) { $queryResult .= join("\t",@row) . "\n"; } # output arguments # if ($queryResult eq ""){$queryResult = "No result found";} return ($queryResult); }
Hope that points you in the right direction.
-bmt
UPDATE: Note that this will still blow up if dnabl is NULL. I played around a bit, but the IFNULL that worked in the numerator of the division failed to work in the denominator. Not sure why...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: DBD::CSV::st execute failed: Can't locate object method "do_err" via package "SQL::Statement::Function::NumericEval"
by rehsack (Sexton) on Jul 08, 2016 at 08:55 UTC | |
Re^2: DBD::CSV::st execute failed: Can't locate object method "do_err" via package "SQL::Statement::Function::NumericEval"
by Sandy_Bio_Perl (Beadle) on Jul 08, 2016 at 09:24 UTC |
In Section
Seekers of Perl Wisdom