From: Peter Rabbitson Date: Thu, 13 Jan 2011 11:41:44 +0000 (+0100) Subject: Fix for => 'shared' on MySQL (RT#64590) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e0a89e400d865458081bc5af9e0eedf349f60de;p=dbsrgits%2FDBIx-Class-Historic.git Fix for => 'shared' on MySQL (RT#64590) --- diff --git a/Changes b/Changes index 09663a6..2f6f95b 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,7 @@ Revision history for DBIx::Class it easier to pass HashRefInflator data directly to ->populate - Improve freeze/thaw semantics and error messages (RT#62546) - Fix inconsistency in Manual::Features (RT#64500) + - Fix incorrect SQL when using for => 'shared' with MySQL (RT#64590) * Misc - Fix test warning on win32 - at this point the test suite is diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 9fc06fb..dc42f38 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -326,6 +326,8 @@ kaare: Kaare Rasmussen konobi: Scott McWhirter +littlesavage: Alexey Illarionov + lukes: Luke Saunders marcus: Marcus Ramberg diff --git a/lib/DBIx/Class/SQLMaker/MySQL.pm b/lib/DBIx/Class/SQLMaker/MySQL.pm index 16e47e7..ccb1195 100644 --- a/lib/DBIx/Class/SQLMaker/MySQL.pm +++ b/lib/DBIx/Class/SQLMaker/MySQL.pm @@ -31,4 +31,19 @@ sub _generate_join_clause { return $self->SUPER::_generate_join_clause( $join_type ); } + +# LOCK IN SHARE MODE +my $for_syntax = { + update => 'FOR UPDATE', + shared => 'LOCK IN SHARE MODE' +}; + +sub _lock_select { + my ($self, $type) = @_; + + my $sql = $for_syntax->{$type} || croak "Unknown SELECT .. FOR type '$type' requested"; + + return " $sql"; +} + 1; diff --git a/t/71mysql.t b/t/71mysql.t index 66ebfd2..d75474e 100644 --- a/t/71mysql.t +++ b/t/71mysql.t @@ -85,6 +85,16 @@ lives_ok { }); } 'Limited FOR UPDATE select works'; +# shared-lock +lives_ok { + $schema->txn_do (sub { + isa_ok ( + $schema->resultset('Artist')->find({artistid => 1}, {for => 'shared'}), + 'DBICTest::Schema::Artist', + ); + }); +} 'LOCK IN SHARE MODE select works'; + my $test_type_info = { 'artistid' => { 'data_type' => 'INT',