4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/dblink/psql_runner.rb', line 4
def check_connection(opt = {})
psql_path = find_psql
unless psql_path
result = "Can not find #{'psql'.bold} in your system\n"
if RUBY_PLATFORM =~ /darwin/
result += "Please run 'brew install postgres' or download it from http://postgresapp.com"
else
result += "Please install postgresql package in your system"
end
result += "\nOr disable connection checking (--no-check-local and --no-check-remote)"
return result
end
passwd = opt[:password] && opt[:password] == '' ? '' : "PGPASSWORD=#{opt[:password]}"
psql_command = "#{passwd} #{psql_path} -h #{opt[:host]} -p #{opt[:port]} -U #{opt[:user]} #{opt[:database]} -c 'select now()'"
if opt[:verbose]
puts "EXEC #{psql_command}"
end
result = %x(#{psql_command} 2>&1)
result.include?('(1 row)') ? true : result
end
|