Skip to content
Permalink
Browse files

Added skip_locked support for PostgreSQL. GitHub issue #19.

  • Loading branch information...
siracusa committed Aug 9, 2019
1 parent 12a90ae commit deadf1e9b0156d3cf9cdde6675f04b055bae2476
Showing with 36 additions and 2 deletions.
  1. +4 −0 modules/Rose-DB/Changes
  2. +1 −1 modules/Rose-DB/lib/Rose/DB.pm
  3. +2 −0 modules/Rose-DB/lib/Rose/DB/Pg.pm
  4. +29 −1 modules/Rose-DB/t/pg.t
@@ -1,3 +1,7 @@
0.779 (08.09.2019) - John Siracusa <siracusa@gmail.com>

* Added skip_locked support for PostgreSQL. (Patch by fhendrikx.)

0.778 (06.28.2016) - John Siracusa <siracusa@gmail.com>

* Added mysql_enable_utf8mb4 attribute. (Patch by Alexander Karelas.)
@@ -21,7 +21,7 @@ our @ISA = qw(Rose::Object);

our $Error;

our $VERSION = '0.778';
our $VERSION = '0.779';

our $Debug = 0;

@@ -152,6 +152,8 @@ sub format_select_lock

$sql .= ' NOWAIT' if($lock->{'nowait'});

$sql .= ' SKIP LOCKED' if($lock->{'skip_locked'});

return $sql;
}

@@ -15,7 +15,7 @@ BEGIN
}
else
{
Test::More->import(tests => 287);
Test::More->import(tests => 292);
}
}

@@ -529,3 +529,31 @@ else
{
SKIP: { skip("HandleError tests (DBI $DBI::VERSION)", 10) }
}

SELECT_LOCK: {
no warnings 'once';
local *Rose::DB_Test::Object::table_sql_from_lock_on_value = sub { 'my_table' };

Rose::DB->register_db(
type => 'select_lock',
driver => 'pg',
database => 'test',
);

$db = Rose::DB->new('select_lock');

my $sql = $db->format_select_lock('Rose::DB_Test::Object', { type => 'shared', nowait => 1, skip_locked => 1 });
is($sql, 'FOR SHARE NOWAIT SKIP LOCKED', 'shared, nowait, skip_locked');

$sql = $db->format_select_lock('Rose::DB_Test::Object', { type => 'for update', nowait => 1, skip_locked => 1 });
is($sql, 'FOR UPDATE NOWAIT SKIP LOCKED', 'for update, nowait, skip_locked');

$sql = $db->format_select_lock('Rose::DB_Test::Object', { type => 'for update', nowait => 1 });
is($sql, 'FOR UPDATE NOWAIT', 'for update, nowait');

$sql = $db->format_select_lock('Rose::DB_Test::Object', { type => 'for update', skip_locked => 1 });
is($sql, 'FOR UPDATE SKIP LOCKED', 'for update, skip_locked');

$sql = $db->format_select_lock('Rose::DB_Test::Object', { type => 'shared' });
is($sql, 'FOR SHARE', 'shared');
}

0 comments on commit deadf1e

Please sign in to comment.
You can’t perform that action at this time.