The Manager (and the rest of RDBO, for that matter) has no way to
"SELECT ... FOR UPDATE." How about something like this instead?
sub get_lock {
my ( $class, %params ) = @_;
my $id = $params{'id'};
my $db = $params{'db'};
$db->dbh->do('select * from table where id = ? for update', undef, $id);
}
-John
I use a combination of get_objects_sql and get_objects_from_sql so my
method can do any search other than just by id
something akin to,
sub get_objects_locked {
my $class = shift;
my ($sql, $args) = $class->get_objects_sql(@_);
return $class->get_objects_from_sql(
@_,
args => $args,
sql => $sql . " FOR UPDATE",
);
}
Graham.
You just have to make sure the object is using the same database
connection as the one you got the lock with. The code above looks
like it's doing that, so it should work fine.
-John
Yeah, it looks like it should. I think your issue might be the "$self
= $obj" part. If you're trying to actually replace the calling
object with a new one, you'd have to do something like "$_[0] = $obj"
-John