From fa7782720ff15fce29b6f875678e9fd0c197485a Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 24 Jul 2020 21:25:51 -0400 Subject: [PATCH] lib,test: replace connection query() method with sync_exec{,_params}. The old generic name was deprecated in favor of the explicit synchronous with/without-params methods. --- lib/common/agendav_plugin.rb | 4 ++-- lib/common/davical_plugin.rb | 4 ++-- lib/common/postfixadmin_plugin.rb | 10 +++++----- lib/common/roundcube_plugin.rb | 4 ++-- lib/mv/plugins/agendav.rb | 4 ++-- lib/mv/plugins/davical.rb | 2 +- lib/mv/plugins/postfixadmin.rb | 2 +- lib/mv/plugins/roundcube.rb | 2 +- lib/rm/plugins/agendav.rb | 2 +- lib/rm/plugins/davical.rb | 2 +- lib/rm/plugins/postfixadmin.rb | 4 ++-- lib/rm/plugins/roundcube.rb | 2 +- test/mailshears_test.rb | 8 ++++---- 13 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/common/agendav_plugin.rb b/lib/common/agendav_plugin.rb index d8ef6d6..3b3389d 100644 --- a/lib/common/agendav_plugin.rb +++ b/lib/common/agendav_plugin.rb @@ -42,7 +42,7 @@ module AgendavPlugin sql_query = 'SELECT username FROM prefs;' begin - connection.query(sql_query) do |result| + connection.sync_exec(sql_query) do |result| users = result.field_values('username') end ensure @@ -65,7 +65,7 @@ module AgendavPlugin sql_query = 'SELECT count(*) FROM shares;' begin - connection.query(sql_query) do |result| + connection.sync_exec(sql_query) do |result| count = result.getvalue(0,0).to_i() end ensure diff --git a/lib/common/davical_plugin.rb b/lib/common/davical_plugin.rb index ba09770..06abbfa 100644 --- a/lib/common/davical_plugin.rb +++ b/lib/common/davical_plugin.rb @@ -55,7 +55,7 @@ module DavicalPlugin sql_query = 'SELECT username FROM usr WHERE user_no > 1;' begin - connection.query(sql_query) do |result| + connection.sync_exec(sql_query) do |result| usernames = result.field_values('username') end ensure @@ -88,7 +88,7 @@ module DavicalPlugin sql_query += 'WHERE usr.username = $1;' begin - connection.query(sql_query, [user.to_s()]) do |result| + connection.sync_exec_params(sql_query, [user.to_s()]) do |result| if result.num_tuples > 0 principal_id = result[0]['principal_id'] end diff --git a/lib/common/postfixadmin_plugin.rb b/lib/common/postfixadmin_plugin.rb index 08fca7d..92b7a5b 100644 --- a/lib/common/postfixadmin_plugin.rb +++ b/lib/common/postfixadmin_plugin.rb @@ -43,7 +43,7 @@ module PostfixadminPlugin sql_query = "SELECT domain FROM domain WHERE domain <> 'ALL';" begin - connection.query(sql_query) do |result| + connection.sync_exec(sql_query) do |result| domains = result.field_values('domain') end ensure @@ -68,7 +68,7 @@ module PostfixadminPlugin sql_query = 'SELECT username FROM mailbox;' begin - connection.query(sql_query) do |result| + connection.sync_exec(sql_query) do |result| users = result.field_values('username') end ensure @@ -104,7 +104,7 @@ module PostfixadminPlugin begin # Now replace each Domain with its string representation and pass # those in as our individual parameters. - connection.query(sql_query, domains.map{ |d| d.to_s() }) do |result| + connection.sync_exec_params(sql_query, domains.map{ |d| d.to_s() }) do |result| usernames = result.field_values('username') end ensure @@ -131,7 +131,7 @@ module PostfixadminPlugin sql_query = 'SELECT address,goto FROM alias;' begin - results = connection.query(sql_query) + results = connection.sync_exec(sql_query) results.each do |row| # row should be a hash aliases << row @@ -163,7 +163,7 @@ module PostfixadminPlugin sql_query = 'SELECT COUNT(domain) as count FROM domain WHERE domain = $1;' begin - connection.query(sql_query, [domain.to_s()]) do |result| + connection.sync_exec_params(sql_query, [domain.to_s()]) do |result| return false if result.ntuples() < 1 count = result.getvalue(0,0).to_i() diff --git a/lib/common/roundcube_plugin.rb b/lib/common/roundcube_plugin.rb index b66c9f6..6d522bb 100644 --- a/lib/common/roundcube_plugin.rb +++ b/lib/common/roundcube_plugin.rb @@ -52,7 +52,7 @@ module RoundcubePlugin sql_query = 'SELECT username FROM users;' begin - connection.query(sql_query) do |result| + connection.sync_exec(sql_query) do |result| usernames = result.field_values('username') end ensure @@ -79,7 +79,7 @@ module RoundcubePlugin sql_query = 'SELECT user_id FROM users WHERE username = $1;' begin - connection.query(sql_query, [user.to_s()]) do |result| + connection.sync_exec_params(sql_query, [user.to_s()]) do |result| if result.num_tuples > 0 user_id = result[0]['user_id'] end diff --git a/lib/mv/plugins/agendav.rb b/lib/mv/plugins/agendav.rb index 2177009..a2fb054 100644 --- a/lib/mv/plugins/agendav.rb +++ b/lib/mv/plugins/agendav.rb @@ -40,7 +40,7 @@ class AgendavMv # The "prefs" table uses the normal username as a key... # This should be harmless if the source user does not exist. sql_query0 = 'UPDATE prefs SET username = $1 WHERE username = $2;' - connection.query(sql_query0, [dst.to_s(), src.to_s()]) + connection.sync_exec_params(sql_query0, [dst.to_s(), src.to_s()]) # But the "shares" table uses encoded principal URLs. For the # "shares" table, we need to do a find/replace on the username @@ -58,7 +58,7 @@ class AgendavMv sql_queries << 'UPDATE shares SET "with"=REPLACE("with", $2, $1);' sql_queries.each do |sql_query| - connection.query(sql_query, [encoded_dst, encoded_src]) + connection.sync_exec_params(sql_query, [encoded_dst, encoded_src]) end ensure # Make sure the connection gets closed even if a query explodes. diff --git a/lib/mv/plugins/davical.rb b/lib/mv/plugins/davical.rb index e7aa050..1a8a18a 100644 --- a/lib/mv/plugins/davical.rb +++ b/lib/mv/plugins/davical.rb @@ -33,7 +33,7 @@ class DavicalMv connection = PG::Connection.new(@db_hash) begin - connection.query(sql_query, [dst.to_s(), src.to_s()]) + 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() diff --git a/lib/mv/plugins/postfixadmin.rb b/lib/mv/plugins/postfixadmin.rb index f8f86c6..1623118 100644 --- a/lib/mv/plugins/postfixadmin.rb +++ b/lib/mv/plugins/postfixadmin.rb @@ -59,7 +59,7 @@ class PostfixadminMv {:value => dst.domainpart(), :type => varchar}, {:value => dst.localpart(), :type => varchar}, {:value => src.to_s(), :type => varchar}] - connection.query(sql_query, params) + connection.sync_exec_params(sql_query, params) end ensure # Make sure the connection gets closed even if a query explodes. diff --git a/lib/mv/plugins/roundcube.rb b/lib/mv/plugins/roundcube.rb index 5cd20c7..e2126f7 100644 --- a/lib/mv/plugins/roundcube.rb +++ b/lib/mv/plugins/roundcube.rb @@ -34,7 +34,7 @@ class RoundcubeMv connection = PG::Connection.new(@db_hash) begin - connection.query(sql_query, [dst.to_s(), src.to_s()]) + 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() diff --git a/lib/rm/plugins/agendav.rb b/lib/rm/plugins/agendav.rb index 921bfe0..2c77090 100644 --- a/lib/rm/plugins/agendav.rb +++ b/lib/rm/plugins/agendav.rb @@ -47,7 +47,7 @@ class AgendavRm connection = PG::Connection.new(@db_hash) begin sql_queries.each do |sql_query| - connection.query(sql_query, [user.to_s()]) + connection.sync_exec_params(sql_query, [user.to_s()]) end ensure # Make sure the connection gets closed even if a query explodes. diff --git a/lib/rm/plugins/davical.rb b/lib/rm/plugins/davical.rb index 1029994..1978e80 100644 --- a/lib/rm/plugins/davical.rb +++ b/lib/rm/plugins/davical.rb @@ -27,7 +27,7 @@ class DavicalRm connection = PG::Connection.new(@db_hash) begin - connection.query(sql_query, [user.to_s()]) + connection.sync_exec_params(sql_query, [user.to_s()]) ensure # Make sure the connection gets closed even if the query explodes. connection.close() diff --git a/lib/rm/plugins/postfixadmin.rb b/lib/rm/plugins/postfixadmin.rb index 46eda47..958d42c 100644 --- a/lib/rm/plugins/postfixadmin.rb +++ b/lib/rm/plugins/postfixadmin.rb @@ -56,7 +56,7 @@ class PostfixadminRm sql_queries.each do |sql_query| varchar = 1043 # from pg_type.h params = [{:value => user.to_s(), :type => varchar}] - connection.query(sql_query, params) + connection.sync_exec_params(sql_query, params) end ensure # Make sure the connection gets closed even if a query explodes. @@ -103,7 +103,7 @@ class PostfixadminRm begin sql_queries.each do |sql_query| - connection.query(sql_query, [domain.to_s()]) + connection.sync_exec_params(sql_query, [domain.to_s()]) end ensure # Make sure the connection gets closed even if a query explodes. diff --git a/lib/rm/plugins/roundcube.rb b/lib/rm/plugins/roundcube.rb index cb55af7..56c3108 100644 --- a/lib/rm/plugins/roundcube.rb +++ b/lib/rm/plugins/roundcube.rb @@ -32,7 +32,7 @@ class RoundcubeRm connection = PG::Connection.new(@db_hash) begin - connection.query(sql_query, [user_id]) + connection.sync_exec_params(sql_query, [user_id]) ensure # Make sure the connection gets closed even if the query explodes. connection.close() diff --git a/test/mailshears_test.rb b/test/mailshears_test.rb index 2b653ed..94f2f49 100644 --- a/test/mailshears_test.rb +++ b/test/mailshears_test.rb @@ -208,7 +208,7 @@ class MailshearsTest < MiniTest::Test plugin_dbname = cfg.send("#{plugin}_dbname") next if plugin_dbname.nil? # Skip the dovecot plugin query = "CREATE DATABASE #{plugin_dbname};" - connection.query(query) + connection.sync_exec(query) plugin_dbhost = cfg.send("#{plugin}_dbhost") plugin_dbport = cfg.send("#{plugin}_dbport") @@ -223,9 +223,9 @@ class MailshearsTest < MiniTest::Test plugin_dbpass) sql = File.open("test/sql/#{plugin}.sql").read() - plugin_conn.query(sql) + plugin_conn.sync_exec(sql) sql = File.open("test/sql/#{plugin}-fixtures.sql").read() - plugin_conn.query(sql) + plugin_conn.sync_exec(sql) plugin_conn.close() end @@ -246,7 +246,7 @@ class MailshearsTest < MiniTest::Test plugin_dbname = cfg.send("#{plugin}_dbname") next if plugin_dbname.nil? # Skip the dovecot plugin query = "DROP DATABASE IF EXISTS #{plugin_dbname};" - connection.query(query) + connection.sync_exec(query) end connection.close() -- 2.44.2