Skip to content

Commit

Permalink
Merge pull request chef-boneyard#353 from baloo/patch-1
Browse files Browse the repository at this point in the history
COOK-1062: Exists should close connection
  • Loading branch information
Joshua Timberman committed Mar 8, 2012
2 parents 2727bcf + 7a135ce commit 8ab4934
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions database/libraries/provider_database_postgresql.rb
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion database/libraries/provider_database_postgresql_user.rb
Expand Up @@ -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
Expand Down

0 comments on commit 8ab4934

Please sign in to comment.