Sha256: b3c707d4ed709d2258156cce7d2bad4400a328ddedd637e9ad915b1391e66355

Contents?: true

Size: 1.37 KB

Versions: 123

Compression:

Stored size: 1.37 KB

Contents

# -*- ruby -*-
#
# Test script, demonstrating a non-poll notification for a table event.
#

BEGIN {
        require 'pathname'
        basedir = Pathname.new( __FILE__ ).expand_path.dirname.parent
        libdir = basedir + 'lib'
        $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
}

require 'pg'

TRIGGER_TABLE = %{
	CREATE TABLE IF NOT EXISTS test ( message text );
}

TRIGGER_FUNCTION = %{
CREATE OR REPLACE FUNCTION notify_test()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
    BEGIN
        NOTIFY woo;
        RETURN NULL;
    END
$$
}

DROP_TRIGGER = %{
DROP TRIGGER IF EXISTS notify_trigger ON test
}


TRIGGER = %{
CREATE TRIGGER notify_trigger
AFTER UPDATE OR INSERT OR DELETE
ON test
FOR EACH STATEMENT
EXECUTE PROCEDURE notify_test();
}

conn = PG.connect( :dbname => 'test' )

conn.exec( TRIGGER_TABLE )
conn.exec( TRIGGER_FUNCTION )
conn.exec( DROP_TRIGGER )
conn.exec( TRIGGER )

conn.exec( 'LISTEN woo' )  # register interest in the 'woo' event

notifications = []

puts "Now switch to a different term and run:",
     '',
     %{  psql test -c "insert into test values ('A message.')"},
	 ''

puts "Waiting up to 30 seconds for for an event!"
conn.wait_for_notify( 30 ) do |notify, pid|
	notifications << [ pid, notify ]
end

if notifications.empty?
	puts "Awww, I didn't see any events."
else
	puts "I got one from pid %d: %s" % notifications.first
end



Version data entries

123 entries across 123 versions & 4 rubygems

Version Path
pg-1.4.0-x64-mingw32 sample/notify_wait.rb
pg-1.4.0 sample/notify_wait.rb
pg-1.3.5-x64-mingw-ucrt sample/notify_wait.rb
pg-1.3.5-x64-mingw32 sample/notify_wait.rb
pg-1.3.5-x86-mingw32 sample/notify_wait.rb
pg-1.3.5 sample/notify_wait.rb
postgresql-lambda-1.3.4.3 ./sample/notify_wait.rb
postgresql-lambda-1.3.4.1 ./sample/notify_wait.rb
pg-1.3.4-x64-mingw32 sample/notify_wait.rb
pg-1.3.4-x64-mingw-ucrt sample/notify_wait.rb
pg-1.3.4-x86-mingw32 sample/notify_wait.rb
pg-1.3.4 sample/notify_wait.rb
pg-1.3.3-x64-mingw-ucrt sample/notify_wait.rb
pg-1.3.3-x64-mingw32 sample/notify_wait.rb
pg-1.3.3-x86-mingw32 sample/notify_wait.rb
pg-1.3.3 sample/notify_wait.rb
pg-1.3.2-x86-mingw32 sample/notify_wait.rb
pg-1.3.2-x64-mingw-ucrt sample/notify_wait.rb
pg-1.3.2-x64-mingw32 sample/notify_wait.rb
pg-1.3.2 sample/notify_wait.rb