X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fmv%2Fplugins%2Froundcube.rb;h=5cd20c77064532988bff689bcf52f43c49b67692;hp=4d8196461ca570a8e51a5aa0880365dda8d950f5;hb=b947ef8844f090eedd50be0383abe417d910bb1a;hpb=58849f9ba58bd0804ffe6c6d8248caf2ab66dc66 diff --git a/lib/mv/plugins/roundcube.rb b/lib/mv/plugins/roundcube.rb index 4d81964..5cd20c7 100644 --- a/lib/mv/plugins/roundcube.rb +++ b/lib/mv/plugins/roundcube.rb @@ -30,16 +30,15 @@ class RoundcubeMv raise NonexistentUserError.new(src.to_s()) if not user_exists(src) raise UserAlreadyExistsError.new(dst.to_s()) if user_exists(dst) - sql_queries = ['UPDATE users SET username = $1 WHERE username = $2;'] + sql_query = 'UPDATE users SET username = $1 WHERE username = $2;' - connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty, - @db_name, @db_user, @db_pass) - - sql_queries.each do |sql_query| + connection = PG::Connection.new(@db_hash) + begin connection.query(sql_query, [dst.to_s(), src.to_s()]) + ensure + # Make sure the connection gets closed even if the query explodes. + connection.close() end - - connection.close() end end