Ok, now that I have a basic understanding of the FOR UPDATE , the initial
selectall_arrayref is confusing me.

The while loop is getting each row , but it's returning a reference.

So when I try to dereference it I am still getting a memory address which
tells me I am not doing it properly.

What I need to do is
foreach my $url (@$url_list) {
        my ($url_id) = (@$url[0]);
}

But I can't figure out how to do this in the while loop without causing it
to do the foreach every time thus increasing the foreach loop each time
through. :)

sub select_url() {

  my $select_query = "SELECT check.url_id AS url_id, check.url_timeout,
url.url_protocol, url.url, url.contact_ids, MD5.MD5,
check.mc_id, check.lc_status, check.lc_MD5_status
                      FROM monitor_check check
                      LEFT OUTER JOIN monitor_url url
                      ON check.url_id = url.url_id
                      LEFT OUTER JOIN monitor_MD5 MD5
                      ON check.url_id = MD5.url_id
                      WHERE ((active = 1)
                      AND ((chk_freq + UNIX_TIMESTAMP(lc_epoch)) <= ?))
                      OR (lc_status = 0)
                      FOR UPDATE";

  my $update_query_statement = "UPDATE monitor_check
                                SET lc_epoch = FROM_UNIXTIME(?)
                                WHERE url_id = ?";

  my @update_values;
  my ($update_query, $update);
  my $url_id;

  while (my $url_list = $dbh->selectall_arrayref($select_query, undef,
$current_time)
        or die "Can't execute statement: $DBI::errstr") {

        @update_values = ($current_time, @$url_list[0]);

    print "DEBUG - @$url_list[0] $current_time\n";

        $update_query = $dbh->prepare($update_query_statement)
                or die "Unable to prepare update_query_statement:
$DBI::errstr";

        $update = $update_query->execute(@update_values)
                or die "Unable to execute update_query: $DBI::errstr";

  }


  return($url_list);

}


Reply via email to