I ... can not figure out a way to check to see if my select statement (ran by perl) pulls results or not, I was also thinking that I might just pull all the names in the DB and use Perl's if control structure to go though the names and compare...
If the "fetch" function (e.g. "fetchrow_array") returns an empty list, there was no row in the table that matched the "Title=?" condition. So you would need to insert a new row with a vote tally of "1".
But if the return from the "fetch" is not empty, one of the returned fields ought to be the current value of the vote tally, so you just increment that and update the row with the new value (using the same "where Title=?" condition, and the same filename parameter when you execute the update).
Doing a query for all rows in the table would work to: you would want a query like "select Title,Tally from FanRatings", and use a loop, something like:
You now have a hash whose keys are the current set of known "Titles" (filenames); as you look at an incoming file name, if it exists as a hash key, it's already in the table, so increment/update the tally; otherwise, insert a new row (and add the new filename as a new hash element, with a value of "1").my %known_ratings; while ( my @ary = $sth->fetchrow_array ) { $known_ratings( $ary[0] } = $ary[1]; }
But this latter is better suited to a case where a single process would be handling lots of input file names and votes in one run -- there are fewer select operations (fewer database transactions) that way. If you're just doing a single filename (selecting to check for existence, then either doing a single insert or a single update), loading the whole table is a lot more work than necessary.
In reply to Re: Check for null results
by graff
in thread Check for null results
by Eagle_f90
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |