The first reply should help a lot -- use placeholders, and get acquainted with the "fetch..." functions in DBI. As for this part:
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:

my %known_ratings; while ( my @ary = $sth->fetchrow_array ) { $known_ratings( $ary[0] } = $ary[1]; }
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").

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.