X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fmv%2Fplugins%2Froundcube.rb;h=e2126f75f244bd5288647ec41ff7610917b90b42;hp=4d8196461ca570a8e51a5aa0880365dda8d950f5;hb=fa7782720ff15fce29b6f875678e9fd0c197485a;hpb=df4e02ebf6a4e28a58abcb298a4442a245ad0b15 diff --git a/lib/mv/plugins/roundcube.rb b/lib/mv/plugins/roundcube.rb index 4d81964..e2126f7 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;'] - - connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty, - @db_name, @db_user, @db_pass) - - sql_queries.each do |sql_query| - connection.query(sql_query, [dst.to_s(), src.to_s()]) + sql_query = 'UPDATE users SET username = $1 WHERE username = $2;' + + connection = PG::Connection.new(@db_hash) + begin + connection.sync_exec_params(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