nlafferty has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: UPDATE WHERE oid = $oid
by runrig (Abbot) on Jul 20, 2001 at 00:54 UTC
    # Update oid with new timestamp my $sql = <<"EOT"; update clock set time = ? where oid = ? EOT my $upd_h = $dbh->prepare($sql); $upd_h->execute($new_time, $oid); # Get oid(s) with latest timestamp # This could all be done in one select # with either a subquery or ordering # by descending time, but this is one way # Get max timestamp $sql = <<"EOT"; select max(time) from clock EOT my ($time) = @{$dbh->selectcol_arrayref($sql)}; # Get all oid(s) with max timestamp $sql = <<"EOT"; select oid from clock where time = ? EOT my (@oids) = @{$dbh->selectcol_arrayref($sql, {}, $time);
Re: UPDATE WHERE oid = $oid
by jepri (Parson) on Jul 20, 2001 at 00:54 UTC
    You need to read the manual first, then come back and ask some more questions.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Re: UPDATE WHERE oid = $oid
by Wookie (Beadle) on Jul 20, 2001 at 01:17 UTC
    This is a terrible hack way to do it - but you could reduce it to one select by:
    $sql='select oid,time'; $sql.='from clock'; $sql.='order by time'; $exec=$dbh->prepare($sql); $exec=$dbh->execute()||die "Query Failed\n$sql\nError:\n$DBI::errstr"; while ($res=$exec->fetch) { $latest_oid=${$res}[0]; }
    As the last record to come off this query should be the one with the latest time stamp - $latest_oid will have the corresponding oid.
    game(Wookie,opponent) eq 'Wookie' ? undef $problem : remove_limbs(arms,opponent);
      You can order by 'time desc' and then the first oid's will be the ones with the latest timestamp.