Permalink
Browse files

Merge pull request #353 from baloo/patch-1

COOK-1062: Exists should close connection
  • Loading branch information...
2 parents 2727bcf + 7a135ce commit 8ab49340fa0522e7dfd0cc86c6eda883d43cfcc6 @jtimberman jtimberman committed Mar 8, 2012
View
12 database/libraries/provider_database_postgresql.rb
@@ -84,10 +84,14 @@ def action_query
private
def exists?
- Chef::Log.debug("#{@new_resource}: checking if database #{@new_resource.database_name} exists")
- ret = db("template1").query("select * from pg_database where datname = '#{@new_resource.database_name}'").num_tuples != 0
- ret ? Chef::Log.debug("#{@new_resource}: database #{@new_resource.database_name} exists") :
- Chef::Log.debug("#{@new_resource}: database #{@new_resource.database_name} does not exist")
+ begin
+ Chef::Log.debug("#{@new_resource}: checking if database #{@new_resource.database_name} exists")
+ ret = db("template1").query("select * from pg_database where datname = '#{@new_resource.database_name}'").num_tuples != 0
+ ret ? Chef::Log.debug("#{@new_resource}: database #{@new_resource.database_name} exists") :
+ Chef::Log.debug("#{@new_resource}: database #{@new_resource.database_name} does not exist")
+ ensure
+ close
+ end
ret
end
View
7 database/libraries/provider_database_postgresql_user.rb
@@ -69,7 +69,12 @@ def action_grant
private
def exists?
- db("template1").query("select * from pg_user where usename='#{@new_resource.username}'").num_tuples != 0
+ begin
+ exists = db("template1").query("select * from pg_user where usename='#{@new_resource.username}'").num_tuples != 0
+ ensure
+ close
+ end
+ exists
end
end

0 comments on commit 8ab4934

Please sign in to comment.