Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a 'select_for_update' wrapper around 'select' method #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/SQL/Abstract.pm
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ sub select {
return wantarray ? ($sql, @bind) : $sql;
}

#======================================================================
# SELECT FOR UPDATE
#======================================================================

sub select_for_update {
my $self = shift;
my($sql, @bind) = $self->select(@_);
$sql .= $self->_sqlcase(' for update');
return wantarray ? ($sql, @bind) : $sql;
}

#======================================================================
# DELETE
#======================================================================
Expand Down Expand Up @@ -2145,6 +2156,12 @@ for details.

=back

=head2 select_for_update($source, $fields, $where, $order)

This is a wrapper around L<select> which will append the
"FOR UPDATE" statement to the end of a select statement.

=back

=head2 delete($table, \%where)

Expand Down
7 changes: 7 additions & 0 deletions t/01generate.t
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ my @tests = (
stmt_q => 'SELECT * FROM `test` WHERE ( `a` != ? )',
bind => ['boom']
},
{
func => 'select_for_update',
args => ['test', '*'],
stmt => 'SELECT * FROM test FOR UPDATE',
stmt_q => 'SELECT * FROM `test` FOR UPDATE',
bind => []
},
{
func => 'update',
args => ['test', {a => 'boom'}, {a => undef}],
Expand Down