]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/rm/plugins/roundcube.rb
Wrap all close() calls in "ensure" blocks and simplify DB connection-making.
[mailshears.git] / lib / rm / plugins / roundcube.rb
index 88e88c42ab4a7683c18c246fefcc329572e1333a..c7ccaa4ccba3865e3572afa396ed047ed9f5c83f 100644 (file)
@@ -27,16 +27,16 @@ class RoundcubeRm
 
     # Thanks to the ON DELETE triggers, this will remove all child
     # records associated with user_id too.
-    sql_queries = ['DELETE FROM users WHERE user_id = $1::int;']
+    sql_query = 'DELETE FROM users WHERE user_id = $1::int;'
 
-    connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
-                                @db_name, @db_user, @db_pass)
+    connection = PG::Connection.connect(@db_hash)
 
-    sql_queries.each do |sql_query|
+    begin
       connection.query(sql_query, [user_id])
+    ensure
+      # Make sure the connection gets closed even if the query explodes.
+      connection.close()
     end
-
-    connection.close()
   end
 
 end