]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
lib,test: replace connection query() method with sync_exec{,_params}. 0.0.4
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 25 Jul 2020 01:25:51 +0000 (21:25 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 25 Jul 2020 01:25:51 +0000 (21:25 -0400)
The old generic name was deprecated in favor of the explicit
synchronous with/without-params methods.

13 files changed:
lib/common/agendav_plugin.rb
lib/common/davical_plugin.rb
lib/common/postfixadmin_plugin.rb
lib/common/roundcube_plugin.rb
lib/mv/plugins/agendav.rb
lib/mv/plugins/davical.rb
lib/mv/plugins/postfixadmin.rb
lib/mv/plugins/roundcube.rb
lib/rm/plugins/agendav.rb
lib/rm/plugins/davical.rb
lib/rm/plugins/postfixadmin.rb
lib/rm/plugins/roundcube.rb
test/mailshears_test.rb

index d8ef6d60c8445fab529bf4560cae4c578904ff3c..3b3389dcd074ea4c8b3e666ebf0874b5ec7dfc99 100644 (file)
@@ -42,7 +42,7 @@ module AgendavPlugin
     sql_query  = 'SELECT username FROM prefs;'
 
     begin
     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
         users = result.field_values('username')
       end
     ensure
@@ -65,7 +65,7 @@ module AgendavPlugin
 
     sql_query  = 'SELECT count(*) FROM shares;'
     begin
 
     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
         count = result.getvalue(0,0).to_i()
       end
     ensure
index ba09770deee3eff9d8483f76d70e23a5f99dfb2e..06abbfa99e31844b6ae22c5190a828837e59862c 100644 (file)
@@ -55,7 +55,7 @@ module DavicalPlugin
     sql_query = 'SELECT username FROM usr WHERE user_no > 1;'
 
     begin
     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
         usernames = result.field_values('username')
       end
     ensure
@@ -88,7 +88,7 @@ module DavicalPlugin
     sql_query += 'WHERE usr.username = $1;'
 
     begin
     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
         if result.num_tuples > 0
           principal_id = result[0]['principal_id']
         end
index 08fca7d32efe77d488328f4ff41e4a7c1e0eaaf5..92b7a5b3036cdc8be3bba7df549d9d026cf8e87f 100644 (file)
@@ -43,7 +43,7 @@ module PostfixadminPlugin
     sql_query = "SELECT domain FROM domain WHERE domain <> 'ALL';"
 
     begin
     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
         domains = result.field_values('domain')
       end
     ensure
@@ -68,7 +68,7 @@ module PostfixadminPlugin
     sql_query = 'SELECT username FROM mailbox;'
 
     begin
     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
         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.
     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
         usernames = result.field_values('username')
       end
     ensure
@@ -131,7 +131,7 @@ module PostfixadminPlugin
     sql_query = 'SELECT address,goto FROM alias;'
 
     begin
     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
       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
     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()
 
         return false if result.ntuples() < 1
         count = result.getvalue(0,0).to_i()
 
index b66c9f603cf2e4c665de427d33f6210108db3b1f..6d522bb371847e433906af3792f74545916bd7cc 100644 (file)
@@ -52,7 +52,7 @@ module RoundcubePlugin
     sql_query = 'SELECT username FROM users;'
 
     begin
     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
         usernames = result.field_values('username')
       end
     ensure
@@ -79,7 +79,7 @@ module RoundcubePlugin
     sql_query = 'SELECT user_id FROM users WHERE username = $1;'
 
     begin
     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
         if result.num_tuples > 0
           user_id = result[0]['user_id']
         end
index 2177009e67295b07b3762966976668e2a932b3ef..a2fb05438dd0cb5808b45d9d64f80d323fa0b037 100644 (file)
@@ -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;'
       # 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
 
       # 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|
       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.
       end
     ensure
       # Make sure the connection gets closed even if a query explodes.
index e7aa050889384234bc8802b924e58038290084c6..1a8a18aa70e8d27cef54ad867a230890587e6932 100644 (file)
@@ -33,7 +33,7 @@ class DavicalMv
 
     connection = PG::Connection.new(@db_hash)
     begin
 
     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()
     ensure
       # Make sure the connection gets closed even if the query explodes.
       connection.close()
index f8f86c6ba45236b570e16f9b5c15fa2647aa77b1..1623118109a9033fd9e01bd75ee5ba737dfcfa8f 100644 (file)
@@ -59,7 +59,7 @@ class PostfixadminMv
                   {:value => dst.domainpart(), :type => varchar},
                   {:value => dst.localpart(), :type => varchar},
                   {:value => src.to_s(), :type => varchar}]
                   {: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.
       end
     ensure
       # Make sure the connection gets closed even if a query explodes.
index 5cd20c77064532988bff689bcf52f43c49b67692..e2126f75f244bd5288647ec41ff7610917b90b42 100644 (file)
@@ -34,7 +34,7 @@ class RoundcubeMv
 
     connection = PG::Connection.new(@db_hash)
     begin
 
     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()
     ensure
       # Make sure the connection gets closed even if the query explodes.
       connection.close()
index 921bfe0687e2610401f2997dfe25cc09b3cfa6b1..2c7709011ca3a421ced83d7d58e2f1aa3c6c2faf 100644 (file)
@@ -47,7 +47,7 @@ class AgendavRm
     connection = PG::Connection.new(@db_hash)
     begin
       sql_queries.each do |sql_query|
     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.
       end
     ensure
       # Make sure the connection gets closed even if a query explodes.
index 1029994b9edc77a6db010eeb73fd8ad776a1b3ed..1978e8025b20a7990c3e8bb73f954b759f0a4590 100644 (file)
@@ -27,7 +27,7 @@ class DavicalRm
 
     connection = PG::Connection.new(@db_hash)
     begin
 
     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()
     ensure
       # Make sure the connection gets closed even if the query explodes.
       connection.close()
index 46eda4736878c25c35e435aee446a89d77be5fe3..958d42cbfd530e9fcb0ae6c7b1b83fa9b2c0ebb3 100644 (file)
@@ -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}]
       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.
       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|
 
     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.
       end
     ensure
       # Make sure the connection gets closed even if a query explodes.
index cb55af7dfb2394b166c2be856f512ab7cdbf7712..56c3108c354cf79d0b5017e025d8e7c64fb75a5a 100644 (file)
@@ -32,7 +32,7 @@ class RoundcubeRm
     connection = PG::Connection.new(@db_hash)
 
     begin
     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()
     ensure
       # Make sure the connection gets closed even if the query explodes.
       connection.close()
index 2b653ede18100dc64e4afcaaaef3f757ebc8b8f6..94f2f4903bd7894b505fa21e8a3ff340503ba668 100644 (file)
@@ -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};"
       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")
 
       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_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()
       sql = File.open("test/sql/#{plugin}-fixtures.sql").read()
-      plugin_conn.query(sql)
+      plugin_conn.sync_exec(sql)
       plugin_conn.close()
     end
 
       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};"
       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()
     end
 
     connection.close()