File: check_conn.rb

package info (click to toggle)
ruby-pg 1.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,316 kB
  • sloc: ansic: 9,403; ruby: 3,160; makefile: 10
file content (21 lines) | stat: -rw-r--r-- 444 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- ruby -*-
# vim: set nosta noet ts=4 sw=4:
# encoding: utf-8

require 'pg'

# This is a minimal example of a function that can test an existing PG::Connection and
# reset it if necessary.

def check_connection( conn )
	begin
		conn.exec( "SELECT 1" )
	rescue PG::Error => err
		$stderr.puts "%p while testing connection: %s" % [ err.class, err.message ]
		conn.reset
	end
end

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