From 8def8385214dc9095bd4dc5369b2f905d99b4b45 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 26 Dec 2010 16:34:34 -0500 Subject: [PATCH] Update the PostfixadminDb class to use the newer 'pg' module. --- src/postfixadmin_db.rb | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/postfixadmin_db.rb b/src/postfixadmin_db.rb index d9112af..0249ea0 100644 --- a/src/postfixadmin_db.rb +++ b/src/postfixadmin_db.rb @@ -1,4 +1,4 @@ -require 'postgres' +require 'pg' class PostfixadminDb @@ -21,6 +21,8 @@ class PostfixadminDb def get_domains_from_db() + domains = [] + # Just assume PostgreSQL for now. begin connection = PGconn.connect(@db_host, @@ -33,21 +35,22 @@ class PostfixadminDb # 'ALL' is a magic domain, and we don't want it. sql_query = "SELECT domain FROM domain WHERE domain <> 'ALL';" - result = connection.query(sql_query) + connection.query(sql_query) do |result| + domains = result.field_values('domain') + end connection.close() rescue PGError => e # But pretend like we're database-agnostic in case we ever are. raise DatabaseError.new(e) end - # The database query returns an array of rows. Since we only asked - # for one column (domain), we can flatten the result into an - # array of domains. - return result.flatten + return domains end def get_accounts_from_db() + accounts = [] + # Just assume PostgreSQL for now. begin connection = PGconn.connect(@db_host, @@ -61,17 +64,16 @@ class PostfixadminDb # If address = goto, then the alias basically says, "really # deliver to that address; it's not an alias." sql_query = 'SELECT username FROM mailbox;' - result = connection.query(sql_query) + connection.query(sql_query) do |result| + accounts = result.field_values('username') + end connection.close() rescue PGError => e # But pretend like we're database-agnostic in case we ever are. raise DatabaseError.new(e) end - # The database query returns an array of rows. Since we only asked - # for one column (address), we can flatten the result into an - # array of addresses. - return result.flatten + return accounts end end -- 2.44.2