8000 Adding a minimal "connection-test function" example · danielcode/ruby-pg@ae9bb3b · GitHub
[go: up one dir, main page]

Skip to content

Commit ae9bb3b

Browse files
committed
Adding a minimal "connection-test function" example
1 parent 0096147 commit ae9bb3b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ lib/pg/result.rb
2828
sample/async_api.rb
2929
sample/async_copyto.rb
3030
sample/async_mixed.rb
31+
sample/check_conn.rb
3132
sample/copyfrom.rb
3233
sample/copyto.rb
3334
sample/cursor.rb

sample/check_conn.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env ruby
2+
# vim: set nosta noet ts=4 sw=4:
3+
# encoding: utf-8
4+
5+
require 'pg'
6+
7+
# This is a minimal example of a function that can test an existing PG::Connection and
8+
# reset it if necessary.
9+
10+
def check_connection( conn )
11+
begin
12+
conn.exec( "SELECT 1" )
13+
rescue PG::Error => err
14+
$stderr.puts "%p while testing connection: %s" % [ err.class, err.message ]
15+
conn.reset
16+
end
17+
end
18+
19+
conn = PG.connect( dbname: 'test' )
20+
check_connection( conn )
21+

0 commit comments

Comments
 (0)
0